-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Use scaled font to determine bounds, match Skia position rounding behavior, add subpixel X/Y/All/None positioning. #53042
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
| const auto* glyphs = run.glyphs(); | ||
| switch (run.positioning()) { | ||
| case SkTextBlobRunIterator::kFull_Positioning: { | ||
| std::vector<SkRect> glyph_bounds; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These bounds are wrong, this computation is moved into the typographer contents where the exact scale is applied to the font size.
|
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. |
|
Remaining issue is that many CJK fonts have fractional Y positions too, fixing that will truly fix all issues. |
|
Actually its not y alignment,it is just slightly less bold. Filled flutter/flutter#149142 |
| text_contents->SetTextFrame(text_frame); | ||
| text_contents->SetColor(paint.color); | ||
| text_contents->SetForceTextColor(paint.mask_blur_descriptor.has_value()); | ||
| text_contents->SetOffset(position); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to use the original offset to compute the subpixel position now.
|
Golden file changes are available for triage from new commit, Click here to view. |
| #include "impeller/typographer/font.h" | ||
| #include "impeller/typographer/glyph.h" | ||
|
|
||
| #include "include/core/SkPaint.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: No newline here and include the third_party/skia before the include like the rest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
|
||
| bool TextContents::CanInheritOpacity(const Entity& entity) const { | ||
| return !frame_->MaybeHasOverlapping(); | ||
| return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow why this isn't true anymore. Add a comment maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment added
| switch ( | ||
| strikeSpec.createScalerContext()->computeAxisAlignmentForHText()) { | ||
| case SkAxisAlignment::kNone: | ||
| // Skia calls this case none, meaning alignment in both X and Y. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call and thanks for documenting. Could also move it into a method AxisAlignment ToAxisAligment(SkAxixalignment align); with the requisite documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| location_in_atlas.y() + height_adjustment, // | ||
| glyph_size.width, // | ||
| glyph_size.height // | ||
| location_in_atlas.x() + 1, // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow this adjustment. Perhaps a short comment? If I had to guess, perhaps to account for errors in sample locations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the correction to the position later. But still not sure why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is part of the glyph padding so that we can avoid clearing the atlas. Though I didn't check in this PR, eventually we should be able to remove the clear.
| // --------------------------------------------------------------------------- | ||
| // Step 1: Determine if the atlas type and font glyph pairs are compatible | ||
| // with the current atlas and reuse if possible. | ||
| // with the current atlas and reuse if possible. Compute glyph sizes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also comute glyph sizes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more details
| //------------------------------------------------------------------------------ | ||
| /// @brief Determines the axis along which there is subpixel positioning. | ||
| /// | ||
| enum class AxisAlignment : uint8_t { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is find of course and not suggesting this be modified. But we also have type safe masks now. So this could be mask values with a mask defined as using AxisAlignmentMask = Mask<AxisAlignment>;.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really using this as a Mask right now, at least I dont think. I think I could rewrite things a bit to treat axis alignment as an off or on mask for which of X/Y have subpixel positioning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, this is fine.
| /// | ||
| struct SubpixelGlyph { | ||
| Glyph glyph; | ||
| Point subpixel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps subpixel_offset?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
Golden file changes are available for triage from new commit, Click here to view. |
…position rounding behavior, add subpixel X/Y/All/None positioning. (flutter/engine#53042)
…149169) flutter/engine@b175108...d032390 2024-05-28 [email protected] Roll Skia from 312160c7c920 to 848d9498fd68 (1 revision) (flutter/engine#53059) 2024-05-28 [email protected] [Impeller] Use scaled font to determine bounds, match Skia position rounding behavior, add subpixel X/Y/All/None positioning. (flutter/engine#53042) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…lutter#149169) flutter/engine@b175108...d032390 2024-05-28 [email protected] Roll Skia from 312160c7c920 to 848d9498fd68 (1 revision) (flutter/engine#53059) 2024-05-28 [email protected] [Impeller] Use scaled font to determine bounds, match Skia position rounding behavior, add subpixel X/Y/All/None positioning. (flutter/engine#53042) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Thx you for these fixes! If related, it would be great if this other issue could also be addressed: flutter/flutter#120857 Currently, The only viable workaround we’ve found is to wrap two |
Multiple fixes to text rendering that match skia behavior on almost all bugs I've found, except for the glyphs are still slightly too fine for some CJK text. The fixes are:
Compute the gylph size in the typographer context, using text size * scale factor text, instead of computing smaller bounds and scaling it up. This was not accurate and as a result we would positon glyphs incorrect by multiple pixels sometimes, causing uneven rows.
Match Skia's rounding behavior. previously we were rounding in multiple places, Skia rounds once. This is important to prevent jumping.
Use 4 subpixel X positions for rendering. This is the big one that ensures the visible layout matches exactly. Adds support for Y, both, and none positioning too. I couldn't find any examples of just Y or both. Some fonts may specify that have no subpixel positioning. So we don't bother to compute it for those.
Fixes flutter/flutter#138386 / mostly, except slightly not bold enough.
Fixes flutter/flutter#147577 / mostly, except slightly not bold enough.
Fixes flutter/flutter#140475
Fixes flutter/flutter#141467
Fixes flutter/flutter#135523
Fixes flutter/flutter#127815