fix: RTL text fillText(maxWidth) x positioning calculation error
#1179
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.