-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Calculate align offset for each paragraph line (LineMetrics.left) #14537
Conversation
final ui.TextDirection textDirection; | ||
|
||
MeasurementResult.forParagraph( | ||
EngineParagraph paragraph, |
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.
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.
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.
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 :)
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.
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. |
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.
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({ |
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.
docs?
/// The text direction of the paragraph. | ||
final ui.TextDirection textDirection; | ||
|
||
MeasurementResult.forParagraph( |
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.
docs?
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 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 |
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.
nit: mimicks or implements? :)
* 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)
…(LineMetrics.left)" (flutter#14537) (flutter#15151)" This reverts commit a2bd950.
…rics.left) (flutter#14537)" (flutter#14569) This reverts commit 1ecfdcb.
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.