Skip to main content

text_typeset/shaping/
run.rs

1use std::ops::Range;
2
3use crate::shaping::shaper::TextDirection;
4use crate::types::FontFaceId;
5
6#[derive(Clone)]
7pub struct ShapedGlyph {
8    pub glyph_id: u16,
9    pub cluster: u32,
10    pub x_advance: f32,
11    pub y_advance: f32,
12    pub x_offset: f32,
13    pub y_offset: f32,
14    /// Font face for this specific glyph. May differ from the run's font_face_id
15    /// when glyph fallback replaced a .notdef with a glyph from another font.
16    pub font_face_id: FontFaceId,
17}
18
19#[derive(Clone)]
20pub struct ShapedRun {
21    pub font_face_id: FontFaceId,
22    pub size_px: f32,
23    /// Resolved font weight (CSS 100–900). Propagated to the glyph
24    /// rasterizer so variable-font `wght` axis is set correctly and
25    /// the glyph cache key distinguishes different weights.
26    pub weight: u16,
27    pub glyphs: Vec<ShapedGlyph>,
28    pub advance_width: f32,
29    pub text_range: Range<usize>,
30    /// Resolved visual direction of this run. Glyphs are stored in visual
31    /// (left-to-right) order, so for an RTL run their `cluster` byte
32    /// offsets descend across the array. Hit-testing and caret placement
33    /// need this to map between visual x and logical offset correctly.
34    pub direction: TextDirection,
35    /// Decoration flags from the source fragment's TextFormat.
36    pub underline_style: crate::types::UnderlineStyle,
37    pub overline: bool,
38    pub strikeout: bool,
39    pub is_link: bool,
40    /// Text foreground color (RGBA). None means default (black).
41    pub foreground_color: Option<[f32; 4]>,
42    /// Underline color (RGBA). None means use foreground_color.
43    pub underline_color: Option<[f32; 4]>,
44    /// Text-level background highlight color (RGBA). None means transparent.
45    pub background_color: Option<[f32; 4]>,
46    /// Hyperlink destination URL.
47    pub anchor_href: Option<String>,
48    /// Tooltip text.
49    pub tooltip: Option<String>,
50    /// Vertical alignment (normal, superscript, subscript).
51    pub vertical_alignment: crate::types::VerticalAlignment,
52    /// If Some, this run represents an inline image placeholder.
53    pub image_name: Option<String>,
54    /// Image height in pixels (used for line height expansion).
55    pub image_height: f32,
56}