make sure to sync PathEffet to null for Dart Canvas rendering (flutter/engine#32672)

This commit is contained in:
Jim Graham
2022-04-14 12:39:04 -07:00
committed by GitHub
parent 058a2cc62c
commit 1c35cc7dc2
3 changed files with 49 additions and 2 deletions

View File

@@ -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:

View File

@@ -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);
}
@@ -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
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB