Skip to main content

FontManager

Trait FontManager 

Source
pub trait FontManager: Send + Sync {
    // Required methods
    fn family(&self, family: &str) -> Vec<Typeface>;
    fn match_character(
        &self,
        family: Option<&str>,
        style: Style,
        locales: &[&str],
        character: char,
    ) -> Option<Typeface>;
    fn system_font(&self, size: f32, style: Style) -> Option<Typeface>;
    fn families(&self) -> Vec<String>;
    fn face_count(&self) -> usize;
    fn watch(&self, on_change: Box<dyn Fn() + Sync + Send>) -> Option<Watch>;

    // Provided method
    fn match_family_style(&self, family: &str, style: Style) -> Option<Typeface> { ... }
}
Expand description

FontManager is the platform’s font lookup, in the shape of Skia’s SkFontMgr.

Answers are typefaces the caller parses; nothing is shaped or rasterised here.

One manager answers every thread at once, as one SkFontMgr does in Skia: it is shared (through an Arc, say) rather than locked by its users. A manager that keeps state it changes while answering, such as the font files it has read, locks that state itself.

Required Methods§

Source

fn family(&self, family: &str) -> Vec<Typeface>

family returns every face the platform has under family; empty for a family it does not know. Names compare the way the platform compares them.

Source

fn match_character( &self, family: Option<&str>, style: Style, locales: &[&str], character: char, ) -> Option<Typeface>

match_character returns a face that covers character, Skia’s matchFamilyStyleCharacter: preferring the languages in locales (BCP 47, most preferred first), then family, then style. None when nothing installed covers it.

Source

fn system_font(&self, size: f32, style: Style) -> Option<Typeface>

system_font returns the platform’s own user-interface face for text at size (in points) nearest style: what a program means by “the system font”. None where the platform has no such notion.

Source

fn families(&self) -> Vec<String>

families lists the installed family names.

Source

fn face_count(&self) -> usize

face_count is how many installed faces the platform reports; 0 means the manager found nothing and every answer will be empty.

Source

fn watch(&self, on_change: Box<dyn Fn() + Sync + Send>) -> Option<Watch>

watch calls on_change whenever the installed fonts change, from whichever thread the platform reports on, for as long as the returned Watch lives. None where the platform cannot say.

Provided Methods§

Source

fn match_family_style(&self, family: &str, style: Style) -> Option<Typeface>

match_family_style returns the family’s face nearest style, Skia’s matchFamilyStyle.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<M> FontManager for Arc<M>
where M: FontManager + ?Sized,

A shared manager is a manager: one Arc of platform can answer several users, each holding a clone, wherever a FontManager is expected.

Source§

fn family(&self, family: &str) -> Vec<Typeface>

Source§

fn match_family_style(&self, family: &str, style: Style) -> Option<Typeface>

Source§

fn match_character( &self, family: Option<&str>, style: Style, locales: &[&str], character: char, ) -> Option<Typeface>

Source§

fn system_font(&self, size: f32, style: Style) -> Option<Typeface>

Source§

fn families(&self) -> Vec<String>

Source§

fn face_count(&self) -> usize

Source§

fn watch(&self, on_change: Box<dyn Fn() + Sync + Send>) -> Option<Watch>

Source§

impl<M> FontManager for Box<M>
where M: FontManager + ?Sized,

A boxed manager is a manager, as std makes a Box<W: Write + ?Sized> a writer: what platform answers can go wherever a FontManager is expected.

Source§

fn family(&self, family: &str) -> Vec<Typeface>

Source§

fn match_family_style(&self, family: &str, style: Style) -> Option<Typeface>

Source§

fn match_character( &self, family: Option<&str>, style: Style, locales: &[&str], character: char, ) -> Option<Typeface>

Source§

fn system_font(&self, size: f32, style: Style) -> Option<Typeface>

Source§

fn families(&self) -> Vec<String>

Source§

fn face_count(&self) -> usize

Source§

fn watch(&self, on_change: Box<dyn Fn() + Sync + Send>) -> Option<Watch>

Implementors§