Skip to main content

Font

Trait Font 

Source
pub trait Font: Send + Sync {
    // Required methods
    fn advance(&self) -> u32;
    fn line_height(&self) -> u32;
    fn draw_glyph(&self, ch: char, draw_pixel: &mut dyn FnMut(i32, i32));
}
Expand description

Trait for custom font providers.

Consumers can implement this trait on custom font types (e.g. anti-aliased fonts, vector text generators, external BDF/PSF font decoders, TTF parsers) and use FontId::Dynamic or FontId::from to pass them to text styling.

Required Methods§

Source

fn advance(&self) -> u32

Character horizontal advance in pixels.

Source

fn line_height(&self) -> u32

Vertical line height in pixels.

Source

fn draw_glyph(&self, ch: char, draw_pixel: &mut dyn FnMut(i32, i32))

Render a single glyph by calling draw_pixel(dx, dy) for each active pixel in the glyph, where (dx, dy) are relative coordinates within the glyph bounding box.

Trait Implementations§

Source§

impl From<&'static dyn Font> for FontId

Source§

fn from(font: &'static dyn Font) -> Self

Converts to this type from the input type.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§