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