gfx/skia/trunk/src/sfnt/SkOTTable_name.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #include "SkOTTable_name.h"
michael@0 9
michael@0 10 #include "SkEndian.h"
michael@0 11 #include "SkString.h"
michael@0 12 #include "SkTSearch.h"
michael@0 13 #include "SkTemplates.h"
michael@0 14 #include "SkUtils.h"
michael@0 15
michael@0 16 static SkUnichar SkUTF16BE_NextUnichar(const uint16_t** srcPtr) {
michael@0 17 SkASSERT(srcPtr && *srcPtr);
michael@0 18
michael@0 19 const uint16_t* src = *srcPtr;
michael@0 20 SkUnichar c = SkEndian_SwapBE16(*src++);
michael@0 21
michael@0 22 SkASSERT(!SkUTF16_IsLowSurrogate(c));
michael@0 23 if (SkUTF16_IsHighSurrogate(c)) {
michael@0 24 unsigned c2 = SkEndian_SwapBE16(*src++);
michael@0 25 SkASSERT(SkUTF16_IsLowSurrogate(c2));
michael@0 26
michael@0 27 c = (c << 10) + c2 + (0x10000 - (0xD800 << 10) - 0xDC00);
michael@0 28 }
michael@0 29 *srcPtr = src;
michael@0 30 return c;
michael@0 31 }
michael@0 32
michael@0 33 static void SkStringFromUTF16BE(const uint16_t* utf16be, size_t length, SkString& utf8) {
michael@0 34 SkASSERT(utf16be != NULL);
michael@0 35
michael@0 36 utf8.reset();
michael@0 37 size_t numberOf16BitValues = length / 2;
michael@0 38 const uint16_t* end = utf16be + numberOf16BitValues;
michael@0 39 while (utf16be < end) {
michael@0 40 utf8.appendUnichar(SkUTF16BE_NextUnichar(&utf16be));
michael@0 41 }
michael@0 42 }
michael@0 43
michael@0 44 /** UnicodeFromMacRoman[macRomanPoint - 0x80] -> unicodeCodePoint.
michael@0 45 * Derived from http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/ROMAN.TXT .
michael@0 46 * In MacRoman the first 128 code points match ASCII code points.
michael@0 47 * This maps the second 128 MacRoman code points to unicode code points.
michael@0 48 */
michael@0 49 static uint16_t UnicodeFromMacRoman[0x80] = {
michael@0 50 0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1,
michael@0 51 0x00E0, 0x00E2, 0x00E4, 0x00E3, 0x00E5, 0x00E7, 0x00E9, 0x00E8,
michael@0 52 0x00EA, 0x00EB, 0x00ED, 0x00EC, 0x00EE, 0x00EF, 0x00F1, 0x00F3,
michael@0 53 0x00F2, 0x00F4, 0x00F6, 0x00F5, 0x00FA, 0x00F9, 0x00FB, 0x00FC,
michael@0 54 0x2020, 0x00B0, 0x00A2, 0x00A3, 0x00A7, 0x2022, 0x00B6, 0x00DF,
michael@0 55 0x00AE, 0x00A9, 0x2122, 0x00B4, 0x00A8, 0x2260, 0x00C6, 0x00D8,
michael@0 56 0x221E, 0x00B1, 0x2264, 0x2265, 0x00A5, 0x00B5, 0x2202, 0x2211,
michael@0 57 0x220F, 0x03C0, 0x222B, 0x00AA, 0x00BA, 0x03A9, 0x00E6, 0x00F8,
michael@0 58 0x00BF, 0x00A1, 0x00AC, 0x221A, 0x0192, 0x2248, 0x2206, 0x00AB,
michael@0 59 0x00BB, 0x2026, 0x00A0, 0x00C0, 0x00C3, 0x00D5, 0x0152, 0x0153,
michael@0 60 0x2013, 0x2014, 0x201C, 0x201D, 0x2018, 0x2019, 0x00F7, 0x25CA,
michael@0 61 0x00FF, 0x0178, 0x2044, 0x20AC, 0x2039, 0x203A, 0xFB01, 0xFB02,
michael@0 62 0x2021, 0x00B7, 0x201A, 0x201E, 0x2030, 0x00C2, 0x00CA, 0x00C1,
michael@0 63 0x00CB, 0x00C8, 0x00CD, 0x00CE, 0x00CF, 0x00CC, 0x00D3, 0x00D4,
michael@0 64 0xF8FF, 0x00D2, 0x00DA, 0x00DB, 0x00D9, 0x0131, 0x02C6, 0x02DC,
michael@0 65 0x00AF, 0x02D8, 0x02D9, 0x02DA, 0x00B8, 0x02DD, 0x02DB, 0x02C7,
michael@0 66 };
michael@0 67
michael@0 68 static void SkStringFromMacRoman(const uint8_t* macRoman, size_t length, SkString& utf8) {
michael@0 69 utf8.reset();
michael@0 70 for (size_t i = 0; i < length; ++i) {
michael@0 71 utf8.appendUnichar(macRoman[i] < 0x80 ? macRoman[i]
michael@0 72 : UnicodeFromMacRoman[macRoman[i] - 0x80]);
michael@0 73 }
michael@0 74 }
michael@0 75
michael@0 76 static struct BCP47FromLanguageId {
michael@0 77 uint16_t languageID;
michael@0 78 const char* bcp47;
michael@0 79 }
michael@0 80 /** The Mac and Windows values do not conflict, so this is currently one single table. */
michael@0 81 BCP47FromLanguageID[] = {
michael@0 82 /** A mapping from Mac Language Designators to BCP 47 codes.
michael@0 83 * The following list was constructed more or less manually.
michael@0 84 * Apple now uses BCP 47 (post OSX10.4), so there will be no new entries.
michael@0 85 */
michael@0 86 {0, "en"}, //English
michael@0 87 {1, "fr"}, //French
michael@0 88 {2, "de"}, //German
michael@0 89 {3, "it"}, //Italian
michael@0 90 {4, "nl"}, //Dutch
michael@0 91 {5, "sv"}, //Swedish
michael@0 92 {6, "es"}, //Spanish
michael@0 93 {7, "da"}, //Danish
michael@0 94 {8, "pt"}, //Portuguese
michael@0 95 {9, "nb"}, //Norwegian
michael@0 96 {10, "he"}, //Hebrew
michael@0 97 {11, "ja"}, //Japanese
michael@0 98 {12, "ar"}, //Arabic
michael@0 99 {13, "fi"}, //Finnish
michael@0 100 {14, "el"}, //Greek
michael@0 101 {15, "is"}, //Icelandic
michael@0 102 {16, "mt"}, //Maltese
michael@0 103 {17, "tr"}, //Turkish
michael@0 104 {18, "hr"}, //Croatian
michael@0 105 {19, "zh-Hant"}, //Chinese (Traditional)
michael@0 106 {20, "ur"}, //Urdu
michael@0 107 {21, "hi"}, //Hindi
michael@0 108 {22, "th"}, //Thai
michael@0 109 {23, "ko"}, //Korean
michael@0 110 {24, "lt"}, //Lithuanian
michael@0 111 {25, "pl"}, //Polish
michael@0 112 {26, "hu"}, //Hungarian
michael@0 113 {27, "et"}, //Estonian
michael@0 114 {28, "lv"}, //Latvian
michael@0 115 {29, "se"}, //Sami
michael@0 116 {30, "fo"}, //Faroese
michael@0 117 {31, "fa"}, //Farsi (Persian)
michael@0 118 {32, "ru"}, //Russian
michael@0 119 {33, "zh-Hans"}, //Chinese (Simplified)
michael@0 120 {34, "nl"}, //Dutch
michael@0 121 {35, "ga"}, //Irish(Gaelic)
michael@0 122 {36, "sq"}, //Albanian
michael@0 123 {37, "ro"}, //Romanian
michael@0 124 {38, "cs"}, //Czech
michael@0 125 {39, "sk"}, //Slovak
michael@0 126 {40, "sl"}, //Slovenian
michael@0 127 {41, "yi"}, //Yiddish
michael@0 128 {42, "sr"}, //Serbian
michael@0 129 {43, "mk"}, //Macedonian
michael@0 130 {44, "bg"}, //Bulgarian
michael@0 131 {45, "uk"}, //Ukrainian
michael@0 132 {46, "be"}, //Byelorussian
michael@0 133 {47, "uz"}, //Uzbek
michael@0 134 {48, "kk"}, //Kazakh
michael@0 135 {49, "az-Cyrl"}, //Azerbaijani (Cyrillic)
michael@0 136 {50, "az-Arab"}, //Azerbaijani (Arabic)
michael@0 137 {51, "hy"}, //Armenian
michael@0 138 {52, "ka"}, //Georgian
michael@0 139 {53, "mo"}, //Moldavian
michael@0 140 {54, "ky"}, //Kirghiz
michael@0 141 {55, "tg"}, //Tajiki
michael@0 142 {56, "tk"}, //Turkmen
michael@0 143 {57, "mn-Mong"}, //Mongolian (Traditional)
michael@0 144 {58, "mn-Cyrl"}, //Mongolian (Cyrillic)
michael@0 145 {59, "ps"}, //Pashto
michael@0 146 {60, "ku"}, //Kurdish
michael@0 147 {61, "ks"}, //Kashmiri
michael@0 148 {62, "sd"}, //Sindhi
michael@0 149 {63, "bo"}, //Tibetan
michael@0 150 {64, "ne"}, //Nepali
michael@0 151 {65, "sa"}, //Sanskrit
michael@0 152 {66, "mr"}, //Marathi
michael@0 153 {67, "bn"}, //Bengali
michael@0 154 {68, "as"}, //Assamese
michael@0 155 {69, "gu"}, //Gujarati
michael@0 156 {70, "pa"}, //Punjabi
michael@0 157 {71, "or"}, //Oriya
michael@0 158 {72, "ml"}, //Malayalam
michael@0 159 {73, "kn"}, //Kannada
michael@0 160 {74, "ta"}, //Tamil
michael@0 161 {75, "te"}, //Telugu
michael@0 162 {76, "si"}, //Sinhalese
michael@0 163 {77, "my"}, //Burmese
michael@0 164 {78, "km"}, //Khmer
michael@0 165 {79, "lo"}, //Lao
michael@0 166 {80, "vi"}, //Vietnamese
michael@0 167 {81, "id"}, //Indonesian
michael@0 168 {82, "tl"}, //Tagalog
michael@0 169 {83, "ms-Latn"}, //Malay (Roman)
michael@0 170 {84, "ms-Arab"}, //Malay (Arabic)
michael@0 171 {85, "am"}, //Amharic
michael@0 172 {86, "ti"}, //Tigrinya
michael@0 173 {87, "om"}, //Oromo
michael@0 174 {88, "so"}, //Somali
michael@0 175 {89, "sw"}, //Swahili
michael@0 176 {90, "rw"}, //Kinyarwanda/Ruanda
michael@0 177 {91, "rn"}, //Rundi
michael@0 178 {92, "ny"}, //Nyanja/Chewa
michael@0 179 {93, "mg"}, //Malagasy
michael@0 180 {94, "eo"}, //Esperanto
michael@0 181 {128, "cy"}, //Welsh
michael@0 182 {129, "eu"}, //Basque
michael@0 183 {130, "ca"}, //Catalan
michael@0 184 {131, "la"}, //Latin
michael@0 185 {132, "qu"}, //Quechua
michael@0 186 {133, "gn"}, //Guarani
michael@0 187 {134, "ay"}, //Aymara
michael@0 188 {135, "tt"}, //Tatar
michael@0 189 {136, "ug"}, //Uighur
michael@0 190 {137, "dz"}, //Dzongkha
michael@0 191 {138, "jv-Latn"}, //Javanese (Roman)
michael@0 192 {139, "su-Latn"}, //Sundanese (Roman)
michael@0 193 {140, "gl"}, //Galician
michael@0 194 {141, "af"}, //Afrikaans
michael@0 195 {142, "br"}, //Breton
michael@0 196 {143, "iu"}, //Inuktitut
michael@0 197 {144, "gd"}, //Scottish (Gaelic)
michael@0 198 {145, "gv"}, //Manx (Gaelic)
michael@0 199 {146, "ga"}, //Irish (Gaelic with Lenition)
michael@0 200 {147, "to"}, //Tongan
michael@0 201 {148, "el"}, //Greek (Polytonic) Note: ISO 15924 does not have an equivalent script name.
michael@0 202 {149, "kl"}, //Greenlandic
michael@0 203 {150, "az-Latn"}, //Azerbaijani (Roman)
michael@0 204 {151, "nn"}, //Nynorsk
michael@0 205
michael@0 206 /** A mapping from Windows LCID to BCP 47 codes.
michael@0 207 * This list is the sorted, curated output of tools/win_lcid.cpp.
michael@0 208 * Note that these are sorted by value for quick binary lookup, and not logically by lsb.
michael@0 209 * The 'bare' language ids (e.g. 0x0001 for Arabic) are ommitted
michael@0 210 * as they do not appear as valid language ids in the OpenType specification.
michael@0 211 */
michael@0 212 { 0x0401, "ar-SA" }, //Arabic
michael@0 213 { 0x0402, "bg-BG" }, //Bulgarian
michael@0 214 { 0x0403, "ca-ES" }, //Catalan
michael@0 215 { 0x0404, "zh-TW" }, //Chinese (Traditional)
michael@0 216 { 0x0405, "cs-CZ" }, //Czech
michael@0 217 { 0x0406, "da-DK" }, //Danish
michael@0 218 { 0x0407, "de-DE" }, //German
michael@0 219 { 0x0408, "el-GR" }, //Greek
michael@0 220 { 0x0409, "en-US" }, //English
michael@0 221 { 0x040a, "es-ES_tradnl" }, //Spanish
michael@0 222 { 0x040b, "fi-FI" }, //Finnish
michael@0 223 { 0x040c, "fr-FR" }, //French
michael@0 224 { 0x040d, "he-IL" }, //Hebrew
michael@0 225 { 0x040d, "he" }, //Hebrew
michael@0 226 { 0x040e, "hu-HU" }, //Hungarian
michael@0 227 { 0x040e, "hu" }, //Hungarian
michael@0 228 { 0x040f, "is-IS" }, //Icelandic
michael@0 229 { 0x0410, "it-IT" }, //Italian
michael@0 230 { 0x0411, "ja-JP" }, //Japanese
michael@0 231 { 0x0412, "ko-KR" }, //Korean
michael@0 232 { 0x0413, "nl-NL" }, //Dutch
michael@0 233 { 0x0414, "nb-NO" }, //Norwegian (Bokmål)
michael@0 234 { 0x0415, "pl-PL" }, //Polish
michael@0 235 { 0x0416, "pt-BR" }, //Portuguese
michael@0 236 { 0x0417, "rm-CH" }, //Romansh
michael@0 237 { 0x0418, "ro-RO" }, //Romanian
michael@0 238 { 0x0419, "ru-RU" }, //Russian
michael@0 239 { 0x041a, "hr-HR" }, //Croatian
michael@0 240 { 0x041b, "sk-SK" }, //Slovak
michael@0 241 { 0x041c, "sq-AL" }, //Albanian
michael@0 242 { 0x041d, "sv-SE" }, //Swedish
michael@0 243 { 0x041e, "th-TH" }, //Thai
michael@0 244 { 0x041f, "tr-TR" }, //Turkish
michael@0 245 { 0x0420, "ur-PK" }, //Urdu
michael@0 246 { 0x0421, "id-ID" }, //Indonesian
michael@0 247 { 0x0422, "uk-UA" }, //Ukrainian
michael@0 248 { 0x0423, "be-BY" }, //Belarusian
michael@0 249 { 0x0424, "sl-SI" }, //Slovenian
michael@0 250 { 0x0425, "et-EE" }, //Estonian
michael@0 251 { 0x0426, "lv-LV" }, //Latvian
michael@0 252 { 0x0427, "lt-LT" }, //Lithuanian
michael@0 253 { 0x0428, "tg-Cyrl-TJ" }, //Tajik (Cyrillic)
michael@0 254 { 0x0429, "fa-IR" }, //Persian
michael@0 255 { 0x042a, "vi-VN" }, //Vietnamese
michael@0 256 { 0x042b, "hy-AM" }, //Armenian
michael@0 257 { 0x042c, "az-Latn-AZ" }, //Azeri (Latin)
michael@0 258 { 0x042d, "eu-ES" }, //Basque
michael@0 259 { 0x042e, "hsb-DE" }, //Upper Sorbian
michael@0 260 { 0x042f, "mk-MK" }, //Macedonian (FYROM)
michael@0 261 { 0x0432, "tn-ZA" }, //Setswana
michael@0 262 { 0x0434, "xh-ZA" }, //isiXhosa
michael@0 263 { 0x0435, "zu-ZA" }, //isiZulu
michael@0 264 { 0x0436, "af-ZA" }, //Afrikaans
michael@0 265 { 0x0437, "ka-GE" }, //Georgian
michael@0 266 { 0x0438, "fo-FO" }, //Faroese
michael@0 267 { 0x0439, "hi-IN" }, //Hindi
michael@0 268 { 0x043a, "mt-MT" }, //Maltese
michael@0 269 { 0x043b, "se-NO" }, //Sami (Northern)
michael@0 270 { 0x043e, "ms-MY" }, //Malay
michael@0 271 { 0x043f, "kk-KZ" }, //Kazakh
michael@0 272 { 0x0440, "ky-KG" }, //Kyrgyz
michael@0 273 { 0x0441, "sw-KE" }, //Kiswahili
michael@0 274 { 0x0442, "tk-TM" }, //Turkmen
michael@0 275 { 0x0443, "uz-Latn-UZ" }, //Uzbek (Latin)
michael@0 276 { 0x0443, "uz" }, //Uzbek
michael@0 277 { 0x0444, "tt-RU" }, //Tatar
michael@0 278 { 0x0445, "bn-IN" }, //Bengali
michael@0 279 { 0x0446, "pa-IN" }, //Punjabi
michael@0 280 { 0x0447, "gu-IN" }, //Gujarati
michael@0 281 { 0x0448, "or-IN" }, //Oriya
michael@0 282 { 0x0449, "ta-IN" }, //Tamil
michael@0 283 { 0x044a, "te-IN" }, //Telugu
michael@0 284 { 0x044b, "kn-IN" }, //Kannada
michael@0 285 { 0x044c, "ml-IN" }, //Malayalam
michael@0 286 { 0x044d, "as-IN" }, //Assamese
michael@0 287 { 0x044e, "mr-IN" }, //Marathi
michael@0 288 { 0x044f, "sa-IN" }, //Sanskrit
michael@0 289 { 0x0450, "mn-Cyrl" }, //Mongolian (Cyrillic)
michael@0 290 { 0x0451, "bo-CN" }, //Tibetan
michael@0 291 { 0x0452, "cy-GB" }, //Welsh
michael@0 292 { 0x0453, "km-KH" }, //Khmer
michael@0 293 { 0x0454, "lo-LA" }, //Lao
michael@0 294 { 0x0456, "gl-ES" }, //Galician
michael@0 295 { 0x0457, "kok-IN" }, //Konkani
michael@0 296 { 0x045a, "syr-SY" }, //Syriac
michael@0 297 { 0x045b, "si-LK" }, //Sinhala
michael@0 298 { 0x045d, "iu-Cans-CA" }, //Inuktitut (Syllabics)
michael@0 299 { 0x045e, "am-ET" }, //Amharic
michael@0 300 { 0x0461, "ne-NP" }, //Nepali
michael@0 301 { 0x0462, "fy-NL" }, //Frisian
michael@0 302 { 0x0463, "ps-AF" }, //Pashto
michael@0 303 { 0x0464, "fil-PH" }, //Filipino
michael@0 304 { 0x0465, "dv-MV" }, //Divehi
michael@0 305 { 0x0468, "ha-Latn-NG" }, //Hausa (Latin)
michael@0 306 { 0x046a, "yo-NG" }, //Yoruba
michael@0 307 { 0x046b, "quz-BO" }, //Quechua
michael@0 308 { 0x046c, "nso-ZA" }, //Sesotho sa Leboa
michael@0 309 { 0x046d, "ba-RU" }, //Bashkir
michael@0 310 { 0x046e, "lb-LU" }, //Luxembourgish
michael@0 311 { 0x046f, "kl-GL" }, //Greenlandic
michael@0 312 { 0x0470, "ig-NG" }, //Igbo
michael@0 313 { 0x0478, "ii-CN" }, //Yi
michael@0 314 { 0x047a, "arn-CL" }, //Mapudungun
michael@0 315 { 0x047c, "moh-CA" }, //Mohawk
michael@0 316 { 0x047e, "br-FR" }, //Breton
michael@0 317 { 0x0480, "ug-CN" }, //Uyghur
michael@0 318 { 0x0481, "mi-NZ" }, //Maori
michael@0 319 { 0x0482, "oc-FR" }, //Occitan
michael@0 320 { 0x0483, "co-FR" }, //Corsican
michael@0 321 { 0x0484, "gsw-FR" }, //Alsatian
michael@0 322 { 0x0485, "sah-RU" }, //Yakut
michael@0 323 { 0x0486, "qut-GT" }, //K'iche
michael@0 324 { 0x0487, "rw-RW" }, //Kinyarwanda
michael@0 325 { 0x0488, "wo-SN" }, //Wolof
michael@0 326 { 0x048c, "prs-AF" }, //Dari
michael@0 327 { 0x0491, "gd-GB" }, //Scottish Gaelic
michael@0 328 { 0x0801, "ar-IQ" }, //Arabic
michael@0 329 { 0x0804, "zh-Hans" }, //Chinese (Simplified)
michael@0 330 { 0x0807, "de-CH" }, //German
michael@0 331 { 0x0809, "en-GB" }, //English
michael@0 332 { 0x080a, "es-MX" }, //Spanish
michael@0 333 { 0x080c, "fr-BE" }, //French
michael@0 334 { 0x0810, "it-CH" }, //Italian
michael@0 335 { 0x0813, "nl-BE" }, //Dutch
michael@0 336 { 0x0814, "nn-NO" }, //Norwegian (Nynorsk)
michael@0 337 { 0x0816, "pt-PT" }, //Portuguese
michael@0 338 { 0x081a, "sr-Latn-CS" }, //Serbian (Latin)
michael@0 339 { 0x081d, "sv-FI" }, //Swedish
michael@0 340 { 0x082c, "az-Cyrl-AZ" }, //Azeri (Cyrillic)
michael@0 341 { 0x082e, "dsb-DE" }, //Lower Sorbian
michael@0 342 { 0x082e, "dsb" }, //Lower Sorbian
michael@0 343 { 0x083b, "se-SE" }, //Sami (Northern)
michael@0 344 { 0x083c, "ga-IE" }, //Irish
michael@0 345 { 0x083e, "ms-BN" }, //Malay
michael@0 346 { 0x0843, "uz-Cyrl-UZ" }, //Uzbek (Cyrillic)
michael@0 347 { 0x0845, "bn-BD" }, //Bengali
michael@0 348 { 0x0850, "mn-Mong-CN" }, //Mongolian (Traditional Mongolian)
michael@0 349 { 0x085d, "iu-Latn-CA" }, //Inuktitut (Latin)
michael@0 350 { 0x085f, "tzm-Latn-DZ" }, //Tamazight (Latin)
michael@0 351 { 0x086b, "quz-EC" }, //Quechua
michael@0 352 { 0x0c01, "ar-EG" }, //Arabic
michael@0 353 { 0x0c04, "zh-Hant" }, //Chinese (Traditional)
michael@0 354 { 0x0c07, "de-AT" }, //German
michael@0 355 { 0x0c09, "en-AU" }, //English
michael@0 356 { 0x0c0a, "es-ES" }, //Spanish
michael@0 357 { 0x0c0c, "fr-CA" }, //French
michael@0 358 { 0x0c1a, "sr-Cyrl-CS" }, //Serbian (Cyrillic)
michael@0 359 { 0x0c3b, "se-FI" }, //Sami (Northern)
michael@0 360 { 0x0c6b, "quz-PE" }, //Quechua
michael@0 361 { 0x1001, "ar-LY" }, //Arabic
michael@0 362 { 0x1004, "zh-SG" }, //Chinese (Simplified)
michael@0 363 { 0x1007, "de-LU" }, //German
michael@0 364 { 0x1009, "en-CA" }, //English
michael@0 365 { 0x100a, "es-GT" }, //Spanish
michael@0 366 { 0x100c, "fr-CH" }, //French
michael@0 367 { 0x101a, "hr-BA" }, //Croatian (Latin)
michael@0 368 { 0x103b, "smj-NO" }, //Sami (Lule)
michael@0 369 { 0x1401, "ar-DZ" }, //Arabic
michael@0 370 { 0x1404, "zh-MO" }, //Chinese (Traditional)
michael@0 371 { 0x1407, "de-LI" }, //German
michael@0 372 { 0x1409, "en-NZ" }, //English
michael@0 373 { 0x140a, "es-CR" }, //Spanish
michael@0 374 { 0x140c, "fr-LU" }, //French
michael@0 375 { 0x141a, "bs-Latn-BA" }, //Bosnian (Latin)
michael@0 376 { 0x141a, "bs" }, //Bosnian
michael@0 377 { 0x143b, "smj-SE" }, //Sami (Lule)
michael@0 378 { 0x143b, "smj" }, //Sami (Lule)
michael@0 379 { 0x1801, "ar-MA" }, //Arabic
michael@0 380 { 0x1809, "en-IE" }, //English
michael@0 381 { 0x180a, "es-PA" }, //Spanish
michael@0 382 { 0x180c, "fr-MC" }, //French
michael@0 383 { 0x181a, "sr-Latn-BA" }, //Serbian (Latin)
michael@0 384 { 0x183b, "sma-NO" }, //Sami (Southern)
michael@0 385 { 0x1c01, "ar-TN" }, //Arabic
michael@0 386 { 0x1c09, "en-ZA" }, //English
michael@0 387 { 0x1c0a, "es-DO" }, //Spanish
michael@0 388 { 0x1c1a, "sr-Cyrl-BA" }, //Serbian (Cyrillic)
michael@0 389 { 0x1c3b, "sma-SE" }, //Sami (Southern)
michael@0 390 { 0x1c3b, "sma" }, //Sami (Southern)
michael@0 391 { 0x2001, "ar-OM" }, //Arabic
michael@0 392 { 0x2009, "en-JM" }, //English
michael@0 393 { 0x200a, "es-VE" }, //Spanish
michael@0 394 { 0x201a, "bs-Cyrl-BA" }, //Bosnian (Cyrillic)
michael@0 395 { 0x201a, "bs-Cyrl" }, //Bosnian (Cyrillic)
michael@0 396 { 0x203b, "sms-FI" }, //Sami (Skolt)
michael@0 397 { 0x203b, "sms" }, //Sami (Skolt)
michael@0 398 { 0x2401, "ar-YE" }, //Arabic
michael@0 399 { 0x2409, "en-029" }, //English
michael@0 400 { 0x240a, "es-CO" }, //Spanish
michael@0 401 { 0x241a, "sr-Latn-RS" }, //Serbian (Latin)
michael@0 402 { 0x243b, "smn-FI" }, //Sami (Inari)
michael@0 403 { 0x2801, "ar-SY" }, //Arabic
michael@0 404 { 0x2809, "en-BZ" }, //English
michael@0 405 { 0x280a, "es-PE" }, //Spanish
michael@0 406 { 0x281a, "sr-Cyrl-RS" }, //Serbian (Cyrillic)
michael@0 407 { 0x2c01, "ar-JO" }, //Arabic
michael@0 408 { 0x2c09, "en-TT" }, //English
michael@0 409 { 0x2c0a, "es-AR" }, //Spanish
michael@0 410 { 0x2c1a, "sr-Latn-ME" }, //Serbian (Latin)
michael@0 411 { 0x3001, "ar-LB" }, //Arabic
michael@0 412 { 0x3009, "en-ZW" }, //English
michael@0 413 { 0x300a, "es-EC" }, //Spanish
michael@0 414 { 0x301a, "sr-Cyrl-ME" }, //Serbian (Cyrillic)
michael@0 415 { 0x3401, "ar-KW" }, //Arabic
michael@0 416 { 0x3409, "en-PH" }, //English
michael@0 417 { 0x340a, "es-CL" }, //Spanish
michael@0 418 { 0x3801, "ar-AE" }, //Arabic
michael@0 419 { 0x380a, "es-UY" }, //Spanish
michael@0 420 { 0x3c01, "ar-BH" }, //Arabic
michael@0 421 { 0x3c0a, "es-PY" }, //Spanish
michael@0 422 { 0x4001, "ar-QA" }, //Arabic
michael@0 423 { 0x4009, "en-IN" }, //English
michael@0 424 { 0x400a, "es-BO" }, //Spanish
michael@0 425 { 0x4409, "en-MY" }, //English
michael@0 426 { 0x440a, "es-SV" }, //Spanish
michael@0 427 { 0x4809, "en-SG" }, //English
michael@0 428 { 0x480a, "es-HN" }, //Spanish
michael@0 429 { 0x4c0a, "es-NI" }, //Spanish
michael@0 430 { 0x500a, "es-PR" }, //Spanish
michael@0 431 { 0x540a, "es-US" }, //Spanish
michael@0 432 };
michael@0 433
michael@0 434 namespace {
michael@0 435 bool BCP47FromLanguageIdLess(const BCP47FromLanguageId& a, const BCP47FromLanguageId& b) {
michael@0 436 return a.languageID < b.languageID;
michael@0 437 }
michael@0 438 }
michael@0 439
michael@0 440 bool SkOTTableName::Iterator::next(SkOTTableName::Iterator::Record& record) {
michael@0 441 const size_t nameRecordsCount = SkEndian_SwapBE16(fName.count);
michael@0 442 const SkOTTableName::Record* nameRecords = SkTAfter<const SkOTTableName::Record>(&fName);
michael@0 443 const SkOTTableName::Record* nameRecord;
michael@0 444
michael@0 445 // Find the next record which matches the requested type.
michael@0 446 do {
michael@0 447 if (fIndex >= nameRecordsCount) {
michael@0 448 return false;
michael@0 449 }
michael@0 450
michael@0 451 nameRecord = &nameRecords[fIndex];
michael@0 452 ++fIndex;
michael@0 453 } while (fType != -1 && nameRecord->nameID.fontSpecific != fType);
michael@0 454
michael@0 455 record.type = nameRecord->nameID.fontSpecific;
michael@0 456
michael@0 457 const uint16_t stringTableOffset = SkEndian_SwapBE16(fName.stringOffset);
michael@0 458 const char* stringTable = SkTAddOffset<const char>(&fName, stringTableOffset);
michael@0 459
michael@0 460 // Decode the name into UTF-8.
michael@0 461 const uint16_t nameOffset = SkEndian_SwapBE16(nameRecord->offset);
michael@0 462 const uint16_t nameLength = SkEndian_SwapBE16(nameRecord->length);
michael@0 463 const char* nameString = SkTAddOffset<const char>(stringTable, nameOffset);
michael@0 464 switch (nameRecord->platformID.value) {
michael@0 465 case SkOTTableName::Record::PlatformID::Windows:
michael@0 466 if (SkOTTableName::Record::EncodingID::Windows::UnicodeBMPUCS2
michael@0 467 != nameRecord->encodingID.windows.value
michael@0 468 && SkOTTableName::Record::EncodingID::Windows::UnicodeUCS4
michael@0 469 != nameRecord->encodingID.windows.value
michael@0 470 && SkOTTableName::Record::EncodingID::Windows::Symbol
michael@0 471 != nameRecord->encodingID.windows.value)
michael@0 472 {
michael@0 473 record.name.reset();
michael@0 474 break;
michael@0 475 }
michael@0 476 case SkOTTableName::Record::PlatformID::Unicode:
michael@0 477 case SkOTTableName::Record::PlatformID::ISO:
michael@0 478 SkStringFromUTF16BE((const uint16_t*)nameString, nameLength, record.name);
michael@0 479 break;
michael@0 480
michael@0 481 case SkOTTableName::Record::PlatformID::Macintosh:
michael@0 482 // TODO: need better decoding, especially on Mac.
michael@0 483 if (SkOTTableName::Record::EncodingID::Macintosh::Roman
michael@0 484 != nameRecord->encodingID.macintosh.value)
michael@0 485 {
michael@0 486 record.name.reset();
michael@0 487 break;
michael@0 488 }
michael@0 489 SkStringFromMacRoman((const uint8_t*)nameString, nameLength, record.name);
michael@0 490 break;
michael@0 491
michael@0 492 case SkOTTableName::Record::PlatformID::Custom:
michael@0 493 // These should never appear in a 'name' table.
michael@0 494 default:
michael@0 495 SkASSERT(false);
michael@0 496 record.name.reset();
michael@0 497 break;
michael@0 498 }
michael@0 499
michael@0 500 // Determine the language.
michael@0 501 const uint16_t languageID = SkEndian_SwapBE16(nameRecord->languageID.languageTagID);
michael@0 502
michael@0 503 // Handle format 1 languages.
michael@0 504 if (SkOTTableName::format_1 == fName.format && languageID >= 0x8000) {
michael@0 505 const uint16_t languageTagRecordIndex = languageID - 0x8000;
michael@0 506
michael@0 507 const SkOTTableName::Format1Ext* format1ext =
michael@0 508 SkTAfter<const SkOTTableName::Format1Ext>(nameRecords, nameRecordsCount);
michael@0 509
michael@0 510 if (languageTagRecordIndex < SkEndian_SwapBE16(format1ext->langTagCount)) {
michael@0 511 const SkOTTableName::Format1Ext::LangTagRecord* languageTagRecord =
michael@0 512 SkTAfter<const SkOTTableName::Format1Ext::LangTagRecord>(format1ext);
michael@0 513
michael@0 514 uint16_t offset = SkEndian_SwapBE16(languageTagRecord[languageTagRecordIndex].offset);
michael@0 515 uint16_t length = SkEndian_SwapBE16(languageTagRecord[languageTagRecordIndex].length);
michael@0 516 const uint16_t* string = SkTAddOffset<const uint16_t>(stringTable, offset);
michael@0 517 SkStringFromUTF16BE(string, length, record.language);
michael@0 518 return true;
michael@0 519 }
michael@0 520 }
michael@0 521
michael@0 522 // Handle format 0 languages, translating them into BCP 47.
michael@0 523 const BCP47FromLanguageId target = { languageID, "" };
michael@0 524 int languageIndex = SkTSearch<BCP47FromLanguageId, BCP47FromLanguageIdLess>(
michael@0 525 BCP47FromLanguageID, SK_ARRAY_COUNT(BCP47FromLanguageID), target, sizeof(target));
michael@0 526 if (languageIndex >= 0) {
michael@0 527 record.language = BCP47FromLanguageID[languageIndex].bcp47;
michael@0 528 return true;
michael@0 529 }
michael@0 530
michael@0 531 // Unknown language, return the BCP 47 code 'und' for 'undetermined'.
michael@0 532 record.language = "und";
michael@0 533 return true;
michael@0 534 }

mercurial