Add option to specify a font collection when creating a
authorkulshin <kulshin@chromium.org>
Wed, 3 Feb 2016 15:22:52 +0000 (07:22 -0800)
committerCommit bot <commit-bot@chromium.org>
Wed, 3 Feb 2016 15:22:52 +0000 (07:22 -0800)
DirectWrite font manager.

The corresponding Chromium change can be found at
https://codereview.chromium.org/1591883002/ .

TBR=reed
This is a trivial and long planned addition to the API.

Review URL: https://codereview.chromium.org/1607083003

include/ports/SkTypeface_win.h
src/ports/SkFontMgr_win_dw.cpp

index b737398..da728ca 100644 (file)
@@ -40,9 +40,11 @@ SK_API void SkTypeface_SetEnsureLOGFONTAccessibleProc(void (*)(const LOGFONT&));
 class SkFontMgr;
 class SkRemotableFontMgr;
 struct IDWriteFactory;
+struct IDWriteFontCollection;
 
 SK_API SkFontMgr* SkFontMgr_New_GDI();
-SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory = NULL);
+SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory = NULL,
+                                            IDWriteFontCollection* collection = NULL);
 
 /**
  *  Creates an SkFontMgr which renders using DirectWrite and obtains its data
index ef09210..11afec3 100644 (file)
@@ -1067,7 +1067,8 @@ SkTypeface* SkFontStyleSet_DirectWrite::matchStyle(const SkFontStyle& pattern) {
 ////////////////////////////////////////////////////////////////////////////////
 #include "SkTypeface_win.h"
 
-SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory) {
+SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory,
+                                            IDWriteFontCollection* collection) {
     if (nullptr == factory) {
         factory = sk_get_dwrite_factory();
         if (nullptr == factory) {
@@ -1075,9 +1076,12 @@ SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory) {
         }
     }
 
-    SkTScopedComPtr<IDWriteFontCollection> sysFontCollection;
-    HRNM(factory->GetSystemFontCollection(&sysFontCollection, FALSE),
-         "Could not get system font collection.");
+    SkTScopedComPtr<IDWriteFontCollection> systemFontCollection;
+    if (nullptr == collection) {
+        HRNM(factory->GetSystemFontCollection(&systemFontCollection, FALSE),
+             "Could not get system font collection.");
+        collection = systemFontCollection.get();
+    }
 
     WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH];
     WCHAR* localeName = nullptr;
@@ -1095,7 +1099,7 @@ SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory) {
         };
     }
 
-    return new SkFontMgr_DirectWrite(factory, sysFontCollection.get(), localeName, localeNameLen);
+    return new SkFontMgr_DirectWrite(factory, collection, localeName, localeNameLen);
 }
 
 #include "SkFontMgr_indirect.h"