Struct kas_text::fonts::FontLibrary

source ·
pub struct FontLibrary { /* private fields */ }
Expand description

Library of loaded fonts

This is the type of the global singleton accessible via the fonts function. Thread-safety is handled via internal locks.

Implementations§

Font management

Get a reference to the font database

Get mutable access to the font database

This can be used to adjust font selection. Note that any changes only affect new font selections, thus it is recommended only to adjust the database before any fonts have been selected. No existing FaceId or FontId will be affected by this; additionally any FontSelector which has already been selected will continue to resolve the existing FontId via the cache.

Get the first face for a font

Assumes that font_id is valid; if not the method will panic.

Each font identifier has at least one font face. This resolves the first (default) one.

Get the first face for a font

This is a wrapper around FontLibrary::first_face_for and FontLibrary::get_face.

Resolve the font face for a character

If last_face_id is a face used by font_id and this face covers c, then return last_face_id. (This is to avoid changing the font face unnecessarily, such as when encountering a space amid Arabic text.)

Otherwise, return the first face of font_id which covers c.

Otherwise (if no face covers c) return None.

Resolve the font face for a character

If last_face_id is a face used by font_id and this face covers c, then return last_face_id. (This is to avoid changing the font face unnecessarily, such as when encountering a space amid Arabic text.)

Otherwise, return the first face of font_id which covers c.

Otherwise (if no face covers c) return the first face for font_id.

Select the default font

If the font database has not yet been initialized, it is initialized.

If FontId(0) has not been defined yet, this sets the default font.

This must be called (at least once) before any other font selection method, and before querying any font-derived properties (such as text dimensions).

Select a font

This method uses internal caching to enable fast look-ups of existing (loaded) fonts. Resolving new fonts may be slower.

Face management

Get a font face from its identifier

Panics if id is not valid (required: id.get() < self.num_faces()).

Get the number of loaded font faces

FaceId values are indices assigned consecutively and are permanent. For any x < self.num_faces(), FaceId(x) is a valid font face identifier.

This value may increase as fonts may be loaded on demand. It will not decrease since fonts are never unloaded during program execution.

Access loaded font face data

Load a font by path

In case the (path, index) combination has already been loaded, the existing font object’s FontId will be returned.

The index is used to select fonts from a font-collection. If the font is not a collection, use 0.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Cast from Self to T Read more
Try converting from Self to T Read more
Try approximate conversion from Self to T Read more
Cast approximately from Self to T Read more
Cast to integer, truncating Read more
Cast to the nearest integer Read more
Cast the floor to an integer Read more
Cast the ceiling to an integer Read more
Try converting to integer with truncation Read more
Try converting to the nearest integer Read more
Try converting the floor to an integer Read more
Try convert the ceiling to an integer Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.