Commit 64bf04b3 authored by eae@chromium.org's avatar eae@chromium.org

[DirectWrite] Limit noSubpixelForSmallSizeFont to low-DPI

Limit the noSubpixelForSmallSizeFont functionality that disables
subpixel text for older fonts at sizes below 16px to low-DPI devices.
At or above a 150% DPI subpixel text is enabled for all fonts assuming
anti-aliasing is enabled.

As the font code isn't aware of the DPI or device pixel ratio it needs
to be supplied by Chrome though WebFontRendering.

Chrome side change is in https://codereview.chromium.org/561503002/

R=cpu@chromium.org, dglazkov@chromium.org
BUG=405445

Review URL: https://codereview.chromium.org/553163002

git-svn-id: svn://svn.chromium.org/blink/trunk@181688 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 7db9482e
......@@ -69,6 +69,7 @@ static FontPlatformDataCache* gFontPlatformDataCache = 0;
bool FontCache::s_useDirectWrite = false;
IDWriteFactory* FontCache::s_directWriteFactory = 0;
bool FontCache::s_useSubpixelPositioning = false;
float FontCache::s_deviceScaleFactor = 1.0;
#endif // OS(WIN)
FontCache* FontCache::fontCache()
......
......@@ -104,8 +104,10 @@ public:
bool useSubpixelPositioning() const { return s_useSubpixelPositioning; }
SkFontMgr* fontManager() { return m_fontManager.get(); }
static bool useDirectWrite() { return s_useDirectWrite; }
static float deviceScaleFactor() { return s_deviceScaleFactor; }
static void setUseDirectWrite(bool useDirectWrite) { s_useDirectWrite = useDirectWrite; }
static void setDirectWriteFactory(IDWriteFactory* factory) { s_directWriteFactory = factory; }
static void setDeviceScaleFactor(float deviceScaleFactor) { s_deviceScaleFactor = deviceScaleFactor; }
static void setUseSubpixelPositioning(bool useSubpixelPositioning) { s_useSubpixelPositioning = useSubpixelPositioning; }
static void addSideloadedFontForTesting(SkTypeface*);
#endif
......@@ -162,6 +164,7 @@ private:
OwnPtr<SkFontMgr> m_fontManager;
static bool s_useDirectWrite;
static IDWriteFactory* s_directWriteFactory;
static float s_deviceScaleFactor;
static bool s_useSubpixelPositioning;
static HashMap<String, RefPtr<SkTypeface> >* s_sideloadedFonts;
#endif
......
......@@ -64,13 +64,20 @@ void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext* context) cons
if (ts >= m_minSizeForAntiAlias) {
// Subpixel text positioning looks pretty bad without font smoothing.
// Disable it unless some type of font smoothing is used. As most tests
// run without font smoothing we enable it for tests to ensure we get
// good test coverage matching the more common smoothing enabled
// behavior.
if (m_useSubpixelPositioning && ts >= m_minSizeForSubpixel
&& ((textFlags & SkPaint::kAntiAlias_Flag) || LayoutTestSupport::isRunningLayoutTest()))
if (m_useSubpixelPositioning
// Disable subpixel text for certain older fonts at smaller sizes as
// they tend to get quite blurry at non-integer sizes and positions.
// For high-DPI this workaround isn't required.
&& (ts >= m_minSizeForSubpixel
|| FontCache::fontCache()->deviceScaleFactor() >= 1.5)
// Subpixel text positioning looks pretty bad without font
// smoothing. Disable it unless some type of font smoothing is used.
// As most tests run without font smoothing we enable it for tests
// to ensure we get good test coverage matching the more common
// smoothing enabled behavior.
&& ((textFlags & SkPaint::kAntiAlias_Flag)
|| LayoutTestSupport::isRunningLayoutTest()))
flags |= SkPaint::kSubpixelText_Flag;
// Only set painting flags when we're actually painting.
......
......@@ -21,6 +21,12 @@ void WebFontRendering::setDirectWriteFactory(IDWriteFactory* factory)
blink::FontCache::setDirectWriteFactory(factory);
}
// static
void WebFontRendering::setDeviceScaleFactor(float deviceScaleFactor)
{
blink::FontCache::setDeviceScaleFactor(deviceScaleFactor);
}
// static
void WebFontRendering::setUseSubpixelPositioning(bool useSubpixelPositioning)
{
......
......@@ -16,6 +16,7 @@ class WebFontRendering {
public:
BLINK_EXPORT static void setUseDirectWrite(bool);
BLINK_EXPORT static void setDirectWriteFactory(IDWriteFactory*);
BLINK_EXPORT static void setDeviceScaleFactor(float);
BLINK_EXPORT static void setUseSubpixelPositioning(bool);
BLINK_EXPORT static void addSideloadedFontForTesting(SkTypeface*);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment