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
impl FontCollectionBase
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates the state of a font collection.
Panics when no font manager backend (IFontManagerImpl) is registered
with the locator.
Sourcepub fn glyph_typeface_cache(&self) -> &GlyphTypefaceCache
pub fn glyph_typeface_cache(&self) -> &GlyphTypefaceCache
The cached glyph typefaces by family name.
Sourcepub fn get(&self, index: usize) -> FontFamily
pub fn get(&self, index: usize) -> FontFamily
The font family at index.
Panics when index is out of range.
Sourcepub fn font_families(&self) -> Vec<FontFamily>
pub fn font_families(&self) -> Vec<FontFamily>
A snapshot of the font families of the collection, sorted by name.
Sourcepub fn try_match_character(
this: &dyn IFontCollectionBase,
codepoint: i32,
style: FontStyle,
weight: FontWeight,
stretch: FontStretch,
family_name: Option<&str>,
culture: Option<&CultureInfo>,
) -> Option<Typeface>
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.
Sourcepub fn try_create_synthetic_glyph_typeface(
this: &dyn IFontCollectionBase,
glyph_typeface: &Rc<GlyphTypeface>,
style: FontStyle,
weight: FontWeight,
stretch: FontStretch,
) -> Option<Rc<GlyphTypeface>>
pub 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.
Sourcepub fn try_get_glyph_typeface(
this: &dyn IFontCollectionBase,
family_name: &str,
style: FontStyle,
weight: FontWeight,
stretch: FontStretch,
) -> Option<Rc<GlyphTypeface>>
pub 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.
Sourcepub fn try_get_family_typefaces(
this: &dyn IFontCollectionBase,
family_name: &str,
) -> Option<Vec<Typeface>>
pub fn try_get_family_typefaces( this: &dyn IFontCollectionBase, family_name: &str, ) -> Option<Vec<Typeface>>
The base implementation of
FontCollectionBaseImpl::try_get_family_typefaces.
Sourcepub fn try_get_nearest_match(
&self,
family_name: &str,
style: FontStyle,
weight: FontWeight,
stretch: FontStretch,
) -> Option<Rc<GlyphTypeface>>
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.
Sourcepub fn try_add_glyph_typeface(
this: &dyn IFontCollectionBase,
glyph_typeface: &Rc<GlyphTypeface>,
) -> bool
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.
Sourcepub fn try_add_glyph_typeface_with_key(
this: &dyn IFontCollectionBase,
glyph_typeface: &Rc<GlyphTypeface>,
key: FontCollectionKey,
) -> bool
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.
Sourcepub fn try_add_glyph_typeface_from_stream(
this: &dyn IFontCollectionBase,
stream: &mut dyn Read,
) -> Option<Rc<GlyphTypeface>>
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.
Sourcepub fn try_add_font_source(this: &dyn IFontCollectionBase, source: &Uri) -> bool
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.
Sourcepub fn add_font_family(&self, font_family: FontFamily)
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.
Sourcepub fn try_get_glyph_typeface_by_key(
this: &dyn IFontCollectionBase,
family_name: &str,
key: FontCollectionKey,
allow_nearest_match: bool,
) -> Option<Rc<GlyphTypeface>>
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).
Sourcepub fn try_get_nearest_match_in(
glyph_typefaces: &GlyphTypefaceMap,
key: FontCollectionKey,
) -> Option<Rc<GlyphTypeface>>
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.
Sourcepub fn try_add_glyph_typeface_by_name(
this: &dyn IFontCollectionBase,
family_name: &str,
key: FontCollectionKey,
glyph_typeface: Option<Rc<GlyphTypeface>>,
) -> bool
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.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for FontCollectionBase
impl !RefUnwindSafe for FontCollectionBase
impl !Send for FontCollectionBase
impl !Sync for FontCollectionBase
impl !UnwindSafe for FontCollectionBase
impl Unpin for FontCollectionBase
impl UnsafeUnpin for FontCollectionBase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more