Struct FontDb

Source
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

Source

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);
Source

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);
Source

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());
Source

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());

Trait Implementations§

Source§

impl Clone for FontDb

Source§

fn clone(&self) -> FontDb

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for FontDb

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for FontDb

§

impl !RefUnwindSafe for FontDb

§

impl Send for FontDb

§

impl Sync for FontDb

§

impl Unpin for FontDb

§

impl !UnwindSafe for FontDb

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<T> ErasedDestructor for T
where T: 'static,