font_atlas/
lib.rs

1extern crate rusttype;
2extern crate void;
3
4use std::io::Result as IoResult;
5use std::path::Path;
6
7/// Contains methods and structures for packing characters into an atlas.
8pub mod glyph_packer;
9/// Contains methods and structures for rasterizing font files to bitmaps.
10pub mod rasterize;
11/// Contains methods and structures for caching fonts and faces.
12pub mod cache;
13
14/// An array of all of the ascii printable characters.
15pub const ASCII: &'static [char] = &[
16    ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/',
17    ':', ';', '<', '=', '>', '?', '[', ']', '\\', '|', '{', '}', '^', '~', '_', '@',
18    '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
19    'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E',
20    'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
21    'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
22];
23
24/// Loads a font from a location on the file system.
25pub fn load_font<P: AsRef<Path>>(path: P) -> IoResult<rasterize::Font> {
26    use std::io::Read;
27    use std::fs::File;
28    let mut buf = vec![];
29    try!(try!(File::open(path)).read_to_end(&mut buf));
30    Ok(load_font_from_bytes(buf))
31}
32
33/// Loads a font from bytes in memory.
34pub fn load_font_from_bytes(bytes: Vec<u8>) -> rasterize::Font {
35    rasterize::Font::new(rusttype::FontCollection::from_bytes(bytes).into_font().unwrap())
36}
37