Skip to content

Commit

Permalink
make sure to sync PathEffet to null for Dart Canvas rendering (flutte…
Browse files Browse the repository at this point in the history
  • Loading branch information
flar authored Apr 14, 2022
1 parent e31f4cd commit 156e809
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/ui/painting/paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ bool Paint::sync_to(DisplayListBuilder* builder,
builder->setDither(uint_data[kDitherIndex] != 0);
}

if (flags.applies_path_effect()) {
// The paint API exposed to Dart does not support path effects. But other
// operations such as text may set a path effect, which must be cleared.
builder->setPathEffect(nullptr);
}

if (flags.applies_mask_filter()) {
switch (uint_data[kMaskFilterIndex]) {
case Null:
Expand Down
45 changes: 43 additions & 2 deletions testing/dart/canvas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ Future<bool> fuzzyGoldenImageCompare(

final Codec codec = await instantiateImageCodec(goldenData);
final FrameInfo frame = await codec.getNextFrame();
expect(frame.image.height, equals(image.width));
expect(frame.image.width, equals(image.height));
expect(frame.image.height, equals(image.height));
expect(frame.image.width, equals(image.width));

areEqual = await fuzzyCompareImages(frame.image, image);
}
Expand Down Expand Up @@ -316,4 +316,45 @@ void main() {
}
expect(areEqual, true);
});

test('Path effects from Paragraphs do not affect further rendering', () async {
void drawText(Canvas canvas, String content, Offset offset,
{TextDecorationStyle style = TextDecorationStyle.solid}) {
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle());
builder.pushStyle(TextStyle(
decoration: TextDecoration.underline,
decorationColor: const Color(0xFF0000FF),
fontSize: 10,
color: const Color(0xFF000000),
decorationStyle: style,
));
builder.addText(content);
final Paragraph paragraph = builder.build();
paragraph.layout(const ParagraphConstraints(width: 100));
canvas.drawParagraph(paragraph, offset);
}

final Image image = await toImage((Canvas canvas) {
canvas.drawColor(const Color(0xFFFFFFFF), BlendMode.srcOver);
final Paint paint = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 5;
drawText(canvas, 'Hello World', const Offset(20, 10));
canvas.drawCircle(const Offset(150, 25), 15, paint..color = const Color(0xFF00FF00));
drawText(canvas, 'Regular text', const Offset(20, 60));
canvas.drawCircle(const Offset(150, 75), 15, paint..color = const Color(0xFFFFFF00));
drawText(canvas, 'Dotted text', const Offset(20, 110), style: TextDecorationStyle.dotted);
canvas.drawCircle(const Offset(150, 125), 15, paint..color = const Color(0xFFFF0000));
drawText(canvas, 'Dashed text', const Offset(20, 160), style: TextDecorationStyle.dashed);
canvas.drawCircle(const Offset(150, 175), 15, paint..color = const Color(0xFFFF0000));
drawText(canvas, 'Wavy text', const Offset(20, 210), style: TextDecorationStyle.wavy);
canvas.drawCircle(const Offset(150, 225), 15, paint..color = const Color(0xFFFF0000));
}, 200, 250);
expect(image.width, equals(200));
expect(image.height, equals(250));

final bool areEqual =
await fuzzyGoldenImageCompare(image, 'dotted_path_effect_mixed_with_stroked_geometry.png');
expect(areEqual, true);
}, skip: !Platform.isLinux); // https://github.com/flutter/flutter/issues/53784
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 156e809

Please sign in to comment.