@@ -10,7 +10,6 @@ import 'package:test/test.dart';
1010
1111import 'package:ui/src/engine.dart' ;
1212import 'package:ui/ui.dart' as ui;
13- import 'package:web_engine_tester/golden_tester.dart' ;
1413
1514import '../matchers.dart' ;
1615import 'common.dart' ;
@@ -50,9 +49,7 @@ void testMain() {
5049 _matrix4x4CompositionTests ();
5150 _toSkRectTests ();
5251 _skVerticesTests ();
53- group ('SkParagraph' , () {
54- _paragraphTests ();
55- });
52+ _paragraphTests ();
5653 group ('SkPath' , () {
5754 _pathTests ();
5855 });
@@ -1450,36 +1447,31 @@ void _textStyleTests() {
14501447}
14511448
14521449void _paragraphTests () {
1453- setUpAll (() async {
1454- CanvasKitRenderer .instance.fontCollection.debugRegisterTestFonts ();
1455- await CanvasKitRenderer .instance.fontCollection.ensureFontsLoaded ();
1456- });
1457-
14581450 // This test is just a kitchen sink that blasts CanvasKit with all paragraph
14591451 // properties all at once, making sure CanvasKit doesn't choke on anything.
14601452 // In particular, this tests that our JS bindings are correct, such as that
14611453 // arguments are of acceptable types and passed in the correct order.
1462- test ('kitchensink' , () async {
1454+ test ('SkParagraph API kitchensink' , () {
14631455 final SkParagraphStyleProperties props = SkParagraphStyleProperties ();
1464- props.textAlign = canvasKit.TextAlign .Left ;
1456+ props.textAlign = canvasKit.TextAlign .Center ;
14651457 props.textDirection = canvasKit.TextDirection .RTL ;
14661458 props.heightMultiplier = 3 ;
14671459 props.textHeightBehavior = canvasKit.TextHeightBehavior .All ;
14681460 props.maxLines = 4 ;
14691461 props.ellipsis = '___' ;
14701462 props.textStyle = SkTextStyleProperties ()
1471- ..backgroundColor = Float32List .fromList (< double > [0.2 , 0 , 0 , 0.5 ])
1472- ..color = Float32List .fromList (< double > [0 , 1 , 0 , 1 ])
1473- ..foregroundColor = Float32List .fromList (< double > [1 , 0 , 1 , 1 ])
1463+ ..backgroundColor = Float32List .fromList (< double > [1 , 2 , 3 , 4 ])
1464+ ..color = Float32List .fromList (< double > [5 , 6 , 7 , 8 ])
1465+ ..foregroundColor = Float32List .fromList (< double > [9 , 10 , 11 , 12 ])
14741466 ..decoration = 0x2
14751467 ..decorationThickness = 2.0
14761468 ..decorationColor = Float32List .fromList (< double > [13 , 14 , 15 , 16 ])
14771469 ..decorationStyle = canvasKit.DecorationStyle .Dotted
14781470 ..textBaseline = canvasKit.TextBaseline .Ideographic
1479- ..fontSize = 48
1471+ ..fontSize = 24
14801472 ..letterSpacing = 5
14811473 ..wordSpacing = 10
1482- ..heightMultiplier = 1.3
1474+ ..heightMultiplier = 2.5
14831475 ..halfLeading = true
14841476 ..locale = 'en_CA'
14851477 ..fontFamilies = < String > ['Roboto' , 'serif' ]
@@ -1494,24 +1486,23 @@ void _paragraphTests() {
14941486 SkFontFeature ()
14951487 ..name = 'tnum'
14961488 ..value = 1 ,
1497- ]
1498- ;
1489+ ];
14991490 props.strutStyle = SkStrutStyleProperties ()
15001491 ..fontFamilies = < String > ['Roboto' , 'Noto' ]
15011492 ..fontStyle = (SkFontStyle ()
15021493 ..slant = canvasKit.FontSlant .Italic
15031494 ..weight = canvasKit.FontWeight .Bold )
1504- ..fontSize = 72
1505- ..heightMultiplier = 1. 5
1495+ ..fontSize = 23
1496+ ..heightMultiplier = 5
15061497 ..halfLeading = true
1507- ..leading = 0
1498+ ..leading = 6
15081499 ..strutEnabled = true
15091500 ..forceStrutHeight = false ;
15101501
15111502 final SkParagraphStyle paragraphStyle = canvasKit.ParagraphStyle (props);
1512- final SkParagraphBuilder builder = canvasKit.ParagraphBuilder .MakeFromFontProvider (
1503+ final SkParagraphBuilder builder = canvasKit.ParagraphBuilder .Make (
15131504 paragraphStyle,
1514- CanvasKitRenderer .instance.fontCollection.fontProvider ,
1505+ CanvasKitRenderer .instance.fontCollection.skFontMgr ,
15151506 );
15161507
15171508 builder.addText ('Hello' );
@@ -1522,93 +1513,51 @@ void _paragraphTests() {
15221513 canvasKit.TextBaseline .Ideographic ,
15231514 4.0 ,
15241515 );
1525- builder.pushStyle (canvasKit.TextStyle (SkTextStyleProperties ()
1526- ..color = Float32List .fromList (< double > [1 , 0 , 0 , 1 ])
1527- ..fontSize = 24
1528- ..fontFamilies = < String > ['Roboto' , 'serif' ]
1529- ));
1516+ builder
1517+ .pushStyle (canvasKit.TextStyle (SkTextStyleProperties ()..fontSize = 12 ));
15301518 builder.addText ('World' );
15311519 builder.pop ();
15321520 builder.pushPaintStyle (
1533- canvasKit.TextStyle (SkTextStyleProperties ()
1534- ..color = Float32List .fromList (< double > [1 , 0 , 0 , 1 ])
1535- ..fontSize = 60
1536- ..fontFamilies = < String > ['Roboto' , 'serif' ]
1537- ),
1538- SkPaint ()..setColorInt (0xFF0000FF ),
1539- SkPaint ()..setColorInt (0xFFFF0000 ),
1540- );
1521+ canvasKit.TextStyle (SkTextStyleProperties ()..fontSize = 12 ),
1522+ SkPaint (),
1523+ SkPaint ());
15411524 builder.addText ('!' );
15421525 builder.pop ();
15431526 builder.pushStyle (
15441527 canvasKit.TextStyle (SkTextStyleProperties ()..halfLeading = true ));
15451528 builder.pop ();
15461529 final SkParagraph paragraph = builder.build ();
1547- paragraph.layout (500 );
1548-
1549- final DomCanvasElement canvas = createDomCanvasElement (
1550- width: 400 ,
1551- height: 160 ,
1552- );
1553- domDocument.body! .append (canvas);
1554-
1555- // TODO(yjbanov): WebGL screenshot tests do not work on Firefox - https://github.com/flutter/flutter/issues/109265
1556- if (! isFirefox) {
1557- final SkSurface surface = canvasKit.MakeWebGLCanvasSurface (canvas);
1558- final SkCanvas skCanvas = surface.getCanvas ();
1559- skCanvas.drawColorInt (0xFFCCCCCC , toSkBlendMode (ui.BlendMode .srcOver));
1560- skCanvas.drawParagraph (paragraph, 20 , 20 );
1561- skCanvas.drawRect (
1562- Float32List .fromList (< double > [20 , 20 , 20 + paragraph.getMaxIntrinsicWidth (), 20 + paragraph.getHeight ()]),
1563- SkPaint ()
1564- ..setStyle (toSkPaintStyle (ui.PaintingStyle .stroke))
1565- ..setStrokeWidth (1 )
1566- ..setColorInt (0xFF00FF00 ),
1567- );
1568- surface.flush ();
1569-
1570- await matchGoldenFile (
1571- 'paragraph_kitchen_sink.png' ,
1572- region: const ui.Rect .fromLTRB (0 , 0 , 400 , 160 ),
1573- maxDiffRatePercent: 0.0 ,
1574- write: true ,
1575- );
1576- }
1577-
1578- void expectAlmost (double actual, double expected) {
1579- expect (actual, within <double >(distance: actual / 100 , from: expected));
1580- }
1581-
1582- expectAlmost (paragraph.getAlphabeticBaseline (), 85.5 );
1530+ paragraph.layout (55 );
1531+ expect (paragraph.getAlphabeticBaseline (),
1532+ within <double >(distance: 0.5 , from: 20.7 ));
15831533 expect (paragraph.didExceedMaxLines (), isFalse);
1584- expectAlmost (paragraph.getHeight (), 108 );
1585- expectAlmost (paragraph.getIdeographicBaseline (), 108 );
1586- expectAlmost (paragraph.getLongestLine (), 263 );
1587- expectAlmost (paragraph.getMaxIntrinsicWidth (), 263 );
1588- expectAlmost (paragraph.getMinIntrinsicWidth (), 135 );
1589- expectAlmost (paragraph.getMaxWidth (), 500 );
1534+ expect (paragraph.getHeight (), 25 );
1535+ expect (paragraph.getIdeographicBaseline (),
1536+ within <double >(distance: 0.5 , from: 25 ));
1537+ expect (paragraph.getLongestLine (), 50 );
1538+ expect (paragraph.getMaxIntrinsicWidth (), 50 );
1539+ expect (paragraph.getMinIntrinsicWidth (), 50 );
1540+ expect (paragraph.getMaxWidth (), 55 );
15901541 expect (
1591- paragraph.getRectsForRange (1 , 3 , canvasKit.RectHeightStyle .Tight , canvasKit. RectWidthStyle . Max ).single ,
1592- hasLength ( 4 ),
1593- );
1542+ paragraph.getRectsForRange (1 , 3 , canvasKit.RectHeightStyle .Tight ,
1543+ canvasKit. RectWidthStyle . Max ),
1544+ < double > [] );
15941545 expect (paragraph.getRectsForPlaceholders (), hasLength (1 ));
15951546 expect (paragraph.getLineMetrics (), hasLength (1 ));
15961547
15971548 final SkLineMetrics lineMetrics =
15981549 paragraph.getLineMetrics ().cast <SkLineMetrics >().single;
1599- expectAlmost (lineMetrics.ascent, 55.6 );
1600- expectAlmost (lineMetrics.descent, 14.8 );
1550+ expect (lineMetrics.ascent, within < double >(distance : 0.5 , from : 20.7 ) );
1551+ expect (lineMetrics.descent, within < double >(distance : 0.2 , from : 4.3 ) );
16011552 expect (lineMetrics.isHardBreak, isTrue);
1602- expectAlmost (lineMetrics.baseline, 85.5 );
1603- expectAlmost (lineMetrics.height, 108 );
1604- expectAlmost (lineMetrics.left, 2.5 );
1605- expectAlmost (lineMetrics.width, 263 );
1553+ expect (lineMetrics.baseline, within < double >(distance : 0.5 , from : 20.7 ) );
1554+ expect (lineMetrics.height, 25 );
1555+ expect (lineMetrics.left, 2.5 );
1556+ expect (lineMetrics.width, 50 );
16061557 expect (lineMetrics.lineNumber, 0 );
16071558
1608- expect (
1609- paragraph.getGlyphPositionAtCoordinate (5 , 5 ).affinity,
1610- canvasKit.Affinity .Upstream ,
1611- );
1559+ expect (paragraph.getGlyphPositionAtCoordinate (5 , 5 ).affinity,
1560+ canvasKit.Affinity .Downstream );
16121561
16131562 // "Hello"
16141563 for (int i = 0 ; i < 5 ; i++ ) {
0 commit comments