font-parse
SFNT/OTF/TrueType/WOFF/WOFF2 binary font parser: offset tables, character maps, glyph outlines, variable fonts.
Layer: L0: leaf · Estate deps: zero (by mandate) · Core deps:
font-types (scalar types) + thiserror · no_std-capable (alloc only;
container decoding behind the woff/woff2 features).
What's here
| Module | Contents |
|---|---|
font |
FontRef: zero-copy view over &[u8] (SFNT offset table + table directory, lifetime-bound table slices), OwnedFont (WOFF/WOFF2/collection decoding into a validated buffer), FontCollection (TTC), VariableFont (fvar/avar/gvar) |
tables |
typed views: head, hhea, hmtx, maxp, cmap (formats 0/4/6/12), loca, glyf (simple + composite outlines), name, OS/2, post, fvar/avar, gvar, GSUB/GPOS structure, stat, DSIG |
woff |
WOFF 1.0: per-table zlib (feature woff) |
woff2 |
WOFF 2.0: Brotli stream + glyf/loca/hmtx transform reversal, checksum recomputation, head.flags bit 11 (feature woff2) |
reader |
bounds-checked big-endian read substrate (TruncatedTable on every shortfall) |
error |
ParseError: the single typed, exhaustive error |
Guarantees
- Total parsers: malformed, truncated, or hostile input yields a typed
ParseError: never a panic, never an out-of-bounds read. Enforced by deny-level lints (unwrap_used/expect_used/panic/indexing_slicing) on the lib target, a cargo-fuzz target over the main entry point, and 500-case proptests over arbitrary and mutated input. - Zero-copy table access:
FontRefborrows the buffer; every table view is a lifetime-bound slice. A view that outlives its bytes is a compile error (trybuild test). Outline extraction allocates (points), table access never does. - Bounded memory: WOFF2 stream sizes are validated against the
decompressed block before slicing (spec MUST), composite expansion is
capped (depth 16, 2^20 points), and WOFF1 zlib output is clamped to the
declared
origLength.
Example
use ;
let bytes = read.unwrap;
let font = new.unwrap;
let head = font.head.unwrap;
assert_eq!;
let cmap = font.cmap.unwrap;
let gid = cmap.codepoint.unwrap;
let advance = font.advance_width.unwrap;
if let Some = font.outline.unwrap
let _raw: = font.table;
Features
| Feature | Default | Effect |
|---|---|---|
std |
✓ | container decoding + lossy name decoding; without it the SFNT core is no_std (alloc) |
woff |
✓ | WOFF 1.0 container (miniz_oxide, implies std) |
woff2 |
✓ | WOFF 2.0 container (brotli-decompressor, implies std) |
Out of scope
CFF outline decoding (OTTO fonts parse; CFF is exposed raw),
rasterization, hinting interpretation, cmap formats 2/8/10/13/14, GSUB/GPOS
lookup subtable types, WOFF2 collection directories, and glyph variation
application (deltas are exposed; instancing is a rendering concern).
Fixtures
The known-good suite runs against fonts generated by
tests/fixtures/generate_fonts.py (fontTools); regenerate fixtures and
expected values together.
Layer
L0: leaf. Zero estate-internal dependencies.