# IFontCollection

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/media/fonts/trait-ifontcollection/

**trait** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
trait IFontCollection: 'static
```

Represents a collection of font families and provides methods for
retrieving font-related information, such as glyph typefaces and fallback
characters.

The collection is a read-only list of [`FontFamily`](/docs/0.5.0/api/ferroui-base/media/struct-fontfamily/) (`count`, `get`,
`font_families`). Handles are `Rc<dyn IFontCollection>`.

A custom collection either implements this trait directly, or implements
`FontCollectionBaseImpl` to
reuse the matching, fallback and caching logic of
`FontCollectionBase` (this
trait is then implemented automatically).





[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L24)

## Members

- [`key`](#function-key)
- [`count`](#function-count)
- [`get`](#function-get)
- [`font_families`](#function-font_families)
- [`try_get_glyph_typeface`](#function-try_get_glyph_typeface)
- [`try_match_character`](#function-try_match_character)
- [`try_get_family_typefaces`](#function-try_get_family_typefaces)
- [`try_create_synthetic_glyph_typeface`](#function-try_create_synthetic_glyph_typeface)
- [`try_get_nearest_match`](#function-try_get_nearest_match)
- [`dispose`](#function-dispose)
- [`as_font_collection_base`](#function-as_font_collection_base)
- [`as_any`](#function-as_any)

<a id="function-key"></a>

### key

```rust
fn key(self: &Self) -> url::Url
```

Gets the unique identifier for the font collection: a URL of the
`fonts:` scheme for a collection added to the font manager
(`fonts:SystemFonts`, `fonts:Inter`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L28)

<a id="function-count"></a>

### count

```rust
fn count(self: &Self) -> usize
```

The number of font families in the collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L31)

<a id="function-get"></a>

### get

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

The font family at `index`.

Panics when `index` is out of range.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L36)

<a id="function-font_families"></a>

### font_families

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

A snapshot of the font families of the collection, in order.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L39)

<a id="function-try_get_glyph_typeface"></a>

### try_get_glyph_typeface

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

Try to get a glyph typeface for given parameters.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L42)

<a id="function-try_match_character"></a>

### try_match_character

```rust
fn try_match_character(self: &Self, codepoint: i32, font_style: FontStyle, font_weight: FontWeight, font_stretch: FontStretch, family_name: Option<&str>, culture: Option<&Locale>) -> Option<Typeface>
```

Tries to match a specified character to a `Typeface` that supports
specified font properties.

`family_name` is optional and used for fallback lookup.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L54)

<a id="function-try_get_family_typefaces"></a>

### try_get_family_typefaces

```rust
fn try_get_family_typefaces(self: &Self, family_name: &str) -> Option<Vec<Typeface>>
```

Tries to get a list of typefaces for the specified family name.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L65)

<a id="function-try_create_synthetic_glyph_typeface"></a>

### try_create_synthetic_glyph_typeface

```rust
fn try_create_synthetic_glyph_typeface(self: &Self, glyph_typeface: &Rc<GlyphTypeface>, style: FontStyle, weight: FontWeight, stretch: FontStretch) -> Option<Rc<GlyphTypeface>>
```

Try to get a synthetic glyph typeface for given parameters.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L68)

<a id="function-try_get_nearest_match"></a>

### try_get_nearest_match

```rust
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.

This method searches for a glyph typeface in the font collection cache
that matches the specified parameters. If an exact match is not found,
fallback mechanisms are applied to find the closest match based on the
specified style, weight, and stretch. If no suitable match is found,
`None` is returned.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L84)

<a id="function-dispose"></a>

### dispose

```rust
fn dispose(self: &Self)
```

Releases the glyph typefaces held by the collection (C# `IDisposable.Dispose`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L93)

<a id="function-as_font_collection_base"></a>

### as_font_collection_base

```rust
fn as_font_collection_base(self: &Self) -> Option<&dyn IFontCollectionBase>
```

The collection viewed as a `FontCollectionBase` derived collection, if
it is one (C# `collection is FontCollectionBase`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L97)

<a id="function-as_any"></a>

### as_any

```rust
fn as_any(self: &Self) -> &dyn Any
```

Lets callers recover the concrete collection type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/fonts/i_font_collection.rs#L102)

## Trait implementations

- [`IFontCollection`](/docs/0.5.0/api/ferroui-base/media/fonts/trait-ifontcollection/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
