[][src]Trait elefont::FontProvider

pub trait FontProvider {
    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>; fn kerning(&self, _a: Glyph, _b: Glyph) -> f32 { ... } }

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

fn pixel_type(&self) -> PixelType

The format of the data generated by the FontProvider

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

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.

fn line_height(&self) -> f32

How much space to include between baselines of the given font

fn metrics(&self, glyph: Glyph) -> Metrics

Get the metrics of a character (how to space it, where to include it on a line, etc.)

fn rasterize(&self, glpyh: Glyph) -> Result<Vec<u8>, CacheError>

Convert a character into image bytes, with the format determined by pixel_type

Loading content...

Provided methods

fn kerning(&self, _a: Glyph, _b: Glyph) -> f32

Optionally expose extra kerning information for glyphs

By default, this is always 0.0. Some font providers may add more information here, however.

Loading content...

Implementors

impl<'_> FontProvider for SizedFont<'_>[src]

Loading content...