adobe_font_metrics/lib.rs
1//! Borrowing, zero-dependency Adobe Font Metrics (AFM) v4.x parser.
2//!
3//! [`parse`] and [`parse_bytes`] retain global metadata, both writing directions,
4//! character advance vectors and ligatures, named/hexadecimal pair kerning,
5//! track kerning, and composite definitions. [`FontMetrics::advance`] resolves
6//! character advances against direction-specific `CharWidth` defaults.
7//!
8//! Optional fields preserve absence. Comments and unrecognized records remain
9//! available through [`FontMetrics::source_records`]. Names and record text borrow
10//! the input; [`FontMetrics::into_owned`] detaches the entire model for storage.
11//! Numeric metrics use `f32`; source formatting is not preserved for serialization.
12//!
13//! # Example
14//!
15//! ```
16//! use adobe_font_metrics::{Direction, Vector, parse};
17//! # fn main() -> Result<(), adobe_font_metrics::ParseError> {
18//! let source = "StartFontMetrics 4.1\nFontName Demo\nFontBBox 0 0 600 700\n\
19//! CharWidth 600 0\nStartCharMetrics 1\nC 65 ; N A ;\n\
20//! EndCharMetrics\nEndFontMetrics\n";
21//! let font = parse(source)?;
22//! assert_eq!(font.advance(&font.character_metrics[0], Direction::Zero),
23//! Some(Vector { x: 600.0, y: 0.0 }));
24//! assert!(font.direction(Direction::Zero).fixed_pitch());
25//! # Ok(())
26//! # }
27//! ```
28//!
29//! # Validation and limits
30//!
31//! The reader checks modeled operands, finite numbers, section boundaries,
32//! declared section counts, and the closing font marker. Standalone pair/track
33//! sections are accepted for compatibility with existing callers. It does not
34//! resolve glyph references, interpret encodings, or certify all cross-field AFM
35//! constraints. Unknown records are preserved without interpretation.
36//!
37//! AFM v3, ACFM/AMFM containers, multiple-master array interpretation, shaping,
38//! and serialization remain outside the implemented API. See the [coverage audit]
39//! and [Adobe Tech Note 5004] for the precise boundary.
40//!
41//! [coverage audit]: https://github.com/kjanat/mosaic/blob/master/docs/afm-parser-scope.md
42//! [Adobe Tech Note 5004]: https://adobe-type-tools.github.io/font-tech-notes/pdfs/5004.AFM_Spec.pdf
43
44#![doc(
45 html_logo_url = "https://mosaiclang.dev/assets/A4.svg",
46 html_favicon_url = "https://mosaiclang.dev/assets/A4.svg"
47)]
48#![deny(missing_docs)]
49
50mod error;
51mod model;
52mod parser;
53mod records;
54
55pub use error::ParseError;
56pub use model::*;
57pub use parser::{parse, parse_bytes};