Expand description
Pure-Rust, zero-dependency parser for Adobe Font Metrics (AFM) files,
per Adobe Tech Note 5004 (5004.AFM_Spec).
§Scope
Supports AFM v4.x (the format Adobe shipped with the Core 14
PostScript fonts). The single entry point is parse, which
consumes a &str and returns a borrowed FontMetrics whose
Cow<'_, str> fields point into the source slice: zero allocations
for glyph names and kerning operands. Call FontMetrics::into_owned
to obtain an OwnedFontMetrics (FontMetrics<'static>) suitable
for caching, baking into static tables, or sending across threads.
AFM v3.x files (e.g. older Adobe samples) are deliberately rejected
with ParseError::UnsupportedVersion. The reader subset here
would handle most v3 files, but the v4-only scope claim is honest;
relax it once a real v3 fixture is on hand to validate against.
§Coverage
- Header:
StartFontMetrics(rejects non-4.x versions). - Global keys:
FontName,FullName,FamilyName,Weight,ItalicAngle,IsFixedPitch,FontBBox,UnderlinePosition,UnderlineThickness,CapHeight,XHeight,Ascender,Descender,EncodingScheme. - Per-character records:
C,CH,WX,W0X,W/W0(X taken),N,B.WY,L, and other tokens are ignored within a record. - Kerning:
KPX,KPY,KP(KPY rows storeadjust = 0.0; only the X axis is exposed in the public type today).StartKernPairs1blocks (direction-1 kerning) are accepted and dropped. StartComposites/CCblocks are accepted and discarded per the user-facing scope of the v0.1 surface.StartTrackKern/TrackKern/EndTrackKern(track kerning) are not modelled and pass through silently.StartDirection 1blocks are skipped; direction-0 and direction-2 blocks are accepted (their inner keys read as if at the top level, matching the layout of real Core 14 AFMs).- Unknown keywords at the top level are silently ignored.
§Errors
ParseError carries a 1-based line number on every variant
that originates inside the source. The parser never panics on
ill-formed input; every malformed record is converted into a
ParseError::InvalidNumber or ParseError::MalformedRecord.
Structs§
- BBox
- A glyph or font bounding box, in 1/1000 em.
- Character
Metric - One entry from a
StartCharMetricsblock. - Font
Metrics - All public AFM data extracted from a single
.adobe-font-metricsfile. - Kerning
Pair - One entry from a
StartKernPairsblock.
Enums§
- Parse
Error - Errors returned by
parse. Line numbers are 1-based. - State 🔒
Functions§
- next_
f32 🔒 - parse
- Parse an AFM file into a borrowed
FontMetrics. - parse_
bbox 🔒 - parse_
bool 🔒 - parse_
char_ 🔒metric_ line - parse_
f32 🔒 - parse_
i32 🔒 - parse_
kern_ 🔒record - split_
keyword 🔒
Type Aliases§
- Owned
Font Metrics - Convenience alias for fully-owned metrics (
'static).