Bug 435739 Poor performance of Firefox 3 with no X RENDER extension
[wine-gecko.git] / gfx / thebes / src / nsUnicodeRange.cpp
blobf6b3d96c86de2fd9af7a6a6b3fda5ea63e16bc67
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
13 * License.
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.
22 * Contributor(s):
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[] =
45 "x-cyrillic",
46 "el",
47 "tr",
48 "he",
49 "ar",
50 "x-baltic",
51 "th",
52 "ko",
53 "ja",
54 "zh-CN",
55 "zh-TW",
56 "x-devanagari",
57 "x-tamil",
58 "x-armn",
59 "x-beng",
60 "x-cans",
61 "x-ethi",
62 "x-geor",
63 "x-gujr",
64 "x-guru",
65 "x-khmr",
66 "x-mlym",
67 "x-orya",
68 "x-telu",
69 "x-knda",
70 "x-sinh"
73 /**********************************************************************
74 * Unicode subranges as defined in unicode 3.0
75 * x-western, x-central-euro, tr, x-baltic -> latin
76 * 0000 - 036f
77 * 1e00 - 1eff
78 * 2000 - 206f (general punctuation)
79 * 20a0 - 20cf (currency symbols)
80 * 2100 - 214f (letterlike symbols)
81 * 2150 - 218f (Number Forms)
82 * el -> greek
83 * 0370 - 03ff
84 * 1f00 - 1fff
85 * x-cyrillic -> cyrillic
86 * 0400 - 04ff
87 * he -> hebrew
88 * 0590 - 05ff
89 * ar -> arabic
90 * 0600 - 06ff
91 * fb50 - fdff (arabic presentation forms)
92 * fe70 - feff (arabic presentation forms b)
93 * th - thai
94 * 0e00 - 0e7f
95 * ko -> korean
96 * ac00 - d7af (hangul Syllables)
97 * 1100 - 11ff (jamo)
98 * 3130 - 318f (hangul compatibility jamo)
99 * ja
100 * 3040 - 309f (hiragana)
101 * 30a0 - 30ff (katakana)
102 * zh-CN
103 * zh-TW
105 * CJK
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)
121 * Armenian
122 * 0530 - 058f
123 * Sriac
124 * 0700 - 074f
125 * Thaana
126 * 0780 - 07bf
127 * Devanagari
128 * 0900 - 097f
129 * Bengali
130 * 0980 - 09ff
131 * Gurmukhi
132 * 0a00 - 0a7f
133 * Gujarati
134 * 0a80 - 0aff
135 * Oriya
136 * 0b00 - 0b7f
137 * Tamil
138 * 0b80 - 0bff
139 * Telugu
140 * 0c00 - 0c7f
141 * Kannada
142 * 0c80 - 0cff
143 * Malayalam
144 * 0d00 - 0d7f
145 * Sinhala
146 * 0d80 - 0def
147 * Lao
148 * 0e80 - 0eff
149 * Tibetan
150 * 0f00 - 0fbf
151 * Myanmar
152 * 1000 - 109f
153 * Georgian
154 * 10a0 - 10ff
155 * Ethiopic
156 * 1200 - 137f
157 * Cherokee
158 * 13a0 - 13ff
159 * Canadian Aboriginal Syllabics
160 * 1400 - 167f
161 * Ogham
162 * 1680 - 169f
163 * Runic
164 * 16a0 - 16ff
165 * Khmer
166 * 1780 - 17ff
167 * Mongolian
168 * 1800 - 18af
169 * Misc - superscripts and subscripts
170 * 2070 - 209f
171 * Misc - Combining Diacritical Marks for Symbols
172 * 20d0 - 20ff
173 * Misc - Arrows
174 * 2190 - 21ff
175 * Misc - Mathematical Operators
176 * 2200 - 22ff
177 * Misc - Miscellaneous Technical
178 * 2300 - 23ff
179 * Misc - Control picture
180 * 2400 - 243f
181 * Misc - Optical character recognition
182 * 2440 - 2450
183 * Misc - Enclose Alphanumerics
184 * 2460 - 24ff
185 * Misc - Box Drawing
186 * 2500 - 257f
187 * Misc - Block Elements
188 * 2580 - 259f
189 * Misc - Geometric Shapes
190 * 25a0 - 25ff
191 * Misc - Miscellaneous Symbols
192 * 2600 - 267f
193 * Misc - Dingbats
194 * 2700 - 27bf
195 * Misc - Braille Patterns
196 * 2800 - 28ff
197 * Yi Syllables
198 * a000 - a48f
199 * Yi radicals
200 * a490 - a4cf
201 * Alphabetic Presentation Forms
202 * fb00 - fb4f
203 * Misc - Combining half Marks
204 * fe20 - fe2f
205 * Misc - small form variants
206 * fe50 - fe6f
207 * Misc - Specials
208 * fff0 - ffff
209 *********************************************************************/
213 #define NUM_OF_SUBTABLES 9
214 #define SUBTABLE_SIZE 16
216 static const PRUint8 gUnicodeSubrangeTable[NUM_OF_SUBTABLES][SUBTABLE_SIZE] =
218 { // table for X---
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
236 { //table for 0X--
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
254 { //table for 1x--
255 kRangeTertiaryTable, //u10xx
256 kRangeKorean, //u11xx
257 kRangeEthiopic, //u12xx
258 kRangeTertiaryTable, //u13xx
259 kRangeCanadian, //u14xx
260 kRangeCanadian, //u15xx
261 kRangeTertiaryTable, //u16xx
262 kRangeKhmer, //u17xx
263 kRangeMongolian, //u18xx
264 kRangeUnassigned, //u19xx
265 kRangeUnassigned, //u1axx
266 kRangeUnassigned, //u1bxx
267 kRangeUnassigned, //u1cxx
268 kRangeUnassigned, //u1dxx
269 kRangeSetLatin, //u1exx
270 kRangeGreek, //u1fxx
272 { //table for 2x--
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
290 { //table for ax--
291 kRangeYi, //ua0xx
292 kRangeYi, //ua1xx
293 kRangeYi, //ua2xx
294 kRangeYi, //ua3xx
295 kRangeYi, //ua4xx
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
308 { //table for dx--
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
326 { // table for fx--
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
402 kRangeOriya, //u0b0x
403 kRangeTamil, //u0b8x
404 kRangeTelugu, //u0c0x
405 kRangeKannada, //u0c8x
406 kRangeMalayalam, //u0d0x
407 kRangeSinhala, //u0d8x
408 kRangeThai, //u0e0x
409 kRangeLao, //u0e8x
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)
438 PRUint32 range;
440 //search the first table
441 range = gUnicodeSubrangeTable[0][ch >> 12];
443 if (range < kRangeTableBase)
444 // we try to get a specific range
445 return range;
447 // otherwise, we have one more table to look at
448 range = gUnicodeSubrangeTable[range - kRangeTableBase][(ch & 0x0f00) >> 8];
449 if (range < kRangeTableBase)
450 return range;
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];
462 return nsnull;