From f1af59f93fbaef459ff616dd58c6ed81c41518a2 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 15 Aug 2017 17:00:54 -0500 Subject: [PATCH] Add render_atlas.rs example --- textium/examples/render_atlas.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 textium/examples/render_atlas.rs diff --git a/textium/examples/render_atlas.rs b/textium/examples/render_atlas.rs new file mode 100644 index 0000000..d7fc1d6 --- /dev/null +++ b/textium/examples/render_atlas.rs @@ -0,0 +1,37 @@ +extern crate textium; +extern crate rusttype; + +use rusttype::{FontCollection}; + +/// An array of all of the ascii printable characters. +pub 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!("Gudea-Regular.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); + + // println!("{:?}", atlas.glyph_data); + for line in bitmap.lines() { + print!("{:03} ", line.len()); + for &pixel in line { + if pixel == 0 { + print!(" "); + } else { + print!("#"); + } + } + println!(""); + } +}