The glyph-provider contract: first-principles type and trait definitions for a stroke (vector) font stack. Zero dependencies (std only), serde-free, and domain-blind — it knows only glyphs, strokes, and metrics, and names no consuming application.
This is the engine/content seam. A provider (a concrete font) decodes a font into this contract; a consumer (a text-layout or graphics engine) reads from this contract. Neither depends on the other — they rendezvous here.
use glyph::{GlyphProvider, Glyph, FontMetrics, Point};
struct OneBar;
impl GlyphProvider for OneBar {
fn glyph(&self, c: char) -> Option<Glyph> {
(c == 'I').then(|| Glyph {
strokes: vec![vec![Point::new(0, 0), Point::new(0, 700)]],
advance: 200,
})
}
fn metrics(&self) -> FontMetrics {
FontMetrics { units_per_em: 1000, ascent: 700, descent: -200, line_gap: 100 }
}
}Point { x: i32, y: i32 }— an integer coordinate in glyph units,y-up. The font stack defines its own minimal point so it pulls in no geometry crate.Glyph { strokes: Vec<Vec<Point>>, advance: i32 }— each innerVecis one pen-down polyline (a stroke);advanceis the pen step to the next glyph.FontMetrics { units_per_em, ascent, descent, line_gap }— font-wide metrics, so a consumer can scale any provider to a requested point size.trait GlyphProvider—glyph(char) -> Option<Glyph>(None= absent) andmetrics() -> FontMetrics.
Licensed under either of Apache-2.0 (LICENSE-APACHE) or MIT (LICENSE-MIT) at your option.