Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright © 2011,2012,2013 Google, Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * This is part of HarfBuzz, a text shaping library. |
michael@0 | 5 | * |
michael@0 | 6 | * Permission is hereby granted, without written agreement and without |
michael@0 | 7 | * license or royalty fees, to use, copy, modify, and distribute this |
michael@0 | 8 | * software and its documentation for any purpose, provided that the |
michael@0 | 9 | * above copyright notice and the following two paragraphs appear in |
michael@0 | 10 | * all copies of this software. |
michael@0 | 11 | * |
michael@0 | 12 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
michael@0 | 13 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
michael@0 | 14 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
michael@0 | 15 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
michael@0 | 16 | * DAMAGE. |
michael@0 | 17 | * |
michael@0 | 18 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
michael@0 | 19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
michael@0 | 20 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
michael@0 | 21 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
michael@0 | 22 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
michael@0 | 23 | * |
michael@0 | 24 | * Google Author(s): Behdad Esfahbod |
michael@0 | 25 | */ |
michael@0 | 26 | |
michael@0 | 27 | #include "hb-ot-shape-complex-indic-private.hh" |
michael@0 | 28 | |
michael@0 | 29 | /* buffer var allocations */ |
michael@0 | 30 | #define myanmar_category() complex_var_u8_0() /* myanmar_category_t */ |
michael@0 | 31 | #define myanmar_position() complex_var_u8_1() /* myanmar_position_t */ |
michael@0 | 32 | |
michael@0 | 33 | |
michael@0 | 34 | /* |
michael@0 | 35 | * Myanmar shaper. |
michael@0 | 36 | */ |
michael@0 | 37 | |
michael@0 | 38 | static const hb_tag_t |
michael@0 | 39 | basic_features[] = |
michael@0 | 40 | { |
michael@0 | 41 | /* |
michael@0 | 42 | * Basic features. |
michael@0 | 43 | * These features are applied in order, one at a time, after initial_reordering. |
michael@0 | 44 | */ |
michael@0 | 45 | HB_TAG('r','p','h','f'), |
michael@0 | 46 | HB_TAG('p','r','e','f'), |
michael@0 | 47 | HB_TAG('b','l','w','f'), |
michael@0 | 48 | HB_TAG('p','s','t','f'), |
michael@0 | 49 | }; |
michael@0 | 50 | static const hb_tag_t |
michael@0 | 51 | other_features[] = |
michael@0 | 52 | { |
michael@0 | 53 | /* |
michael@0 | 54 | * Other features. |
michael@0 | 55 | * These features are applied all at once, after final_reordering. |
michael@0 | 56 | */ |
michael@0 | 57 | HB_TAG('p','r','e','s'), |
michael@0 | 58 | HB_TAG('a','b','v','s'), |
michael@0 | 59 | HB_TAG('b','l','w','s'), |
michael@0 | 60 | HB_TAG('p','s','t','s'), |
michael@0 | 61 | /* Positioning features, though we don't care about the types. */ |
michael@0 | 62 | HB_TAG('d','i','s','t'), |
michael@0 | 63 | /* Pre-release version of Windows 8 Myanmar font had abvm,blwm |
michael@0 | 64 | * features. The released Windows 8 version of the font (as well |
michael@0 | 65 | * as the released spec) used 'mark' instead. The Windows 8 |
michael@0 | 66 | * shaper however didn't apply 'mark' but did apply 'mkmk'. |
michael@0 | 67 | * Perhaps it applied abvm/blwm. This was fixed in a Windows 8 |
michael@0 | 68 | * update, so now it applies mark/mkmk. We are guessing that |
michael@0 | 69 | * it still applies abvm/blwm too. |
michael@0 | 70 | */ |
michael@0 | 71 | HB_TAG('a','b','v','m'), |
michael@0 | 72 | HB_TAG('b','l','w','m'), |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | static void |
michael@0 | 76 | setup_syllables (const hb_ot_shape_plan_t *plan, |
michael@0 | 77 | hb_font_t *font, |
michael@0 | 78 | hb_buffer_t *buffer); |
michael@0 | 79 | static void |
michael@0 | 80 | initial_reordering (const hb_ot_shape_plan_t *plan, |
michael@0 | 81 | hb_font_t *font, |
michael@0 | 82 | hb_buffer_t *buffer); |
michael@0 | 83 | static void |
michael@0 | 84 | final_reordering (const hb_ot_shape_plan_t *plan, |
michael@0 | 85 | hb_font_t *font, |
michael@0 | 86 | hb_buffer_t *buffer); |
michael@0 | 87 | |
michael@0 | 88 | static void |
michael@0 | 89 | collect_features_myanmar (hb_ot_shape_planner_t *plan) |
michael@0 | 90 | { |
michael@0 | 91 | hb_ot_map_builder_t *map = &plan->map; |
michael@0 | 92 | |
michael@0 | 93 | /* Do this before any lookups have been applied. */ |
michael@0 | 94 | map->add_gsub_pause (setup_syllables); |
michael@0 | 95 | |
michael@0 | 96 | map->add_global_bool_feature (HB_TAG('l','o','c','l')); |
michael@0 | 97 | /* The Indic specs do not require ccmp, but we apply it here since if |
michael@0 | 98 | * there is a use of it, it's typically at the beginning. */ |
michael@0 | 99 | map->add_global_bool_feature (HB_TAG('c','c','m','p')); |
michael@0 | 100 | |
michael@0 | 101 | |
michael@0 | 102 | map->add_gsub_pause (initial_reordering); |
michael@0 | 103 | for (unsigned int i = 0; i < ARRAY_LENGTH (basic_features); i++) |
michael@0 | 104 | { |
michael@0 | 105 | map->add_feature (basic_features[i], 1, F_GLOBAL | F_MANUAL_ZWJ); |
michael@0 | 106 | map->add_gsub_pause (NULL); |
michael@0 | 107 | } |
michael@0 | 108 | map->add_gsub_pause (final_reordering); |
michael@0 | 109 | for (unsigned int i = 0; i < ARRAY_LENGTH (other_features); i++) |
michael@0 | 110 | map->add_feature (other_features[i], 1, F_GLOBAL | F_MANUAL_ZWJ); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | static void |
michael@0 | 114 | override_features_myanmar (hb_ot_shape_planner_t *plan) |
michael@0 | 115 | { |
michael@0 | 116 | plan->map.add_feature (HB_TAG('l','i','g','a'), 0, F_GLOBAL); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | |
michael@0 | 120 | enum syllable_type_t { |
michael@0 | 121 | consonant_syllable, |
michael@0 | 122 | punctuation_cluster, |
michael@0 | 123 | broken_cluster, |
michael@0 | 124 | non_myanmar_cluster, |
michael@0 | 125 | }; |
michael@0 | 126 | |
michael@0 | 127 | #include "hb-ot-shape-complex-myanmar-machine.hh" |
michael@0 | 128 | |
michael@0 | 129 | |
michael@0 | 130 | /* Note: This enum is duplicated in the -machine.rl source file. |
michael@0 | 131 | * Not sure how to avoid duplication. */ |
michael@0 | 132 | enum myanmar_category_t { |
michael@0 | 133 | OT_As = 18, /* Asat */ |
michael@0 | 134 | OT_D = 19, /* Digits except zero */ |
michael@0 | 135 | OT_D0 = 20, /* Digit zero */ |
michael@0 | 136 | OT_DB = OT_N, /* Dot below */ |
michael@0 | 137 | OT_GB = OT_DOTTEDCIRCLE, |
michael@0 | 138 | OT_MH = 21, /* Various consonant medial types */ |
michael@0 | 139 | OT_MR = 22, /* Various consonant medial types */ |
michael@0 | 140 | OT_MW = 23, /* Various consonant medial types */ |
michael@0 | 141 | OT_MY = 24, /* Various consonant medial types */ |
michael@0 | 142 | OT_PT = 25, /* Pwo and other tones */ |
michael@0 | 143 | OT_VAbv = 26, |
michael@0 | 144 | OT_VBlw = 27, |
michael@0 | 145 | OT_VPre = 28, |
michael@0 | 146 | OT_VPst = 29, |
michael@0 | 147 | OT_VS = 30, /* Variation selectors */ |
michael@0 | 148 | OT_P = 31 /* Punctuation */ |
michael@0 | 149 | }; |
michael@0 | 150 | |
michael@0 | 151 | |
michael@0 | 152 | static inline bool |
michael@0 | 153 | is_one_of (const hb_glyph_info_t &info, unsigned int flags) |
michael@0 | 154 | { |
michael@0 | 155 | /* If it ligated, all bets are off. */ |
michael@0 | 156 | if (_hb_glyph_info_ligated (&info)) return false; |
michael@0 | 157 | return !!(FLAG (info.myanmar_category()) & flags); |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | /* Note: |
michael@0 | 161 | * |
michael@0 | 162 | * We treat Vowels and placeholders as if they were consonants. This is safe because Vowels |
michael@0 | 163 | * cannot happen in a consonant syllable. The plus side however is, we can call the |
michael@0 | 164 | * consonant syllable logic from the vowel syllable function and get it all right! */ |
michael@0 | 165 | #define CONSONANT_FLAGS (FLAG (OT_C) | FLAG (OT_CM) | FLAG (OT_Ra) | FLAG (OT_V) | FLAG (OT_NBSP) | FLAG (OT_GB)) |
michael@0 | 166 | static inline bool |
michael@0 | 167 | is_consonant (const hb_glyph_info_t &info) |
michael@0 | 168 | { |
michael@0 | 169 | return is_one_of (info, CONSONANT_FLAGS); |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | |
michael@0 | 173 | static inline void |
michael@0 | 174 | set_myanmar_properties (hb_glyph_info_t &info) |
michael@0 | 175 | { |
michael@0 | 176 | hb_codepoint_t u = info.codepoint; |
michael@0 | 177 | unsigned int type = hb_indic_get_categories (u); |
michael@0 | 178 | indic_category_t cat = (indic_category_t) (type & 0x7F); |
michael@0 | 179 | indic_position_t pos = (indic_position_t) (type >> 8); |
michael@0 | 180 | |
michael@0 | 181 | /* Myanmar |
michael@0 | 182 | * http://www.microsoft.com/typography/OpenTypeDev/myanmar/intro.htm#analyze |
michael@0 | 183 | */ |
michael@0 | 184 | if (unlikely (hb_in_range<hb_codepoint_t> (u, 0xFE00, 0xFE0F))) |
michael@0 | 185 | cat = (indic_category_t) OT_VS; |
michael@0 | 186 | else if (unlikely (u == 0x200C)) cat = (indic_category_t) OT_ZWNJ; |
michael@0 | 187 | else if (unlikely (u == 0x200D)) cat = (indic_category_t) OT_ZWJ; |
michael@0 | 188 | |
michael@0 | 189 | switch (u) |
michael@0 | 190 | { |
michael@0 | 191 | case 0x104E: |
michael@0 | 192 | cat = (indic_category_t) OT_C; /* The spec says C, IndicSyllableCategory doesn't have. */ |
michael@0 | 193 | break; |
michael@0 | 194 | |
michael@0 | 195 | case 0x002D: case 0x00A0: case 0x00D7: case 0x2012: |
michael@0 | 196 | case 0x2013: case 0x2014: case 0x2015: case 0x2022: |
michael@0 | 197 | case 0x25CC: case 0x25FB: case 0x25FC: case 0x25FD: |
michael@0 | 198 | case 0x25FE: |
michael@0 | 199 | cat = (indic_category_t) OT_GB; |
michael@0 | 200 | break; |
michael@0 | 201 | |
michael@0 | 202 | case 0x1004: case 0x101B: case 0x105A: |
michael@0 | 203 | cat = (indic_category_t) OT_Ra; |
michael@0 | 204 | break; |
michael@0 | 205 | |
michael@0 | 206 | case 0x1032: case 0x1036: |
michael@0 | 207 | cat = (indic_category_t) OT_A; |
michael@0 | 208 | break; |
michael@0 | 209 | |
michael@0 | 210 | case 0x103A: |
michael@0 | 211 | cat = (indic_category_t) OT_As; |
michael@0 | 212 | break; |
michael@0 | 213 | |
michael@0 | 214 | case 0x1041: case 0x1042: case 0x1043: case 0x1044: |
michael@0 | 215 | case 0x1045: case 0x1046: case 0x1047: case 0x1048: |
michael@0 | 216 | case 0x1049: case 0x1090: case 0x1091: case 0x1092: |
michael@0 | 217 | case 0x1093: case 0x1094: case 0x1095: case 0x1096: |
michael@0 | 218 | case 0x1097: case 0x1098: case 0x1099: |
michael@0 | 219 | cat = (indic_category_t) OT_D; |
michael@0 | 220 | break; |
michael@0 | 221 | |
michael@0 | 222 | case 0x1040: |
michael@0 | 223 | cat = (indic_category_t) OT_D; /* XXX The spec says D0, but Uniscribe doesn't seem to do. */ |
michael@0 | 224 | break; |
michael@0 | 225 | |
michael@0 | 226 | case 0x103E: case 0x1060: |
michael@0 | 227 | cat = (indic_category_t) OT_MH; |
michael@0 | 228 | break; |
michael@0 | 229 | |
michael@0 | 230 | case 0x103C: |
michael@0 | 231 | cat = (indic_category_t) OT_MR; |
michael@0 | 232 | break; |
michael@0 | 233 | |
michael@0 | 234 | case 0x103D: case 0x1082: |
michael@0 | 235 | cat = (indic_category_t) OT_MW; |
michael@0 | 236 | break; |
michael@0 | 237 | |
michael@0 | 238 | case 0x103B: case 0x105E: case 0x105F: |
michael@0 | 239 | cat = (indic_category_t) OT_MY; |
michael@0 | 240 | break; |
michael@0 | 241 | |
michael@0 | 242 | case 0x1063: case 0x1064: case 0x1069: case 0x106A: |
michael@0 | 243 | case 0x106B: case 0x106C: case 0x106D: case 0xAA7B: |
michael@0 | 244 | cat = (indic_category_t) OT_PT; |
michael@0 | 245 | break; |
michael@0 | 246 | |
michael@0 | 247 | case 0x1038: case 0x1087: case 0x1088: case 0x1089: |
michael@0 | 248 | case 0x108A: case 0x108B: case 0x108C: case 0x108D: |
michael@0 | 249 | case 0x108F: case 0x109A: case 0x109B: case 0x109C: |
michael@0 | 250 | cat = (indic_category_t) OT_SM; |
michael@0 | 251 | break; |
michael@0 | 252 | |
michael@0 | 253 | case 0x104A: case 0x104B: |
michael@0 | 254 | cat = (indic_category_t) OT_P; |
michael@0 | 255 | break; |
michael@0 | 256 | } |
michael@0 | 257 | |
michael@0 | 258 | if (cat == OT_M) |
michael@0 | 259 | { |
michael@0 | 260 | switch ((int) pos) |
michael@0 | 261 | { |
michael@0 | 262 | case POS_PRE_C: cat = (indic_category_t) OT_VPre; |
michael@0 | 263 | pos = POS_PRE_M; break; |
michael@0 | 264 | case POS_ABOVE_C: cat = (indic_category_t) OT_VAbv; break; |
michael@0 | 265 | case POS_BELOW_C: cat = (indic_category_t) OT_VBlw; break; |
michael@0 | 266 | case POS_POST_C: cat = (indic_category_t) OT_VPst; break; |
michael@0 | 267 | } |
michael@0 | 268 | } |
michael@0 | 269 | |
michael@0 | 270 | info.myanmar_category() = (myanmar_category_t) cat; |
michael@0 | 271 | info.myanmar_position() = pos; |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | |
michael@0 | 275 | |
michael@0 | 276 | static void |
michael@0 | 277 | setup_masks_myanmar (const hb_ot_shape_plan_t *plan HB_UNUSED, |
michael@0 | 278 | hb_buffer_t *buffer, |
michael@0 | 279 | hb_font_t *font HB_UNUSED) |
michael@0 | 280 | { |
michael@0 | 281 | HB_BUFFER_ALLOCATE_VAR (buffer, myanmar_category); |
michael@0 | 282 | HB_BUFFER_ALLOCATE_VAR (buffer, myanmar_position); |
michael@0 | 283 | |
michael@0 | 284 | /* We cannot setup masks here. We save information about characters |
michael@0 | 285 | * and setup masks later on in a pause-callback. */ |
michael@0 | 286 | |
michael@0 | 287 | unsigned int count = buffer->len; |
michael@0 | 288 | for (unsigned int i = 0; i < count; i++) |
michael@0 | 289 | set_myanmar_properties (buffer->info[i]); |
michael@0 | 290 | } |
michael@0 | 291 | |
michael@0 | 292 | static void |
michael@0 | 293 | setup_syllables (const hb_ot_shape_plan_t *plan HB_UNUSED, |
michael@0 | 294 | hb_font_t *font HB_UNUSED, |
michael@0 | 295 | hb_buffer_t *buffer) |
michael@0 | 296 | { |
michael@0 | 297 | find_syllables (buffer); |
michael@0 | 298 | } |
michael@0 | 299 | |
michael@0 | 300 | static int |
michael@0 | 301 | compare_myanmar_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) |
michael@0 | 302 | { |
michael@0 | 303 | int a = pa->myanmar_position(); |
michael@0 | 304 | int b = pb->myanmar_position(); |
michael@0 | 305 | |
michael@0 | 306 | return a < b ? -1 : a == b ? 0 : +1; |
michael@0 | 307 | } |
michael@0 | 308 | |
michael@0 | 309 | |
michael@0 | 310 | /* Rules from: |
michael@0 | 311 | * http://www.microsoft.com/typography/OpenTypeDev/myanmar/intro.htm */ |
michael@0 | 312 | |
michael@0 | 313 | static void |
michael@0 | 314 | initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan, |
michael@0 | 315 | hb_face_t *face, |
michael@0 | 316 | hb_buffer_t *buffer, |
michael@0 | 317 | unsigned int start, unsigned int end) |
michael@0 | 318 | { |
michael@0 | 319 | hb_glyph_info_t *info = buffer->info; |
michael@0 | 320 | |
michael@0 | 321 | unsigned int base = end; |
michael@0 | 322 | bool has_reph = false; |
michael@0 | 323 | |
michael@0 | 324 | { |
michael@0 | 325 | unsigned int limit = start; |
michael@0 | 326 | if (start + 3 <= end && |
michael@0 | 327 | info[start ].myanmar_category() == OT_Ra && |
michael@0 | 328 | info[start+1].myanmar_category() == OT_As && |
michael@0 | 329 | info[start+2].myanmar_category() == OT_H) |
michael@0 | 330 | { |
michael@0 | 331 | limit += 3; |
michael@0 | 332 | base = start; |
michael@0 | 333 | has_reph = true; |
michael@0 | 334 | } |
michael@0 | 335 | |
michael@0 | 336 | { |
michael@0 | 337 | if (!has_reph) |
michael@0 | 338 | base = limit; |
michael@0 | 339 | |
michael@0 | 340 | for (unsigned int i = limit; i < end; i++) |
michael@0 | 341 | if (is_consonant (info[i])) |
michael@0 | 342 | { |
michael@0 | 343 | base = i; |
michael@0 | 344 | break; |
michael@0 | 345 | } |
michael@0 | 346 | } |
michael@0 | 347 | } |
michael@0 | 348 | |
michael@0 | 349 | /* Reorder! */ |
michael@0 | 350 | { |
michael@0 | 351 | unsigned int i = start; |
michael@0 | 352 | for (; i < start + (has_reph ? 3 : 0); i++) |
michael@0 | 353 | info[i].myanmar_position() = POS_AFTER_MAIN; |
michael@0 | 354 | for (; i < base; i++) |
michael@0 | 355 | info[i].myanmar_position() = POS_PRE_C; |
michael@0 | 356 | if (i < end) |
michael@0 | 357 | { |
michael@0 | 358 | info[i].myanmar_position() = POS_BASE_C; |
michael@0 | 359 | i++; |
michael@0 | 360 | } |
michael@0 | 361 | indic_position_t pos = POS_AFTER_MAIN; |
michael@0 | 362 | /* The following loop may be ugly, but it implements all of |
michael@0 | 363 | * Myanmar reordering! */ |
michael@0 | 364 | for (; i < end; i++) |
michael@0 | 365 | { |
michael@0 | 366 | if (info[i].myanmar_category() == OT_MR) /* Pre-base reordering */ |
michael@0 | 367 | { |
michael@0 | 368 | info[i].myanmar_position() = POS_PRE_C; |
michael@0 | 369 | continue; |
michael@0 | 370 | } |
michael@0 | 371 | if (info[i].myanmar_position() < POS_BASE_C) /* Left matra */ |
michael@0 | 372 | { |
michael@0 | 373 | continue; |
michael@0 | 374 | } |
michael@0 | 375 | |
michael@0 | 376 | if (pos == POS_AFTER_MAIN && info[i].myanmar_category() == OT_VBlw) |
michael@0 | 377 | { |
michael@0 | 378 | pos = POS_BELOW_C; |
michael@0 | 379 | info[i].myanmar_position() = pos; |
michael@0 | 380 | continue; |
michael@0 | 381 | } |
michael@0 | 382 | |
michael@0 | 383 | if (pos == POS_BELOW_C && info[i].myanmar_category() == OT_A) |
michael@0 | 384 | { |
michael@0 | 385 | info[i].myanmar_position() = POS_BEFORE_SUB; |
michael@0 | 386 | continue; |
michael@0 | 387 | } |
michael@0 | 388 | if (pos == POS_BELOW_C && info[i].myanmar_category() == OT_VBlw) |
michael@0 | 389 | { |
michael@0 | 390 | info[i].myanmar_position() = pos; |
michael@0 | 391 | continue; |
michael@0 | 392 | } |
michael@0 | 393 | if (pos == POS_BELOW_C && info[i].myanmar_category() != OT_A) |
michael@0 | 394 | { |
michael@0 | 395 | pos = POS_AFTER_SUB; |
michael@0 | 396 | info[i].myanmar_position() = pos; |
michael@0 | 397 | continue; |
michael@0 | 398 | } |
michael@0 | 399 | info[i].myanmar_position() = pos; |
michael@0 | 400 | } |
michael@0 | 401 | } |
michael@0 | 402 | |
michael@0 | 403 | buffer->merge_clusters (start, end); |
michael@0 | 404 | /* Sit tight, rock 'n roll! */ |
michael@0 | 405 | hb_bubble_sort (info + start, end - start, compare_myanmar_order); |
michael@0 | 406 | } |
michael@0 | 407 | |
michael@0 | 408 | static void |
michael@0 | 409 | initial_reordering_broken_cluster (const hb_ot_shape_plan_t *plan, |
michael@0 | 410 | hb_face_t *face, |
michael@0 | 411 | hb_buffer_t *buffer, |
michael@0 | 412 | unsigned int start, unsigned int end) |
michael@0 | 413 | { |
michael@0 | 414 | /* We already inserted dotted-circles, so just call the consonant_syllable. */ |
michael@0 | 415 | initial_reordering_consonant_syllable (plan, face, buffer, start, end); |
michael@0 | 416 | } |
michael@0 | 417 | |
michael@0 | 418 | static void |
michael@0 | 419 | initial_reordering_punctuation_cluster (const hb_ot_shape_plan_t *plan HB_UNUSED, |
michael@0 | 420 | hb_face_t *face HB_UNUSED, |
michael@0 | 421 | hb_buffer_t *buffer HB_UNUSED, |
michael@0 | 422 | unsigned int start HB_UNUSED, unsigned int end HB_UNUSED) |
michael@0 | 423 | { |
michael@0 | 424 | /* Nothing to do right now. If we ever switch to using the output |
michael@0 | 425 | * buffer in the reordering process, we'd need to next_glyph() here. */ |
michael@0 | 426 | } |
michael@0 | 427 | |
michael@0 | 428 | static void |
michael@0 | 429 | initial_reordering_non_myanmar_cluster (const hb_ot_shape_plan_t *plan HB_UNUSED, |
michael@0 | 430 | hb_face_t *face HB_UNUSED, |
michael@0 | 431 | hb_buffer_t *buffer HB_UNUSED, |
michael@0 | 432 | unsigned int start HB_UNUSED, unsigned int end HB_UNUSED) |
michael@0 | 433 | { |
michael@0 | 434 | /* Nothing to do right now. If we ever switch to using the output |
michael@0 | 435 | * buffer in the reordering process, we'd need to next_glyph() here. */ |
michael@0 | 436 | } |
michael@0 | 437 | |
michael@0 | 438 | |
michael@0 | 439 | static void |
michael@0 | 440 | initial_reordering_syllable (const hb_ot_shape_plan_t *plan, |
michael@0 | 441 | hb_face_t *face, |
michael@0 | 442 | hb_buffer_t *buffer, |
michael@0 | 443 | unsigned int start, unsigned int end) |
michael@0 | 444 | { |
michael@0 | 445 | syllable_type_t syllable_type = (syllable_type_t) (buffer->info[start].syllable() & 0x0F); |
michael@0 | 446 | switch (syllable_type) { |
michael@0 | 447 | case consonant_syllable: initial_reordering_consonant_syllable (plan, face, buffer, start, end); return; |
michael@0 | 448 | case punctuation_cluster: initial_reordering_punctuation_cluster (plan, face, buffer, start, end); return; |
michael@0 | 449 | case broken_cluster: initial_reordering_broken_cluster (plan, face, buffer, start, end); return; |
michael@0 | 450 | case non_myanmar_cluster: initial_reordering_non_myanmar_cluster (plan, face, buffer, start, end); return; |
michael@0 | 451 | } |
michael@0 | 452 | } |
michael@0 | 453 | |
michael@0 | 454 | static inline void |
michael@0 | 455 | insert_dotted_circles (const hb_ot_shape_plan_t *plan HB_UNUSED, |
michael@0 | 456 | hb_font_t *font, |
michael@0 | 457 | hb_buffer_t *buffer) |
michael@0 | 458 | { |
michael@0 | 459 | /* Note: This loop is extra overhead, but should not be measurable. */ |
michael@0 | 460 | bool has_broken_syllables = false; |
michael@0 | 461 | unsigned int count = buffer->len; |
michael@0 | 462 | for (unsigned int i = 0; i < count; i++) |
michael@0 | 463 | if ((buffer->info[i].syllable() & 0x0F) == broken_cluster) { |
michael@0 | 464 | has_broken_syllables = true; |
michael@0 | 465 | break; |
michael@0 | 466 | } |
michael@0 | 467 | if (likely (!has_broken_syllables)) |
michael@0 | 468 | return; |
michael@0 | 469 | |
michael@0 | 470 | |
michael@0 | 471 | hb_codepoint_t dottedcircle_glyph; |
michael@0 | 472 | if (!font->get_glyph (0x25CC, 0, &dottedcircle_glyph)) |
michael@0 | 473 | return; |
michael@0 | 474 | |
michael@0 | 475 | hb_glyph_info_t dottedcircle = {0}; |
michael@0 | 476 | dottedcircle.codepoint = 0x25CC; |
michael@0 | 477 | set_myanmar_properties (dottedcircle); |
michael@0 | 478 | dottedcircle.codepoint = dottedcircle_glyph; |
michael@0 | 479 | |
michael@0 | 480 | buffer->clear_output (); |
michael@0 | 481 | |
michael@0 | 482 | buffer->idx = 0; |
michael@0 | 483 | unsigned int last_syllable = 0; |
michael@0 | 484 | while (buffer->idx < buffer->len) |
michael@0 | 485 | { |
michael@0 | 486 | unsigned int syllable = buffer->cur().syllable(); |
michael@0 | 487 | syllable_type_t syllable_type = (syllable_type_t) (syllable & 0x0F); |
michael@0 | 488 | if (unlikely (last_syllable != syllable && syllable_type == broken_cluster)) |
michael@0 | 489 | { |
michael@0 | 490 | last_syllable = syllable; |
michael@0 | 491 | |
michael@0 | 492 | hb_glyph_info_t info = dottedcircle; |
michael@0 | 493 | info.cluster = buffer->cur().cluster; |
michael@0 | 494 | info.mask = buffer->cur().mask; |
michael@0 | 495 | info.syllable() = buffer->cur().syllable(); |
michael@0 | 496 | |
michael@0 | 497 | buffer->output_info (info); |
michael@0 | 498 | } |
michael@0 | 499 | else |
michael@0 | 500 | buffer->next_glyph (); |
michael@0 | 501 | } |
michael@0 | 502 | |
michael@0 | 503 | buffer->swap_buffers (); |
michael@0 | 504 | } |
michael@0 | 505 | |
michael@0 | 506 | static void |
michael@0 | 507 | initial_reordering (const hb_ot_shape_plan_t *plan, |
michael@0 | 508 | hb_font_t *font, |
michael@0 | 509 | hb_buffer_t *buffer) |
michael@0 | 510 | { |
michael@0 | 511 | insert_dotted_circles (plan, font, buffer); |
michael@0 | 512 | |
michael@0 | 513 | hb_glyph_info_t *info = buffer->info; |
michael@0 | 514 | unsigned int count = buffer->len; |
michael@0 | 515 | if (unlikely (!count)) return; |
michael@0 | 516 | unsigned int last = 0; |
michael@0 | 517 | unsigned int last_syllable = info[0].syllable(); |
michael@0 | 518 | for (unsigned int i = 1; i < count; i++) |
michael@0 | 519 | if (last_syllable != info[i].syllable()) { |
michael@0 | 520 | initial_reordering_syllable (plan, font->face, buffer, last, i); |
michael@0 | 521 | last = i; |
michael@0 | 522 | last_syllable = info[last].syllable(); |
michael@0 | 523 | } |
michael@0 | 524 | initial_reordering_syllable (plan, font->face, buffer, last, count); |
michael@0 | 525 | } |
michael@0 | 526 | |
michael@0 | 527 | static void |
michael@0 | 528 | final_reordering (const hb_ot_shape_plan_t *plan, |
michael@0 | 529 | hb_font_t *font HB_UNUSED, |
michael@0 | 530 | hb_buffer_t *buffer) |
michael@0 | 531 | { |
michael@0 | 532 | hb_glyph_info_t *info = buffer->info; |
michael@0 | 533 | unsigned int count = buffer->len; |
michael@0 | 534 | |
michael@0 | 535 | /* Zero syllables now... */ |
michael@0 | 536 | for (unsigned int i = 0; i < count; i++) |
michael@0 | 537 | info[i].syllable() = 0; |
michael@0 | 538 | |
michael@0 | 539 | HB_BUFFER_DEALLOCATE_VAR (buffer, myanmar_category); |
michael@0 | 540 | HB_BUFFER_DEALLOCATE_VAR (buffer, myanmar_position); |
michael@0 | 541 | } |
michael@0 | 542 | |
michael@0 | 543 | |
michael@0 | 544 | const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar = |
michael@0 | 545 | { |
michael@0 | 546 | "myanmar", |
michael@0 | 547 | collect_features_myanmar, |
michael@0 | 548 | override_features_myanmar, |
michael@0 | 549 | NULL, /* data_create */ |
michael@0 | 550 | NULL, /* data_destroy */ |
michael@0 | 551 | NULL, /* preprocess_text */ |
michael@0 | 552 | HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT, |
michael@0 | 553 | NULL, /* decompose */ |
michael@0 | 554 | NULL, /* compose */ |
michael@0 | 555 | setup_masks_myanmar, |
michael@0 | 556 | HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY, |
michael@0 | 557 | false, /* fallback_position */ |
michael@0 | 558 | }; |