SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory, IDWriteFontCollection* collection, IDWriteFontFallback* fallback) { if (nullptr == factory) { factory = sk_get_dwrite_factory(); if (nullptr == factory) { return nullptr; } } 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; int localeNameLen = 0; // Dynamically load GetUserDefaultLocaleName function, as it is not available on XP. SkGetUserDefaultLocaleNameProc getUserDefaultLocaleNameProc = nullptr; HRESULT hr = SkGetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc); if (nullptr == getUserDefaultLocaleNameProc) { SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); } else { localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_NAME_MAX_LENGTH); if (localeNameLen) { localeName = localeNameStorage; }; } return new SkFontMgr_DirectWrite(factory, collection, fallback, localeName, localeNameLen); }
SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory) { if (NULL == factory) { factory = sk_get_dwrite_factory(); if (NULL == factory) { return NULL; } } SkTScopedComPtr<IDWriteFontCollection> sysFontCollection; HRNM(SkFontMgr_GetFontCollectionToUse(&sysFontCollection, factory), "Could not get system font collection."); WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH]; WCHAR* localeName = NULL; int localeNameLen = 0; // Dynamically load GetUserDefaultLocaleName function, as it is not available on XP. SkGetUserDefaultLocaleNameProc getUserDefaultLocaleNameProc = NULL; HRESULT hr = SkGetGetUserDefaultLocaleNameProc(&getUserDefaultLocaleNameProc); if (NULL == getUserDefaultLocaleNameProc) { SK_TRACEHR(hr, "Could not get GetUserDefaultLocaleName."); } else { localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_NAME_MAX_LENGTH); if (localeNameLen) { localeName = localeNameStorage; }; } return SkNEW_ARGS(SkFontMgr_DirectWrite, (factory, sysFontCollection.get(), localeName, localeNameLen)); }