feat(usvgr): measure text from shaping alone and share shaped glyphs with the layout #26
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.42) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 347 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.350
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #26"
general
weight: 0.35
coderabbitai[bot]
Follow-up to your review of dmtrKovalenko/fframes#256: measuring text there built a whole
Tree. This adds what fframes needs to measure with kerning and layout only, and lets the layout reuse that work.usvgr::text_advance(text, &font, font_size, &resolver, &fontdb, cache)returns the advance width of a string. It runs the shaping the layout runs (bidi runs, kerning, font variations, automaticopsz, fallback fonts) and nothing else: no XML, no tree, no outlines.UsvgrTextShapeCachekeeps shaped glyphs per (text, font, size, features).text_advanceandlayout_textread and fill the same cache, so text that was measured is not shaped again when it is converted, and text drawn at a new position on every frame is shaped once. The handle is cheap to clone.Cache::new_with_text_cachesand the publicusvgr_shape_cachefield attach it to a converter cache.Font::newbuilds a font the way a<text>element does. The mapping of weight, stretch and style to thewght,wdth,italandslntaxes moved there from the parser, unchanged.process_chunkthe first span's glyphs stay shared with the cache and are copied only when another span overwrites some of them.Without a shape cache nothing changes:
Cache::default()has none.Numbers (Ryzen 7 9800X3D, release, Inter ExtraBold 46 px, measured from fframes):
| Case | Tree per measurement (#256) | This change |
|---|---|---|
| Measure a 38-character line, nothing cached | 118.6 µs | 30.2 µs |
| Measure the same line again | 118.6 µs | 0.10 µs |
| Measure the 21 words of a caption, per frame | 1069 µs | 3.2 µs |
| Convert a frame of 21 words that move every frame | 519 µs | 135 µs with the shared cache |
Tests: five unit tests in
text/mod.rs. The advance equals what the layout gives for kerned Latin, Arabic through a fallback font, mixed direction, marks, and Roboto Flex at weights 100 and 900. Measured text is not shaped again by a conversion that holds the same cache.Checked:
cargo test -p usvgrand the 1705 render tests insvgrpass.svgr-capidoes not compile and twosvgrtypestests fail onmainas well, so I left them out.<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Added text-advance measurement, including support for empty text and reporting when font selection or shaping fails.
Added an optional shared cache for shaped text, allowing text measurement and rendering to reuse results.
Variable-font settings now derive default weight, width, and style axes from font properties while retaining explicitly specified axis values.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->