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

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

Issue 1740533003: Initialize font fallback when creating DWrite font manager (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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
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 WCHAR* localeName, int localeNameLength, IDWriteFontFa llback* fallback)
268 : fFactory(SkRefComPtr(factory)) 268 : fFactory(SkRefComPtr(factory))
269 , fFontCollection(SkRefComPtr(fontCollection)) 269 , fFontCollection(SkRefComPtr(fontCollection))
270 , fLocaleName(localeNameLength) 270 , fLocaleName(localeNameLength)
271 #if SK_HAS_DWRITE_2_H
272 , fFontFallback(SkSafeRefComPtr(fallback))
273 #endif
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 }
278 #endif 281 #endif
279 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); 282 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR));
280 } 283 }
(...skipping 21 matching lines...) Expand all
302 HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const; 305 HRESULT getDefaultFontFamily(IDWriteFontFamily** fontFamily) const;
303 306
304 /** Creates a typeface using a typeface cache. */ 307 /** Creates a typeface using a typeface cache. */
305 SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace, 308 SkTypeface* createTypefaceFromDWriteFont(IDWriteFontFace* fontFace,
306 IDWriteFont* font, 309 IDWriteFont* font,
307 IDWriteFontFamily* fontFamily) cons t; 310 IDWriteFontFamily* fontFamily) cons t;
308 311
309 SkTScopedComPtr<IDWriteFactory> fFactory; 312 SkTScopedComPtr<IDWriteFactory> fFactory;
310 #if SK_HAS_DWRITE_2_H 313 #if SK_HAS_DWRITE_2_H
311 SkTScopedComPtr<IDWriteFactory2> fFactory2; 314 SkTScopedComPtr<IDWriteFactory2> fFactory2;
315 SkTScopedComPtr<IDWriteFontFallback> fFontFallback;
312 #endif 316 #endif
313 SkTScopedComPtr<IDWriteFontCollection> fFontCollection; 317 SkTScopedComPtr<IDWriteFontCollection> fFontCollection;
314 SkSMallocWCHAR fLocaleName; 318 SkSMallocWCHAR fLocaleName;
315 mutable SkMutex fTFCacheMutex; 319 mutable SkMutex fTFCacheMutex;
316 mutable SkTypefaceCache fTFCache; 320 mutable SkTypefaceCache fTFCache;
317 321
318 friend class SkFontStyleSet_DirectWrite; 322 friend class SkFontStyleSet_DirectWrite;
319 friend class FontFallbackRenderer; 323 friend class FontFallbackRenderer;
320 }; 324 };
321 325
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 dwBcp47 = &fLocaleName; 759 dwBcp47 = &fLocaleName;
756 } else { 760 } else {
757 // TODO: support fallback stack. 761 // TODO: support fallback stack.
758 // TODO: DirectWrite supports 'zh-CN' or 'zh-Hans', but 'zh' misses comp letely 762 // TODO: DirectWrite supports 'zh-CN' or 'zh-Hans', but 'zh' misses comp letely
759 // and may produce a Japanese font. 763 // and may produce a Japanese font.
760 HRN(sk_cstring_to_wchar(bcp47[bcp47Count - 1], &dwBcp47Local)); 764 HRN(sk_cstring_to_wchar(bcp47[bcp47Count - 1], &dwBcp47Local));
761 dwBcp47 = &dwBcp47Local; 765 dwBcp47 = &dwBcp47Local;
762 } 766 }
763 767
764 #if SK_HAS_DWRITE_2_H 768 #if SK_HAS_DWRITE_2_H
765 if (fFactory2.get()) { 769 if (fFactory2.get() || fFontFallback.get()) {
bungeman-skia 2016/03/01 16:09:24 As this code stands, this test actually needs to b
Ilya Kulshin 2016/03/07 23:42:04 Acknowledged.
766 SkTScopedComPtr<IDWriteFontFallback> fontFallback; 770 SkTScopedComPtr<IDWriteFontFallback> systemFontFallback;
767 HRNM(fFactory2->GetSystemFontFallback(&fontFallback), "Could not get sys tem fallback."); 771 IDWriteFontFallback* fontFallback = fFontFallback.get();
772 if (!fontFallback) {
773 HRNM(fFactory2->GetSystemFontFallback(&systemFontFallback), "Could not get system fallback.");
774 fontFallback = systemFontFallback.get();
775 }
bungeman-skia 2016/03/01 16:09:24 This code (resolving an IDWriteFontFallback) shoul
Ilya Kulshin 2016/03/07 23:42:04 Moved it to SkfontMgr_New_DirectWrite, since that
768 776
769 SkTScopedComPtr<IDWriteNumberSubstitution> numberSubstitution; 777 SkTScopedComPtr<IDWriteNumberSubstitution> numberSubstitution;
770 HRNM(fFactory2->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METH OD_NONE, nullptr, TRUE, 778 HRNM(fFactory2->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METH OD_NONE, nullptr, TRUE,
771 &numberSubstitution), 779 &numberSubstitution),
772 "Could not create number substitution."); 780 "Could not create number substitution.");
773 SkTScopedComPtr<FontFallbackSource> fontFallbackSource( 781 SkTScopedComPtr<FontFallbackSource> fontFallbackSource(
774 new FontFallbackSource(str, strLen, *dwBcp47, numberSubstitution.get ())); 782 new FontFallbackSource(str, strLen, *dwBcp47, numberSubstitution.get ()));
775 783
776 UINT32 mappedLength; 784 UINT32 mappedLength;
777 SkTScopedComPtr<IDWriteFont> font; 785 SkTScopedComPtr<IDWriteFont> font;
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 HRNM(font->CreateFontFace(&fontFace), "Could not create font face."); 1069 HRNM(font->CreateFontFace(&fontFace), "Could not create font face.");
1062 1070
1063 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(), 1071 return fFontMgr->createTypefaceFromDWriteFont(fontFace.get(), font.get(),
1064 fFontFamily.get()); 1072 fFontFamily.get());
1065 } 1073 }
1066 1074
1067 //////////////////////////////////////////////////////////////////////////////// 1075 ////////////////////////////////////////////////////////////////////////////////
1068 #include "SkTypeface_win.h" 1076 #include "SkTypeface_win.h"
1069 1077
1070 SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory, 1078 SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory,
1071 IDWriteFontCollection* collection) { 1079 IDWriteFontCollection* collection,
1080 IDWriteFontFallback* fallback) {
1072 if (nullptr == factory) { 1081 if (nullptr == factory) {
1073 factory = sk_get_dwrite_factory(); 1082 factory = sk_get_dwrite_factory();
1074 if (nullptr == factory) { 1083 if (nullptr == factory) {
1075 return nullptr; 1084 return nullptr;
1076 } 1085 }
1077 } 1086 }
1078 1087
1079 SkTScopedComPtr<IDWriteFontCollection> systemFontCollection; 1088 SkTScopedComPtr<IDWriteFontCollection> systemFontCollection;
1080 if (nullptr == collection) { 1089 if (nullptr == collection) {
1081 HRNM(factory->GetSystemFontCollection(&systemFontCollection, FALSE), 1090 HRNM(factory->GetSystemFontCollection(&systemFontCollection, FALSE),
(...skipping 10 matching lines...) Expand all
1092 HRESULT hr = SkGetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc ); 1101 HRESULT hr = SkGetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc );
1093 if (nullptr == getUserDefaultLocaleNameProc) { 1102 if (nullptr == getUserDefaultLocaleNameProc) {
1094 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); 1103 SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName.");
1095 } else { 1104 } else {
1096 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH); 1105 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH);
1097 if (localeNameLen) { 1106 if (localeNameLen) {
1098 localeName = localeNameStorage; 1107 localeName = localeNameStorage;
1099 }; 1108 };
1100 } 1109 }
1101 1110
1102 return new SkFontMgr_DirectWrite(factory, collection, localeName, localeName Len); 1111 return new SkFontMgr_DirectWrite(factory, collection, localeName, localeName Len, fallback);
1103 } 1112 }
1104 1113
1105 #include "SkFontMgr_indirect.h" 1114 #include "SkFontMgr_indirect.h"
1106 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) { 1115 SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(SkRemotableFontMgr* proxy) {
1107 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite()); 1116 SkAutoTUnref<SkFontMgr> impl(SkFontMgr_New_DirectWrite());
1108 if (impl.get() == nullptr) { 1117 if (impl.get() == nullptr) {
1109 return nullptr; 1118 return nullptr;
1110 } 1119 }
1111 return new SkFontMgr_Indirect(impl.get(), proxy); 1120 return new SkFontMgr_Indirect(impl.get(), proxy);
1112 } 1121 }
1113 #endif//defined(SK_BUILD_FOR_WIN32) 1122 #endif//defined(SK_BUILD_FOR_WIN32)
OLDNEW
« include/ports/SkTypeface_win.h ('K') | « include/ports/SkTypeface_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698