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
This commit is contained in:
bungeman 2014-09-10 07:49:05 -07:00 committed by Commit bot
parent 841010f4bd
commit f548444684
4 changed files with 40 additions and 20 deletions

View File

@ -44,10 +44,11 @@
'GR_GL_FUNCTION_TYPE=__stdcall',
],
'msvs_disabled_warnings': [
4345, # This is an FYI about a behavior change from long ago. Chrome stifles it too.
4275, # An exported class was derived from a class that was not exported
4345, # This is an FYI about a behavior change from long ago. Chrome stifles it too.
4355, # 'this' used in base member initializer list. Off by default in newer compilers.
],
'msvs_cygwin_shell': 0,
'msvs_disabled_warnings': [4275],
'msvs_settings': {
'VCCLCompilerTool': {
'WarningLevel': '3',

View File

@ -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;
metrics->fMaxCharWidth = metrics->fXMax - metrics->fXMin;
} else {
metrics->fTop = metrics->fAscent;
metrics->fBottom = metrics->fDescent;
}
return;
}
#else
# pragma message("No dwrite_1.h is available, font metrics may be affected.")
#endif
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;
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -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,

View File

@ -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();
////////////////////////////////////////////////////////////////////////////////