Trait font_kit::source::Source

source ·
pub trait Source: Any {
    // Required methods
    fn all_fonts(&self) -> Result<Vec<Handle>, SelectionError>;
    fn all_families(&self) -> Result<Vec<String>, SelectionError>;
    fn select_family_by_name(
        &self,
        family_name: &str,
    ) -> Result<FamilyHandle, SelectionError>;
    fn as_any(&self) -> &dyn Any;
    fn as_mut_any(&mut self) -> &mut dyn Any;

    // Provided methods
    fn select_by_postscript_name(
        &self,
        postscript_name: &str,
    ) -> Result<Handle, SelectionError> { ... }
    fn select_best_match(
        &self,
        family_names: &[FamilyName],
        properties: &Properties,
    ) -> Result<Handle, SelectionError> { ... }
}
Expand description

A database of installed fonts that can be queried.

This trait is object-safe.

Required Methods§

source

fn all_fonts(&self) -> Result<Vec<Handle>, SelectionError>

Returns paths of all fonts installed on the system.

source

fn all_families(&self) -> Result<Vec<String>, SelectionError>

Returns the names of all families installed on the system.

source

fn select_family_by_name( &self, family_name: &str, ) -> Result<FamilyHandle, SelectionError>

Looks up a font family by name and returns the handles of all the fonts in that family.

source

fn as_any(&self) -> &dyn Any

Accesses this Source as Any, which allows downcasting back to a concrete type from a trait object.

source

fn as_mut_any(&mut self) -> &mut dyn Any

Accesses this Source as Any, which allows downcasting back to a concrete type from a trait object.

Provided Methods§

source

fn select_by_postscript_name( &self, postscript_name: &str, ) -> Result<Handle, SelectionError>

Selects a font by PostScript name, which should be a unique identifier.

The default implementation, which is used by the DirectWrite and the filesystem backends, does a brute-force search of installed fonts to find the one that matches.

source

fn select_best_match( &self, family_names: &[FamilyName], properties: &Properties, ) -> Result<Handle, SelectionError>

Performs font matching according to the CSS Fonts Level 3 specification and returns the handle.

Implementors§