Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: src/ports/SkFontMgr_win_dw.cpp

Issue 1878843002: Add option to specify font fallback when creating the skia font manager (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/ports/SkTypeface_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 SkASSERT(fFactory2.get());
bungeman-skia 2016/04/14 21:48:39 nit: Skia uses 4 space indents.
Ilya Kulshin 2016/04/14 22:30:37 Done.
283 }
278 #endif 284 #endif
279 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); 285 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR));
280 } 286 }
281 287
282 protected: 288 protected:
283 int onCountFamilies() const override; 289 int onCountFamilies() const override;
284 void onGetFamilyName(int index, SkString* familyName) const override; 290 void onGetFamilyName(int index, SkString* familyName) const override;
285 SkFontStyleSet* onCreateStyleSet(int index) const override; 291 SkFontStyleSet* onCreateStyleSet(int index) const override;
286 SkFontStyleSet* onMatchFamily(const char familyName[]) const override; 292 SkFontStyleSet* onMatchFamily(const char familyName[]) const override;
287 virtual SkTypeface* onMatchFamilyStyle(const char familyName[], 293 virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
(...skipping 14 matching lines...) Expand all
302 HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const; 308 HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const;
303 309
304 /** Creates a typeface using a typeface cache. */ 310 /** Creates a typeface using a typeface cache. */
305 SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace, 311 SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace,
306 IDWriteFont* font, 312 IDWriteFont* font,
307 IDWriteFontFamily* fontFamily) cons t; 313 IDWriteFontFamily* fontFamily) cons t;
308 314
309 SkTScopedComPtr<IDWriteFactory> fFactory; 315 SkTScopedComPtr<IDWriteFactory> fFactory;
310 #if SK_HAS_DWRITE_2_H 316 #if SK_HAS_DWRITE_2_H
311 SkTScopedComPtr<IDWriteFactory2> fFactory2; 317 SkTScopedComPtr<IDWriteFactory2> fFactory2;
318 SkTScopedComPtr<IDWriteFontFallback> fFontFallback;
312 #endif 319 #endif
313 SkTScopedComPtr<IDWriteFontCollection> fFontCollection; 320 SkTScopedComPtr<IDWriteFontCollection> fFontCollection;
314 SkSMallocWCHAR fLocaleName; 321 SkSMallocWCHAR fLocaleName;
315 mutable SkMutex fTFCacheMutex; 322 mutable SkMutex fTFCacheMutex;
316 mutable SkTypefaceCache fTFCache; 323 mutable SkTypefaceCache fTFCache;
317 324
318 friend class SkFontStyleSet_DirectWrite; 325 friend class SkFontStyleSet_DirectWrite;
319 friend class FontFallbackRenderer; 326 friend class FontFallbackRenderer;
320 }; 327 };
321 328
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 } else { 763 } else {
757 // TODO: support fallback stack. 764 // TODO: support fallback stack.
758 // TODO: DirectWrite supports 'zh-CN' or 'zh-Hans', but 'zh' misses comp letely 765 // TODO: DirectWrite supports 'zh-CN' or 'zh-Hans', but 'zh' misses comp letely
759 // and may produce a Japanese font. 766 // and may produce a Japanese font.
760 HRN(sk_cstring_to_wchar(bcp47[bcp47Count - 1], &dwBcp47Local)); 767 HRN(sk_cstring_to_wchar(bcp47[bcp47Count - 1], &dwBcp47Local));
761 dwBcp47 = &dwBcp47Local; 768 dwBcp47 = &dwBcp47Local;
762 } 769 }
763 770
764 #if SK_HAS_DWRITE_2_H 771 #if SK_HAS_DWRITE_2_H
765 if (fFactory2.get()) { 772 if (fFactory2.get()) {
766 SkTScopedComPtr<IDWriteFontFallback> fontFallback; 773 SkTScopedComPtr<IDWriteFontFallback> systemFontFallback;
767 HRNM(fFactory2->GetSystemFontFallback(&fontFallback), "Could not get sys tem fallback."); 774 IDWriteFontFallback* fontFallback = fFontFallback.get();
775 if (!fontFallback) {
776 HRNM(fFactory2->GetSystemFontFallback(&systemFontFallback),
777 "Could not get system fallback.");
778 fontFallback = systemFontFallback.get();
779 }
bungeman-skia 2016/04/14 21:48:39 Hmmm... I see. The idea is that while making the t
Ilya Kulshin 2016/04/14 22:30:37 Yes, after Chromium starts providing the fallback,
768 780
769 SkTScopedComPtr<IDWriteNumberSubstitution> numberSubstitution; 781 SkTScopedComPtr<IDWriteNumberSubstitution> numberSubstitution;
770 HRNM(fFactory2->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METH OD_NONE, nullptr, TRUE, 782 HRNM(fFactory2->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METH OD_NONE, nullptr, TRUE,
771 &numberSubstitution), 783 &numberSubstitution),
772 "Could not create number substitution."); 784 "Could not create number substitution.");
773 SkTScopedComPtr<FontFallbackSource> fontFallbackSource( 785 SkTScopedComPtr<FontFallbackSource> fontFallbackSource(
774 new FontFallbackSource(str, strLen, *dwBcp47, numberSubstitution.get ())); 786 new FontFallbackSource(str, strLen, *dwBcp47, numberSubstitution.get ()));
775 787
776 UINT32 mappedLength; 788 UINT32 mappedLength;
777 SkTScopedComPtr<IDWriteFont> font; 789 SkTScopedComPtr<IDWriteFont> font;
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 1074
1063 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), 1075 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(),
1064 fFontFamily.get()); 1076 fFontFamily.get());
1065 } 1077 }
1066 1078
1067 //////////////////////////////////////////////////////////////////////////////// 1079 ////////////////////////////////////////////////////////////////////////////////
1068 #include "SkTypeface_win.h" 1080 #include "SkTypeface_win.h"
1069 1081
1070 SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory, 1082 SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory,
1071 IDWriteFontCollection* collection) { 1083 IDWriteFontCollection* collection) {
1084 return SkFontMgr_New_DirectWrite(factory, collection, nullptr);
1085 }
1086
1087 SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory,
1088 IDWriteFontCollection* collection,
1089 IDWriteFontFallback* fallback) {
1072 if (nullptr == factory) { 1090 if (nullptr == factory) {
1073 factory = sk_get_dwrite_factory(); 1091 factory = sk_get_dwrite_factory();
1074 if (nullptr == factory) { 1092 if (nullptr == factory) {
1075 return nullptr; 1093 return nullptr;
1076 } 1094 }
1077 } 1095 }
1078 1096
1079 SkTScopedComPtr<IDWriteFontCollection> systemFontCollection; 1097 SkTScopedComPtr<IDWriteFontCollection> systemFontCollection;
1080 if (nullptr == collection) { 1098 if (nullptr == collection) {
1081 HRNM(factory->GetSystemFontCollection(&systemFontCollection, FALSE), 1099 HRNM(factory->GetSystemFontCollection(&systemFontCollection, FALSE),
(...skipping 10 matching lines...) Expand all
1092 HRESULT hr = SkGetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc ); 1110 HRESULT hr = SkGetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc );
1093 if (nullptr == getUserDefaultLocaleNameProc) { 1111 if (nullptr == getUserDefaultLocaleNameProc) {
1094 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); 1112 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName.");
1095 } else { 1113 } else {
1096 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH); 1114 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH);
1097 if (localeNameLen) { 1115 if (localeNameLen) {
1098 localeName = localeNameStorage; 1116 localeName = localeNameStorage;
1099 }; 1117 };
1100 } 1118 }
1101 1119
1102 return new SkFontMgr_DirectWrite(factory, collection, localeName, localeName Len); 1120 return new SkFontMgr_DirectWrite(factory, collection, fallback, localeName, localeNameLen);
1103 } 1121 }
1104 1122
1105 #include "SkFontMgr_indirect.h" 1123 #include "SkFontMgr_indirect.h"
1106 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { 1124 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) {
1107 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); 1125 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite());
1108 if (impl.get() == nullptr) { 1126 if (impl.get() == nullptr) {
1109 return nullptr; 1127 return nullptr;
1110 } 1128 }
1111 return new SkFontMgr_Indirect(impl.get(), proxy); 1129 return new SkFontMgr_Indirect(impl.get(), proxy);
1112 } 1130 }
1113 #endif//defined(SK_BUILD_FOR_WIN32) 1131 #endif//defined(SK_BUILD_FOR_WIN32)
OLDNEW
« no previous file with comments | « include/ports/SkTypeface_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698