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, with the weight, slant and width the file declares.

The face answers only to family, as FaceSet::register describes. 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.

Source

pub fn require_family(&mut self, name: &str) -> bool

require_family makes sure the family name has a face, asking the sources when none is registered.

The sources are asked in order and what they answer is registered (Skia’s findTypefaces walking its managers). It returns false when nobody had the family, and records the miss for Self::take_unanswered.

Source

pub fn require_codepoint( &mut self, families: &[String], codepoint: char, attrs: FontAttrs, ) -> bool

require_codepoint makes sure a face that families and attrs resolve to covers codepoint, asking the sources for a fallback face when none does.

It is the per-character half of Self::require_family (Skia’s defaultFallback(unicode, ..)): false means no source covered the character, and the miss is recorded for Self::take_unanswered.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>