' @@ -40,7 +56,17 @@ void testMain() { '' '
', ); - expect(paragraph.spans, hasLength(1)); + + // Should break "Hello" into "Hel" and "lo". + paragraph.layout(ParagraphConstraints(width: 39.0)); + expect( + paragraph.toDomElement().outerHtml, + ''
+ ''
+ 'Hel
lo'
+ ''
+ '
Hello
', ); - expect(paragraph.spans, hasLength(1)); final FlatTextSpan textSpan = paragraph.spans.single as FlatTextSpan; expect(textSpan.style, styleWithDefaults()); @@ -77,9 +105,16 @@ void testMain() { final CanvasParagraph paragraph = builder.build(); expect(paragraph.paragraphStyle, style); expect(paragraph.toPlainText(), 'Hello'); + + double expectedHeight = 14.0; + if (isIosSafari) { + // On iOS Safari, the height measurement is one extra pixel. + expectedHeight++; + } + paragraph.layout(ParagraphConstraints(width: double.infinity)); expect( paragraph.toDomElement().outerHtml, - '' @@ -133,7 +174,6 @@ void testMain() { '' '
', ); - expect(paragraph.spans, hasLength(1)); final FlatTextSpan span = paragraph.spans.single as FlatTextSpan; expect(span.textOf(paragraph), 'Hello'); @@ -161,6 +201,9 @@ void testMain() { final CanvasParagraph paragraph = builder.build(); expect(paragraph.toPlainText(), 'Hello world'); + expect(paragraph.spans, hasLength(2)); + + paragraph.layout(ParagraphConstraints(width: double.infinity)); expect( paragraph.toDomElement().outerHtml, '' @@ -172,7 +215,20 @@ void testMain() { '' '
', ); - expect(paragraph.spans, hasLength(2)); + + // Should break "Hello world" into "Hello" and " world". + paragraph.layout(ParagraphConstraints(width: 70.0)); + expect( + paragraph.toDomElement().outerHtml, + ''
+ ''
+ 'Hello'
+ ''
+ ''
+ '
world'
+ ''
+ '
' @@ -224,7 +283,6 @@ void testMain() { '' '
', ); - expect(paragraph.spans, hasLength(3)); final FlatTextSpan hello = paragraph.spans[0] as FlatTextSpan; expect(hello.textOf(paragraph), 'Hello'); @@ -259,6 +317,48 @@ void testMain() { ), ); }); + + test('Paragraph with new lines generates correct DOM', () { + final EngineParagraphStyle style = EngineParagraphStyle(fontSize: 13.0); + final CanvasParagraphBuilder builder = CanvasParagraphBuilder(style); + + builder.addText('First\nSecond '); + builder.pushStyle(TextStyle(fontStyle: FontStyle.italic)); + builder.addText('ThirdLongLine'); + + final CanvasParagraph paragraph = builder.build(); + expect(paragraph.toPlainText(), 'First\nSecond ThirdLongLine'); + expect(paragraph.spans, hasLength(2)); + + // There's a new line between "First" and "Second", but "Second" and + // "ThirdLongLine" remain together since constraints are infinite. + paragraph.layout(ParagraphConstraints(width: double.infinity)); + expect( + paragraph.toDomElement().outerHtml, + ''
+ ''
+ 'First
Second '
+ ''
+ ''
+ 'ThirdLongLine'
+ ''
+ '
'
+ ''
+ 'First
Second
'
+ ''
+ ''
+ 'ThirdLongLine'
+ ''
+ '