pub struct FontRegistry { /* private fields */ }Expand description
Font registry that discovers and caches system fonts
Implementations§
Source§impl FontRegistry
impl FontRegistry
Sourcepub fn new() -> FontRegistry
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.
Sourcepub fn load_font_data(&mut self, data: Vec<u8>) -> usize
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.
Sourcepub fn preload_fonts(&mut self, names: &[&str])
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.
Sourcepub fn load_font(&mut self, name: &str) -> Result<Arc<FontFace>, TextError>
pub fn load_font(&mut self, name: &str) -> Result<Arc<FontFace>, TextError>
Load a font by name (e.g., “Fira Code”, “Inter”, “Arial”)
Sourcepub fn load_font_with_style(
&mut self,
name: &str,
weight: u16,
italic: bool,
) -> Result<Arc<FontFace>, TextError>
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
Sourcepub fn load_generic(
&mut self,
generic: GenericFont,
) -> Result<Arc<FontFace>, TextError>
pub fn load_generic( &mut self, generic: GenericFont, ) -> Result<Arc<FontFace>, TextError>
Load a generic font category
Sourcepub fn load_generic_with_style(
&mut self,
generic: GenericFont,
weight: u16,
italic: bool,
) -> Result<Arc<FontFace>, TextError>
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
Sourcepub fn load_with_fallback(
&mut self,
name: Option<&str>,
generic: GenericFont,
) -> Result<Arc<FontFace>, TextError>
pub fn load_with_fallback( &mut self, name: Option<&str>, generic: GenericFont, ) -> Result<Arc<FontFace>, TextError>
Load a font with fallback to generic category
Sourcepub fn load_with_fallback_styled(
&mut self,
name: Option<&str>,
generic: GenericFont,
weight: u16,
italic: bool,
) -> Result<Arc<FontFace>, TextError>
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
Sourcepub fn get_cached(&self, name: &str) -> Option<Arc<FontFace>>
pub fn get_cached(&self, name: &str) -> Option<Arc<FontFace>>
Get cached font by name (doesn’t load - for use during render)
Sourcepub fn get_cached_with_style(
&self,
name: &str,
weight: u16,
italic: bool,
) -> Option<Arc<FontFace>>
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
Sourcepub fn get_cached_generic(&self, generic: GenericFont) -> Option<Arc<FontFace>>
pub fn get_cached_generic(&self, generic: GenericFont) -> Option<Arc<FontFace>>
Get cached generic font (doesn’t load - for use during render)
Sourcepub fn get_cached_generic_with_style(
&self,
generic: GenericFont,
weight: u16,
italic: bool,
) -> Option<Arc<FontFace>>
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
Sourcepub fn get_for_render(
&self,
name: Option<&str>,
generic: GenericFont,
) -> Option<Arc<FontFace>>
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
Sourcepub fn get_for_render_with_style(
&self,
name: Option<&str>,
generic: GenericFont,
weight: u16,
italic: bool,
) -> Option<Arc<FontFace>>
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
Sourcepub fn get_emoji_font(&self) -> Option<Arc<FontFace>>
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.
Sourcepub fn needs_emoji_font(c: char) -> bool
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.
Sourcepub fn list_families(&mut self) -> Vec<String>
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.
Sourcepub fn has_font(&mut self, name: &str) -> bool
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.
Sourcepub fn preload_font_family(&mut self, name: &str)
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.