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
This commit is contained in:
Jonathan Kew 2022-02-01 21:41:17 +00:00
parent af363ac1f9
commit f8aa71dcae
4 changed files with 102 additions and 4 deletions

View file

@ -1176,10 +1176,6 @@ CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph&
CGContextSetTextDrawingMode(fCG.get(), kCGTextFill); 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 // force our checks below to happen
fDoAA = !doAA; fDoAA = !doAA;
fDoLCD = !doLCD; fDoLCD = !doLCD;
@ -1187,6 +1183,24 @@ CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph&
CGContextSetTextMatrix(fCG.get(), context.fTransform); 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) { if (fDoAA != doAA) {
CGContextSetShouldAntialias(fCG.get(), doAA); CGContextSetShouldAntialias(fCG.get(), doAA);
fDoAA = doAA; fDoAA = doAA;

View file

@ -0,0 +1,37 @@
<html>
<head>
<meta charset=UTF-8>
<title>“Amiri Quran Colored” test</title>
<style>
@font-face {
font-family: AmiriMonochrome;
font-style: normal;
font-weight: 400;
src: url('../fonts/AmiriQuran.otf');
}
.test {
float: left;
direction: rtl;
font-size: 330px;
line-height: 0;
margin: 10px;
padding: 0 50px;
background: blue;
color: blue;
}
.monochrome {
font-family: AmiriMonochrome;
}
</style>
</head>
<div>The Arabic glyphs should NOT be visible against the blue background in either box:</div>
<div class="test monochrome">
<p>اردو
</p>
</div>
<div class="test monochrome">
<p>اردو
</p>
</div>
</html>

View file

@ -0,0 +1,46 @@
<html>
<head>
<meta charset=UTF-8>
<title>“Amiri Quran Colored” test</title>
<style>
@font-face {
font-family: AmiriColored;
font-style: normal;
font-weight: 400;
src: url('../fonts/AmiriQuranColored.otf');
}
@font-face {
font-family: AmiriMonochrome;
font-style: normal;
font-weight: 400;
src: url('../fonts/AmiriQuran.otf');
}
.test {
float: left;
direction: rtl;
font-size: 330px;
line-height: 0;
margin: 10px;
padding: 0 50px;
background: blue;
color: blue;
}
.colored {
font-family: AmiriColored;
}
.monochrome {
font-family: AmiriMonochrome;
}
</style>
</head>
<div>The Arabic glyphs should NOT be visible against the blue background in either box:</div>
<div class="test colored">
<p>اردو
</p>
</div>
<div class="test monochrome">
<p>اردو
</p>
</div>
</html>

View file

@ -2112,4 +2112,5 @@ skip-if(Android||!browserIsFission) fuzzy(255-255,171000-171000) HTTP == 1743533
== 1743560-1.html 1743560-1-ref.html == 1743560-1.html 1743560-1-ref.html
== 1743851-1.html 1743851-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 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 == 1750146-1.html 1750146-1-ref.html