github web-platform-tests/wpt merge_pr_46833

latest releases: merge_pr_49470, epochs/three_hourly/2024-12-03_06H, epochs/six_hourly/2024-12-03_06H...
6 months ago

Use visual runs and save ShapeResults in TextMetrics

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/c/chromium/src/+/5593278
Reviewed-by: Koji Ishii kojii@chromium.org
Commit-Queue: Andres Ricardo Perez andresrperez@chromium.org
Cr-Commit-Position: refs/heads/main@{#1322195}

Don't miss a new wpt release

NewReleases is sending notifications on new releases.