thanks, jk
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.2 KiB

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