Support PaintTranslate in COLRv1 rasterisation

Found during implementation of COLRv1 fuzzer for FreeType that translate
operation was still missing.

Added a test glyph containing two squares filled with a radial gradient
shifted by dx 128, dy -128 and dx -308, dy 307
combined using a PaintComposite.

Bug: skia:11790
Change-Id: I4cbfe34a111a450777dc2f8fa9d32a405f808a89
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/389116
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Dominik Röttsches 2021-03-25 16:13:46 +02:00 committed by Skia Commit-Bot
parent ced1d35bc5
commit 2e04df9a06
3 changed files with 18 additions and 2 deletions

View File

@ -31,7 +31,7 @@ public:
protected:
struct EmojiFont {
sk_sp<SkTypeface> fTypeface;
const uint16_t fGlyphs[9] = {19, 33, 34, 20, 21, 22, 23, 24, 25 };
const uint16_t fGlyphs[10] = { 19, 33, 34, 35, 20, 21, 22, 23, 24, 25 };
const size_t fGlyphs_bytesize =
SK_ARRAY_COUNT(fGlyphs) * sizeof(uint16_t);
} fEmojiFont;
@ -50,7 +50,7 @@ protected:
return SkString("colrv1");
}
SkISize onISize() override { return SkISize::Make(1200, 600); }
SkISize onISize() override { return SkISize::Make(1400, 600); }
DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
canvas->drawColor(SK_ColorWHITE);

Binary file not shown.

View File

@ -671,6 +671,14 @@ void colrv1_draw_paint(SkCanvas* canvas,
canvas->concat(transform);
break;
}
case FT_COLR_PAINTFORMAT_TRANSLATE: {
SkMatrix translate = SkMatrix::Translate(
SkFixedToScalar(colrv1_paint.u.translate.dx),
-SkFixedToScalar(colrv1_paint.u.translate.dy));
canvas->concat(translate);
break;
}
case FT_COLR_PAINTFORMAT_ROTATE: {
SkMatrix rotation = SkMatrix::RotateDeg(
SkFixedToScalar(colrv1_paint.u.rotate.angle),
@ -768,6 +776,14 @@ bool colrv1_traverse_paint(SkCanvas* canvas,
colrv1_traverse_paint(canvas, palette, face, paint.u.transformed.paint);
canvas->restore();
break;
case FT_COLR_PAINTFORMAT_TRANSLATE:
canvas->saveLayer(nullptr, nullptr);
// Traverse / draw operation will apply transform.
colrv1_draw_paint(canvas, palette, face, paint);
traverse_result =
colrv1_traverse_paint(canvas, palette, face, paint.u.translate.paint);
canvas->restore();
break;
case FT_COLR_PAINTFORMAT_ROTATE:
canvas->saveLayer(nullptr, nullptr);
// Traverse / draw operation will apply transform.