Bug 1053652 - Cannot open include file: 'dwrite_1.h'. r=gw280, a=lmandel
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Fri, 03 Oct 2014 01:54:23 -0400
changeset 225505 9541f5fe77f717fd7ffed9d28d640dd2a69df013
parent 225504 690369cf0542fd3591ad529a1dd879faa4d4bb88
child 225506 f1d7d83cacd6a173eeab9ce1f4a5d3923c8db0a0
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgw280, lmandel
bugs1053652
milestone34.0a2
Bug 1053652 - Cannot open include file: 'dwrite_1.h'. r=gw280, a=lmandel Imports/Transplants upstream https://codereview.chromium.org/552383002/
gfx/skia/trunk/src/ports/SkScalerContext_win_dw.cpp
gfx/skia/trunk/src/ports/SkTypeface_win_dw.h
gfx/skia/trunk/src/utils/win/SkDWrite.h
--- a/gfx/skia/trunk/src/ports/SkScalerContext_win_dw.cpp
+++ b/gfx/skia/trunk/src/ports/SkScalerContext_win_dw.cpp
@@ -21,17 +21,19 @@
 #include "SkOTTable_maxp.h"
 #include "SkPath.h"
 #include "SkScalerContext.h"
 #include "SkScalerContext_win_dw.h"
 #include "SkTScopedComPtr.h"
 #include "SkTypeface_win_dw.h"
 
 #include <dwrite.h>
-#include <dwrite_1.h>
+#if SK_HAS_DWRITE_1_H
+#  include <dwrite_1.h>
+#endif
 
 static bool isLCD(const SkScalerContext::Rec& rec) {
     return SkMask::kLCD16_Format == rec.fMaskFormat ||
            SkMask::kLCD32_Format == rec.fMaskFormat;
 }
 
 static bool is_hinted_without_gasp(DWriteFontTypeface* typeface) {
     AutoTDWriteTable<SkOTTableMaximumProfile> maxp(typeface->fDWriteFontFace.get());
@@ -474,42 +476,48 @@ void SkScalerContext_DW::generateFontMet
     metrics->fLeading = fTextSizeRender * SkIntToScalar(dwfm.lineGap) / upem;
     metrics->fXHeight = fTextSizeRender * SkIntToScalar(dwfm.xHeight) / upem;
     metrics->fUnderlineThickness = fTextSizeRender * SkIntToScalar(dwfm.underlineThickness) / upem;
     metrics->fUnderlinePosition = -(fTextSizeRender * SkIntToScalar(dwfm.underlinePosition) / upem);
 
     metrics->fFlags |= SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag;
     metrics->fFlags |= SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag;
 
+#if SK_HAS_DWRITE_1_H
     if (NULL != fTypeface->fDWriteFontFace1.get()) {
         DWRITE_FONT_METRICS1 dwfm1;
         fTypeface->fDWriteFontFace1->GetMetrics(&dwfm1);
         metrics->fTop = -fTextSizeRender * SkIntToScalar(dwfm1.glyphBoxTop) / upem;
         metrics->fBottom = -fTextSizeRender * SkIntToScalar(dwfm1.glyphBoxBottom) / upem;
         metrics->fXMin = fTextSizeRender * SkIntToScalar(dwfm1.glyphBoxLeft) / upem;
         metrics->fXMax = fTextSizeRender * SkIntToScalar(dwfm1.glyphBoxRight) / upem;
 
         metrics->fMaxCharWidth = metrics->fXMax - metrics->fXMin;
-    } else {
-        AutoTDWriteTable<SkOTTableHead> head(fTypeface->fDWriteFontFace.get());
-        if (head.fExists &&
-            head.fSize >= sizeof(SkOTTableHead) &&
-            head->version == SkOTTableHead::version1)
-        {
-            metrics->fTop = -fTextSizeRender * (int16_t)SkEndian_SwapBE16(head->yMax) / upem;
-            metrics->fBottom = -fTextSizeRender * (int16_t)SkEndian_SwapBE16(head->yMin) / upem;
-            metrics->fXMin = fTextSizeRender * (int16_t)SkEndian_SwapBE16(head->xMin) / upem;
-            metrics->fXMax = fTextSizeRender * (int16_t)SkEndian_SwapBE16(head->xMax) / upem;
+        return;
+    }
+#else
+#  pragma message("No dwrite_1.h is available, font metrics may be affected.")
+#endif
 
-            metrics->fMaxCharWidth = metrics->fXMax - metrics->fXMin;
-        } else {
-            metrics->fTop = metrics->fAscent;
-            metrics->fBottom = metrics->fDescent;
-        }
+    AutoTDWriteTable<SkOTTableHead> head(fTypeface->fDWriteFontFace.get());
+    if (head.fExists &&
+        head.fSize >= sizeof(SkOTTableHead) &&
+        head->version == SkOTTableHead::version1)
+    {
+        metrics->fTop = -fTextSizeRender * (int16_t)SkEndian_SwapBE16(head->yMax) / upem;
+        metrics->fBottom = -fTextSizeRender * (int16_t)SkEndian_SwapBE16(head->yMin) / upem;
+        metrics->fXMin = fTextSizeRender * (int16_t)SkEndian_SwapBE16(head->xMin) / upem;
+        metrics->fXMax = fTextSizeRender * (int16_t)SkEndian_SwapBE16(head->xMax) / upem;
+
+        metrics->fMaxCharWidth = metrics->fXMax - metrics->fXMin;
+        return;
     }
+
+    metrics->fTop = metrics->fAscent;
+    metrics->fBottom = metrics->fDescent;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "SkColorPriv.h"
 
 static void bilevel_to_bw(const uint8_t* SK_RESTRICT src, const SkGlyph& glyph) {
     const int width = glyph.fWidth;
--- a/gfx/skia/trunk/src/ports/SkTypeface_win_dw.h
+++ b/gfx/skia/trunk/src/ports/SkTypeface_win_dw.h
@@ -12,17 +12,19 @@
 #include "SkDWrite.h"
 #include "SkHRESULT.h"
 #include "SkTScopedComPtr.h"
 #include "SkTypeface.h"
 #include "SkTypefaceCache.h"
 #include "SkTypes.h"
 
 #include <dwrite.h>
-#include <dwrite_1.h>
+#if SK_HAS_DWRITE_1_H
+#  include <dwrite_1.h>
+#endif
 
 class SkFontDescriptor;
 struct SkScalerContextRec;
 
 static SkTypeface::Style get_style(IDWriteFont* font) {
     int style = SkTypeface::kNormal;
     DWRITE_FONT_WEIGHT weight = font->GetWeight();
     if (DWRITE_FONT_WEIGHT_DEMI_BOLD <= weight) {
@@ -47,31 +49,35 @@ private:
         : SkTypeface(style, fontID, false)
         , fFactory(SkRefComPtr(factory))
         , fDWriteFontCollectionLoader(SkSafeRefComPtr(fontCollectionLoader))
         , fDWriteFontFileLoader(SkSafeRefComPtr(fontFileLoader))
         , fDWriteFontFamily(SkRefComPtr(fontFamily))
         , fDWriteFont(SkRefComPtr(font))
         , fDWriteFontFace(SkRefComPtr(fontFace))
     {
+#if SK_HAS_DWRITE_1_H
         if (!SUCCEEDED(fDWriteFontFace->QueryInterface(&fDWriteFontFace1))) {
             // IUnknown::QueryInterface states that if it fails, punk will be set to NULL.
             // http://blogs.msdn.com/b/oldnewthing/archive/2004/03/26/96777.aspx
             SK_ALWAYSBREAK(NULL == fDWriteFontFace1.get());
         }
+#endif
     }
 
 public:
     SkTScopedComPtr<IDWriteFactory> fFactory;
     SkTScopedComPtr<IDWriteFontCollectionLoader> fDWriteFontCollectionLoader;
     SkTScopedComPtr<IDWriteFontFileLoader> fDWriteFontFileLoader;
     SkTScopedComPtr<IDWriteFontFamily> fDWriteFontFamily;
     SkTScopedComPtr<IDWriteFont> fDWriteFont;
     SkTScopedComPtr<IDWriteFontFace> fDWriteFontFace;
+#if SK_HAS_DWRITE_1_H
     SkTScopedComPtr<IDWriteFontFace1> fDWriteFontFace1;
+#endif
 
     static DWriteFontTypeface* Create(IDWriteFactory* factory,
                                       IDWriteFontFace* fontFace,
                                       IDWriteFont* font,
                                       IDWriteFontFamily* fontFamily,
                                       IDWriteFontFileLoader* fontFileLoader = NULL,
                                       IDWriteFontCollectionLoader* fontCollectionLoader = NULL) {
         SkTypeface::Style style = get_style(font);
--- a/gfx/skia/trunk/src/utils/win/SkDWrite.h
+++ b/gfx/skia/trunk/src/utils/win/SkDWrite.h
@@ -6,22 +6,27 @@
  */
 
 #ifndef SkDWrite_DEFINED
 #define SkDWrite_DEFINED
 
 #include "SkTemplates.h"
 
 #include <dwrite.h>
+#include <winsdkver.h>
 
 class SkString;
 
 ////////////////////////////////////////////////////////////////////////////////
 // Factory
 
+#ifndef SK_HAS_DWRITE_1_H
+#define SK_HAS_DWRITE_1_H (WINVER_MAXVER >= 0x0602)
+#endif
+
 IDWriteFactory* sk_get_dwrite_factory();
 
 ////////////////////////////////////////////////////////////////////////////////
 // String conversion
 
 /** Prefer to use this type to prevent template proliferation. */
 typedef SkAutoSTMalloc<16, WCHAR> SkSMallocWCHAR;