Skip to main content

BytesFontProvider

Struct BytesFontProvider 

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

In-memory font registry. Register bundled and project fonts up front; this implementation never scans the system.

Two BTreeMaps are maintained:

  • by_key: (family_lower, weight, style) -> FontData for resolve.
  • by_id: id -> FontData for by_id.

Implementations§

Source§

impl BytesFontProvider

Source

pub fn new() -> Self

Create an empty registry.

Source

pub fn register( &mut self, family: &str, weight: u16, style: FontStyle, bytes: Arc<[u8]>, index: u32, source: FontSource, ) -> String

Register a font face and return its stable id.

The id is computed as "{family_kebab_lower}-{weight}-{style_lower}", e.g. "noto-sans-400-normal". If the same face is registered more than once, the most recent registration wins and reuses the original id. Because kebab-casing can collapse distinct families (e.g. "My Font" and "my-font") onto the same base id, a numeric suffix is appended when the base id is already taken by a different face, so every registered face keeps a unique id. Returns the assigned stable id as a convenience; callers may register purely for the side effect.

source records the provenance of the face (FontSource); it is carried on the resolved FontData so the compile stage can emit a font.local advisory when a face resolves from the local system.

Source

pub fn available_families(&self) -> Vec<String>

Return the lowercase family names of all registered faces (deduplicated, sorted).

Trait Implementations§

Source§

impl Debug for BytesFontProvider

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BytesFontProvider

Source§

fn default() -> Self

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

impl FontProvider for BytesFontProvider

Source§

fn resolve( &self, families: &[String], weight: u16, style: FontStyle, ) -> Option<FontData>

Resolve by a priority-ordered family list, weight, and style. Read more
Source§

fn by_id(&self, id: &str) -> Option<FontData>

Resolve by the stable id recorded on a shaped run.
Source§

fn all_faces(&self) -> Vec<FontData>

All registered faces, in a deterministic order (for building an SVG fontdb, etc.).

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> 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, 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.