This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Support all combinations of GetRectsForRange styles #6591
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0f590c5
Support all combinations of GetRectsForRange styles
GaryQian e1b4e26
Merge branch 'master' of github.com:flutter/engine into textrects
GaryQian bd7f2b3
Move cacheable rects metrics to Layout.
GaryQian bbbfb7b
Reworked rects to use existing metrics
GaryQian 674a912
rects work
GaryQian d08cbe7
Fix init of max/min and improve kIncludeLineSpacingMiddle impl.
GaryQian cfa9967
Reorder RectStyle enums
GaryQian dc13fc3
Fix nits
GaryQian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,19 +59,36 @@ class Paragraph { | |
|
|
||
| // Options for various types of bounding boxes provided by | ||
| // GetRectsForRange(...). | ||
| // These options can be individually enabled, for example: | ||
| // | ||
| // (RectStyle::kTight | RectStyle::kExtendEndOfLine) | ||
| // | ||
| // provides tight bounding boxes and extends the last box per line to the end | ||
| // of the layout area. | ||
| enum RectStyle { | ||
| kNone = 0x0, // kNone cannot be combined with |. | ||
|
|
||
| // Provide tight bounding boxes that fit heights per span. Otherwise, the | ||
| // heights of spans are the max of the heights of the line the span belongs | ||
| // in. | ||
| kTight = 0x1 | ||
| enum class RectHeightStyle { | ||
| // Provide tight bounding boxes that fit heights per run. | ||
| kTight, | ||
|
|
||
| // The height of the boxes will be the maximum height of all runs in the | ||
| // line. All rects in the same line will be the same height. | ||
| kMax, | ||
|
|
||
| // Extends the top and/or bottom edge of the bounds to fully cover any line | ||
| // spacing. The top edge of each line should be the same as the bottom edge | ||
| // of the line above. There should be no gaps in vertical coverage given any | ||
| // ParagraphStyle line_height. | ||
| // | ||
| // The top and bottom of each rect will cover half of the | ||
| // space above and half of the space below the line. | ||
| kIncludeLineSpacingMiddle, | ||
| // The line spacing will be added to the top of the rect. | ||
| kIncludeLineSpacingTop, | ||
| // The line spacing will be added to the bottom of the rect. | ||
| kIncludeLineSpacingBottom | ||
| }; | ||
|
|
||
| enum class RectWidthStyle { | ||
| // Provide tight bounding boxes that fit widths to the runs of each line | ||
| // independently. | ||
| kTight, | ||
|
|
||
| // Extends the width of the last rect of each line to match the position of | ||
| // the widest rect over all the lines. | ||
| kMax | ||
| }; | ||
|
|
||
| struct PositionWithAffinity { | ||
|
|
@@ -158,7 +175,8 @@ class Paragraph { | |
| // end glyph indexes, including start and excluding end. | ||
| std::vector<TextBox> GetRectsForRange(size_t start, | ||
| size_t end, | ||
| RectStyle rect_style) const; | ||
| RectHeightStyle rect_height_style, | ||
| RectWidthStyle rect_width_style) const; | ||
|
|
||
| // Returns the index of the glyph that corresponds to the provided coordinate, | ||
| // with the top left corner as the origin, and +y direction as down. | ||
|
|
@@ -240,6 +258,24 @@ class Paragraph { | |
| std::vector<double> line_baselines_; | ||
| bool did_exceed_max_lines_; | ||
|
|
||
| // Metrics for use in GetRectsForRange(...); | ||
| // Per-line max metrics over all runs in a given line. | ||
| std::vector<SkScalar> line_max_spacings_; | ||
| std::vector<SkScalar> line_max_descent_; | ||
| std::vector<SkScalar> line_max_ascent_; | ||
| // Overall left and right extremes over all lines. | ||
| double max_right_; | ||
| double min_left_; | ||
|
|
||
| struct LineBoxMetrics { | ||
|
||
| std::vector<Paragraph::TextBox> boxes; | ||
| // Per-line metrics for max and min coordinates for left and right boxes. | ||
| // These metrics cannot be calculated in layout generically because of | ||
| // selections that do not cover the whole line. | ||
| SkScalar max_right = FLT_MIN; | ||
| SkScalar min_left = FLT_MAX; | ||
| }; | ||
|
|
||
| class BidiRun { | ||
| public: | ||
| BidiRun(size_t s, size_t e, TextDirection d, const TextStyle& st) | ||
|
|
||
Oops, something went wrong.
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.
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.
Remove the ternary operator here (similar to the change made to
adjusted_bottomabove)