|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +// @dart = 2.6 |
| 6 | +import 'dart:html' as html; |
| 7 | + |
| 8 | +import 'package:ui/src/engine.dart'; |
| 9 | +import 'package:ui/ui.dart'; |
| 10 | +import 'package:test/test.dart'; |
| 11 | + |
| 12 | +import 'package:web_engine_tester/golden_tester.dart'; |
| 13 | + |
| 14 | +void main() async { |
| 15 | + final Rect region = Rect.fromLTWH(0, 0, 500, 500); |
| 16 | + |
| 17 | + BitmapCanvas canvas; |
| 18 | + |
| 19 | + setUp(() { |
| 20 | + canvas = BitmapCanvas(region); |
| 21 | + }); |
| 22 | + |
| 23 | + tearDown(() { |
| 24 | + canvas.rootElement.remove(); |
| 25 | + }); |
| 26 | + |
| 27 | + test('draws paths using nonzero and evenodd winding rules', () async { |
| 28 | + paintPaths(canvas); |
| 29 | + html.document.body.append(canvas.rootElement); |
| 30 | + await matchGoldenFile('canvas_path_winding.png', region: region); |
| 31 | + }); |
| 32 | + |
| 33 | +} |
| 34 | + |
| 35 | +void paintPaths(BitmapCanvas canvas) { |
| 36 | + canvas.drawRect(Rect.fromLTRB(0, 0, 500, 500), |
| 37 | + SurfacePaintData() |
| 38 | + ..color = Color(0xFFFFFFFF) |
| 39 | + ..style = PaintingStyle.fill); // white |
| 40 | + |
| 41 | + SurfacePaint paintFill = SurfacePaint() |
| 42 | + ..style = PaintingStyle.fill |
| 43 | + ..color = Color(0xFF00B0FF); |
| 44 | + SurfacePaint paintStroke = SurfacePaint() |
| 45 | + ..style = PaintingStyle.stroke |
| 46 | + ..strokeWidth = 2 |
| 47 | + ..color = Color(0xFFE00000); |
| 48 | + Path path1 = Path() |
| 49 | + ..fillType = PathFillType.evenOdd |
| 50 | + ..moveTo(50, 0) |
| 51 | + ..lineTo(21, 90) |
| 52 | + ..lineTo(98, 35) |
| 53 | + ..lineTo(2, 35) |
| 54 | + ..lineTo(79, 90) |
| 55 | + ..close() |
| 56 | + ..addRect(Rect.fromLTWH(20, 100, 200, 50)) |
| 57 | + ..addRect(Rect.fromLTWH(40, 120, 160, 10)); |
| 58 | + Path path2 = Path() |
| 59 | + ..fillType = PathFillType.nonZero |
| 60 | + ..moveTo(50, 200) |
| 61 | + ..lineTo(21, 290) |
| 62 | + ..lineTo(98, 235) |
| 63 | + ..lineTo(2, 235) |
| 64 | + ..lineTo(79, 290) |
| 65 | + ..close() |
| 66 | + ..addRect(Rect.fromLTWH(20, 300, 200, 50)) |
| 67 | + ..addRect(Rect.fromLTWH(40, 320, 160, 10)); |
| 68 | + canvas.drawPath(path1, paintFill.paintData); |
| 69 | + canvas.drawPath(path2, paintFill.paintData); |
| 70 | + canvas.drawPath(path1, paintStroke.paintData); |
| 71 | + canvas.drawPath(path2, paintStroke.paintData); |
| 72 | +} |
0 commit comments