Bounded local-font paragraph layout¶
With text enabled, paragraph::ParagraphLayout::new composes the existing
local font shaper with explicit finite positive width, baseline spacing and
physical Left/Center/Right alignment. The input remains at most 4096 UTF8 bytes;
complete output is limited to 256 lines, 512 directional runs and 16384 glyphs.
Preparation allocates and repeatedly shapes candidate lines on UI/worker threads;
output caps do not globally bound backend work or memory. Cache the result before
callbacks; it owns the original source and paragraph options/base direction.
Retain the matching font and shaping style identity.
Line opportunities come from pinned unicode-linebreak 0.1.5 with Unicode 15.0
data; bidi retains the separate Unicode 16.0 backend. Its default line-break
profile treats complex-context (SA) characters as alphabetic, so dictionary
breaking for languages such as Thai is not supplied. The greedy policy accepts
consecutive fitting break opportunities until the first overflowing candidate.
An oversized first unbreakable unit is retained as one overflowing line, flagged
by overflows(); no character is forcibly split, clipped, dropped or replaced.
Spaces remain in their source lines and their advances participate in fitting.
There is no hyphen insertion, discretionary soft-hyphen substitution or
justification. Font coverage still appears as missing glyph zero, without fallback.
Resolve bidi embedding/isolate context for the whole input before soft wrapping,
then apply line reordering to each candidate and shape each original directional
slice. Base direction is explicit in TextOptions; script/language/features apply
to each run, rather than providing automatic script segmentation. LF, CRLF, CR and
Unicode line/paragraph separators create hard lines. Original separator byte ranges
remain available separately from content ranges; empty input and trailing hard
separators produce empty lines. Other controls/noncharacters reject. This does
not supply interactive editing, rich text or native font registration. The
optional prepared source mapping below consumes this immutable layout.
Each line exposes its original UTF8 content/separator ranges, width, visual runs
and alignment/baseline offset. Run X positions accumulate left-to-right in visual
order; glyph Y remains upward from the existing shaper. source_cluster(i) maps
one glyph's local cluster back to the original paragraph byte offset. Spacing
height is line_count * line_height, with the first baseline at zero; it is not
measured ascender/descent or ink bounds. Overlong lines start at X zero for every
alignment. Invalid styles, numeric overflow or capacity failure return no partial
layout.
SvgDrawing::paragraph_text renders the selected local TrueType outlines and
returns the layout. All paragraph/drawing/path limits apply, and a late outline
or document failure restores the whole existing document and command count.
The paragraph emits no text nodes, scripts, font URLs or implicit resources;
consumers supply accessible meaning through their title/markup.
cargo run -p ravet-surface --features text --example paragraph-outlines --locked -- \
crates/ravet-surface/tests/fixtures/text/NotoSansArabic.ttf > target/paragraph.svg
Six portable groups cover exact wrapping/whitespace/glyph identity, global byte clusters, physical alignment, all hard separators/empty lines, nonbreaking spaces, combining marks/zero-width breaks, preserved embedding levels across soft wraps, unbreakable overflow, maximum bytes/lines/runs, invalid styles and whole-drawing rollback. The synthetic 720×420 example renders two five-line paragraphs with opposite explicit base directions. The collaborative browser reports 192 paths, no text nodes and finite ink inside the viewport; visual inspection shows joined Arabic/marks and readable Latin without clipping. This is local SVG browser rendering, with no native/GPU/bitmap, assistive-technology or other-font/script conformance claim. See decision 0172 and the dependency notices in licensing.