Fix HTML renderer does not render border (flutter/engine#34812)

This commit is contained in:
Bruno Leroux
2022-09-15 19:00:14 +02:00
committed by GitHub
parent f3f5f8abfc
commit be6a4135d3
2 changed files with 40 additions and 1 deletions

View File

@@ -488,6 +488,20 @@ class RecordingCanvas {
drawRRect(rrect, paint);
return;
}
// Use drawRect for straight line paths painted with a zero strokeWidth
final ui.Rect? line = sPath.toStraightLine();
if (line != null && paint.strokeWidth == 0) {
final double left = math.min(line.left, line.right);
final double top = math.min(line.top, line.bottom);
final double width = line.width.abs();
final double height = line.height.abs();
final double inflatedHeight = line.height == 0 ? 1 : height;
final double inflatedWidth = line.width == 0 ? 1 : width;
final ui.Size inflatedSize = ui.Size(inflatedWidth, inflatedHeight);
paint.style = ui.PaintingStyle.fill;
drawRect(ui.Offset(left, top) & inflatedSize, paint);
return;
}
}
final SurfacePath sPath = path as SurfacePath;
if (!sPath.pathRef.isEmpty) {

View File

@@ -479,6 +479,31 @@ Future<void> testMain() async {
await checkScreenshot(rc, 'line_rotated');
});
// Regression test for https://github.com/flutter/flutter/issues/46339.
test('Should draw a Rect for straight line when strokeWidth is zero.', () async {
final RecordingCanvas rc = RecordingCanvas(screenRect);
final Path path = Path();
final SurfacePaint paint = SurfacePaint()
..style = PaintingStyle.stroke
..strokeWidth = 0.0
..color = const Color(0xFFFF0000);
path.moveTo(10, 10);
path.lineTo(90, 10);
rc.drawPath(path, paint);
rc.endRecording();
// Should draw a Rect
final List<PaintCommand> commands = rc.debugPaintCommands;
expect(commands.length, 1);
expect(commands.first, isA<PaintDrawRect>());
// Should inflate picture bounds
expect(
rc.pictureBounds,
within(distance: 0.1, from: const Rect.fromLTRB(10, 10, 90, 11)),
);
await checkScreenshot(rc, 'path_straight_line_with_zero_stroke_width');
});
test('Should support reusing path and reset when drawing into canvas.',
() async {
final RecordingCanvas rc =
@@ -532,7 +557,7 @@ Future<void> testMain() async {
// Regression test for https://github.com/flutter/flutter/issues/64371.
test('Should draw line following a polygon without closing path.', () async {
final RecordingCanvas rc =
RecordingCanvas(const Rect.fromLTRB(0, 0, 200, 400));
RecordingCanvas(const Rect.fromLTRB(0, 0, 200, 400));
rc.save();
rc.translate(50.0, 100.0);
final Path path = Path();