dwrite: Map Mac language id to locale name.

This commit is contained in:
Nikolay Sivov 2014-11-04 16:36:16 +03:00 committed by Alexandre Julliard
parent c8c810c210
commit 3a2de7aef8
1 changed files with 278 additions and 6 deletions

View File

@ -262,6 +262,250 @@ enum TT_NAME_MAC_ENCODING_ID
TT_NAME_MAC_ENCODING_UNINTERPRETED
};
enum TT_NAME_MAC_LANGUAGE_ID
{
TT_NAME_MAC_LANGID_ENGLISH = 0,
TT_NAME_MAC_LANGID_FRENCH,
TT_NAME_MAC_LANGID_GERMAN,
TT_NAME_MAC_LANGID_ITALIAN,
TT_NAME_MAC_LANGID_DUTCH,
TT_NAME_MAC_LANGID_SWEDISH,
TT_NAME_MAC_LANGID_SPANISH,
TT_NAME_MAC_LANGID_DANISH,
TT_NAME_MAC_LANGID_PORTUGUESE,
TT_NAME_MAC_LANGID_NORWEGIAN,
TT_NAME_MAC_LANGID_HEBREW,
TT_NAME_MAC_LANGID_JAPANESE,
TT_NAME_MAC_LANGID_ARABIC,
TT_NAME_MAC_LANGID_FINNISH,
TT_NAME_MAC_LANGID_GREEK,
TT_NAME_MAC_LANGID_ICELANDIC,
TT_NAME_MAC_LANGID_MALTESE,
TT_NAME_MAC_LANGID_TURKISH,
TT_NAME_MAC_LANGID_CROATIAN,
TT_NAME_MAC_LANGID_TRAD_CHINESE,
TT_NAME_MAC_LANGID_URDU,
TT_NAME_MAC_LANGID_HINDI,
TT_NAME_MAC_LANGID_THAI,
TT_NAME_MAC_LANGID_KOREAN,
TT_NAME_MAC_LANGID_LITHUANIAN,
TT_NAME_MAC_LANGID_POLISH,
TT_NAME_MAC_LANGID_HUNGARIAN,
TT_NAME_MAC_LANGID_ESTONIAN,
TT_NAME_MAC_LANGID_LATVIAN,
TT_NAME_MAC_LANGID_SAMI,
TT_NAME_MAC_LANGID_FAROESE,
TT_NAME_MAC_LANGID_FARSI,
TT_NAME_MAC_LANGID_RUSSIAN,
TT_NAME_MAC_LANGID_SIMPL_CHINESE,
TT_NAME_MAC_LANGID_FLEMISH,
TT_NAME_MAC_LANGID_GAELIC,
TT_NAME_MAC_LANGID_ALBANIAN,
TT_NAME_MAC_LANGID_ROMANIAN,
TT_NAME_MAC_LANGID_CZECH,
TT_NAME_MAC_LANGID_SLOVAK,
TT_NAME_MAC_LANGID_SLOVENIAN,
TT_NAME_MAC_LANGID_YIDDISH,
TT_NAME_MAC_LANGID_SERBIAN,
TT_NAME_MAC_LANGID_MACEDONIAN,
TT_NAME_MAC_LANGID_BULGARIAN,
TT_NAME_MAC_LANGID_UKRAINIAN,
TT_NAME_MAC_LANGID_BYELORUSSIAN,
TT_NAME_MAC_LANGID_UZBEK,
TT_NAME_MAC_LANGID_KAZAKH,
TT_NAME_MAC_LANGID_AZERB_CYR,
TT_NAME_MAC_LANGID_AZERB_ARABIC,
TT_NAME_MAC_LANGID_ARMENIAN,
TT_NAME_MAC_LANGID_GEORGIAN,
TT_NAME_MAC_LANGID_MOLDAVIAN,
TT_NAME_MAC_LANGID_KIRGHIZ,
TT_NAME_MAC_LANGID_TAJIKI,
TT_NAME_MAC_LANGID_TURKMEN,
TT_NAME_MAC_LANGID_MONGOLIAN,
TT_NAME_MAC_LANGID_MONGOLIAN_CYR,
TT_NAME_MAC_LANGID_PASHTO,
TT_NAME_MAC_LANGID_KURDISH,
TT_NAME_MAC_LANGID_KASHMIRI,
TT_NAME_MAC_LANGID_SINDHI,
TT_NAME_MAC_LANGID_TIBETAN,
TT_NAME_MAC_LANGID_NEPALI,
TT_NAME_MAC_LANGID_SANSKRIT,
TT_NAME_MAC_LANGID_MARATHI,
TT_NAME_MAC_LANGID_BENGALI,
TT_NAME_MAC_LANGID_ASSAMESE,
TT_NAME_MAC_LANGID_GUJARATI,
TT_NAME_MAC_LANGID_PUNJABI,
TT_NAME_MAC_LANGID_ORIYA,
TT_NAME_MAC_LANGID_MALAYALAM,
TT_NAME_MAC_LANGID_KANNADA,
TT_NAME_MAC_LANGID_TAMIL,
TT_NAME_MAC_LANGID_TELUGU,
TT_NAME_MAC_LANGID_SINHALESE,
TT_NAME_MAC_LANGID_BURMESE,
TT_NAME_MAC_LANGID_KHMER,
TT_NAME_MAC_LANGID_LAO,
TT_NAME_MAC_LANGID_VIETNAMESE,
TT_NAME_MAC_LANGID_INDONESIAN,
TT_NAME_MAC_LANGID_TAGALONG,
TT_NAME_MAC_LANGID_MALAY_ROMAN,
TT_NAME_MAC_LANGID_MALAY_ARABIC,
TT_NAME_MAC_LANGID_AMHARIC,
TT_NAME_MAC_LANGID_TIGRINYA,
TT_NAME_MAC_LANGID_GALLA,
TT_NAME_MAC_LANGID_SOMALI,
TT_NAME_MAC_LANGID_SWAHILI,
TT_NAME_MAC_LANGID_KINYARWANDA,
TT_NAME_MAC_LANGID_RUNDI,
TT_NAME_MAC_LANGID_NYANJA,
TT_NAME_MAC_LANGID_MALAGASY,
TT_NAME_MAC_LANGID_ESPERANTO,
TT_NAME_MAC_LANGID_WELSH,
TT_NAME_MAC_LANGID_BASQUE,
TT_NAME_MAC_LANGID_CATALAN,
TT_NAME_MAC_LANGID_LATIN,
TT_NAME_MAC_LANGID_QUENCHUA,
TT_NAME_MAC_LANGID_GUARANI,
TT_NAME_MAC_LANGID_AYMARA,
TT_NAME_MAC_LANGID_TATAR,
TT_NAME_MAC_LANGID_UIGHUR,
TT_NAME_MAC_LANGID_DZONGKHA,
TT_NAME_MAC_LANGID_JAVANESE,
TT_NAME_MAC_LANGID_SUNDANESE,
TT_NAME_MAC_LANGID_GALICIAN,
TT_NAME_MAC_LANGID_AFRIKAANS,
TT_NAME_MAC_LANGID_BRETON,
TT_NAME_MAC_LANGID_INUKTITUT,
TT_NAME_MAC_LANGID_SCOTTISH_GAELIC,
TT_NAME_MAC_LANGID_MANX_GAELIC,
TT_NAME_MAC_LANGID_IRISH_GAELIC,
TT_NAME_MAC_LANGID_TONGAN,
TT_NAME_MAC_LANGID_GREEK_POLYTONIC,
TT_NAME_MAC_LANGID_GREENLANDIC,
TT_NAME_MAC_LANGID_AZER_ROMAN
};
/* Names are indexed with TT_NAME_MAC_LANGUAGE_ID values */
static const char name_mac_langid_to_locale[][10] = {
"en-US",
"fr-FR",
"de-DE",
"it-IT",
"nl-NL",
"sv-SE",
"es-ES",
"da-DA",
"pt-PT",
"no-NO",
"he-IL",
"ja-JP",
"ar-AR",
"fi-FI",
"el-GR",
"is-IS",
"mt-MT",
"tr-TR",
"hr-HR",
"zh-HK",
"ur-PK",
"hi-IN",
"th-TH",
"ko-KR",
"lt-LT",
"pl-PL",
"hu-HU",
"et-EE",
"lv-LV",
"se-NO",
"fo-FO",
"fa-IR",
"ru-RU",
"zh-CN",
"nl-BE",
"gd-GB",
"sq-AL",
"ro-RO",
"cs-CZ",
"sk-SK",
"sl-SI",
"",
"sr-Latn",
"mk-MK",
"bg-BG",
"uk-UA",
"be-BY",
"uz-Latn",
"kk-KZ",
"az-Cyrl-AZ",
"az-AZ",
"hy-AM",
"ka-GE",
"",
"",
"tg-TJ",
"tk-TM",
"mn-Mong",
"mn-MN",
"ps-AF",
"ku-Arab",
"",
"sd-Arab",
"bo-CN",
"ne-NP",
"sa-IN",
"mr-IN",
"bn-IN",
"as-IN",
"gu-IN",
"pa-Arab",
"or-IN",
"ml-IN",
"kn-IN",
"ta-LK",
"te-IN",
"si-LK",
"",
"km-KH",
"lo-LA",
"vi-VN",
"id-ID",
"",
"ms-MY",
"ms-Arab",
"am-ET",
"ti-ET",
"",
"",
"sw-KE",
"rw-RW",
"",
"",
"",
"",
"cy-GB",
"eu-ES",
"ca-ES",
"",
"",
"",
"",
"tt-RU",
"ug-CN",
"",
"",
"",
"gl-ES",
"af-ZA",
"br-FR",
"iu-Latn-CA",
"gd-GB",
"",
"ga-IE",
"",
"",
"kl-GL",
"az-Latn"
};
enum OPENTYPE_STRING_ID
{
OPENTYPE_STRING_COPYRIGHT_NOTICE = 0,
@ -737,6 +981,39 @@ static UINT get_name_record_codepage(enum OPENTYPE_PLATFORM_ID platform, USHORT
return codepage;
}
static void get_name_record_locale(enum OPENTYPE_PLATFORM_ID platform, USHORT lang_id, WCHAR *locale, USHORT locale_len)
{
static const WCHAR enusW[] = {'e','n','-','U','S',0};
switch (platform) {
case OPENTYPE_PLATFORM_MAC:
{
const char *locale_name = NULL;
if (lang_id > TT_NAME_MAC_LANGID_AZER_ROMAN)
ERR("invalid mac lang id %d\n", lang_id);
else if (!name_mac_langid_to_locale[lang_id][0])
FIXME("failed to map mac lang id %d to locale name\n", lang_id);
else
locale_name = name_mac_langid_to_locale[lang_id];
if (locale_name)
MultiByteToWideChar(CP_ACP, 0, name_mac_langid_to_locale[lang_id], -1, locale, locale_len);
else
strcpyW(locale, enusW);
break;
}
case OPENTYPE_PLATFORM_WIN:
if (!LCIDToLocaleName(MAKELCID(lang_id, SORT_DEFAULT), locale, locale_len, 0)) {
FIXME("failed to get locale name for lcid=0x%08x\n", MAKELCID(lang_id, SORT_DEFAULT));
strcpyW(locale, enusW);
}
break;
default:
FIXME("unknown platform %d\n", platform);
}
}
HRESULT opentype_get_font_strings_from_id(const void *table_data, DWRITE_INFORMATIONAL_STRING_ID id, IDWriteLocalizedStrings **strings)
{
const TT_NAME_V0 *header;
@ -790,6 +1067,7 @@ HRESULT opentype_get_font_strings_from_id(const void *table_data, DWRITE_INFORMA
UINT codepage;
codepage = get_name_record_codepage(platform, encoding);
get_name_record_locale(platform, lang_id, locale, sizeof(locale)/sizeof(WCHAR));
if (codepage) {
DWORD len = MultiByteToWideChar(codepage, 0, (LPSTR)(storage_area + offset), length, NULL, 0);
@ -806,12 +1084,6 @@ HRESULT opentype_get_font_strings_from_id(const void *table_data, DWRITE_INFORMA
name_string[i] = GET_BE_WORD(name_string[i]);
}
if (!LCIDToLocaleName(MAKELCID(lang_id, SORT_DEFAULT), locale, sizeof(locale)/sizeof(WCHAR), 0)) {
static const WCHAR enusW[] = {'e','n','-','u','s',0};
FIXME("failed to get locale name for lcid=0x%08x\n", MAKELCID(lang_id, SORT_DEFAULT));
strcpyW(locale, enusW);
}
TRACE("string %s for locale %s found\n", debugstr_w(name_string), debugstr_w(locale));
add_localizedstring(*strings, locale, name_string);
heap_free(name_string);