diff options
author | 2014-09-10 07:49:05 -0700 | |
---|---|---|
committer | 2014-09-10 07:49:05 -0700 | |
commit | f548444684b9c96f7717aebe645944af4f95d650 (patch) | |
tree | efa5cb607d15bbc202315eeac92fb6dc7bd099c7 /src | |
parent | 841010f4bd54663e41900359fd32640767e6c8cd (diff) |
Detect presence of dwrite_1.h.
This introduces the SK_HAS_DWRITE_1_H define which may be set at
build time or will be true when WINVER_MAXVER >= 0x0602 .
The dwrite_1.h header is available starting in Windows SDK 8.0.
This change supports users who must still use Windows SDK 7.0.
It also allows for easier local testing of the older interfaces
on newer versions of Windows.
See also: https://bugzilla.mozilla.org/show_bug.cgi?id=1053652
R=george@mozilla.com, mtklein@google.com
Author: bungeman@google.com
Review URL: https://codereview.chromium.org/552383002
Diffstat (limited to 'src')
-rw-r--r-- | src/ports/SkScalerContext_win_dw.cpp | 40 | ||||
-rw-r--r-- | src/ports/SkTypeface_win_dw.h | 8 | ||||
-rw-r--r-- | src/utils/win/SkDWrite.h | 5 |
3 files changed, 36 insertions, 17 deletions
diff --git a/src/ports/SkScalerContext_win_dw.cpp b/src/ports/SkScalerContext_win_dw.cpp index e72746a520..7884b13259 100644 --- a/src/ports/SkScalerContext_win_dw.cpp +++ b/src/ports/SkScalerContext_win_dw.cpp @@ -26,7 +26,9 @@ #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 || @@ -524,6 +526,7 @@ void SkScalerContext_DW::generateFontMetrics(SkPaint::FontMetrics* metrics) { metrics->fFlags |= SkPaint::FontMetrics::kUnderlineThinknessIsValid_Flag; metrics->fFlags |= SkPaint::FontMetrics::kUnderlinePositionIsValid_Flag; +#if SK_HAS_DWRITE_1_H if (fTypeface->fDWriteFontFace1.get()) { DWRITE_FONT_METRICS1 dwfm1; fTypeface->fDWriteFontFace1->GetMetrics(&dwfm1); @@ -533,23 +536,28 @@ void SkScalerContext_DW::generateFontMetrics(SkPaint::FontMetrics* metrics) { 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; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/ports/SkTypeface_win_dw.h b/src/ports/SkTypeface_win_dw.h index 465db3446b..650685825d 100644 --- a/src/ports/SkTypeface_win_dw.h +++ b/src/ports/SkTypeface_win_dw.h @@ -17,7 +17,9 @@ #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; @@ -52,11 +54,13 @@ private: , 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: @@ -66,7 +70,9 @@ public: 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, diff --git a/src/utils/win/SkDWrite.h b/src/utils/win/SkDWrite.h index a7799921d2..5b566730e5 100644 --- a/src/utils/win/SkDWrite.h +++ b/src/utils/win/SkDWrite.h @@ -11,12 +11,17 @@ #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(); //////////////////////////////////////////////////////////////////////////////// |