pub struct FontDb { /* private fields */ }Expand description
Font database via fontique: bundled assets + system fonts for Parley layout.
The database owns its discovery collection and mutable source cache. Clones
have cloneable Fontique state but are otherwise independent values. System
font contents and ordering are platform-dependent; the bundled monospace
face is registered first to provide a deterministic candidate for
[FontId::Mono].
§Examples
use ailloli_ui_core::FontId;
use ailloli_ui_text::FontDb;
let db = FontDb::new();
assert_eq!(db.families_for(FontId::Ui).len(), 1);
assert!(db.families_for(FontId::Mono).len() >= 1);Implementations§
Source§impl FontDb
impl FontDb
Sourcepub fn new() -> Self
pub fn new() -> Self
Builds a database with system discovery and bundled fonts enabled.
Construction registers JetBrains Mono Nerd Font, scans the platform’s
font sources through Fontique, and optionally scans the relative
assets/fonts directory. Invalid optional paths are ignored. System
discovery may perform filesystem I/O and its results vary by platform.
§Examples
use ailloli_ui_core::FontId;
use ailloli_ui_text::FontDb;
let db = FontDb::new();
assert!(db.families_for(FontId::Mono).len() >= 1);Sourcepub fn families_for(&self, font_id: FontId) -> Vec<QueryFamily<'static>>
pub fn families_for(&self, font_id: FontId) -> Vec<QueryFamily<'static>>
Returns the ordered query families for an Ailloli font slot.
[FontId::Ui] returns only generic sans-serif. [FontId::Mono] returns
the bundled family first when registration succeeded, then generic
monospace. The newly allocated vector is suitable for Self::query_first.
§Examples
use ailloli_ui_core::FontId;
use ailloli_ui_text::FontDb;
let db = FontDb::new();
assert_eq!(db.families_for(FontId::Ui).len(), 1);
assert!(db.families_for(FontId::Mono).len() >= 1);Sourcepub fn resolve_first(
&mut self,
font_id: FontId,
attrs: Attributes,
) -> Option<QueryFont>
pub fn resolve_first( &mut self, font_id: FontId, attrs: Attributes, ) -> Option<QueryFont>
Returns the first matching QueryFont for the requested style.
Matching uses the ordered families from Self::families_for, the
supplied weight/stretch/style attributes, and a Latin-script fallback.
It stops after the first result. None means Fontique found no candidate;
system-font availability makes that outcome platform-dependent for UI.
The mutable borrow updates Fontique’s source cache.
§Examples
use ailloli_ui_core::FontId;
use ailloli_ui_text::FontDb;
use fontique::Attributes;
let mut db = FontDb::new();
assert!(db.resolve_first(FontId::Mono, Attributes::default()).is_some());Sourcepub fn query_first(
&mut self,
families: &[QueryFamily<'static>],
attrs: Attributes,
) -> Option<QueryFont>
pub fn query_first( &mut self, families: &[QueryFamily<'static>], attrs: Attributes, ) -> Option<QueryFont>
Returns the first Fontique match for explicit ordered families.
The query always installs a Latin (Latn) fallback key and stops after
its first callback. An empty or unmatched family slice may still resolve
through fallback; callers must treat None as a normal miss. The result
borrows no data from self.
§Examples
use ailloli_ui_core::FontId;
use ailloli_ui_text::FontDb;
use fontique::Attributes;
let mut db = FontDb::new();
let families = db.families_for(FontId::Mono);
assert!(db.query_first(&families, Attributes::default()).is_some());