Skip to content

Extract WrapsText - #6

Merged
smnandre merged 1 commit into
ateliersvg:mainfrom
smnandre:sa/wraps-text
Sep 19, 2026
Merged

smnandre merged 1 commit into
ateliersvg:mainfrom
smnandre:sa/wraps-text

Conversation

@smnandre

Copy link
Copy Markdown
Contributor

TextMeasurerInterface asks for two methods. Only one of them, measureLine(), knows
anything about the font. wrap() is greedy line breaking that calls measureLine() and
nothing else, so every implementation has to write it again.

atelier/diagram did: ThemeTextMeasurer has seven lines of its own work and 78 copied
from CharWidthTextMeasurer, 76 of them character for character.

This moves that logic into a WrapsText trait. CharWidthTextMeasurer now uses it and
keeps only what measures a glyph.

The trait reads the baseline from measureLine('M', ...)->ascent rather than from private
state. Output is unchanged: lines, width, height and both baselines match to 1e-12 across
word breaking, blank text, a zero width and an overlong word.

Nothing breaks. wrap() stays on the interface and the trait is opt-in, so an existing
implementation compiles and runs untouched.

@smnandre
smnandre merged commit 9a3a0ce into ateliersvg:main Sep 19, 2026
5 checks passed
@smnandre
smnandre deleted the sa/wraps-text branch September 19, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant