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 #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 | 23 |
24 class SkFontDescriptor; | 24 class SkFontDescriptor; |
25 struct SkScalerContextRec; | 25 struct SkScalerContextRec; |
26 | 26 |
27 static SkTypeface::Style get_style(IDWriteFont* font) { | 27 static SkFontStyle get_style(IDWriteFont* font) { |
28 int style = SkTypeface::kNormal; | 28 DWRITE_FONT_STYLE dwStyle = font->GetStyle(); |
29 DWRITE_FONT_WEIGHT weight = font->GetWeight(); | 29 return SkFontStyle(font->GetWeight(), |
30 if (DWRITE_FONT_WEIGHT_DEMI_BOLD <= weight) { | 30 font->GetStretch(), |
31 style |= SkTypeface::kBold; | 31 (DWRITE_FONT_STYLE_OBLIQUE == dwStyle || |
32 } | 32 DWRITE_FONT_STYLE_ITALIC == dwStyle) |
33 DWRITE_FONT_STYLE angle = font->GetStyle(); | 33 ? SkFontStyle::kItalic_Slant |
34 if (DWRITE_FONT_STYLE_OBLIQUE == angle || DWRITE_FONT_STYLE_ITALIC == angle)
{ | 34 : SkFontStyle::kUpright_Slant
); |
35 style |= SkTypeface::kItalic; | |
36 } | |
37 return static_cast<SkTypeface::Style>(style); | |
38 } | 35 } |
39 | 36 |
40 class DWriteFontTypeface : public SkTypeface { | 37 class DWriteFontTypeface : public SkTypeface { |
41 private: | 38 private: |
42 DWriteFontTypeface(SkTypeface::Style style, SkFontID fontID, | 39 DWriteFontTypeface(const SkFontStyle& style, SkFontID fontID, |
43 IDWriteFactory* factory, | 40 IDWriteFactory* factory, |
44 IDWriteFontFace* fontFace, | 41 IDWriteFontFace* fontFace, |
45 IDWriteFont* font, | 42 IDWriteFont* font, |
46 IDWriteFontFamily* fontFamily, | 43 IDWriteFontFamily* fontFamily, |
47 IDWriteFontFileLoader* fontFileLoader = NULL, | 44 IDWriteFontFileLoader* fontFileLoader = NULL, |
48 IDWriteFontCollectionLoader* fontCollectionLoader = NULL) | 45 IDWriteFontCollectionLoader* fontCollectionLoader = NULL) |
49 : SkTypeface(style, fontID, false) | 46 : SkTypeface(style, fontID, false) |
50 , fFactory(SkRefComPtr(factory)) | 47 , fFactory(SkRefComPtr(factory)) |
51 , fDWriteFontCollectionLoader(SkSafeRefComPtr(fontCollectionLoader)) | 48 , fDWriteFontCollectionLoader(SkSafeRefComPtr(fontCollectionLoader)) |
52 , fDWriteFontFileLoader(SkSafeRefComPtr(fontFileLoader)) | 49 , fDWriteFontFileLoader(SkSafeRefComPtr(fontFileLoader)) |
(...skipping 20 matching lines...) Expand all Loading... |
73 #if SK_HAS_DWRITE_1_H | 70 #if SK_HAS_DWRITE_1_H |
74 SkTScopedComPtr<IDWriteFontFace1> fDWriteFontFace1; | 71 SkTScopedComPtr<IDWriteFontFace1> fDWriteFontFace1; |
75 #endif | 72 #endif |
76 | 73 |
77 static DWriteFontTypeface* Create(IDWriteFactory* factory, | 74 static DWriteFontTypeface* Create(IDWriteFactory* factory, |
78 IDWriteFontFace* fontFace, | 75 IDWriteFontFace* fontFace, |
79 IDWriteFont* font, | 76 IDWriteFont* font, |
80 IDWriteFontFamily* fontFamily, | 77 IDWriteFontFamily* fontFamily, |
81 IDWriteFontFileLoader* fontFileLoader = NU
LL, | 78 IDWriteFontFileLoader* fontFileLoader = NU
LL, |
82 IDWriteFontCollectionLoader* fontCollectio
nLoader = NULL) { | 79 IDWriteFontCollectionLoader* fontCollectio
nLoader = NULL) { |
83 SkTypeface::Style style = get_style(font); | |
84 SkFontID fontID = SkTypefaceCache::NewFontID(); | 80 SkFontID fontID = SkTypefaceCache::NewFontID(); |
85 return SkNEW_ARGS(DWriteFontTypeface, (style, fontID, | 81 return SkNEW_ARGS(DWriteFontTypeface, (get_style(font), fontID, |
86 factory, fontFace, font, fontFami
ly, | 82 factory, fontFace, font, fontFami
ly, |
87 fontFileLoader, fontCollectionLoa
der)); | 83 fontFileLoader, fontCollectionLoa
der)); |
88 } | 84 } |
89 | 85 |
90 protected: | 86 protected: |
91 virtual void weak_dispose() const SK_OVERRIDE { | 87 virtual void weak_dispose() const SK_OVERRIDE { |
92 if (fDWriteFontCollectionLoader.get()) { | 88 if (fDWriteFontCollectionLoader.get()) { |
93 HRV(fFactory->UnregisterFontCollectionLoader(fDWriteFontCollectionLo
ader.get())); | 89 HRV(fFactory->UnregisterFontCollectionLoader(fDWriteFontCollectionLo
ader.get())); |
94 } | 90 } |
95 if (fDWriteFontFileLoader.get()) { | 91 if (fDWriteFontFileLoader.get()) { |
(...skipping 19 matching lines...) Expand all Loading... |
115 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_
OVERRIDE; | 111 virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_
OVERRIDE; |
116 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; | 112 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; |
117 virtual size_t onGetTableData(SkFontTableTag, size_t offset, | 113 virtual size_t onGetTableData(SkFontTableTag, size_t offset, |
118 size_t length, void* data) const SK_OVERRIDE; | 114 size_t length, void* data) const SK_OVERRIDE; |
119 | 115 |
120 private: | 116 private: |
121 typedef SkTypeface INHERITED; | 117 typedef SkTypeface INHERITED; |
122 }; | 118 }; |
123 | 119 |
124 #endif | 120 #endif |
OLD | NEW |