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

[web] Calculate align offset for each paragraph line (LineMetrics.left) #14537

Merged
merged 2 commits into from
Dec 18, 2019

Conversation

mdebbar
Copy link
Contributor

@mdebbar mdebbar commented Dec 17, 2019

We used to calculate a single _alignOffset for the whole paragraph, which works fine in the single-line case. But it falls apart when the paragraph has multiple lines.

The change in this PR does the "align offset" calculation for each line individually. This makes it possible to render multi-line paragraphs on canvas and correctly aligning them.

@mdebbar mdebbar added the platform-web Code specifically for the web engine label Dec 17, 2019
@mdebbar mdebbar requested a review from yjbanov December 17, 2019 23:50
@mdebbar mdebbar self-assigned this Dec 17, 2019
@auto-assign auto-assign bot requested a review from gaaclarke December 17, 2019 23:51
final ui.TextDirection textDirection;

MeasurementResult.forParagraph(
EngineParagraph paragraph,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we deconstruct the paragraph prior to calling the constructor? Otherwise, this API creates a temptation to store the paragraph in the MeasurementResult object, which could be very unsafe. At any moment the framework can draw the paragraph, lay it out again with different constraints, then draw it again, resulting in previous MeasurementResult objects holding onto a stale paragraph object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other APIs use the from nomenclature to indicate that the object is constructed based on another object but does not hold onto it (e.g. List.from), but to fully satisfy my paranoia I think I wouldn't use the paragraph at all :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I'll pass the textDirection and textAlign values individually.

@required double maxWidth,
}) {
final double emptySpace = maxWidth - lineWidth;
// WARNING: the [paragraph] may not be laid out yet at this point.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be useful to know why it matters for this function? E.g. you can add "This function must not use layout metrics, such as paragraph.height"

@@ -958,3 +984,28 @@ class MaxIntrinsicCalculator {
_lastHardLineEnd = hardLineEnd;
}
}

double calculateAlignOffsetForLine({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs?

/// The text direction of the paragraph.
final ui.TextDirection textDirection;

MeasurementResult.forParagraph(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted this constructor.

@@ -705,13 +714,15 @@ int _excludeTrailing(String text, int start, int end, CharPredicate predicate) {
/// It mimicks the Flutter engine's behavior when it comes to handling ellipsis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: mimicks or implements? :)

@mdebbar mdebbar requested a review from yjbanov December 18, 2019 20:44
@mdebbar mdebbar merged commit 1ecfdcb into flutter:master Dec 18, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
chingjun added a commit that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
chingjun added a commit that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Dec 19, 2019
chingjun pushed a commit to flutter/flutter that referenced this pull request Dec 19, 2019
* 988b8f1 Fix FontLoader does not remove the cache in web engine (flutter/engine#14536)

* 0aacac7 Roll src/third_party/skia 21df075cab00..e6a2ad81ab40 (1 commits) (flutter/engine#14552)

* 417dd7e Roll fuchsia/sdk/core/mac-amd64 from esDH2... to NHgyx... (flutter/engine#14554)

* f2e841d [Web] Fix pointer binding  (flutter/engine#14378)

* 105eb66 Roll src/third_party/skia e6a2ad81ab40..8fec4140f614 (17 commits) (flutter/engine#14557)

* 1ecfdcb [web] Calculate align offset for each paragraph line (LineMetrics.left) (flutter/engine#14537)

* dda3619 Roll src/third_party/dart 270966b16044..171059d27689 (19 commits) (flutter/engine#14558)

* 9c1bd8a Fixes Objective-C objects memory leaks (flutter/engine#14326)

* f2dbeb8 Reland Wire up Opacity on Fuchsia (flutter/engine#14559)

* 2f536e5 Roll fuchsia/sdk/core/linux-amd64 from jsuQq... to VdBKA... (flutter/engine#14560)

* 4312d37 Revert "[fuchsia] Add diagnostics directory to the set of remote dirs (#14470)" (flutter/engine#14566)

* 5c77ea1 Roll src/third_party/skia 8fec4140f614..9e0afb791ac2 (4 commits) (flutter/engine#14563)

* a09ff7c Roll src/third_party/dart 171059d27689..aa6709974dea (11 commits) (flutter/engine#14567)

* 0f90e65 Revert "[web] Calculate align offset for each paragraph line (LineMetrics.left) (#14537)" (flutter/engine#14569)
mdebbar added a commit to mdebbar/engine that referenced this pull request Jan 6, 2020
mdebbar added a commit to mdebbar/engine that referenced this pull request Jan 6, 2020
mdebbar added a commit to mdebbar/engine that referenced this pull request Jan 8, 2020
mdebbar added a commit that referenced this pull request Jan 8, 2020
NoamDev pushed a commit to NoamDev/engine that referenced this pull request Feb 27, 2020
NoamDev added a commit to NoamDev/engine that referenced this pull request Feb 27, 2020
filmil pushed a commit to filmil/engine that referenced this pull request Mar 13, 2020
filmil pushed a commit to filmil/engine that referenced this pull request Mar 13, 2020
filmil pushed a commit to filmil/engine that referenced this pull request Mar 13, 2020
@mdebbar mdebbar deleted the line_metrics_left branch April 15, 2021 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes platform-web Code specifically for the web engine
Projects
None yet
3 participants