AUDIO
Source snapshot · 11 November 2026

Portable layout, SVG drawing and animation

Prepared source carets, hit tests and selections

caret::CaretMap::new(&layout) derives original UTF8 extended-grapheme boundaries and pen geometry from the immutable paragraph source, shaped clusters, visual runs and line baselines. TextPosition includes Upstream/Downstream affinity: the same byte at a soft wrap can resolve to the preceding line's end or following line's start; a bidi boundary can resolve to two different X positions. Invalid byte offsets, including positions inside combining graphemes/CRLF, return None.

The optional pinned unicode-segmentation 1.13.3 uses Unicode 17.0 data, separately from line-break Unicode 15.0 and bidi Unicode 16.0. Unsupported non-monotone, cross-grapheme or missing-initial-boundary backend clusters reject with Shaping. Ligature interior positions divide the cluster advance equally among graphemes; this is an explicit interpolation policy, not GDEF font caret measurement. Mark offsets/ink bounds do not alter pen carets or selection cells.

Preparation allocates at most 8194 affinity positions and 4096 grapheme cells within the 4096-byte source cap. Prepared caret, hit_test and selection operations allocate nothing. Hit tests choose the nearest baseline, with vertical midpoints choosing the later line. Finite coordinates outside clamp to available lines/pen positions; nonfinite coordinates return None. X ties prefer the supplied affinity, then earlier source bytes. Invisible/bidi source positions may coincide, so source/point/source round trips are not guaranteed.

selection(range, &mut output) accepts a half-open logical range at grapheme boundaries and writes only the returned prefix of visual line/X-ordered boxes. Each pen box spans baseline ±half the configured line height, rather than font ascender/descent or glyph ink. Touching selected cells merge with four relative machine epsilons for floating-point edge rounding; bidi logical selections can remain visually disjoint. Hard separators have no pen width, so selecting only one produces no box. Invalid endpoints or insufficient output capacity preserve every caller slot; unused output slots also remain untouched after success.

Six portable groups check numeric/source/affinity contracts, a real one-glyph synthetic ffi substitution with analytic equal-grapheme carets, selection rollback and maximum source boundaries. A 3000-iteration prepared lookup/hit/selection loop records zero heap allocations. The first-party rectangular fixture retains generator/provenance. This is reusable editing geometry; interactive input adapters, IME/clipboard/native caret, assistive technology, global backend work/deadline and complete Unicode conformance remain separate. See decision 0175.

cargo run -p ravet-surface --features text --example paragraph-carets --locked -- \
  crates/ravet-surface/tests/fixtures/text/NotoSansArabic.ttf > target/paragraph-carets.svg

The 720×320 browser fixture contains 73 outline paths and no text nodes. It shows one mixed bidi byte with two visual affinities, a logical selection with two disjoint boxes, and four equally spaced carets within the actual ffi substitution. The middle ligature grapheme has one 24-unit pen selection at size 72. Visual inspection confirms separate highlight boxes/carets and unclipped source geometry; this remains local SVG evidence, rather than native text interaction.