pub struct EmbeddedFont {Show 14 fields
pub bytes: &'static [u8],
pub face: Face<'static>,
pub ttf: Face<'static>,
pub postscript_name: &'static str,
pub units_per_em: u16,
pub ascender: i16,
pub descender: i16,
pub cap_height: i16,
pub x_height: i16,
pub italic_angle: f32,
pub bbox: (i16, i16, i16, i16),
pub stem_v: i16,
pub flags: u32,
plan_cache: RwLock<HashMap<(Script, Option<Language>), Arc<ShapePlan>>>,
}Expand description
A bundled TrueType face: the raw bytes plus the metrics and
parsed rustybuzz::Face needed to shape text and emit a PDF
FontDescriptor.
Constructed internally from a &'static [u8] (the bundled
include_bytes!-loaded TTF). The crate’s user-facing surface is
the crate::EmbeddedFontId enum; this struct is the per-cut
data block those ids resolve through.
Fields§
§bytes: &'static [u8]Raw TTF bytes. Held statically so the parsed Face<'static>
can borrow them.
face: Face<'static>HarfBuzz/rustybuzz face. Borrows bytes.
ttf: Face<'static>Pre-parsed ttf-parser face. The PDF backend reads
FontDescriptor fields (italic angle, bbox, …) through this;
rustybuzz wraps it but doesn’t re-expose every getter.
postscript_name: &'static strPostScript name (from the name table, ID 6). Becomes the
/BaseFont entry’s suffix after the six-letter subset tag.
units_per_em: u16head.unitsPerEm. Typically 1000 (CFF) or a power of two for
TrueType outlines.
ascender: i16hhea.ascender (font units).
descender: i16hhea.descender (font units, typically negative).
cap_height: i16OS/2.sCapHeight if present, else ascender * 7 / 10 as a
PDF-conventional fallback.
x_height: i16OS/2.sxHeight if present, else ascender * 1 / 2 as a
fallback.
italic_angle: f32post.italicAngle in degrees. OpenType and PDF /ItalicAngle
share the same convention (counter-clockwise from vertical,
negative for italic slanted right per PDF 1.7 §9.8.2), so the
value passes through unchanged.
bbox: (i16, i16, i16, i16)head font bounding box (xMin, yMin, xMax, yMax). Becomes
FontDescriptor /FontBBox.
stem_v: i16Heuristic stem-vertical width for /StemV: 80 for regular,
120 for bold. ttf-parser doesn’t surface a reliable StemV;
most fonts don’t ship it in OS/2. PDF validators accept the
heuristic.
flags: u32PDF FontDescriptor /Flags. Nonsymbolic (bit 6, value 32) for
Latin/Cyrillic/Greek fonts; the italic bit (bit 7, value 64)
is OR’d in for italic cuts.
plan_cache: RwLock<HashMap<(Script, Option<Language>), Arc<ShapePlan>>>Compiled rustybuzz shape plans, keyed by the buffer’s
(script, language) after segment-property guessing. A plan is the
compiled GSUB/GPOS feature program for a
(face, script, language, LTR, no user features) tuple; it is
invariant across the thousands of per-run shaping calls, so building
it once per script (Latin dominates real text) replaces the plan
recompilation rustybuzz::shape does on every call — ~22% of build
time in profiling. RwLock because the font is shared &'static;
the hit path (the common case) only needs a read lock. Plans are
Arc-wrapped so the hit path can clone the handle out and release
the lock before shaping.
Implementations§
Source§impl EmbeddedFont
impl EmbeddedFont
Sourcepub(crate) fn from_static(
bytes: &'static [u8],
postscript_name: &'static str,
is_bold: bool,
is_italic: bool,
) -> Self
pub(crate) fn from_static( bytes: &'static [u8], postscript_name: &'static str, is_bold: bool, is_italic: bool, ) -> Self
Parse a bundled TTF blob into an EmbeddedFont. The blob
must outlive the program (which it does: bundled cuts come
from include_bytes! and are baked into the binary).
postscript_name, is_bold, and is_italic are provided by
the caller rather than read from the name table because the
bundled cuts are known statics and parse-time string ownership
would require allocating; the name table also ships
platform-specific encodings we don’t want to navigate.
§Panics
Panics if the bytes don’t parse as a TrueType font. The four
bundled cuts have been parse-verified at vendor time and are
re-verified by tests/parse_bundled.rs on every CI run, so
reaching this panic requires post-build corruption (e.g. a
failed LFS pull or a truncated binary). Threading
Result/Option through the dozens of downstream call sites
to handle a case the compile-time include_bytes! already
rules out would make the code materially worse; the lint
suppression is the explicit CLAUDE.md exception, paired with
the CI test that catches the only realistic failure mode.
Sourcepub fn glyph_index(&self, ch: char) -> Option<u16>
pub fn glyph_index(&self, ch: char) -> Option<u16>
Look up the GID for a Unicode codepoint, if the face covers it.
Used by the layout engine’s glyph_width shortcut when shaping
a single codepoint would be wasteful.
Sourcepub fn advance_units(&self, gid: u16) -> u16
pub fn advance_units(&self, gid: u16) -> u16
Horizontal advance for gid in font units, sourced from the
hmtx table.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for EmbeddedFont
impl RefUnwindSafe for EmbeddedFont
impl Send for EmbeddedFont
impl Sync for EmbeddedFont
impl Unpin for EmbeddedFont
impl UnsafeUnpin for EmbeddedFont
impl UnwindSafe for EmbeddedFont
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.