pub struct FontRef<'a> { /* private fields */ }Expand description
Zero-copy reference over an SFNT font.
The reference borrows the whole byte buffer; table access is a lifetime- bound slice — nothing is copied, nothing is allocated. Views obtained from it (typed tables, outlines) die with the borrow.
Implementations§
Source§impl<'a> FontRef<'a>
impl<'a> FontRef<'a>
Sourcepub fn new(data: &'a [u8]) -> Result<Self, ParseError>
pub fn new(data: &'a [u8]) -> Result<Self, ParseError>
Parse and validate the SFNT offset table and every table-directory entry.
Accepts TrueType (0x00010000, 'true') and CFF-flavored ('OTTO')
fonts; for collections (‘ttcf’) use FontCollection.
§Errors
ParseError::InvalidSfnt for a bad signature or zero table count;
ParseError::TruncatedTable for a truncated directory or an entry
whose offset + length exceeds the buffer.
Sourcepub const fn sfnt_version(&self) -> u32
pub const fn sfnt_version(&self) -> u32
The sfntVersion field (0x00010000, 'OTTO', 'true').
Sourcepub fn is_variable(&self) -> bool
pub fn is_variable(&self) -> bool
True when the font declares variable-font tables (fvar).
Sourcepub const fn num_tables(&self) -> u16
pub const fn num_tables(&self) -> u16
Number of directory entries.
Sourcepub fn table(&self, tag: TableTag) -> Option<&'a [u8]>
pub fn table(&self, tag: TableTag) -> Option<&'a [u8]>
Raw bytes of a known table (None when absent).
Sourcepub fn table_by_tag(&self, tag: Tag) -> Option<&'a [u8]>
pub fn table_by_tag(&self, tag: Tag) -> Option<&'a [u8]>
Raw bytes of an arbitrary table by raw tag.
Sourcepub fn table_directory(&self) -> Vec<(RawTag, u32, u32, u32)>
pub fn table_directory(&self) -> Vec<(RawTag, u32, u32, u32)>
All directory entries as (tag, checksum, offset, length), in
directory order. Tags are raw four-byte values (known or not).
Sourcepub fn head(&self) -> Result<HeadTable<'a>, ParseError>
pub fn head(&self) -> Result<HeadTable<'a>, ParseError>
head — units per em, loca format, style flags.
§Errors
Missing table (ParseError::UnknownTableTag) or parse errors.
Sourcepub fn hhea(&self) -> Result<HheaTable<'a>, ParseError>
pub fn hhea(&self) -> Result<HheaTable<'a>, ParseError>
Sourcepub fn hmtx(&self) -> Result<HmtxTable<'a>, ParseError>
pub fn hmtx(&self) -> Result<HmtxTable<'a>, ParseError>
hmtx — advance widths and side bearings (wired to hhea + maxp).
§Errors
Missing tables or parse errors.
Sourcepub fn maxp(&self) -> Result<MaxpTable<'a>, ParseError>
pub fn maxp(&self) -> Result<MaxpTable<'a>, ParseError>
Sourcepub fn num_glyphs(&self) -> u16
pub fn num_glyphs(&self) -> u16
Glyph count (0 when maxp is absent or invalid).
Sourcepub fn cmap(&self) -> Result<Cmap<'a>, ParseError>
pub fn cmap(&self) -> Result<Cmap<'a>, ParseError>
Sourcepub fn name(&self) -> Result<NameTable<'a>, ParseError>
pub fn name(&self) -> Result<NameTable<'a>, ParseError>
Sourcepub fn os2(&self) -> Result<Os2Table<'a>, ParseError>
pub fn os2(&self) -> Result<Os2Table<'a>, ParseError>
Sourcepub fn post(&self) -> Result<PostTable<'a>, ParseError>
pub fn post(&self) -> Result<PostTable<'a>, ParseError>
Sourcepub fn stat(&self) -> Result<StatTable<'a>, ParseError>
pub fn stat(&self) -> Result<StatTable<'a>, ParseError>
Sourcepub fn dsig(&self) -> Result<DsigTable<'a>, ParseError>
pub fn dsig(&self) -> Result<DsigTable<'a>, ParseError>
Sourcepub fn layout(&self, kind: LayoutKind) -> Result<LayoutTable<'a>, ParseError>
pub fn layout(&self, kind: LayoutKind) -> Result<LayoutTable<'a>, ParseError>
GSUB/GPOS layout structure by kind.
§Errors
Missing table (ParseError::UnknownTableTag) or parse errors.
Sourcepub fn variable(&self) -> Result<VariableFont<'a>, ParseError>
pub fn variable(&self) -> Result<VariableFont<'a>, ParseError>
Sourcepub fn glyph_data(&self, gid: GlyphId) -> Result<Option<&'a [u8]>, ParseError>
pub fn glyph_data(&self, gid: GlyphId) -> Result<Option<&'a [u8]>, ParseError>
Byte range of glyph gid within glyf (None = empty glyph or an
id beyond numGlyphs).
§Errors
Missing glyf/loca tables or malformed loca entries.
Sourcepub fn glyph(&self, gid: GlyphId) -> Result<Option<GlyphRef<'a>>, ParseError>
pub fn glyph(&self, gid: GlyphId) -> Result<Option<GlyphRef<'a>>, ParseError>
Parse glyph gid (simple or composite view; None = empty).
§Errors
Missing tables or malformed glyph records.
Sourcepub fn advance_width(&self, gid: GlyphId) -> Result<u16, ParseError>
pub fn advance_width(&self, gid: GlyphId) -> Result<u16, ParseError>
Sourcepub fn outline(&self, gid: GlyphId) -> Result<Option<GlyphOutline>, ParseError>
pub fn outline(&self, gid: GlyphId) -> Result<Option<GlyphOutline>, ParseError>
Fully resolved outline for gid: composite components (with their
2x2 transforms and offsets) are applied recursively.
Returns None for empty glyphs or ids beyond numGlyphs. The result
is allocated (points in font units); table access stays zero-copy.
Point-matched composites (no ARGS_ARE_XY_VALUES) place components
at the origin — full point matching is a rendering concern and out of
scope for a parser.
§Errors
Malformed glyph records, or a composite nest that exceeds the depth
cap ([MAX_COMPONENT_DEPTH]) or the point budget
([MAX_OUTLINE_POINTS]).
Sourcepub fn gvar_deltas(
&self,
gid: GlyphId,
) -> Result<Vec<TupleVariation>, ParseError>
pub fn gvar_deltas( &self, gid: GlyphId, ) -> Result<Vec<TupleVariation>, ParseError>
Variable-font deltas for gid via gvar (empty vec when the font is
not variable or the glyph has no deltas). The glyph’s point count is
resolved from glyf automatically.
§Errors
Malformed gvar data.