Skip to main content

OwnedTextRun

Struct OwnedTextRun 

Source
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: TextRunContext

Run styling, font, and direction context.

§logical_text: String

Preserved 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: f32

Total visual horizontal advance width of the run.

Implementations§

Source§

impl OwnedTextRun

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for OwnedTextRun

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OwnedTextRun

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for OwnedTextRun

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for OwnedTextRun

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.