Skip to main content

FontCache

Struct FontCache 

Source
pub struct FontCache { /* private fields */ }

Implementations§

Source§

impl FontCache

Source

pub fn from_bytes(bytes: &[u8]) -> Self

Source

pub fn from_asset(name: impl AssetRef) -> Option<Self>

Load a font from a bundled asset by logical name — resolved per-platform via rosace_core::asset (dev: assets/<name>; mobile: the app bundle). Returns None if the asset is missing or not a valid font, so callers can fall back to default/[embedded].

let brand = FontCache::from_asset("fonts/Brand.ttf")
    .unwrap_or_else(FontCache::default);
Source

pub fn embedded() -> Self

A fallback font compiled into the binary — DejaVu Sans (permissive Bitstream Vera license). Used when no system font is available, most importantly on the web/wasm target where system_ui() finds nothing. Guarantees text always renders on every platform.

Source

pub fn bundled() -> Self

The DEFAULT app font (Phase 32, user-decided): bundled Inter (SIL OFL — this crate’s own assets/fonts/inter/LICENSE-OFL.txt), the same pleasant, screen-tuned face on EVERY platform with clearly differentiable weights — Regular for body, real Bold (700) for emphasis. Replaces “whatever the OS ships” as the default (system_ui() remains available as an opt-in); also replaces the short-lived Medium-by-default experiment, which read slightly bold.

Italic faces (Inter-Italic/Inter-BoldItalic) are bundled alongside but not yet wired — the text pipeline has no italic axis yet (tracked in PHASE_32.md).

Source

pub fn system_ui() -> Option<Self>

Load a system proportional / UI font plus (when available) a real bold face and the Unicode fallback chain. Prefers a same-family bold face found inside the regular candidate’s own file (see Self::weight_score); only falls back to the unrelated BOLD_PATHS standalone files when the chosen family has no bold member of its own (e.g. plain Arial.ttf, which IS the regular face and needs the separate Arial Bold.ttf).

Source

pub fn system_mono() -> Option<Self>

Load a system monospace font (Menlo, Courier, DejaVu Mono, etc.).

Source

pub fn set_icon_face(&self, font: Arc<OwnedFace>)

Install an in-memory icon face — glyphs the primary faces miss route to it before the disk fallback chain, so icon-font codepoints (PUA) flow through the ordinary text path: physical-px rasterization, glyph cache, and the GPU glyph atlas, with zero new draw commands.

Idempotent: the first registration wins; later calls are no-ops. Registration clears the route cache so codepoints resolved earlier (as tofu) re-route to the new face.

Source

pub fn has_icon_face(&self) -> bool

True once an icon face is installed — lets callers skip re-registration on every paint.

Source

pub fn glyph_weighted( &self, c: char, px: f32, weight: FontWeight, ) -> CachedGlyph

Shared handle to the cached glyph for c at px/weight — routed through the bold face and Unicode fallbacks.

Source

pub fn glyph(&self, c: char, px: f32) -> CachedGlyph

Regular-weight glyph (hot path for plain text).

Source

pub fn rasterize(&self, c: char, px: f32) -> (GlyphMetrics, Vec<u8>)

Rasterize a single character (copies the bitmap — prefer FontCache::glyph in hot paths).

Source

pub fn color_glyph_rgba(&self, c: char, px: f32) -> Option<Arc<ColorGlyph>>

Real color glyph for c at px, if c is in an emoji range AND the emoji fallback face actually has a color bitmap for it (sbix only today — see EMOJI_FALLBACK_PATHS’s doc for the Windows/Linux gap). None for anything else, including a plain character that happens to fail this lookup — callers fall through to the normal outline path.

Source

pub fn kern_weighted( &self, left: char, right: char, px: f32, weight: FontWeight, ) -> f32

Kerning between left and right at px/weight. Zero when the pair spans different faces (fallback boundaries have no kern data), or when the face has no kern table. Reads the kern table directly via ttf_parser (already a dependency here for name-table/ collection-index introspection) — swash’s own shaping module targets full GPOS-based complex-script shaping, a bigger API than the simple pairwise advance this UI-text layout model needs.

Source

pub fn kern(&self, left: char, right: char, px: f32) -> f32

Source

pub fn advance_width_weighted( &self, c: char, px: f32, weight: FontWeight, ) -> f32

Pixel advance width at px/weight. Cached, fallback-routed.

Source

pub fn advance_width(&self, c: char, px: f32) -> f32

Source

pub fn measure_text_weighted( &self, text: &str, px: f32, weight: FontWeight, ) -> f32

Total pixel width of a string at px/weight — advances plus kerning, in lockstep with SkiaCanvas::draw_text_weighted so measured and painted widths agree.

Source

pub fn measure_text(&self, text: &str, px: f32) -> f32

Source

pub fn ascender(&self, px: f32) -> i32

Distance from the top of the line box to the baseline, in pixels. Always from the primary face — mixed-face runs share one baseline.

Source

pub fn line_height(&self, px: f32) -> f32

Full line height (ascender + descender + gap) in pixels.

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.