Skip to main content

TextGeometry

Struct TextGeometry 

Source
pub struct TextGeometry { /* private fields */ }
Expand description

Byte<->pixel geometry derived from one ShapedRun.

Implementations§

Source§

impl TextGeometry

Source

pub fn with_size(self, size_px: f32, line_height_px: f32) -> Self

Bake font-size line metrics so Self::byte_to_caret returns a real caret rect top / height. Matches the render caret math: ascent = size_px * 0.9 above the baseline, descent = size_px * 0.15 below (fixed font-metric ratios, independent of line-height - only the spacing between lines changes, not the glyph box a caret hugs). line_height_px is the resolved CSS line-height (or the size_px * DEFAULT_LINE_HEIGHT_MULTIPLIER fallback), supplied by the caller so this pure-math module never has to know the fallback constant itself.

Source

pub fn caret_xy(&self, byte: usize) -> (f32, f32)

Visual (x, baseline_y) of the caret for a logical byte offset, in run-local coords. This is the byte->pixel math the render caret / selection draw path consumes (relocated verbatim from render-wgpu).

Source

pub fn byte_to_caret(&self, byte: usize) -> CaretGeometry

Logical byte -> caret rect (run-local). top / height are only meaningful once Self::with_size has baked the metrics.

Source

pub fn line_count(&self) -> usize

Number of visual (post-wrap) lines.

Source

pub fn visual_line_of_byte(&self, byte: usize) -> usize

Visual line index containing byte. Past-end / between-line bytes snap to the nearest preceding line.

Source

pub fn visual_line_bounds(&self, line: usize) -> (usize, usize)

Logical byte range [start, end) of visual line line (end excludes a soft-wrap break and a trailing ‘\n’, since neither emits a glyph cluster). Empty tuple for an out-of-range line.

Source

pub fn byte_at_line_x(&self, line: usize, goal_x: f32) -> usize

Byte on visual line line whose caret x is nearest goal_x (goal-column landing). Clamps to the line’s byte range.

Source

pub fn x_to_byte(&self, x: f32, y: f32) -> usize

Visual hit-test: run-local pointer (x, y) -> logical byte. Picks the visual line by y, then the nearest cluster edge by x within that line (BiDi-correct). Past-end snaps to the line’s trailing byte.

A line that produced no glyphs - a blank line between two paragraphs - has no entry in lines, so the entry cannot be reached by y / line_height: that counts every visual line while lines counts only the ones that drew something, and the two diverge by the number of blank lines above the pointer. The line is matched on its baseline instead. A y over a blank line resolves to the end of the last line above it.

Source

pub fn selection_bands(&self, lo: usize, hi: usize) -> Vec<SelectionBand>

Emit one selection band per line-portion of each maximal contiguous BiDi-level run the logical range [lo, hi) intersects.

A segment is a maximal (font, BiDi level) run and keeps going across a line break, so a single min/max over a whole segment would merge two lines into one wide rectangle. Bucketing by baseline keeps each line’s highlight on its own line; baseline_y is the offset from the first line’s baseline, which is what the caret path already uses.

Trait Implementations§

Source§

impl Clone for TextGeometry

Source§

fn clone(&self) -> TextGeometry

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 TextGeometry

Source§

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

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

impl From<&ShapedRun> for TextGeometry

Source§

fn from(run: &ShapedRun) -> Self

Converts to this type from the input type.

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.

§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> ConditionalSend for T
where T: Send,