pub struct FontCache<T> { /* private fields */ }Expand description
A cache that stores multiple fonts types of multiple weights.
The basic usage for a FontCache is to load all of the fonts that
you plan on using into the FontCache, then call create_face for
each of the font/size combinations that you see yourself using.
Implementations§
Source§impl<T> FontCache<T>
impl<T> FontCache<T>
Sourcepub fn load_font<S: Into<String>>(&mut self, name: S, font: Font)
pub fn load_font<S: Into<String>>(&mut self, name: S, font: Font)
Loads a font into the cache with a given name. This will allow you to call
create_face passing in the name in order to generate a rendering of this
font at a given size.
Sourcepub fn create_face<I, F, E>(
&mut self,
name: &str,
scale: f32,
chars: I,
f: F,
) -> Result<(), FontCacheError<E>>
pub fn create_face<I, F, E>( &mut self, name: &str, scale: f32, chars: I, f: F, ) -> Result<(), FontCacheError<E>>
Given the name of an already-loaded font and the scale at which to draw it,
create_face generates an atlas with the characters in chars and stores it
this cache.
The function f is used to transform a character bitmap into whatever
format you want to use internally.
Sourcepub fn get_face_cache(&self, name: &str, scale: f32) -> Option<&FaceCache<T>>
pub fn get_face_cache(&self, name: &str, scale: f32) -> Option<&FaceCache<T>>
Retrieves a facecache reference given the name of the font and a scale (assuming one exists).
Sourcepub fn get_face_cache_mut(
&mut self,
name: &str,
scale: f32,
) -> Option<&mut FaceCache<T>>
pub fn get_face_cache_mut( &mut self, name: &str, scale: f32, ) -> Option<&mut FaceCache<T>>
Retrieves a mutable facecache given the name of the font and a scale (assuming one exists).
Sourcepub fn drawing_commands(
&self,
font_name: &str,
scale: f32,
string: &str,
) -> Result<Vec<DrawCommand<'_, T>>, FontCacheError<Void>>
pub fn drawing_commands( &self, font_name: &str, scale: f32, string: &str, ) -> Result<Vec<DrawCommand<'_, T>>, FontCacheError<Void>>
Returns the drawing commands for a given font name, scale and the string to draw.
Can fail if the font hasn’t been rasterized with create_face.
Sourcepub fn drawing_commands_prepared<F, E>(
&mut self,
font_name: &str,
scale: f32,
string: &str,
f: F,
) -> Result<Vec<DrawCommand<'_, T>>, FontCacheError<E>>
pub fn drawing_commands_prepared<F, E>( &mut self, font_name: &str, scale: f32, string: &str, f: F, ) -> Result<Vec<DrawCommand<'_, T>>, FontCacheError<E>>
Returns the drawing commands for a given font name, scale, and the string to draw.
If the font hasn’t been loaded with load_font an error is returned.
If the font hasn’t been rasterized with create_face, it is done so now.