Fix wrapped text decorations counting character and word spacing twice - #1806
Merged
Merged
Conversation
The line wrapper's textWidth already includes characterSpacing and wordSpacing for each word, and _fragment and boundsOfString added both again, so the underline, strike, link and goTo of wrapped text and the bounds width were too wide. Measure the line text instead, as the lineBreak: false path already does.
3 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix.
The line wrapper's
textWidthalready includescharacterSpacingandwordSpacingfor each word (lib/line_wrapper.js,wordWidth()andemitLine)._fragmentandboundsOfStringthen add both again, so on wrapped text the underline, strike, link and goTo rectangles and the bounds width are too wide. ThelineBreak: falsepath measures the text itself and is correct.doc.text('Hello big world', x, y, { underline: true, ...spacing })at 12pt:lineBreak: falsewidth: 400, masterwidth: 400, this PRcharacterSpacing: 4wordSpacing: 5boundsOfString(..., { width: 400 })returns the same widths. With no spacing set, the output for left, center, right and justify is unchanged.The fix measures the line in both places, the way the
lineBreak: falsefallback in_fragmentalready does. Center alignment still uses the wrapper'stextWidthand is not touched here. The new tests intests/unit/text.spec.jsfail on master and pass with the change.prettier --check,lintandnpm test(61 files, 526 tests) pass on Node 22; I did not run Node 20 or 24.Checklist:
Written with AI assistance (Claude); I have reviewed the change.