frust_scene/glyph.rs
1//! Glyph and font primitives used by [`crate::Command::GlyphRun`].
2
3use kurbo::Affine;
4use peniko::{Brush, FontData};
5
6/// Opaque wrapper around a loaded font resource (blob + collection index).
7///
8/// `frust-text` constructs `FontHandle`s from `peniko::FontData`;
9/// `frust-render` (layer 4) unwraps them when building glyph draw calls.
10/// `peniko::FontData` is the shared Linebender vocabulary `vello_common` re-exports — it
11/// does not count as a vello type for the purposes of this crate's "no vello in
12/// the public API" rule. Note: peniko 0.6.1 names
13/// this type `FontData`, not `Font`; the shape
14/// (blob + collection index) is unchanged.
15#[derive(Clone, Debug)]
16pub struct FontHandle(FontData);
17
18impl FontHandle {
19 /// Wraps a `peniko::FontData` for use in a [`GlyphRun`].
20 pub fn new(font: FontData) -> Self {
21 Self(font)
22 }
23
24 /// Borrows the underlying `peniko::FontData`.
25 pub fn font(&self) -> &FontData {
26 &self.0
27 }
28}
29
30impl From<FontData> for FontHandle {
31 fn from(font: FontData) -> Self {
32 Self::new(font)
33 }
34}
35
36/// A single positioned glyph within a [`GlyphRun`].
37#[derive(Clone, Copy, Debug, PartialEq)]
38pub struct Glyph {
39 /// Glyph ID within the run's font.
40 pub id: u32,
41 /// X position, in the run's local coordinate space (pre-transform).
42 pub x: f32,
43 /// Y position, in the run's local coordinate space (pre-transform).
44 pub y: f32,
45}
46
47/// A run of glyphs sharing a font, size, brush, and transform.
48#[derive(Clone, Debug)]
49pub struct GlyphRun {
50 /// Font this run's glyph IDs are resolved against.
51 pub font: FontHandle,
52 /// Font size, in pixels.
53 pub font_size: f32,
54 /// Paint used to fill the glyphs.
55 pub brush: Brush,
56 /// Transform applied to the whole run.
57 pub transform: Affine,
58 /// The positioned glyphs.
59 pub glyphs: Vec<Glyph>,
60}