FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    FontCollectionBase

    struct · ferroui-base · v0.5.0

    struct FontCollectionBase
    

    The state and the shared matching, fallback and caching logic of font collections.

    Upstream this is an abstract class. Here a collection type holds a FontCollectionBase and implements FontCollectionBaseImpl (the abstract and virtual members); IFontCollection is then implemented for it automatically. Members of the base class that reach overridable members are associated functions taking the collection as this (FontCollectionBase::try_add_glyph_typeface(this, ..)); the others are methods of the state (collection.base().count()).

    View source

    Members

    new

    fn new() -> Self
    

    Creates the state of a font collection.

    Panics when no font manager backend (IFontManagerImpl) is registered with the locator.

    Source

    glyph_typeface_cache

    fn glyph_typeface_cache(self: &Self) -> &GlyphTypefaceCache
    

    The cached glyph typefaces by family name.

    Source

    count

    fn count(self: &Self) -> usize
    

    The number of font families in the collection.

    Source

    get

    fn get(self: &Self, index: usize) -> FontFamily
    

    The font family at index.

    Panics when index is out of range.

    Source

    font_families

    fn font_families(self: &Self) -> Vec<FontFamily>
    

    A snapshot of the font families of the collection, sorted by name.

    Source

    try_match_character

    fn try_match_character(this: &dyn IFontCollectionBase, codepoint: i32, style: FontStyle, weight: FontWeight, stretch: FontStretch, family_name: Option<&str>, culture: Option<&Locale>) -> Option<Typeface>
    

    The base implementation of FontCollectionBaseImpl::try_match_character.

    Source

    try_create_synthetic_glyph_typeface

    fn try_create_synthetic_glyph_typeface(this: &dyn IFontCollectionBase, glyph_typeface: &Rc<GlyphTypeface>, style: FontStyle, weight: FontWeight, stretch: FontStretch) -> Option<Rc<GlyphTypeface>>
    

    The base implementation of FontCollectionBaseImpl::try_create_synthetic_glyph_typeface.

    Source

    try_get_glyph_typeface

    fn try_get_glyph_typeface(this: &dyn IFontCollectionBase, family_name: &str, style: FontStyle, weight: FontWeight, stretch: FontStretch) -> Option<Rc<GlyphTypeface>>
    

    The base implementation of FontCollectionBaseImpl::try_get_glyph_typeface.

    Source

    try_get_family_typefaces

    fn try_get_family_typefaces(this: &dyn IFontCollectionBase, family_name: &str) -> Option<Vec<Typeface>>
    

    The base implementation of FontCollectionBaseImpl::try_get_family_typefaces.

    Source

    try_get_nearest_match

    fn try_get_nearest_match(self: &Self, family_name: &str, style: FontStyle, weight: FontWeight, stretch: FontStretch) -> Option<Rc<GlyphTypeface>>
    

    Attempts to retrieve the glyph typeface that most closely matches the specified font family name, style, weight, and stretch.

    Source

    try_add_glyph_typeface

    fn try_add_glyph_typeface(this: &dyn IFontCollectionBase, glyph_typeface: &Rc<GlyphTypeface>) -> bool
    

    Attempts to add the specified GlyphTypeface to the font collection.

    This method checks the family name and, if applicable, the typographic family name and other family names provided by the glyph typeface. If any of these names can be associated with the glyph typeface, the typeface is added to the collection. The method ensures that duplicate entries are not added.

    Returns true if the glyph typeface was successfully added to the collection; otherwise, false.

    Source

    try_add_glyph_typeface_with_key

    fn try_add_glyph_typeface_with_key(this: &dyn IFontCollectionBase, glyph_typeface: &Rc<GlyphTypeface>, key: FontCollectionKey) -> bool
    

    Attempts to add the specified glyph typeface to the collection using the provided key.

    The method adds the glyph typeface using both its typographic family name and all available family names. If the glyph typeface's family name is empty, the method returns false and does not add the typeface.

    Source

    try_add_glyph_typeface_from_stream

    fn try_add_glyph_typeface_from_stream(this: &dyn IFontCollectionBase, stream: &mut dyn Read) -> Option<Rc<GlyphTypeface>>
    

    Attempts to add a glyph typeface from the specified font stream.

    The method first attempts to create a glyph typeface from the provided font stream. If successful, it adds the created glyph typeface to the collection.

    Returns the created glyph typeface if it was created and added; otherwise, None.

    Source

    try_add_font_source

    fn try_add_font_source(this: &dyn IFontCollectionBase, source: &url::Url) -> bool
    

    Attempts to add a font source to the font collection.

    This method processes the specified font source and attempts to load all available fonts from it. Fonts are added to the collection based on their family name and typographic family name (if available).

    source can be a file: path (a font file or a directory of font files) or a resource URI (ferres:, resm:).

    Returns true if at least one font from the specified source was successfully added to the font collection; otherwise, false.

    Source

    add_font_family

    fn add_font_family(self: &Self, font_family: FontFamily)
    

    Inserts the specified font family into the collection, maintaining the collection in sorted order by font family name.

    If a font family with the same name (ignoring case) already exists in the collection, nothing is added.

    Source

    try_get_glyph_typeface_by_key

    fn try_get_glyph_typeface_by_key(this: &dyn IFontCollectionBase, family_name: &str, key: FontCollectionKey, allow_nearest_match: bool) -> Option<Rc<GlyphTypeface>>
    

    Attempts to retrieve a glyph typeface that matches the specified font family name and font collection key.

    This method performs a binary search to locate font families with names that match the specified family_name (ignoring case). If multiple matches are found, the method iterates over them to find the best match based on the provided key.

    allow_nearest_match tells whether to allow a nearest match (as opposed to only an exact match).

    Source

    try_get_nearest_match_in

    fn try_get_nearest_match_in(glyph_typefaces: &GlyphTypefaceMap, key: FontCollectionKey) -> Option<Rc<GlyphTypeface>>
    

    Attempts to retrieve the nearest matching GlyphTypeface for the specified font key from the provided collection of glyph typefaces.

    This method attempts to find the best match for the specified font key by considering various fallback strategies, such as normalizing the font style, stretch, and weight. If no suitable match is found, the method will return the first available glyph typeface from the collection, if any.

    Source

    try_add_glyph_typeface_by_name

    fn try_add_glyph_typeface_by_name(this: &dyn IFontCollectionBase, family_name: &str, key: FontCollectionKey, glyph_typeface: Option<Rc<GlyphTypeface>>) -> bool
    

    Attempts to add a glyph typeface to the cache for the specified font family and key.

    The font family is added to the collection, in sorted order, with the first glyph typeface cached for it.

    glyph_typeface can be None (the platform has no typeface for the key): the answer is cached so that the platform is not asked again, and the family is not added to the collection, which lists only families it has a typeface of.

    Returns true if the glyph typeface was successfully added to the cache or the same typeface is already cached for the key; otherwise, false.

    Source

    dispose

    fn dispose(self: &Self)
    

    Disposes every cached glyph typeface.

    Source

    Trait implementations

    • Send
    • Sync
    • Freeze
    • UnsafeUnpin
    • Unpin
    • UnwindSafe
    • RefUnwindSafe
    • ClassDefaults
    • Borrow<T>
    • BorrowMut<T>
    • Into<U>
    • From<T>
    • TryInto<U>
    • TryFrom<U>
    • Any
    • ErasedDestructor
    • IntoEither
    • Default

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.