Skip to content

Commit

Permalink
Bug 1532171 - don't use light-on-dark mask when font smoothing is dis…
Browse files Browse the repository at this point in the history
…abled on macOS r=rhunt

Differential Revision: https://phabricator.services.mozilla.com/D22006

--HG--
extra : moz-landing-system : lando
  • Loading branch information
lsalzman committed Mar 4, 2019
1 parent 28ef99f commit f4063ee
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions gfx/skia/skia/src/ports/SkFontHost_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2337,19 +2337,6 @@ SkScalerContext* SkTypeface_Mac::onCreateScalerContext(const SkScalerContextEffe
}

void SkTypeface_Mac::onFilterRec(SkScalerContextRec* rec) const {
if (rec->fMaskFormat == SkMask::kLCD16_Format ||
rec->fFlags & SkScalerContext::kGenA8FromLCD_Flag) {
SkColor color = rec->getLuminanceColor();
int r = SkColorGetR(color);
int g = SkColorGetG(color);
int b = SkColorGetB(color);
// Choose whether to draw using a light-on-dark mask based on observed
// color/luminance thresholds that CoreText uses.
if (r >= 85 && g >= 85 && b >= 85 && r + g + b >= 2 * 255) {
rec->fFlags |= SkScalerContext::kLightOnDark_Flag;
}
}

if (rec->fFlags & SkScalerContext::kLCD_BGROrder_Flag ||
rec->fFlags & SkScalerContext::kLCD_Vertical_Flag)
{
Expand Down Expand Up @@ -2431,6 +2418,21 @@ void SkTypeface_Mac::onFilterRec(SkScalerContextRec* rec) const {
//CoreGraphics dialates smoothed text as needed.
rec->setContrast(0);
}

// Smoothing will be used if the format is either LCD or if there is hinting.
// In those cases, we need to choose the proper dilation mask based on the color.
if (rec->fMaskFormat == SkMask::kLCD16_Format ||
(rec->fMaskFormat == SkMask::kA8_Format && rec->getHinting() != SkPaint::kNo_Hinting())) {
SkColor color = rec->getLuminanceColor();
int r = SkColorGetR(color);
int g = SkColorGetG(color);
int b = SkColorGetB(color);
// Choose whether to draw using a light-on-dark mask based on observed
// color/luminance thresholds that CoreText uses.
if (r >= 85 && g >= 85 && b >= 85 && r + g + b >= 2 * 255) {
rec->fFlags |= SkScalerContext::kLightOnDark_Flag;
}
}
}

/** Takes ownership of the CFStringRef. */
Expand Down

0 comments on commit f4063ee

Please sign in to comment.