Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7f69f0d

Browse files
authored
[web] Fix arc rendering when it starts a new sub path. (#18535)
* Fix Path.addArc failure due to incorrect start position
1 parent 1475c2f commit 7f69f0d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/web_ui/dev/goldens_lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
repository: https://github.com/flutter/goldens.git
2-
revision: f80e019e225915e220f0f37884c8cd1b942d9bc2
2+
revision: 993752770817654e362b85f4781d300a9b215d4c

lib/web_ui/lib/src/engine/canvas_pool.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ class _CanvasPool extends _SaveStackTracking {
520520
break;
521521
case PathCommandTypes.ellipse:
522522
final Ellipse ellipse = command;
523+
if (c == 0) {
524+
// Ellipses that start a new path need to set start point,
525+
// otherwise it incorrectly uses last point.
526+
ctx.moveTo(subpath.startX, subpath.startY);
527+
}
523528
DomRenderer.ellipse(ctx,
524529
ellipse.x,
525530
ellipse.y,

lib/web_ui/test/golden_tests/engine/canvas_arc_golden_test.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// @dart = 2.6
66
import 'dart:html' as html;
7-
7+
import 'dart:math' as math;
88
import 'package:ui/src/engine.dart';
99
import 'package:ui/ui.dart';
1010
import 'package:test/test.dart';
@@ -47,6 +47,20 @@ void main() async {
4747
await matchGoldenFile('canvas_arc_to_point.png', region: region);
4848
});
4949

50+
test('Path.addArc that starts new path has correct start point', () async {
51+
final Rect rect = Rect.fromLTWH(20, 20, 200, 200);
52+
final Path p = Path()
53+
..fillType = PathFillType.evenOdd
54+
..addRect(rect)
55+
..addArc(Rect.fromCircle(center: rect.center,
56+
radius: rect.size.shortestSide / 2), 0.25 * math.pi, 1.5 * math.pi);
57+
canvas.drawPath(p, SurfacePaintData()
58+
..color = Color(0xFFFF9800) // orange
59+
..style = PaintingStyle.fill);
60+
61+
html.document.body.append(canvas.rootElement);
62+
await matchGoldenFile('canvas_addarc.png', region: region);
63+
});
5064
}
5165

5266
void paintArc(BitmapCanvas canvas, Offset offset,

0 commit comments

Comments
 (0)