@@ -6,29 +6,30 @@ import 'package:test/bootstrap/browser.dart';
66import 'package:test/test.dart' ;
77import 'package:ui/src/engine.dart' ;
88import 'package:ui/ui.dart' ;
9+
10+ import 'paragraph/helper.dart' ;
911import 'screenshot.dart' ;
1012
1113void main () {
1214 internalBootstrapBrowserTest (() => testMain);
1315}
1416
1517Future <void > testMain () async {
16- setUp (() async {
17- debugEmulateFlutterTesterEnvironment = true ;
18- });
18+ setUpStableTestFonts ();
1919
2020 /// Regression test for https://github.com/flutter/flutter/issues/64734.
2121 test ('Clips using difference' , () async {
22+ const Offset shift = Offset (8 , 8 );
2223 const Rect region = Rect .fromLTRB (0 , 0 , 400 , 300 );
2324 final RecordingCanvas canvas = RecordingCanvas (region);
24- const Rect titleRect = Rect .fromLTWH (20 , 0 , 50 , 20 );
25+ final Rect titleRect = const Rect .fromLTWH (20 , 0 , 50 , 20 ). shift (shift );
2526 final SurfacePaint paint = SurfacePaint ()
2627 ..style = PaintingStyle .stroke
2728 ..color = const Color (0xff000000 )
2829 ..strokeWidth = 1 ;
2930 canvas.save ();
3031 try {
31- final Rect borderRect = Rect .fromLTRB (0 , 10 , region.width, region.height);
32+ final Rect borderRect = Rect .fromLTRB (0 , 10 , region.width, region.height). shift (shift) ;
3233 canvas.clipRect (titleRect, ClipOp .difference);
3334 canvas.drawRect (borderRect, paint);
3435 } finally {
@@ -38,4 +39,50 @@ Future<void> testMain() async {
3839 await canvasScreenshot (canvas, 'clip_op_difference' ,
3940 region: const Rect .fromLTRB (0 , 0 , 420 , 360 ));
4041 });
42+
43+ /// Regression test for https://github.com/flutter/flutter/issues/86345
44+ test ('Clips with zero width or height' , () async {
45+ const Rect region = Rect .fromLTRB (0 , 0 , 400 , 300 );
46+ final RecordingCanvas canvas = RecordingCanvas (region);
47+
48+ final SurfacePaint paint = SurfacePaint ()
49+ ..style = PaintingStyle .fill
50+ ..color = const Color (0xff00ff00 );
51+ final SurfacePaint borderPaint = SurfacePaint ()
52+ ..style = PaintingStyle .stroke
53+ ..color = const Color (0xffff0000 )
54+ ..strokeWidth = 1 ;
55+
56+ for (int i = 0 ; i < 3 ; i++ ) {
57+ for (int j = 0 ; j < 3 ; j++ ) {
58+ final double x = 10 + i * 70 ;
59+ final double y = 10 + j * 70 ;
60+ canvas.save ();
61+ // Clip.
62+ canvas.clipRect (
63+ Rect .fromLTWH (x, y, i * 25 , j * 25 ),
64+ ClipOp .intersect,
65+ );
66+ // Draw the blue (clipped) rect.
67+ canvas.drawRect (
68+ Rect .fromLTWH (x, y, 50 , 50 ),
69+ paint,
70+ );
71+ final Paragraph p = plain (
72+ EngineParagraphStyle (fontFamily: 'Roboto' , fontSize: 34 ),
73+ '23' ,
74+ textStyle: EngineTextStyle .only (color: const Color (0xff0000ff )),
75+ );
76+ p.layout (const ParagraphConstraints (width: double .infinity));
77+ canvas.drawParagraph (p, Offset (x, y));
78+ canvas.restore ();
79+ // Draw the red border.
80+ canvas.drawRect (
81+ Rect .fromLTWH (x, y, 50 , 50 ),
82+ borderPaint,
83+ );
84+ }
85+ }
86+ await canvasScreenshot (canvas, 'clip_zero_width_height' , region: region);
87+ });
4188}
0 commit comments