1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
|
/*
* Copyright (C) 2007 Apple Computer, Inc.
*
* Portions are Copyright (C) 1998 Netscape Communications Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Alternatively, the contents of this file may be used under the terms
* of either the Mozilla Public License Version 1.1, found at
* http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
* License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
* (the "GPL"), in which case the provisions of the MPL or the GPL are
* applicable instead of those above. If you wish to allow use of your
* version of this file only under the terms of one of those two
* licenses (the MPL or the GPL) and not to allow others to use your
* version of this file under the LGPL, indicate your decision by
* deletingthe provisions above and replace them with the notice and
* other provisions required by the MPL or the GPL, as the case may be.
* If you do not delete the provisions above, a recipient may use your
* version of this file under any of the LGPL, the MPL or the GPL.
*/
#include "config.h"
#include "UnicodeRange.h"
namespace WebCore {
// This table depends on unicode range definitions.
// Each item's index must correspond to a unicode range value
// eg. x-cyrillic = LangGroupTable[cRangeCyrillic]
static const char* gUnicodeRangeToLangGroupTable[] =
{
"x-cyrillic",
"el",
"tr",
"he",
"ar",
"x-baltic",
"th",
"ko",
"ja",
"zh-CN",
"zh-TW",
"x-devanagari",
"x-tamil",
"x-armn",
"x-beng",
"x-cans",
"x-ethi",
"x-geor",
"x-gujr",
"x-guru",
"x-khmr",
"x-mlym"
};
/**********************************************************************
* Unicode subranges as defined in unicode 3.0
* x-western, x-central-euro, tr, x-baltic -> latin
* 0000 - 036f
* 1e00 - 1eff
* 2000 - 206f (general punctuation)
* 20a0 - 20cf (currency symbols)
* 2100 - 214f (letterlike symbols)
* 2150 - 218f (Number Forms)
* el -> greek
* 0370 - 03ff
* 1f00 - 1fff
* x-cyrillic -> cyrillic
* 0400 - 04ff
* he -> hebrew
* 0590 - 05ff
* ar -> arabic
* 0600 - 06ff
* fb50 - fdff (arabic presentation forms)
* fe70 - feff (arabic presentation forms b)
* th - thai
* 0e00 - 0e7f
* ko -> korean
* ac00 - d7af (hangul Syllables)
* 1100 - 11ff (jamo)
* 3130 - 318f (hangul compatibility jamo)
* ja
* 3040 - 309f (hiragana)
* 30a0 - 30ff (katakana)
* zh-CN
* zh-TW
*
* CJK
* 3100 - 312f (bopomofo)
* 31a0 - 31bf (bopomofo extended)
* 3000 - 303f (CJK Symbols and Punctuation)
* 2e80 - 2eff (CJK radicals supplement)
* 2f00 - 2fdf (Kangxi Radicals)
* 2ff0 - 2fff (Ideographic Description Characters)
* 3190 - 319f (kanbun)
* 3200 - 32ff (Enclosed CJK letters and Months)
* 3300 - 33ff (CJK compatibility)
* 3400 - 4dbf (CJK Unified Ideographs Extension A)
* 4e00 - 9faf (CJK Unified Ideographs)
* f900 - fa5f (CJK Compatibility Ideographs)
* fe30 - fe4f (CJK compatibility Forms)
* ff00 - ffef (halfwidth and fullwidth forms)
*
* Armenian
* 0530 - 058f
* Sriac
* 0700 - 074f
* Thaana
* 0780 - 07bf
* Devanagari
* 0900 - 097f
* Bengali
* 0980 - 09ff
* Gurmukhi
* 0a00 - 0a7f
* Gujarati
* 0a80 - 0aff
* Oriya
* 0b00 - 0b7f
* Tamil
* 0b80 - 0bff
* Telugu
* 0c00 - 0c7f
* Kannada
* 0c80 - 0cff
* Malayalam
* 0d00 - 0d7f
* Sinhala
* 0d80 - 0def
* Lao
* 0e80 - 0eff
* Tibetan
* 0f00 - 0fbf
* Myanmar
* 1000 - 109f
* Georgian
* 10a0 - 10ff
* Ethiopic
* 1200 - 137f
* Cherokee
* 13a0 - 13ff
* Canadian Aboriginal Syllabics
* 1400 - 167f
* Ogham
* 1680 - 169f
* Runic
* 16a0 - 16ff
* Khmer
* 1780 - 17ff
* Mongolian
* 1800 - 18af
* Misc - superscripts and subscripts
* 2070 - 209f
* Misc - Combining Diacritical Marks for Symbols
* 20d0 - 20ff
* Misc - Arrows
* 2190 - 21ff
* Misc - Mathematical Operators
* 2200 - 22ff
* Misc - Miscellaneous Technical
* 2300 - 23ff
* Misc - Control picture
* 2400 - 243f
* Misc - Optical character recognition
* 2440 - 2450
* Misc - Enclose Alphanumerics
* 2460 - 24ff
* Misc - Box Drawing
* 2500 - 257f
* Misc - Block Elements
* 2580 - 259f
* Misc - Geometric Shapes
* 25a0 - 25ff
* Misc - Miscellaneous Symbols
* 2600 - 267f
* Misc - Dingbats
* 2700 - 27bf
* Misc - Braille Patterns
* 2800 - 28ff
* Yi Syllables
* a000 - a48f
* Yi radicals
* a490 - a4cf
* Alphabetic Presentation Forms
* fb00 - fb4f
* Misc - Combining half Marks
* fe20 - fe2f
* Misc - small form variants
* fe50 - fe6f
* Misc - Specials
* fff0 - ffff
*********************************************************************/
static const unsigned cNumSubTables = 9;
static const unsigned cSubTableSize = 16;
static const unsigned char gUnicodeSubrangeTable[cNumSubTables][cSubTableSize] =
{
{ // table for X---
cRangeTableBase+1, //u0xxx
cRangeTableBase+2, //u1xxx
cRangeTableBase+3, //u2xxx
cRangeSetCJK, //u3xxx
cRangeSetCJK, //u4xxx
cRangeSetCJK, //u5xxx
cRangeSetCJK, //u6xxx
cRangeSetCJK, //u7xxx
cRangeSetCJK, //u8xxx
cRangeSetCJK, //u9xxx
cRangeTableBase+4, //uaxxx
cRangeKorean, //ubxxx
cRangeKorean, //ucxxx
cRangeTableBase+5, //udxxx
cRangePrivate, //uexxx
cRangeTableBase+6 //ufxxx
},
{ //table for 0X--
cRangeSetLatin, //u00xx
cRangeSetLatin, //u01xx
cRangeSetLatin, //u02xx
cRangeGreek, //u03xx XXX 0300-036f is in fact cRangeCombiningDiacriticalMarks
cRangeCyrillic, //u04xx
cRangeTableBase+7, //u05xx, includes Cyrillic supplement, Hebrew, and Armenian
cRangeArabic, //u06xx
cRangeTertiaryTable, //u07xx
cRangeUnassigned, //u08xx
cRangeTertiaryTable, //u09xx
cRangeTertiaryTable, //u0axx
cRangeTertiaryTable, //u0bxx
cRangeTertiaryTable, //u0cxx
cRangeTertiaryTable, //u0dxx
cRangeTertiaryTable, //u0exx
cRangeTibetan, //u0fxx
},
{ //table for 1x--
cRangeTertiaryTable, //u10xx
cRangeKorean, //u11xx
cRangeEthiopic, //u12xx
cRangeTertiaryTable, //u13xx
cRangeCanadian, //u14xx
cRangeCanadian, //u15xx
cRangeTertiaryTable, //u16xx
cRangeKhmer, //u17xx
cRangeMongolian, //u18xx
cRangeUnassigned, //u19xx
cRangeUnassigned, //u1axx
cRangeUnassigned, //u1bxx
cRangeUnassigned, //u1cxx
cRangeUnassigned, //u1dxx
cRangeSetLatin, //u1exx
cRangeGreek, //u1fxx
},
{ //table for 2x--
cRangeSetLatin, //u20xx
cRangeSetLatin, //u21xx
cRangeMathOperators, //u22xx
cRangeMiscTechnical, //u23xx
cRangeControlOpticalEnclose, //u24xx
cRangeBoxBlockGeometrics, //u25xx
cRangeMiscSymbols, //u26xx
cRangeDingbats, //u27xx
cRangeBraillePattern, //u28xx
cRangeUnassigned, //u29xx
cRangeUnassigned, //u2axx
cRangeUnassigned, //u2bxx
cRangeUnassigned, //u2cxx
cRangeUnassigned, //u2dxx
cRangeSetCJK, //u2exx
cRangeSetCJK, //u2fxx
},
{ //table for ax--
cRangeYi, //ua0xx
cRangeYi, //ua1xx
cRangeYi, //ua2xx
cRangeYi, //ua3xx
cRangeYi, //ua4xx
cRangeUnassigned, //ua5xx
cRangeUnassigned, //ua6xx
cRangeUnassigned, //ua7xx
cRangeUnassigned, //ua8xx
cRangeUnassigned, //ua9xx
cRangeUnassigned, //uaaxx
cRangeUnassigned, //uabxx
cRangeKorean, //uacxx
cRangeKorean, //uadxx
cRangeKorean, //uaexx
cRangeKorean, //uafxx
},
{ //table for dx--
cRangeKorean, //ud0xx
cRangeKorean, //ud1xx
cRangeKorean, //ud2xx
cRangeKorean, //ud3xx
cRangeKorean, //ud4xx
cRangeKorean, //ud5xx
cRangeKorean, //ud6xx
cRangeKorean, //ud7xx
cRangeSurrogate, //ud8xx
cRangeSurrogate, //ud9xx
cRangeSurrogate, //udaxx
cRangeSurrogate, //udbxx
cRangeSurrogate, //udcxx
cRangeSurrogate, //uddxx
cRangeSurrogate, //udexx
cRangeSurrogate, //udfxx
},
{ // table for fx--
cRangePrivate, //uf0xx
cRangePrivate, //uf1xx
cRangePrivate, //uf2xx
cRangePrivate, //uf3xx
cRangePrivate, //uf4xx
cRangePrivate, //uf5xx
cRangePrivate, //uf6xx
cRangePrivate, //uf7xx
cRangePrivate, //uf8xx
cRangeSetCJK, //uf9xx
cRangeSetCJK, //ufaxx
cRangeArabic, //ufbxx, includes alphabic presentation form
cRangeArabic, //ufcxx
cRangeArabic, //ufdxx
cRangeArabic, //ufexx, includes Combining half marks,
// CJK compatibility forms,
// CJK compatibility forms,
// small form variants
cRangeTableBase+8, //uffxx, halfwidth and fullwidth forms, includes Specials
},
{ //table for 0x0500 - 0x05ff
cRangeCyrillic, //u050x
cRangeCyrillic, //u051x
cRangeCyrillic, //u052x
cRangeArmenian, //u053x
cRangeArmenian, //u054x
cRangeArmenian, //u055x
cRangeArmenian, //u056x
cRangeArmenian, //u057x
cRangeArmenian, //u058x
cRangeHebrew, //u059x
cRangeHebrew, //u05ax
cRangeHebrew, //u05bx
cRangeHebrew, //u05cx
cRangeHebrew, //u05dx
cRangeHebrew, //u05ex
cRangeHebrew, //u05fx
},
{ //table for 0xff00 - 0xffff
cRangeSetCJK, //uff0x, fullwidth latin
cRangeSetCJK, //uff1x, fullwidth latin
cRangeSetCJK, //uff2x, fullwidth latin
cRangeSetCJK, //uff3x, fullwidth latin
cRangeSetCJK, //uff4x, fullwidth latin
cRangeSetCJK, //uff5x, fullwidth latin
cRangeSetCJK, //uff6x, halfwidth katakana
cRangeSetCJK, //uff7x, halfwidth katakana
cRangeSetCJK, //uff8x, halfwidth katakana
cRangeSetCJK, //uff9x, halfwidth katakana
cRangeSetCJK, //uffax, halfwidth hangul jamo
cRangeSetCJK, //uffbx, halfwidth hangul jamo
cRangeSetCJK, //uffcx, halfwidth hangul jamo
cRangeSetCJK, //uffdx, halfwidth hangul jamo
cRangeSetCJK, //uffex, fullwidth symbols
cRangeSpecials, //ufffx, Specials
},
};
// Most scripts between U+0700 and U+16FF are assigned a chunk of 128 (0x80)
// code points so that the number of entries in the tertiary range
// table for that range is obtained by dividing (0x1700 - 0x0700) by 128.
// Exceptions: Ethiopic, Tibetan, Hangul Jamo and Canadian aboriginal
// syllabaries take multiple chunks and Ogham and Runic share a single chunk.
static const unsigned cTertiaryTableSize = ((0x1700 - 0x0700) / 0x80);
static const unsigned char gUnicodeTertiaryRangeTable[cTertiaryTableSize] =
{ //table for 0x0700 - 0x1600
cRangeSyriac, //u070x
cRangeThaana, //u078x
cRangeUnassigned, //u080x place holder(resolved in the 2ndary tab.)
cRangeUnassigned, //u088x place holder(resolved in the 2ndary tab.)
cRangeDevanagari, //u090x
cRangeBengali, //u098x
cRangeGurmukhi, //u0a0x
cRangeGujarati, //u0a8x
cRangeOriya, //u0b0x
cRangeTamil, //u0b8x
cRangeTelugu, //u0c0x
cRangeKannada, //u0c8x
cRangeMalayalam, //u0d0x
cRangeSinhala, //u0d8x
cRangeThai, //u0e0x
cRangeLao, //u0e8x
cRangeTibetan, //u0f0x place holder(resolved in the 2ndary tab.)
cRangeTibetan, //u0f8x place holder(resolved in the 2ndary tab.)
cRangeMyanmar, //u100x
cRangeGeorgian, //u108x
cRangeKorean, //u110x place holder(resolved in the 2ndary tab.)
cRangeKorean, //u118x place holder(resolved in the 2ndary tab.)
cRangeEthiopic, //u120x place holder(resolved in the 2ndary tab.)
cRangeEthiopic, //u128x place holder(resolved in the 2ndary tab.)
cRangeEthiopic, //u130x
cRangeCherokee, //u138x
cRangeCanadian, //u140x place holder(resolved in the 2ndary tab.)
cRangeCanadian, //u148x place holder(resolved in the 2ndary tab.)
cRangeCanadian, //u150x place holder(resolved in the 2ndary tab.)
cRangeCanadian, //u158x place holder(resolved in the 2ndary tab.)
cRangeCanadian, //u160x
cRangeOghamRunic, //u168x this contains two scripts, Ogham & Runic
};
// A two level index is almost enough for locating a range, with the
// exception of u03xx and u05xx. Since we don't really care about range for
// combining diacritical marks in our font application, they are
// not discriminated further. Future adoption of this method for other use
// should be aware of this limitation. The implementation can be extended if
// there is such a need.
// For Indic, Southeast Asian scripts and some other scripts between
// U+0700 and U+16FF, it's extended to the third level.
unsigned int findCharUnicodeRange(UChar32 ch)
{
if (ch >= 0xFFFF)
return 0;
unsigned int range;
//search the first table
range = gUnicodeSubrangeTable[0][ch >> 12];
if (range < cRangeTableBase)
// we try to get a specific range
return range;
// otherwise, we have one more table to look at
range = gUnicodeSubrangeTable[range - cRangeTableBase][(ch & 0x0f00) >> 8];
if (range < cRangeTableBase)
return range;
if (range < cRangeTertiaryTable)
return gUnicodeSubrangeTable[range - cRangeTableBase][(ch & 0x00f0) >> 4];
// Yet another table to look at : U+0700 - U+16FF : 128 code point blocks
return gUnicodeTertiaryRangeTable[(ch - 0x0700) >> 7];
}
const char* langGroupFromUnicodeRange(unsigned char unicodeRange)
{
if (cRangeSpecificItemNum > unicodeRange)
return gUnicodeRangeToLangGroupTable[unicodeRange];
return 0;
}
}
|