lightweight_pdf_layout/font_resolver.rs
1use lightweight_pdf_core::FontKey;
2
3/// Per-font metrics, normalized to 1000 units-per-em (PDF/Type1
4/// convention). `lightweight-pdf-layout` never sees font bytes — only this.
5pub trait FontMetrics {
6 /// Advance width for one character, in 1/1000 em. Implementors must
7 /// return *some* usable width even for unrepresentable characters
8 /// (e.g. a notdef/fallback width) so wrapping code never has to
9 /// special-case "no metric available".
10 fn advance(&self, ch: char) -> f32;
11 fn ascent(&self) -> f32;
12 fn descent(&self) -> f32;
13
14 /// Whether the font has an actual glyph for `ch` (as opposed to
15 /// `advance`'s notdef fallback width). Defaults to `true` so existing
16 /// implementors (test doubles, anything that doesn't track glyph
17 /// coverage) don't need to change; `lightweight-pdf`'s embedded-font
18 /// adapter overrides this to drive `LayoutWarningKind::MissingGlyph`.
19 fn has_glyph(&self, _ch: char) -> bool {
20 true
21 }
22}
23
24/// `lightweight-pdf-layout`'s only dependency on fonts: given a [`FontKey`], hand
25/// back metrics. Implemented by the facade crate, which bridges to
26/// `lightweight-pdf-fonts::FontData` (ADR-010).
27pub trait FontResolver {
28 fn metrics(&self, key: FontKey) -> &dyn FontMetrics;
29}