Browse Source

textium: face cache example (really should move some of these to tests)

master
Erin 8 years ago
parent
commit
7205ed386c
1 changed files with 28 additions and 0 deletions
  1. +28
    -0
      textium/examples/face_cache.rs

+ 28
- 0
textium/examples/face_cache.rs View File

@ -0,0 +1,28 @@
extern crate textium;
extern crate rusttype;
use rusttype::{FontCollection};
use textium::texture::Bitmap;
use textium::cache::Cache;
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 mut cache: Cache<Bitmap<u8>> = Cache::new();
cache.add_font("IBM", font);
let transform = |buf| Ok(buf);
let x = cache.build_face("IBM", 32., ASCII.iter().cloned(), transform);
println!("{:?}", x);
}

Loading…
Cancel
Save