[web] Initial rich measurement implementation (flutter/engine#22779)

This commit is contained in:
Mouad Debbar
2020-12-03 16:33:03 -08:00
committed by GitHub
parent 37b2722631
commit c1a4d77e5e
7 changed files with 1257 additions and 26 deletions

View File

@@ -530,6 +530,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/shadow.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/test_embedding.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text/canvas_paragraph.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text/font_collection.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text/layout_service.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text/line_break_properties.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text/line_breaker.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/text/measurement.dart

View File

@@ -125,6 +125,7 @@ part 'engine/services/serialization.dart';
part 'engine/shadow.dart';
part 'engine/test_embedding.dart';
part 'engine/text/font_collection.dart';
part 'engine/text/layout_service.dart';
part 'engine/text/line_break_properties.dart';
part 'engine/text/line_breaker.dart';
part 'engine/text/measurement.dart';

View File

@@ -34,39 +34,34 @@ class CanvasParagraph implements EngineParagraph {
/// The number of placeholders in this paragraph.
final int placeholderCount;
// Defaulting to -1 for non-laid-out paragraphs like the native engine does.
@override
double width = -1.0;
double get width => _layoutService.width;
@override
double height = 0.0;
double get height => _layoutService.height;
@override
double get longestLine {
assert(isLaidOut);
// TODO(mdebbar): Use the line metrics generated during layout to find out
// the longest line.
return 0.0;
}
double get longestLine => _layoutService.longestLine;
@override
double minIntrinsicWidth = 0.0;
double get minIntrinsicWidth => _layoutService.minIntrinsicWidth;
@override
double maxIntrinsicWidth = 0.0;
double get maxIntrinsicWidth => _layoutService.maxIntrinsicWidth;
@override
double alphabeticBaseline = -1.0;
double get alphabeticBaseline => _layoutService.alphabeticBaseline;
@override
double ideographicBaseline = -1.0;
double get ideographicBaseline => _layoutService.ideographicBaseline;
@override
bool get didExceedMaxLines => _didExceedMaxLines;
bool _didExceedMaxLines = false;
bool get didExceedMaxLines => _layoutService.didExceedMaxLines;
ui.ParagraphConstraints? _lastUsedConstraints;
late final TextLayoutService _layoutService = TextLayoutService(this);
@override
void layout(ui.ParagraphConstraints constraints) {
// When constraint width has a decimal place, we floor it to avoid getting
@@ -88,8 +83,7 @@ class CanvasParagraph implements EngineParagraph {
if (Profiler.isBenchmarkMode) {
stopwatch = Stopwatch()..start();
}
// TODO(mdebbar): Perform the layout using a new rich text measurement service.
// TODO(mdebbar): Don't forget to update `_didExceedMaxLines`.
_layoutService.performLayout(constraints);
if (Profiler.isBenchmarkMode) {
stopwatch.stop();
Profiler.instance
@@ -161,7 +155,7 @@ class CanvasParagraph implements EngineParagraph {
isSpan: true,
);
domRenderer.append(element, spanElement);
} else if (span is ParagraphPlaceholder) {
} else if (span is PlaceholderSpan) {
domRenderer.append(
element,
_createPlaceholderElement(placeholder: span),
@@ -234,8 +228,7 @@ class CanvasParagraph implements EngineParagraph {
@override
List<ui.LineMetrics> computeLineMetrics() {
// TODO(mdebbar): After layout, line metrics should be available.
return <ui.LineMetrics>[];
return _layoutService.lines;
}
}
@@ -243,7 +236,11 @@ class CanvasParagraph implements EngineParagraph {
///
/// These spans are stored as a flat list in the paragraph object.
abstract class ParagraphSpan {
const ParagraphSpan();
/// The index of the beginning of the range of text represented by this span.
int get start;
/// The index of the end of the range of text represented by this span.
int get end;
}
/// Represent a span of text in the paragraph.
@@ -254,7 +251,7 @@ abstract class ParagraphSpan {
/// Instead of keeping spans and styles in a tree hierarchy like the framework
/// does, we flatten the structure and resolve/merge all the styles from parent
/// nodes.
class FlatTextSpan extends ParagraphSpan {
class FlatTextSpan implements ParagraphSpan {
/// Creates a [FlatTextSpan] with the given [style], representing the span of
/// text in the range between [start] and [end].
FlatTextSpan({
@@ -266,10 +263,10 @@ class FlatTextSpan extends ParagraphSpan {
/// The resolved style of the span.
final EngineTextStyle style;
/// The index of the beginning of the range of text represented by this span.
@override
final int start;
/// The index of the end of the range of text represented by this span.
@override
final int end;
String textOf(CanvasParagraph paragraph) {
@@ -279,6 +276,31 @@ class FlatTextSpan extends ParagraphSpan {
}
}
class PlaceholderSpan extends ParagraphPlaceholder implements ParagraphSpan {
PlaceholderSpan(
int index,
double width,
double height,
ui.PlaceholderAlignment alignment, {
required double baselineOffset,
required ui.TextBaseline baseline,
}) : start = index,
end = index,
super(
width,
height,
alignment,
baselineOffset: baselineOffset,
baseline: baseline,
);
@override
final int start;
@override
final int end;
}
/// Represents a node in the tree of text styles pushed to [ui.ParagraphBuilder].
///
/// The [ui.ParagraphBuilder.pushText] and [ui.ParagraphBuilder.pop] operations
@@ -551,7 +573,8 @@ class CanvasParagraphBuilder implements ui.ParagraphBuilder {
_placeholderCount++;
_placeholderScales.add(scale);
_spans.add(ParagraphPlaceholder(
_spans.add(PlaceholderSpan(
_plainTextBuffer.length,
width * scale,
height * scale,
alignment,

View File

@@ -0,0 +1,381 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.12
part of engine;
/// Performs layout on a [CanvasParagraph].
///
/// It uses a [html.CanvasElement] to measure text.
class TextLayoutService {
TextLayoutService(this.paragraph);
final CanvasParagraph paragraph;
final html.CanvasRenderingContext2D context = html.CanvasElement().context2D;
// *** Results of layout *** //
// Look at the Paragraph class for documentation of the following properties.
double width = -1.0;
double height = 0.0;
double longestLine = 0.0;
double minIntrinsicWidth = 0.0;
double maxIntrinsicWidth = 0.0;
double alphabeticBaseline = -1.0;
double ideographicBaseline = -1.0;
bool didExceedMaxLines = false;
final List<EngineLineMetrics> lines = <EngineLineMetrics>[];
// *** Convenient shortcuts used during layout *** //
int? get maxLines => paragraph.paragraphStyle._maxLines;
bool get unlimitedLines => maxLines == null;
bool get hasEllipsis => paragraph.paragraphStyle._ellipsis != null;
/// Performs the layout on a paragraph given the [constraints].
///
/// The function starts by resetting all layout-related properties. Then it
/// starts looping through the paragraph to calculate all layout metrics.
///
/// It uses a [Spanometer] to perform measurements within spans of the
/// paragraph. It also uses [LineBuilders] to generate [EngineLineMetrics] as
/// it iterates through the paragraph.
///
/// The main loop keeps going until:
///
/// 1. The end of the paragraph is reached (i.e. LineBreakType.endOfText).
/// 2. Enough lines have been computed to satisfy [maxLines].
/// 3. An ellipsis is appended because of an overflow.
void performLayout(ui.ParagraphConstraints constraints) {
final int spanCount = paragraph.spans.length;
// Reset results from previous layout.
width = constraints.width;
height = 0.0;
longestLine = 0.0;
minIntrinsicWidth = 0.0;
maxIntrinsicWidth = 0.0;
didExceedMaxLines = false;
lines.clear();
final Spanometer spanometer = Spanometer(paragraph, context);
int spanIndex = 0;
ParagraphSpan span = paragraph.spans[0];
LineBuilder currentLine = LineBuilder.first(paragraph, spanometer);
LineBuilder maxIntrinsicLine = LineBuilder.first(paragraph, spanometer);
// The only way to exit this while loop is by hitting the `break;` statement
// when we reach the `endOfText` line break.
while (true) {
// *********************************************** //
// *** HANDLE HARD LINE BREAKS AND END OF TEXT *** //
// *********************************************** //
if (currentLine.end.isHard) {
if (currentLine.isNotEmpty) {
lines.add(currentLine.build());
}
if (currentLine.end.type == LineBreakType.endOfText) {
break;
} else {
currentLine = currentLine.nextLine();
}
}
// ********************************* //
// *** THE MAIN MEASUREMENT PART *** //
// ********************************* //
if (span is PlaceholderSpan) {
spanometer.currentSpan = null;
final double lineWidth = currentLine.width + span.width;
// TODO(mdebbar): Consider how placeholders affect min/max intrinsics.
if (lineWidth <= constraints.width) {
// The placeholder fits on the current line.
// TODO(mdebbar):
// (1) adjust the current line's height to fit the placeholder.
// (2) update accumulated line width.
} else {
// The placeholder can't fit on the current line.
// TODO(mdebbar):
// (1) create a line.
// (2) adjust the new line's height to fit the placeholder.
// (3) update `lineStart`, etc.
}
} else if (span is FlatTextSpan) {
spanometer.currentSpan = span;
final LineBreakResult nextBreak = currentLine.findNextBreak(span.end);
final double additionalWidth =
currentLine.getAdditionalWidthTo(nextBreak);
// For the purpose of max intrinsic width, we don't care if the line
// fits within the constraints or not. So we always extend it.
if (maxIntrinsicLine.end != nextBreak) {
maxIntrinsicLine.extendTo(nextBreak);
}
if (currentLine.width + additionalWidth <= constraints.width) {
// TODO(mdebbar): Handle the case when `nextBreak` is just a span end
// that shouldn't extend the line yet.
// The line can extend to `nextBreak` without overflowing.
currentLine.extendTo(nextBreak);
} else {
// The chunk of text can't fit into the current line.
final bool isLastLine =
(hasEllipsis && unlimitedLines) || lines.length + 1 == maxLines;
if (isLastLine && hasEllipsis) {
// We've reached the line that requires an ellipsis to be appended
// to it.
// TODO(mdebbar): Remove this line and implement overflow ellipsis.
currentLine.extendTo(nextBreak);
} else if (currentLine.isEmpty) {
// The current line is still empty, which means we are dealing
// with a single block of text that doesn't fit in a single line.
// We need to force-break it.
// TODO(mdebbar): Remove this line and implement force-breaking.
currentLine.extendTo(nextBreak);
} else {
// Normal line break.
lines.add(currentLine.build());
currentLine = currentLine.nextLine();
}
}
} else {
throw UnimplementedError('Unknown span type: ${span.runtimeType}');
}
// ************************************************ //
// *** LONGEST LINE && MAX/MIN INTRINSIC WIDTHS *** //
// ************************************************ //
if (longestLine < currentLine.width) {
longestLine = currentLine.width;
}
if (minIntrinsicWidth < currentLine.widthOfLastExtension) {
minIntrinsicWidth = currentLine.widthOfLastExtension;
}
if (maxIntrinsicLine.end.isHard) {
// Max intrinsic width includes the width of trailing spaces.
if (maxIntrinsicWidth < maxIntrinsicLine.widthIncludingSpace) {
maxIntrinsicWidth = maxIntrinsicLine.widthIncludingSpace;
}
maxIntrinsicLine = maxIntrinsicLine.nextLine();
}
// ********************************************* //
// *** ADVANCE TO THE NEXT SPAN IF NECESSARY *** //
// ********************************************* //
// Only go to the next span if we've reached the end of this span.
if (currentLine.end.index >= span.end && spanIndex < spanCount - 1) {
span = paragraph.spans[++spanIndex];
}
}
}
}
/// Builds instances of [EngineLineMetrics] for the given [paragraph].
///
/// Usage of this class starts by calling [LineBuilder.first] to start building
/// the first line of the paragraph.
///
/// Then new line breaks can be found by calling [LineBuilder.findNextBreak].
///
/// The line can be extended one or more times before it's built by calling
/// [LineBuilder.build] which generates the [EngineLineMetrics] instace.
///
/// To start building the next line, simply call [LineBuilder.nextLine] which
/// creates a new [LineBuilder] that can be extended and built and so on.
class LineBuilder {
LineBuilder._(
this.paragraph,
this.spanometer, {
required this.start,
required this.lineNumber,
}) : end = start;
/// Creates a [LineBuilder] for the first line in a paragraph.
factory LineBuilder.first(CanvasParagraph paragraph, Spanometer spanometer) {
return LineBuilder._(
paragraph,
spanometer,
lineNumber: 0,
start: LineBreakResult.sameIndex(0, LineBreakType.prohibited),
);
}
final CanvasParagraph paragraph;
final Spanometer spanometer;
final LineBreakResult start;
final int lineNumber;
LineBreakResult end;
/// The width of the line so far, excluding trailing white space.
double width = 0.0;
/// The width of trailing white space in the line.
double widthOfTrailingSpace = 0.0;
/// The width of the line so far, including trailing white space.
double get widthIncludingSpace => width + widthOfTrailingSpace;
/// The width of the last extension to the line made via [extendTo].
double widthOfLastExtension = 0.0;
bool get isEmpty => start == end;
bool get isNotEmpty => !isEmpty;
/// Measures the width of text between the end of this line and [newEnd].
double getAdditionalWidthTo(LineBreakResult newEnd) {
// If the extension is all made of space characters, it shouldn't add
// anything to the width.
if (end.index == newEnd.indexWithoutTrailingSpaces) {
return 0.0;
}
return widthOfTrailingSpace + spanometer.measure(end, newEnd);
}
/// Extends the line by setting a [newEnd].
void extendTo(LineBreakResult newEnd) {
// If the current end of the line is a hard break, the line shouldn't be
// extended any further.
assert(
isEmpty || !end.isHard,
'Cannot extend a line that ends with a hard break.',
);
// TODO(mdebbar): Handle the case where the entire extension is made of spaces.
widthOfLastExtension = spanometer.measure(end, newEnd);
final double additionalWidthIncludingSpace =
spanometer.measureIncludingSpace(end, newEnd);
// Add the width of previous trailing space.
width += widthOfTrailingSpace + widthOfLastExtension;
widthOfTrailingSpace = additionalWidthIncludingSpace - widthOfLastExtension;
end = newEnd;
}
/// Builds the [EngineLineMetrics] instance that represents this line.
EngineLineMetrics build() {
final String text = paragraph.toPlainText();
return EngineLineMetrics.withText(
text.substring(start.index, end.indexWithoutTrailingNewlines),
startIndex: start.index,
endIndex: end.index,
endIndexWithoutNewlines: end.indexWithoutTrailingNewlines,
hardBreak: end.isHard,
width: width,
widthWithTrailingSpaces: width + widthOfTrailingSpace,
// TODO(mdebbar): Calculate actual align offset.
left: 0.0,
lineNumber: lineNumber,
);
}
/// Finds the next line break after the end of this line.
LineBreakResult findNextBreak(int maxEnd) {
return nextLineBreak(paragraph.toPlainText(), end.index, maxEnd: maxEnd);
}
/// Creates a new [LineBuilder] to build the next line in the paragraph.
LineBuilder nextLine() {
return LineBuilder._(
paragraph,
spanometer,
start: end,
lineNumber: lineNumber + 1,
);
}
}
/// Responsible for taking measurements within spans of a paragraph.
///
/// Can't perform measurements across spans. To measure across spans, multiple
/// measurements have to be taken.
///
/// Before performing any measurement, the [currentSpan] has to be set. Once
/// it's set, the [Spanometer] updates the underlying [context] so that
/// subsequent measurements use the correct styles.
class Spanometer {
Spanometer(this.paragraph, this.context);
final CanvasParagraph paragraph;
final html.CanvasRenderingContext2D context;
String _cssFontString = '';
double? get letterSpacing => _currentSpan!.style._letterSpacing;
FlatTextSpan? _currentSpan;
set currentSpan(FlatTextSpan? span) {
if (span == _currentSpan) {
return;
}
_currentSpan = span;
// No need to update css font string when `span` is null.
if (span == null) {
return;
}
// Update the font string if it's different from the previous span.
final String cssFontString = span.style.cssFontString;
if (_cssFontString != cssFontString) {
_cssFontString = cssFontString;
context.font = cssFontString;
}
}
/// Measures the width of text between two line breaks.
///
/// Doesn't include the width of any trailing white space.
double measure(LineBreakResult start, LineBreakResult end) {
return _measure(start.index, end.indexWithoutTrailingSpaces);
}
/// Measures the width of text between two line breaks.
///
/// Includes the width of trailing white space, if any.
double measureIncludingSpace(LineBreakResult start, LineBreakResult end) {
return _measure(start.index, end.indexWithoutTrailingNewlines);
}
double _measure(int start, int end) {
assert(_currentSpan != null);
final FlatTextSpan span = _currentSpan!;
// Make sure the range is within the current span.
assert(start >= span.start && start <= span.end);
assert(end >= span.start && end <= span.end);
final String text = paragraph.toPlainText();
return _measureSubstring(
context,
text,
start,
end,
letterSpacing: letterSpacing,
);
}
}

View File

@@ -1589,7 +1589,7 @@ class DomParagraphBuilder implements ui.ParagraphBuilder {
/// Holds information for a placeholder in a paragraph.
///
/// [width], [height] and [baselineOffset] are expected to be already scaled.
class ParagraphPlaceholder extends ParagraphSpan {
class ParagraphPlaceholder {
ParagraphPlaceholder(
this.width,
this.height,

View File

@@ -0,0 +1,142 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.12
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
TestLine l(
String? displayText,
int? startIndex,
int? endIndex, {
int? endIndexWithoutNewlines,
bool? hardBreak,
double? width,
double? widthWithTrailingSpaces,
double? left,
}) {
return TestLine(
displayText: displayText,
startIndex: startIndex,
endIndex: endIndex,
endIndexWithoutNewlines: endIndexWithoutNewlines,
hardBreak: hardBreak,
width: width,
widthWithTrailingSpaces: widthWithTrailingSpaces,
left: left,
);
}
void expectLines(CanvasParagraph paragraph, List<TestLine> expectedLines) {
final List<EngineLineMetrics> lines =
paragraph.computeLineMetrics() as List<EngineLineMetrics>;
expect(lines, hasLength(expectedLines.length));
for (int i = 0; i < lines.length; i++) {
final EngineLineMetrics line = lines[i];
final TestLine expectedLine = expectedLines[i];
expect(
line.lineNumber,
i,
reason: '${i}th line had the wrong `lineNumber`. Expected: $i. Actual: ${line.lineNumber}',
);
if (expectedLine.displayText != null) {
expect(
line.displayText,
expectedLine.displayText,
reason:
'${i}th line had a different `displayText` value: "${line.displayText}" vs. "${expectedLine.displayText}"',
);
}
if (expectedLine.startIndex != null) {
expect(
line.startIndex,
expectedLine.startIndex,
reason:
'${i}th line had a different `startIndex` value: "${line.startIndex}" vs. "${expectedLine.startIndex}"',
);
}
if (expectedLine.endIndex != null) {
expect(
line.endIndex,
expectedLine.endIndex,
reason:
'${i}th line had a different `endIndex` value: "${line.endIndex}" vs. "${expectedLine.endIndex}"',
);
}
if (expectedLine.endIndexWithoutNewlines != null) {
expect(
line.endIndexWithoutNewlines,
expectedLine.endIndexWithoutNewlines,
reason:
'${i}th line had a different `endIndexWithoutNewlines` value: "${line.endIndexWithoutNewlines}" vs. "${expectedLine.endIndexWithoutNewlines}"',
);
}
if (expectedLine.hardBreak != null) {
expect(
line.hardBreak,
expectedLine.hardBreak,
reason:
'${i}th line had a different `hardBreak` value: "${line.hardBreak}" vs. "${expectedLine.hardBreak}"',
);
}
if (expectedLine.height != null) {
expect(
line.height,
expectedLine.height,
reason:
'${i}th line had a different `height` value: "${line.height}" vs. "${expectedLine.height}"',
);
}
if (expectedLine.width != null) {
expect(
line.width,
expectedLine.width,
reason:
'${i}th line had a different `width` value: "${line.width}" vs. "${expectedLine.width}"',
);
}
if (expectedLine.widthWithTrailingSpaces != null) {
expect(
line.widthWithTrailingSpaces,
expectedLine.widthWithTrailingSpaces,
reason:
'${i}th line had a different `widthWithTrailingSpaces` value: "${line.widthWithTrailingSpaces}" vs. "${expectedLine.widthWithTrailingSpaces}"',
);
}
if (expectedLine.left != null) {
expect(
line.left,
expectedLine.left,
reason:
'${i}th line had a different `left` value: "${line.left}" vs. "${expectedLine.left}"',
);
}
}
}
class TestLine {
TestLine({
this.displayText,
this.startIndex,
this.endIndex,
this.endIndexWithoutNewlines,
this.hardBreak,
this.height,
this.width,
this.widthWithTrailingSpaces,
this.left,
});
final String? displayText;
final int? startIndex;
final int? endIndex;
final int? endIndexWithoutNewlines;
final bool? hardBreak;
final double? height;
final double? width;
final double? widthWithTrailingSpaces;
final double? left;
}

View File

@@ -0,0 +1,683 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.12
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;
import 'layout_service_helper.dart';
const bool skipForceBreak = true;
const bool skipOverflow = true;
const bool skipMaxLines = true;
const bool skipTextAlign = true;
const bool skipWordSpacing = true;
final EngineParagraphStyle ahemStyle = EngineParagraphStyle(
fontFamily: 'ahem',
fontSize: 10,
);
ui.ParagraphConstraints constrain(double width) {
return ui.ParagraphConstraints(width: width);
}
CanvasParagraph plain(
EngineParagraphStyle style,
String text, {
EngineTextStyle? textStyle,
}) {
final CanvasParagraphBuilder builder = CanvasParagraphBuilder(style);
if (textStyle != null) {
builder.pushStyle(textStyle);
}
builder.addText(text);
return builder.build();
}
void main() {
internalBootstrapBrowserTest(() => testMain);
}
void testMain() async {
await ui.webOnlyInitializeTestDomRenderer();
test('preserves whitespace when measuring', () {
CanvasParagraph paragraph;
// leading whitespaces
paragraph = plain(ahemStyle, ' abc')..layout(constrain(double.infinity));
expect(paragraph.maxIntrinsicWidth, 60);
expect(paragraph.minIntrinsicWidth, 30);
// expect(paragraph.height, 10);
expectLines(paragraph, [
l(' abc', 0, 6, hardBreak: true, width: 60.0),
]);
// trailing whitespaces
paragraph = plain(ahemStyle, 'abc ')..layout(constrain(double.infinity));
expect(paragraph.maxIntrinsicWidth, 60);
expect(paragraph.minIntrinsicWidth, 30);
// expect(paragraph.height, 10);
expectLines(paragraph, [
l('abc ', 0, 6, hardBreak: true, width: 30.0),
]);
// mixed whitespaces
paragraph = plain(ahemStyle, ' ab c ')
..layout(constrain(double.infinity));
expect(paragraph.maxIntrinsicWidth, 100);
expect(paragraph.minIntrinsicWidth, 20);
// expect(paragraph.height, 10);
expectLines(paragraph, [
l(' ab c ', 0, 10, hardBreak: true, width: 80.0, left: 0.0),
]);
// single whitespace
paragraph = plain(ahemStyle, ' ')..layout(constrain(double.infinity));
expect(paragraph.maxIntrinsicWidth, 10);
expect(paragraph.minIntrinsicWidth, 0);
// expect(paragraph.height, 10);
expectLines(paragraph, [
l(' ', 0, 1, hardBreak: true, width: 0.0, left: 0.0),
]);
// whitespace only
paragraph = plain(ahemStyle, ' ')..layout(constrain(double.infinity));
expect(paragraph.maxIntrinsicWidth, 50);
expect(paragraph.minIntrinsicWidth, 0);
// expect(paragraph.height, 10);
expectLines(paragraph, [
l(' ', 0, 5, hardBreak: true, width: 0.0, left: 0.0),
]);
});
test('uses single-line when text can fit without wrapping', () {
final CanvasParagraph paragraph = plain(ahemStyle, '12345')
..layout(constrain(50.0));
// Should fit on a single line.
expect(paragraph.maxIntrinsicWidth, 50);
expect(paragraph.minIntrinsicWidth, 50);
expect(paragraph.width, 50);
// expect(paragraph.height, 10);
expectLines(paragraph, [
l('12345', 0, 5, hardBreak: true, width: 50.0, left: 0.0),
]);
});
test('simple multi-line text', () {
final CanvasParagraph paragraph = plain(ahemStyle, 'foo bar baz')
..layout(constrain(70.0));
expect(paragraph.maxIntrinsicWidth, 110);
expect(paragraph.minIntrinsicWidth, 30);
expect(paragraph.width, 70);
// expect(paragraph.height, 20);
expectLines(paragraph, [
l('foo bar ', 0, 8, hardBreak: false, width: 70.0, left: 0.0),
l('baz', 8, 11, hardBreak: true, width: 30.0, left: 0.0),
]);
});
test('uses multi-line for long text', () {
CanvasParagraph paragraph;
// The long text doesn't fit in 50px of width, so it needs to wrap.
paragraph = plain(ahemStyle, '1234567890')..layout(constrain(50.0));
expect(paragraph.maxIntrinsicWidth, 100);
expect(paragraph.minIntrinsicWidth, 100);
expect(paragraph.width, 50);
// expect(paragraph.height, 20);
expectLines(paragraph, [
l('12345', 0, 5, hardBreak: false, width: 50.0, left: 0.0),
l('67890', 5, 10, hardBreak: true, width: 50.0, left: 0.0),
]);
// The first word is force-broken twice.
paragraph = plain(ahemStyle, 'abcdefghijk lm')..layout(constrain(50.0));
expect(paragraph.maxIntrinsicWidth, 140);
expect(paragraph.minIntrinsicWidth, 110);
expect(paragraph.width, 50);
// expect(paragraph.height, 30);
expectLines(paragraph, [
l('abcde', 0, 5, hardBreak: false, width: 50.0, left: 0.0),
l('fghij', 5, 10, hardBreak: false, width: 50.0, left: 0.0),
l('k lm', 10, 14, hardBreak: true, width: 40.0, left: 0.0),
]);
// Constraints aren't enough even for a single character. In this case,
// we show a minimum of one character per line.
paragraph = plain(ahemStyle, 'AA')..layout(constrain(8.0));
expect(paragraph.maxIntrinsicWidth, 20);
expect(paragraph.minIntrinsicWidth, 20);
expect(paragraph.width, 8);
// expect(paragraph.height, 20);
expectLines(paragraph, [
l('A', 0, 1, hardBreak: false, width: 10.0, left: 0.0),
l('A', 1, 2, hardBreak: true, width: 10.0, left: 0.0),
]);
// Extremely narrow constraints with new line in the middle.
paragraph = plain(ahemStyle, 'AA\nA')..layout(constrain(8.0));
expect(paragraph.maxIntrinsicWidth, 20);
expect(paragraph.minIntrinsicWidth, 20);
expect(paragraph.width, 8);
// expect(paragraph.height, 30);
expectLines(paragraph, [
l('A', 0, 1, hardBreak: false, width: 10.0, left: 0.0),
l('A', 1, 3, hardBreak: true, width: 10.0, left: 0.0),
l('A', 3, 4, hardBreak: true, width: 10.0, left: 0.0),
]);
// Extremely narrow constraints with new line in the end.
paragraph = plain(ahemStyle, 'AAA\n')..layout(constrain(8.0));
expect(paragraph.maxIntrinsicWidth, 30);
expect(paragraph.minIntrinsicWidth, 30);
expect(paragraph.width, 8);
// expect(paragraph.height, 40);
expectLines(paragraph, [
l('A', 0, 1, hardBreak: false, width: 10.0, left: 0.0),
l('A', 1, 2, hardBreak: false, width: 10.0, left: 0.0),
l('A', 2, 4, hardBreak: true, width: 10.0, left: 0.0),
l('', 4, 4, hardBreak: true, width: 0.0, left: 0.0),
]);
}, skip: skipForceBreak);
test('uses multi-line for text that contains new-line', () {
final CanvasParagraph paragraph = plain(ahemStyle, '12\n34')
..layout(constrain(50.0));
// Text containing newlines should always be drawn in multi-line mode.
expect(paragraph.maxIntrinsicWidth, 20);
expect(paragraph.minIntrinsicWidth, 20);
expect(paragraph.width, 50);
// expect(paragraph.height, 20);
expectLines(paragraph, [
l('12', 0, 3, hardBreak: true, width: 20.0, left: 0.0),
l('34', 3, 5, hardBreak: true, width: 20.0, left: 0.0),
]);
});
test('empty lines', () {
CanvasParagraph paragraph;
// Empty lines in the beginning.
paragraph = plain(ahemStyle, '\n\n1234')..layout(constrain(50.0));
expect(paragraph.maxIntrinsicWidth, 40);
expect(paragraph.minIntrinsicWidth, 40);
// expect(paragraph.height, 30);
expectLines(paragraph, [
l('', 0, 1, hardBreak: true, width: 0.0, left: 0.0),
l('', 1, 2, hardBreak: true, width: 0.0, left: 0.0),
l('1234', 2, 6, hardBreak: true, width: 40.0, left: 0.0),
]);
// Empty lines in the middle.
paragraph = plain(ahemStyle, '12\n\n345')..layout(constrain(50.0));
expect(paragraph.maxIntrinsicWidth, 30);
expect(paragraph.minIntrinsicWidth, 30);
// expect(paragraph.height, 30);
expectLines(paragraph, [
l('12', 0, 3, hardBreak: true, width: 20.0, left: 0.0),
l('', 3, 4, hardBreak: true, width: 0.0, left: 0.0),
l('345', 4, 7, hardBreak: true, width: 30.0, left: 0.0),
]);
// Empty lines in the end.
paragraph = plain(ahemStyle, '1234\n\n')..layout(constrain(50.0));
expect(paragraph.maxIntrinsicWidth, 40);
expect(paragraph.minIntrinsicWidth, 40);
// expect(paragraph.height, 30);
expectLines(paragraph, [
l('1234', 0, 5, hardBreak: true, width: 40.0, left: 0.0),
l('', 5, 6, hardBreak: true, width: 0.0, left: 0.0),
l('', 6, 6, hardBreak: true, width: 0.0, left: 0.0),
]);
});
test(
'wraps multi-line text correctly when constraint width is infinite',
() {
final CanvasParagraph paragraph = plain(ahemStyle, '123\n456 789')
..layout(constrain(double.infinity));
expect(paragraph.maxIntrinsicWidth, 70);
expect(paragraph.minIntrinsicWidth, 30);
expect(paragraph.width, double.infinity);
// expect(paragraph.height, 20);
expectLines(paragraph, [
l('123', 0, 4, hardBreak: true, width: 30.0, left: 0.0),
l('456 789', 4, 11, hardBreak: true, width: 70.0, left: 0.0),
]);
},
);
test('takes letter spacing into account', () {
final EngineTextStyle spacedTextStyle =
EngineTextStyle.only(letterSpacing: 3);
final CanvasParagraph spacedText =
plain(ahemStyle, 'abc', textStyle: spacedTextStyle)
..layout(constrain(100.0));
expect(spacedText.minIntrinsicWidth, 39);
expect(spacedText.maxIntrinsicWidth, 39);
});
test('takes word spacing into account', () {
final CanvasParagraph normalText = plain(ahemStyle, 'a b c')
..layout(constrain(100.0));
final CanvasParagraph spacedText = plain(ahemStyle, 'a b c',
textStyle: EngineTextStyle.only(wordSpacing: 1.5))
..layout(constrain(100.0));
expect(
normalText.maxIntrinsicWidth < spacedText.maxIntrinsicWidth,
isTrue,
);
}, skip: skipWordSpacing);
test('minIntrinsicWidth', () {
CanvasParagraph paragraph;
// Simple case.
paragraph = plain(ahemStyle, 'abc de fghi')..layout(constrain(50.0));
expect(paragraph.minIntrinsicWidth, 40);
expectLines(paragraph, [
l('abc ', 0, 4, hardBreak: false, width: 30.0, left: 0.0),
l('de ', 4, 7, hardBreak: false, width: 20.0, left: 0.0),
l('fghi', 7, 11, hardBreak: true, width: 40.0, left: 0.0),
]);
// With new lines.
paragraph = plain(ahemStyle, 'abcd\nef\nghi')..layout(constrain(50.0));
expect(paragraph.minIntrinsicWidth, 40);
expectLines(paragraph, [
l('abcd', 0, 5, hardBreak: true, width: 40.0, left: 0.0),
l('ef', 5, 8, hardBreak: true, width: 20.0, left: 0.0),
l('ghi', 8, 11, hardBreak: true, width: 30.0, left: 0.0),
]);
// With trailing whitespace.
paragraph = plain(ahemStyle, 'abcd efg')..layout(constrain(50.0));
expect(paragraph.minIntrinsicWidth, 40);
expectLines(paragraph, [
l('abcd ', 0, 10, hardBreak: false, width: 40.0, left: 0.0),
l('efg', 10, 13, hardBreak: true, width: 30.0, left: 0.0),
]);
// With trailing whitespace and new lines.
paragraph = plain(ahemStyle, 'abc \ndefg')..layout(constrain(50.0));
expect(paragraph.minIntrinsicWidth, 40);
expectLines(paragraph, [
l('abc ', 0, 8, hardBreak: true, width: 30.0, left: 0.0),
l('defg', 8, 12, hardBreak: true, width: 40.0, left: 0.0),
]);
if (!skipForceBreak) {
// Very long text.
paragraph = plain(ahemStyle, 'AAAAAAAAAAAA')..layout(constrain(50.0));
expect(paragraph.minIntrinsicWidth, 120);
expectLines(paragraph, [
l('AAAAA', 0, 5, hardBreak: false, width: 50.0, left: 0.0),
l('AAAAA', 5, 10, hardBreak: false, width: 50.0, left: 0.0),
l('AA', 10, 12, hardBreak: true, width: 20.0, left: 0.0),
]);
}
});
test('maxIntrinsicWidth', () {
CanvasParagraph paragraph;
// Simple case.
paragraph = plain(ahemStyle, 'abc de fghi')..layout(constrain(50.0));
expect(paragraph.maxIntrinsicWidth, 110);
expectLines(paragraph, [
l('abc ', 0, 4, hardBreak: false, width: 30.0, left: 0.0),
l('de ', 4, 7, hardBreak: false, width: 20.0, left: 0.0),
l('fghi', 7, 11, hardBreak: true, width: 40.0, left: 0.0),
]);
// With new lines.
paragraph = plain(ahemStyle, 'abcd\nef\nghi')..layout(constrain(50.0));
expect(paragraph.maxIntrinsicWidth, 40);
expectLines(paragraph, [
l('abcd', 0, 5, hardBreak: true, width: 40.0, left: 0.0),
l('ef', 5, 8, hardBreak: true, width: 20.0, left: 0.0),
l('ghi', 8, 11, hardBreak: true, width: 30.0, left: 0.0),
]);
// With long whitespace.
paragraph = plain(ahemStyle, 'abcd efg')..layout(constrain(50.0));
expect(paragraph.maxIntrinsicWidth, 100);
expectLines(paragraph, [
l('abcd ', 0, 7, hardBreak: false, width: 40.0, left: 0.0),
l('efg', 7, 10, hardBreak: true, width: 30.0, left: 0.0),
]);
// With trailing whitespace.
paragraph = plain(ahemStyle, 'abc def ')..layout(constrain(50.0));
expect(paragraph.maxIntrinsicWidth, 100);
expectLines(paragraph, [
l('abc ', 0, 4, hardBreak: false, width: 30.0, left: 0.0),
l('def ', 4, 10, hardBreak: true, width: 30.0, left: 0.0),
]);
// With trailing whitespace and new lines.
paragraph = plain(ahemStyle, 'abc \ndef ')..layout(constrain(50.0));
expect(paragraph.maxIntrinsicWidth, 60);
expectLines(paragraph, [
l('abc ', 0, 5, hardBreak: true, width: 30.0, left: 0.0),
l('def ', 5, 11, hardBreak: true, width: 30.0, left: 0.0),
]);
if (!skipForceBreak) {
// Very long text.
paragraph = plain(ahemStyle, 'AAAAAAAAAAAA')..layout(constrain(50.0));
expect(paragraph.maxIntrinsicWidth, 120);
expectLines(paragraph, [
l('AAAAA', 0, 5, hardBreak: false, width: 50.0, left: 0.0),
l('AAAAA', 5, 10, hardBreak: false, width: 50.0, left: 0.0),
l('AA', 10, 12, hardBreak: true, width: 20.0, left: 0.0),
]);
}
});
test('respects text overflow', () {
final EngineParagraphStyle overflowStyle = EngineParagraphStyle(
fontFamily: 'ahem',
fontSize: 10,
ellipsis: '...',
);
// The text shouldn't be broken into multiple lines, so the height should
// be equal to a height of a single line.
final CanvasParagraph longText = plain(
overflowStyle,
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
)..layout(constrain(50.0));
expect(longText.minIntrinsicWidth, 480);
expect(longText.maxIntrinsicWidth, 480);
// expect(longText.height, 10);
expectLines(longText, [
l('AA...', 0, 2, hardBreak: false, width: 50.0, left: 0.0),
]);
// The short prefix should make the text break into two lines, but the
// second line should remain unbroken.
final CanvasParagraph longTextShortPrefix = plain(
overflowStyle,
'AAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
)..layout(constrain(50.0));
expect(longTextShortPrefix.minIntrinsicWidth, 450);
expect(longTextShortPrefix.maxIntrinsicWidth, 450);
// expect(longTextShortPrefix.height, 20);
expectLines(longTextShortPrefix, [
l('AAA', 0, 4, hardBreak: true, width: 30.0, left: 0.0),
l('AA...', 4, 6, hardBreak: false, width: 50.0, left: 0.0),
]);
// Tiny constraints.
final CanvasParagraph paragraph = plain(overflowStyle, 'AAAA')
..layout(constrain(30.0));
expect(paragraph.minIntrinsicWidth, 40);
expect(paragraph.maxIntrinsicWidth, 40);
// expect(paragraph.height, 10);
expectLines(paragraph, [
l('...', 0, 0, hardBreak: false, width: 30.0, left: 0.0),
]);
// Tinier constraints (not enough for the ellipsis).
paragraph.layout(constrain(10.0));
expect(paragraph.minIntrinsicWidth, 40);
expect(paragraph.maxIntrinsicWidth, 40);
// expect(paragraph.height, 10);
// TODO(flutter_web): https://github.com/flutter/flutter/issues/34346
// expectLines(paragraph, [
// l('.', 0, 0, hardBreak: false, width: 10.0, left: 0.0),
// ]);
expectLines(paragraph, [
l('...', 0, 0, hardBreak: false, width: 30.0, left: 0.0),
]);
}, skip: skipOverflow);
test('respects max lines', () {
final EngineParagraphStyle maxlinesStyle = EngineParagraphStyle(
fontFamily: 'ahem',
fontSize: 10,
maxLines: 2,
);
// The height should be that of a single line.
final CanvasParagraph oneline = plain(maxlinesStyle, 'One line')
..layout(constrain(double.infinity));
// expect(oneline.height, 10);
expectLines(oneline, [
l('One line', 0, 8, hardBreak: true, width: 80.0, left: 0.0),
]);
// The height should respect max lines and be limited to two lines here.
final CanvasParagraph threelines =
plain(maxlinesStyle, 'First\nSecond\nThird')
..layout(constrain(double.infinity));
// expect(threelines.height, 20);
expectLines(threelines, [
l('First', 0, 6, hardBreak: true, width: 50.0, left: 0.0),
l('Second', 6, 13, hardBreak: true, width: 60.0, left: 0.0),
]);
// The height should respect max lines and be limited to two lines here.
final CanvasParagraph veryLong = plain(
maxlinesStyle,
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
)..layout(constrain(50.0));
// expect(veryLong.height, 20);
expectLines(veryLong, [
l('Lorem ', 0, 6, hardBreak: false, width: 50.0, left: 0.0),
l('ipsum ', 6, 12, hardBreak: false, width: 50.0, left: 0.0),
]);
// Case when last line is a long unbreakable word.
final CanvasParagraph veryLongLastLine = plain(
maxlinesStyle,
'AAA AAAAAAAAAAAAAAAAAAA',
)..layout(constrain(50.0));
// expect(veryLongLastLine.height, 20);
expectLines(veryLongLastLine, [
l('AAA ', 0, 4, hardBreak: false, width: 30.0, left: 0.0),
l('AAAAA', 4, 9, hardBreak: false, width: 50.0, left: 0.0),
]);
}, skip: skipMaxLines);
test('respects text overflow and max lines combined', () {
final EngineParagraphStyle onelineStyle = EngineParagraphStyle(
fontFamily: 'ahem',
fontSize: 10,
maxLines: 1,
ellipsis: '...',
);
final EngineParagraphStyle multilineStyle = EngineParagraphStyle(
fontFamily: 'ahem',
fontSize: 10,
maxLines: 2,
ellipsis: '...',
);
CanvasParagraph paragraph;
// Simple no overflow case.
paragraph = plain(onelineStyle, 'abcdef')..layout(constrain(60.0));
// expect(paragraph.height, 10);
expectLines(paragraph, [
l('abcdef', 0, 6, hardBreak: true, width: 60.0, left: 0.0),
]);
// Simple overflow case.
paragraph = plain(onelineStyle, 'abcd efg')..layout(constrain(60.0));
// expect(paragraph.height, 10);
expectLines(paragraph, [
l('abc...', 0, 3, hardBreak: false, width: 60.0, left: 0.0),
]);
// Another simple overflow case.
paragraph = plain(onelineStyle, 'a bcde fgh')..layout(constrain(60.0));
// expect(paragraph.height, 10);
expectLines(paragraph, [
l('a b...', 0, 3, hardBreak: false, width: 60.0, left: 0.0),
]);
// The ellipsis is supposed to go on the second line, but because the
// 2nd line doesn't overflow, no ellipsis is shown.
paragraph = plain(multilineStyle, 'abcdef ghijkl')..layout(constrain(60.0));
// expect(paragraph.height, 20);
expectLines(paragraph, [
l('abcdef ', 0, 7, hardBreak: false, width: 60.0, left: 0.0),
l('ghijkl', 7, 13, hardBreak: true, width: 60.0, left: 0.0),
]);
// But when the 2nd line is long enough, the ellipsis is shown.
paragraph = plain(multilineStyle, 'abcd efghijkl')..layout(constrain(60.0));
// expect(paragraph.height, 20);
expectLines(paragraph, [
l('abcd ', 0, 5, hardBreak: false, width: 40.0, left: 0.0),
l('efg...', 5, 8, hardBreak: false, width: 60.0, left: 0.0),
]);
// Even if the second line can be broken, we don't break it, we just
// insert the ellipsis.
paragraph = plain(multilineStyle, 'abcde f gh ijk')
..layout(constrain(60.0));
// expect(paragraph.height, 20);
expectLines(paragraph, [
l('abcde ', 0, 6, hardBreak: false, width: 50.0, left: 0.0),
l('f g...', 6, 9, hardBreak: false, width: 60.0, left: 0.0),
]);
// First line overflows but second line doesn't.
paragraph = plain(multilineStyle, 'abcdefg hijk')..layout(constrain(60.0));
// expect(paragraph.height, 20);
expectLines(paragraph, [
l('abcdef', 0, 6, hardBreak: false, width: 60.0, left: 0.0),
l('g hijk', 6, 12, hardBreak: true, width: 60.0, left: 0.0),
]);
// Both first and second lines overflow.
paragraph = plain(multilineStyle, 'abcdefg hijklmnop')
..layout(constrain(60.0));
// expect(paragraph.height, 20);
expectLines(paragraph, [
l('abcdef', 0, 6, hardBreak: false, width: 60.0, left: 0.0),
l('g h...', 6, 9, hardBreak: false, width: 60.0, left: 0.0),
]);
}, skip: skipOverflow || skipMaxLines);
test('handles textAlign', () {
CanvasParagraph paragraph;
EngineParagraphStyle createStyle(ui.TextAlign textAlign) {
return EngineParagraphStyle(
fontFamily: 'ahem',
fontSize: 10,
textAlign: textAlign,
textDirection: ui.TextDirection.ltr,
);
}
paragraph = plain(createStyle(ui.TextAlign.start), 'abc\ndefghi')
..layout(constrain(50.0));
expectLines(paragraph, [
l('abc', 0, 4, hardBreak: true, width: 30.0, left: 0.0),
l('defgh', 4, 9, hardBreak: false, width: 50.0, left: 0.0),
l('i', 9, 10, hardBreak: true, width: 10.0, left: 0.0),
]);
paragraph = plain(createStyle(ui.TextAlign.end), 'abc\ndefghi')
..layout(constrain(50.0));
expectLines(paragraph, [
l('abc', 0, 4, hardBreak: true, width: 30.0, left: 20.0),
l('defgh', 4, 9, hardBreak: false, width: 50.0, left: 0.0),
l('i', 9, 10, hardBreak: true, width: 10.0, left: 40.0),
]);
paragraph = plain(createStyle(ui.TextAlign.center), 'abc\ndefghi')
..layout(constrain(50.0));
expectLines(paragraph, [
l('abc', 0, 4, hardBreak: true, width: 30.0, left: 10.0),
l('defgh', 4, 9, hardBreak: false, width: 50.0, left: 0.0),
l('i', 9, 10, hardBreak: true, width: 10.0, left: 20.0),
]);
paragraph = plain(createStyle(ui.TextAlign.left), 'abc\ndefghi')
..layout(constrain(50.0));
expectLines(paragraph, [
l('abc', 0, 4, hardBreak: true, width: 30.0, left: 0.0),
l('defgh', 4, 9, hardBreak: false, width: 50.0, left: 0.0),
l('i', 9, 10, hardBreak: true, width: 10.0, left: 0.0),
]);
paragraph = plain(createStyle(ui.TextAlign.right), 'abc\ndefghi')
..layout(constrain(50.0));
expectLines(paragraph, [
l('abc', 0, 4, hardBreak: true, width: 30.0, left: 20.0),
l('defgh', 4, 9, hardBreak: false, width: 50.0, left: 0.0),
l('i', 9, 10, hardBreak: true, width: 10.0, left: 40.0),
]);
}, skip: skipTextAlign);
test('handles rtl with textAlign', () {
CanvasParagraph paragraph;
EngineParagraphStyle createStyle(ui.TextAlign textAlign) {
return EngineParagraphStyle(
fontFamily: 'ahem',
fontSize: 10,
textAlign: textAlign,
textDirection: ui.TextDirection.rtl,
);
}
paragraph = plain(createStyle(ui.TextAlign.start), 'abc\ndefghi')
..layout(constrain(50.0));
expectLines(paragraph, [
l('abc', 0, 4, hardBreak: true, width: 30.0, left: 20.0),
l('defgh', 4, 9, hardBreak: false, width: 50.0, left: 0.0),
l('i', 9, 10, hardBreak: true, width: 10.0, left: 40.0),
]);
paragraph = plain(createStyle(ui.TextAlign.end), 'abc\ndefghi')
..layout(constrain(50.0));
expectLines(paragraph, [
l('abc', 0, 4, hardBreak: true, width: 30.0, left: 0.0),
l('defgh', 4, 9, hardBreak: false, width: 50.0, left: 0.0),
l('i', 9, 10, hardBreak: true, width: 10.0, left: 0.0),
]);
paragraph = plain(createStyle(ui.TextAlign.center), 'abc\ndefghi')
..layout(constrain(50.0));
expectLines(paragraph, [
l('abc', 0, 4, hardBreak: true, width: 30.0, left: 10.0),
l('defgh', 4, 9, hardBreak: false, width: 50.0, left: 0.0),
l('i', 9, 10, hardBreak: true, width: 10.0, left: 20.0),
]);
paragraph = plain(createStyle(ui.TextAlign.left), 'abc\ndefghi')
..layout(constrain(50.0));
expectLines(paragraph, [
l('abc', 0, 4, hardBreak: true, width: 30.0, left: 0.0),
l('defgh', 4, 9, hardBreak: false, width: 50.0, left: 0.0),
l('i', 9, 10, hardBreak: true, width: 10.0, left: 0.0),
]);
paragraph = plain(createStyle(ui.TextAlign.right), 'abc\ndefghi')
..layout(constrain(50.0));
expectLines(paragraph, [
l('abc', 0, 4, hardBreak: true, width: 30.0, left: 20.0),
l('defgh', 4, 9, hardBreak: false, width: 50.0, left: 0.0),
l('i', 9, 10, hardBreak: true, width: 10.0, left: 40.0),
]);
}, skip: skipTextAlign);
}