pub trait FontProvider {
// Required methods
fn pixel_type(&self) -> PixelType;
fn single_glyph(&self, character: char) -> Glyph;
fn glyphs(&self, string: &str, glyphs: &mut Vec<Glyph>);
fn line_height(&self) -> f32;
fn metrics(&self, glyph: Glyph) -> Metrics;
fn rasterize(&self, glpyh: Glyph) -> Result<Vec<u8>, CacheError>;
// Provided method
fn kerning(&self, _a: Glyph, _b: Glyph) -> f32 { ... }
}Expand description
Any object that can turn characters into glyphs and render them can be a FontProvider
FontProviders can be TTF font rasters, like rusttype (a pure-Rust library for decoding fonts) or fontkit (a library that delegates to system APIs to handle fonts). Other FontProviders could include bitmap fonts, or a combination of libraries (like a library to handle shaping and another library to handle rendering.)
It is assumed that a given font provider will operate at a fixed size. For a variable-sized source (like a TTF font), the font size can be paired with the font data to produce a single FontProvider.
Required Methods§
Sourcefn pixel_type(&self) -> PixelType
fn pixel_type(&self) -> PixelType
The format of the data generated by the FontProvider
Sourcefn single_glyph(&self, character: char) -> Glyph
fn single_glyph(&self, character: char) -> Glyph
Convert a single character into a Glyph
Generally you should use [glyphs], but when rendering just one character this method can
be useful
Sourcefn glyphs(&self, string: &str, glyphs: &mut Vec<Glyph>)
fn glyphs(&self, string: &str, glyphs: &mut Vec<Glyph>)
Convert the string into glyphs, and push the glyphs into the provided buffer
This is not necessarily the same as running single_glyph over every character in the
string! Text is hard.
Sourcefn line_height(&self) -> f32
fn line_height(&self) -> f32
How much space to include between baselines of the given font
Sourcefn metrics(&self, glyph: Glyph) -> Metrics
fn metrics(&self, glyph: Glyph) -> Metrics
Get the metrics of a character (how to space it, where to include it on a line, etc.)
Sourcefn rasterize(&self, glpyh: Glyph) -> Result<Vec<u8>, CacheError>
fn rasterize(&self, glpyh: Glyph) -> Result<Vec<u8>, CacheError>
Convert a character into image bytes, with the format determined by pixel_type