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

Commit 156e809

Browse files
authored
make sure to sync PathEffet to null for Dart Canvas rendering (#32672)
1 parent e31f4cd commit 156e809

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

lib/ui/painting/paint.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ bool Paint::sync_to(DisplayListBuilder* builder,
292292
builder->setDither(uint_data[kDitherIndex] != 0);
293293
}
294294

295+
if (flags.applies_path_effect()) {
296+
// The paint API exposed to Dart does not support path effects. But other
297+
// operations such as text may set a path effect, which must be cleared.
298+
builder->setPathEffect(nullptr);
299+
}
300+
295301
if (flags.applies_mask_filter()) {
296302
switch (uint_data[kMaskFilterIndex]) {
297303
case Null:

testing/dart/canvas_test.dart

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ Future<bool> fuzzyGoldenImageCompare(
154154

155155
final Codec codec = await instantiateImageCodec(goldenData);
156156
final FrameInfo frame = await codec.getNextFrame();
157-
expect(frame.image.height, equals(image.width));
158-
expect(frame.image.width, equals(image.height));
157+
expect(frame.image.height, equals(image.height));
158+
expect(frame.image.width, equals(image.width));
159159

160160
areEqual = await fuzzyCompareImages(frame.image, image);
161161
}
@@ -316,4 +316,45 @@ void main() {
316316
}
317317
expect(areEqual, true);
318318
});
319+
320+
test('Path effects from Paragraphs do not affect further rendering', () async {
321+
void drawText(Canvas canvas, String content, Offset offset,
322+
{TextDecorationStyle style = TextDecorationStyle.solid}) {
323+
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle());
324+
builder.pushStyle(TextStyle(
325+
decoration: TextDecoration.underline,
326+
decorationColor: const Color(0xFF0000FF),
327+
fontSize: 10,
328+
color: const Color(0xFF000000),
329+
decorationStyle: style,
330+
));
331+
builder.addText(content);
332+
final Paragraph paragraph = builder.build();
333+
paragraph.layout(const ParagraphConstraints(width: 100));
334+
canvas.drawParagraph(paragraph, offset);
335+
}
336+
337+
final Image image = await toImage((Canvas canvas) {
338+
canvas.drawColor(const Color(0xFFFFFFFF), BlendMode.srcOver);
339+
final Paint paint = Paint()
340+
..style = PaintingStyle.stroke
341+
..strokeWidth = 5;
342+
drawText(canvas, 'Hello World', const Offset(20, 10));
343+
canvas.drawCircle(const Offset(150, 25), 15, paint..color = const Color(0xFF00FF00));
344+
drawText(canvas, 'Regular text', const Offset(20, 60));
345+
canvas.drawCircle(const Offset(150, 75), 15, paint..color = const Color(0xFFFFFF00));
346+
drawText(canvas, 'Dotted text', const Offset(20, 110), style: TextDecorationStyle.dotted);
347+
canvas.drawCircle(const Offset(150, 125), 15, paint..color = const Color(0xFFFF0000));
348+
drawText(canvas, 'Dashed text', const Offset(20, 160), style: TextDecorationStyle.dashed);
349+
canvas.drawCircle(const Offset(150, 175), 15, paint..color = const Color(0xFFFF0000));
350+
drawText(canvas, 'Wavy text', const Offset(20, 210), style: TextDecorationStyle.wavy);
351+
canvas.drawCircle(const Offset(150, 225), 15, paint..color = const Color(0xFFFF0000));
352+
}, 200, 250);
353+
expect(image.width, equals(200));
354+
expect(image.height, equals(250));
355+
356+
final bool areEqual =
357+
await fuzzyGoldenImageCompare(image, 'dotted_path_effect_mixed_with_stroked_geometry.png');
358+
expect(areEqual, true);
359+
}, skip: !Platform.isLinux); // https://github.com/flutter/flutter/issues/53784
319360
}
4.77 KB
Loading

0 commit comments

Comments
 (0)