pub struct OwnedTextRun {
pub context: TextRunContext,
pub logical_text: String,
pub clusters: Vec<TextCluster>,
pub glyphs: Vec<RunGlyph>,
pub total_advance: f32,
}Expand description
A fully measured, shaped, and hit-testable text run owning all metrics.
Provides the shared text-run representation across source code views, Markdown documents, labels, and search excerpts (Plan §13.1).
Fields§
§context: TextRunContextRun styling, font, and direction context.
logical_text: StringPreserved exact original logical text.
clusters: Vec<TextCluster>Clustered source-to-glyph associations in logical order.
glyphs: Vec<RunGlyph>Positioned glyphs in visual presentation order.
total_advance: f32Total visual horizontal advance width of the run.
Implementations§
Source§impl OwnedTextRun
impl OwnedTextRun
Sourcepub fn from_shaped_run(
context: TextRunContext,
shaped: &ShapedRun,
scale: f32,
) -> Result<Self, String>
pub fn from_shaped_run( context: TextRunContext, shaped: &ShapedRun, scale: f32, ) -> Result<Self, String>
Construct an OwnedTextRun from a shaped run and layout scale.
The scale converts font design units into user coordinates
(font_size / units_per_em). Glyphs retain the shaper’s visual order;
clusters are stored in logical source order in both directions. In RTL
runs their visual positions therefore descend through the cluster array.
§Errors
Rejects a direction mismatch, non-positive/non-finite size or scale, incomplete or non-monotone source coverage, invalid scalar boundaries, missing glyphs, negative horizontal advances, or non-finite positioning. Repeated cluster ranges must be consecutive, as for a base and its marks.
Sourcepub fn hit_test(&self, visual_x: f32) -> HitTestResult
pub fn hit_test(&self, visual_x: f32) -> HitTestResult
Perform CPU line-level hit testing against visual X position.
Resolves to an actual atomic cluster edge. Exterior coordinates and gaps produce inexact nearest-edge hits. NaN produces an inexact logical start; infinities clamp to the corresponding visual extreme. Empty runs have an inexact zero caret. Glyph positions and cluster geometry must come from the same layout snapshot.
Sourcepub fn caret_at_byte(
&self,
byte_offset: usize,
affinity: CaretAffinity,
) -> Option<CaretPosition>
pub fn caret_at_byte( &self, byte_offset: usize, affinity: CaretAffinity, ) -> Option<CaretPosition>
Resolve a logical UTF-8 position to an atomic source-cluster caret.
At an interior scalar boundary of a ligature or combining cluster,
Leading snaps to the cluster’s logical start and Trailing to its
logical end. The returned byte and UTF-16 offsets identify that real
edge, not the requested interior position. No glyph-internal caret is
invented. Mid-scalar and out-of-range offsets return None.
At a shared boundary, Leading chooses the following cluster’s leading
edge; Trailing chooses the preceding cluster’s trailing edge. At the
document endpoints only the existing inward cluster edge is available.
Sourcepub fn caret_at_utf16(
&self,
utf16_offset: usize,
affinity: CaretAffinity,
) -> Option<CaretPosition>
pub fn caret_at_utf16( &self, utf16_offset: usize, affinity: CaretAffinity, ) -> Option<CaretPosition>
Resolve a native UTF-16 position using the same cluster-snapping policy.
Surrogate-pair interiors and out-of-range offsets return None.
Sourcepub fn selection_rects(
&self,
range: Range<usize>,
y: f32,
height: f32,
) -> Vec<SelectionRect>
pub fn selection_rects( &self, range: Range<usize>, y: f32, height: f32, ) -> Vec<SelectionRect>
Compute visual-order selection rectangles for a logical source range.
Partial cluster selections cover the complete cluster. Adjacent and overlapping visual intervals are unioned in either direction; separated intervals remain separate. Ranges must be in bounds at UTF-8 scalar boundaries. Invalid ranges, non-finite coordinates, or non-positive heights return no rectangles, rather than publishing a partial selection.