hb-ot-shape-complex-indic.cc revision 8df5636968389ac7bf8620ccd091fd4872b0bbee
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 27b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 283ed4634ec349fa9e943ad23718c04be4dd4bba62Behdad Esfahbod#include "hb-ot-shape-complex-indic-private.hh" 29352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod 30743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic int 31743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodcompare_codepoint (const void *pa, const void *pb) 32743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 33743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_codepoint_t a = * (hb_codepoint_t *) pa; 34743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_codepoint_t b = * (hb_codepoint_t *) pb; 35743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 36743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod return a < b ? -1 : a == b ? 0 : +1; 37743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 38743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 39743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic indic_position_t 40743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodconsonant_position (hb_codepoint_t u) 41743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 42743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod consonant_position_t *record; 43743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 44743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod record = (consonant_position_t *) bsearch (&u, consonant_positions, 45743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod ARRAY_LENGTH (consonant_positions), 46743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod sizeof (consonant_positions[0]), 47743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod compare_codepoint); 48743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 49dbccf87eef0d26838fa4bb3ae26410f6c4818836Behdad Esfahbod return record ? record->position : POS_BASE_C; 50743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 51743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 52352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbodstatic bool 53352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbodis_ra (hb_codepoint_t u) 54352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod{ 55352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod return !!bsearch (&u, ra_chars, 56352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod ARRAY_LENGTH (ra_chars), 57352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod sizeof (ra_chars[0]), 58352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod compare_codepoint); 59352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod} 60352372ae5ea0998e40cf9fe43c22b6b610a5764eBehdad Esfahbod 619ee27a928a989c71923cef82a9e9828f8e9ca051Behdad Esfahbodstatic bool 629da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodis_joiner (const hb_glyph_info_t &info) 639ee27a928a989c71923cef82a9e9828f8e9ca051Behdad Esfahbod{ 649da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod return !!(FLAG (info.indic_category()) & (FLAG (OT_ZWJ) | FLAG (OT_ZWNJ))); 659da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod} 669da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod 679da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodstatic bool 689da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbodis_consonant (const hb_glyph_info_t &info) 699da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod{ 701a1fa8c655a082fc1439608457ba717306cc83caBehdad Esfahbod /* Note: 711a1fa8c655a082fc1439608457ba717306cc83caBehdad Esfahbod * 721a1fa8c655a082fc1439608457ba717306cc83caBehdad Esfahbod * We treat Vowels and NBSP as if they were consonants. This is safe because Vowels 73c5306b6861cfaa50af40e8ceb058791fa06d7981Behdad Esfahbod * cannot happen in a consonant syllable. The plus side however is, we can call the 74c5306b6861cfaa50af40e8ceb058791fa06d7981Behdad Esfahbod * consonant syllable logic from the vowel syllable function and get it all right! */ 751a1fa8c655a082fc1439608457ba717306cc83caBehdad Esfahbod return !!(FLAG (info.indic_category()) & (FLAG (OT_C) | FLAG (OT_Ra) | FLAG (OT_V) | FLAG (OT_NBSP))); 769ee27a928a989c71923cef82a9e9828f8e9ca051Behdad Esfahbod} 77c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod 78c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbodstatic const struct { 79c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod hb_tag_t tag; 80c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod hb_bool_t is_global; 81c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod} indic_basic_features[] = 82b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{ 83c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('n','u','k','t'), true}, 84c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('a','k','h','n'), false}, 85c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('r','p','h','f'), false}, 861ac075b227090a9ad930dcc1670236c176b27067Behdad Esfahbod {HB_TAG('r','k','r','f'), true}, 87c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('p','r','e','f'), false}, 88c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('b','l','w','f'), false}, 89c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('h','a','l','f'), false}, 90c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('v','a','t','u'), true}, 91c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod {HB_TAG('p','s','t','f'), false}, 929da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod {HB_TAG('c','j','c','t'), false}, 93c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod}; 94c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod 95c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod/* Same order as the indic_basic_features array */ 96c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbodenum { 97c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod _NUKT, 98c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod AKHN, 99c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod RPHF, 100df6d45c693c417bf311e6fa49f18a8558542e525Behdad Esfahbod _RKRF, 101c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod PREF, 102c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod BLWF, 103c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod HALF, 104c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod _VATU, 105c7fe56a1d5d3e969b6ec51cd9ecd471706a19568Behdad Esfahbod PSTF, 106e8eedf2687f05372bf5476e84139d01ba67c9f73Behdad Esfahbod CJCT 107b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod}; 108b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 109b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodstatic const hb_tag_t indic_other_features[] = 110b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{ 111b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod HB_TAG('p','r','e','s'), 112b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod HB_TAG('a','b','v','s'), 113b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod HB_TAG('b','l','w','s'), 114b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod HB_TAG('p','s','t','s'), 115b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod HB_TAG('h','a','l','n'), 116b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 117b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod HB_TAG('d','i','s','t'), 118b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod HB_TAG('a','b','v','m'), 119b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod HB_TAG('b','l','w','m'), 120b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod}; 121b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 122743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 123743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 124743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodinitial_reordering (const hb_ot_map_t *map, 125743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_face_t *face, 126743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_buffer_t *buffer, 127743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod void *user_data HB_UNUSED); 128f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbodstatic void 129f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbodfinal_reordering (const hb_ot_map_t *map, 130f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod hb_face_t *face, 131f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod hb_buffer_t *buffer, 132743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod void *user_data HB_UNUSED); 133b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 134b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodvoid 13576f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod_hb_ot_shape_complex_collect_features_indic (hb_ot_map_builder_t *map, const hb_segment_properties_t *props) 136b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{ 137f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod map->add_bool_feature (HB_TAG('l','o','c','l')); 138a54a5505a35eef5315a8e2e7a79502901e3eff5fBehdad Esfahbod /* The Indic specs do not require ccmp, but we apply it here since if 139a54a5505a35eef5315a8e2e7a79502901e3eff5fBehdad Esfahbod * there is a use of it, it's typically at the beginning. */ 140f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod map->add_bool_feature (HB_TAG('c','c','m','p')); 141f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod 142743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod map->add_gsub_pause (initial_reordering, NULL); 143f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod 144412b91889d9a1ae477e8b6907d0b9a76e78a6c91Behdad Esfahbod for (unsigned int i = 0; i < ARRAY_LENGTH (indic_basic_features); i++) { 14576f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod map->add_bool_feature (indic_basic_features[i].tag, indic_basic_features[i].is_global); 146412b91889d9a1ae477e8b6907d0b9a76e78a6c91Behdad Esfahbod map->add_gsub_pause (NULL, NULL); 147412b91889d9a1ae477e8b6907d0b9a76e78a6c91Behdad Esfahbod } 148b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 149f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod map->add_gsub_pause (final_reordering, NULL); 150f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbod 151412b91889d9a1ae477e8b6907d0b9a76e78a6c91Behdad Esfahbod for (unsigned int i = 0; i < ARRAY_LENGTH (indic_other_features); i++) { 15276f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod map->add_bool_feature (indic_other_features[i], true); 153412b91889d9a1ae477e8b6907d0b9a76e78a6c91Behdad Esfahbod map->add_gsub_pause (NULL, NULL); 154412b91889d9a1ae477e8b6907d0b9a76e78a6c91Behdad Esfahbod } 155b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod} 156b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 157867361c3ad39629a8d5b7dc48d558a1c19e37d43Behdad Esfahbod 15811138ccff71f442da1fcf64faa0e1d22e083e775Behdad Esfahbodhb_ot_shape_normalization_mode_t 15911138ccff71f442da1fcf64faa0e1d22e083e775Behdad Esfahbod_hb_ot_shape_complex_normalization_preference_indic (void) 16002cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod{ 16102cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod /* We want split matras decomposed by the common shaping logic. */ 16211138ccff71f442da1fcf64faa0e1d22e083e775Behdad Esfahbod return HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED; 16302cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod} 16402cdf743c2ec345a44d4fcf865594b6ac13fccd0Behdad Esfahbod 165867361c3ad39629a8d5b7dc48d558a1c19e37d43Behdad Esfahbod 166b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbodvoid 167acd88e659fdb2fa1cbf7171f0a1c7fbc81b9f298Behdad Esfahbod_hb_ot_shape_complex_setup_masks_indic (hb_ot_map_t *map, hb_buffer_t *buffer, hb_font_t *font) 168b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod{ 1699f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod HB_BUFFER_ALLOCATE_VAR (buffer, indic_category); 1709f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod HB_BUFFER_ALLOCATE_VAR (buffer, indic_position); 171ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod HB_BUFFER_ALLOCATE_VAR (buffer, indic_syllable); 1729f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod 173743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* We cannot setup masks here. We save information about characters 174743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * and setup masks later on in a pause-callback. */ 175743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 176743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod unsigned int count = buffer->len; 177b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod for (unsigned int i = 0; i < count; i++) 178b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod { 17992332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod hb_glyph_info_t &info = buffer->info[i]; 18092332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod unsigned int type = get_indic_categories (info.codepoint); 18192332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod 18292332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_category() = type & 0x0F; 18392332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_position() = type >> 4; 18492332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod 18592332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod if (info.indic_category() == OT_C) { 18692332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_position() = consonant_position (info.codepoint); 18792332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod if (is_ra (info.codepoint)) 18892332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_category() = OT_Ra; 18992332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod } else if (info.indic_category() == OT_SM || 19092332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_category() == OT_VD) { 19192332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_position() = POS_SMVD; 19292332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod } else if (unlikely (info.codepoint == 0x200C)) 19392332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_category() = OT_ZWNJ; 19492332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod else if (unlikely (info.codepoint == 0x200D)) 19592332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_category() = OT_ZWJ; 19692332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod 19792332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod if (unlikely (info.codepoint == 0x0952)) { 19892332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_category() = OT_A; 19992332e5116271a5d96e532005fe750e7552a6cbbBehdad Esfahbod info.indic_position() = POS_SMVD; 20033c92e769563ec2a6c1249b57d8cac742eea6f88Behdad Esfahbod } 201b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod } 202743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 203b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 20445d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbodstatic int 20545d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbodcompare_indic_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) 20645d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod{ 20745d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod int a = pa->indic_position(); 20845d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod int b = pb->indic_position(); 20945d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 21045d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod return a < b ? -1 : a == b ? 0 : +1; 21145d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod} 212867361c3ad39629a8d5b7dc48d558a1c19e37d43Behdad Esfahbod 213743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 214ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbodinitial_reordering_consonant_syllable (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array, 215ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int start, unsigned int end) 216743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 217743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod unsigned int i; 218ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod hb_glyph_info_t *info = buffer->info; 219743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 220743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* Comments from: 221743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */ 222743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 223743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* 1. Find base consonant: 224743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 225743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * The shaping engine finds the base consonant of the syllable, using the 226743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * following algorithm: starting from the end of the syllable, move backwards 227743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * until a consonant is found that does not have a below-base or post-base 228743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * form (post-base forms have to follow below-base forms), or that is not a 229743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * pre-base reordering Ra, or arrive at the first consonant. The consonant 230743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * stopped at will be the base. 231743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 232743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o If the syllable starts with Ra + Halant (in a script that has Reph) 233743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * and has more than one consonant, Ra is excluded from candidates for 234743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * base consonants. 235743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod */ 236743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 2375e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod unsigned int base = end; 23876b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod bool has_reph = false; 239743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 24076b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod /* -> If the syllable starts with Ra + Halant (in a script that has Reph) 24176b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod * and has more than one consonant, Ra is excluded from candidates for 24276b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod * base consonants. */ 2435e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod unsigned int limit = start; 24476b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod if (mask_array[RPHF] && 2456d8e0cb74c02f6bc09cd4abe9e4bc82062e1b517Behdad Esfahbod start + 3 <= end && 24676b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod info[start].indic_category() == OT_Ra && 2476d8e0cb74c02f6bc09cd4abe9e4bc82062e1b517Behdad Esfahbod info[start + 1].indic_category() == OT_H && 2486d8e0cb74c02f6bc09cd4abe9e4bc82062e1b517Behdad Esfahbod !is_joiner (info[start + 2])) 24976b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod { 2505e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod limit += 2; 2515e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod base = start; 25276b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod has_reph = true; 2535e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod }; 25476b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod 25576b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod /* -> starting from the end of the syllable, move backwards */ 25676b3409de6887c1cdd5c679939497b1b56f4554bBehdad Esfahbod i = end; 257743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod do { 258743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod i--; 259743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* -> until a consonant is found */ 26097158392a5899ddb739afaac925128f33f699bd7Behdad Esfahbod if (is_consonant (info[i])) 261743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod { 262743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* -> that does not have a below-base or post-base form 263743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * (post-base forms have to follow below-base forms), */ 264dbccf87eef0d26838fa4bb3ae26410f6c4818836Behdad Esfahbod if (info[i].indic_position() != POS_BELOW_C && 265dbccf87eef0d26838fa4bb3ae26410f6c4818836Behdad Esfahbod info[i].indic_position() != POS_POST_C) 266743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod { 267743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod base = i; 268743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod break; 269743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod } 270743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 271cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod /* -> or that is not a pre-base reordering Ra, 272cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod * 273e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * TODO 274e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod */ 275e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 276cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod /* -> or arrive at the first consonant. The consonant stopped at will 277cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod * be the base. */ 278743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod base = i; 279743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod } 2805e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod else 2815e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod if (is_joiner (info[i])) 2825e72071062c015237b79fbd0521341a63166a204Behdad Esfahbod break; 283cfd4382ec1af91640129551697de36fd42c0849aBehdad Esfahbod } while (i > limit); 284743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod if (base < start) 285743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod base = start; /* Just in case... */ 286743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 2873d25079f8d6be81b9b4b91d3a97016b8a572f571Behdad Esfahbod /* -> If the syllable starts with Ra + Halant (in a script that has Reph) 2883d25079f8d6be81b9b4b91d3a97016b8a572f571Behdad Esfahbod * and has more than one consonant, Ra is excluded from candidates for 2893d25079f8d6be81b9b4b91d3a97016b8a572f571Behdad Esfahbod * base consonants. */ 2903d25079f8d6be81b9b4b91d3a97016b8a572f571Behdad Esfahbod if (has_reph && base == start) { 2913d25079f8d6be81b9b4b91d3a97016b8a572f571Behdad Esfahbod /* Have no other consonant, so Reph is not formed and Ra becomes base. */ 2923d25079f8d6be81b9b4b91d3a97016b8a572f571Behdad Esfahbod has_reph = false; 2933d25079f8d6be81b9b4b91d3a97016b8a572f571Behdad Esfahbod } 2943d25079f8d6be81b9b4b91d3a97016b8a572f571Behdad Esfahbod 2953d25079f8d6be81b9b4b91d3a97016b8a572f571Behdad Esfahbod 296743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* 2. Decompose and reorder Matras: 297743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 298743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * Each matra and any syllable modifier sign in the cluster are moved to the 299743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * appropriate position relative to the consonant(s) in the cluster. The 300743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * shaping engine decomposes two- or three-part matras into their constituent 301743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * parts before any repositioning. Matra characters are classified by which 302743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * consonant in a conjunct they have affinity for and are reordered to the 303743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * following positions: 304743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 305743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o Before first half form in the syllable 306743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o After subjoined consonants 307743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o After post-form consonant 308743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * o After main consonant (for above marks) 309743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 310743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * IMPLEMENTATION NOTES: 311743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 312743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * The normalize() routine has already decomposed matras for us, so we don't 313743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * need to worry about that. 314743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod */ 315743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 316743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 317743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* 3. Reorder marks to canonical order: 318743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 319743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * Adjacent nukta and halant or nukta and vedic sign are always repositioned 320743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * if necessary, so that the nukta is first. 321743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 322743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * IMPLEMENTATION NOTES: 323743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * 324743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * We don't need to do this: the normalize() routine already did this for us. 325743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod */ 326743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 327743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 32845d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod /* Reorder characters */ 32945d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 33045d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod for (i = start; i < base; i++) 331dbccf87eef0d26838fa4bb3ae26410f6c4818836Behdad Esfahbod info[i].indic_position() = POS_PRE_C; 332dbccf87eef0d26838fa4bb3ae26410f6c4818836Behdad Esfahbod info[base].indic_position() = POS_BASE_C; 33345d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 334fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod /* Handle beginning Ra */ 335dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod if (has_reph) 336dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod info[start].indic_position() = POS_RA_TO_BECOME_REPH; 337fd06bf56110e73826b3d5c73ac964e2609450d46Behdad Esfahbod 338f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod /* For old-style Indic script tags, move the first post-base Halant after 339f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod * last consonant. */ 340f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod if ((map->get_chosen_script (0) & 0x000000FF) != '2') { 341f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod /* We should only do this for Indic scripts which have a version two I guess. */ 342f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod for (i = base + 1; i < end; i++) 343f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod if (info[i].indic_category() == OT_H) { 344f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod unsigned int j; 345f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod for (j = end - 1; j > i; j--) 346190eb31a16178269aecaf5d2ecc9012f956749f4Behdad Esfahbod if (is_consonant (info[j])) 347f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod break; 348f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod if (j > i) { 349f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod /* Move Halant to after last consonant. */ 350f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod hb_glyph_info_t t = info[i]; 351f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod memmove (&info[i], &info[i + 1], (j - i) * sizeof (info[0])); 352f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod info[j] = t; 353f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod } 354f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod break; 355f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod } 356f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod } 357f5bc2725cb892264ba223e0a49f7fd2c622a0730Behdad Esfahbod 35845d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod /* Attach ZWJ, ZWNJ, nukta, and halant to previous char to move with them. */ 35945d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod for (i = start + 1; i < end; i++) 360ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod if ((FLAG (info[i].indic_category()) & 36145d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod (FLAG (OT_ZWNJ) | FLAG (OT_ZWJ) | FLAG (OT_N) | FLAG (OT_H)))) 362ee58f3bc75d2d071a71b94063bf12205a5871acbBehdad Esfahbod info[i].indic_position() = info[i - 1].indic_position(); 36345d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 36445d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod /* We do bubble-sort, skip malicious clusters attempts */ 365b99d63ae114fb58f129562b293a8a66543d499adBehdad Esfahbod if (end - start < 64) 366a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod { 367a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod /* Sit tight, rock 'n roll! */ 368d3637edb248162970e202e9d0671540274192844Behdad Esfahbod hb_bubble_sort (info + start, end - start, compare_indic_order); 369a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod /* Find base again */ 370a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod base = end; 371a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod for (i = start; i < end; i++) 372a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod if (info[i].indic_position() == POS_BASE_C) { 373a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod base = i; 374a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod break; 375a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod } 376a391ff50b9a7b6ac3e58d199ea726b20ee6839bbBehdad Esfahbod } 37745d6f29f15f1d2323bcaa2498aed23ff0c8a1567Behdad Esfahbod 378743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* Setup masks now */ 379743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 380281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod { 381281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod hb_mask_t mask; 382281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod 383dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod /* Reph */ 384dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod if (has_reph) 385daf3234bdc82c669302599a76d2b14f5e69989dbBehdad Esfahbod info[start].mask |= mask_array[RPHF]; 386dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod 387281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod /* Pre-base */ 388281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod mask = mask_array[HALF] | mask_array[AKHN] | mask_array[CJCT]; 389281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod for (i = start; i < base; i++) 390281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod info[i].mask |= mask; 391281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod /* Base */ 392281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod mask = mask_array[AKHN] | mask_array[CJCT]; 393281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod info[base].mask |= mask; 394281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod /* Post-base */ 395281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod mask = mask_array[BLWF] | mask_array[PSTF] | mask_array[CJCT]; 396281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod for (i = base + 1; i < end; i++) 397281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod info[i].mask |= mask; 398281683995a46ed37aeeb84061249758c59822457Behdad Esfahbod } 3999da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod 4009da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod /* Apply ZWJ/ZWNJ effects */ 4019da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod for (i = start + 1; i < end; i++) 4029da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod if (is_joiner (info[i])) { 4039da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod bool non_joiner = info[i].indic_category() == OT_ZWNJ; 4046b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod unsigned int j = i; 4059da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod 4069da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod do { 4079da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod j--; 4086b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod 409a91c58bf98258a34e5f7c1ad39a38db58fadc4b9Behdad Esfahbod /* Reading the Unicode and OpenType specs, I think the following line 410a91c58bf98258a34e5f7c1ad39a38db58fadc4b9Behdad Esfahbod * is correct, but this is not what the test suite expects currently. 411a91c58bf98258a34e5f7c1ad39a38db58fadc4b9Behdad Esfahbod * The test suite has been drinking, not me... But disable while 412a91c58bf98258a34e5f7c1ad39a38db58fadc4b9Behdad Esfahbod * investigating. 413a91c58bf98258a34e5f7c1ad39a38db58fadc4b9Behdad Esfahbod */ 414a91c58bf98258a34e5f7c1ad39a38db58fadc4b9Behdad Esfahbod //info[j].mask &= !mask_array[CJCT]; 4156b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod if (non_joiner) 4166b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod info[j].mask &= !mask_array[HALF]; 4176b37bc80843e38ca7b62500f95fd70c08af68d62Behdad Esfahbod 4189da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod } while (j > start && !is_consonant (info[j])); 4199da0487cd452d780673e24329ce03e174a4ef83bBehdad Esfahbod } 420743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 421743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 422743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 423743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 424ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbodinitial_reordering_vowel_syllable (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array, 425ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int start, unsigned int end) 426743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 427c5306b6861cfaa50af40e8ceb058791fa06d7981Behdad Esfahbod /* We made the vowels look like consonants. So let's call the consonant logic! */ 428c5306b6861cfaa50af40e8ceb058791fa06d7981Behdad Esfahbod initial_reordering_consonant_syllable (map, buffer, mask_array, start, end); 429743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 430743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 431743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 432ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbodinitial_reordering_standalone_cluster (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array, 433ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int start, unsigned int end) 434743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 4351a1fa8c655a082fc1439608457ba717306cc83caBehdad Esfahbod /* We made the vowels look like consonants. So let's call the consonant logic! */ 4361a1fa8c655a082fc1439608457ba717306cc83caBehdad Esfahbod initial_reordering_consonant_syllable (map, buffer, mask_array, start, end); 437743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 438743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 439743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 440ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbodinitial_reordering_non_indic (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array, 441743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod unsigned int start, unsigned int end) 442743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 443743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod /* Nothing to do right now. If we ever switch to using the output 444743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod * buffer in the reordering process, we'd need to next_glyph() here. */ 445743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 446743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 447743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod#include "hb-ot-shape-complex-indic-machine.hh" 448743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 449743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 450743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodinitial_reordering (const hb_ot_map_t *map, 451743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_face_t *face, 452743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod hb_buffer_t *buffer, 453743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod void *user_data HB_UNUSED) 454743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 455b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod hb_mask_t mask_array[ARRAY_LENGTH (indic_basic_features)] = {0}; 456b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod unsigned int num_masks = ARRAY_LENGTH (indic_basic_features); 457b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod for (unsigned int i = 0; i < num_masks; i++) 45876f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod mask_array[i] = map->get_1_mask (indic_basic_features[i].tag); 459743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 460743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod find_syllables (map, buffer, mask_array); 461b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod} 462b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 463743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbodstatic void 464ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbodfinal_reordering_syllable (hb_buffer_t *buffer, 465ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int start, unsigned int end) 466743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod{ 4674ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod hb_glyph_info_t *info = buffer->info; 4684ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 469e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod /* 4. Final reordering: 470e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 471e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * After the localized forms and basic shaping forms GSUB features have been 472e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * applied (see below), the shaping engine performs some final glyph 473e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * reordering before applying all the remaining font features to the entire 474e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * cluster. 4754ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod */ 4764ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 4774ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod /* Find base again */ 4784ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod unsigned int base = end; 4794ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod for (unsigned int i = start; i < end; i++) 4804ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod if (info[i].indic_position() == POS_BASE_C) { 4814ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod base = i; 4824ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod break; 4834ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod } 4844ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 4854ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod if (base == start) { 4864ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod /* There's no Reph, and no left Matra to reposition. Just merge the cluster 4874ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod * and go home. */ 4884ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod buffer->merge_clusters (start, end); 4894ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod return; 4904ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod } 4914ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 4924705a7026900e51f6430f03a73c87f2df035df92Behdad Esfahbod unsigned int start_of_last_cluster = base; 4934705a7026900e51f6430f03a73c87f2df035df92Behdad Esfahbod 4944ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod /* o Reorder matras: 495e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 496e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * If a pre-base matra character had been reordered before applying basic 497e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * features, the glyph can be moved closer to the main consonant based on 498e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * whether half-forms had been formed. Actual position for the matra is 499e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * defined as “after last standalone halant glyph, after initial matra 500e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * position and before the main consonant”. If ZWJ or ZWNJ follow this 501e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * halant, position is moved after it. 5024ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod */ 5034ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 5044ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod unsigned int new_matra_pos = base - 1; 5054ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod while (new_matra_pos > start && 5064ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod !(FLAG (info[new_matra_pos].indic_category()) & (FLAG (OT_M) | FLAG (OT_H)))) 5074ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod new_matra_pos--; 5084ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod /* If we found no Halant we are done. Otherwise... */ 5094ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod if (info[new_matra_pos].indic_category() == OT_H) { 5104ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ 5114ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod if (new_matra_pos + 1 < end && is_joiner (info[new_matra_pos + 1])) 5124ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod new_matra_pos++; 5134ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 5144ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod /* Now go see if there's actually any matras... */ 5154ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod for (unsigned int i = new_matra_pos; i > start; i--) 5167708ee23cbcc8c8edce13e73b6e549b77bd8c2d0Behdad Esfahbod if (info[i - 1].indic_position () == POS_LEFT_MATRA) 5174ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod { 5184ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod unsigned int old_matra_pos = i - 1; 5194ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod hb_glyph_info_t matra = info[old_matra_pos]; 5204ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod memmove (&info[old_matra_pos], &info[old_matra_pos + 1], (new_matra_pos - old_matra_pos) * sizeof (info[0])); 5214ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod info[new_matra_pos] = matra; 5224705a7026900e51f6430f03a73c87f2df035df92Behdad Esfahbod start_of_last_cluster = MIN (new_matra_pos, start_of_last_cluster); 5234ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod new_matra_pos--; 5244ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod } 5254ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod } 5264ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 5274ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod 5284ac9e98d9d2ea973dd612dc4063cf78496c643a0Behdad Esfahbod /* o Reorder reph: 529e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 530e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * Reph’s original position is always at the beginning of the syllable, 531e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * (i.e. it is not reordered at the character reordering stage). However, 532e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * it will be reordered according to the basic-forms shaping results. 533e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * Possible positions for reph, depending on the script, are; after main, 534e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * before post-base consonant forms, and after post-base consonant forms. 535dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod */ 536dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod 537dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod /* If there's anything after the Ra that has the REPH pos, it ought to be halant. 538dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * Which means that the font has failed to ligate the Reph. In which case, we 539dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * shouldn't move. */ 540dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod if (start + 1 < end && 541dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod info[start].indic_position() == POS_RA_TO_BECOME_REPH && 542dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod info[start + 1].indic_position() != POS_RA_TO_BECOME_REPH) 543dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod { 544dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod /* 1. If reph should be positioned after post-base consonant forms, 545dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * proceed to step 5. 546dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 547dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 2. If the reph repositioning class is not after post-base: target 548dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * position is after the first explicit halant glyph between the 549dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * first post-reph consonant and last main consonant. If ZWJ or ZWNJ 550dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * are following this halant, position is moved after it. If such 551dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * position is found, this is the target position. Otherwise, 552dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * proceed to the next step. 553dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 554dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * Note: in old-implementation fonts, where classifications were 555dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * fixed in shaping engine, there was no case where reph position 556dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * will be found on this step. 557dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 558dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 3. If reph should be repositioned after the main consonant: from the 559dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * first consonant not ligated with main, or find the first 560dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * consonant that is not a potential pre-base reordering Ra. 561dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 562dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 563dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 4. If reph should be positioned before post-base consonant, find 564dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * first post-base classified consonant not ligated with main. If no 565dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * consonant is found, the target position should be before the 566dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * first matra, syllable modifier sign or vedic sign. 567dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 568dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 5. If no consonant is found in steps 3 or 4, move reph to a position 569dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * immediately before the first post-base matra, syllable modifier 570dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * sign or vedic sign that has a reordering class after the intended 571dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * reph position. For example, if the reordering position for reph 572dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * is post-main, it will skip above-base matras that also have a 573dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * post-main position. 574dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 575dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod * 6. Otherwise, reorder reph to the end of the syllable. 576dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod */ 577dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod 578dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod start_of_last_cluster = start; /* Yay, one big cluster! */ 579dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod 580dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod /* Now let's go shopping for a position. */ 581dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod unsigned int new_reph_pos = end - 1; 582dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod while (new_reph_pos > start && (FLAG (info[new_reph_pos].indic_position()) & (FLAG (POS_SMVD)))) 583dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod new_reph_pos--; 584dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod 5858df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod if (unlikely (info[new_reph_pos].indic_category() == OT_H)) { 5868df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod /* *If* the Reph is to be ending up after a Matra,Halant sequence, 5878df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod * position it before that Halant so it can interact with the Matra. 5888df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod * However, if it's a plain Consonant,Halant we shouldn't do that. 5898df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod */ 5908df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod for (unsigned int i = base + 1; i < new_reph_pos; i++) 5918df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod if (info[i].indic_category() == OT_M) { 5928df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod /* Ok, got it. */ 5938df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod new_reph_pos--; 5948df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod } 5958df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod } 5968df5636968389ac7bf8620ccd091fd4872b0bbeeBehdad Esfahbod 597dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod /* Move */ 598dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod hb_glyph_info_t reph = info[start]; 599dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod memmove (&info[start], &info[start + 1], (new_reph_pos - start) * sizeof (info[0])); 600dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod info[new_reph_pos] = reph; 601dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod } 602dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod 603dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod 604dbb105883c6e9b83e78dc8b10766cd56b98cd7e1Behdad Esfahbod /* o Reorder pre-base reordering consonants: 605e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 606e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * If a pre-base reordering consonant is found, reorder it according to 607e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * the following rules: 608e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 609e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 1. Only reorder a glyph produced by substitution during application 610e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * of the feature. (Note that a font may shape a Ra consonant with 611e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * the feature generally but block it in certain contexts.) 612e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 613e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 2. Try to find a target position the same way as for pre-base matra. 614e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * If it is found, reorder pre-base consonant glyph. 615e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 616e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * 3. If position is not found, reorder immediately before main 617e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod * consonant. 618e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod */ 619e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 620e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod /* TODO */ 621ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod buffer->merge_clusters (start, end); 622ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod} 623e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 624e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 625ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbodstatic void 626ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbodfinal_reordering (const hb_ot_map_t *map, 627ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod hb_face_t *face, 628ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod hb_buffer_t *buffer, 629ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod void *user_data HB_UNUSED) 630ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod{ 631ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int count = buffer->len; 632ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod if (!count) return; 633ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod 634ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod hb_glyph_info_t *info = buffer->info; 635ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int last = 0; 636ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod unsigned int last_syllable = info[0].indic_syllable(); 637ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod for (unsigned int i = 1; i < count; i++) 638ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod if (last_syllable != info[i].indic_syllable()) { 639ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod final_reordering_syllable (buffer, last, i); 640ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod last = i; 641ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod last_syllable = info[last].indic_syllable(); 642ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod } 643ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod final_reordering_syllable (buffer, last, count); 644e7be05702447ae270d797398132c1930cd3a9b86Behdad Esfahbod 645ef24cc8c8e2478a6352c340f4611a617646de4ccBehdad Esfahbod HB_BUFFER_DEALLOCATE_VAR (buffer, indic_syllable); 646743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category); 647743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position); 648743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod} 649743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 650743807a3ce1b2229e5307a8aea074a7544623d8dBehdad Esfahbod 651b9ddbd55930228422e82b34a141ad1b6093f5376Behdad Esfahbod 652