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§

source§

impl FontLibrary

Font management

source

pub fn read_db(&self) -> RwLockReadGuard<'_, Database>

Get a reference to the font database

source

pub fn update_db<F, T>(&self, f: F) -> T
where F: FnOnce(&mut Database) -> T,

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.

source

pub fn first_face_for(&self, font_id: FontId) -> Result<FaceId, InvalidFontId>

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.

source

pub fn get_first_face(&self, font_id: FontId) -> Result<FaceRef, InvalidFontId>

Get the first face for a font

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

source

pub fn face_for_char( &self, font_id: FontId, last_face_id: Option<FaceId>, c: char ) -> Result<Option<FaceId>, InvalidFontId>

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.

source

pub fn face_for_char_or_first( &self, font_id: FontId, last_face_id: Option<FaceId>, c: char ) -> Result<FaceId, InvalidFontId>

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.

source

pub fn select_default(&self) -> Result<(), Box<dyn Error>>

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

source

pub fn select_font( &self, selector: &FontSelector<'_> ) -> Result<FontId, Box<dyn Error>>

Select a font

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

source§

impl FontLibrary

Face management

source

pub fn get_face(&self, id: FaceId) -> FaceRef

Get a font face from its identifier

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

source

pub fn num_faces(&self) -> usize

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.

source

pub fn face_data<'a>(&'a self) -> FaceData<'a>

Access loaded font face data

source

pub fn load_path( &self, path: &Path, index: u32 ) -> Result<FaceId, Box<dyn Error>>

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§

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<S, T> Cast<T> for S
where T: Conv<S>,

source§

fn cast(self) -> T

Cast from Self to T Read more
source§

fn try_cast(self) -> Result<T, Error>

Try converting from Self to T Read more
source§

impl<S, T> CastApprox<T> for S
where T: ConvApprox<S>,

source§

fn try_cast_approx(self) -> Result<T, Error>

Try approximate conversion from Self to T Read more
source§

fn cast_approx(self) -> T

Cast approximately from Self to T Read more
source§

impl<S, T> CastFloat<T> for S
where T: ConvFloat<S>,

source§

fn cast_trunc(self) -> T

Cast to integer, truncating Read more
source§

fn cast_nearest(self) -> T

Cast to the nearest integer Read more
source§

fn cast_floor(self) -> T

Cast the floor to an integer Read more
source§

fn cast_ceil(self) -> T

Cast the ceiling to an integer Read more
source§

fn try_cast_trunc(self) -> Result<T, Error>

Try converting to integer with truncation Read more
source§

fn try_cast_nearest(self) -> Result<T, Error>

Try converting to the nearest integer Read more
source§

fn try_cast_floor(self) -> Result<T, Error>

Try converting the floor to an integer Read more
source§

fn try_cast_ceil(self) -> Result<T, Error>

Try convert the ceiling to an integer Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more