1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsUnicodeRange.h"
40 // This table depends on unicode range definitions.
41 // Each item's index must correspond unicode range value
42 // eg. x-cyrillic = LangGroupTable[kRangeCyrillic]
43 static const char *gUnicodeRangeToLangGroupTable
[] =
73 /**********************************************************************
74 * Unicode subranges as defined in unicode 3.0
75 * x-western, x-central-euro, tr, x-baltic -> latin
78 * 2000 - 206f (general punctuation)
79 * 20a0 - 20cf (currency symbols)
80 * 2100 - 214f (letterlike symbols)
81 * 2150 - 218f (Number Forms)
85 * x-cyrillic -> cyrillic
91 * fb50 - fdff (arabic presentation forms)
92 * fe70 - feff (arabic presentation forms b)
96 * ac00 - d7af (hangul Syllables)
98 * 3130 - 318f (hangul compatibility jamo)
100 * 3040 - 309f (hiragana)
101 * 30a0 - 30ff (katakana)
106 * 3100 - 312f (bopomofo)
107 * 31a0 - 31bf (bopomofo extended)
108 * 3000 - 303f (CJK Symbols and Punctuation)
109 * 2e80 - 2eff (CJK radicals supplement)
110 * 2f00 - 2fdf (Kangxi Radicals)
111 * 2ff0 - 2fff (Ideographic Description Characters)
112 * 3190 - 319f (kanbun)
113 * 3200 - 32ff (Enclosed CJK letters and Months)
114 * 3300 - 33ff (CJK compatibility)
115 * 3400 - 4dbf (CJK Unified Ideographs Extension A)
116 * 4e00 - 9faf (CJK Unified Ideographs)
117 * f900 - fa5f (CJK Compatibility Ideographs)
118 * fe30 - fe4f (CJK compatibility Forms)
119 * ff00 - ffef (halfwidth and fullwidth forms)
159 * Canadian Aboriginal Syllabics
169 * Misc - superscripts and subscripts
171 * Misc - Combining Diacritical Marks for Symbols
175 * Misc - Mathematical Operators
177 * Misc - Miscellaneous Technical
179 * Misc - Control picture
181 * Misc - Optical character recognition
183 * Misc - Enclose Alphanumerics
187 * Misc - Block Elements
189 * Misc - Geometric Shapes
191 * Misc - Miscellaneous Symbols
195 * Misc - Braille Patterns
201 * Alphabetic Presentation Forms
203 * Misc - Combining half Marks
205 * Misc - small form variants
209 *********************************************************************/
213 #define NUM_OF_SUBTABLES 9
214 #define SUBTABLE_SIZE 16
216 static const PRUint8 gUnicodeSubrangeTable
[NUM_OF_SUBTABLES
][SUBTABLE_SIZE
] =
219 kRangeTableBase
+1, //u0xxx
220 kRangeTableBase
+2, //u1xxx
221 kRangeTableBase
+3, //u2xxx
222 kRangeSetCJK
, //u3xxx
223 kRangeSetCJK
, //u4xxx
224 kRangeSetCJK
, //u5xxx
225 kRangeSetCJK
, //u6xxx
226 kRangeSetCJK
, //u7xxx
227 kRangeSetCJK
, //u8xxx
228 kRangeSetCJK
, //u9xxx
229 kRangeTableBase
+4, //uaxxx
230 kRangeKorean
, //ubxxx
231 kRangeKorean
, //ucxxx
232 kRangeTableBase
+5, //udxxx
233 kRangePrivate
, //uexxx
234 kRangeTableBase
+6 //ufxxx
237 kRangeSetLatin
, //u00xx
238 kRangeSetLatin
, //u01xx
239 kRangeSetLatin
, //u02xx
240 kRangeGreek
, //u03xx XXX 0300-036f is in fact kRangeCombiningDiacriticalMarks
241 kRangeCyrillic
, //u04xx
242 kRangeTableBase
+7, //u05xx, includes Cyrillic supplement, Hebrew, and Armenian
243 kRangeArabic
, //u06xx
244 kRangeTertiaryTable
, //u07xx
245 kRangeUnassigned
, //u08xx
246 kRangeTertiaryTable
, //u09xx
247 kRangeTertiaryTable
, //u0axx
248 kRangeTertiaryTable
, //u0bxx
249 kRangeTertiaryTable
, //u0cxx
250 kRangeTertiaryTable
, //u0dxx
251 kRangeTertiaryTable
, //u0exx
252 kRangeTibetan
, //u0fxx
255 kRangeTertiaryTable
, //u10xx
256 kRangeKorean
, //u11xx
257 kRangeEthiopic
, //u12xx
258 kRangeTertiaryTable
, //u13xx
259 kRangeCanadian
, //u14xx
260 kRangeCanadian
, //u15xx
261 kRangeTertiaryTable
, //u16xx
263 kRangeMongolian
, //u18xx
264 kRangeUnassigned
, //u19xx
265 kRangeUnassigned
, //u1axx
266 kRangeUnassigned
, //u1bxx
267 kRangeUnassigned
, //u1cxx
268 kRangeUnassigned
, //u1dxx
269 kRangeSetLatin
, //u1exx
273 kRangeSetLatin
, //u20xx
274 kRangeSetLatin
, //u21xx
275 kRangeMathOperators
, //u22xx
276 kRangeMiscTechnical
, //u23xx
277 kRangeControlOpticalEnclose
, //u24xx
278 kRangeBoxBlockGeometrics
, //u25xx
279 kRangeMiscSymbols
, //u26xx
280 kRangeDingbats
, //u27xx
281 kRangeBraillePattern
, //u28xx
282 kRangeUnassigned
, //u29xx
283 kRangeUnassigned
, //u2axx
284 kRangeUnassigned
, //u2bxx
285 kRangeUnassigned
, //u2cxx
286 kRangeUnassigned
, //u2dxx
287 kRangeSetCJK
, //u2exx
288 kRangeSetCJK
, //u2fxx
296 kRangeUnassigned
, //ua5xx
297 kRangeUnassigned
, //ua6xx
298 kRangeUnassigned
, //ua7xx
299 kRangeUnassigned
, //ua8xx
300 kRangeUnassigned
, //ua9xx
301 kRangeUnassigned
, //uaaxx
302 kRangeUnassigned
, //uabxx
303 kRangeKorean
, //uacxx
304 kRangeKorean
, //uadxx
305 kRangeKorean
, //uaexx
306 kRangeKorean
, //uafxx
309 kRangeKorean
, //ud0xx
310 kRangeKorean
, //ud1xx
311 kRangeKorean
, //ud2xx
312 kRangeKorean
, //ud3xx
313 kRangeKorean
, //ud4xx
314 kRangeKorean
, //ud5xx
315 kRangeKorean
, //ud6xx
316 kRangeKorean
, //ud7xx
317 kRangeSurrogate
, //ud8xx
318 kRangeSurrogate
, //ud9xx
319 kRangeSurrogate
, //udaxx
320 kRangeSurrogate
, //udbxx
321 kRangeSurrogate
, //udcxx
322 kRangeSurrogate
, //uddxx
323 kRangeSurrogate
, //udexx
324 kRangeSurrogate
, //udfxx
327 kRangePrivate
, //uf0xx
328 kRangePrivate
, //uf1xx
329 kRangePrivate
, //uf2xx
330 kRangePrivate
, //uf3xx
331 kRangePrivate
, //uf4xx
332 kRangePrivate
, //uf5xx
333 kRangePrivate
, //uf6xx
334 kRangePrivate
, //uf7xx
335 kRangePrivate
, //uf8xx
336 kRangeSetCJK
, //uf9xx
337 kRangeSetCJK
, //ufaxx
338 kRangeArabic
, //ufbxx, includes alphabic presentation form
339 kRangeArabic
, //ufcxx
340 kRangeArabic
, //ufdxx
341 kRangeArabic
, //ufexx, includes Combining half marks,
342 // CJK compatibility forms,
343 // CJK compatibility forms,
344 // small form variants
345 kRangeTableBase
+8, //uffxx, halfwidth and fullwidth forms, includes Specials
347 { //table for 0x0500 - 0x05ff
348 kRangeCyrillic
, //u050x
349 kRangeCyrillic
, //u051x
350 kRangeCyrillic
, //u052x
351 kRangeArmenian
, //u053x
352 kRangeArmenian
, //u054x
353 kRangeArmenian
, //u055x
354 kRangeArmenian
, //u056x
355 kRangeArmenian
, //u057x
356 kRangeArmenian
, //u058x
357 kRangeHebrew
, //u059x
358 kRangeHebrew
, //u05ax
359 kRangeHebrew
, //u05bx
360 kRangeHebrew
, //u05cx
361 kRangeHebrew
, //u05dx
362 kRangeHebrew
, //u05ex
363 kRangeHebrew
, //u05fx
365 { //table for 0xff00 - 0xffff
366 kRangeSetCJK
, //uff0x, fullwidth latin
367 kRangeSetCJK
, //uff1x, fullwidth latin
368 kRangeSetCJK
, //uff2x, fullwidth latin
369 kRangeSetCJK
, //uff3x, fullwidth latin
370 kRangeSetCJK
, //uff4x, fullwidth latin
371 kRangeSetCJK
, //uff5x, fullwidth latin
372 kRangeSetCJK
, //uff6x, halfwidth katakana
373 kRangeSetCJK
, //uff7x, halfwidth katakana
374 kRangeSetCJK
, //uff8x, halfwidth katakana
375 kRangeSetCJK
, //uff9x, halfwidth katakana
376 kRangeSetCJK
, //uffax, halfwidth hangul jamo
377 kRangeSetCJK
, //uffbx, halfwidth hangul jamo
378 kRangeSetCJK
, //uffcx, halfwidth hangul jamo
379 kRangeSetCJK
, //uffdx, halfwidth hangul jamo
380 kRangeSetCJK
, //uffex, fullwidth symbols
381 kRangeSpecials
, //ufffx, Specials
385 // Most scripts between U+0700 and U+16FF are assigned a chunk of 128 (0x80)
386 // code points so that the number of entries in the tertiary range
387 // table for that range is obtained by dividing (0x1700 - 0x0700) by 128.
388 // Exceptions: Ethiopic, Tibetan, Hangul Jamo and Canadian aboriginal
389 // syllabaries take multiple chunks and Ogham and Runic share a single chunk.
390 #define TERTIARY_TABLE_SIZE ((0x1700 - 0x0700) / 0x80)
392 static const PRUint8 gUnicodeTertiaryRangeTable
[TERTIARY_TABLE_SIZE
] =
393 { //table for 0x0700 - 0x1600
394 kRangeSyriac
, //u070x
395 kRangeThaana
, //u078x
396 kRangeUnassigned
, //u080x place holder(resolved in the 2ndary tab.)
397 kRangeUnassigned
, //u088x place holder(resolved in the 2ndary tab.)
398 kRangeDevanagari
, //u090x
399 kRangeBengali
, //u098x
400 kRangeGurmukhi
, //u0a0x
401 kRangeGujarati
, //u0a8x
404 kRangeTelugu
, //u0c0x
405 kRangeKannada
, //u0c8x
406 kRangeMalayalam
, //u0d0x
407 kRangeSinhala
, //u0d8x
410 kRangeTibetan
, //u0f0x place holder(resolved in the 2ndary tab.)
411 kRangeTibetan
, //u0f8x place holder(resolved in the 2ndary tab.)
412 kRangeMyanmar
, //u100x
413 kRangeGeorgian
, //u108x
414 kRangeKorean
, //u110x place holder(resolved in the 2ndary tab.)
415 kRangeKorean
, //u118x place holder(resolved in the 2ndary tab.)
416 kRangeEthiopic
, //u120x place holder(resolved in the 2ndary tab.)
417 kRangeEthiopic
, //u128x place holder(resolved in the 2ndary tab.)
418 kRangeEthiopic
, //u130x
419 kRangeCherokee
, //u138x
420 kRangeCanadian
, //u140x place holder(resolved in the 2ndary tab.)
421 kRangeCanadian
, //u148x place holder(resolved in the 2ndary tab.)
422 kRangeCanadian
, //u150x place holder(resolved in the 2ndary tab.)
423 kRangeCanadian
, //u158x place holder(resolved in the 2ndary tab.)
424 kRangeCanadian
, //u160x
425 kRangeOghamRunic
, //u168x this contains two scripts, Ogham & Runic
428 // A two level index is almost enough for locating a range, with the
429 // exception of u03xx and u05xx. Since we don't really care about range for
430 // combining diacritical marks in our font application, they are
431 // not discriminated further. But future adoption of this module for other use
432 // should be aware of this limitation. The implementation can be extended if
433 // there is such a need.
434 // For Indic, Southeast Asian scripts and some other scripts between
435 // U+0700 and U+16FF, it's extended to the third level.
436 PRUint32
FindCharUnicodeRange(PRUnichar ch
)
440 //search the first table
441 range
= gUnicodeSubrangeTable
[0][ch
>> 12];
443 if (range
< kRangeTableBase
)
444 // we try to get a specific range
447 // otherwise, we have one more table to look at
448 range
= gUnicodeSubrangeTable
[range
- kRangeTableBase
][(ch
& 0x0f00) >> 8];
449 if (range
< kRangeTableBase
)
451 if (range
< kRangeTertiaryTable
)
452 return gUnicodeSubrangeTable
[range
- kRangeTableBase
][(ch
& 0x00f0) >> 4];
454 // Yet another table to look at : U+0700 - U+16FF : 128 code point blocks
455 return gUnicodeTertiaryRangeTable
[(ch
- 0x0700) >> 7];
458 const char* LangGroupFromUnicodeRange(PRUint8 unicodeRange
)
460 if (kRangeSpecificItemNum
> unicodeRange
)
461 return gUnicodeRangeToLangGroupTable
[unicodeRange
];