86 hb_buffer_t *buffer); 87 88 static void 89 collect_features_myanmar (hb_ot_shape_planner_t *plan) 90 { 91 hb_ot_map_builder_t *map = &plan->map; 92 93 /* Do this before any lookups have been applied. */ 94 map->add_gsub_pause (setup_syllables); 95 96 map->add_global_bool_feature (HB_TAG('l','o','c','l')); 97 /* The Indic specs do not require ccmp, but we apply it here since if 98 * there is a use of it, it's typically at the beginning. */ 99 map->add_global_bool_feature (HB_TAG('c','c','m','p')); 100 101 102 map->add_gsub_pause (initial_reordering); 103 for (unsigned int i = 0; i < ARRAY_LENGTH (basic_features); i++) 104 { 105 map->add_feature (basic_features[i], 1, F_GLOBAL | F_MANUAL_ZWJ); 106 map->add_gsub_pause (NULL); 107 } 108 map->add_gsub_pause (final_reordering); 109 for (unsigned int i = 0; i < ARRAY_LENGTH (other_features); i++) 110 map->add_feature (other_features[i], 1, F_GLOBAL | F_MANUAL_ZWJ); 111 } 112 113 static void 114 override_features_myanmar (hb_ot_shape_planner_t *plan) 115 { 116 plan->map.add_feature (HB_TAG('l','i','g','a'), 0, F_GLOBAL); 117 } 118 119 120 enum syllable_type_t { 121 consonant_syllable, 122 punctuation_cluster, 123 broken_cluster, 124 non_myanmar_cluster, 125 }; 126 127 #include "hb-ot-shape-complex-myanmar-machine.hh" 128 129 130 /* Note: This enum is duplicated in the -machine.rl source file. 131 * Not sure how to avoid duplication. */ 132 enum myanmar_category_t { 133 OT_As = 18, /* Asat */ 134 OT_D = 19, /* Digits except zero */ 135 OT_D0 = 20, /* Digit zero */ 136 OT_DB = OT_N, /* Dot below */ 137 OT_GB = OT_PLACEHOLDER, 138 OT_MH = 21, /* Various consonant medial types */ 139 OT_MR = 22, /* Various consonant medial types */ 140 OT_MW = 23, /* Various consonant medial types */ 141 OT_MY = 24, /* Various consonant medial types */ 142 OT_PT = 25, /* Pwo and other tones */ 143 OT_VAbv = 26, 144 OT_VBlw = 27, 145 OT_VPre = 28, 146 OT_VPst = 29, 147 OT_VS = 30, /* Variation selectors */ 148 OT_P = 31 /* Punctuation */ 149 }; 150 151 152 static inline bool 153 is_one_of (const hb_glyph_info_t &info, unsigned int flags) 154 { 155 /* If it ligated, all bets are off. */ 156 if (_hb_glyph_info_ligated (&info)) return false; 157 return !!(FLAG_SAFE (info.myanmar_category()) & flags); 158 } 159 160 static inline bool 161 is_consonant (const hb_glyph_info_t &info) 162 { 163 return is_one_of (info, CONSONANT_FLAGS); 164 } 165 166 167 static inline void 168 set_myanmar_properties (hb_glyph_info_t &info) 169 { 170 hb_codepoint_t u = info.codepoint; 171 unsigned int type = hb_indic_get_categories (u); 172 indic_category_t cat = (indic_category_t) (type & 0x7Fu); 173 indic_position_t pos = (indic_position_t) (type >> 8); 174 175 /* Myanmar 176 * http://www.microsoft.com/typography/OpenTypeDev/myanmar/intro.htm#analyze 177 */ 178 if (unlikely (hb_in_range (u, 0xFE00u, 0xFE0Fu))) 179 cat = (indic_category_t) OT_VS; 180 181 switch (u) 182 { 183 case 0x104Eu: 184 cat = (indic_category_t) OT_C; /* The spec says C, IndicSyllableCategory doesn't have. */ 185 break; 186 187 case 0x002Du: case 0x00A0u: case 0x00D7u: case 0x2012u: 188 case 0x2013u: case 0x2014u: case 0x2015u: case 0x2022u: 189 case 0x25CCu: case 0x25FBu: case 0x25FCu: case 0x25FDu: 190 case 0x25FEu: 191 cat = (indic_category_t) OT_GB; 192 break; 193 194 case 0x1004u: case 0x101Bu: case 0x105Au: 195 cat = (indic_category_t) OT_Ra; 196 break; 197 198 case 0x1032u: case 0x1036u: 280 hb_font_t *font HB_UNUSED) 281 { 282 HB_BUFFER_ALLOCATE_VAR (buffer, myanmar_category); 283 HB_BUFFER_ALLOCATE_VAR (buffer, myanmar_position); 284 285 /* We cannot setup masks here. We save information about characters 286 * and setup masks later on in a pause-callback. */ 287 288 unsigned int count = buffer->len; 289 hb_glyph_info_t *info = buffer->info; 290 for (unsigned int i = 0; i < count; i++) 291 set_myanmar_properties (info[i]); 292 } 293 294 static void 295 setup_syllables (const hb_ot_shape_plan_t *plan HB_UNUSED, 296 hb_font_t *font HB_UNUSED, 297 hb_buffer_t *buffer) 298 { 299 find_syllables (buffer); 300 } 301 302 static int 303 compare_myanmar_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) 304 { 305 int a = pa->myanmar_position(); 306 int b = pb->myanmar_position(); 307 308 return a < b ? -1 : a == b ? 0 : +1; 309 } 310 311 312 /* Rules from: 313 * http://www.microsoft.com/typography/OpenTypeDev/myanmar/intro.htm */ 314 315 static void 316 initial_reordering_consonant_syllable (hb_buffer_t *buffer, 317 unsigned int start, unsigned int end) 318 { 319 hb_glyph_info_t *info = buffer->info; 493 final_reordering (const hb_ot_shape_plan_t *plan, 494 hb_font_t *font HB_UNUSED, 495 hb_buffer_t *buffer) 496 { 497 hb_glyph_info_t *info = buffer->info; 498 unsigned int count = buffer->len; 499 500 /* Zero syllables now... */ 501 for (unsigned int i = 0; i < count; i++) 502 info[i].syllable() = 0; 503 504 HB_BUFFER_DEALLOCATE_VAR (buffer, myanmar_category); 505 HB_BUFFER_DEALLOCATE_VAR (buffer, myanmar_position); 506 } 507 508 509 /* Uniscribe seems to have a shaper for 'mymr' that is like the 510 * generic shaper, except that it zeros mark advances GDEF_LATE. */ 511 const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar_old = 512 { 513 "default", 514 NULL, /* collect_features */ 515 NULL, /* override_features */ 516 NULL, /* data_create */ 517 NULL, /* data_destroy */ 518 NULL, /* preprocess_text */ 519 NULL, /* postprocess_glyphs */ 520 HB_OT_SHAPE_NORMALIZATION_MODE_DEFAULT, 521 NULL, /* decompose */ 522 NULL, /* compose */ 523 NULL, /* setup_masks */ 524 NULL, /* disable_otl */ 525 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE, 526 true, /* fallback_position */ 527 }; 528 529 const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar = 530 { 531 "myanmar", 532 collect_features_myanmar, 533 override_features_myanmar, 534 NULL, /* data_create */ 535 NULL, /* data_destroy */ 536 NULL, /* preprocess_text */ 537 NULL, /* postprocess_glyphs */ 538 HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT, 539 NULL, /* decompose */ 540 NULL, /* compose */ 541 setup_masks_myanmar, 542 NULL, /* disable_otl */ 543 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY, 544 false, /* fallback_position */ 545 }; | 86 hb_buffer_t *buffer); 87 88 static void 89 collect_features_myanmar (hb_ot_shape_planner_t *plan) 90 { 91 hb_ot_map_builder_t *map = &plan->map; 92 93 /* Do this before any lookups have been applied. */ 94 map->add_gsub_pause (setup_syllables); 95 96 map->add_global_bool_feature (HB_TAG('l','o','c','l')); 97 /* The Indic specs do not require ccmp, but we apply it here since if 98 * there is a use of it, it's typically at the beginning. */ 99 map->add_global_bool_feature (HB_TAG('c','c','m','p')); 100 101 102 map->add_gsub_pause (initial_reordering); 103 for (unsigned int i = 0; i < ARRAY_LENGTH (basic_features); i++) 104 { 105 map->add_feature (basic_features[i], 1, F_GLOBAL | F_MANUAL_ZWJ); 106 map->add_gsub_pause (nullptr); 107 } 108 map->add_gsub_pause (final_reordering); 109 for (unsigned int i = 0; i < ARRAY_LENGTH (other_features); i++) 110 map->add_feature (other_features[i], 1, F_GLOBAL | F_MANUAL_ZWJ); 111 } 112 113 static void 114 override_features_myanmar (hb_ot_shape_planner_t *plan) 115 { 116 plan->map.add_feature (HB_TAG('l','i','g','a'), 0, F_GLOBAL); 117 } 118 119 120 enum syllable_type_t { 121 consonant_syllable, 122 punctuation_cluster, 123 broken_cluster, 124 non_myanmar_cluster, 125 }; 126 127 #include "hb-ot-shape-complex-myanmar-machine.hh" 128 129 130 /* Note: This enum is duplicated in the -machine.rl source file. 131 * Not sure how to avoid duplication. */ 132 enum myanmar_category_t { 133 OT_As = 18, /* Asat */ 134 OT_D0 = 20, /* Digit zero */ 135 OT_DB = OT_N, /* Dot below */ 136 OT_GB = OT_PLACEHOLDER, 137 OT_MH = 21, /* Various consonant medial types */ 138 OT_MR = 22, /* Various consonant medial types */ 139 OT_MW = 23, /* Various consonant medial types */ 140 OT_MY = 24, /* Various consonant medial types */ 141 OT_PT = 25, /* Pwo and other tones */ 142 OT_VAbv = 26, 143 OT_VBlw = 27, 144 OT_VPre = 28, 145 OT_VPst = 29, 146 OT_VS = 30, /* Variation selectors */ 147 OT_P = 31, /* Punctuation */ 148 OT_D = 32, /* Digits except zero */ 149 }; 150 151 152 static inline bool 153 is_one_of (const hb_glyph_info_t &info, unsigned int flags) 154 { 155 /* If it ligated, all bets are off. */ 156 if (_hb_glyph_info_ligated (&info)) return false; 157 return !!(FLAG_UNSAFE (info.myanmar_category()) & flags); 158 } 159 160 static inline bool 161 is_consonant (const hb_glyph_info_t &info) 162 { 163 return is_one_of (info, CONSONANT_FLAGS); 164 } 165 166 167 static inline void 168 set_myanmar_properties (hb_glyph_info_t &info) 169 { 170 hb_codepoint_t u = info.codepoint; 171 unsigned int type = hb_indic_get_categories (u); 172 indic_category_t cat = (indic_category_t) (type & 0x7Fu); 173 indic_position_t pos = (indic_position_t) (type >> 8); 174 175 /* Myanmar 176 * http://www.microsoft.com/typography/OpenTypeDev/myanmar/intro.htm#analyze 177 */ 178 if (unlikely (hb_in_range<hb_codepoint_t> (u, 0xFE00u, 0xFE0Fu))) 179 cat = (indic_category_t) OT_VS; 180 181 switch (u) 182 { 183 case 0x104Eu: 184 cat = (indic_category_t) OT_C; /* The spec says C, IndicSyllableCategory doesn't have. */ 185 break; 186 187 case 0x002Du: case 0x00A0u: case 0x00D7u: case 0x2012u: 188 case 0x2013u: case 0x2014u: case 0x2015u: case 0x2022u: 189 case 0x25CCu: case 0x25FBu: case 0x25FCu: case 0x25FDu: 190 case 0x25FEu: 191 cat = (indic_category_t) OT_GB; 192 break; 193 194 case 0x1004u: case 0x101Bu: case 0x105Au: 195 cat = (indic_category_t) OT_Ra; 196 break; 197 198 case 0x1032u: case 0x1036u: 280 hb_font_t *font HB_UNUSED) 281 { 282 HB_BUFFER_ALLOCATE_VAR (buffer, myanmar_category); 283 HB_BUFFER_ALLOCATE_VAR (buffer, myanmar_position); 284 285 /* We cannot setup masks here. We save information about characters 286 * and setup masks later on in a pause-callback. */ 287 288 unsigned int count = buffer->len; 289 hb_glyph_info_t *info = buffer->info; 290 for (unsigned int i = 0; i < count; i++) 291 set_myanmar_properties (info[i]); 292 } 293 294 static void 295 setup_syllables (const hb_ot_shape_plan_t *plan HB_UNUSED, 296 hb_font_t *font HB_UNUSED, 297 hb_buffer_t *buffer) 298 { 299 find_syllables (buffer); 300 foreach_syllable (buffer, start, end) 301 buffer->unsafe_to_break (start, end); 302 } 303 304 static int 305 compare_myanmar_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) 306 { 307 int a = pa->myanmar_position(); 308 int b = pb->myanmar_position(); 309 310 return a < b ? -1 : a == b ? 0 : +1; 311 } 312 313 314 /* Rules from: 315 * http://www.microsoft.com/typography/OpenTypeDev/myanmar/intro.htm */ 316 317 static void 318 initial_reordering_consonant_syllable (hb_buffer_t *buffer, 319 unsigned int start, unsigned int end) 320 { 321 hb_glyph_info_t *info = buffer->info; 495 final_reordering (const hb_ot_shape_plan_t *plan, 496 hb_font_t *font HB_UNUSED, 497 hb_buffer_t *buffer) 498 { 499 hb_glyph_info_t *info = buffer->info; 500 unsigned int count = buffer->len; 501 502 /* Zero syllables now... */ 503 for (unsigned int i = 0; i < count; i++) 504 info[i].syllable() = 0; 505 506 HB_BUFFER_DEALLOCATE_VAR (buffer, myanmar_category); 507 HB_BUFFER_DEALLOCATE_VAR (buffer, myanmar_position); 508 } 509 510 511 /* Uniscribe seems to have a shaper for 'mymr' that is like the 512 * generic shaper, except that it zeros mark advances GDEF_LATE. */ 513 const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar_old = 514 { 515 nullptr, /* collect_features */ 516 nullptr, /* override_features */ 517 nullptr, /* data_create */ 518 nullptr, /* data_destroy */ 519 nullptr, /* preprocess_text */ 520 nullptr, /* postprocess_glyphs */ 521 HB_OT_SHAPE_NORMALIZATION_MODE_DEFAULT, 522 nullptr, /* decompose */ 523 nullptr, /* compose */ 524 nullptr, /* setup_masks */ 525 nullptr, /* disable_otl */ 526 nullptr, /* reorder_marks */ 527 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE, 528 true, /* fallback_position */ 529 }; 530 531 const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar = 532 { 533 collect_features_myanmar, 534 override_features_myanmar, 535 nullptr, /* data_create */ 536 nullptr, /* data_destroy */ 537 nullptr, /* preprocess_text */ 538 nullptr, /* postprocess_glyphs */ 539 HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT, 540 nullptr, /* decompose */ 541 nullptr, /* compose */ 542 setup_masks_myanmar, 543 nullptr, /* disable_otl */ 544 nullptr, /* reorder_marks */ 545 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY, 546 false, /* fallback_position */ 547 }; |