|
|
@ -1,10 +1,13 @@ |
|
|
|
extern crate image;
|
|
|
|
extern crate textium;
|
|
|
|
extern crate rusttype;
|
|
|
|
|
|
|
|
use std::path::Path;
|
|
|
|
use rusttype::{FontCollection};
|
|
|
|
use textium::texture::Buffer2d;
|
|
|
|
use image::{ImageBuffer, Luma};
|
|
|
|
|
|
|
|
/// An array of all of the ascii printable characters.
|
|
|
|
pub const ASCII: &'static [char] = &[
|
|
|
|
const ASCII: &'static [char] = &[
|
|
|
|
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
|
|
|
|
':', ';', '<', '=', '>', '?', '[', ']', '\\', '|', '{', '}', '^', '~', '_', '@',
|
|
|
|
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
|
|
@ -14,24 +17,14 @@ pub const ASCII: &'static [char] = &[ |
|
|
|
];
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let font_data = include_bytes!("Gudea-Regular.ttf");
|
|
|
|
let font_data = include_bytes!("Px437_IBM_VGA8.ttf");
|
|
|
|
let font = FontCollection::from_bytes(font_data as &[u8])
|
|
|
|
.into_font().unwrap();
|
|
|
|
let font = textium::Font::new(font);
|
|
|
|
|
|
|
|
let chrs = ASCII.iter().cloned();
|
|
|
|
let (atlas, bitmap, line_height) = font.make_atlas(chrs, 40.0, 1, 64, 64);
|
|
|
|
let chrs = ASCII.iter().cloned().chain(ASCII.iter().cloned());
|
|
|
|
let (_, bitmap, _) = font.make_atlas(chrs, 20.0, 1, 256, 128);
|
|
|
|
|
|
|
|
// println!("{:?}", atlas.glyph_data);
|
|
|
|
for line in bitmap.lines() {
|
|
|
|
print!("{:03} ", line.len());
|
|
|
|
for &pixel in line {
|
|
|
|
if pixel == 0 {
|
|
|
|
print!(" ");
|
|
|
|
} else {
|
|
|
|
print!("#");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
println!("");
|
|
|
|
}
|
|
|
|
let img: ImageBuffer<Luma<u8>, _> = ImageBuffer::from_raw(bitmap.width() as u32, bitmap.height() as u32, bitmap.raw()).unwrap();
|
|
|
|
let _ = img.save(&Path::new("atlas.png"));
|
|
|
|
}
|