Repository navigation
[web] Fix WebParagraph subpixel text stretching and letter jittering - #191030
Merged
Merged
Conversation
Fixes targetRect calculation in WebParagraph painting: - Removes .ceilToDouble() from targetRect width/height, preserving exact sourceRect.width / devicePixelRatio ratio for 1:1 physical pixel mapping without non-uniform scaling artifacts. - Removes .floorToDouble() from targetRect offset coordinates, preserving subpixel positioning and preventing letter jittering. - Removes unnecessary CSS style assignments on offscreen 2D paint canvas. - Adds unit tests covering WebParagraph painting across fractional and integer devicePixelRatio values.
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the web paragraph painter to correctly handle fractional device pixel ratios by removing explicit canvas style width/height resizing and avoiding rounding or flooring of target rectangle coordinates and dimensions. A test is added to verify subpixel precision and correct mapping under fractional DPRs. The review feedback suggests renaming a misleadingly named style variable to improve readability and modifying the mock canvas's fallback method to return null instead of throwing to increase robustness.
Rusino
approved these changes
Aug 17, 2026
This was referenced Aug 18, 2026
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.
Description
Fixes subpixel text stretching, distortion, and letter jittering issues in
WebParagraphwhen rendered with CanvasKit/Skwasm.Root Cause
targetRectapplied.floorToDouble()to its origin (dx,dy). Snapping logical coordinates to integer pixels while the text canvas was rasterized with floating-point origins caused 1-pixel positioning shifts and letter jittering during smooth scrolling or subpixel placement.targetRectapplied.ceilToDouble()tosourceRect.width / devicePixelRatioandsourceRect.height / devicePixelRatio. On fractional or high-DPI displays (e.g. 2.0 DPR wheresourceRect.width= 21 physical px), rounding the logical width to11.0caused CanvasKit to render the 21 physical pixel source bitmap across 22 physical screen pixels. WithFilterQuality.none, nearest-neighbor sampling stretched the texture, producing distorted glyphs and non-uniform pixel columns._resizePaintCanvasunnecessarily mutated.style.widthand.style.heighton an unattached offscreenDomHTMLCanvasElement.Fix
.ceilToDouble()fromtargetRectdimensions, preserving exactsourceRect.width / devicePixelRatiophysical-to-logical ratio for 1:1 screen pixel mapping..floorToDouble()fromtargetRectorigin coordinates, preserving subpixel positioning accuracy.paragraph_test.dartasserting DPR ratio and subpixel accuracy across fractional and integer DPR values.Tests
test('WebParagraph correctly handles fractional devicePixelRatio')inparagraph_test.dart.Fixes #188321