fix: RTL text fillText(maxWidth) x positioning calculation error#1179
Merged
Brooooooklyn merged 2 commits intomainfrom Dec 21, 2025
Merged
fix: RTL text fillText(maxWidth) x positioning calculation error#1179Brooooooklyn merged 2 commits intomainfrom
fillText(maxWidth) x positioning calculation error#1179Brooooooklyn merged 2 commits intomainfrom
Conversation
477120b to
a29fbe6
Compare
fillText(maxWidth) x positioning calculation errorfillText(maxWidth) x positioning calculation error
a29fbe6 to
ae4c9be
Compare
The `direction` algorithm has been rewritten, most scenarios now align with the browser. - Added more comprehensive test cases for `direction` - Also fixed the bug where `measureText.width` returned different values in LRT and RTL layouts The solution is to use `getMaxIntrinsicWidth` instead of `getRectsForRange`, which also avoids manually iterating through glyph widths. Part of #1172
ae4c9be to
4254910
Compare
3 tasks
Owner
|
cursor review |
Brooooooklyn
approved these changes
Dec 21, 2025
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.
The
directionalgorithm has been rewritten, most scenarios now align with the browser.directionmeasureText.widthreturned different values in LRT and RTL layoutsThe solution is to use
getMaxIntrinsicWidthinstead ofgetRectsForRange, which also avoids manually iterating through glyph widths.Part of #1172
Note
Reworks text direction layout to fix RTL x calculation and unify measureText.width across directions, and adds comprehensive direction/letter-spacing tests.
skia-c/skia_c.cpp)paragraph->getMaxIntrinsicWidth()forline_width(direction-independent, includes trailing spaces) instead of summinggetRectsForRange().paint_x/alignment logic: separatertl_offsetandletter_spacing_offset; compute center/right/start/end consistently; correct scaling interaction withmaxWidth.left,right) to include letter-spacing offset; minor float literal and cleanup tweaks.__test__/text.spec.ts)maxWidth, save/restore, stroke withletterSpacing, negativeletterSpacing, MDN example updates.direction-measure-textensuringmeasureText.widthmatches in LTR/RTL; refactor alignment test intodrawDirectionAlignTest; tweak canvas sizes/fonts where needed.Written by Cursor Bugbot for commit 6ff4761. This will update automatically on new commits. Configure here.