pub struct FontRegistry { /* private fields */ }Expand description
A loaded font registry: the theme’s declared families materialised into
live fontdue::Font handles, indexed by family id / weight / style.
Implementations§
Source§impl FontRegistry
impl FontRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty registry. Use Self::insert / Self::set_fallbacks
to populate it, or Self::from_families to load a whole theme in
one go.
Sourcepub fn insert(
&mut self,
family: impl Into<String>,
weight: u16,
style: FontStyle,
font: Arc<Font>,
)
pub fn insert( &mut self, family: impl Into<String>, weight: u16, style: FontStyle, font: Arc<Font>, )
Register a single font source.
Sourcepub fn set_fallbacks(&mut self, family: impl Into<String>, chain: Vec<String>)
pub fn set_fallbacks(&mut self, family: impl Into<String>, chain: Vec<String>)
Set the fallback chain for a family.
Sourcepub fn resolve(
&self,
family: &str,
weight: u16,
style: FontStyle,
) -> Option<Arc<Font>>
pub fn resolve( &self, family: &str, weight: u16, style: FontStyle, ) -> Option<Arc<Font>>
Resolve a triple to a loaded [Font]. See the module docs for the
precedence order.
Sourcepub fn from_families(
families: &HashMap<String, FontFamilyDef>,
) -> Result<Self, FontLoadError>
pub fn from_families( families: &HashMap<String, FontFamilyDef>, ) -> Result<Self, FontLoadError>
Load every source declared in families into the registry.
families is keyed by family id (the string the theme JSON uses in
fonts.<id> and that super::FontRef::Named references). The
family’s name field is carried for human display only; lookups go
through the id.
Sourcepub fn from_families_lenient(families: &HashMap<String, FontFamilyDef>) -> Self
pub fn from_families_lenient(families: &HashMap<String, FontFamilyDef>) -> Self
Like Self::from_families but tolerant: sources that fail to load
are logged via eprintln! and skipped instead of aborting the whole
registry build. Intended for the runtime path where a missing TTF
on a user’s machine should degrade to “fall back to system font for
that weight” rather than crash the shell.
Returns a registry that may be partial — callers cannot assume any
specific weight is loaded, only that what COULD be loaded is
loaded. Font resolution’s fallback ladder (family → closest weight
→ fallback chain → Canvas::font) handles the gaps gracefully.
Trait Implementations§
Source§impl Debug for FontRegistry
impl Debug for FontRegistry
Source§impl Default for FontRegistry
impl Default for FontRegistry
Source§fn default() -> FontRegistry
fn default() -> FontRegistry
Auto Trait Implementations§
impl Freeze for FontRegistry
impl RefUnwindSafe for FontRegistry
impl Send for FontRegistry
impl Sync for FontRegistry
impl Unpin for FontRegistry
impl UnwindSafe for FontRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more