Skip to main content

Crate adobe_font_metrics

Crate adobe_font_metrics 

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

error 🔒
model 🔒
parser 🔒
records 🔒

Structs§

BBox
A font or glyph bounding box, with ordinary f32 precision limits.
CharacterMetric
One character record; missing advances stay absent until resolved against the font.
Composite
A CC construction recipe; it does not synthesize outlines or character metrics.
CompositeComponent
One PCC component in a composite definition.
DirectionMetrics
Authored metrics for one writing direction. Shared blocks populate both entries.
FontMetrics
Parsed AFM metric data. Optional authored fields retain absence; accessors resolve defaults.
KerningPair
A complete pair adjustment in one writing direction.
Ligature
One L successor ligature rule. Every rule on a character is retained in order.
SourceRecord
Comment or uninterpreted extension data, ordered by appearance in the source.
TrackKern
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§

CharacterCode
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.
KerningOperands
Pair operands retain the distinction between glyph names and encoded hexadecimal values.
MetricsSets
MetricsSets or StartDirection selector; 2 applies to both directions.
ParseError
Errors returned by crate::parse. Line numbers are 1-based.
RecordContext
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§

OwnedFontMetrics
Fully owned AFM data that can outlive the original input.