From f8aa71dcae3467fadb88353e5cfd087331f48924 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Tue, 1 Feb 2022 21:41:17 +0000 Subject: [PATCH] Bug 1747272 - Apply current color when rasterizing glyphs from color fonts in Skia using Core Text. r=lsalzman Differential Revision: https://phabricator.services.mozilla.com/D137567 --- gfx/skia/skia/src/ports/SkFontHost_mac.cpp | 22 +++++++++-- layout/reftests/bugs/1747272-1-ref.html | 37 +++++++++++++++++ layout/reftests/bugs/1747272-1.html | 46 ++++++++++++++++++++++ layout/reftests/bugs/reftest.list | 1 + 4 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 layout/reftests/bugs/1747272-1-ref.html create mode 100644 layout/reftests/bugs/1747272-1.html diff --git a/gfx/skia/skia/src/ports/SkFontHost_mac.cpp b/gfx/skia/skia/src/ports/SkFontHost_mac.cpp index e57b5eb5fb72..8e7b9363ba04 100644 --- a/gfx/skia/skia/src/ports/SkFontHost_mac.cpp +++ b/gfx/skia/skia/src/ports/SkFontHost_mac.cpp @@ -1176,10 +1176,6 @@ CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph& CGContextSetTextDrawingMode(fCG.get(), kCGTextFill); - // Draw black on white to create mask. (Special path exists to speed this up in CG.) - // If light-on-dark is requested, draw white on black. - CGContextSetGrayFillColor(fCG.get(), lightOnDark ? 1.0f : 0.0f, 1.0f); - // force our checks below to happen fDoAA = !doAA; fDoLCD = !doLCD; @@ -1187,6 +1183,24 @@ CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph& CGContextSetTextMatrix(fCG.get(), context.fTransform); } + if (glyph.isColor()) { + // Set the current color for layers with palette index 0xffff, or non-colored + // glyphs that may be present in a color font. + // + // Per comment in the Windows code at https://searchfox.org/mozilla-central/source/gfx/skia/skia/src/ports/SkScalerContext_win_dw.cpp#1069-1074: + // > "getLuminanceColor() is kinda sorta what is wanted here, but not really, + // > it will often be the wrong value because it wan't designed for this. + // + // Empirically, in simple testcases it looks like a decent approximation of what + // we need. + SkColor4f color = SkColor4f::FromColor(context.getRec().getLuminanceColor()); + CGContextSetRGBFillColor(fCG.get(), color.fR, color.fG, color.fB, 1.0f); + } else { + // Draw black on white to create mask. (Special path exists to speed this up in CG.) + // If light-on-dark is requested, draw white on black. + CGContextSetGrayFillColor(fCG.get(), lightOnDark ? 1.0f : 0.0f, 1.0f); + } + if (fDoAA != doAA) { CGContextSetShouldAntialias(fCG.get(), doAA); fDoAA = doAA; diff --git a/layout/reftests/bugs/1747272-1-ref.html b/layout/reftests/bugs/1747272-1-ref.html new file mode 100644 index 000000000000..ea9252267ee0 --- /dev/null +++ b/layout/reftests/bugs/1747272-1-ref.html @@ -0,0 +1,37 @@ + + + + “Amiri Quran Colored” test + + +
The Arabic glyphs should NOT be visible against the blue background in either box:
+
+

اردو +

+
+
+

اردو +

+
+ + diff --git a/layout/reftests/bugs/1747272-1.html b/layout/reftests/bugs/1747272-1.html new file mode 100644 index 000000000000..79f3c6007d62 --- /dev/null +++ b/layout/reftests/bugs/1747272-1.html @@ -0,0 +1,46 @@ + + + + “Amiri Quran Colored” test + + +
The Arabic glyphs should NOT be visible against the blue background in either box:
+
+

اردو +

+
+
+

اردو +

+
+ + diff --git a/layout/reftests/bugs/reftest.list b/layout/reftests/bugs/reftest.list index 1a67b4551375..3f71489225dc 100644 --- a/layout/reftests/bugs/reftest.list +++ b/layout/reftests/bugs/reftest.list @@ -2112,4 +2112,5 @@ skip-if(Android||!browserIsFission) fuzzy(255-255,171000-171000) HTTP == 1743533 == 1743560-1.html 1743560-1-ref.html == 1743851-1.html 1743851-1-ref.html pref(image.downscale-during-decode.enabled,true) == 1744468-1.html 1744468-1-ref.html # do not increase fuzz without looking, the test should be smoothly downscaled, not pixelated +== 1747272-1.html 1747272-1-ref.html == 1750146-1.html 1750146-1-ref.html