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 "SkTScopedComPtr.h" | 14 #include "SkTScopedComPtr.h" |
15 #include "SkTypeface.h" | 15 #include "SkTypeface.h" |
16 #include "SkTypefaceCache.h" | 16 #include "SkTypefaceCache.h" |
17 #include "SkTypes.h" | 17 #include "SkTypes.h" |
18 | 18 |
19 #include <dwrite.h> | 19 #include <dwrite.h> |
| 20 #include <dwrite_1.h> |
20 | 21 |
21 class SkFontDescriptor; | 22 class SkFontDescriptor; |
22 struct SkScalerContextRec; | 23 struct SkScalerContextRec; |
23 | 24 |
24 static SkTypeface::Style get_style(IDWriteFont* font) { | 25 static SkTypeface::Style get_style(IDWriteFont* font) { |
25 int style = SkTypeface::kNormal; | 26 int style = SkTypeface::kNormal; |
26 DWRITE_FONT_WEIGHT weight = font->GetWeight(); | 27 DWRITE_FONT_WEIGHT weight = font->GetWeight(); |
27 if (DWRITE_FONT_WEIGHT_DEMI_BOLD <= weight) { | 28 if (DWRITE_FONT_WEIGHT_DEMI_BOLD <= weight) { |
28 style |= SkTypeface::kBold; | 29 style |= SkTypeface::kBold; |
29 } | 30 } |
(...skipping 13 matching lines...) Expand all Loading... |
43 IDWriteFontFamily* fontFamily, | 44 IDWriteFontFamily* fontFamily, |
44 IDWriteFontFileLoader* fontFileLoader = NULL, | 45 IDWriteFontFileLoader* fontFileLoader = NULL, |
45 IDWriteFontCollectionLoader* fontCollectionLoader = NULL) | 46 IDWriteFontCollectionLoader* fontCollectionLoader = NULL) |
46 : SkTypeface(style, fontID, false) | 47 : SkTypeface(style, fontID, false) |
47 , fFactory(SkRefComPtr(factory)) | 48 , fFactory(SkRefComPtr(factory)) |
48 , fDWriteFontCollectionLoader(SkSafeRefComPtr(fontCollectionLoader)) | 49 , fDWriteFontCollectionLoader(SkSafeRefComPtr(fontCollectionLoader)) |
49 , fDWriteFontFileLoader(SkSafeRefComPtr(fontFileLoader)) | 50 , fDWriteFontFileLoader(SkSafeRefComPtr(fontFileLoader)) |
50 , fDWriteFontFamily(SkRefComPtr(fontFamily)) | 51 , fDWriteFontFamily(SkRefComPtr(fontFamily)) |
51 , fDWriteFont(SkRefComPtr(font)) | 52 , fDWriteFont(SkRefComPtr(font)) |
52 , fDWriteFontFace(SkRefComPtr(fontFace)) | 53 , fDWriteFontFace(SkRefComPtr(fontFace)) |
53 { } | 54 { |
| 55 if (!SUCCEEDED(fDWriteFontFace->QueryInterface(&fDWriteFontFace1))) { |
| 56 // IUnknown::QueryInterface states that if it fails, punk will be se
t to NULL. |
| 57 // http://blogs.msdn.com/b/oldnewthing/archive/2004/03/26/96777.aspx |
| 58 SK_ALWAYSBREAK(NULL == fDWriteFontFace1.get()); |
| 59 } |
| 60 } |
54 | 61 |
55 public: | 62 public: |
56 SkTScopedComPtr<IDWriteFactory> fFactory; | 63 SkTScopedComPtr<IDWriteFactory> fFactory; |
57 SkTScopedComPtr<IDWriteFontCollectionLoader> fDWriteFontCollectionLoader; | 64 SkTScopedComPtr<IDWriteFontCollectionLoader> fDWriteFontCollectionLoader; |
58 SkTScopedComPtr<IDWriteFontFileLoader> fDWriteFontFileLoader; | 65 SkTScopedComPtr<IDWriteFontFileLoader> fDWriteFontFileLoader; |
59 SkTScopedComPtr<IDWriteFontFamily> fDWriteFontFamily; | 66 SkTScopedComPtr<IDWriteFontFamily> fDWriteFontFamily; |
60 SkTScopedComPtr<IDWriteFont> fDWriteFont; | 67 SkTScopedComPtr<IDWriteFont> fDWriteFont; |
61 SkTScopedComPtr<IDWriteFontFace> fDWriteFontFace; | 68 SkTScopedComPtr<IDWriteFontFace> fDWriteFontFace; |
| 69 SkTScopedComPtr<IDWriteFontFace1> fDWriteFontFace1; |
62 | 70 |
63 static DWriteFontTypeface* Create(IDWriteFactory* factory, | 71 static DWriteFontTypeface* Create(IDWriteFactory* factory, |
64 IDWriteFontFace* fontFace, | 72 IDWriteFontFace* fontFace, |
65 IDWriteFont* font, | 73 IDWriteFont* font, |
66 IDWriteFontFamily* fontFamily, | 74 IDWriteFontFamily* fontFamily, |
67 IDWriteFontFileLoader* fontFileLoader = NU
LL, | 75 IDWriteFontFileLoader* fontFileLoader = NU
LL, |
68 IDWriteFontCollectionLoader* fontCollectio
nLoader = NULL) { | 76 IDWriteFontCollectionLoader* fontCollectio
nLoader = NULL) { |
69 SkTypeface::Style style = get_style(font); | 77 SkTypeface::Style style = get_style(font); |
70 SkFontID fontID = SkTypefaceCache::NewFontID(); | 78 SkFontID fontID = SkTypefaceCache::NewFontID(); |
71 return SkNEW_ARGS(DWriteFontTypeface, (style, fontID, | 79 return SkNEW_ARGS(DWriteFontTypeface, (style, fontID, |
(...skipping 28 matching lines...) Expand all Loading... |
100 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_
OVERRIDE; | 108 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_
OVERRIDE; |
101 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; | 109 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; |
102 virtual size_t onGetTableData(SkFontTableTag, size_t offset, | 110 virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
103 size_t length, void* data) const SK_OVERRIDE; | 111 size_t length, void* data) const SK_OVERRIDE; |
104 | 112 |
105 private: | 113 private: |
106 typedef SkTypeface INHERITED; | 114 typedef SkTypeface INHERITED; |
107 }; | 115 }; |
108 | 116 |
109 #endif | 117 #endif |
OLD | NEW |