8#if defined(SK_BUILD_FOR_WIN)
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wcast-function-type"
22static IDWriteFactory* gDWriteFactory =
nullptr;
24static void release_dwrite_factory() {
26 gDWriteFactory->Release();
30static void create_dwrite_factory(IDWriteFactory** factory) {
31 using DWriteCreateFactoryProc =
decltype(DWriteCreateFactory)*;
32 DWriteCreateFactoryProc dWriteCreateFactoryProc;
34 dWriteCreateFactoryProc =
reinterpret_cast<DWriteCreateFactoryProc
>(
35 GetProcAddress(LoadLibraryW(
L"DWriteCore.dll"),
"DWriteCoreCreateFactory"));
37 if (!dWriteCreateFactoryProc) {
38 dWriteCreateFactoryProc =
reinterpret_cast<DWriteCreateFactoryProc
>(
39 GetProcAddress(LoadLibraryW(
L"dwrite.dll"),
"DWriteCreateFactory"));
42 if (!dWriteCreateFactoryProc) {
45 hr = ERROR_PROC_NOT_FOUND;
47 HRVM(hr,
"Could not get DWriteCreateFactory proc.");
50 HRVM(dWriteCreateFactoryProc(DWRITE_FACTORY_TYPE_SHARED,
51 __uuidof(IDWriteFactory),
52 reinterpret_cast<IUnknown**
>(factory)),
53 "Could not create DirectWrite factory.");
54 atexit(release_dwrite_factory);
60 once(create_dwrite_factory, &gDWriteFactory);
61 return gDWriteFactory;
69 int wlen = MultiByteToWideChar(CP_UTF8, 0, skname, -1,
nullptr, 0);
72 "Could not get length for wchar to utf-8 conversion.");
75 wlen = MultiByteToWideChar(CP_UTF8, 0, skname, -1,
name->get(), wlen);
77 HRM(HRESULT_FROM_WIN32(
GetLastError()),
"Could not convert wchar to utf-8.");
84 int len = WideCharToMultiByte(CP_UTF8, 0,
name, nameLen,
nullptr, 0,
nullptr,
nullptr);
91 "Could not get length for utf-8 to wchar conversion.");
95 len = WideCharToMultiByte(CP_UTF8, 0,
name, nameLen, skname->
data(),
len,
nullptr,
nullptr);
97 HRM(HRESULT_FROM_WIN32(
GetLastError()),
"Could not convert utf-8 to wchar.");
107 UINT32 nameIndex = 0;
108 if (preferedLocale) {
111 (void)
names->FindLocaleName(preferedLocale, &nameIndex, &nameExists);
118 HRM(
names->GetStringLength(nameIndex, &nameLen),
"Could not get name length.");
121 HRM(
names->GetString(nameIndex,
name.get(), nameLen + 1),
"Could not get string.");
129 GetProcAddress(LoadLibraryW(
L"Kernel32.dll"),
"GetUserDefaultLocaleName")
134 hr = ERROR_PROC_NOT_FOUND;
141#if defined(__clang__)
142 #pragma clang diagnostic pop
HRESULT sk_wchar_to_skstring(WCHAR *name, int nameLen, SkString *skname)
HRESULT sk_get_locale_string(IDWriteLocalizedStrings *names, const WCHAR *preferedLocale, SkString *skname)
int(WINAPI * SkGetUserDefaultLocaleNameProc)(LPWSTR, int)
HRESULT sk_cstring_to_wchar(const char *skname, SkSMallocWCHAR *name)
HRESULT SkGetGetUserDefaultLocaleNameProc(SkGetUserDefaultLocaleNameProc *proc)
IDWriteFactory * sk_get_dwrite_factory()
const char * data() const
static const char *const names[]
DEF_SWITCHES_START aot vmservice shared library name
WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI GetLastError(VOID)