aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-21 14:53:59 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-21 14:53:59 +0000
commitaf9296e1e96a6ccec9630da769ef5e19456e369a (patch)
tree184c2b26e40eb256cdcf564f74d3b402e860cbc7 /src
parent9e02527eee928253ef1388695be75892804c3cf3 (diff)
Update DirectWrite code so that it is loadable on XP.
This change delay loads GetUserDefaultLocaleName since it is available in Vista+. R=reed@google.com Review URL: https://codereview.chromium.org/23380002 git-svn-id: http://skia.googlecode.com/svn/trunk@10847 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/ports/SkFontHost_win_dw.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/ports/SkFontHost_win_dw.cpp b/src/ports/SkFontHost_win_dw.cpp
index e1685e63b0..fe246dbf72 100644
--- a/src/ports/SkFontHost_win_dw.cpp
+++ b/src/ports/SkFontHost_win_dw.cpp
@@ -97,12 +97,6 @@ private:
SkTDArray<uint8_t> fBits;
};
-typedef HRESULT (WINAPI *DWriteCreateFactoryProc)(
- __in DWRITE_FACTORY_TYPE factoryType,
- __in REFIID iid,
- __out IUnknown **factory
-);
-
static HRESULT get_dwrite_factory(IDWriteFactory** factory) {
static IDWriteFactory* gDWriteFactory = NULL;
@@ -111,6 +105,7 @@ static HRESULT get_dwrite_factory(IDWriteFactory** factory) {
return S_OK;
}
+ typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc;
DWriteCreateFactoryProc dWriteCreateFactoryProc =
reinterpret_cast<DWriteCreateFactoryProc>(
GetProcAddress(LoadLibraryW(L"dwrite.dll"), "DWriteCreateFactory")
@@ -1847,6 +1842,13 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
#endif
+typedef decltype(GetUserDefaultLocaleName)* GetUserDefaultLocaleNameProc;
+static GetUserDefaultLocaleNameProc GetGetUserDefaultLocaleNameProc() {
+ return reinterpret_cast<GetUserDefaultLocaleNameProc>(
+ GetProcAddress(LoadLibraryW(L"Kernel32.dll"), "GetUserDefaultLocaleName")
+ );
+}
+
SkFontMgr* SkFontMgr::Factory() {
IDWriteFactory* factory;
HRNM(get_dwrite_factory(&factory), "Could not get factory.");
@@ -1857,10 +1859,18 @@ SkFontMgr* SkFontMgr::Factory() {
WCHAR localeNameStorage[LOCALE_NAME_MAX_LENGTH];
WCHAR* localeName = NULL;
- int localeNameLen = GetUserDefaultLocaleName(localeNameStorage, LOCALE_NAME_MAX_LENGTH);
- if (localeNameLen) {
- localeName = localeNameStorage;
- };
+ int localeNameLen = 0;
+
+ // Dynamically load GetUserDefaultLocaleName function, as it is not available on XP.
+ GetUserDefaultLocaleNameProc getUserDefaultLocaleNameProc = GetGetUserDefaultLocaleNameProc();
+ if (NULL == getUserDefaultLocaleNameProc) {
+ SkDebugf("Could not get GetUserDefaultLocaleName.");
+ } else {
+ localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_NAME_MAX_LENGTH);
+ if (localeNameLen) {
+ localeName = localeNameStorage;
+ };
+ }
return SkNEW_ARGS(SkFontMgr_DirectWrite, (sysFontCollection.get(), localeName, localeNameLen));
}