pub struct TextGeometry { /* private fields */ }Expand description
Byte<->pixel geometry derived from one ShapedRun.
Implementations§
Source§impl TextGeometry
impl TextGeometry
Sourcepub fn with_size(self, size_px: f32, line_height_px: f32) -> Self
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.
Sourcepub fn caret_xy(&self, byte: usize) -> (f32, f32)
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).
Sourcepub fn byte_to_caret(&self, byte: usize) -> CaretGeometry
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.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Number of visual (post-wrap) lines.
Sourcepub fn visual_line_of_byte(&self, byte: usize) -> usize
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.
Sourcepub fn visual_line_bounds(&self, line: usize) -> (usize, usize)
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.
Sourcepub fn byte_at_line_x(&self, line: usize, goal_x: f32) -> usize
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.
Sourcepub fn x_to_byte(&self, x: f32, y: f32) -> usize
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.
Sourcepub fn selection_bands(&self, lo: usize, hi: usize) -> Vec<SelectionBand>
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
impl Clone for TextGeometry
Source§fn clone(&self) -> TextGeometry
fn clone(&self) -> TextGeometry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more