| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkTypeface_win_dw_DEFINED | 8 #ifndef SkTypeface_win_dw_DEFINED |
| 9 #define SkTypeface_win_dw_DEFINED | 9 #define SkTypeface_win_dw_DEFINED |
| 10 | 10 |
| 11 #include "SkAdvancedTypefaceMetrics.h" | 11 #include "SkAdvancedTypefaceMetrics.h" |
| 12 #include "SkDWrite.h" | 12 #include "SkDWrite.h" |
| 13 #include "SkHRESULT.h" | 13 #include "SkHRESULT.h" |
| 14 #include "SkLeanWindows.h" | 14 #include "SkLeanWindows.h" |
| 15 #include "SkTScopedComPtr.h" | 15 #include "SkTScopedComPtr.h" |
| 16 #include "SkTypeface.h" | 16 #include "SkTypeface.h" |
| 17 #include "SkTypefaceCache.h" | 17 #include "SkTypefaceCache.h" |
| 18 | 18 |
| 19 #include <dwrite.h> | 19 #include <dwrite.h> |
| 20 #if SK_HAS_DWRITE_1_H | 20 #if SK_HAS_DWRITE_1_H |
| 21 # include <dwrite_1.h> | 21 # include <dwrite_1.h> |
| 22 #endif | 22 #endif |
| 23 #if SK_HAS_DWRITE_2_H | |
| 24 # include <dwrite_2.h> | |
| 25 #endif | |
| 26 | 23 |
| 27 class SkFontDescriptor; | 24 class SkFontDescriptor; |
| 28 struct SkScalerContextRec; | 25 struct SkScalerContextRec; |
| 29 | 26 |
| 30 static SkFontStyle get_style(IDWriteFont* font) { | 27 static SkFontStyle get_style(IDWriteFont* font) { |
| 31 int weight = font->GetWeight(); | 28 int weight = font->GetWeight(); |
| 32 int width = font->GetStretch(); | 29 int width = font->GetStretch(); |
| 33 SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant; | 30 SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant; |
| 34 switch (font->GetStyle()) { | 31 switch (font->GetStyle()) { |
| 35 case DWRITE_FONT_STYLE_NORMAL: slant = SkFontStyle::kUpright_Slant; brea
k; | 32 case DWRITE_FONT_STYLE_NORMAL: slant = SkFontStyle::kUpright_Slant; brea
k; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 57 , fDWriteFont(SkRefComPtr(font)) | 54 , fDWriteFont(SkRefComPtr(font)) |
| 58 , fDWriteFontFace(SkRefComPtr(fontFace)) | 55 , fDWriteFontFace(SkRefComPtr(fontFace)) |
| 59 { | 56 { |
| 60 #if SK_HAS_DWRITE_1_H | 57 #if SK_HAS_DWRITE_1_H |
| 61 if (!SUCCEEDED(fDWriteFontFace->QueryInterface(&fDWriteFontFace1))) { | 58 if (!SUCCEEDED(fDWriteFontFace->QueryInterface(&fDWriteFontFace1))) { |
| 62 // IUnknown::QueryInterface states that if it fails, punk will be se
t to nullptr. | 59 // IUnknown::QueryInterface states that if it fails, punk will be se
t to nullptr. |
| 63 // http://blogs.msdn.com/b/oldnewthing/archive/2004/03/26/96777.aspx | 60 // http://blogs.msdn.com/b/oldnewthing/archive/2004/03/26/96777.aspx |
| 64 SkASSERT_RELEASE(nullptr == fDWriteFontFace1.get()); | 61 SkASSERT_RELEASE(nullptr == fDWriteFontFace1.get()); |
| 65 } | 62 } |
| 66 #endif | 63 #endif |
| 67 #if SK_HAS_DWRITE_2_H | |
| 68 if (!SUCCEEDED(fDWriteFontFace->QueryInterface(&fDWriteFontFace2))) { | |
| 69 SkASSERT_RELEASE(nullptr == fDWriteFontFace2.get()); | |
| 70 } | |
| 71 if (!SUCCEEDED(fFactory->QueryInterface(&fFactory2))) { | |
| 72 SkASSERT_RELEASE(nullptr == fFactory2.get()); | |
| 73 } | |
| 74 #endif | |
| 75 } | 64 } |
| 76 | 65 |
| 77 public: | 66 public: |
| 78 SkTScopedComPtr<IDWriteFactory> fFactory; | 67 SkTScopedComPtr<IDWriteFactory> fFactory; |
| 79 #if SK_HAS_DWRITE_2_H | |
| 80 SkTScopedComPtr<IDWriteFactory2> fFactory2; | |
| 81 #else | |
| 82 const decltype(nullptr) fFactory2 = nullptr; | |
| 83 #endif | |
| 84 SkTScopedComPtr<IDWriteFontCollectionLoader> fDWriteFontCollectionLoader; | 68 SkTScopedComPtr<IDWriteFontCollectionLoader> fDWriteFontCollectionLoader; |
| 85 SkTScopedComPtr<IDWriteFontFileLoader> fDWriteFontFileLoader; | 69 SkTScopedComPtr<IDWriteFontFileLoader> fDWriteFontFileLoader; |
| 86 SkTScopedComPtr<IDWriteFontFamily> fDWriteFontFamily; | 70 SkTScopedComPtr<IDWriteFontFamily> fDWriteFontFamily; |
| 87 SkTScopedComPtr<IDWriteFont> fDWriteFont; | 71 SkTScopedComPtr<IDWriteFont> fDWriteFont; |
| 88 SkTScopedComPtr<IDWriteFontFace> fDWriteFontFace; | 72 SkTScopedComPtr<IDWriteFontFace> fDWriteFontFace; |
| 89 #if SK_HAS_DWRITE_1_H | 73 #if SK_HAS_DWRITE_1_H |
| 90 SkTScopedComPtr<IDWriteFontFace1> fDWriteFontFace1; | 74 SkTScopedComPtr<IDWriteFontFace1> fDWriteFontFace1; |
| 91 #endif | 75 #endif |
| 92 #if SK_HAS_DWRITE_2_H | |
| 93 SkTScopedComPtr<IDWriteFontFace2> fDWriteFontFace2; | |
| 94 #else | |
| 95 const decltype(nullptr) fDWriteFontFace2 = nullptr; | |
| 96 #endif | |
| 97 | 76 |
| 98 static DWriteFontTypeface* Create(IDWriteFactory* factory, | 77 static DWriteFontTypeface* Create(IDWriteFactory* factory, |
| 99 IDWriteFontFace* fontFace, | 78 IDWriteFontFace* fontFace, |
| 100 IDWriteFont* font, | 79 IDWriteFont* font, |
| 101 IDWriteFontFamily* fontFamily, | 80 IDWriteFontFamily* fontFamily, |
| 102 IDWriteFontFileLoader* fontFileLoader = nu
llptr, | 81 IDWriteFontFileLoader* fontFileLoader = nu
llptr, |
| 103 IDWriteFontCollectionLoader* fontCollectio
nLoader = nullptr) { | 82 IDWriteFontCollectionLoader* fontCollectio
nLoader = nullptr) { |
| 104 SkFontID fontID = SkTypefaceCache::NewFontID(); | 83 SkFontID fontID = SkTypefaceCache::NewFontID(); |
| 105 return new DWriteFontTypeface(get_style(font), fontID, factory, fontFace
, font, fontFamily, | 84 return new DWriteFontTypeface(get_style(font), fontID, factory, fontFace
, font, fontFamily, |
| 106 fontFileLoader, fontCollectionLoader); | 85 fontFileLoader, fontCollectionLoader); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 134 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; | 113 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override; |
| 135 int onGetTableTags(SkFontTableTag tags[]) const override; | 114 int onGetTableTags(SkFontTableTag tags[]) const override; |
| 136 virtual size_t onGetTableData(SkFontTableTag, size_t offset, | 115 virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
| 137 size_t length, void* data) const override; | 116 size_t length, void* data) const override; |
| 138 | 117 |
| 139 private: | 118 private: |
| 140 typedef SkTypeface INHERITED; | 119 typedef SkTypeface INHERITED; |
| 141 }; | 120 }; |
| 142 | 121 |
| 143 #endif | 122 #endif |
| OLD | NEW |