Skip to main content

FontSource

Trait FontSource 

Source
pub trait FontSource {
    // Required methods
    fn family(&mut self, name: &str) -> Vec<Font>;
    fn face_for_codepoint(
        &mut self,
        codepoint: char,
        attrs: FontAttrs,
    ) -> Option<Font>;

    // Provided method
    fn default_face(&mut self, attrs: FontAttrs) -> Option<Font> { ... }
}
Expand description

FontSource locates fonts that are not already registered.

A source may consult installed fonts, downloaded assets, or another host-owned repository. FontCollection consults sources in registration order.

Required Methods§

Source

fn family(&mut self, name: &str) -> Vec<Font>

family returns every available face matching a family name.

Source

fn face_for_codepoint( &mut self, codepoint: char, attrs: FontAttrs, ) -> Option<Font>

face_for_codepoint returns a covering face nearest to attrs.

Provided Methods§

Source

fn default_face(&mut self, attrs: FontAttrs) -> Option<Font>

default_face returns the source’s default face nearest to attrs, the face text is set in when no family it asks for has one: Skia’s SkFontMgr::legacyMakeTypeface(nullptr, style). A collection asks for it only while it has no face at all.

The default answers None: a source without a default leaves an empty collection’s text to its character lookup, and what that misses to the collection’s demand, for a host that loads fonts asynchronously.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl FontSource for SystemFonts

Source§

fn family(&mut self, name: &str) -> Vec<Font>

Source§

fn face_for_codepoint( &mut self, codepoint: char, attrs: FontAttrs, ) -> Option<Font>

Implementors§