Skip to main content

FontRef

Struct FontRef 

Source
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>

Source

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.

Source

pub fn as_bytes(&self) -> &'a [u8] ⓘ

The whole borrowed buffer.

Source

pub const fn sfnt_version(&self) -> u32

The sfntVersion field (0x00010000, 'OTTO', 'true').

Source

pub const fn is_cff(&self) -> bool

True for CFF-outline (‘OTTO’) fonts — glyf/loca are absent.

Source

pub fn is_variable(&self) -> bool

True when the font declares variable-font tables (fvar).

Source

pub const fn num_tables(&self) -> u16

Number of directory entries.

Source

pub fn table(&self, tag: TableTag) -> Option<&'a [u8]>

Raw bytes of a known table (None when absent).

Source

pub fn table_by_tag(&self, tag: Tag) -> Option<&'a [u8]>

Raw bytes of an arbitrary table by raw tag.

Source

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

Source

pub fn head(&self) -> Result<HeadTable<'a>, ParseError>

head — units per em, loca format, style flags.

§Errors

Missing table (ParseError::UnknownTableTag) or parse errors.

Source

pub fn hhea(&self) -> Result<HheaTable<'a>, ParseError>

hhea — horizontal header.

§Errors

Missing table or parse errors.

Source

pub fn hmtx(&self) -> Result<HmtxTable<'a>, ParseError>

hmtx — advance widths and side bearings (wired to hhea + maxp).

§Errors

Missing tables or parse errors.

Source

pub fn maxp(&self) -> Result<MaxpTable<'a>, ParseError>

maxp — glyph count and memory hints.

§Errors

Missing table or parse errors.

Source

pub fn num_glyphs(&self) -> u16

Glyph count (0 when maxp is absent or invalid).

Source

pub fn cmap(&self) -> Result<Cmap<'a>, ParseError>

cmap — character-to-glyph mapping.

§Errors

Missing table or parse errors.

Source

pub fn name(&self) -> Result<NameTable<'a>, ParseError>

name — naming table.

§Errors

Missing table or parse errors.

Source

pub fn os2(&self) -> Result<Os2Table<'a>, ParseError>

OS/2 — weight/width classes and metrics.

§Errors

Missing table or parse errors.

Source

pub fn post(&self) -> Result<PostTable<'a>, ParseError>

post — PostScript names and italic angle.

§Errors

Missing table or parse errors.

Source

pub fn stat(&self) -> Result<StatTable<'a>, ParseError>

stat — style attributes.

§Errors

Missing table or parse errors.

Source

pub fn dsig(&self) -> Result<DsigTable<'a>, ParseError>

DSIG — digital signature (header only).

§Errors

Missing table or parse errors.

Source

pub fn layout(&self, kind: LayoutKind) -> Result<LayoutTable<'a>, ParseError>

GSUB/GPOS layout structure by kind.

§Errors

Missing table (ParseError::UnknownTableTag) or parse errors.

Source

pub fn variable(&self) -> Result<VariableFont<'a>, ParseError>

fvar + optional avar/gvar — the variable-font view.

§Errors

Missing fvar or parse errors.

Source

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.

Source

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.

Source

pub fn advance_width(&self, gid: GlyphId) -> Result<u16, ParseError>

Advance width for gid via hmtx.

§Errors

Missing tables or malformed hmtx.

Source

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]).

Source

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.

Trait Implementations§

Source§

impl<'a> Clone for FontRef<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for FontRef<'a>

Source§

impl<'a> Debug for FontRef<'a>

Source§

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

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

impl<'a> Eq for FontRef<'a>

Source§

impl<'a> PartialEq for FontRef<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for FontRef<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for FontRef<'a>

§

impl<'a> RefUnwindSafe for FontRef<'a>

§

impl<'a> Send for FontRef<'a>

§

impl<'a> Sync for FontRef<'a>

§

impl<'a> Unpin for FontRef<'a>

§

impl<'a> UnsafeUnpin for FontRef<'a>

§

impl<'a> UnwindSafe for FontRef<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.