Skip to main content

Crate adobe_font_metrics

Crate adobe_font_metrics 

Source
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 store adjust = 0.0; only the X axis is exposed in the public type today). StartKernPairs1 blocks (direction-1 kerning) are accepted and dropped.
  • StartComposites/CC blocks 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 1 blocks 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.
CharacterMetric
One entry from a StartCharMetrics block.
FontMetrics
All public AFM data extracted from a single .adobe-font-metrics file.
KerningPair
One entry from a StartKernPairs block.

Enums§

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

OwnedFontMetrics
Convenience alias for fully-owned metrics ('static).