Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use visual runs and save ShapeResults in TextMetrics #46833

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chromium-wpt-export-bot
Copy link
Collaborator

A previous CL implemented TextMetrics::getSelectionRects() by saving
the logical runs produced by BidiParagraph. This approach can fail
when the direction of text in the canvas is set directly with
ctx.direction, as the visual order of the runs (and therefore the
correct selection rects) can change without modifying the order in which
the logical runs are processed.

This change uses BidiParagraph::GetVisualRuns() instead, to iterate the
runs in the visual order. To calculate selection rects from these runs,
it is necessary to save the starting x position and character offset in
the input string.

Additionally, in order to avoid shaping the text over and over again,
the ShapeResult cache is only generated the first time the new method
is called. A new struct was created to hold the information needed for
each run. We defer the actual shaping of its ShapeResult as to not
significantly affect the performance of ctx.measureText().

Bug: 341213359
Change-Id: Iba4c461cddafa3d00d309f9a48e848b75ca84ff6
Reviewed-on: https://chromium-review.googlesource.com/5593278
WPT-Export-Revision: 0a3e301c2c0cff2d7c47916821618ed3ce428e3a

A previous CL implemented `TextMetrics::getSelectionRects()` by saving
the logical runs produced by `BidiParagraph`. This approach can fail
when the direction of text in the canvas is set directly with
`ctx.direction`, as the visual order of the runs (and therefore the
correct selection rects) can change without modifying the order in which
the logical runs are processed.

This change uses `BidiParagraph::GetVisualRuns()` instead, to iterate the
runs in the visual order. To calculate selection rects from these runs,
it is necessary to save the starting x position and character offset in
the input string.

Additionally, in order to avoid shaping the text over and over again,
the `ShapeResult` cache is only generated the first time the new method
is called. A new struct was created to hold the information needed for
each run. We defer the actual shaping of its `ShapeResult` as to not
significantly affect the performance of `ctx.measureText()`.

Bug: 341213359
Change-Id: Iba4c461cddafa3d00d309f9a48e848b75ca84ff6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants