Bug 1298484. Use cleartype and convert to grayscale AA for skia windows fonts if cleartype is disabled system wide. r=lsalzman

This commit is contained in:
Mason Chang 2016-09-02 15:00:29 -07:00
parent 45276cf8ca
commit e6c63d0931
7 changed files with 101 additions and 53 deletions

View File

@ -672,6 +672,7 @@ public:
typedef void (*FontDescriptorOutput)(const uint8_t *aData, uint32_t aLength, Float aFontSize, void *aBaton);
virtual FontType GetType() const = 0;
virtual AntialiasMode GetDefaultAAMode() { return AntialiasMode::DEFAULT; }
/** This allows getting a path that describes the outline of a set of glyphs.
* A target is passed in so that the guarantee is made the returned path

View File

@ -1183,12 +1183,8 @@ ShouldUseCGToFillGlyphs(const GlyphRenderingOptions* aOptions, const Pattern& aP
#endif
void
DrawTargetSkia::FillGlyphs(ScaledFont *aFont,
const GlyphBuffer &aBuffer,
const Pattern &aPattern,
const DrawOptions &aOptions,
const GlyphRenderingOptions *aRenderingOptions)
static bool
CanDrawFont(ScaledFont* aFont)
{
switch (aFont->GetType()) {
case FontType::SKIA:
@ -1197,8 +1193,20 @@ DrawTargetSkia::FillGlyphs(ScaledFont *aFont,
case FontType::MAC:
case FontType::GDI:
case FontType::DWRITE:
break;
return true;
default:
return false;
}
}
void
DrawTargetSkia::FillGlyphs(ScaledFont *aFont,
const GlyphBuffer &aBuffer,
const Pattern &aPattern,
const DrawOptions &aOptions,
const GlyphRenderingOptions *aRenderingOptions)
{
if (!CanDrawFont(aFont)) {
return;
}
@ -1219,11 +1227,18 @@ DrawTargetSkia::FillGlyphs(ScaledFont *aFont,
}
AutoPaintSetup paint(mCanvas.get(), aOptions, aPattern);
AntialiasMode aaMode = aFont->GetDefaultAAMode();
if (aOptions.mAntialiasMode != AntialiasMode::DEFAULT) {
aaMode = aOptions.mAntialiasMode;
}
bool aaEnabled = aaMode != AntialiasMode::NONE;
paint.mPaint.setAntiAlias(aaEnabled);
paint.mPaint.setTypeface(typeface);
paint.mPaint.setTextSize(SkFloatToScalar(skiaFont->mSize));
paint.mPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
bool shouldLCDRenderText = ShouldLCDRenderText(aFont->GetType(), aOptions.mAntialiasMode);
bool shouldLCDRenderText = ShouldLCDRenderText(aFont->GetType(), aaMode);
paint.mPaint.setLCDRenderText(shouldLCDRenderText);
bool useSubpixelText = true;
@ -1237,7 +1252,7 @@ DrawTargetSkia::FillGlyphs(ScaledFont *aFont,
useSubpixelText = false;
break;
case FontType::MAC:
if (aOptions.mAntialiasMode == AntialiasMode::GRAY) {
if (aaMode == AntialiasMode::GRAY) {
// Normally, Skia enables LCD FontSmoothing which creates thicker fonts
// and also enables subpixel AA. CoreGraphics without font smoothing
// explicitly creates thinner fonts and grayscale AA.
@ -1257,14 +1272,15 @@ DrawTargetSkia::FillGlyphs(ScaledFont *aFont,
}
break;
case FontType::GDI:
{
if (!shouldLCDRenderText) {
// If we have non LCD GDI text, Cairo currently always uses cleartype fonts and
// converts them to grayscale. Force Skia to do the same, otherwise we use
// GDI fonts with the ANTIALIASED_QUALITY which is generally bolder than
// Cleartype fonts.
// If we have non LCD GDI text, render the fonts as cleartype and convert them
// to grayscale. This seems to be what Chrome and IE are doing on Windows 7.
// This also applies if cleartype is disabled system wide.
paint.mPaint.setFlags(paint.mPaint.getFlags() | SkPaint::kGenA8FromLCD_Flag);
}
break;
}
default:
break;
}

58
gfx/2d/HelpersWinFonts.h Normal file
View File

@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
namespace mozilla {
namespace gfx {
// Cleartype can be dynamically enabled/disabled, so we have to check it
// everytime we want to render some text.
static BYTE
GetSystemTextQuality()
{
BOOL font_smoothing;
UINT smoothing_type;
if (!SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &font_smoothing, 0)) {
return DEFAULT_QUALITY;
}
if (font_smoothing) {
if (!SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE,
0, &smoothing_type, 0)) {
return DEFAULT_QUALITY;
}
if (smoothing_type == FE_FONTSMOOTHINGCLEARTYPE) {
return CLEARTYPE_QUALITY;
}
return ANTIALIASED_QUALITY;
}
return DEFAULT_QUALITY;
}
static AntialiasMode
GetSystemDefaultAAMode()
{
AntialiasMode defaultMode = AntialiasMode::SUBPIXEL;
switch (GetSystemTextQuality()) {
case CLEARTYPE_QUALITY:
defaultMode = AntialiasMode::SUBPIXEL;
break;
case ANTIALIASED_QUALITY:
defaultMode = AntialiasMode::GRAY;
break;
case DEFAULT_QUALITY:
defaultMode = AntialiasMode::NONE;
break;
}
return defaultMode;
}
} // namespace gfx
} // namespace mozilla

View File

@ -22,35 +22,11 @@ using namespace std;
#include "cairo-win32.h"
#endif
#include "HelpersWinFonts.h"
namespace mozilla {
namespace gfx {
static BYTE
GetSystemTextQuality()
{
BOOL font_smoothing;
UINT smoothing_type;
if (!SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &font_smoothing, 0)) {
return DEFAULT_QUALITY;
}
if (font_smoothing) {
if (!SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE,
0, &smoothing_type, 0)) {
return DEFAULT_QUALITY;
}
if (smoothing_type == FE_FONTSMOOTHINGCLEARTYPE) {
return CLEARTYPE_QUALITY;
}
return ANTIALIASED_QUALITY;
}
return DEFAULT_QUALITY;
}
#define GASP_TAG 0x70736167
#define GASP_DOGRAY 0x2
@ -315,19 +291,7 @@ ScaledFontDWrite::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton
AntialiasMode
ScaledFontDWrite::GetDefaultAAMode()
{
AntialiasMode defaultMode = AntialiasMode::SUBPIXEL;
switch (GetSystemTextQuality()) {
case CLEARTYPE_QUALITY:
defaultMode = AntialiasMode::SUBPIXEL;
break;
case ANTIALIASED_QUALITY:
defaultMode = AntialiasMode::GRAY;
break;
case DEFAULT_QUALITY:
defaultMode = AntialiasMode::NONE;
break;
}
AntialiasMode defaultMode = GetSystemDefaultAAMode();
if (defaultMode == AntialiasMode::GRAY) {
if (!DoGrayscale(mFontFace, mSize)) {

View File

@ -44,7 +44,7 @@ public:
virtual bool GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton);
virtual AntialiasMode GetDefaultAAMode();
virtual AntialiasMode GetDefaultAAMode() override;
#ifdef USE_SKIA
virtual SkTypeface* GetSkTypeface();

View File

@ -18,6 +18,8 @@
#include "cairo-win32.h"
#endif
#include "HelpersWinFonts.h"
namespace mozilla {
namespace gfx {
@ -86,6 +88,12 @@ ScaledFontWin::GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton)
return true;
}
AntialiasMode
ScaledFontWin::GetDefaultAAMode()
{
return GetSystemDefaultAAMode();
}
#ifdef USE_SKIA
SkTypeface* ScaledFontWin::GetSkTypeface()
{

View File

@ -22,6 +22,7 @@ public:
bool GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton) override;
virtual bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override;
virtual AntialiasMode GetDefaultAAMode() override;
#ifdef USE_SKIA
virtual SkTypeface* GetSkTypeface();