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
impl FontCollection
Sourcepub fn new() -> FontCollection
pub fn new() -> FontCollection
new creates an empty collection with no font sources.
Sourcepub fn faces(&self) -> &FaceSet
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.
Sourcepub fn register(&mut self, family: &str, bytes: Vec<u8>) -> Option<FontId>
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.
Sourcepub fn add_fallback(&mut self, id: FontId)
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.
Sourcepub fn get(&self, id: FontId) -> &Font
pub fn get(&self, id: FontId) -> &Font
get returns a registered font by identifier.
§Panics
Panics if id does not belong to this collection.
Sourcepub fn family(&self, name: &str) -> Option<FontId>
pub fn family(&self, name: &str) -> Option<FontId>
family returns the first font matching a family name or alias.
Sourcepub fn add_source(&mut self, source: impl FontSource + 'static)
pub fn add_source(&mut self, source: impl FontSource + 'static)
add_source appends a source consulted when registered fonts cannot satisfy a request.
Sourcepub fn add_boxed_source(&mut self, source: Box<dyn FontSource>)
pub fn add_boxed_source(&mut self, source: Box<dyn FontSource>)
add_boxed_source appends an already boxed font source.
Sourcepub fn adopt_faces(&mut self, faces: FaceSet)
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.
Sourcepub fn take_unanswered(&mut self) -> FontDemand
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.
Sourcepub fn require_family(&mut self, name: &str) -> bool
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.
Sourcepub fn require_codepoint(
&mut self,
families: &[String],
codepoint: char,
attrs: FontAttrs,
) -> bool
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.