Expand description
Borrowing, zero-dependency Adobe Font Metrics (AFM) v4.x parser.
parse and parse_bytes retain global metadata, both writing directions,
character advance vectors and ligatures, named/hexadecimal pair kerning,
track kerning, and composite definitions. FontMetrics::advance resolves
character advances against direction-specific CharWidth defaults.
Optional fields preserve absence. Comments and unrecognized records remain
available through FontMetrics::source_records. Names and record text borrow
the input; FontMetrics::into_owned detaches the entire model for storage.
Numeric metrics use f32; source formatting is not preserved for serialization.
§Example
use adobe_font_metrics::{Direction, Vector, parse};
let source = "StartFontMetrics 4.1\nFontName Demo\nFontBBox 0 0 600 700\n\
CharWidth 600 0\nStartCharMetrics 1\nC 65 ; N A ;\n\
EndCharMetrics\nEndFontMetrics\n";
let font = parse(source)?;
assert_eq!(font.advance(&font.character_metrics[0], Direction::Zero),
Some(Vector { x: 600.0, y: 0.0 }));
assert!(font.direction(Direction::Zero).fixed_pitch());§Validation and limits
The reader checks modeled operands, finite numbers, section boundaries, declared section counts, and the closing font marker. Standalone pair/track sections are accepted for compatibility with existing callers. It does not resolve glyph references, interpret encodings, or certify all cross-field AFM constraints. Unknown records are preserved without interpretation.
AFM v3, ACFM/AMFM containers, multiple-master array interpretation, shaping, and serialization remain outside the implemented API. See the coverage audit and Adobe Tech Note 5004 for the precise boundary.
Modules§
Structs§
- BBox
- A font or glyph bounding box, with ordinary
f32precision limits. - Character
Metric - One character record; missing advances stay absent until resolved against the font.
- Composite
- A
CCconstruction recipe; it does not synthesize outlines or character metrics. - Composite
Component - One
PCCcomponent in a composite definition. - Direction
Metrics - Authored metrics for one writing direction. Shared blocks populate both entries.
- Font
Metrics - Parsed AFM metric data. Optional authored fields retain absence; accessors resolve defaults.
- Kerning
Pair - A complete pair adjustment in one writing direction.
- Ligature
- One
L successor ligaturerule. Every rule on a character is retained in order. - Source
Record - Comment or uninterpreted extension data, ordered by appearance in the source.
- Track
Kern - One track-kerning curve, retained as its degree and endpoint values.
- Vector
- A point or displacement in AFM units (1/1000 of the font scale).
Enums§
- Character
Code - An encoded character number; hexadecimal digits are retained without angle brackets. These values are encoding-specific and are not Unicode scalar values.
- Direction
- AFM writing direction, independent of the sign or axis of an advance vector.
- Kerning
Operands - Pair operands retain the distinction between glyph names and encoded hexadecimal values.
- Metrics
Sets MetricsSetsorStartDirectionselector; 2 applies to both directions.- Parse
Error - Errors returned by
crate::parse. Line numbers are 1-based. - Record
Context - Location of a comment or unrecognized record within the parsed AFM structure.
Functions§
- parse
- Parse AFM v4.x text into borrowed font metrics.
- parse_
bytes - Parse AFM file bytes without a caller-side decoding step or lossy conversion. Names and text borrow the byte slice through a validated ASCII view.
Type Aliases§
- Owned
Font Metrics - Fully owned AFM data that can outlive the original input.