stet-fonts
Pure-Rust parsers for Type 1, CFF / Type 2, and TrueType fonts, plus the geometry primitives they produce.
This crate has no stet-specific dependencies and is usable on its own
for font-parsing workflows that don't need a PostScript interpreter or PDF
renderer. If you're building a stet-family project, the
stet facade pulls this in automatically.
What's inside
| Module | Purpose |
|---|---|
geometry |
Matrix (affine transforms), PathSegment, PsPath — the shared path/transform types |
type1_parser |
Adobe Type 1 binary / ASCII parser; eexec decryption |
charstring |
Type 1 charstring interpreter (CharString → PsPath) |
cff_parser |
Compact Font Format (CFF) parser — returns every font in the file, including CID-keyed FontSets |
type2_charstring |
Type 2 charstring interpreter for CFF glyphs |
truetype |
TrueType table accessors (head, loca, glyf, hmtx, cmap), simple & composite glyph resolution, glyf → PsPath conversion |
encoding |
StandardEncoding, ISOLatin1Encoding, SymbolEncoding, and other named encodings |
agl |
Adobe Glyph List — glyph name → Unicode mapping |
system_fonts |
Platform font directory discovery, substitution of the 35 standard PostScript names to URW equivalents |
Standalone use
[]
= "0.2"
Parse a Type 1 font
use parse_type1;
let data = read?;
let font = parse_type1?;
println!;
println!;
# Ok::
Parse a CFF font and render a glyph to a path
use parse_cff;
use execute_type2_charstring;
let data = read?; // bare .cff (OpenType CFF
// tables must be extracted first)
let fonts = parse_cff?;
let font = &fonts;
// Run the Type 2 charstring program for GID 1 (GID 0 is always .notdef).
let gid = 1usize;
let result = execute_type2_charstring?;
// result.path — `PsPath` in font units
// result.width_x — advance width
# Ok::
Read TrueType glyph outlines
use truetype;
let data = read?;
let upm = get_units_per_em;
let num_glyphs = get_num_glyphs;
if let Some = get_glyf_data
# Ok::
Scope and non-goals
These parsers are the ones stet needs to render PDFs and run a PostScript
Level 3 interpreter, so the surface is shaped around that: whole-font
parsing, glyph outlines as PsPath, no layout or shaping, no colour
fonts, no variable-font (fvar/gvar) interpolation, no OpenType GSUB /
GPOS / BASE / GDEF tables. If you need a general-purpose font-layout
library, look at ttf-parser,
rustybuzz, or
skrifa instead.
License
Apache-2.0 OR MIT