pub struct FontCache { /* private fields */ }Implementations§
Source§impl FontCache
impl FontCache
pub fn from_bytes(bytes: &[u8]) -> Self
Sourcepub fn from_asset(name: impl AssetRef) -> Option<Self>
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);Sourcepub fn embedded() -> Self
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.
Sourcepub fn bundled() -> Self
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).
Sourcepub fn system_ui() -> Option<Self>
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).
Sourcepub fn system_mono() -> Option<Self>
pub fn system_mono() -> Option<Self>
Load a system monospace font (Menlo, Courier, DejaVu Mono, etc.).
Sourcepub fn set_icon_face(&self, font: Arc<OwnedFace>)
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.
Sourcepub fn has_icon_face(&self) -> bool
pub fn has_icon_face(&self) -> bool
True once an icon face is installed — lets callers skip re-registration on every paint.
Sourcepub fn glyph_weighted(
&self,
c: char,
px: f32,
weight: FontWeight,
) -> CachedGlyph
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.
Sourcepub fn glyph(&self, c: char, px: f32) -> CachedGlyph
pub fn glyph(&self, c: char, px: f32) -> CachedGlyph
Regular-weight glyph (hot path for plain text).
Sourcepub fn rasterize(&self, c: char, px: f32) -> (GlyphMetrics, Vec<u8>)
pub fn rasterize(&self, c: char, px: f32) -> (GlyphMetrics, Vec<u8>)
Rasterize a single character (copies the bitmap — prefer
FontCache::glyph in hot paths).
Sourcepub fn color_glyph_rgba(&self, c: char, px: f32) -> Option<Arc<ColorGlyph>>
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.
Sourcepub fn kern_weighted(
&self,
left: char,
right: char,
px: f32,
weight: FontWeight,
) -> f32
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.
pub fn kern(&self, left: char, right: char, px: f32) -> f32
Sourcepub fn advance_width_weighted(
&self,
c: char,
px: f32,
weight: FontWeight,
) -> f32
pub fn advance_width_weighted( &self, c: char, px: f32, weight: FontWeight, ) -> f32
Pixel advance width at px/weight. Cached, fallback-routed.
pub fn advance_width(&self, c: char, px: f32) -> f32
Sourcepub fn measure_text_weighted(
&self,
text: &str,
px: f32,
weight: FontWeight,
) -> f32
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.
pub fn measure_text(&self, text: &str, px: f32) -> f32
Sourcepub fn ascender(&self, px: f32) -> i32
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.
Sourcepub fn line_height(&self, px: f32) -> f32
pub fn line_height(&self, px: f32) -> f32
Full line height (ascender + descender + gap) in pixels.