OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2009 Red Hat, Inc. | 2 * Copyright © 2009 Red Hat, Inc. |
3 * Copyright © 2011 Codethink Limited | 3 * Copyright © 2011 Codethink Limited |
4 * Copyright © 2010,2011 Google, Inc. | 4 * Copyright © 2010,2011,2012 Google, Inc. |
5 * | 5 * |
6 * This is part of HarfBuzz, a text shaping library. | 6 * This is part of HarfBuzz, a text shaping library. |
7 * | 7 * |
8 * Permission is hereby granted, without written agreement and without | 8 * Permission is hereby granted, without written agreement and without |
9 * license or royalty fees, to use, copy, modify, and distribute this | 9 * license or royalty fees, to use, copy, modify, and distribute this |
10 * software and its documentation for any purpose, provided that the | 10 * software and its documentation for any purpose, provided that the |
11 * above copyright notice and the following two paragraphs appear in | 11 * above copyright notice and the following two paragraphs appear in |
12 * all copies of this software. | 12 * all copies of this software. |
13 * | 13 * |
14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR | 14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
(...skipping 15 matching lines...) Expand all Loading... |
30 | 30 |
31 #ifndef HB_UNICODE_PRIVATE_HH | 31 #ifndef HB_UNICODE_PRIVATE_HH |
32 #define HB_UNICODE_PRIVATE_HH | 32 #define HB_UNICODE_PRIVATE_HH |
33 | 33 |
34 #include "hb-private.hh" | 34 #include "hb-private.hh" |
35 | 35 |
36 #include "hb-unicode.h" | 36 #include "hb-unicode.h" |
37 #include "hb-object-private.hh" | 37 #include "hb-object-private.hh" |
38 | 38 |
39 | 39 |
| 40 extern HB_INTERNAL const uint8_t _hb_modified_combining_class[256]; |
40 | 41 |
41 /* | 42 /* |
42 * hb_unicode_funcs_t | 43 * hb_unicode_funcs_t |
43 */ | 44 */ |
44 | 45 |
45 #define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS \ | 46 #define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS \ |
46 HB_UNICODE_FUNC_IMPLEMENT (combining_class) \ | 47 HB_UNICODE_FUNC_IMPLEMENT (combining_class) \ |
47 HB_UNICODE_FUNC_IMPLEMENT (eastasian_width) \ | 48 HB_UNICODE_FUNC_IMPLEMENT (eastasian_width) \ |
48 HB_UNICODE_FUNC_IMPLEMENT (general_category) \ | 49 HB_UNICODE_FUNC_IMPLEMENT (general_category) \ |
49 HB_UNICODE_FUNC_IMPLEMENT (mirroring) \ | 50 HB_UNICODE_FUNC_IMPLEMENT (mirroring) \ |
50 HB_UNICODE_FUNC_IMPLEMENT (script) \ | 51 HB_UNICODE_FUNC_IMPLEMENT (script) \ |
51 HB_UNICODE_FUNC_IMPLEMENT (compose) \ | 52 HB_UNICODE_FUNC_IMPLEMENT (compose) \ |
52 HB_UNICODE_FUNC_IMPLEMENT (decompose) \ | 53 HB_UNICODE_FUNC_IMPLEMENT (decompose) \ |
| 54 HB_UNICODE_FUNC_IMPLEMENT (decompose_compatibility) \ |
53 /* ^--- Add new callbacks here */ | 55 /* ^--- Add new callbacks here */ |
54 | 56 |
55 /* Simple callbacks are those taking a hb_codepoint_t and returning a hb_codepoi
nt_t */ | 57 /* Simple callbacks are those taking a hb_codepoint_t and returning a hb_codepoi
nt_t */ |
56 #define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE \ | 58 #define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE \ |
57 HB_UNICODE_FUNC_IMPLEMENT (unsigned int, combining_class) \ | 59 HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_combining_class_t, combining_class) \ |
58 HB_UNICODE_FUNC_IMPLEMENT (unsigned int, eastasian_width) \ | 60 HB_UNICODE_FUNC_IMPLEMENT (unsigned int, eastasian_width) \ |
59 HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_general_category_t, general_category) \ | 61 HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_general_category_t, general_category) \ |
60 HB_UNICODE_FUNC_IMPLEMENT (hb_codepoint_t, mirroring) \ | 62 HB_UNICODE_FUNC_IMPLEMENT (hb_codepoint_t, mirroring) \ |
61 HB_UNICODE_FUNC_IMPLEMENT (hb_script_t, script) \ | 63 HB_UNICODE_FUNC_IMPLEMENT (hb_script_t, script) \ |
62 /* ^--- Add new simple callbacks here */ | 64 /* ^--- Add new simple callbacks here */ |
63 | 65 |
64 struct _hb_unicode_funcs_t { | 66 struct hb_unicode_funcs_t { |
65 hb_object_header_t header; | 67 hb_object_header_t header; |
66 ASSERT_POD (); | 68 ASSERT_POD (); |
67 | 69 |
68 hb_unicode_funcs_t *parent; | 70 hb_unicode_funcs_t *parent; |
69 | 71 |
70 bool immutable; | 72 bool immutable; |
71 | 73 |
72 /* Don't access these directly. Call hb_unicode_*() instead. */ | 74 #define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \ |
| 75 inline return_type name (hb_codepoint_t unicode) { return func.name (this, uni
code, user_data.name); } |
| 76 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE |
| 77 #undef HB_UNICODE_FUNC_IMPLEMENT |
| 78 |
| 79 inline hb_bool_t compose (hb_codepoint_t a, hb_codepoint_t b, |
| 80 » » » hb_codepoint_t *ab) |
| 81 { |
| 82 *ab = 0; |
| 83 if (unlikely (!a || !b)) return false; |
| 84 return func.compose (this, a, b, ab, user_data.compose); |
| 85 } |
| 86 |
| 87 inline hb_bool_t decompose (hb_codepoint_t ab, |
| 88 » » » hb_codepoint_t *a, hb_codepoint_t *b) |
| 89 { |
| 90 *a = ab; *b = 0; |
| 91 return func.decompose (this, ab, a, b, user_data.decompose); |
| 92 } |
| 93 |
| 94 inline unsigned int decompose_compatibility (hb_codepoint_t u, |
| 95 » » » » » hb_codepoint_t *decomposed) |
| 96 { |
| 97 unsigned int ret = func.decompose_compatibility (this, u, decomposed, user_d
ata.decompose_compatibility); |
| 98 if (ret == 1 && u == decomposed[0]) { |
| 99 decomposed[0] = 0; |
| 100 return 0; |
| 101 } |
| 102 decomposed[ret] = 0; |
| 103 return ret; |
| 104 } |
| 105 |
| 106 |
| 107 unsigned int |
| 108 modified_combining_class (hb_codepoint_t unicode) |
| 109 { |
| 110 return _hb_modified_combining_class[combining_class (unicode)]; |
| 111 } |
| 112 |
| 113 inline hb_bool_t |
| 114 is_variation_selector (hb_codepoint_t unicode) |
| 115 { |
| 116 return unlikely (hb_in_ranges<hb_codepoint_t> (unicode, |
| 117 » » » » » » 0x180B, 0x180D, /* MONGOLIAN
FREE VARIATION SELECTOR ONE..THREE */ |
| 118 » » » » » » 0xFE00, 0xFE0F, /* VARIATION
SELECTOR-1..16 */ |
| 119 » » » » » » 0xE0100, 0xE01EF)); /* VARIA
TION SELECTOR-17..256 */ |
| 120 } |
| 121 |
| 122 /* Zero-Width invisible characters: |
| 123 * |
| 124 * 00AD SOFT HYPHEN |
| 125 * 034F COMBINING GRAPHEME JOINER |
| 126 * |
| 127 * 180E MONGOLIAN VOWEL SEPARATOR |
| 128 * |
| 129 * 200B ZERO WIDTH SPACE |
| 130 * 200C ZERO WIDTH NON-JOINER |
| 131 * 200D ZERO WIDTH JOINER |
| 132 * 200E LEFT-TO-RIGHT MARK |
| 133 * 200F RIGHT-TO-LEFT MARK |
| 134 * |
| 135 * 2028 LINE SEPARATOR |
| 136 * |
| 137 * 202A LEFT-TO-RIGHT EMBEDDING |
| 138 * 202B RIGHT-TO-LEFT EMBEDDING |
| 139 * 202C POP DIRECTIONAL FORMATTING |
| 140 * 202D LEFT-TO-RIGHT OVERRIDE |
| 141 * 202E RIGHT-TO-LEFT OVERRIDE |
| 142 * |
| 143 * 2060 WORD JOINER |
| 144 * 2061 FUNCTION APPLICATION |
| 145 * 2062 INVISIBLE TIMES |
| 146 * 2063 INVISIBLE SEPARATOR |
| 147 * |
| 148 * FEFF ZERO WIDTH NO-BREAK SPACE |
| 149 */ |
| 150 inline hb_bool_t |
| 151 is_zero_width (hb_codepoint_t ch) |
| 152 { |
| 153 return ((ch & ~0x007F) == 0x2000 && (hb_in_ranges<hb_codepoint_t> (ch, |
| 154 » » » » » » » » 0x200B, 0
x200F, |
| 155 » » » » » » » » 0x202A, 0
x202E, |
| 156 » » » » » » » » 0x2060, 0
x2064) || |
| 157 » » » » » (ch == 0x2028))) || |
| 158 » unlikely (ch == 0x0009 || |
| 159 » » ch == 0x00AD || |
| 160 » » ch == 0x034F || |
| 161 » » ch == 0x180E || |
| 162 » » ch == 0xFEFF); |
| 163 } |
| 164 |
73 | 165 |
74 struct { | 166 struct { |
75 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_func_t name; | 167 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_func_t name; |
76 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS | 168 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS |
77 #undef HB_UNICODE_FUNC_IMPLEMENT | 169 #undef HB_UNICODE_FUNC_IMPLEMENT |
78 } func; | 170 } func; |
79 | 171 |
80 struct { | 172 struct { |
81 #define HB_UNICODE_FUNC_IMPLEMENT(name) void *name; | 173 #define HB_UNICODE_FUNC_IMPLEMENT(name) void *name; |
82 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS | 174 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS |
83 #undef HB_UNICODE_FUNC_IMPLEMENT | 175 #undef HB_UNICODE_FUNC_IMPLEMENT |
84 } user_data; | 176 } user_data; |
85 | 177 |
86 struct { | 178 struct { |
87 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_destroy_func_t name; | 179 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_destroy_func_t name; |
88 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS | 180 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS |
89 #undef HB_UNICODE_FUNC_IMPLEMENT | 181 #undef HB_UNICODE_FUNC_IMPLEMENT |
90 } destroy; | 182 } destroy; |
91 }; | 183 }; |
92 | 184 |
93 | 185 |
94 #ifdef HAVE_GLIB | 186 extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil; |
95 extern HB_INTERNAL const hb_unicode_funcs_t _hb_glib_unicode_funcs; | |
96 #define _hb_unicode_funcs_default _hb_glib_unicode_funcs | |
97 #elif defined(HAVE_ICU) | |
98 extern HB_INTERNAL const hb_unicode_funcs_t _hb_icu_unicode_funcs; | |
99 #define _hb_unicode_funcs_default _hb_icu_unicode_funcs | |
100 #else | |
101 #define HB_UNICODE_FUNCS_NIL 1 | |
102 #define _hb_unicode_funcs_default _hb_unicode_funcs_nil | |
103 #endif | |
104 | 187 |
105 | 188 |
106 HB_INTERNAL unsigned int | 189 /* Modified combining marks */ |
107 _hb_unicode_modified_combining_class (hb_unicode_funcs_t *ufuncs, | |
108 » » » » hb_codepoint_t unicode); | |
109 | 190 |
110 static inline hb_bool_t | 191 /* Hebrew |
111 _hb_unicode_is_variation_selector (hb_codepoint_t unicode) | 192 * |
112 { | 193 * We permute the "fixed-position" classes 10-26 into the order |
113 return unlikely ((unicode >= 0x180B && unicode <= 0x180D) || /* MONGOLIAN FR
EE VARIATION SELECTOR ONE..THREE */ | 194 * described in the SBL Hebrew manual: |
114 » » (unicode >= 0xFE00 && unicode <= 0xFE0F) || /* VARIATION SE
LECTOR-1..16 */ | 195 * |
115 » » (unicode >= 0xE0100 && unicode <= 0xE01EF)); /* VARIATION SE
LECTOR-17..256 */ | 196 * http://www.sbl-site.org/Fonts/SBLHebrewUserManual1.5x.pdf |
116 } | 197 * |
| 198 * (as recommended by: |
| 199 * http://forum.fontlab.com/archive-old-microsoft-volt-group/vista-and-diacriti
c-ordering-t6751.0.html) |
| 200 * |
| 201 * More details here: |
| 202 * https://bugzilla.mozilla.org/show_bug.cgi?id=662055 |
| 203 */ |
| 204 #define HB_MODIFIED_COMBINING_CLASS_CCC10 22 /* sheva */ |
| 205 #define HB_MODIFIED_COMBINING_CLASS_CCC11 15 /* hataf segol */ |
| 206 #define HB_MODIFIED_COMBINING_CLASS_CCC12 16 /* hataf patah */ |
| 207 #define HB_MODIFIED_COMBINING_CLASS_CCC13 17 /* hataf qamats */ |
| 208 #define HB_MODIFIED_COMBINING_CLASS_CCC14 23 /* hiriq */ |
| 209 #define HB_MODIFIED_COMBINING_CLASS_CCC15 18 /* tsere */ |
| 210 #define HB_MODIFIED_COMBINING_CLASS_CCC16 19 /* segol */ |
| 211 #define HB_MODIFIED_COMBINING_CLASS_CCC17 20 /* patah */ |
| 212 #define HB_MODIFIED_COMBINING_CLASS_CCC18 21 /* qamats */ |
| 213 #define HB_MODIFIED_COMBINING_CLASS_CCC19 14 /* holam */ |
| 214 #define HB_MODIFIED_COMBINING_CLASS_CCC20 24 /* qubuts */ |
| 215 #define HB_MODIFIED_COMBINING_CLASS_CCC21 12 /* dagesh */ |
| 216 #define HB_MODIFIED_COMBINING_CLASS_CCC22 25 /* meteg */ |
| 217 #define HB_MODIFIED_COMBINING_CLASS_CCC23 13 /* rafe */ |
| 218 #define HB_MODIFIED_COMBINING_CLASS_CCC24 10 /* shin dot */ |
| 219 #define HB_MODIFIED_COMBINING_CLASS_CCC25 11 /* sin dot */ |
| 220 #define HB_MODIFIED_COMBINING_CLASS_CCC26 26 /* point varika */ |
117 | 221 |
118 /* Zero-Width invisible characters: | 222 /* |
| 223 * Arabic |
119 * | 224 * |
120 * 00AD SOFT HYPHEN | 225 * Modify to move Shadda (ccc=33) before other marks. See: |
121 * 034F COMBINING GRAPHEME JOINER | 226 * http://unicode.org/faq/normalization.html#8 |
| 227 * http://unicode.org/faq/normalization.html#9 |
| 228 */ |
| 229 #define HB_MODIFIED_COMBINING_CLASS_CCC27 28 /* fathatan */ |
| 230 #define HB_MODIFIED_COMBINING_CLASS_CCC28 29 /* dammatan */ |
| 231 #define HB_MODIFIED_COMBINING_CLASS_CCC29 30 /* kasratan */ |
| 232 #define HB_MODIFIED_COMBINING_CLASS_CCC30 31 /* fatha */ |
| 233 #define HB_MODIFIED_COMBINING_CLASS_CCC31 32 /* damma */ |
| 234 #define HB_MODIFIED_COMBINING_CLASS_CCC32 33 /* kasra */ |
| 235 #define HB_MODIFIED_COMBINING_CLASS_CCC33 27 /* shadda */ |
| 236 #define HB_MODIFIED_COMBINING_CLASS_CCC34 34 /* sukun */ |
| 237 #define HB_MODIFIED_COMBINING_CLASS_CCC35 35 /* superscript alef */ |
| 238 |
| 239 /* Syriac */ |
| 240 #define HB_MODIFIED_COMBINING_CLASS_CCC36 36 /* superscript alaph */ |
| 241 |
| 242 /* Telugu |
122 * | 243 * |
123 * 200B ZERO WIDTH SPACE | 244 * Modify Telugu length marks (ccc=84, ccc=91). |
124 * 200C ZERO WIDTH NON-JOINER | 245 * These are the only matras in the main Indic scripts range that have |
125 * 200D ZERO WIDTH JOINER | 246 * a non-zero ccc. That makes them reorder with the Halant that is |
126 * 200E LEFT-TO-RIGHT MARK | 247 * ccc=9. Just zero them, we don't need them in our Indic shaper. |
127 * 200F RIGHT-TO-LEFT MARK | 248 */ |
| 249 #define HB_MODIFIED_COMBINING_CLASS_CCC84 0 /* length mark */ |
| 250 #define HB_MODIFIED_COMBINING_CLASS_CCC91 0 /* ai length mark */ |
| 251 |
| 252 /* Thai |
128 * | 253 * |
129 * 2028 LINE SEPARATOR | 254 * Modify U+0E38 and U+0E39 (ccc=103) to be reordered before U+0E3A (ccc=9). |
130 * | 255 * Assign 3, which is unassigned otherwise. |
131 * 202A LEFT-TO-RIGHT EMBEDDING | 256 * Uniscribe does this reordering too. |
132 * 202B RIGHT-TO-LEFT EMBEDDING | |
133 * 202C POP DIRECTIONAL FORMATTING | |
134 * 202D LEFT-TO-RIGHT OVERRIDE | |
135 * 202E RIGHT-TO-LEFT OVERRIDE | |
136 * | |
137 * 2060 WORD JOINER | |
138 * 2061 FUNCTION APPLICATION | |
139 * 2062 INVISIBLE TIMES | |
140 * 2063 INVISIBLE SEPARATOR | |
141 * | |
142 * FEFF ZERO WIDTH NO-BREAK SPACE | |
143 */ | 257 */ |
144 static inline hb_bool_t | 258 #define HB_MODIFIED_COMBINING_CLASS_CCC103 3 /* sara u / sara uu */ |
145 _hb_unicode_is_zero_width (hb_codepoint_t ch) | 259 #define HB_MODIFIED_COMBINING_CLASS_CCC107 107 /* mai * */ |
146 { | 260 |
147 return ((ch & ~0x007F) == 0x2000 && ( | 261 /* Lao */ |
148 » (ch >= 0x200B && ch <= 0x200F) || | 262 #define HB_MODIFIED_COMBINING_CLASS_CCC118 118 /* sign u / sign uu */ |
149 » (ch >= 0x202A && ch <= 0x202E) || | 263 #define HB_MODIFIED_COMBINING_CLASS_CCC122 122 /* mai * */ |
150 » (ch >= 0x2060 && ch <= 0x2063) || | 264 |
151 » (ch == 0x2028) | 265 /* Tibetan */ |
152 » )) || unlikely (ch == 0x0009 | 266 #define HB_MODIFIED_COMBINING_CLASS_CCC129 129 /* sign aa */ |
153 » » || ch == 0x00AD | 267 #define HB_MODIFIED_COMBINING_CLASS_CCC130 130 /* sign i */ |
154 » » || ch == 0x034F | 268 #define HB_MODIFIED_COMBINING_CLASS_CCC132 132 /* sign u */ |
155 » » || ch == 0xFEFF); | 269 |
156 } | 270 |
| 271 /* Misc */ |
| 272 |
| 273 #define HB_UNICODE_GENERAL_CATEGORY_IS_MARK(gen_cat) \ |
| 274 » (FLAG (gen_cat) & \ |
| 275 » (FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) | \ |
| 276 » FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | \ |
| 277 » FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK))) |
| 278 |
157 | 279 |
158 #endif /* HB_UNICODE_PRIVATE_HH */ | 280 #endif /* HB_UNICODE_PRIVATE_HH */ |
OLD | NEW |