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
Add line boundary information to LineMetrics. #13727
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f38dfdc
Add line boundary information to Paragraph
gspencergoog d44bbcd
Add web API
gspencergoog 3f534dc
Changing return type for getWordBoundary to TextRange
gspencergoog 48502a1
Move to TextPosition, remove extra fields on LineMetrics (for now)
gspencergoog a249d84
Update comments.
gspencergoog 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1237,12 +1237,23 @@ abstract class Paragraph { | |
| /// within the text. | ||
| TextPosition getPositionForOffset(Offset offset); | ||
|
|
||
| /// Returns the [start, end] of the word at the given offset. Characters not | ||
| /// part of a word, such as spaces, symbols, and punctuation, have word breaks | ||
| /// on both sides. In such cases, this method will return [offset, offset+1]. | ||
| /// Word boundaries are defined more precisely in Unicode Standard Annex #29 | ||
| /// http://www.unicode.org/reports/tr29/#Word_Boundaries | ||
| List<int> getWordBoundary(dynamic position); | ||
| /// Returns the [TextRange] of the word at the given [TextPosition]. | ||
| /// | ||
| /// Characters not part of a word, such as spaces, symbols, and punctuation, | ||
| /// have word breaks on both sides. In such cases, this method will return | ||
| /// [offset, offset+1]. Word boundaries are defined more precisely in Unicode | ||
| /// Standard Annex #29 http://www.unicode.org/reports/tr29/#Word_Boundaries | ||
| TextRange getWordBoundary(TextPosition position); | ||
|
|
||
| /// Returns the [TextRange] of the line at the given [TextPosition]. | ||
| /// | ||
| /// The newline (if any) is returned as part of the range. | ||
| /// | ||
| /// Not valid until after layout. | ||
| /// | ||
| /// This can potentially be expensive, since it needs to compute the line | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The line metrics are computed as part of layout, so as long as it is used after layout, this should not be particularly expensive. We currently don't do any additional computation beyond that of layout to calculate the LineMetrics. What should be mentioned though is that this is invalid before layout.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, this warning can remain, as it depends on the implementation. Web or SkShaper may have more expensive implementations. It just so happens LibTxt computes this in layout. |
||
| /// metrics, so use it sparingly. | ||
| TextRange getLineBoundary(TextPosition position); | ||
|
|
||
| /// Returns a list of text boxes that enclose all placeholders in the paragraph. | ||
| /// | ||
|
|
@@ -1252,6 +1263,13 @@ abstract class Paragraph { | |
| /// where positive y values indicate down. | ||
| List<TextBox> getBoxesForPlaceholders(); | ||
|
|
||
| /// Returns the full list of [LineMetrics] that describe in detail the various | ||
| /// metrics of each laid out line. | ||
| /// | ||
| /// Not valid until after layout. | ||
| /// | ||
| /// This can potentially return a large amount of data, so it is not recommended | ||
| /// to repeatedly call this. Instead, cache the results. | ||
| List<LineMetrics> computeLineMetrics(); | ||
| } | ||
|
|
||
|
|
||
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.
Is there a reason this is implemented in C++ and not in Dart directly? (Implementing it in Dart would reduce unnecessary work since web can also use the same implementation).
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 have the history on why that is, but I assume the reason is that we didn't want to have to implement, test, and maintain the code, and it already existed in the text library. If that's the case, then I suspect that with the advent of web, it makes sense to make the investment and implement, test, and maintain it (since we'll need to do that anyhow for web).
It's possible that it is somehow linked to the text processing library that we use, though, so I'll defer to the engine team on that.
cc/ @jason-simmons @GaryQian
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.
In this case, it would be far more efficient to compute it in C++ instead of serializing and passing all the LineMetrics to dart, decoding, and processing it there.
This also keeps implementations consistent throughout the Paragraph API. Methods such as GetRectsForRange requires a significant computation that can only be done at engine level, and splitting implementation between dart and C++ would make it harder to maintain.