Use visual runs and save ShapeResults in TextMetrics #46833
Draft
+2,443
−26
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.
A previous CL implemented
TextMetrics::getSelectionRects()
by savingthe logical runs produced by
BidiParagraph
. This approach can failwhen the direction of text in the canvas is set directly with
ctx.direction
, as the visual order of the runs (and therefore thecorrect selection rects) can change without modifying the order in which
the logical runs are processed.
This change uses
BidiParagraph::GetVisualRuns()
instead, to iterate theruns 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 methodis called. A new struct was created to hold the information needed for
each run. We defer the actual shaping of its
ShapeResult
as to notsignificantly affect the performance of
ctx.measureText()
.Bug: 341213359
Change-Id: Iba4c461cddafa3d00d309f9a48e848b75ca84ff6
Reviewed-on: https://chromium-review.googlesource.com/5593278
WPT-Export-Revision: 0a3e301c2c0cff2d7c47916821618ed3ce428e3a