1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
use std::{io, path::Path};

use graphics::glyph_cache::rusttype;
use texture::TextureSettings;

use crate::RenderBuffer;

/// A character cache for drawing text to a `RenderBuffer`.
///
/// If the link to the `GlyphCache` type is not working,
/// try generating the docs yourself.
pub type BufferGlyphs<'a> = rusttype::GlyphCache<'a, (), RenderBuffer>;

/// Create a `BufferGlyphs` from some font data
pub fn buffer_glyphs_from_bytes<'a>(font_data: &'a [u8]) -> Result<BufferGlyphs<'a>, ()> {
    BufferGlyphs::from_bytes(font_data, (), TextureSettings::new())
}
/// Create a `BufferGlyphs` from a path to some font
pub fn buffer_glyphs_from_path<'a, P: AsRef<Path>>(font_path: P) -> io::Result<BufferGlyphs<'a>> {
    BufferGlyphs::new(font_path, (), TextureSettings::new())
}