Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright © 2009 Red Hat, Inc. |
michael@0 | 3 | * Copyright © 2011 Codethink Limited |
michael@0 | 4 | * Copyright © 2010,2011,2012 Google, Inc. |
michael@0 | 5 | * |
michael@0 | 6 | * This is part of HarfBuzz, a text shaping library. |
michael@0 | 7 | * |
michael@0 | 8 | * Permission is hereby granted, without written agreement and without |
michael@0 | 9 | * license or royalty fees, to use, copy, modify, and distribute this |
michael@0 | 10 | * software and its documentation for any purpose, provided that the |
michael@0 | 11 | * above copyright notice and the following two paragraphs appear in |
michael@0 | 12 | * all copies of this software. |
michael@0 | 13 | * |
michael@0 | 14 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
michael@0 | 15 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
michael@0 | 16 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
michael@0 | 17 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
michael@0 | 18 | * DAMAGE. |
michael@0 | 19 | * |
michael@0 | 20 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
michael@0 | 21 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
michael@0 | 22 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
michael@0 | 23 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
michael@0 | 24 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
michael@0 | 25 | * |
michael@0 | 26 | * Red Hat Author(s): Behdad Esfahbod |
michael@0 | 27 | * Codethink Author(s): Ryan Lortie |
michael@0 | 28 | * Google Author(s): Behdad Esfahbod |
michael@0 | 29 | */ |
michael@0 | 30 | |
michael@0 | 31 | #ifndef HB_UNICODE_PRIVATE_HH |
michael@0 | 32 | #define HB_UNICODE_PRIVATE_HH |
michael@0 | 33 | |
michael@0 | 34 | #include "hb-private.hh" |
michael@0 | 35 | #include "hb-object-private.hh" |
michael@0 | 36 | |
michael@0 | 37 | |
michael@0 | 38 | extern HB_INTERNAL const uint8_t _hb_modified_combining_class[256]; |
michael@0 | 39 | |
michael@0 | 40 | /* |
michael@0 | 41 | * hb_unicode_funcs_t |
michael@0 | 42 | */ |
michael@0 | 43 | |
michael@0 | 44 | #define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS \ |
michael@0 | 45 | HB_UNICODE_FUNC_IMPLEMENT (combining_class) \ |
michael@0 | 46 | HB_UNICODE_FUNC_IMPLEMENT (eastasian_width) \ |
michael@0 | 47 | HB_UNICODE_FUNC_IMPLEMENT (general_category) \ |
michael@0 | 48 | HB_UNICODE_FUNC_IMPLEMENT (mirroring) \ |
michael@0 | 49 | HB_UNICODE_FUNC_IMPLEMENT (script) \ |
michael@0 | 50 | HB_UNICODE_FUNC_IMPLEMENT (compose) \ |
michael@0 | 51 | HB_UNICODE_FUNC_IMPLEMENT (decompose) \ |
michael@0 | 52 | HB_UNICODE_FUNC_IMPLEMENT (decompose_compatibility) \ |
michael@0 | 53 | /* ^--- Add new callbacks here */ |
michael@0 | 54 | |
michael@0 | 55 | /* Simple callbacks are those taking a hb_codepoint_t and returning a hb_codepoint_t */ |
michael@0 | 56 | #define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE \ |
michael@0 | 57 | HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_combining_class_t, combining_class) \ |
michael@0 | 58 | HB_UNICODE_FUNC_IMPLEMENT (unsigned int, eastasian_width) \ |
michael@0 | 59 | HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_general_category_t, general_category) \ |
michael@0 | 60 | HB_UNICODE_FUNC_IMPLEMENT (hb_codepoint_t, mirroring) \ |
michael@0 | 61 | HB_UNICODE_FUNC_IMPLEMENT (hb_script_t, script) \ |
michael@0 | 62 | /* ^--- Add new simple callbacks here */ |
michael@0 | 63 | |
michael@0 | 64 | struct hb_unicode_funcs_t { |
michael@0 | 65 | hb_object_header_t header; |
michael@0 | 66 | ASSERT_POD (); |
michael@0 | 67 | |
michael@0 | 68 | hb_unicode_funcs_t *parent; |
michael@0 | 69 | |
michael@0 | 70 | bool immutable; |
michael@0 | 71 | |
michael@0 | 72 | #define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \ |
michael@0 | 73 | inline return_type name (hb_codepoint_t unicode) { return func.name (this, unicode, user_data.name); } |
michael@0 | 74 | HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE |
michael@0 | 75 | #undef HB_UNICODE_FUNC_IMPLEMENT |
michael@0 | 76 | |
michael@0 | 77 | inline hb_bool_t compose (hb_codepoint_t a, hb_codepoint_t b, |
michael@0 | 78 | hb_codepoint_t *ab) |
michael@0 | 79 | { |
michael@0 | 80 | *ab = 0; |
michael@0 | 81 | if (unlikely (!a || !b)) return false; |
michael@0 | 82 | return func.compose (this, a, b, ab, user_data.compose); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | inline hb_bool_t decompose (hb_codepoint_t ab, |
michael@0 | 86 | hb_codepoint_t *a, hb_codepoint_t *b) |
michael@0 | 87 | { |
michael@0 | 88 | *a = ab; *b = 0; |
michael@0 | 89 | return func.decompose (this, ab, a, b, user_data.decompose); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | inline unsigned int decompose_compatibility (hb_codepoint_t u, |
michael@0 | 93 | hb_codepoint_t *decomposed) |
michael@0 | 94 | { |
michael@0 | 95 | unsigned int ret = func.decompose_compatibility (this, u, decomposed, user_data.decompose_compatibility); |
michael@0 | 96 | if (ret == 1 && u == decomposed[0]) { |
michael@0 | 97 | decomposed[0] = 0; |
michael@0 | 98 | return 0; |
michael@0 | 99 | } |
michael@0 | 100 | decomposed[ret] = 0; |
michael@0 | 101 | return ret; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | |
michael@0 | 105 | unsigned int |
michael@0 | 106 | modified_combining_class (hb_codepoint_t unicode) |
michael@0 | 107 | { |
michael@0 | 108 | /* XXX This hack belongs to the Myanmar shaper. */ |
michael@0 | 109 | if (unlikely (unicode == 0x1037)) unicode = 0x103A; |
michael@0 | 110 | |
michael@0 | 111 | /* XXX This hack belongs to the SEA shaper (for Tai Tham): |
michael@0 | 112 | * Reorder SAKOT to ensure it comes after any tone marks. */ |
michael@0 | 113 | if (unlikely (unicode == 0x1A60)) return 254; |
michael@0 | 114 | |
michael@0 | 115 | return _hb_modified_combining_class[combining_class (unicode)]; |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | inline hb_bool_t |
michael@0 | 119 | is_variation_selector (hb_codepoint_t unicode) |
michael@0 | 120 | { |
michael@0 | 121 | return unlikely (hb_in_ranges<hb_codepoint_t> (unicode, |
michael@0 | 122 | 0x180B, 0x180D, /* MONGOLIAN FREE VARIATION SELECTOR ONE..THREE */ |
michael@0 | 123 | 0xFE00, 0xFE0F, /* VARIATION SELECTOR-1..16 */ |
michael@0 | 124 | 0xE0100, 0xE01EF)); /* VARIATION SELECTOR-17..256 */ |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | /* Default_Ignorable codepoints: |
michael@0 | 128 | * |
michael@0 | 129 | * Note that as of Oct 2012 (Unicode 6.2), U+180E MONGOLIAN VOWEL SEPARATOR |
michael@0 | 130 | * is NOT Default_Ignorable, but it really behaves in a way that it should |
michael@0 | 131 | * be. That has been reported to the Unicode Technical Committee for |
michael@0 | 132 | * consideration. As such, we include it here, since Uniscribe removes it. |
michael@0 | 133 | * It *is* in Unicode 6.3 however. U+061C ARABIC LETTER MARK from Unicode |
michael@0 | 134 | * 6.3 is also added manually. The new Unicode 6.3 bidi formatting |
michael@0 | 135 | * characters are encoded in a block that was Default_Ignorable already. |
michael@0 | 136 | * |
michael@0 | 137 | * Note: While U+115F, U+1160, U+3164 and U+FFA0 are Default_Ignorable, |
michael@0 | 138 | * we do NOT want to hide them, as the way Uniscribe has implemented them |
michael@0 | 139 | * is with regular spacing glyphs, and that's the way fonts are made to work. |
michael@0 | 140 | * As such, we make exceptions for those four. |
michael@0 | 141 | * |
michael@0 | 142 | * Gathered from: |
michael@0 | 143 | * http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:DI:]&abb=on&ucd=on&esc=on |
michael@0 | 144 | * |
michael@0 | 145 | * Last updated to the page with the following versions: |
michael@0 | 146 | * Version 3.6; ICU version: 50.0.1.0; Unicode version: 6.1.0.0 |
michael@0 | 147 | * |
michael@0 | 148 | * 4,167 Code Points |
michael@0 | 149 | * |
michael@0 | 150 | * [\u00AD\u034F\u115F\u1160\u17B4\u17B5\u180B-\u180D\u200B-\u200F\u202A-\u202E\u2060-\u206F\u3164\uFE00-\uFE0F\uFEFF\uFFA0\uFFF0-\uFFF8\U0001D173-\U0001D17A\U000E0000-\U000E0FFF] |
michael@0 | 151 | * |
michael@0 | 152 | * 00AD ;SOFT HYPHEN |
michael@0 | 153 | * 034F ;COMBINING GRAPHEME JOINER |
michael@0 | 154 | * #115F ;HANGUL CHOSEONG FILLER |
michael@0 | 155 | * #1160 ;HANGUL JUNGSEONG FILLER |
michael@0 | 156 | * 17B4 ;KHMER VOWEL INHERENT AQ |
michael@0 | 157 | * 17B5 ;KHMER VOWEL INHERENT AA |
michael@0 | 158 | * 180B..180D ;MONGOLIAN FREE VARIATION SELECTOR THREE |
michael@0 | 159 | * 200B..200F ;RIGHT-TO-LEFT MARK |
michael@0 | 160 | * 202A..202E ;RIGHT-TO-LEFT OVERRIDE |
michael@0 | 161 | * 2060..206F ;NOMINAL DIGIT SHAPES |
michael@0 | 162 | * #3164 ;HANGUL FILLER |
michael@0 | 163 | * FE00..FE0F ;VARIATION SELECTOR-16 |
michael@0 | 164 | * FEFF ;ZERO WIDTH NO-BREAK SPACE |
michael@0 | 165 | * #FFA0 ;HALFWIDTH HANGUL FILLER |
michael@0 | 166 | * FFF0..FFF8 ;<unassigned-FFF8> |
michael@0 | 167 | * 1D173..1D17A ;MUSICAL SYMBOL END PHRASE |
michael@0 | 168 | * E0000..E0FFF ;<unassigned-E0FFF> |
michael@0 | 169 | */ |
michael@0 | 170 | inline hb_bool_t |
michael@0 | 171 | is_default_ignorable (hb_codepoint_t ch) |
michael@0 | 172 | { |
michael@0 | 173 | hb_codepoint_t plane = ch >> 16; |
michael@0 | 174 | if (likely (plane == 0)) |
michael@0 | 175 | { |
michael@0 | 176 | /* BMP */ |
michael@0 | 177 | hb_codepoint_t page = ch >> 8; |
michael@0 | 178 | switch (page) { |
michael@0 | 179 | case 0x00: return unlikely (ch == 0x00AD); |
michael@0 | 180 | case 0x03: return unlikely (ch == 0x034F); |
michael@0 | 181 | case 0x06: return unlikely (ch == 0x061C); |
michael@0 | 182 | case 0x17: return hb_in_range<hb_codepoint_t> (ch, 0x17B4, 0x17B5); |
michael@0 | 183 | case 0x18: return hb_in_range<hb_codepoint_t> (ch, 0x180B, 0x180E); |
michael@0 | 184 | case 0x20: return hb_in_ranges<hb_codepoint_t> (ch, 0x200B, 0x200F, |
michael@0 | 185 | 0x202A, 0x202E, |
michael@0 | 186 | 0x2060, 0x206F); |
michael@0 | 187 | case 0xFE: return hb_in_range<hb_codepoint_t> (ch, 0xFE00, 0xFE0F) || ch == 0xFEFF; |
michael@0 | 188 | case 0xFF: return hb_in_range<hb_codepoint_t> (ch, 0xFFF0, 0xFFF8); |
michael@0 | 189 | default: return false; |
michael@0 | 190 | } |
michael@0 | 191 | } |
michael@0 | 192 | else |
michael@0 | 193 | { |
michael@0 | 194 | /* Other planes */ |
michael@0 | 195 | switch (plane) { |
michael@0 | 196 | case 0x01: return hb_in_range<hb_codepoint_t> (ch, 0x0001D173, 0x0001D17A); |
michael@0 | 197 | case 0x0E: return hb_in_range<hb_codepoint_t> (ch, 0x000E0000, 0x000E0FFF); |
michael@0 | 198 | default: return false; |
michael@0 | 199 | } |
michael@0 | 200 | } |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | |
michael@0 | 204 | struct { |
michael@0 | 205 | #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_func_t name; |
michael@0 | 206 | HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS |
michael@0 | 207 | #undef HB_UNICODE_FUNC_IMPLEMENT |
michael@0 | 208 | } func; |
michael@0 | 209 | |
michael@0 | 210 | struct { |
michael@0 | 211 | #define HB_UNICODE_FUNC_IMPLEMENT(name) void *name; |
michael@0 | 212 | HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS |
michael@0 | 213 | #undef HB_UNICODE_FUNC_IMPLEMENT |
michael@0 | 214 | } user_data; |
michael@0 | 215 | |
michael@0 | 216 | struct { |
michael@0 | 217 | #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_destroy_func_t name; |
michael@0 | 218 | HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS |
michael@0 | 219 | #undef HB_UNICODE_FUNC_IMPLEMENT |
michael@0 | 220 | } destroy; |
michael@0 | 221 | }; |
michael@0 | 222 | |
michael@0 | 223 | |
michael@0 | 224 | extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil; |
michael@0 | 225 | |
michael@0 | 226 | |
michael@0 | 227 | /* Modified combining marks */ |
michael@0 | 228 | |
michael@0 | 229 | /* Hebrew |
michael@0 | 230 | * |
michael@0 | 231 | * We permute the "fixed-position" classes 10-26 into the order |
michael@0 | 232 | * described in the SBL Hebrew manual: |
michael@0 | 233 | * |
michael@0 | 234 | * http://www.sbl-site.org/Fonts/SBLHebrewUserManual1.5x.pdf |
michael@0 | 235 | * |
michael@0 | 236 | * (as recommended by: |
michael@0 | 237 | * http://forum.fontlab.com/archive-old-microsoft-volt-group/vista-and-diacritic-ordering-t6751.0.html) |
michael@0 | 238 | * |
michael@0 | 239 | * More details here: |
michael@0 | 240 | * https://bugzilla.mozilla.org/show_bug.cgi?id=662055 |
michael@0 | 241 | */ |
michael@0 | 242 | #define HB_MODIFIED_COMBINING_CLASS_CCC10 22 /* sheva */ |
michael@0 | 243 | #define HB_MODIFIED_COMBINING_CLASS_CCC11 15 /* hataf segol */ |
michael@0 | 244 | #define HB_MODIFIED_COMBINING_CLASS_CCC12 16 /* hataf patah */ |
michael@0 | 245 | #define HB_MODIFIED_COMBINING_CLASS_CCC13 17 /* hataf qamats */ |
michael@0 | 246 | #define HB_MODIFIED_COMBINING_CLASS_CCC14 23 /* hiriq */ |
michael@0 | 247 | #define HB_MODIFIED_COMBINING_CLASS_CCC15 18 /* tsere */ |
michael@0 | 248 | #define HB_MODIFIED_COMBINING_CLASS_CCC16 19 /* segol */ |
michael@0 | 249 | #define HB_MODIFIED_COMBINING_CLASS_CCC17 20 /* patah */ |
michael@0 | 250 | #define HB_MODIFIED_COMBINING_CLASS_CCC18 21 /* qamats */ |
michael@0 | 251 | #define HB_MODIFIED_COMBINING_CLASS_CCC19 14 /* holam */ |
michael@0 | 252 | #define HB_MODIFIED_COMBINING_CLASS_CCC20 24 /* qubuts */ |
michael@0 | 253 | #define HB_MODIFIED_COMBINING_CLASS_CCC21 12 /* dagesh */ |
michael@0 | 254 | #define HB_MODIFIED_COMBINING_CLASS_CCC22 25 /* meteg */ |
michael@0 | 255 | #define HB_MODIFIED_COMBINING_CLASS_CCC23 13 /* rafe */ |
michael@0 | 256 | #define HB_MODIFIED_COMBINING_CLASS_CCC24 10 /* shin dot */ |
michael@0 | 257 | #define HB_MODIFIED_COMBINING_CLASS_CCC25 11 /* sin dot */ |
michael@0 | 258 | #define HB_MODIFIED_COMBINING_CLASS_CCC26 26 /* point varika */ |
michael@0 | 259 | |
michael@0 | 260 | /* |
michael@0 | 261 | * Arabic |
michael@0 | 262 | * |
michael@0 | 263 | * Modify to move Shadda (ccc=33) before other marks. See: |
michael@0 | 264 | * http://unicode.org/faq/normalization.html#8 |
michael@0 | 265 | * http://unicode.org/faq/normalization.html#9 |
michael@0 | 266 | */ |
michael@0 | 267 | #define HB_MODIFIED_COMBINING_CLASS_CCC27 28 /* fathatan */ |
michael@0 | 268 | #define HB_MODIFIED_COMBINING_CLASS_CCC28 29 /* dammatan */ |
michael@0 | 269 | #define HB_MODIFIED_COMBINING_CLASS_CCC29 30 /* kasratan */ |
michael@0 | 270 | #define HB_MODIFIED_COMBINING_CLASS_CCC30 31 /* fatha */ |
michael@0 | 271 | #define HB_MODIFIED_COMBINING_CLASS_CCC31 32 /* damma */ |
michael@0 | 272 | #define HB_MODIFIED_COMBINING_CLASS_CCC32 33 /* kasra */ |
michael@0 | 273 | #define HB_MODIFIED_COMBINING_CLASS_CCC33 27 /* shadda */ |
michael@0 | 274 | #define HB_MODIFIED_COMBINING_CLASS_CCC34 34 /* sukun */ |
michael@0 | 275 | #define HB_MODIFIED_COMBINING_CLASS_CCC35 35 /* superscript alef */ |
michael@0 | 276 | |
michael@0 | 277 | /* Syriac */ |
michael@0 | 278 | #define HB_MODIFIED_COMBINING_CLASS_CCC36 36 /* superscript alaph */ |
michael@0 | 279 | |
michael@0 | 280 | /* Telugu |
michael@0 | 281 | * |
michael@0 | 282 | * Modify Telugu length marks (ccc=84, ccc=91). |
michael@0 | 283 | * These are the only matras in the main Indic scripts range that have |
michael@0 | 284 | * a non-zero ccc. That makes them reorder with the Halant that is |
michael@0 | 285 | * ccc=9. Just zero them, we don't need them in our Indic shaper. |
michael@0 | 286 | */ |
michael@0 | 287 | #define HB_MODIFIED_COMBINING_CLASS_CCC84 0 /* length mark */ |
michael@0 | 288 | #define HB_MODIFIED_COMBINING_CLASS_CCC91 0 /* ai length mark */ |
michael@0 | 289 | |
michael@0 | 290 | /* Thai |
michael@0 | 291 | * |
michael@0 | 292 | * Modify U+0E38 and U+0E39 (ccc=103) to be reordered before U+0E3A (ccc=9). |
michael@0 | 293 | * Assign 3, which is unassigned otherwise. |
michael@0 | 294 | * Uniscribe does this reordering too. |
michael@0 | 295 | */ |
michael@0 | 296 | #define HB_MODIFIED_COMBINING_CLASS_CCC103 3 /* sara u / sara uu */ |
michael@0 | 297 | #define HB_MODIFIED_COMBINING_CLASS_CCC107 107 /* mai * */ |
michael@0 | 298 | |
michael@0 | 299 | /* Lao */ |
michael@0 | 300 | #define HB_MODIFIED_COMBINING_CLASS_CCC118 118 /* sign u / sign uu */ |
michael@0 | 301 | #define HB_MODIFIED_COMBINING_CLASS_CCC122 122 /* mai * */ |
michael@0 | 302 | |
michael@0 | 303 | /* Tibetan */ |
michael@0 | 304 | #define HB_MODIFIED_COMBINING_CLASS_CCC129 129 /* sign aa */ |
michael@0 | 305 | #define HB_MODIFIED_COMBINING_CLASS_CCC130 130 /* sign i */ |
michael@0 | 306 | #define HB_MODIFIED_COMBINING_CLASS_CCC132 132 /* sign u */ |
michael@0 | 307 | |
michael@0 | 308 | |
michael@0 | 309 | /* Misc */ |
michael@0 | 310 | |
michael@0 | 311 | #define HB_UNICODE_GENERAL_CATEGORY_IS_MARK(gen_cat) \ |
michael@0 | 312 | (FLAG (gen_cat) & \ |
michael@0 | 313 | (FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) | \ |
michael@0 | 314 | FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | \ |
michael@0 | 315 | FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK))) |
michael@0 | 316 | |
michael@0 | 317 | |
michael@0 | 318 | #endif /* HB_UNICODE_PRIVATE_HH */ |