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 using default attributes.
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.