Skip to main content

FontCollection

Struct FontCollection 

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

FontCollection owns registered faces and sources for resolving missing fonts.

Paragraph building consults sources in order and registers their answers. Unanswered requests accumulate until Self::take_unanswered is called.

Implementations§

Source§

impl FontCollection

Source

pub fn new() -> FontCollection

new creates an empty collection with no font sources.

Source

pub fn faces(&self) -> &FaceSet

faces returns the faces currently registered in the collection.

A built paragraph clones this set and remains independent of later changes.

Source

pub fn register(&mut self, family: &str, bytes: Vec<u8>) -> Option<FontId>

register adds font bytes under a family using default attributes.

It returns None when face zero cannot be parsed.

Source

pub fn add(&mut self, font: Font) -> FontId

add registers an already parsed font.

Source

pub fn add_fallback(&mut self, id: FontId)

add_fallback appends a registered font to the global fallback order.

id must belong to this collection.

Source

pub fn get(&self, id: FontId) -> &Font

get returns a registered font by identifier.

§Panics

Panics if id does not belong to this collection.

Source

pub fn len(&self) -> usize

len returns the number of registered fonts.

Source

pub fn family(&self, name: &str) -> Option<FontId>

family returns the first font matching a family name or alias.

Source

pub fn add_source(&mut self, source: impl FontSource + 'static)

add_source appends a source consulted when registered fonts cannot satisfy a request.

Source

pub fn add_boxed_source(&mut self, source: Box<dyn FontSource>)

add_boxed_source appends an already boxed font source.

Source

pub fn is_empty(&self) -> bool

is_empty reports whether no fonts are currently registered.

Source

pub fn adopt_faces(&mut self, faces: FaceSet)

adopt_faces replaces the registered faces with a prepared set.

This supports hosts that answer FontDemand using FaceSet::grown_by.

Source

pub fn take_unanswered(&mut self) -> FontDemand

take_unanswered drains font requests that no source could satisfy.

Hosts may load and Self::register matching fonts before rebuilding affected paragraphs.

Trait Implementations§

Source§

impl Default for FontCollection

Source§

fn default() -> FontCollection

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> 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 = 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>,

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.