Skip to main content

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
15/// `lightweight-pdf-layout`'s only dependency on fonts: given a [`FontKey`], hand
16/// back metrics. Implemented by the facade crate, which bridges to
17/// `lightweight-pdf-fonts::FontData` (ADR-010).
18pub trait FontResolver {
19    fn metrics(&self, key: FontKey) -> &dyn FontMetrics;
20}