Skip to main content

FontRegistry

Struct FontRegistry 

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

Font registry that discovers and caches system fonts

Implementations§

Source§

impl FontRegistry

Source

pub fn new() -> FontRegistry

Create a new font registry with lazy loading

Only loads known essential system fonts by path. Full system font scan is deferred until needed.

Source

pub fn load_font_data(&mut self, data: Vec<u8>) -> usize

Load a font from raw data (e.g., embedded or bundled fonts)

This is useful for loading fonts that aren’t in the standard system paths, such as app-bundled fonts or fonts loaded via CoreText on iOS.

Returns the number of font faces loaded from the data.

Source

pub fn preload_fonts(&mut self, names: &[&str])

Preload specific fonts by name with all available variants (call at startup for fonts your app uses)

This discovers and loads all variants (bold, italic, etc.) of each font. Note: This may trigger a full system font scan if the font isn’t found in the known fonts.

Source

pub fn load_font(&mut self, name: &str) -> Result<Arc<FontFace>, TextError>

Load a font by name (e.g., “Fira Code”, “Inter”, “Arial”)

Source

pub fn load_font_with_style( &mut self, name: &str, weight: u16, italic: bool, ) -> Result<Arc<FontFace>, TextError>

Load a font by name with specific weight and italic style

§Arguments
  • name - Font family name (e.g., “Fira Code”, “Inter”)
  • weight - Font weight (100-900, where 400 is normal, 700 is bold)
  • italic - Whether to load italic variant
Source

pub fn load_generic( &mut self, generic: GenericFont, ) -> Result<Arc<FontFace>, TextError>

Load a generic font category

Source

pub fn load_generic_with_style( &mut self, generic: GenericFont, weight: u16, italic: bool, ) -> Result<Arc<FontFace>, TextError>

Load a generic font category with specific weight and italic style

§Arguments
  • generic - Generic font category (System, Monospace, Serif, SansSerif)
  • weight - Font weight (100-900, where 400 is normal, 700 is bold)
  • italic - Whether to load italic variant
Source

pub fn load_with_fallback( &mut self, name: Option<&str>, generic: GenericFont, ) -> Result<Arc<FontFace>, TextError>

Load a font with fallback to generic category

Source

pub fn load_with_fallback_styled( &mut self, name: Option<&str>, generic: GenericFont, weight: u16, italic: bool, ) -> Result<Arc<FontFace>, TextError>

Load a font with fallback to generic category, with specific weight and style

Source

pub fn get_cached(&self, name: &str) -> Option<Arc<FontFace>>

Get cached font by name (doesn’t load - for use during render)

Source

pub fn get_cached_with_style( &self, name: &str, weight: u16, italic: bool, ) -> Option<Arc<FontFace>>

Get cached font by name with specific weight and style

Source

pub fn get_cached_generic(&self, generic: GenericFont) -> Option<Arc<FontFace>>

Get cached generic font (doesn’t load - for use during render)

Source

pub fn get_cached_generic_with_style( &self, generic: GenericFont, weight: u16, italic: bool, ) -> Option<Arc<FontFace>>

Get cached generic font with specific weight and style

Source

pub fn get_for_render( &self, name: Option<&str>, generic: GenericFont, ) -> Option<Arc<FontFace>>

Fast font lookup for rendering - only uses cache, never loads Returns the requested font if cached, or None if loading is needed

Source

pub fn get_for_render_with_style( &self, name: Option<&str>, generic: GenericFont, weight: u16, italic: bool, ) -> Option<Arc<FontFace>>

Fast font lookup for rendering with specific weight and style

Source

pub fn get_emoji_font(&self) -> Option<Arc<FontFace>>

Get the emoji font if available (cached)

Returns the cached emoji font if it was successfully loaded during initialization, or None if no emoji font is available.

Source

pub fn needs_emoji_font(c: char) -> bool

Check if a character needs an emoji font

Returns true for emoji characters that typically need a color emoji font.

Source

pub fn list_families(&mut self) -> Vec<String>

List available font families on the system

Note: This triggers a full system font scan if not already done.

Source

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

Check if a font is available

Note: This may trigger a full system font scan if the font isn’t found in the initially loaded fonts.

Source

pub fn preload_font_family(&mut self, name: &str)

Preload all variants (weights and styles) of a font family

This discovers all available variants of the font using fontdb and loads each one into the cache.

Trait Implementations§

Source§

impl Default for FontRegistry

Source§

fn default() -> FontRegistry

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> 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> Upcast<T> for T

Source§

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,