Bug 1321901 - Use IDWriteFontFace::GetRecommendedRenderingMode for font rendering mode in Skia. r=lsalzman
☠☠ backed out by 387b89eeed54 ☠ ☠
authorMason Chang <mchang@mozilla.com>
Wed, 07 Dec 2016 17:27:04 -1000
changeset 325401 f7e0dfe88d42e4c326fdb75b1ebd4228fd1d2f01
parent 325400 cb095e4247e2b059e0af8427e32e4da55cd7edb1
child 325402 82aeade4d0073cd0c2da2d61543fe0a50430cfbb
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerslsalzman
bugs1321901
milestone53.0a1
Bug 1321901 - Use IDWriteFontFace::GetRecommendedRenderingMode for font rendering mode in Skia. r=lsalzman
gfx/skia/skia/src/ports/SkScalerContext_win_dw.cpp
gfx/skia/skia/src/ports/SkScalerContext_win_dw.h
--- a/gfx/skia/skia/src/ports/SkScalerContext_win_dw.cpp
+++ b/gfx/skia/skia/src/ports/SkScalerContext_win_dw.cpp
@@ -214,17 +214,23 @@ SkScalerContext_DW::SkScalerContext_DW(D
 #if SK_HAS_DWRITE_2_H
     fTypeface->fFactory->QueryInterface<IDWriteFactory2>(&fFactory2);
 
     SkTScopedComPtr<IDWriteFontFace2> fontFace2;
     fTypeface->fDWriteFontFace->QueryInterface<IDWriteFontFace2>(&fontFace2);
     fIsColorFont = fFactory2.get() && fontFace2.get() && fontFace2->IsColorFont();
 #endif
 
-    // In general, all glyphs should use CLEARTYPE_NATURAL_SYMMETRIC
+    IDWriteFactory* factory = sk_get_dwrite_factory();
+    if (factory != nullptr) {
+        HRVM(factory->CreateRenderingParams(&fDefaultRenderingParams),
+        "Could not create default rendering params");
+    }
+
+    // In general, all glyphs should DWriteFontFace::GetRecommendedRenderingMode
     // except when bi-level rendering is requested or there are embedded
     // bi-level bitmaps (and the embedded bitmap flag is set and no rotation).
     //
     // DirectWrite's IDWriteFontFace::GetRecommendedRenderingMode does not do
     // this. As a result, determine the actual size of the text and then see if
     // there are any embedded bi-level bitmaps of that size. If there are, then
     // force bitmaps by requesting bi-level rendering.
     //
@@ -310,23 +316,31 @@ SkScalerContext_DW::SkScalerContext_DW(D
     // drop out control in the y direction in order to be legible.
     } else if (is_hinted_without_gasp(typeface)) {
         fTextSizeRender = gdiTextSize;
         fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL;
         fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1;
         fTextSizeMeasure = realTextSize;
         fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL;
 
-    // The normal case is to use natural symmetric rendering and linear metrics.
+    // The normal case is to use the recommended rendering mode
     } else {
         fTextSizeRender = realTextSize;
-        fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;
         fTextureType = DWRITE_TEXTURE_CLEARTYPE_3x1;
         fTextSizeMeasure = realTextSize;
         fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL;
+
+        if (!SUCCEEDED(fTypeface->fDWriteFontFace->GetRecommendedRenderingMode(
+                fTextSizeRender,
+                1.0f,
+                fMeasuringMode,
+                fDefaultRenderingParams.get(),
+                &fRenderingMode))) {
+            fRenderingMode = DWRITE_RENDERING_MODE_CLEARTYPE_NATURAL_SYMMETRIC;
+        }
     }
 
     if (this->isSubpixel()) {
         fTextSizeMeasure = realTextSize;
         fMeasuringMode = DWRITE_MEASURING_MODE_NATURAL;
     }
 }
 
--- a/gfx/skia/skia/src/ports/SkScalerContext_win_dw.h
+++ b/gfx/skia/skia/src/ports/SkScalerContext_win_dw.h
@@ -70,15 +70,16 @@ private:
     SkScalar fTextSizeRender;
     /** The text size to measure with. */
     SkScalar fTextSizeMeasure;
     SkAutoTUnref<DWriteFontTypeface> fTypeface;
     int fGlyphCount;
     DWRITE_RENDERING_MODE fRenderingMode;
     DWRITE_TEXTURE_TYPE fTextureType;
     DWRITE_MEASURING_MODE fMeasuringMode;
+    SkTScopedComPtr<IDWriteRenderingParams> fDefaultRenderingParams;
 #if SK_HAS_DWRITE_2_H
     SkTScopedComPtr<IDWriteFactory2> fFactory2;
     bool fIsColorFont;
 #endif
 };
 
 #endif