FontCache

Struct FontCache 

Source
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>

Source

pub fn new() -> FontCache<T>

Create an empty FontCache.

Source

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.

Source

pub fn create_face<I, F, E>( &mut self, name: &str, scale: f32, chars: I, f: F, ) -> Result<(), FontCacheError<E>>
where I: Iterator<Item = char>, F: Fn(Bitmap) -> Result<T, 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.

Source

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).

Source

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).

Source

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.

Source

pub fn drawing_commands_prepared<F, E>( &mut self, font_name: &str, scale: f32, string: &str, f: F, ) -> Result<Vec<DrawCommand<'_, T>>, FontCacheError<E>>
where F: Fn(Bitmap) -> Result<T, 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.

Trait Implementations§

Source§

impl<T: Debug> Debug for FontCache<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for FontCache<T>

§

impl<T> RefUnwindSafe for FontCache<T>
where T: RefUnwindSafe,

§

impl<T> Send for FontCache<T>
where T: Send,

§

impl<T> Sync for FontCache<T>
where T: Sync,

§

impl<T> Unpin for FontCache<T>
where T: Unpin,

§

impl<T> UnwindSafe for FontCache<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.