1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! SFNT/OTF/TrueType/WOFF/WOFF2 binary font parser — offset tables,
//! character maps, glyph outlines, variable fonts.
//!
//! font-parse reads font files **in place**: a [`FontRef`] is a lifetime-
//! bound view over `&[u8]` — table access touches nothing, allocates
//! nothing, copies nothing. Typed table views ([`HeadTable`], [`Cmap`],
//! [`GlyphOutline`], …) read fields on demand from the borrowed bytes and
//! die with the borrow.
//!
//! # Totality
//!
//! Every parser is **total**: malformed, truncated, hostile input produces a
//! typed [`ParseError`] — never a panic, never an out-of-bounds read. Bounds
//! are checked at every field read (deny-level `indexing_slicing` /
//! `unwrap_used` lints enforce this), so fuzzing asserts `Err`-not-panic
//! (see `fuzz/`).
//!
//! # Containers
//!
//! | Container | Entry point | Feature |
//! |---|---|---|
//! | SFNT / TrueType / OTF | [`FontRef::new`] | — (no_std) |
//! | TTC collection | [`FontCollection::parse`], [`OwnedFont::from_collection`] | — |
//! | WOFF 1.0 (zlib) | [`OwnedFont::from_woff`] | `woff` (std) |
//! | WOFF 2.0 (Brotli + glyf/loca/hmtx transforms) | [`OwnedFont::from_woff2`] | `woff2` (std) |
//!
//! WOFF/WOFF2 decoding reconstructs a standalone SFNT ([`OwnedFont`]) with
//! recomputed table checksums and `head.checkSumAdjustment`.
//!
//! # Example
//!
//! ```no_run
//! use font_parse::{FontRef, TableTag, GlyphId};
//!
//! # fn main() -> Result<(), font_parse::ParseError> {
//! let bytes = std::fs::read("tests/fixtures/minimal.ttf").expect("fixture");
//! let font = FontRef::new(&bytes)?;
//!
//! // Zero-copy table access.
//! let head = font.head()?;
//! assert_eq!(head.units_per_em()?, 1000);
//!
//! // Character mapping.
//! let cmap = font.cmap()?;
//! let gid = cmap.codepoint('A').expect("A is mapped");
//!
//! // Metrics and outlines.
//! let advance = font.advance_width(gid)?;
//! if let Some(outline) = font.outline(gid)? {
//! let _ = outline.point_count();
//! }
//! let _raw: Option<&[u8]> = font.table(TableTag::Glyf);
//! let _ = GlyphId::new(0);
//! # Ok(())
//! # }
//! ```
//!
//! # Out of scope
//!
//! CFF outline decoding (OTTO fonts parse; their `CFF` table is exposed raw),
//! rasterization, glyph instruction (hinting) interpretation, cmap lookup
//! subtable formats 2/8/10/13/14, GSUB/GPOS lookup subtable types, and WOFF2
//! collection directories. This crate is the estate's font edge: consumers
//! bring the buffers and take the glyphs.
//!
//! # Layer
//!
//! L0 — leaf. Zero estate-internal dependencies; external deps are
//! `font-types` (scalar types) + `thiserror`, with `miniz_oxide`/`brotli-
//! decompressor` behind the container features.
extern crate alloc;
pub use ;
pub use ;
pub use ;
pub use TableTag;
// Scalar types re-exported from Google Fonts' `font-types` — the crate's
// numeric vocabulary (16.16 `Fixed`, 2.14 `F2Dot14`, `GlyphId`, `Tag`, …).
pub use ;
/// SFNT table checksum: u32 sum of big-endian words, zero-padded to four
/// bytes. Exposed for container verification and directory checks.