Skip to main content

FontCollectionBase

Struct FontCollectionBase 

Source
pub struct FontCollectionBase { /* private fields */ }
Expand description

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()).

Implementations§

Source§

impl FontCollectionBase

Source

pub fn new() -> Self

Creates the state of a font collection.

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

Source

pub fn glyph_typeface_cache(&self) -> &GlyphTypefaceCache

The cached glyph typefaces by family name.

Source

pub fn count(&self) -> usize

The number of font families in the collection.

Source

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

The font family at index.

Panics when index is out of range.

Source

pub fn font_families(&self) -> Vec<FontFamily>

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

Source

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

The base implementation of FontCollectionBaseImpl::try_match_character.

Source

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

Source

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

Source

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

Source

pub fn try_get_nearest_match( &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

pub 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

pub 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

pub 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

pub fn try_add_font_source(this: &dyn IFontCollectionBase, source: &Uri) -> 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

pub fn add_font_family(&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

pub 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

pub 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

pub 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

pub fn dispose(&self)

Disposes every cached glyph typeface.

Trait Implementations§

Source§

impl Default for FontCollectionBase

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.