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 #include "SkTypes.h" | 8 #include "SkTypes.h" |
9 #if defined(SK_BUILD_FOR_WIN32) | 9 #if defined(SK_BUILD_FOR_WIN32) |
10 | 10 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 *fontFileEnumerator = enumerator.release(); | 257 *fontFileEnumerator = enumerator.release(); |
258 return S_OK; | 258 return S_OK; |
259 } | 259 } |
260 | 260 |
261 //////////////////////////////////////////////////////////////////////////////// | 261 //////////////////////////////////////////////////////////////////////////////// |
262 | 262 |
263 class SkFontMgr_DirectWrite : public SkFontMgr { | 263 class SkFontMgr_DirectWrite : public SkFontMgr { |
264 public: | 264 public: |
265 /** localeNameLength must include the null terminator. */ | 265 /** localeNameLength must include the null terminator. */ |
266 SkFontMgr_DirectWrite(IDWriteFactory* factory, IDWriteFontCollection* fontCo
llection, | 266 SkFontMgr_DirectWrite(IDWriteFactory* factory, IDWriteFontCollection* fontCo
llection, |
267 WCHAR* localeName, int localeNameLength) | 267 IDWriteFontFallback* fallback, WCHAR* localeName, int
localeNameLength) |
268 : fFactory(SkRefComPtr(factory)) | 268 : fFactory(SkRefComPtr(factory)) |
| 269 #if SK_HAS_DWRITE_2_H |
| 270 , fFontFallback(SkSafeRefComPtr(fallback)) |
| 271 #endif |
269 , fFontCollection(SkRefComPtr(fontCollection)) | 272 , fFontCollection(SkRefComPtr(fontCollection)) |
270 , fLocaleName(localeNameLength) | 273 , fLocaleName(localeNameLength) |
271 { | 274 { |
272 #if SK_HAS_DWRITE_2_H | 275 #if SK_HAS_DWRITE_2_H |
273 if (!SUCCEEDED(fFactory->QueryInterface(&fFactory2))) { | 276 if (!SUCCEEDED(fFactory->QueryInterface(&fFactory2))) { |
274 // IUnknown::QueryInterface states that if it fails, punk will be se
t to nullptr. | 277 // IUnknown::QueryInterface states that if it fails, punk will be se
t to nullptr. |
275 // http://blogs.msdn.com/b/oldnewthing/archive/2004/03/26/96777.aspx | 278 // http://blogs.msdn.com/b/oldnewthing/archive/2004/03/26/96777.aspx |
276 SkASSERT_RELEASE(nullptr == fFactory2.get()); | 279 SkASSERT_RELEASE(nullptr == fFactory2.get()); |
277 } | 280 } |
| 281 if (fFontFallback.get()) { |
| 282 // factory must be provied if fallback is non-null, else the fallbac
k will not be used. |
| 283 SkASSERT(fFactory2.get()); |
| 284 } |
278 #endif | 285 #endif |
279 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); | 286 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); |
280 } | 287 } |
281 | 288 |
282 protected: | 289 protected: |
283 int onCountFamilies() const override; | 290 int onCountFamilies() const override; |
284 void onGetFamilyName(int index, SkString* familyName) const override; | 291 void onGetFamilyName(int index, SkString* familyName) const override; |
285 SkFontStyleSet* onCreateStyleSet(int index) const override; | 292 SkFontStyleSet* onCreateStyleSet(int index) const override; |
286 SkFontStyleSet* onMatchFamily(const char familyName[]) const override; | 293 SkFontStyleSet* onMatchFamily(const char familyName[]) const override; |
287 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], | 294 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], |
(...skipping 14 matching lines...) Expand all Loading... |
302 HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const; | 309 HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const; |
303 | 310 |
304 /** Creates a typeface using a typeface cache. */ | 311 /** Creates a typeface using a typeface cache. */ |
305 SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace, | 312 SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace, |
306 IDWriteFont* font, | 313 IDWriteFont* font, |
307 IDWriteFontFamily* fontFamily) cons
t; | 314 IDWriteFontFamily* fontFamily) cons
t; |
308 | 315 |
309 SkTScopedComPtr<IDWriteFactory> fFactory; | 316 SkTScopedComPtr<IDWriteFactory> fFactory; |
310 #if SK_HAS_DWRITE_2_H | 317 #if SK_HAS_DWRITE_2_H |
311 SkTScopedComPtr<IDWriteFactory2> fFactory2; | 318 SkTScopedComPtr<IDWriteFactory2> fFactory2; |
| 319 SkTScopedComPtr<IDWriteFontFallback> fFontFallback; |
312 #endif | 320 #endif |
313 SkTScopedComPtr<IDWriteFontCollection> fFontCollection; | 321 SkTScopedComPtr<IDWriteFontCollection> fFontCollection; |
314 SkSMallocWCHAR fLocaleName; | 322 SkSMallocWCHAR fLocaleName; |
315 mutable SkMutex fTFCacheMutex; | 323 mutable SkMutex fTFCacheMutex; |
316 mutable SkTypefaceCache fTFCache; | 324 mutable SkTypefaceCache fTFCache; |
317 | 325 |
318 friend class SkFontStyleSet_DirectWrite; | 326 friend class SkFontStyleSet_DirectWrite; |
319 friend class FontFallbackRenderer; | 327 friend class FontFallbackRenderer; |
320 }; | 328 }; |
321 | 329 |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 } else { | 764 } else { |
757 // TODO: support fallback stack. | 765 // TODO: support fallback stack. |
758 // TODO: DirectWrite supports 'zh-CN' or 'zh-Hans', but 'zh' misses comp
letely | 766 // TODO: DirectWrite supports 'zh-CN' or 'zh-Hans', but 'zh' misses comp
letely |
759 // and may produce a Japanese font. | 767 // and may produce a Japanese font. |
760 HRN(sk_cstring_to_wchar(bcp47[bcp47Count - 1], &dwBcp47Local)); | 768 HRN(sk_cstring_to_wchar(bcp47[bcp47Count - 1], &dwBcp47Local)); |
761 dwBcp47 = &dwBcp47Local; | 769 dwBcp47 = &dwBcp47Local; |
762 } | 770 } |
763 | 771 |
764 #if SK_HAS_DWRITE_2_H | 772 #if SK_HAS_DWRITE_2_H |
765 if (fFactory2.get()) { | 773 if (fFactory2.get()) { |
766 SkTScopedComPtr<IDWriteFontFallback> fontFallback; | 774 SkTScopedComPtr<IDWriteFontFallback> systemFontFallback; |
767 HRNM(fFactory2->GetSystemFontFallback(&fontFallback), "Could not get sys
tem fallback."); | 775 IDWriteFontFallback* fontFallback = fFontFallback.get(); |
| 776 if (!fontFallback) { |
| 777 HRNM(fFactory2->GetSystemFontFallback(&systemFontFallback), |
| 778 "Could not get system fallback."); |
| 779 fontFallback = systemFontFallback.get(); |
| 780 } |
768 | 781 |
769 SkTScopedComPtr<IDWriteNumberSubstitution> numberSubstitution; | 782 SkTScopedComPtr<IDWriteNumberSubstitution> numberSubstitution; |
770 HRNM(fFactory2->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METH
OD_NONE, nullptr, TRUE, | 783 HRNM(fFactory2->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METH
OD_NONE, nullptr, TRUE, |
771 &numberSubstitution), | 784 &numberSubstitution), |
772 "Could not create number substitution."); | 785 "Could not create number substitution."); |
773 SkTScopedComPtr<FontFallbackSource> fontFallbackSource( | 786 SkTScopedComPtr<FontFallbackSource> fontFallbackSource( |
774 new FontFallbackSource(str, strLen, *dwBcp47, numberSubstitution.get
())); | 787 new FontFallbackSource(str, strLen, *dwBcp47, numberSubstitution.get
())); |
775 | 788 |
776 UINT32 mappedLength; | 789 UINT32 mappedLength; |
777 SkTScopedComPtr<IDWriteFont> font; | 790 SkTScopedComPtr<IDWriteFont> font; |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 | 1075 |
1063 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), | 1076 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), |
1064 fFontFamily.get()); | 1077 fFontFamily.get()); |
1065 } | 1078 } |
1066 | 1079 |
1067 //////////////////////////////////////////////////////////////////////////////// | 1080 //////////////////////////////////////////////////////////////////////////////// |
1068 #include "SkTypeface_win.h" | 1081 #include "SkTypeface_win.h" |
1069 | 1082 |
1070 SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory, | 1083 SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory, |
1071 IDWriteFontCollection* collection) { | 1084 IDWriteFontCollection* collection) { |
| 1085 return SkFontMgr_New_DirectWrite(factory, collection, nullptr); |
| 1086 } |
| 1087 |
| 1088 SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory, |
| 1089 IDWriteFontCollection* collection, |
| 1090 IDWriteFontFallback* fallback) { |
1072 if (nullptr == factory) { | 1091 if (nullptr == factory) { |
1073 factory = sk_get_dwrite_factory(); | 1092 factory = sk_get_dwrite_factory(); |
1074 if (nullptr == factory) { | 1093 if (nullptr == factory) { |
1075 return nullptr; | 1094 return nullptr; |
1076 } | 1095 } |
1077 } | 1096 } |
1078 | 1097 |
1079 SkTScopedComPtr<IDWriteFontCollection> systemFontCollection; | 1098 SkTScopedComPtr<IDWriteFontCollection> systemFontCollection; |
1080 if (nullptr == collection) { | 1099 if (nullptr == collection) { |
1081 HRNM(factory->GetSystemFontCollection(&systemFontCollection, FALSE), | 1100 HRNM(factory->GetSystemFontCollection(&systemFontCollection, FALSE), |
(...skipping 10 matching lines...) Expand all Loading... |
1092 HRESULT hr = SkGetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc
); | 1111 HRESULT hr = SkGetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc
); |
1093 if (nullptr == getUserDefaultLocaleNameProc) { | 1112 if (nullptr == getUserDefaultLocaleNameProc) { |
1094 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); | 1113 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); |
1095 } else { | 1114 } else { |
1096 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N
AME_MAX_LENGTH); | 1115 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N
AME_MAX_LENGTH); |
1097 if (localeNameLen) { | 1116 if (localeNameLen) { |
1098 localeName = localeNameStorage; | 1117 localeName = localeNameStorage; |
1099 }; | 1118 }; |
1100 } | 1119 } |
1101 | 1120 |
1102 return new SkFontMgr_DirectWrite(factory, collection, localeName, localeName
Len); | 1121 return new SkFontMgr_DirectWrite(factory, collection, fallback, localeName,
localeNameLen); |
1103 } | 1122 } |
1104 | 1123 |
1105 #include "SkFontMgr_indirect.h" | 1124 #include "SkFontMgr_indirect.h" |
1106 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { | 1125 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { |
1107 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); | 1126 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); |
1108 if (impl.get() == nullptr) { | 1127 if (impl.get() == nullptr) { |
1109 return nullptr; | 1128 return nullptr; |
1110 } | 1129 } |
1111 return new SkFontMgr_Indirect(impl.get(), proxy); | 1130 return new SkFontMgr_Indirect(impl.get(), proxy); |
1112 } | 1131 } |
1113 #endif//defined(SK_BUILD_FOR_WIN32) | 1132 #endif//defined(SK_BUILD_FOR_WIN32) |
OLD | NEW |