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 /// UAX #9 embedding level (even LTR, odd RTL), used by rule L2 to put
36 /// the runs of a line into visual order.
37 ///
38 /// `direction` cannot stand in for this: it collapses level 0 and
39 /// level 2, so a Latin phrase nested inside Arabic would reorder as
40 /// though it sat at paragraph level. Runs shaped outside a bidi
41 /// analysis keep level 0, which reorders as plain LTR.
42 pub bidi_level: u8,
43 /// Decoration flags from the source fragment's TextFormat.
44 pub underline_style: crate::types::UnderlineStyle,
45 pub overline: bool,
46 pub strikeout: bool,
47 pub is_link: bool,
48 /// Text foreground color (RGBA). None means default (black).
49 pub foreground_color: Option<[f32; 4]>,
50 /// Underline color (RGBA). None means use foreground_color.
51 pub underline_color: Option<[f32; 4]>,
52 /// Text-level background highlight color (RGBA). None means transparent.
53 pub background_color: Option<[f32; 4]>,
54 /// Hyperlink destination URL.
55 pub anchor_href: Option<String>,
56 /// Tooltip text.
57 pub tooltip: Option<String>,
58 /// Vertical alignment (normal, superscript, subscript).
59 pub vertical_alignment: crate::types::VerticalAlignment,
60 /// If Some, this run represents an inline image placeholder.
61 pub image_name: Option<String>,
62 /// Image height in pixels (used for line height expansion).
63 pub image_height: f32,
64}