svg_loader: fix tspan/text positioning#4451
Conversation
Binary Size Report
|
|
#4421 (comment) Currently, whitespace at both ends of the text is not supported. |
Pixel Test Report
|
There was a problem hiding this comment.
Pull request overview
Fixes SVG <text>/<tspan> layout so text runs without explicit x/y continue from the previous run end, with dx/dy applied as deltas and text-anchor affecting measurement/positioning (addresses #4421 pixel mismatches attributed to loader behavior).
Changes:
- Adjust
<tspan>close handling to avoid splicing in more cases, and change text-data parsing to sometimes emit an unpositioned “run”<tspan>node. - Track a running
textPositionwhile building tspans, and update it after each run while accounting fortext-anchor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/loaders/svg/tvgSvgLoader.cpp | Updates <tspan> splicing rules and text-data parsing to create unpositioned run tspans after inline tspans. |
| src/loaders/svg/tvgSvgBuilder.cpp | Adds running pen-position tracking across text/tspan runs and updates positioning using alignment/measurement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| static void _updateTextPosition(Text* text, const SvgTextNode& textNode, float anchor, Point& textPosition) | ||
| { | ||
| auto box = _bounds(text); | ||
| auto w = box.w > 0.0f ? box.w : 0.0f; | ||
| textPosition.x = textNode.x + textNode.dx + (1.0f - anchor) * w; | ||
| textPosition.y = textNode.y + textNode.dy; | ||
| } |
There was a problem hiding this comment.
To calculate the exact x of textPosition, we need the accurate size of the text. For now, this requires calling load() to compute the size. Since the updated flag prevents duplicate loads, the overall computation time stays the same.
a06237f to
f9fe564
Compare
Track a running text position so a run with unset x/y continues from the previous run's end and dx/dy apply as deltas on top. Apply text-anchor before measuring so the anchor takes effect. issue : #4421
f9fe564 to
3714401
Compare
Track a running text position so a run with unset x/y continues from the previous run's end and dx/dy apply as deltas on top. Apply text-anchor before measuring so the anchor takes effect.
issue : #4421