/* * Copyright 2014 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/ #include"include/core/SkTypes.h" #ifdefined(SK_BUILD_FOR_WIN)
/** Converts a utf8 string to a WCHAR string. */
HRESULT sk_cstring_to_wchar(constchar* skname, SkSMallocWCHAR* name) { int wlen = MultiByteToWideChar(CP_UTF8, 0, skname, -1, nullptr, 0); if (0 == wlen) {
HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not get length for wchar to utf-8 conversion.");
}
name->reset(wlen);
wlen = MultiByteToWideChar(CP_UTF8, 0, skname, -1, name->get(), wlen); if (0 == wlen) {
HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert wchar to utf-8.");
} return S_OK;
}
/** Converts a WCHAR string to a utf8 string. */
HRESULT sk_wchar_to_skstring(WCHAR* name, int nameLen, SkString* skname) { int len = WideCharToMultiByte(CP_UTF8, 0, name, nameLen, nullptr, 0, nullptr, nullptr); if (0 == len) { if (nameLen <= 0) {
skname->reset(); return S_OK;
}
HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not get length for utf-8 to wchar conversion.");
}
skname->resize(len);
len = WideCharToMultiByte(CP_UTF8, 0, name, nameLen, skname->data(), len, nullptr, nullptr); if (0 == len) {
HRM(HRESULT_FROM_WIN32(GetLastError()), "Could not convert utf-8 to wchar.");
} return S_OK;
}
HRESULT sk_get_locale_string(IDWriteLocalizedStrings* names, const WCHAR* preferedLocale,
SkString* skname) {
UINT32 nameIndex = 0; if (preferedLocale) { // Ignore any errors and continue with index 0 if there is a problem. BOOL nameExists = FALSE;
(void)names->FindLocaleName(preferedLocale, &nameIndex, &nameExists); if (!nameExists) {
nameIndex = 0;
}
}
UINT32 nameLen;
HRM(names->GetStringLength(nameIndex, &nameLen), "Could not get name length.");
SkSMallocWCHAR name(nameLen + 1);
HRM(names->GetString(nameIndex, name.get(), nameLen + 1), "Could not get string.");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.