extern crate image; extern crate textium; extern crate rusttype; use std::path::Path; use rusttype::{FontCollection}; use textium::texture::Buffer2d; use image::{ImageBuffer, Luma}; const ASCII: &'static [char] = &[ ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '[', ']', '\\', '|', '{', '}', '^', '~', '_', '@', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ]; fn main() { 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().chain(ASCII.iter().cloned()); let (_, bitmap, _) = font.make_atlas(chrs, 20.0, 1, 256, 128); let img: ImageBuffer, _> = ImageBuffer::from_raw(bitmap.width() as u32, bitmap.height() as u32, bitmap.raw()).unwrap(); let _ = img.save(&Path::new("atlas.png")); }