hb-ot-shape-complex-indic.cc revision 9f377ed3210fe7d9f15e0c4f82020556f9a8f6f0
1b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod/* 220503ccd578c9983162857954e3236413469ed35Behdad Esfahbod * Copyright © 2011 Google, Inc. 3b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * 4b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * This is part of HarfBuzz, a text shaping library. 5b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * 6b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * Permission is hereby granted, without written agreement and without 7b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this 8b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * software and its documentation for any purpose, provided that the 9b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * above copyright notice and the following two paragraphs appear in 10b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * all copies of this software. 11b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * 12b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 13b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 14b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 15b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 16b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * DAMAGE. 17b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * 18b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 19b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 21b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 22b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 23b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * 24b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod * Google Author(s): Behdad Esfahbod 25b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod */ 26b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 273ed4634ec349fa9e943ad23718c04be4dd4bba62Behdad Esfahbod#include "hb-ot-shape-complex-indic-private.hh" 28a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod#include "hb-ot-shape-private.hh" 29352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod 30ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbodstatic const struct indic_options_t 31ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod{ 32ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod indic_options_t (void) 33ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod { 34ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod char *c = getenv ("HB_OT_INDIC_OPTIONS"); 35ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod uniscribe_bug_compatible = c && strstr (c, "uniscribe-bug-compatible"); 36ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod } 37ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod 38ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod bool uniscribe_bug_compatible; 39ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod} options; 40ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod 41743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic int 42743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodcompare_codepoint (const void *pa, const void *pb) 43743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 44743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_codepoint_t a = * (hb_codepoint_t *) pa; 45743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_codepoint_t b = * (hb_codepoint_t *) pb; 46743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 47743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod return a < b ? -1 : a == b ? 0 : +1; 48743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 49743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 50743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic indic_position_t 51743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodconsonant_position (hb_codepoint_t u) 52743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 53743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod consonant_position_t *record; 54743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 55743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod record = (consonant_position_t *) bsearch (&u, consonant_positions, 56743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod ARRAY_LENGTH (consonant_positions), 57743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod sizeof (consonant_positions[0]), 58743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod compare_codepoint); 59743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 60dbccf87eef0d26838fa4bb3ae26410f6c4818836Behdad Esfahbod return record ? record->position : POS_BASE_C; 61743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 62743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 63352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbodstatic bool 64352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbodis_ra (hb_codepoint_t u) 65352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod{ 66352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod return !!bsearch (&u, ra_chars, 67352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod ARRAY_LENGTH (ra_chars), 68352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod sizeof (ra_chars[0]), 69352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod compare_codepoint); 70352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod} 71352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod 729ee27a928a989c71923cef82a9e9828f8e9ca051Behdad Esfahbodstatic bool 739da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodis_joiner (const hb_glyph_info_t &info) 749ee27a928a989c71923cef82a9e9828f8e9ca051Behdad Esfahbod{ 759da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod return !!(FLAG (info.indic_category()) & (FLAG (OT_ZWJ) | FLAG (OT_ZWNJ))); 769da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod} 779da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod 789da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodstatic bool 799da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodis_consonant (const hb_glyph_info_t &info) 809da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod{ 811a1fa8c655a082fc1439608457ba717306cc83caBehdad Esfahbod /* Note: 821a1fa8c655a082fc1439608457ba717306cc83caBehdad Esfahbod * 8318c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod * We treat Vowels and placeholders as if they were consonants. This is safe because Vowels 84c5306b6861cfaa50af40e8ceb058791fa06d7981Behdad Esfahbod * cannot happen in a consonant syllable. The plus side however is, we can call the 85c5306b6861cfaa50af40e8ceb058791fa06d7981Behdad Esfahbod * consonant syllable logic from the vowel syllable function and get it all right! */ 8618c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod return !!(FLAG (info.indic_category()) & (FLAG (OT_C) | FLAG (OT_Ra) | FLAG (OT_V) | FLAG (OT_NBSP) | FLAG (OT_DOTTEDCIRCLE))); 879ee27a928a989c71923cef82a9e9828f8e9ca051Behdad Esfahbod} 88c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod 89eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbodstruct feature_list_t { 90c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod hb_tag_t tag; 91c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod hb_bool_t is_global; 92eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod}; 93eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod 94eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbodstatic const feature_list_t 95eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbodindic_basic_features[] = 96b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{ 97c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('n','u','k','t'), true}, 98c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('a','k','h','n'), false}, 99c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('r','p','h','f'), false}, 1001ac075b227090a9ad930dcc1670236c176b27067Behdad Esfahbod {HB_TAG('r','k','r','f'), true}, 101c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('p','r','e','f'), false}, 102c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('b','l','w','f'), false}, 103c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('h','a','l','f'), false}, 104c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('v','a','t','u'), true}, 105c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('p','s','t','f'), false}, 1069da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod {HB_TAG('c','j','c','t'), false}, 107c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod}; 108c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod 109c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod/* Same order as the indic_basic_features array */ 110c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbodenum { 111c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod _NUKT, 112c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod AKHN, 113c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod RPHF, 114df6d45c693c417bf311e6fa49f18a8558542e525Behdad Esfahbod _RKRF, 115c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod PREF, 116c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod BLWF, 117c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod HALF, 118c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod _VATU, 119c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod PSTF, 120e8eedf2687f05372bf5476e84139d01ba67c9f73Behdad Esfahbod CJCT 121b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod}; 122b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 123eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbodstatic const feature_list_t 124eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbodindic_other_features[] = 125b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{ 126eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod {HB_TAG('i','n','i','t'), false}, 127eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod {HB_TAG('p','r','e','s'), true}, 128eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod {HB_TAG('a','b','v','s'), true}, 129eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod {HB_TAG('b','l','w','s'), true}, 130eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod {HB_TAG('p','s','t','s'), true}, 131eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod {HB_TAG('h','a','l','n'), true}, 132eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod 133eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod {HB_TAG('d','i','s','t'), true}, 134eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod {HB_TAG('a','b','v','m'), true}, 135eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod {HB_TAG('b','l','w','m'), true}, 136eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod}; 137eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod 138eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod/* Same order as the indic_other_features array */ 139eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbodenum { 140eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod INIT 141b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod}; 142b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 143743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 144743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 145743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodinitial_reordering (const hb_ot_map_t *map, 146743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_face_t *face, 147743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_buffer_t *buffer, 148743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod void *user_data HB_UNUSED); 149f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbodstatic void 150f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbodfinal_reordering (const hb_ot_map_t *map, 151f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod hb_face_t *face, 152f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod hb_buffer_t *buffer, 153743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod void *user_data HB_UNUSED); 154b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 155b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodvoid 1569f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod_hb_ot_shape_complex_collect_features_indic (hb_ot_map_builder_t *map, 1579f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod const hb_segment_properties_t *props HB_UNUSED) 158b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{ 159f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod map->add_bool_feature (HB_TAG('l','o','c','l')); 160a54a5505a35eef5315a8e2e7a79502901e3eff5fBehdad Esfahbod /* The Indic specs do not require ccmp, but we apply it here since if 161a54a5505a35eef5315a8e2e7a79502901e3eff5fBehdad Esfahbod * there is a use of it, it's typically at the beginning. */ 162f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod map->add_bool_feature (HB_TAG('c','c','m','p')); 163f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod 164743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod map->add_gsub_pause (initial_reordering, NULL); 165f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod 166412b91889d9a1ae477e8b6907d0b9a76e78a6c91Behdad Esfahbod for (unsigned int i = 0; i < ARRAY_LENGTH (indic_basic_features); i++) { 16776f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod map->add_bool_feature (indic_basic_features[i].tag, indic_basic_features[i].is_global); 168412b91889d9a1ae477e8b6907d0b9a76e78a6c91Behdad Esfahbod map->add_gsub_pause (NULL, NULL); 169412b91889d9a1ae477e8b6907d0b9a76e78a6c91Behdad Esfahbod } 170b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 171f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod map->add_gsub_pause (final_reordering, NULL); 172f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod 173412b91889d9a1ae477e8b6907d0b9a76e78a6c91Behdad Esfahbod for (unsigned int i = 0; i < ARRAY_LENGTH (indic_other_features); i++) { 174eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod map->add_bool_feature (indic_other_features[i].tag, indic_other_features[i].is_global); 175412b91889d9a1ae477e8b6907d0b9a76e78a6c91Behdad Esfahbod map->add_gsub_pause (NULL, NULL); 176412b91889d9a1ae477e8b6907d0b9a76e78a6c91Behdad Esfahbod } 177b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod} 178b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 179867361c3ad39629a8d5b7dc48d558a1c19e37d43Behdad Esfahbod 18011138ccff71f442da1fcf64faa0e1d22e083e775Behdad Esfahbodhb_ot_shape_normalization_mode_t 18111138ccff71f442da1fcf64faa0e1d22e083e775Behdad Esfahbod_hb_ot_shape_complex_normalization_preference_indic (void) 18202cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod{ 18302cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod /* We want split matras decomposed by the common shaping logic. */ 18411138ccff71f442da1fcf64faa0e1d22e083e775Behdad Esfahbod return HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED; 18502cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod} 18602cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod 187867361c3ad39629a8d5b7dc48d558a1c19e37d43Behdad Esfahbod 188b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodvoid 1899f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod_hb_ot_shape_complex_setup_masks_indic (hb_ot_map_t *map HB_UNUSED, 1909f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod hb_buffer_t *buffer, 1919f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod hb_font_t *font) 192b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{ 1939f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod HB_BUFFER_ALLOCATE_VAR (buffer, indic_category); 1949f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod HB_BUFFER_ALLOCATE_VAR (buffer, indic_position); 1959f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod 196743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* We cannot setup masks here. We save information about characters 197743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * and setup masks later on in a pause-callback. */ 198743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 199743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod unsigned int count = buffer->len; 200b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod for (unsigned int i = 0; i < count; i++) 201b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod { 20292332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod hb_glyph_info_t &info = buffer->info[i]; 20392332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod unsigned int type = get_indic_categories (info.codepoint); 20492332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod 20592332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_category() = type & 0x0F; 20692332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_position() = type >> 4; 20792332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod 2083399a06e7033651ee926448737bdb18e553c1796Behdad Esfahbod /* The spec says U+0952 is OT_A. However, testing shows that Uniscribe 2093399a06e7033651ee926448737bdb18e553c1796Behdad Esfahbod * treats U+0951..U+0952 all as OT_VD. 2103399a06e7033651ee926448737bdb18e553c1796Behdad Esfahbod * TESTS: 2113399a06e7033651ee926448737bdb18e553c1796Behdad Esfahbod * U+092E,U+0947,U+0952 2123399a06e7033651ee926448737bdb18e553c1796Behdad Esfahbod * U+092E,U+0952,U+0947 2133399a06e7033651ee926448737bdb18e553c1796Behdad Esfahbod * U+092E,U+0947,U+0951 2143399a06e7033651ee926448737bdb18e553c1796Behdad Esfahbod * U+092E,U+0951,U+0947 2153399a06e7033651ee926448737bdb18e553c1796Behdad Esfahbod * */ 2163399a06e7033651ee926448737bdb18e553c1796Behdad Esfahbod if (unlikely (hb_in_range<hb_codepoint_t> (info.codepoint, 0x0951, 0x0954))) 2173399a06e7033651ee926448737bdb18e553c1796Behdad Esfahbod info.indic_category() = OT_VD; 2183399a06e7033651ee926448737bdb18e553c1796Behdad Esfahbod 21992332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod if (info.indic_category() == OT_C) { 22092332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_position() = consonant_position (info.codepoint); 22192332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod if (is_ra (info.codepoint)) 22292332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_category() = OT_Ra; 22392332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod } else if (info.indic_category() == OT_SM || 22492332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_category() == OT_VD) { 22592332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_position() = POS_SMVD; 22692332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod } else if (unlikely (info.codepoint == 0x200C)) 22792332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_category() = OT_ZWNJ; 22892332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod else if (unlikely (info.codepoint == 0x200D)) 22992332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_category() = OT_ZWJ; 23018c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod else if (unlikely (info.codepoint == 0x25CC)) 23118c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod info.indic_category() = OT_DOTTEDCIRCLE; 232b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod } 233743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 234b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 23545d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbodstatic int 23645d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbodcompare_indic_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) 23745d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod{ 23845d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod int a = pa->indic_position(); 23945d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod int b = pb->indic_position(); 24045d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 24145d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod return a < b ? -1 : a == b ? 0 : +1; 24245d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod} 243867361c3ad39629a8d5b7dc48d558a1c19e37d43Behdad Esfahbod 2447ea58db311bfb0d8f804d1e9f4a1f004bd45075aBehdad Esfahbod/* Rules from: 2457ea58db311bfb0d8f804d1e9f4a1f004bd45075aBehdad Esfahbod * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */ 2467ea58db311bfb0d8f804d1e9f4a1f004bd45075aBehdad Esfahbod 247743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 2480831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbodinitial_reordering_syllable (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array, 2490831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod unsigned int start, unsigned int end, unsigned int base); 2500831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod 2510831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbodstatic void 252ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbodinitial_reordering_consonant_syllable (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array, 253ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int start, unsigned int end) 254743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 255ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod hb_glyph_info_t *info = buffer->info; 256743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 257743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* 1. Find base consonant: 258743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 259743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * The shaping engine finds the base consonant of the syllable, using the 260743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * following algorithm: starting from the end of the syllable, move backwards 261743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * until a consonant is found that does not have a below-base or post-base 262743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * form (post-base forms have to follow below-base forms), or that is not a 263743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * pre-base reordering Ra, or arrive at the first consonant. The consonant 264743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * stopped at will be the base. 265743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 266743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o If the syllable starts with Ra + Halant (in a script that has Reph) 267743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * and has more than one consonant, Ra is excluded from candidates for 268743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * base consonants. 269743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod */ 270743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 2715e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod unsigned int base = end; 27276b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod bool has_reph = false; 273743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 27476b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod /* -> If the syllable starts with Ra + Halant (in a script that has Reph) 27576b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod * and has more than one consonant, Ra is excluded from candidates for 27676b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod * base consonants. */ 2775e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod unsigned int limit = start; 27876b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod if (mask_array[RPHF] && 2796d8e0cb74c02f6bc09cd4abe9e4bc82062e1b517Behdad Esfahbod start + 3 <= end && 28076b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod info[start].indic_category() == OT_Ra && 2816d8e0cb74c02f6bc09cd4abe9e4bc82062e1b517Behdad Esfahbod info[start + 1].indic_category() == OT_H && 2826d8e0cb74c02f6bc09cd4abe9e4bc82062e1b517Behdad Esfahbod !is_joiner (info[start + 2])) 28376b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod { 2845e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod limit += 2; 2855e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod base = start; 28676b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod has_reph = true; 2875e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod }; 28876b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod 2893c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod { 2903c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod /* -> starting from the end of the syllable, move backwards */ 2913c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod unsigned int i = end; 2923c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod do { 2933c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod i--; 2943c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod /* -> until a consonant is found */ 2953c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod if (is_consonant (info[i])) 296743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod { 2973c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod /* -> that does not have a below-base or post-base form 2983c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod * (post-base forms have to follow below-base forms), */ 2993c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod if (info[i].indic_position() != POS_BELOW_C && 3003c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod info[i].indic_position() != POS_POST_C) 3013c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod { 3023c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod base = i; 3033c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod break; 3043c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod } 305743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 3063c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod /* -> or that is not a pre-base reordering Ra, 3073c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod * 3083c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod * TODO 3093c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod */ 310e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 3113c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod /* -> or arrive at the first consonant. The consonant stopped at will 3123c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod * be the base. */ 3133c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod base = i; 3143c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod } 3153c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod else 3163c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod if (is_joiner (info[i])) 3173c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod break; 3183c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod } while (i > limit); 3193c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod if (base < start) 3203c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod base = start; /* Just in case... */ 3213c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod } 322743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 3230831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod /* Continue reading below ------v */ 3240831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod initial_reordering_syllable (map, buffer, mask_array, start, end, base); 3250831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod} 3263d25079f8d6be81b9b4b91d3a97016b8a572f571Behdad Esfahbod 3270831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbodstatic void 3289f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbodinitial_reordering_syllable (const hb_ot_map_t *map, 3299f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod hb_buffer_t *buffer, 3309f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod hb_mask_t *mask_array, 3310831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod unsigned int start, unsigned int end, unsigned int base) 3320831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod{ 3330831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod hb_glyph_info_t *info = buffer->info; 3343d25079f8d6be81b9b4b91d3a97016b8a572f571Behdad Esfahbod 335743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* 2. Decompose and reorder Matras: 336743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 337743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * Each matra and any syllable modifier sign in the cluster are moved to the 338743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * appropriate position relative to the consonant(s) in the cluster. The 339743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * shaping engine decomposes two- or three-part matras into their constituent 340743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * parts before any repositioning. Matra characters are classified by which 341743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * consonant in a conjunct they have affinity for and are reordered to the 342743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * following positions: 343743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 344743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o Before first half form in the syllable 345743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o After subjoined consonants 346743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o After post-form consonant 347743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o After main consonant (for above marks) 348743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 349743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * IMPLEMENTATION NOTES: 350743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 351743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * The normalize() routine has already decomposed matras for us, so we don't 352743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * need to worry about that. 353743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod */ 354743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 355743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 356743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* 3. Reorder marks to canonical order: 357743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 358743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * Adjacent nukta and halant or nukta and vedic sign are always repositioned 359743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * if necessary, so that the nukta is first. 360743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 361743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * IMPLEMENTATION NOTES: 362743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 363743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * We don't need to do this: the normalize() routine already did this for us. 364743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod */ 365743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 366743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 36745d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod /* Reorder characters */ 36845d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 3693c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod for (unsigned int i = start; i < base; i++) 370dbccf87eef0d26838fa4bb3ae26410f6c4818836Behdad Esfahbod info[i].indic_position() = POS_PRE_C; 371dbccf87eef0d26838fa4bb3ae26410f6c4818836Behdad Esfahbod info[base].indic_position() = POS_BASE_C; 37245d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 373fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod /* Handle beginning Ra */ 3740831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod if (mask_array[RPHF] && 3750831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod start != base && 3760831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod start + 3 <= end && 3770831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod info[start].indic_category() == OT_Ra && 3780831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod info[start + 1].indic_category() == OT_H && 3790831061efb78983b9c6e1e72574c977e56383c08Behdad Esfahbod !is_joiner (info[start + 2])) 380dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod info[start].indic_position() = POS_RA_TO_BECOME_REPH; 381fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod 382f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod /* For old-style Indic script tags, move the first post-base Halant after 383f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod * last consonant. */ 384f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod if ((map->get_chosen_script (0) & 0x000000FF) != '2') { 385f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod /* We should only do this for Indic scripts which have a version two I guess. */ 3863c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod for (unsigned int i = base + 1; i < end; i++) 387f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod if (info[i].indic_category() == OT_H) { 388f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod unsigned int j; 389f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod for (j = end - 1; j > i; j--) 390190eb31a16178269aecaf5d2ecc9012f956749f4Behdad Esfahbod if (is_consonant (info[j])) 391f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod break; 392f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod if (j > i) { 393f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod /* Move Halant to after last consonant. */ 394f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod hb_glyph_info_t t = info[i]; 395f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod memmove (&info[i], &info[i + 1], (j - i) * sizeof (info[0])); 396f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod info[j] = t; 397f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod } 398f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod break; 399f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod } 400f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod } 401f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod 40245d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod /* Attach ZWJ, ZWNJ, nukta, and halant to previous char to move with them. */ 403ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod if (!options.uniscribe_bug_compatible) 404ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod { 405ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod /* Please update the Uniscribe branch when touching this! */ 406ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod for (unsigned int i = start + 1; i < end; i++) 407ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod if ((FLAG (info[i].indic_category()) & (FLAG (OT_ZWNJ) | FLAG (OT_ZWJ) | FLAG (OT_N) | FLAG (OT_H)))) 408ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod info[i].indic_position() = info[i - 1].indic_position(); 409ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod } else { 41067ea29af49bb08ee679914076808327992cf6676Behdad Esfahbod /* 41167ea29af49bb08ee679914076808327992cf6676Behdad Esfahbod * Uniscribe doesn't move the Halant with Left Matra. 41267ea29af49bb08ee679914076808327992cf6676Behdad Esfahbod * TEST: U+092B,U+093F,U+094DE 41367ea29af49bb08ee679914076808327992cf6676Behdad Esfahbod */ 414ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod /* Please update the non-Uniscribe branch when touching this! */ 415ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod for (unsigned int i = start + 1; i < end; i++) 416ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod if ((FLAG (info[i].indic_category()) & (FLAG (OT_ZWNJ) | FLAG (OT_ZWJ) | FLAG (OT_N) | FLAG (OT_H)))) { 417ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod info[i].indic_position() = info[i - 1].indic_position(); 4186a091df9b403b147ef78f3974610dedf4ce1e08aBehdad Esfahbod if (info[i].indic_category() == OT_H && info[i].indic_position() == POS_PRE_M) 419ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod for (unsigned int j = i; j > start; j--) 4206a091df9b403b147ef78f3974610dedf4ce1e08aBehdad Esfahbod if (info[j - 1].indic_position() != POS_PRE_M) { 421ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod info[i].indic_position() = info[j - 1].indic_position(); 422ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod break; 423ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod } 424ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod } 425ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod } 42645d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 42745d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod /* We do bubble-sort, skip malicious clusters attempts */ 428b99d63ae114fb58f129562b293a8a66543d499adBehdad Esfahbod if (end - start < 64) 429a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod { 430a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod /* Sit tight, rock 'n roll! */ 431d3637edb248162970e202e9d0671540274192844Behdad Esfahbod hb_bubble_sort (info + start, end - start, compare_indic_order); 432a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod /* Find base again */ 433a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod base = end; 4343c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod for (unsigned int i = start; i < end; i++) 435a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod if (info[i].indic_position() == POS_BASE_C) { 436a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod base = i; 437a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod break; 438a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod } 439a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod } 44045d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 441743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* Setup masks now */ 442743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 443281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod { 444281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod hb_mask_t mask; 445281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod 446dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod /* Reph */ 447668c6046c1b3af3bd316bda0cc8636f2a5e8df42Behdad Esfahbod for (unsigned int i = start; i < end && info[i].indic_position() == POS_RA_TO_BECOME_REPH; i++) 448668c6046c1b3af3bd316bda0cc8636f2a5e8df42Behdad Esfahbod info[i].mask |= mask_array[RPHF]; 449dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod 450281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod /* Pre-base */ 451281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod mask = mask_array[HALF] | mask_array[AKHN] | mask_array[CJCT]; 4523c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod for (unsigned int i = start; i < base; i++) 453281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod info[i].mask |= mask; 454281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod /* Base */ 455281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod mask = mask_array[AKHN] | mask_array[CJCT]; 456281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod info[base].mask |= mask; 457281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod /* Post-base */ 458281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod mask = mask_array[BLWF] | mask_array[PSTF] | mask_array[CJCT]; 4593c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod for (unsigned int i = base + 1; i < end; i++) 460281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod info[i].mask |= mask; 461281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod } 4629da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod 4639da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod /* Apply ZWJ/ZWNJ effects */ 4643c2ea9481b1028e927e615a5434ebf8edcb5f891Behdad Esfahbod for (unsigned int i = start + 1; i < end; i++) 4659da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod if (is_joiner (info[i])) { 4669da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod bool non_joiner = info[i].indic_category() == OT_ZWNJ; 4676b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod unsigned int j = i; 4689da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod 4699da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod do { 4709da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod j--; 4716b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod 4723bf27a9f0e92aa31b464bd3b9fdea5933c9ae8b1Behdad Esfahbod info[j].mask &= ~mask_array[CJCT]; 4736b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod if (non_joiner) 474c6d904d67db589dd6209928e56504f04f6a07756Behdad Esfahbod info[j].mask &= ~mask_array[HALF]; 4756b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod 4769da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod } while (j > start && !is_consonant (info[j])); 4779da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod } 478743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 479743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 480743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 481743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 4829f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbodinitial_reordering_vowel_syllable (const hb_ot_map_t *map, 4839f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod hb_buffer_t *buffer, 4849f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod hb_mask_t *mask_array, 485ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int start, unsigned int end) 486743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 487c5306b6861cfaa50af40e8ceb058791fa06d7981Behdad Esfahbod /* We made the vowels look like consonants. So let's call the consonant logic! */ 488c5306b6861cfaa50af40e8ceb058791fa06d7981Behdad Esfahbod initial_reordering_consonant_syllable (map, buffer, mask_array, start, end); 489743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 490743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 491743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 4929f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbodinitial_reordering_standalone_cluster (const hb_ot_map_t *map, 4939f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod hb_buffer_t *buffer, 4949f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod hb_mask_t *mask_array, 495ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int start, unsigned int end) 496743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 49718c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod /* We treat NBSP/dotted-circle as if they are consonants, so we should just chain. 49818c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod * Only if not in compatibility mode that is... */ 49918c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod 50018c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod if (options.uniscribe_bug_compatible) 50118c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod { 50218c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod /* For dotted-circle, this is what Uniscribe does: 50318c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod * If dotted-circle is the last glyph, it just does nothing. 50418c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod * Ie. It doesn't form Reph. */ 50518c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod if (buffer->info[end - 1].indic_category() == OT_DOTTEDCIRCLE) 50618c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod return; 50718c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod } 50818c06e189bd078affbb84c3bb5bb80687a227c5eBehdad Esfahbod 5091a1fa8c655a082fc1439608457ba717306cc83caBehdad Esfahbod initial_reordering_consonant_syllable (map, buffer, mask_array, start, end); 510743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 511743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 512743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 5139f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbodinitial_reordering_non_indic (const hb_ot_map_t *map HB_UNUSED, 5149f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod hb_buffer_t *buffer HB_UNUSED, 5159f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod hb_mask_t *mask_array HB_UNUSED, 5169f377ed3210fe7d9f15e0c4f82020556f9a8f6f0Behdad Esfahbod unsigned int start, unsigned int end) 517743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 518743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* Nothing to do right now. If we ever switch to using the output 519743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * buffer in the reordering process, we'd need to next_glyph() here. */ 520743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 521743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 522743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod#include "hb-ot-shape-complex-indic-machine.hh" 523743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 524743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 525743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodinitial_reordering (const hb_ot_map_t *map, 526743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_face_t *face, 527743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_buffer_t *buffer, 528743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod void *user_data HB_UNUSED) 529743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 530b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod hb_mask_t mask_array[ARRAY_LENGTH (indic_basic_features)] = {0}; 531b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod unsigned int num_masks = ARRAY_LENGTH (indic_basic_features); 532b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod for (unsigned int i = 0; i < num_masks; i++) 53376f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod mask_array[i] = map->get_1_mask (indic_basic_features[i].tag); 534743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 535743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod find_syllables (map, buffer, mask_array); 536b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod} 537b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 538743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 539eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbodfinal_reordering_syllable (hb_buffer_t *buffer, hb_mask_t *mask_array, 540ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int start, unsigned int end) 541743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 5424ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod hb_glyph_info_t *info = buffer->info; 5434ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 544e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod /* 4. Final reordering: 545e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 546e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * After the localized forms and basic shaping forms GSUB features have been 547e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * applied (see below), the shaping engine performs some final glyph 548e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * reordering before applying all the remaining font features to the entire 549e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * cluster. 5504ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod */ 5514ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 5524ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod /* Find base again */ 5534ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod unsigned int base = end; 5544ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod for (unsigned int i = start; i < end; i++) 5554ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod if (info[i].indic_position() == POS_BASE_C) { 5564ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod base = i; 5574ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod break; 5584ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod } 5594ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 5604ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod if (base == start) { 5614ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod /* There's no Reph, and no left Matra to reposition. Just merge the cluster 5624ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod * and go home. */ 5634ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod buffer->merge_clusters (start, end); 5644ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod return; 5654ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod } 5664ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 5674705a7026900e51f6430f03a73c87f2df035df92Behdad Esfahbod unsigned int start_of_last_cluster = base; 5684705a7026900e51f6430f03a73c87f2df035df92Behdad Esfahbod 5694ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod /* o Reorder matras: 570e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 571e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * If a pre-base matra character had been reordered before applying basic 572e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * features, the glyph can be moved closer to the main consonant based on 573e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * whether half-forms had been formed. Actual position for the matra is 574e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * defined as “after last standalone halant glyph, after initial matra 575e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * position and before the main consonant”. If ZWJ or ZWNJ follow this 576e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * halant, position is moved after it. 5774ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod */ 5784ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 5799d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod { 5809d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod unsigned int new_matra_pos = base - 1; 5819d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod while (new_matra_pos > start && 5829d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod !(FLAG (info[new_matra_pos].indic_category()) & (FLAG (OT_M) | FLAG (OT_H)))) 5839d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod new_matra_pos--; 5849d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod /* If we found no Halant we are done. Otherwise only proceed if the Halant does 5859d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod * not belong to the Matra itself! */ 5869d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod if (info[new_matra_pos].indic_category() == OT_H && 5876a091df9b403b147ef78f3974610dedf4ce1e08aBehdad Esfahbod info[new_matra_pos].indic_position() != POS_PRE_M) { 5889d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ 5899d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod if (new_matra_pos + 1 < end && is_joiner (info[new_matra_pos + 1])) 5909d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod new_matra_pos++; 5919d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod 5929d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod /* Now go see if there's actually any matras... */ 5939d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod for (unsigned int i = new_matra_pos; i > start; i--) 5946a091df9b403b147ef78f3974610dedf4ce1e08aBehdad Esfahbod if (info[i - 1].indic_position () == POS_PRE_M) 5959d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod { 5969d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod unsigned int old_matra_pos = i - 1; 5979d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod hb_glyph_info_t matra = info[old_matra_pos]; 5989d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod memmove (&info[old_matra_pos], &info[old_matra_pos + 1], (new_matra_pos - old_matra_pos) * sizeof (info[0])); 5999d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod info[new_matra_pos] = matra; 6009d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod start_of_last_cluster = MIN (new_matra_pos, start_of_last_cluster); 6019d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod new_matra_pos--; 6029d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod } 6039d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod } 6044ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod } 6054ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 6064ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 6074ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod /* o Reorder reph: 608e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 609e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * Reph’s original position is always at the beginning of the syllable, 610e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * (i.e. it is not reordered at the character reordering stage). However, 611e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * it will be reordered according to the basic-forms shaping results. 612e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * Possible positions for reph, depending on the script, are; after main, 613e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * before post-base consonant forms, and after post-base consonant forms. 614dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod */ 615dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod 616dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod /* If there's anything after the Ra that has the REPH pos, it ought to be halant. 617dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * Which means that the font has failed to ligate the Reph. In which case, we 618dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * shouldn't move. */ 619dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod if (start + 1 < end && 620dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod info[start].indic_position() == POS_RA_TO_BECOME_REPH && 621dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod info[start + 1].indic_position() != POS_RA_TO_BECOME_REPH) 622dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod { 62302b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod unsigned int new_reph_pos; 62402b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod 62502b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod enum reph_position_t { 626f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod REPH_AFTER_MAIN, 627f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod REPH_BEFORE_SUBSCRIPT, 628f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod REPH_AFTER_SUBSCRIPT, 629f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod REPH_BEFORE_POSTSCRIPT, 630f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod REPH_AFTER_POSTSCRIPT, 631f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod } reph_pos; 632f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod 633f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod /* XXX Figure out old behavior too */ 6347f852b644b8143492a02edfc853114aaa23446bdBehdad Esfahbod switch ((hb_tag_t) buffer->props.script) 635f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod { 636f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod case HB_SCRIPT_MALAYALAM: 637f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod case HB_SCRIPT_ORIYA: 638f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod reph_pos = REPH_AFTER_MAIN; 639f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod break; 640f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod 641f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod case HB_SCRIPT_GURMUKHI: 642f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod reph_pos = REPH_BEFORE_SUBSCRIPT; 643f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod break; 644f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod 645f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod case HB_SCRIPT_BENGALI: 646f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod reph_pos = REPH_AFTER_SUBSCRIPT; 647f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod break; 648f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod 649f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod default: 650f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod case HB_SCRIPT_DEVANAGARI: 651f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod case HB_SCRIPT_GUJARATI: 652f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod reph_pos = REPH_BEFORE_POSTSCRIPT; 653f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod break; 654f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod 655f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod case HB_SCRIPT_KANNADA: 656f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod case HB_SCRIPT_TAMIL: 657f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod case HB_SCRIPT_TELUGU: 658f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod reph_pos = REPH_AFTER_POSTSCRIPT; 659f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod break; 660f89367251109af235f4f0446c13c261a5a4a6f72Behdad Esfahbod } 66102b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod 662dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod /* 1. If reph should be positioned after post-base consonant forms, 663dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * proceed to step 5. 66402b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod */ 6659d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod if (reph_pos == REPH_AFTER_POSTSCRIPT) 66602b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod { 6679d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod goto reph_step_5; 66802b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod } 66902b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod 67002b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod /* 2. If the reph repositioning class is not after post-base: target 671dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * position is after the first explicit halant glyph between the 672dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * first post-reph consonant and last main consonant. If ZWJ or ZWNJ 673dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * are following this halant, position is moved after it. If such 674dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * position is found, this is the target position. Otherwise, 675dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * proceed to the next step. 676dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 677dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * Note: in old-implementation fonts, where classifications were 678dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * fixed in shaping engine, there was no case where reph position 679dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * will be found on this step. 68002b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod */ 68102b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod { 68202b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod new_reph_pos = start + 1; 68302b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod while (new_reph_pos < base && info[new_reph_pos].indic_category() != OT_H) 68402b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod new_reph_pos++; 68502b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod 68602b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod if (new_reph_pos < base && info[new_reph_pos].indic_category() == OT_H) { 68702b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */ 68802b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1])) 68902b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod new_reph_pos++; 69002b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod goto reph_move; 69102b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod } 69202b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod } 69302b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod 69402b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod /* 3. If reph should be repositioned after the main consonant: find the 695dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * first consonant not ligated with main, or find the first 696dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * consonant that is not a potential pre-base reordering Ra. 69702b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod */ 6989d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod if (reph_pos == REPH_AFTER_MAIN) 69902b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod { 70002b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod /* XXX */ 70102b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod } 70202b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod 70302b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod /* 4. If reph should be positioned before post-base consonant, find 704dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * first post-base classified consonant not ligated with main. If no 705dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * consonant is found, the target position should be before the 706dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * first matra, syllable modifier sign or vedic sign. 70702b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod */ 7089d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod /* This is our take on what step 4 is trying to say (and failing, BADLY). */ 7099d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod if (reph_pos == REPH_AFTER_SUBSCRIPT) 71002b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod { 7119d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod new_reph_pos = base; 7129d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod while (new_reph_pos < end && 7136a091df9b403b147ef78f3974610dedf4ce1e08aBehdad Esfahbod !( FLAG (info[new_reph_pos + 1].indic_position()) & (FLAG (POS_POST_C) | FLAG (POS_POST_M) | FLAG (POS_SMVD)))) 7149d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod new_reph_pos++; 7159d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod if (new_reph_pos < end) 7169d0d319a4a7e85d922e58fade0f40caae1c9f109Behdad Esfahbod goto reph_move; 71702b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod } 71802b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod 71902b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod /* 5. If no consonant is found in steps 3 or 4, move reph to a position 720dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * immediately before the first post-base matra, syllable modifier 721dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * sign or vedic sign that has a reordering class after the intended 722dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * reph position. For example, if the reordering position for reph 723dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * is post-main, it will skip above-base matras that also have a 724dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * post-main position. 725dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod */ 72602b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod reph_step_5: 72702b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod { 72802b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod /* XXX */ 72902b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod } 730dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod 73102b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod /* 6. Otherwise, reorder reph to the end of the syllable. 73202b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod */ 73302b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod { 73402b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod new_reph_pos = end - 1; 73502b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod while (new_reph_pos > start && info[new_reph_pos].indic_position() == POS_SMVD) 73602b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod new_reph_pos--; 73702b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod 738892eb7878238d810a2a70f9dadbf958207bfeaa1Behdad Esfahbod /* 739892eb7878238d810a2a70f9dadbf958207bfeaa1Behdad Esfahbod * If the Reph is to be ending up after a Matra,Halant sequence, 740892eb7878238d810a2a70f9dadbf958207bfeaa1Behdad Esfahbod * position it before that Halant so it can interact with the Matra. 741892eb7878238d810a2a70f9dadbf958207bfeaa1Behdad Esfahbod * However, if it's a plain Consonant,Halant we shouldn't do that. 742892eb7878238d810a2a70f9dadbf958207bfeaa1Behdad Esfahbod * Uniscribe doesn't do this. 743892eb7878238d810a2a70f9dadbf958207bfeaa1Behdad Esfahbod * TEST: U+0930,U+094D,U+0915,U+094B,U+094D 744892eb7878238d810a2a70f9dadbf958207bfeaa1Behdad Esfahbod */ 745892eb7878238d810a2a70f9dadbf958207bfeaa1Behdad Esfahbod if (!options.uniscribe_bug_compatible && 746892eb7878238d810a2a70f9dadbf958207bfeaa1Behdad Esfahbod unlikely (info[new_reph_pos].indic_category() == OT_H)) { 74702b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod for (unsigned int i = base + 1; i < new_reph_pos; i++) 74802b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod if (info[i].indic_category() == OT_M) { 74902b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod /* Ok, got it. */ 75002b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod new_reph_pos--; 75102b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod } 75202b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod } 75302b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod goto reph_move; 7548df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod } 7558df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod 75602b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod reph_move: 75702b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod { 75802b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod /* Move */ 75902b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod hb_glyph_info_t reph = info[start]; 76002b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod memmove (&info[start], &info[start + 1], (new_reph_pos - start) * sizeof (info[0])); 76102b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod info[new_reph_pos] = reph; 76202b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod start_of_last_cluster = start; /* Yay, one big cluster! */ 76302b2922fbf098c8282eb23dc2c54d5829cf67024Behdad Esfahbod } 764dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod } 765dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod 766dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod 767dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod /* o Reorder pre-base reordering consonants: 768e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 769e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * If a pre-base reordering consonant is found, reorder it according to 770e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * the following rules: 771e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 772e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 1. Only reorder a glyph produced by substitution during application 773e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * of the feature. (Note that a font may shape a Ra consonant with 774e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * the feature generally but block it in certain contexts.) 775e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 776e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 2. Try to find a target position the same way as for pre-base matra. 777e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * If it is found, reorder pre-base consonant glyph. 778e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 779e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 3. If position is not found, reorder immediately before main 780e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * consonant. 781e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod */ 782e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 783eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod /* TODO */ 784eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod 785eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod 786eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod 787a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod /* Apply 'init' to the Left Matra if it's a word start. */ 7886a091df9b403b147ef78f3974610dedf4ce1e08aBehdad Esfahbod if (info[start].indic_position () == POS_PRE_M && 789a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod (!start || 790eace47b173807d94b29a6490d0bc3c9f8f6168d1Behdad Esfahbod !(FLAG (_hb_glyph_info_get_general_category (&info[start - 1])) & 791a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod (FLAG (HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER) | 792a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod FLAG (HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER) | 793a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod FLAG (HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER) | 794a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod FLAG (HB_UNICODE_GENERAL_CATEGORY_TITLECASE_LETTER) | 795a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod FLAG (HB_UNICODE_GENERAL_CATEGORY_UPPERCASE_LETTER) | 796a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) | 797a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | 798a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK))))) 799a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod info[start].mask |= mask_array[INIT]; 800a913b024d84973556094fd64ce5f0b7106fcc3b5Behdad Esfahbod 801eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod 80221d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod 80321d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod /* Finish off the clusters and go home! */ 80421d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod 805ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod if (!options.uniscribe_bug_compatible) 806ebe29733d44fe0fa9fb30f946ab0dd7a40336a24Behdad Esfahbod { 80721d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod /* This is what Uniscribe does. Ie. add cluster boundaries after Halant,ZWNJ. 80821d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod * This means, half forms are submerged into the main consonants cluster. 80921d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod * This is unnecessary, and makes cursor positioning harder, but that's what 81021d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod * Uniscribe does. */ 81121d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod unsigned int cluster_start = start; 81221d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod for (unsigned int i = start + 1; i < start_of_last_cluster; i++) 81321d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod if (info[i - 1].indic_category() == OT_H && info[i].indic_category() == OT_ZWNJ) { 81421d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod i++; 81521d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod buffer->merge_clusters (cluster_start, i); 81621d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod cluster_start = i; 81721d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod } 81821d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod start_of_last_cluster = cluster_start; 81921d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod } 82021d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod 82121d2803133c2c424ed37a9f3d17c7fc4963e5a60Behdad Esfahbod buffer->merge_clusters (start_of_last_cluster, end); 822ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod} 823e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 824e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 825ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbodstatic void 826ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbodfinal_reordering (const hb_ot_map_t *map, 827ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod hb_face_t *face, 828ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod hb_buffer_t *buffer, 829ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod void *user_data HB_UNUSED) 830ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod{ 831ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int count = buffer->len; 832ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod if (!count) return; 833ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod 834eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod hb_mask_t mask_array[ARRAY_LENGTH (indic_other_features)] = {0}; 835eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod unsigned int num_masks = ARRAY_LENGTH (indic_other_features); 836eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod for (unsigned int i = 0; i < num_masks; i++) 837eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod mask_array[i] = map->get_1_mask (indic_other_features[i].tag); 838eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod 839ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod hb_glyph_info_t *info = buffer->info; 840ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int last = 0; 841cee7187447b76b22e1bb6136d137b35ac49c3a5dBehdad Esfahbod unsigned int last_syllable = info[0].syllable(); 842ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod for (unsigned int i = 1; i < count; i++) 843cee7187447b76b22e1bb6136d137b35ac49c3a5dBehdad Esfahbod if (last_syllable != info[i].syllable()) { 844eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod final_reordering_syllable (buffer, mask_array, last, i); 845ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod last = i; 846cee7187447b76b22e1bb6136d137b35ac49c3a5dBehdad Esfahbod last_syllable = info[last].syllable(); 847ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod } 848eed903b1644e087178438959664a6a57bebc398bBehdad Esfahbod final_reordering_syllable (buffer, mask_array, last, count); 849e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 850743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category); 851743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position); 852743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 853743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 854743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 855b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 856