Compare to the correct hinting.
Without this change no-hinting subpixel-antialias requests on Mac 10.14
will not be gamma adjusted when they should be.
Bug: chromium:933137
Change-Id: I666f9f37ac849ed76a6b6aaab4966f4dd9fb5fb3
Reviewed-on: https://skia-review.googlesource.com/c/194188
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Mike Reed <reed@google.com>
diff --git a/gm/typeface.cpp b/gm/typeface.cpp
index 39d27fd..b90e9e7 100644
--- a/gm/typeface.cpp
+++ b/gm/typeface.cpp
@@ -149,8 +149,7 @@
static void draw_typeface_rendering_gm(SkCanvas* canvas, sk_sp<SkTypeface> face,
char character = 'A') {
struct AliasType {
- bool antiAlias;
- bool subpixelAntitalias;
+ SkFont::Edging edging;
bool inLayer;
} constexpr aliasTypes[] {
#ifndef SK_BUILD_FOR_IOS
@@ -164,24 +163,12 @@
// 0x330b19d8 <+88>: ldr r0, [r4, #0x4]
// Disable testing embedded bitmaps on iOS for now.
// See https://bug.skia.org/5530 .
- { false, false, false }, // aliased
+ { SkFont::Edging::kAlias , false },
#endif
- { true, false, false }, // anti-aliased
- { true, true , false }, // subpixel anti-aliased
- { true, false, true }, // anti-aliased in layer (flat pixel geometry)
- { true, true , true }, // subpixel anti-aliased in layer (flat pixel geometry)
- };
-
- auto compute_edging = [](AliasType at) {
- if (at.antiAlias) {
- if (at.subpixelAntitalias) {
- return SkFont::Edging::kSubpixelAntiAlias;
- } else {
- return SkFont::Edging::kAntiAlias;
- }
- } else {
- return SkFont::Edging::kAlias;
- }
+ { SkFont::Edging::kAntiAlias , false },
+ { SkFont::Edging::kSubpixelAntiAlias, false },
+ { SkFont::Edging::kAntiAlias , true },
+ { SkFont::Edging::kSubpixelAntiAlias, true },
};
// The hintgasp.ttf is designed for the following sizes to be different.
@@ -229,7 +216,7 @@
font.setSubpixel(subpixel.requested);
for (const AliasType& alias : aliasTypes) {
- font.setEdging(compute_edging(alias));
+ font.setEdging(alias.edging);
SkAutoCanvasRestore acr(canvas, false);
if (alias.inLayer) {
canvas->saveLayer(nullptr, &paint);
@@ -292,7 +279,7 @@
font.setEmbolden(fakeBold);
for (const AliasType& alias : aliasTypes) {
- font.setEdging(compute_edging(alias));
+ font.setEdging(alias.edging);
SkAutoCanvasRestore acr(canvas, false);
if (alias.inLayer) {
canvas->saveLayer(nullptr, &paint);
@@ -343,7 +330,7 @@
y += dy;
x = 5;
- font.setEdging(compute_edging(alias));
+ font.setEdging(alias.edging);
SkAutoCanvasRestore acr(canvas, false);
if (alias.inLayer) {
canvas->saveLayer(nullptr, &paint);
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 4bfc7fa..2f3aa34 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -2230,16 +2230,17 @@
SmoothBehavior smoothBehavior = smooth_behavior();
// Only two levels of hinting are supported.
- // kNo_Hinting means avoid CoreGraphics outline dilation.
- // kNormal_Hinting means CoreGraphics outline dilation is allowed.
- // If there is no lcd support, hinting (dilation) cannot be supported.
- SkFontHinting hinting = rec->getHinting();
- if (kSlight_SkFontHinting == hinting || smoothBehavior == SmoothBehavior::none) {
- hinting = kNo_SkFontHinting;
- } else if (kFull_SkFontHinting == hinting) {
- hinting = kNormal_SkFontHinting;
+ // kNo_Hinting means avoid CoreGraphics outline dilation (smoothing).
+ // kNormal_Hinting means CoreGraphics outline dilation (smoothing) is allowed.
+ if (kSlight_SkFontHinting == rec->getHinting()) {
+ rec->setHinting(kNo_SkFontHinting);
+ } else if (kFull_SkFontHinting == rec->getHinting()) {
+ rec->setHinting(kNormal_SkFontHinting);
}
- rec->setHinting(hinting);
+ // If smoothing has no effect, don't request it.
+ if (smoothBehavior == SmoothBehavior::none) {
+ rec->setHinting(kNo_SkFontHinting);
+ }
// FIXME: lcd smoothed un-hinted rasterization unsupported.
// Tracked by http://code.google.com/p/skia/issues/detail?id=915 .
@@ -2259,7 +2260,6 @@
// [LCD][no-hint]: curently unable to honor, and must pick which to respect.
// Currenly side with LCD, effectively ignoring the hinting setting.
// [LCD][yes-hint]: generate LCD using CoreGraphic's LCD output.
-
if (rec->fMaskFormat == SkMask::kLCD16_Format) {
if (smoothBehavior == SmoothBehavior::subpixel) {
//CoreGraphics creates 555 masks for smoothed text anyway.
@@ -2267,7 +2267,7 @@
rec->setHinting(kNormal_SkFontHinting);
} else {
rec->fMaskFormat = SkMask::kA8_Format;
- if (smoothBehavior == SmoothBehavior::some) {
+ if (smoothBehavior != SmoothBehavior::none) {
rec->setHinting(kNormal_SkFontHinting);
}
}
@@ -2282,7 +2282,7 @@
// Unhinted A8 masks (those not derived from LCD masks) must respect SK_GAMMA_APPLY_TO_A8.
// All other masks can use regular gamma.
- if (SkMask::kA8_Format == rec->fMaskFormat && kNo_SkFontHinting == hinting) {
+ if (SkMask::kA8_Format == rec->fMaskFormat && kNo_SkFontHinting == rec->getHinting()) {
#ifndef SK_GAMMA_APPLY_TO_A8
// SRGBTODO: Is this correct? Do we want contrast boost?
rec->ignorePreBlend();