Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 27aba59 | 2012-05-24 15:00:01 -0400 | [diff] [blame] | 2 | * Copyright © 2011,2012 Google, Inc. |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 3 | * |
| 4 | * This is part of HarfBuzz, a text shaping library. |
| 5 | * |
| 6 | * Permission is hereby granted, without written agreement and without |
| 7 | * license or royalty fees, to use, copy, modify, and distribute this |
| 8 | * software and its documentation for any purpose, provided that the |
| 9 | * above copyright notice and the following two paragraphs appear in |
| 10 | * all copies of this software. |
| 11 | * |
| 12 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 13 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 14 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 15 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 16 | * DAMAGE. |
| 17 | * |
| 18 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 21 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 22 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 23 | * |
| 24 | * Google Author(s): Behdad Esfahbod |
| 25 | */ |
| 26 | |
Behdad Esfahbod | 7aad536 | 2019-06-26 13:21:03 -0700 | [diff] [blame] | 27 | #include "hb.hh" |
| 28 | |
| 29 | #ifndef HB_NO_OT_SHAPE |
| 30 | |
Behdad Esfahbod | 5bfb0b7 | 2022-06-03 02:56:41 -0600 | [diff] [blame] | 31 | #include "hb-ot-shaper-indic.hh" |
| 32 | #include "hb-ot-shaper-indic-machine.hh" |
| 33 | #include "hb-ot-shaper-vowel-constraints.hh" |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 34 | #include "hb-ot-layout.hh" |
Behdad Esfahbod | 352372a | 2011-07-30 19:04:02 -0400 | [diff] [blame] | 35 | |
Behdad Esfahbod | 3a83d33 | 2013-02-12 12:14:10 -0500 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * Indic shaper. |
| 39 | */ |
| 40 | |
| 41 | |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 42 | static inline void |
| 43 | set_indic_properties (hb_glyph_info_t &info) |
| 44 | { |
| 45 | hb_codepoint_t u = info.codepoint; |
| 46 | unsigned int type = hb_indic_get_categories (u); |
| 47 | |
| 48 | info.indic_category() = (indic_category_t) (type & 0xFFu); |
| 49 | info.indic_position() = (indic_position_t) (type >> 8); |
| 50 | } |
| 51 | |
Behdad Esfahbod | 10a5485 | 2022-06-10 06:34:56 -0600 | [diff] [blame] | 52 | |
| 53 | static inline bool |
| 54 | is_one_of (const hb_glyph_info_t &info, unsigned int flags) |
| 55 | { |
| 56 | /* If it ligated, all bets are off. */ |
| 57 | if (_hb_glyph_info_ligated (&info)) return false; |
| 58 | return !!(FLAG_UNSAFE (info.indic_category()) & flags); |
| 59 | } |
| 60 | |
| 61 | /* Note: |
| 62 | * |
| 63 | * We treat Vowels and placeholders as if they were consonants. This is safe because Vowels |
| 64 | * cannot happen in a consonant syllable. The plus side however is, we can call the |
| 65 | * consonant syllable logic from the vowel syllable function and get it all right! |
| 66 | * |
| 67 | * Keep in sync with consonant_categories in the generator. */ |
| 68 | #define CONSONANT_FLAGS_INDIC (FLAG (I_Cat(C)) | FLAG (I_Cat(CS)) | FLAG (I_Cat(Ra)) | FLAG (I_Cat(CM)) | FLAG (I_Cat(V)) | FLAG (I_Cat(PLACEHOLDER)) | FLAG (I_Cat(DOTTEDCIRCLE))) |
| 69 | |
| 70 | static inline bool |
| 71 | is_consonant (const hb_glyph_info_t &info) |
| 72 | { |
| 73 | return is_one_of (info, CONSONANT_FLAGS_INDIC); |
| 74 | } |
| 75 | |
Behdad Esfahbod | 9e3917f | 2022-06-10 06:20:56 -0600 | [diff] [blame] | 76 | #define JOINER_FLAGS (FLAG (I_Cat(ZWJ)) | FLAG (I_Cat(ZWNJ))) |
| 77 | |
| 78 | static inline bool |
| 79 | is_joiner (const hb_glyph_info_t &info) |
| 80 | { |
| 81 | return is_one_of (info, JOINER_FLAGS); |
| 82 | } |
| 83 | |
| 84 | static inline bool |
| 85 | is_halant (const hb_glyph_info_t &info) |
| 86 | { |
| 87 | return is_one_of (info, FLAG (I_Cat(H))); |
| 88 | } |
| 89 | |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 90 | struct hb_indic_would_substitute_feature_t |
| 91 | { |
| 92 | void init (const hb_ot_map_t *map, hb_tag_t feature_tag, bool zero_context_) |
| 93 | { |
| 94 | zero_context = zero_context_; |
Behdad Esfahbod | 55a1e0b | 2022-07-20 13:10:28 -0600 | [diff] [blame] | 95 | lookups = map->get_stage_lookups (0/*GSUB*/, |
| 96 | map->get_feature_stage (0/*GSUB*/, feature_tag)); |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | bool would_substitute (const hb_codepoint_t *glyphs, |
| 100 | unsigned int glyphs_count, |
| 101 | hb_face_t *face) const |
| 102 | { |
Behdad Esfahbod | 55a1e0b | 2022-07-20 13:10:28 -0600 | [diff] [blame] | 103 | for (const auto &lookup : lookups) |
| 104 | if (hb_ot_layout_lookup_would_substitute (face, lookup.index, glyphs, glyphs_count, zero_context)) |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 105 | return true; |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | private: |
Behdad Esfahbod | 55a1e0b | 2022-07-20 13:10:28 -0600 | [diff] [blame] | 110 | hb_array_t<const hb_ot_map_t::lookup_map_t> lookups; |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 111 | bool zero_context; |
| 112 | }; |
| 113 | |
| 114 | |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 115 | /* |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 116 | * Indic configurations. Note that we do not want to keep every single script-specific |
| 117 | * behavior in these tables necessarily. This should mainly be used for per-script |
| 118 | * properties that are cheaper keeping here, than in the code. Ie. if, say, one and |
| 119 | * only one script has an exception, that one script can be if'ed directly in the code, |
| 120 | * instead of adding a new flag in these structs. |
| 121 | */ |
| 122 | |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 123 | enum reph_position_t { |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 124 | REPH_POS_AFTER_MAIN = POS_AFTER_MAIN, |
| 125 | REPH_POS_BEFORE_SUB = POS_BEFORE_SUB, |
| 126 | REPH_POS_AFTER_SUB = POS_AFTER_SUB, |
| 127 | REPH_POS_BEFORE_POST = POS_BEFORE_POST, |
Behdad Esfahbod | 0758953 | 2018-01-05 15:08:28 +0000 | [diff] [blame] | 128 | REPH_POS_AFTER_POST = POS_AFTER_POST |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 129 | }; |
| 130 | enum reph_mode_t { |
| 131 | REPH_MODE_IMPLICIT, /* Reph formed out of initial Ra,H sequence. */ |
| 132 | REPH_MODE_EXPLICIT, /* Reph formed out of initial Ra,H,ZWJ sequence. */ |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 133 | REPH_MODE_LOG_REPHA /* Encoded Repha character, needs reordering. */ |
| 134 | }; |
Behdad Esfahbod | 8acbb6b | 2013-10-15 12:15:49 +0200 | [diff] [blame] | 135 | enum blwf_mode_t { |
| 136 | BLWF_MODE_PRE_AND_POST, /* Below-forms feature applied to pre-base and post-base. */ |
| 137 | BLWF_MODE_POST_ONLY /* Below-forms feature applied to post-base only. */ |
| 138 | }; |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 139 | struct indic_config_t |
| 140 | { |
| 141 | hb_script_t script; |
| 142 | bool has_old_spec; |
| 143 | hb_codepoint_t virama; |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 144 | reph_position_t reph_pos; |
| 145 | reph_mode_t reph_mode; |
Behdad Esfahbod | 8acbb6b | 2013-10-15 12:15:49 +0200 | [diff] [blame] | 146 | blwf_mode_t blwf_mode; |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | static const indic_config_t indic_configs[] = |
| 150 | { |
| 151 | /* Default. Should be first. */ |
David Corbett | 78c5ae3 | 2022-06-25 13:32:04 -0400 | [diff] [blame] | 152 | {HB_SCRIPT_INVALID, false, 0,REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST}, |
| 153 | {HB_SCRIPT_DEVANAGARI,true, 0x094Du,REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST}, |
| 154 | {HB_SCRIPT_BENGALI, true, 0x09CDu,REPH_POS_AFTER_SUB, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST}, |
| 155 | {HB_SCRIPT_GURMUKHI, true, 0x0A4Du,REPH_POS_BEFORE_SUB, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST}, |
| 156 | {HB_SCRIPT_GUJARATI, true, 0x0ACDu,REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST}, |
| 157 | {HB_SCRIPT_ORIYA, true, 0x0B4Du,REPH_POS_AFTER_MAIN, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST}, |
| 158 | {HB_SCRIPT_TAMIL, true, 0x0BCDu,REPH_POS_AFTER_POST, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST}, |
| 159 | {HB_SCRIPT_TELUGU, true, 0x0C4Du,REPH_POS_AFTER_POST, REPH_MODE_EXPLICIT, BLWF_MODE_POST_ONLY}, |
| 160 | {HB_SCRIPT_KANNADA, true, 0x0CCDu,REPH_POS_AFTER_POST, REPH_MODE_IMPLICIT, BLWF_MODE_POST_ONLY}, |
| 161 | {HB_SCRIPT_MALAYALAM, true, 0x0D4Du,REPH_POS_AFTER_MAIN, REPH_MODE_LOG_REPHA,BLWF_MODE_PRE_AND_POST}, |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | |
Behdad Esfahbod | 1676f60 | 2018-09-24 17:55:03 -0400 | [diff] [blame] | 165 | static const hb_ot_map_feature_t |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 166 | indic_features[] = |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 167 | { |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 168 | /* |
| 169 | * Basic features. |
Behdad Esfahbod | 62a535f | 2021-08-03 10:11:27 -0600 | [diff] [blame] | 170 | * These features are applied in order, one at a time, after initial_reordering, |
| 171 | * constrained to the syllable. |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 172 | */ |
Behdad Esfahbod | 044d7a0 | 2022-03-28 12:38:56 -0600 | [diff] [blame] | 173 | {HB_TAG('n','u','k','t'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 174 | {HB_TAG('a','k','h','n'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 175 | {HB_TAG('r','p','h','f'), F_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 176 | {HB_TAG('r','k','r','f'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 177 | {HB_TAG('p','r','e','f'), F_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 178 | {HB_TAG('b','l','w','f'), F_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 179 | {HB_TAG('a','b','v','f'), F_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 180 | {HB_TAG('h','a','l','f'), F_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 181 | {HB_TAG('p','s','t','f'), F_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 182 | {HB_TAG('v','a','t','u'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 183 | {HB_TAG('c','j','c','t'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE}, |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 184 | /* |
| 185 | * Other features. |
Behdad Esfahbod | 62a535f | 2021-08-03 10:11:27 -0600 | [diff] [blame] | 186 | * These features are applied all at once, after final_reordering, constrained |
| 187 | * to the syllable. |
Behdad Esfahbod | a01cbf6 | 2013-10-15 16:37:53 +0200 | [diff] [blame] | 188 | * Default Bengali font in Windows for example has intermixed |
| 189 | * lookups for init,pres,abvs,blws features. |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 190 | */ |
Behdad Esfahbod | 044d7a0 | 2022-03-28 12:38:56 -0600 | [diff] [blame] | 191 | {HB_TAG('i','n','i','t'), F_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 192 | {HB_TAG('p','r','e','s'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 193 | {HB_TAG('a','b','v','s'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 194 | {HB_TAG('b','l','w','s'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 195 | {HB_TAG('p','s','t','s'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE}, |
| 196 | {HB_TAG('h','a','l','n'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE}, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 197 | }; |
| 198 | |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 199 | /* |
| 200 | * Must be in the same order as the indic_features array. |
| 201 | */ |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 202 | enum { |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 203 | _INDIC_NUKT, |
| 204 | _INDIC_AKHN, |
| 205 | INDIC_RPHF, |
| 206 | _INDIC_RKRF, |
| 207 | INDIC_PREF, |
| 208 | INDIC_BLWF, |
| 209 | INDIC_ABVF, |
| 210 | INDIC_HALF, |
| 211 | INDIC_PSTF, |
| 212 | _INDIC_VATU, |
| 213 | _INDIC_CJCT, |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 214 | |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 215 | INDIC_INIT, |
| 216 | _INDIC_PRES, |
| 217 | _INDIC_ABVS, |
| 218 | _INDIC_BLWS, |
| 219 | _INDIC_PSTS, |
| 220 | _INDIC_HALN, |
Behdad Esfahbod | 3583fb0 | 2018-09-23 22:33:38 -0400 | [diff] [blame] | 221 | |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 222 | INDIC_NUM_FEATURES, |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 223 | INDIC_BASIC_FEATURES = INDIC_INIT, /* Don't forget to update this! */ |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 224 | }; |
| 225 | |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 226 | static bool |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 227 | setup_syllables_indic (const hb_ot_shape_plan_t *plan, |
| 228 | hb_font_t *font, |
| 229 | hb_buffer_t *buffer); |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 230 | static bool |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 231 | initial_reordering_indic (const hb_ot_shape_plan_t *plan, |
| 232 | hb_font_t *font, |
| 233 | hb_buffer_t *buffer); |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 234 | static bool |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 235 | final_reordering_indic (const hb_ot_shape_plan_t *plan, |
| 236 | hb_font_t *font, |
| 237 | hb_buffer_t *buffer); |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 238 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 239 | static void |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 240 | collect_features_indic (hb_ot_shape_planner_t *plan) |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 241 | { |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 242 | hb_ot_map_builder_t *map = &plan->map; |
| 243 | |
Behdad Esfahbod | 166b5cf | 2012-09-07 14:55:07 -0400 | [diff] [blame] | 244 | /* Do this before any lookups have been applied. */ |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 245 | map->add_gsub_pause (setup_syllables_indic); |
Behdad Esfahbod | 166b5cf | 2012-09-07 14:55:07 -0400 | [diff] [blame] | 246 | |
Behdad Esfahbod | 044d7a0 | 2022-03-28 12:38:56 -0600 | [diff] [blame] | 247 | map->enable_feature (HB_TAG('l','o','c','l'), F_PER_SYLLABLE); |
Behdad Esfahbod | a54a550 | 2011-07-20 16:42:10 -0400 | [diff] [blame] | 248 | /* The Indic specs do not require ccmp, but we apply it here since if |
| 249 | * there is a use of it, it's typically at the beginning. */ |
Behdad Esfahbod | 044d7a0 | 2022-03-28 12:38:56 -0600 | [diff] [blame] | 250 | map->enable_feature (HB_TAG('c','c','m','p'), F_PER_SYLLABLE); |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 251 | |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 252 | |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 253 | unsigned int i = 0; |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 254 | map->add_gsub_pause (initial_reordering_indic); |
Behdad Esfahbod | 3583fb0 | 2018-09-23 22:33:38 -0400 | [diff] [blame] | 255 | |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 256 | for (; i < INDIC_BASIC_FEATURES; i++) { |
Behdad Esfahbod | 1676f60 | 2018-09-24 17:55:03 -0400 | [diff] [blame] | 257 | map->add_feature (indic_features[i]); |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 258 | map->add_gsub_pause (nullptr); |
Behdad Esfahbod | 412b918 | 2012-05-09 11:07:18 +0200 | [diff] [blame] | 259 | } |
Behdad Esfahbod | 3583fb0 | 2018-09-23 22:33:38 -0400 | [diff] [blame] | 260 | |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 261 | map->add_gsub_pause (final_reordering_indic); |
Behdad Esfahbod | 3583fb0 | 2018-09-23 22:33:38 -0400 | [diff] [blame] | 262 | |
Behdad Esfahbod | 3583fb0 | 2018-09-23 22:33:38 -0400 | [diff] [blame] | 263 | for (; i < INDIC_NUM_FEATURES; i++) |
Behdad Esfahbod | 1676f60 | 2018-09-24 17:55:03 -0400 | [diff] [blame] | 264 | map->add_feature (indic_features[i]); |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 265 | } |
| 266 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 267 | static void |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 268 | override_features_indic (hb_ot_shape_planner_t *plan) |
Behdad Esfahbod | d96838e | 2012-07-16 20:26:57 -0400 | [diff] [blame] | 269 | { |
Behdad Esfahbod | 1676f60 | 2018-09-24 17:55:03 -0400 | [diff] [blame] | 270 | plan->map.disable_feature (HB_TAG('l','i','g','a')); |
Behdad Esfahbod | ad2ab1d | 2022-06-24 11:08:35 -0600 | [diff] [blame] | 271 | plan->map.add_gsub_pause (hb_syllabic_clear_var); // Don't need syllables anymore, use stop to free buffer var |
Behdad Esfahbod | d96838e | 2012-07-16 20:26:57 -0400 | [diff] [blame] | 272 | } |
| 273 | |
Behdad Esfahbod | 867361c | 2011-06-17 18:35:46 -0400 | [diff] [blame] | 274 | |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 275 | struct indic_shape_plan_t |
| 276 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 277 | bool load_virama_glyph (hb_font_t *font, hb_codepoint_t *pglyph) const |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame] | 278 | { |
Behdad Esfahbod | f73c15c | 2022-08-03 12:54:03 -0600 | [diff] [blame] | 279 | hb_codepoint_t glyph = virama_glyph; |
Behdad Esfahbod | 4bc16ac | 2018-07-31 21:05:51 -0700 | [diff] [blame] | 280 | if (unlikely (glyph == (hb_codepoint_t) -1)) |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame] | 281 | { |
Behdad Esfahbod | 8b5bc14 | 2016-02-24 19:05:23 +0900 | [diff] [blame] | 282 | if (!config->virama || !font->get_nominal_glyph (config->virama, &glyph)) |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame] | 283 | glyph = 0; |
| 284 | /* Technically speaking, the spec says we should apply 'locl' to virama too. |
| 285 | * Maybe one day... */ |
| 286 | |
Behdad Esfahbod | 8b5bc14 | 2016-02-24 19:05:23 +0900 | [diff] [blame] | 287 | /* Our get_nominal_glyph() function needs a font, so we can't get the virama glyph |
Behdad Esfahbod | 4bc16ac | 2018-07-31 21:05:51 -0700 | [diff] [blame] | 288 | * during shape planning... Instead, overwrite it here. */ |
Behdad Esfahbod | f73c15c | 2022-08-03 12:54:03 -0600 | [diff] [blame] | 289 | virama_glyph = (int) glyph; |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | *pglyph = glyph; |
| 293 | return glyph != 0; |
| 294 | } |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 295 | |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 296 | const indic_config_t *config; |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 297 | |
| 298 | bool is_old_spec; |
Behdad Esfahbod | a1394a2 | 2019-05-12 15:47:46 -0700 | [diff] [blame] | 299 | #ifndef HB_NO_UNISCRIBE_BUG_COMPATIBLE |
Behdad Esfahbod | 1bc7a8d | 2018-09-10 22:51:26 +0200 | [diff] [blame] | 300 | bool uniscribe_bug_compatible; |
Behdad Esfahbod | 73943bd | 2019-05-13 14:48:31 -0700 | [diff] [blame] | 301 | #else |
| 302 | static constexpr bool uniscribe_bug_compatible = false; |
Behdad Esfahbod | a1394a2 | 2019-05-12 15:47:46 -0700 | [diff] [blame] | 303 | #endif |
Behdad Esfahbod | 4bc16ac | 2018-07-31 21:05:51 -0700 | [diff] [blame] | 304 | mutable hb_atomic_int_t virama_glyph; |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 305 | |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 306 | hb_indic_would_substitute_feature_t rphf; |
| 307 | hb_indic_would_substitute_feature_t pref; |
| 308 | hb_indic_would_substitute_feature_t blwf; |
| 309 | hb_indic_would_substitute_feature_t pstf; |
Behdad Esfahbod | b6d0f15 | 2019-12-05 12:19:52 +0000 | [diff] [blame] | 310 | hb_indic_would_substitute_feature_t vatu; |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 311 | |
| 312 | hb_mask_t mask_array[INDIC_NUM_FEATURES]; |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | static void * |
| 316 | data_create_indic (const hb_ot_shape_plan_t *plan) |
| 317 | { |
Behdad Esfahbod | 2337f0d | 2021-07-08 10:58:50 -0600 | [diff] [blame] | 318 | indic_shape_plan_t *indic_plan = (indic_shape_plan_t *) hb_calloc (1, sizeof (indic_shape_plan_t)); |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 319 | if (unlikely (!indic_plan)) |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 320 | return nullptr; |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 321 | |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 322 | indic_plan->config = &indic_configs[0]; |
| 323 | for (unsigned int i = 1; i < ARRAY_LENGTH (indic_configs); i++) |
| 324 | if (plan->props.script == indic_configs[i].script) { |
| 325 | indic_plan->config = &indic_configs[i]; |
| 326 | break; |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 327 | } |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 328 | |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 329 | indic_plan->is_old_spec = indic_plan->config->has_old_spec && ((plan->map.chosen_script[0] & 0x000000FFu) != '2'); |
Behdad Esfahbod | a1394a2 | 2019-05-12 15:47:46 -0700 | [diff] [blame] | 330 | #ifndef HB_NO_UNISCRIBE_BUG_COMPATIBLE |
Behdad Esfahbod | 1bc7a8d | 2018-09-10 22:51:26 +0200 | [diff] [blame] | 331 | indic_plan->uniscribe_bug_compatible = hb_options ().uniscribe_bug_compatible; |
Behdad Esfahbod | a1394a2 | 2019-05-12 15:47:46 -0700 | [diff] [blame] | 332 | #endif |
Behdad Esfahbod | f73c15c | 2022-08-03 12:54:03 -0600 | [diff] [blame] | 333 | indic_plan->virama_glyph = -1; |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 334 | |
Behdad Esfahbod | b5a0f69 | 2013-10-17 18:04:23 +0200 | [diff] [blame] | 335 | /* Use zero-context would_substitute() matching for new-spec of the main |
Behdad Esfahbod | 508cc3d | 2015-12-17 17:31:17 +0000 | [diff] [blame] | 336 | * Indic scripts, and scripts with one spec only, but not for old-specs. |
| 337 | * The new-spec for all dual-spec scripts says zero-context matching happens. |
| 338 | * |
| 339 | * However, testing with Malayalam shows that old and new spec both allow |
| 340 | * context. Testing with Bengali new-spec however shows that it doesn't. |
| 341 | * So, the heuristic here is the way it is. It should *only* be changed, |
| 342 | * as we discover more cases of what Windows does. DON'T TOUCH OTHERWISE. |
| 343 | */ |
| 344 | bool zero_context = !indic_plan->is_old_spec && plan->props.script != HB_SCRIPT_MALAYALAM; |
Behdad Esfahbod | b5a0f69 | 2013-10-17 18:04:23 +0200 | [diff] [blame] | 345 | indic_plan->rphf.init (&plan->map, HB_TAG('r','p','h','f'), zero_context); |
| 346 | indic_plan->pref.init (&plan->map, HB_TAG('p','r','e','f'), zero_context); |
| 347 | indic_plan->blwf.init (&plan->map, HB_TAG('b','l','w','f'), zero_context); |
| 348 | indic_plan->pstf.init (&plan->map, HB_TAG('p','s','t','f'), zero_context); |
Behdad Esfahbod | b6d0f15 | 2019-12-05 12:19:52 +0000 | [diff] [blame] | 349 | indic_plan->vatu.init (&plan->map, HB_TAG('v','a','t','u'), zero_context); |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 350 | |
| 351 | for (unsigned int i = 0; i < ARRAY_LENGTH (indic_plan->mask_array); i++) |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 352 | indic_plan->mask_array[i] = (indic_features[i].flags & F_GLOBAL) ? |
| 353 | 0 : plan->map.get_1_mask (indic_features[i].tag); |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 354 | |
| 355 | return indic_plan; |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static void |
| 359 | data_destroy_indic (void *data) |
| 360 | { |
Behdad Esfahbod | 2337f0d | 2021-07-08 10:58:50 -0600 | [diff] [blame] | 361 | hb_free (data); |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | static indic_position_t |
| 365 | consonant_position_from_face (const indic_shape_plan_t *indic_plan, |
Behdad Esfahbod | 684fe59 | 2013-10-17 18:30:06 +0200 | [diff] [blame] | 366 | const hb_codepoint_t consonant, |
| 367 | const hb_codepoint_t virama, |
Behdad Esfahbod | 8144936 | 2013-03-05 20:08:59 -0500 | [diff] [blame] | 368 | hb_face_t *face) |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 369 | { |
Behdad Esfahbod | 8144936 | 2013-03-05 20:08:59 -0500 | [diff] [blame] | 370 | /* For old-spec, the order of glyphs is Consonant,Virama, |
| 371 | * whereas for new-spec, it's Virama,Consonant. However, |
| 372 | * some broken fonts (like Free Sans) simply copied lookups |
| 373 | * from old-spec to new-spec without modification. |
| 374 | * And oddly enough, Uniscribe seems to respect those lookups. |
| 375 | * Eg. in the sequence U+0924,U+094D,U+0930, Uniscribe finds |
| 376 | * base at 0. The font however, only has lookups matching |
| 377 | * 930,94D in 'blwf', not the expected 94D,930 (with new-spec |
| 378 | * table). As such, we simply match both sequences. Seems |
Behdad Esfahbod | b6d0f15 | 2019-12-05 12:19:52 +0000 | [diff] [blame] | 379 | * to work. |
| 380 | * |
| 381 | * Vatu is done as well, for: |
| 382 | * https://github.com/harfbuzz/harfbuzz/issues/1587 |
| 383 | */ |
Behdad Esfahbod | 684fe59 | 2013-10-17 18:30:06 +0200 | [diff] [blame] | 384 | hb_codepoint_t glyphs[3] = {virama, consonant, virama}; |
Behdad Esfahbod | b5a0f69 | 2013-10-17 18:04:23 +0200 | [diff] [blame] | 385 | if (indic_plan->blwf.would_substitute (glyphs , 2, face) || |
Behdad Esfahbod | b6d0f15 | 2019-12-05 12:19:52 +0000 | [diff] [blame] | 386 | indic_plan->blwf.would_substitute (glyphs+1, 2, face) || |
| 387 | indic_plan->vatu.would_substitute (glyphs , 2, face) || |
| 388 | indic_plan->vatu.would_substitute (glyphs+1, 2, face)) |
Behdad Esfahbod | 8144936 | 2013-03-05 20:08:59 -0500 | [diff] [blame] | 389 | return POS_BELOW_C; |
Behdad Esfahbod | b5a0f69 | 2013-10-17 18:04:23 +0200 | [diff] [blame] | 390 | if (indic_plan->pstf.would_substitute (glyphs , 2, face) || |
Behdad Esfahbod | 684fe59 | 2013-10-17 18:30:06 +0200 | [diff] [blame] | 391 | indic_plan->pstf.would_substitute (glyphs+1, 2, face)) |
Behdad Esfahbod | 8144936 | 2013-03-05 20:08:59 -0500 | [diff] [blame] | 392 | return POS_POST_C; |
Behdad Esfahbod | 3c1666c | 2016-05-06 16:05:07 +0100 | [diff] [blame] | 393 | if (indic_plan->pref.would_substitute (glyphs , 2, face) || |
| 394 | indic_plan->pref.would_substitute (glyphs+1, 2, face)) |
Behdad Esfahbod | ae9a583 | 2013-10-17 12:24:55 +0200 | [diff] [blame] | 395 | return POS_POST_C; |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 396 | return POS_BASE_C; |
| 397 | } |
| 398 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 399 | static void |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 400 | setup_masks_indic (const hb_ot_shape_plan_t *plan HB_UNUSED, |
| 401 | hb_buffer_t *buffer, |
| 402 | hb_font_t *font HB_UNUSED) |
Behdad Esfahbod | 24eacf1 | 2012-08-02 08:42:11 -0400 | [diff] [blame] | 403 | { |
| 404 | HB_BUFFER_ALLOCATE_VAR (buffer, indic_category); |
| 405 | HB_BUFFER_ALLOCATE_VAR (buffer, indic_position); |
| 406 | |
| 407 | /* We cannot setup masks here. We save information about characters |
| 408 | * and setup masks later on in a pause-callback. */ |
| 409 | |
| 410 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 411 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | 24eacf1 | 2012-08-02 08:42:11 -0400 | [diff] [blame] | 412 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 413 | set_indic_properties (info[i]); |
Behdad Esfahbod | 24eacf1 | 2012-08-02 08:42:11 -0400 | [diff] [blame] | 414 | } |
| 415 | |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 416 | static bool |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 417 | setup_syllables_indic (const hb_ot_shape_plan_t *plan HB_UNUSED, |
| 418 | hb_font_t *font HB_UNUSED, |
| 419 | hb_buffer_t *buffer) |
Behdad Esfahbod | 166b5cf | 2012-09-07 14:55:07 -0400 | [diff] [blame] | 420 | { |
Behdad Esfahbod | 15543f7 | 2022-06-04 10:55:50 -0600 | [diff] [blame] | 421 | HB_BUFFER_ALLOCATE_VAR (buffer, syllable); |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 422 | find_syllables_indic (buffer); |
Behdad Esfahbod | 9e005c5 | 2017-08-10 18:45:33 -0700 | [diff] [blame] | 423 | foreach_syllable (buffer, start, end) |
| 424 | buffer->unsafe_to_break (start, end); |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 425 | return false; |
Behdad Esfahbod | 166b5cf | 2012-09-07 14:55:07 -0400 | [diff] [blame] | 426 | } |
| 427 | |
Behdad Esfahbod | 24eacf1 | 2012-08-02 08:42:11 -0400 | [diff] [blame] | 428 | static int |
| 429 | compare_indic_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) |
| 430 | { |
| 431 | int a = pa->indic_position(); |
| 432 | int b = pb->indic_position(); |
| 433 | |
Behdad Esfahbod | 39c132a | 2022-06-10 07:12:39 -0600 | [diff] [blame] | 434 | return (int) a - (int) b; |
Behdad Esfahbod | 24eacf1 | 2012-08-02 08:42:11 -0400 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | |
| 438 | |
| 439 | static void |
Behdad Esfahbod | 3724f13 | 2019-07-02 15:23:00 -0700 | [diff] [blame] | 440 | update_consonant_positions_indic (const hb_ot_shape_plan_t *plan, |
| 441 | hb_font_t *font, |
| 442 | hb_buffer_t *buffer) |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 443 | { |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 444 | const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data; |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 445 | |
Behdad Esfahbod | 684fe59 | 2013-10-17 18:30:06 +0200 | [diff] [blame] | 446 | hb_codepoint_t virama; |
Behdad Esfahbod | 4bc16ac | 2018-07-31 21:05:51 -0700 | [diff] [blame] | 447 | if (indic_plan->load_virama_glyph (font, &virama)) |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 448 | { |
| 449 | hb_face_t *face = font->face; |
| 450 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 451 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 452 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 453 | if (info[i].indic_position() == POS_BASE_C) |
| 454 | { |
| 455 | hb_codepoint_t consonant = info[i].codepoint; |
| 456 | info[i].indic_position() = consonant_position_from_face (indic_plan, consonant, virama, face); |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
Behdad Esfahbod | 867361c | 2011-06-17 18:35:46 -0400 | [diff] [blame] | 461 | |
Behdad Esfahbod | 7ea58db | 2012-05-11 18:58:57 +0200 | [diff] [blame] | 462 | /* Rules from: |
Ebrahim Byagowi | f24b0b9 | 2018-04-12 13:40:45 +0430 | [diff] [blame] | 463 | * https://docs.microsqoft.com/en-us/typography/script-development/devanagari */ |
Behdad Esfahbod | 7ea58db | 2012-05-11 18:58:57 +0200 | [diff] [blame] | 464 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 465 | static void |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 466 | initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan, |
| 467 | hb_face_t *face, |
| 468 | hb_buffer_t *buffer, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 469 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 470 | { |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame] | 471 | const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data; |
Behdad Esfahbod | ee58f3b | 2011-07-30 19:15:53 -0400 | [diff] [blame] | 472 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 473 | |
ebraminio | 7c6937e | 2017-11-20 14:49:22 -0500 | [diff] [blame] | 474 | /* https://github.com/harfbuzz/harfbuzz/issues/435#issuecomment-335560167 |
Unknown | 97145df | 2017-11-03 09:05:00 -0400 | [diff] [blame] | 475 | * // For compatibility with legacy usage in Kannada, |
Behdad Esfahbod | fa48ccb | 2017-10-12 14:07:37 +0200 | [diff] [blame] | 476 | * // Ra+h+ZWJ must behave like Ra+ZWJ+h... |
| 477 | */ |
| 478 | if (buffer->props.script == HB_SCRIPT_KANNADA && |
| 479 | start + 3 <= end && |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 480 | is_one_of (info[start ], FLAG (I_Cat(Ra))) && |
| 481 | is_one_of (info[start+1], FLAG (I_Cat(H))) && |
| 482 | is_one_of (info[start+2], FLAG (I_Cat(ZWJ)))) |
Behdad Esfahbod | fa48ccb | 2017-10-12 14:07:37 +0200 | [diff] [blame] | 483 | { |
| 484 | buffer->merge_clusters (start+1, start+3); |
Behdad Esfahbod | 3fd9311 | 2023-02-07 14:16:24 -0700 | [diff] [blame] | 485 | hb_swap (info[start+1], info[start+2]); |
Behdad Esfahbod | fa48ccb | 2017-10-12 14:07:37 +0200 | [diff] [blame] | 486 | } |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 487 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 488 | /* 1. Find base consonant: |
| 489 | * |
| 490 | * The shaping engine finds the base consonant of the syllable, using the |
| 491 | * following algorithm: starting from the end of the syllable, move backwards |
| 492 | * until a consonant is found that does not have a below-base or post-base |
| 493 | * form (post-base forms have to follow below-base forms), or that is not a |
Nathan Willis | 0dc03ef | 2017-12-05 17:43:09 +0000 | [diff] [blame] | 494 | * pre-base-reordering Ra, or arrive at the first consonant. The consonant |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 495 | * stopped at will be the base. |
| 496 | * |
| 497 | * o If the syllable starts with Ra + Halant (in a script that has Reph) |
| 498 | * and has more than one consonant, Ra is excluded from candidates for |
| 499 | * base consonants. |
| 500 | */ |
| 501 | |
Behdad Esfahbod | 5e72071 | 2011-07-31 17:51:50 -0400 | [diff] [blame] | 502 | unsigned int base = end; |
Behdad Esfahbod | 76b3409 | 2012-05-09 11:43:43 +0200 | [diff] [blame] | 503 | bool has_reph = false; |
| 504 | |
Behdad Esfahbod | 76b3409 | 2012-05-09 11:43:43 +0200 | [diff] [blame] | 505 | { |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 506 | /* -> If the syllable starts with Ra + Halant (in a script that has Reph) |
| 507 | * and has more than one consonant, Ra is excluded from candidates for |
| 508 | * base consonants. */ |
| 509 | unsigned int limit = start; |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 510 | if (indic_plan->mask_array[INDIC_RPHF] && |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 511 | start + 3 <= end && |
Behdad Esfahbod | 8b217f5 | 2012-12-21 15:48:32 -0500 | [diff] [blame] | 512 | ( |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 513 | (indic_plan->config->reph_mode == REPH_MODE_IMPLICIT && !is_joiner (info[start + 2])) || |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 514 | (indic_plan->config->reph_mode == REPH_MODE_EXPLICIT && info[start + 2].indic_category() == I_Cat(ZWJ)) |
Behdad Esfahbod | 3285e10 | 2012-07-18 17:22:14 -0400 | [diff] [blame] | 515 | )) |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 516 | { |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 517 | /* See if it matches the 'rphf' feature. */ |
Behdad Esfahbod | 2953112 | 2014-05-15 14:04:02 -0600 | [diff] [blame] | 518 | hb_codepoint_t glyphs[3] = {info[start].codepoint, |
| 519 | info[start + 1].codepoint, |
| 520 | indic_plan->config->reph_mode == REPH_MODE_EXPLICIT ? |
| 521 | info[start + 2].codepoint : 0}; |
| 522 | if (indic_plan->rphf.would_substitute (glyphs, 2, face) || |
| 523 | (indic_plan->config->reph_mode == REPH_MODE_EXPLICIT && |
| 524 | indic_plan->rphf.would_substitute (glyphs, 3, face))) |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 525 | { |
| 526 | limit += 2; |
| 527 | while (limit < end && is_joiner (info[limit])) |
| 528 | limit++; |
| 529 | base = start; |
| 530 | has_reph = true; |
| 531 | } |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 532 | } else if (indic_plan->config->reph_mode == REPH_MODE_LOG_REPHA && info[start].indic_category() == I_Cat(Repha)) |
Behdad Esfahbod | 8b217f5 | 2012-12-21 15:48:32 -0500 | [diff] [blame] | 533 | { |
| 534 | limit += 1; |
| 535 | while (limit < end && is_joiner (info[limit])) |
| 536 | limit++; |
| 537 | base = start; |
| 538 | has_reph = true; |
| 539 | } |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 540 | |
Behdad Esfahbod | 14dbdd9 | 2012-07-18 13:13:03 -0400 | [diff] [blame] | 541 | { |
David Corbett | 78c5ae3 | 2022-06-25 13:32:04 -0400 | [diff] [blame] | 542 | /* -> starting from the end of the syllable, move backwards */ |
| 543 | unsigned int i = end; |
| 544 | bool seen_below = false; |
| 545 | do { |
| 546 | i--; |
| 547 | /* -> until a consonant is found */ |
| 548 | if (is_consonant (info[i])) |
| 549 | { |
| 550 | /* -> that does not have a below-base or post-base form |
| 551 | * (post-base forms have to follow below-base forms), */ |
| 552 | if (info[i].indic_position() != POS_BELOW_C && |
| 553 | (info[i].indic_position() != POS_POST_C || seen_below)) |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 554 | { |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 555 | base = i; |
David Corbett | 78c5ae3 | 2022-06-25 13:32:04 -0400 | [diff] [blame] | 556 | break; |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 557 | } |
David Corbett | 78c5ae3 | 2022-06-25 13:32:04 -0400 | [diff] [blame] | 558 | if (info[i].indic_position() == POS_BELOW_C) |
| 559 | seen_below = true; |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 560 | |
David Corbett | 78c5ae3 | 2022-06-25 13:32:04 -0400 | [diff] [blame] | 561 | /* -> or that is not a pre-base-reordering Ra, |
| 562 | * |
| 563 | * IMPLEMENTATION NOTES: |
| 564 | * |
| 565 | * Our pre-base-reordering Ra's are marked POS_POST_C, so will be skipped |
| 566 | * by the logic above already. |
| 567 | */ |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 568 | |
David Corbett | 78c5ae3 | 2022-06-25 13:32:04 -0400 | [diff] [blame] | 569 | /* -> or arrive at the first consonant. The consonant stopped at will |
| 570 | * be the base. */ |
| 571 | base = i; |
| 572 | } |
| 573 | else |
| 574 | { |
| 575 | /* A ZWJ after a Halant stops the base search, and requests an explicit |
| 576 | * half form. |
| 577 | * A ZWJ before a Halant, requests a subjoined form instead, and hence |
| 578 | * search continues. This is particularly important for Bengali |
| 579 | * sequence Ra,H,Ya that should form Ya-Phalaa by subjoining Ya. */ |
| 580 | if (start < i && |
| 581 | info[i].indic_category() == I_Cat(ZWJ) && |
| 582 | info[i - 1].indic_category() == I_Cat(H)) |
| 583 | break; |
| 584 | } |
| 585 | } while (i > limit); |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 586 | } |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 587 | |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 588 | /* -> If the syllable starts with Ra + Halant (in a script that has Reph) |
| 589 | * and has more than one consonant, Ra is excluded from candidates for |
Behdad Esfahbod | 2278eef | 2012-07-24 00:26:43 -0400 | [diff] [blame] | 590 | * base consonants. |
| 591 | * |
| 592 | * Only do this for unforced Reph. (ie. not for Ra,H,ZWJ. */ |
Behdad Esfahbod | 9621e0b | 2013-02-11 06:58:27 -0500 | [diff] [blame] | 593 | if (has_reph && base == start && limit - base <= 2) { |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 594 | /* Have no other consonant, so Reph is not formed and Ra becomes base. */ |
| 595 | has_reph = false; |
| 596 | } |
Behdad Esfahbod | 5e4e21f | 2012-05-13 16:46:08 +0200 | [diff] [blame] | 597 | } |
Behdad Esfahbod | 2278eef | 2012-07-24 00:26:43 -0400 | [diff] [blame] | 598 | |
Behdad Esfahbod | 3d25079 | 2012-05-10 11:37:42 +0200 | [diff] [blame] | 599 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 600 | /* 2. Decompose and reorder Matras: |
| 601 | * |
n8willis | 40b05d7 | 2017-10-12 12:48:48 +0100 | [diff] [blame] | 602 | * Each matra and any syllable modifier sign in the syllable are moved to the |
| 603 | * appropriate position relative to the consonant(s) in the syllable. The |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 604 | * shaping engine decomposes two- or three-part matras into their constituent |
| 605 | * parts before any repositioning. Matra characters are classified by which |
| 606 | * consonant in a conjunct they have affinity for and are reordered to the |
| 607 | * following positions: |
| 608 | * |
| 609 | * o Before first half form in the syllable |
| 610 | * o After subjoined consonants |
| 611 | * o After post-form consonant |
| 612 | * o After main consonant (for above marks) |
| 613 | * |
| 614 | * IMPLEMENTATION NOTES: |
| 615 | * |
| 616 | * The normalize() routine has already decomposed matras for us, so we don't |
| 617 | * need to worry about that. |
| 618 | */ |
| 619 | |
| 620 | |
| 621 | /* 3. Reorder marks to canonical order: |
| 622 | * |
| 623 | * Adjacent nukta and halant or nukta and vedic sign are always repositioned |
| 624 | * if necessary, so that the nukta is first. |
| 625 | * |
| 626 | * IMPLEMENTATION NOTES: |
| 627 | * |
| 628 | * We don't need to do this: the normalize() routine already did this for us. |
| 629 | */ |
| 630 | |
| 631 | |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 632 | /* Reorder characters */ |
| 633 | |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 634 | for (unsigned int i = start; i < base; i++) |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 635 | info[i].indic_position() = hb_min (POS_PRE_C, (indic_position_t) info[i].indic_position()); |
Behdad Esfahbod | 55f70eb | 2012-07-17 12:50:13 -0400 | [diff] [blame] | 636 | |
Behdad Esfahbod | 075d671 | 2012-07-18 15:41:53 -0400 | [diff] [blame] | 637 | if (base < end) |
| 638 | info[base].indic_position() = POS_BASE_C; |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 639 | |
Behdad Esfahbod | fd06bf5 | 2011-07-30 20:14:44 -0400 | [diff] [blame] | 640 | /* Handle beginning Ra */ |
Behdad Esfahbod | 5e4e21f | 2012-05-13 16:46:08 +0200 | [diff] [blame] | 641 | if (has_reph) |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 642 | info[start].indic_position() = POS_RA_TO_BECOME_REPH; |
Behdad Esfahbod | fd06bf5 | 2011-07-30 20:14:44 -0400 | [diff] [blame] | 643 | |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 644 | /* For old-style Indic script tags, move the first post-base Halant after |
Behdad Esfahbod | fc0daaf | 2014-07-23 16:48:51 -0400 | [diff] [blame] | 645 | * last consonant. |
| 646 | * |
| 647 | * Reports suggest that in some scripts Uniscribe does this only if there |
Behdad Esfahbod | 92ba990 | 2018-07-31 15:19:32 -0700 | [diff] [blame] | 648 | * is *not* a Halant after last consonant already. We know that is the |
| 649 | * case for Kannada, while it reorders unconditionally in other scripts, |
| 650 | * eg. Malayalam, Bengali, and Devanagari. We don't currently know about |
Behdad Esfahbod | 5671947 | 2020-06-05 12:57:23 -0700 | [diff] [blame] | 651 | * other scripts, so we block Kannada. |
Behdad Esfahbod | fc0daaf | 2014-07-23 16:48:51 -0400 | [diff] [blame] | 652 | * |
| 653 | * Kannada test case: |
| 654 | * U+0C9A,U+0CCD,U+0C9A,U+0CCD |
| 655 | * With some versions of Lohit Kannada. |
| 656 | * https://bugs.freedesktop.org/show_bug.cgi?id=59118 |
| 657 | * |
| 658 | * Malayalam test case: |
| 659 | * U+0D38,U+0D4D,U+0D31,U+0D4D,U+0D31,U+0D4D |
| 660 | * With lohit-ttf-20121122/Lohit-Malayalam.ttf |
Behdad Esfahbod | 8b9cbe3 | 2018-06-30 12:28:03 +0430 | [diff] [blame] | 661 | * |
Behdad Esfahbod | 92ba990 | 2018-07-31 15:19:32 -0700 | [diff] [blame] | 662 | * Bengali test case: |
Behdad Esfahbod | 8b9cbe3 | 2018-06-30 12:28:03 +0430 | [diff] [blame] | 663 | * U+0998,U+09CD,U+09AF,U+09CD |
| 664 | * With Windows XP vrinda.ttf |
| 665 | * https://github.com/harfbuzz/harfbuzz/issues/1073 |
Behdad Esfahbod | 92ba990 | 2018-07-31 15:19:32 -0700 | [diff] [blame] | 666 | * |
| 667 | * Devanagari test case: |
| 668 | * U+091F,U+094D,U+0930,U+094D |
| 669 | * With chandas.ttf |
| 670 | * https://github.com/harfbuzz/harfbuzz/issues/1071 |
Behdad Esfahbod | fc0daaf | 2014-07-23 16:48:51 -0400 | [diff] [blame] | 671 | */ |
| 672 | if (indic_plan->is_old_spec) |
| 673 | { |
Behdad Esfahbod | af876cc | 2018-07-31 15:27:29 -0700 | [diff] [blame] | 674 | bool disallow_double_halants = buffer->props.script == HB_SCRIPT_KANNADA; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 675 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 676 | if (info[i].indic_category() == I_Cat(H)) |
Behdad Esfahbod | fc0daaf | 2014-07-23 16:48:51 -0400 | [diff] [blame] | 677 | { |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 678 | unsigned int j; |
| 679 | for (j = end - 1; j > i; j--) |
Behdad Esfahbod | fc0daaf | 2014-07-23 16:48:51 -0400 | [diff] [blame] | 680 | if (is_consonant (info[j]) || |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 681 | (disallow_double_halants && info[j].indic_category() == I_Cat(H))) |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 682 | break; |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 683 | if (info[j].indic_category() != I_Cat(H) && j > i) { |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 684 | /* Move Halant to after last consonant. */ |
| 685 | hb_glyph_info_t t = info[i]; |
| 686 | memmove (&info[i], &info[i + 1], (j - i) * sizeof (info[0])); |
| 687 | info[j] = t; |
| 688 | } |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 689 | break; |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 693 | /* Attach misc marks to previous char to move with them. */ |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 694 | { |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 695 | indic_position_t last_pos = POS_START; |
| 696 | for (unsigned int i = start; i < end; i++) |
| 697 | { |
Behdad Esfahbod | 1c65746 | 2022-06-10 06:29:45 -0600 | [diff] [blame] | 698 | if ((FLAG_UNSAFE (info[i].indic_category()) & (JOINER_FLAGS | FLAG (I_Cat(N)) | FLAG (I_Cat(RS)) | FLAG (I_Cat(CM)) | FLAG (I_Cat(H))))) |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 699 | { |
| 700 | info[i].indic_position() = last_pos; |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 701 | if (unlikely (info[i].indic_category() == I_Cat(H) && |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 702 | info[i].indic_position() == POS_PRE_M)) |
| 703 | { |
| 704 | /* |
| 705 | * Uniscribe doesn't move the Halant with Left Matra. |
David Corbett | 78c5ae3 | 2022-06-25 13:32:04 -0400 | [diff] [blame] | 706 | * TEST: U+092B,U+093F,U+094D |
| 707 | * We follow. |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 708 | */ |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 709 | for (unsigned int j = i; j > start; j--) |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 710 | if (info[j - 1].indic_position() != POS_PRE_M) { |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 711 | info[i].indic_position() = info[j - 1].indic_position(); |
| 712 | break; |
| 713 | } |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 714 | } |
| 715 | } else if (info[i].indic_position() != POS_SMVD) { |
David Corbett | 260df1f | 2022-12-04 12:25:22 -0500 | [diff] [blame] | 716 | if (info[i].indic_category() == I_Cat(MPst) && |
| 717 | i > start && info[i - 1].indic_category() == I_Cat(SM)) |
| 718 | info[i - 1].indic_position() = info[i].indic_position(); |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 719 | last_pos = (indic_position_t) info[i].indic_position(); |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 720 | } |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 721 | } |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 722 | } |
Behdad Esfahbod | ddce2d8 | 2013-10-18 18:07:11 +0200 | [diff] [blame] | 723 | /* For post-base consonants let them own anything before them |
| 724 | * since the last consonant or matra. */ |
Behdad Esfahbod | 74ccc6a | 2012-07-17 11:16:19 -0400 | [diff] [blame] | 725 | { |
Behdad Esfahbod | ddce2d8 | 2013-10-18 18:07:11 +0200 | [diff] [blame] | 726 | unsigned int last = base; |
Behdad Esfahbod | 74ccc6a | 2012-07-17 11:16:19 -0400 | [diff] [blame] | 727 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | ddce2d8 | 2013-10-18 18:07:11 +0200 | [diff] [blame] | 728 | if (is_consonant (info[i])) |
| 729 | { |
| 730 | for (unsigned int j = last + 1; j < i; j++) |
| 731 | if (info[j].indic_position() < POS_SMVD) |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 732 | info[j].indic_position() = info[i].indic_position(); |
Behdad Esfahbod | ddce2d8 | 2013-10-18 18:07:11 +0200 | [diff] [blame] | 733 | last = i; |
David Corbett | 260df1f | 2022-12-04 12:25:22 -0500 | [diff] [blame] | 734 | } else if (FLAG_UNSAFE (info[i].indic_category()) & (FLAG (I_Cat(M)) | FLAG (I_Cat(MPst)))) |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 735 | last = i; |
Behdad Esfahbod | 74ccc6a | 2012-07-17 11:16:19 -0400 | [diff] [blame] | 736 | } |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 737 | |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 738 | |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 739 | { |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 740 | /* Use syllable() for sort accounting temporarily. */ |
| 741 | unsigned int syllable = info[start].syllable(); |
| 742 | for (unsigned int i = start; i < end; i++) |
| 743 | info[i].syllable() = i - start; |
| 744 | |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 745 | /* Sit tight, rock 'n roll! */ |
Behdad Esfahbod | 85846b3 | 2015-09-01 15:07:52 +0100 | [diff] [blame] | 746 | hb_stable_sort (info + start, end - start, compare_indic_order); |
Behdad Esfahbod | f53ef69 | 2022-11-04 16:00:34 -0600 | [diff] [blame] | 747 | |
| 748 | /* Find base again; also flip left-matra sequence. */ |
| 749 | unsigned first_left_matra = end; |
| 750 | unsigned last_left_matra = end; |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 751 | base = end; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 752 | for (unsigned int i = start; i < end; i++) |
Behdad Esfahbod | f53ef69 | 2022-11-04 16:00:34 -0600 | [diff] [blame] | 753 | { |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 754 | if (info[i].indic_position() == POS_BASE_C) |
| 755 | { |
| 756 | base = i; |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 757 | break; |
| 758 | } |
Behdad Esfahbod | f53ef69 | 2022-11-04 16:00:34 -0600 | [diff] [blame] | 759 | else if (info[i].indic_position() == POS_PRE_M) |
| 760 | { |
| 761 | if (first_left_matra == end) |
| 762 | first_left_matra = i; |
| 763 | last_left_matra = i; |
| 764 | } |
| 765 | } |
| 766 | /* https://github.com/harfbuzz/harfbuzz/issues/3863 */ |
| 767 | if (first_left_matra < last_left_matra) |
| 768 | { |
| 769 | /* No need to merge clusters, handled later. */ |
| 770 | buffer->reverse_range (first_left_matra, last_left_matra + 1); |
| 771 | /* Reverse back nuktas, etc. */ |
| 772 | unsigned i = first_left_matra; |
| 773 | for (unsigned j = i; j <= last_left_matra; j++) |
David Corbett | 260df1f | 2022-12-04 12:25:22 -0500 | [diff] [blame] | 774 | if (FLAG_UNSAFE (info[j].indic_category()) & (FLAG (I_Cat(M)) | FLAG (I_Cat(MPst)))) |
Behdad Esfahbod | f53ef69 | 2022-11-04 16:00:34 -0600 | [diff] [blame] | 775 | { |
| 776 | buffer->reverse_range (i, j + 1); |
| 777 | i = j + 1; |
| 778 | } |
| 779 | } |
| 780 | |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 781 | /* Things are out-of-control for post base positions, they may shuffle |
| 782 | * around like crazy. In old-spec mode, we move halants around, so in |
| 783 | * that case merge all clusters after base. Otherwise, check the sort |
| 784 | * order and merge as needed. |
Behdad Esfahbod | 5828c45 | 2015-09-01 16:26:35 +0100 | [diff] [blame] | 785 | * For pre-base stuff, we handle cluster issues in final reordering. |
| 786 | * |
| 787 | * We could use buffer->sort() for this, if there was no special |
| 788 | * reordering of pre-base stuff happening later... |
Behdad Esfahbod | ca645ac | 2018-10-27 00:39:31 -0700 | [diff] [blame] | 789 | * We don't want to merge_clusters all of that, which buffer->sort() |
Behdad Esfahbod | fd48943 | 2021-03-02 16:21:17 -0700 | [diff] [blame] | 790 | * would. Here's a concrete example: |
| 791 | * |
| 792 | * Assume there's a pre-base consonant and explicit Halant before base, |
| 793 | * followed by a prebase-reordering (left) Matra: |
| 794 | * |
| 795 | * C,H,ZWNJ,B,M |
| 796 | * |
| 797 | * At this point in reordering we would have: |
| 798 | * |
| 799 | * M,C,H,ZWNJ,B |
| 800 | * |
| 801 | * whereas in final reordering we will bring the Matra closer to Base: |
| 802 | * |
| 803 | * C,H,ZWNJ,M,B |
| 804 | * |
| 805 | * That's why we don't want to merge-clusters anything before the Base |
| 806 | * at this point. But if something moved from after Base to before it, |
| 807 | * we should merge clusters from base to them. In final-reordering, we |
| 808 | * only move things around before base, and merge-clusters up to base. |
| 809 | * These two merge-clusters from the two sides of base will interlock |
| 810 | * to merge things correctly. See: |
| 811 | * https://github.com/harfbuzz/harfbuzz/issues/2272 |
Behdad Esfahbod | 5828c45 | 2015-09-01 16:26:35 +0100 | [diff] [blame] | 812 | */ |
Behdad Esfahbod | 79b2fa6 | 2018-10-26 21:21:18 -0700 | [diff] [blame] | 813 | if (indic_plan->is_old_spec || end - start > 127) |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 814 | buffer->merge_clusters (base, end); |
| 815 | else |
| 816 | { |
| 817 | /* Note! syllable() is a one-byte field. */ |
| 818 | for (unsigned int i = base; i < end; i++) |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 819 | if (info[i].syllable() != 255) |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 820 | { |
Behdad Esfahbod | fd48943 | 2021-03-02 16:21:17 -0700 | [diff] [blame] | 821 | unsigned int min = i; |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 822 | unsigned int max = i; |
| 823 | unsigned int j = start + info[i].syllable(); |
| 824 | while (j != i) |
| 825 | { |
Behdad Esfahbod | fd48943 | 2021-03-02 16:21:17 -0700 | [diff] [blame] | 826 | min = hb_min (min, j); |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 827 | max = hb_max (max, j); |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 828 | unsigned int next = start + info[j].syllable(); |
| 829 | info[j].syllable() = 255; /* So we don't process j later again. */ |
| 830 | j = next; |
| 831 | } |
Behdad Esfahbod | fd48943 | 2021-03-02 16:21:17 -0700 | [diff] [blame] | 832 | buffer->merge_clusters (hb_max (base, min), max + 1); |
Behdad Esfahbod | 28d5dae | 2013-10-16 12:32:12 +0200 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | |
| 836 | /* Put syllable back in. */ |
| 837 | for (unsigned int i = start; i < end; i++) |
| 838 | info[i].syllable() = syllable; |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 839 | } |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 840 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 841 | /* Setup masks now */ |
| 842 | |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 843 | { |
| 844 | hb_mask_t mask; |
| 845 | |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 846 | /* Reph */ |
Behdad Esfahbod | 668c604 | 2012-05-11 15:34:13 +0200 | [diff] [blame] | 847 | for (unsigned int i = start; i < end && info[i].indic_position() == POS_RA_TO_BECOME_REPH; i++) |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 848 | info[i].mask |= indic_plan->mask_array[INDIC_RPHF]; |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 849 | |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 850 | /* Pre-base */ |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 851 | mask = indic_plan->mask_array[INDIC_HALF]; |
Behdad Esfahbod | c7dacac | 2013-10-17 12:20:24 +0200 | [diff] [blame] | 852 | if (!indic_plan->is_old_spec && |
| 853 | indic_plan->config->blwf_mode == BLWF_MODE_PRE_AND_POST) |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 854 | mask |= indic_plan->mask_array[INDIC_BLWF]; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 855 | for (unsigned int i = start; i < base; i++) |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 856 | info[i].mask |= mask; |
| 857 | /* Base */ |
Behdad Esfahbod | 20b68e6 | 2012-07-20 10:47:46 -0400 | [diff] [blame] | 858 | mask = 0; |
Behdad Esfahbod | 075d671 | 2012-07-18 15:41:53 -0400 | [diff] [blame] | 859 | if (base < end) |
| 860 | info[base].mask |= mask; |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 861 | /* Post-base */ |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 862 | mask = indic_plan->mask_array[INDIC_BLWF] | |
| 863 | indic_plan->mask_array[INDIC_ABVF] | |
| 864 | indic_plan->mask_array[INDIC_PSTF]; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 865 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 866 | info[i].mask |= mask; |
| 867 | } |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 868 | |
Behdad Esfahbod | 85c51ec | 2013-02-12 18:17:39 -0500 | [diff] [blame] | 869 | if (indic_plan->is_old_spec && |
| 870 | buffer->props.script == HB_SCRIPT_DEVANAGARI) |
| 871 | { |
| 872 | /* Old-spec eye-lash Ra needs special handling. From the |
| 873 | * spec: |
| 874 | * |
| 875 | * "The feature 'below-base form' is applied to consonants |
| 876 | * having below-base forms and following the base consonant. |
| 877 | * The exception is vattu, which may appear below half forms |
| 878 | * as well as below the base glyph. The feature 'below-base |
| 879 | * form' will be applied to all such occurrences of Ra as well." |
| 880 | * |
| 881 | * Test case: U+0924,U+094D,U+0930,U+094d,U+0915 |
| 882 | * with Sanskrit 2003 font. |
| 883 | * |
| 884 | * However, note that Ra,Halant,ZWJ is the correct way to |
| 885 | * request eyelash form of Ra, so we wouldbn't inhibit it |
| 886 | * in that sequence. |
| 887 | * |
| 888 | * Test case: U+0924,U+094D,U+0930,U+094d,U+200D,U+0915 |
| 889 | */ |
| 890 | for (unsigned int i = start; i + 1 < base; i++) |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 891 | if (info[i ].indic_category() == I_Cat(Ra) && |
| 892 | info[i+1].indic_category() == I_Cat(H) && |
Behdad Esfahbod | 85c51ec | 2013-02-12 18:17:39 -0500 | [diff] [blame] | 893 | (i + 2 == base || |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 894 | info[i+2].indic_category() != I_Cat(ZWJ))) |
Behdad Esfahbod | 85c51ec | 2013-02-12 18:17:39 -0500 | [diff] [blame] | 895 | { |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 896 | info[i ].mask |= indic_plan->mask_array[INDIC_BLWF]; |
| 897 | info[i+1].mask |= indic_plan->mask_array[INDIC_BLWF]; |
Behdad Esfahbod | 85c51ec | 2013-02-12 18:17:39 -0500 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | |
Behdad Esfahbod | 3c1666c | 2016-05-06 16:05:07 +0100 | [diff] [blame] | 901 | unsigned int pref_len = 2; |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 902 | if (indic_plan->mask_array[INDIC_PREF] && base + pref_len < end) |
Behdad Esfahbod | 17d7de9 | 2012-07-16 15:20:15 -0400 | [diff] [blame] | 903 | { |
Nathan Willis | 0dc03ef | 2017-12-05 17:43:09 +0000 | [diff] [blame] | 904 | /* Find a Halant,Ra sequence and mark it for pre-base-reordering processing. */ |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 905 | for (unsigned int i = base + 1; i + pref_len - 1 < end; i++) { |
| 906 | hb_codepoint_t glyphs[2]; |
| 907 | for (unsigned int j = 0; j < pref_len; j++) |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 908 | glyphs[j] = info[i + j].codepoint; |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 909 | if (indic_plan->pref.would_substitute (glyphs, pref_len, face)) |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 910 | { |
Behdad Esfahbod | 74f4bbf | 2013-10-17 19:07:53 +0200 | [diff] [blame] | 911 | for (unsigned int j = 0; j < pref_len; j++) |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 912 | info[i++].mask |= indic_plan->mask_array[INDIC_PREF]; |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 913 | break; |
| 914 | } |
Behdad Esfahbod | 56be677 | 2012-11-12 14:09:40 -0800 | [diff] [blame] | 915 | } |
Behdad Esfahbod | 17d7de9 | 2012-07-16 15:20:15 -0400 | [diff] [blame] | 916 | } |
| 917 | |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 918 | /* Apply ZWJ/ZWNJ effects */ |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 919 | for (unsigned int i = start + 1; i < end; i++) |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 920 | if (is_joiner (info[i])) { |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 921 | bool non_joiner = info[i].indic_category() == I_Cat(ZWNJ); |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 922 | unsigned int j = i; |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 923 | |
| 924 | do { |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 925 | j--; |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 926 | |
Behdad Esfahbod | cfc507c | 2013-02-14 10:40:12 -0500 | [diff] [blame] | 927 | /* ZWJ/ZWNJ should disable CJCT. They do that by simply |
| 928 | * being there, since we don't skip them for the CJCT |
Behdad Esfahbod | a8cf7b4 | 2013-03-19 05:53:26 -0400 | [diff] [blame] | 929 | * feature (ie. F_MANUAL_ZWJ) */ |
Behdad Esfahbod | 20b68e6 | 2012-07-20 10:47:46 -0400 | [diff] [blame] | 930 | |
| 931 | /* A ZWNJ disables HALF. */ |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 932 | if (non_joiner) |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 933 | info[j].mask &= ~indic_plan->mask_array[INDIC_HALF]; |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 934 | |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 935 | } while (j > start && !is_consonant (info[j])); |
| 936 | } |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 937 | } |
| 938 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 939 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 940 | initial_reordering_standalone_cluster (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 941 | hb_face_t *face, |
Behdad Esfahbod | 9f377ed | 2012-05-13 16:13:44 +0200 | [diff] [blame] | 942 | hb_buffer_t *buffer, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 943 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 944 | { |
Behdad Esfahbod | cf78dd4 | 2014-05-27 17:53:37 -0400 | [diff] [blame] | 945 | /* We treat placeholder/dotted-circle as if they are consonants, so we |
| 946 | * should just chain. Only if not in compatibility mode that is... */ |
Behdad Esfahbod | 18c06e1 | 2012-05-11 20:02:14 +0200 | [diff] [blame] | 947 | |
Behdad Esfahbod | ccc88e9 | 2019-05-12 16:12:06 -0700 | [diff] [blame] | 948 | const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data; |
Behdad Esfahbod | 1bc7a8d | 2018-09-10 22:51:26 +0200 | [diff] [blame] | 949 | if (indic_plan->uniscribe_bug_compatible) |
Behdad Esfahbod | 18c06e1 | 2012-05-11 20:02:14 +0200 | [diff] [blame] | 950 | { |
| 951 | /* For dotted-circle, this is what Uniscribe does: |
| 952 | * If dotted-circle is the last glyph, it just does nothing. |
| 953 | * Ie. It doesn't form Reph. */ |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 954 | if (buffer->info[end - 1].indic_category() == I_Cat(DOTTEDCIRCLE)) |
Behdad Esfahbod | 18c06e1 | 2012-05-11 20:02:14 +0200 | [diff] [blame] | 955 | return; |
| 956 | } |
| 957 | |
Behdad Esfahbod | f2c0f59 | 2012-11-12 14:02:02 -0800 | [diff] [blame] | 958 | initial_reordering_consonant_syllable (plan, face, buffer, start, end); |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static void |
Behdad Esfahbod | 3724f13 | 2019-07-02 15:23:00 -0700 | [diff] [blame] | 962 | initial_reordering_syllable_indic (const hb_ot_shape_plan_t *plan, |
| 963 | hb_face_t *face, |
| 964 | hb_buffer_t *buffer, |
| 965 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 966 | { |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 967 | indic_syllable_type_t syllable_type = (indic_syllable_type_t) (buffer->info[start].syllable() & 0x0F); |
Behdad Esfahbod | ecb0b24 | 2015-07-22 12:02:09 +0100 | [diff] [blame] | 968 | switch (syllable_type) |
| 969 | { |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 970 | case indic_vowel_syllable: /* We made the vowels look like consonants. So let's call the consonant logic! */ |
| 971 | case indic_consonant_syllable: |
Behdad Esfahbod | ecb0b24 | 2015-07-22 12:02:09 +0100 | [diff] [blame] | 972 | initial_reordering_consonant_syllable (plan, face, buffer, start, end); |
| 973 | break; |
| 974 | |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 975 | case indic_broken_cluster: /* We already inserted dotted-circles, so just call the standalone_cluster. */ |
| 976 | case indic_standalone_cluster: |
Behdad Esfahbod | ecb0b24 | 2015-07-22 12:02:09 +0100 | [diff] [blame] | 977 | initial_reordering_standalone_cluster (plan, face, buffer, start, end); |
| 978 | break; |
| 979 | |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 980 | case indic_symbol_cluster: |
| 981 | case indic_non_indic_cluster: |
Behdad Esfahbod | ecb0b24 | 2015-07-22 12:02:09 +0100 | [diff] [blame] | 982 | break; |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 986 | static bool |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 987 | initial_reordering_indic (const hb_ot_shape_plan_t *plan, |
| 988 | hb_font_t *font, |
| 989 | hb_buffer_t *buffer) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 990 | { |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 991 | bool ret = false; |
Simon Cozens | f19018d | 2020-09-17 15:08:32 +0100 | [diff] [blame] | 992 | if (!buffer->message (font, "start reordering indic initial")) |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 993 | return ret; |
Behdad Esfahbod | 0ddade4 | 2021-01-15 19:13:47 -0700 | [diff] [blame] | 994 | |
Behdad Esfahbod | 3724f13 | 2019-07-02 15:23:00 -0700 | [diff] [blame] | 995 | update_consonant_positions_indic (plan, font, buffer); |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 996 | if (hb_syllabic_insert_dotted_circles (font, buffer, |
| 997 | indic_broken_cluster, |
| 998 | I_Cat(DOTTEDCIRCLE), |
| 999 | I_Cat(Repha), |
| 1000 | POS_END)) |
| 1001 | ret = true; |
Behdad Esfahbod | 327d14e | 2012-08-31 16:49:34 -0400 | [diff] [blame] | 1002 | |
Behdad Esfahbod | ecb0b24 | 2015-07-22 12:02:09 +0100 | [diff] [blame] | 1003 | foreach_syllable (buffer, start, end) |
Behdad Esfahbod | 3724f13 | 2019-07-02 15:23:00 -0700 | [diff] [blame] | 1004 | initial_reordering_syllable_indic (plan, font->face, buffer, start, end); |
Behdad Esfahbod | 0ddade4 | 2021-01-15 19:13:47 -0700 | [diff] [blame] | 1005 | |
Simon Cozens | 428c111 | 2020-09-18 16:24:47 +0100 | [diff] [blame] | 1006 | (void) buffer->message (font, "end reordering indic initial"); |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 1007 | |
| 1008 | return ret; |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 1009 | } |
| 1010 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1011 | static void |
Behdad Esfahbod | 3724f13 | 2019-07-02 15:23:00 -0700 | [diff] [blame] | 1012 | final_reordering_syllable_indic (const hb_ot_shape_plan_t *plan, |
| 1013 | hb_buffer_t *buffer, |
| 1014 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1015 | { |
Behdad Esfahbod | 85fc6c4 | 2012-08-02 12:21:44 -0400 | [diff] [blame] | 1016 | const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data; |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1017 | hb_glyph_info_t *info = buffer->info; |
| 1018 | |
Behdad Esfahbod | 04dc52f | 2014-06-06 17:28:38 -0400 | [diff] [blame] | 1019 | |
| 1020 | /* This function relies heavily on halant glyphs. Lots of ligation |
n8willis | 40b05d7 | 2017-10-12 12:48:48 +0100 | [diff] [blame] | 1021 | * and possibly multiple substitutions happened prior to this |
Behdad Esfahbod | 04dc52f | 2014-06-06 17:28:38 -0400 | [diff] [blame] | 1022 | * phase, and that might have messed up our properties. Recover |
| 1023 | * from a particular case of that where we're fairly sure that a |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 1024 | * class of I_Cat(H) is desired but has been lost. */ |
Behdad Esfahbod | 4bc16ac | 2018-07-31 21:05:51 -0700 | [diff] [blame] | 1025 | /* We don't call load_virama_glyph(), since we know it's already |
| 1026 | * loaded. */ |
Behdad Esfahbod | f73c15c | 2022-08-03 12:54:03 -0600 | [diff] [blame] | 1027 | hb_codepoint_t virama_glyph = indic_plan->virama_glyph; |
Behdad Esfahbod | 4bc16ac | 2018-07-31 21:05:51 -0700 | [diff] [blame] | 1028 | if (virama_glyph) |
Behdad Esfahbod | 04dc52f | 2014-06-06 17:28:38 -0400 | [diff] [blame] | 1029 | { |
Behdad Esfahbod | 04dc52f | 2014-06-06 17:28:38 -0400 | [diff] [blame] | 1030 | for (unsigned int i = start; i < end; i++) |
| 1031 | if (info[i].codepoint == virama_glyph && |
| 1032 | _hb_glyph_info_ligated (&info[i]) && |
| 1033 | _hb_glyph_info_multiplied (&info[i])) |
| 1034 | { |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 1035 | /* This will make sure that this glyph passes is_halant() test. */ |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 1036 | info[i].indic_category() = I_Cat(H); |
Behdad Esfahbod | 04dc52f | 2014-06-06 17:28:38 -0400 | [diff] [blame] | 1037 | _hb_glyph_info_clear_ligated_and_multiplied (&info[i]); |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1042 | /* 4. Final reordering: |
| 1043 | * |
| 1044 | * After the localized forms and basic shaping forms GSUB features have been |
| 1045 | * applied (see below), the shaping engine performs some final glyph |
| 1046 | * reordering before applying all the remaining font features to the entire |
n8willis | 40b05d7 | 2017-10-12 12:48:48 +0100 | [diff] [blame] | 1047 | * syllable. |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1048 | */ |
| 1049 | |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 1050 | bool try_pref = !!indic_plan->mask_array[INDIC_PREF]; |
Behdad Esfahbod | 1d634cb | 2014-06-06 17:55:02 -0400 | [diff] [blame] | 1051 | |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1052 | /* Find base again */ |
Behdad Esfahbod | 5f0eaaa | 2012-07-20 15:47:24 -0400 | [diff] [blame] | 1053 | unsigned int base; |
| 1054 | for (base = start; base < end; base++) |
Behdad Esfahbod | 1d634cb | 2014-06-06 17:55:02 -0400 | [diff] [blame] | 1055 | if (info[base].indic_position() >= POS_BASE_C) |
| 1056 | { |
Behdad Esfahbod | 3c1666c | 2016-05-06 16:05:07 +0100 | [diff] [blame] | 1057 | if (try_pref && base + 1 < end) |
Behdad Esfahbod | 1d634cb | 2014-06-06 17:55:02 -0400 | [diff] [blame] | 1058 | { |
| 1059 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 1060 | if ((info[i].mask & indic_plan->mask_array[INDIC_PREF]) != 0) |
Behdad Esfahbod | 1d634cb | 2014-06-06 17:55:02 -0400 | [diff] [blame] | 1061 | { |
| 1062 | if (!(_hb_glyph_info_substituted (&info[i]) && |
| 1063 | _hb_glyph_info_ligated_and_didnt_multiply (&info[i]))) |
| 1064 | { |
| 1065 | /* Ok, this was a 'pref' candidate but didn't form any. |
| 1066 | * Base is around here... */ |
| 1067 | base = i; |
Behdad Esfahbod | 9761f9d | 2018-01-05 15:33:11 +0000 | [diff] [blame] | 1068 | while (base < end && is_halant (info[base])) |
Behdad Esfahbod | 1d634cb | 2014-06-06 17:55:02 -0400 | [diff] [blame] | 1069 | base++; |
Behdad Esfahbod | 453ded0 | 2023-03-28 13:17:15 -0600 | [diff] [blame] | 1070 | if (base < end) |
| 1071 | info[base].indic_position() = POS_BASE_C; |
Behdad Esfahbod | 1d634cb | 2014-06-06 17:55:02 -0400 | [diff] [blame] | 1072 | |
| 1073 | try_pref = false; |
| 1074 | } |
| 1075 | break; |
| 1076 | } |
Behdad Esfahbod | 453ded0 | 2023-03-28 13:17:15 -0600 | [diff] [blame] | 1077 | if (base == end) |
| 1078 | break; |
Behdad Esfahbod | 1d634cb | 2014-06-06 17:55:02 -0400 | [diff] [blame] | 1079 | } |
Behdad Esfahbod | 45b7ec3 | 2015-12-18 13:47:16 +0000 | [diff] [blame] | 1080 | /* For Malayalam, skip over unformed below- (but NOT post-) forms. */ |
| 1081 | if (buffer->props.script == HB_SCRIPT_MALAYALAM) |
| 1082 | { |
| 1083 | for (unsigned int i = base + 1; i < end; i++) |
| 1084 | { |
| 1085 | while (i < end && is_joiner (info[i])) |
| 1086 | i++; |
Behdad Esfahbod | 9761f9d | 2018-01-05 15:33:11 +0000 | [diff] [blame] | 1087 | if (i == end || !is_halant (info[i])) |
Behdad Esfahbod | 45b7ec3 | 2015-12-18 13:47:16 +0000 | [diff] [blame] | 1088 | break; |
| 1089 | i++; /* Skip halant. */ |
| 1090 | while (i < end && is_joiner (info[i])) |
| 1091 | i++; |
| 1092 | if (i < end && is_consonant (info[i]) && info[i].indic_position() == POS_BELOW_C) |
| 1093 | { |
| 1094 | base = i; |
| 1095 | info[base].indic_position() = POS_BASE_C; |
| 1096 | } |
| 1097 | } |
| 1098 | } |
Behdad Esfahbod | 1d634cb | 2014-06-06 17:55:02 -0400 | [diff] [blame] | 1099 | |
Behdad Esfahbod | 5f0eaaa | 2012-07-20 15:47:24 -0400 | [diff] [blame] | 1100 | if (start < base && info[base].indic_position() > POS_BASE_C) |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 1101 | base--; |
Behdad Esfahbod | 5f0eaaa | 2012-07-20 15:47:24 -0400 | [diff] [blame] | 1102 | break; |
| 1103 | } |
Behdad Esfahbod | a0cb9f3 | 2013-02-13 09:26:55 -0500 | [diff] [blame] | 1104 | if (base == end && start < base && |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 1105 | is_one_of (info[base - 1], FLAG (I_Cat(ZWJ)))) |
Behdad Esfahbod | a0cb9f3 | 2013-02-13 09:26:55 -0500 | [diff] [blame] | 1106 | base--; |
Behdad Esfahbod | e7ce50d | 2014-07-16 12:30:39 -0400 | [diff] [blame] | 1107 | if (base < end) |
| 1108 | while (start < base && |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 1109 | is_one_of (info[base], (FLAG (I_Cat(N)) | FLAG (I_Cat(H))))) |
Behdad Esfahbod | e7ce50d | 2014-07-16 12:30:39 -0400 | [diff] [blame] | 1110 | base--; |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1111 | |
Behdad Esfahbod | 4705a70 | 2012-05-10 13:09:08 +0200 | [diff] [blame] | 1112 | |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1113 | /* o Reorder matras: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1114 | * |
| 1115 | * If a pre-base matra character had been reordered before applying basic |
| 1116 | * features, the glyph can be moved closer to the main consonant based on |
| 1117 | * whether half-forms had been formed. Actual position for the matra is |
| 1118 | * defined as “after last standalone halant glyph, after initial matra |
| 1119 | * position and before the main consonant”. If ZWJ or ZWNJ follow this |
| 1120 | * halant, position is moved after it. |
Behdad Esfahbod | 9940504 | 2018-07-03 14:29:25 +0430 | [diff] [blame] | 1121 | * |
| 1122 | * IMPLEMENTATION NOTES: |
| 1123 | * |
| 1124 | * It looks like the last sentence is wrong. Testing, with Windows 7 Uniscribe |
| 1125 | * and Devanagari shows that the behavior is best described as: |
| 1126 | * |
| 1127 | * "If ZWJ follows this halant, matra is NOT repositioned after this halant. |
| 1128 | * If ZWNJ follows this halant, position is moved after it." |
| 1129 | * |
| 1130 | * Test case, with Adobe Devanagari or Nirmala UI: |
| 1131 | * |
| 1132 | * U+091F,U+094D,U+200C,U+092F,U+093F |
| 1133 | * (Matra moves to the middle, after ZWNJ.) |
| 1134 | * |
| 1135 | * U+091F,U+094D,U+200D,U+092F,U+093F |
| 1136 | * (Matra does NOT move, stays to the left.) |
| 1137 | * |
| 1138 | * https://github.com/harfbuzz/harfbuzz/issues/1070 |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1139 | */ |
| 1140 | |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1141 | if (start + 1 < end && start < base) /* Otherwise there can't be any pre-base matra characters. */ |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1142 | { |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1143 | /* If we lost track of base, alas, position before last thingy. */ |
| 1144 | unsigned int new_pos = base == end ? base - 2 : base - 1; |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1145 | |
Behdad Esfahbod | 27bd55b | 2012-09-05 15:11:14 -0400 | [diff] [blame] | 1146 | /* Malayalam / Tamil do not have "half" forms or explicit virama forms. |
| 1147 | * The glyphs formed by 'half' are Chillus or ligated explicit viramas. |
| 1148 | * We want to position matra after them. |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1149 | */ |
Behdad Esfahbod | 27bd55b | 2012-09-05 15:11:14 -0400 | [diff] [blame] | 1150 | if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL) |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1151 | { |
Behdad Esfahbod | 9940504 | 2018-07-03 14:29:25 +0430 | [diff] [blame] | 1152 | search: |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1153 | while (new_pos > start && |
David Corbett | 260df1f | 2022-12-04 12:25:22 -0500 | [diff] [blame] | 1154 | !(is_one_of (info[new_pos], (FLAG (I_Cat(M)) | FLAG (I_Cat(MPst)) | FLAG (I_Cat(H)))))) |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1155 | new_pos--; |
| 1156 | |
| 1157 | /* If we found no Halant we are done. |
| 1158 | * Otherwise only proceed if the Halant does |
| 1159 | * not belong to the Matra itself! */ |
Behdad Esfahbod | 9761f9d | 2018-01-05 15:33:11 +0000 | [diff] [blame] | 1160 | if (is_halant (info[new_pos]) && |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1161 | info[new_pos].indic_position() != POS_PRE_M) |
| 1162 | { |
Behdad Esfahbod | 9940504 | 2018-07-03 14:29:25 +0430 | [diff] [blame] | 1163 | #if 0 // See comment above |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1164 | /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ |
| 1165 | if (new_pos + 1 < end && is_joiner (info[new_pos + 1])) |
| 1166 | new_pos++; |
Behdad Esfahbod | 9940504 | 2018-07-03 14:29:25 +0430 | [diff] [blame] | 1167 | #endif |
| 1168 | if (new_pos + 1 < end) |
| 1169 | { |
| 1170 | /* -> If ZWJ follows this halant, matra is NOT repositioned after this halant. */ |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 1171 | if (info[new_pos + 1].indic_category() == I_Cat(ZWJ)) |
Behdad Esfahbod | 9940504 | 2018-07-03 14:29:25 +0430 | [diff] [blame] | 1172 | { |
| 1173 | /* Keep searching. */ |
| 1174 | if (new_pos > start) |
| 1175 | { |
| 1176 | new_pos--; |
| 1177 | goto search; |
| 1178 | } |
| 1179 | } |
Adrian Wong | 2f125b0 | 2019-02-13 21:04:46 +1100 | [diff] [blame] | 1180 | /* -> If ZWNJ follows this halant, position is moved after it. |
| 1181 | * |
| 1182 | * IMPLEMENTATION NOTES: |
| 1183 | * |
| 1184 | * This is taken care of by the state-machine. A Halant,ZWNJ is a terminating |
| 1185 | * sequence for a consonant syllable; any pre-base matras occurring after it |
| 1186 | * will belong to the subsequent syllable. |
| 1187 | */ |
Behdad Esfahbod | 9940504 | 2018-07-03 14:29:25 +0430 | [diff] [blame] | 1188 | } |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1189 | } |
| 1190 | else |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 1191 | new_pos = start; /* No move. */ |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1192 | } |
| 1193 | |
Behdad Esfahbod | 27bd55b | 2012-09-05 15:11:14 -0400 | [diff] [blame] | 1194 | if (start < new_pos && info[new_pos].indic_position () != POS_PRE_M) |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 1195 | { |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1196 | /* Now go see if there's actually any matras... */ |
Behdad Esfahbod | 921ce5b | 2012-07-16 15:26:56 -0400 | [diff] [blame] | 1197 | for (unsigned int i = new_pos; i > start; i--) |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 1198 | if (info[i - 1].indic_position () == POS_PRE_M) |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1199 | { |
Behdad Esfahbod | 1a1dbe9 | 2012-07-16 15:40:33 -0400 | [diff] [blame] | 1200 | unsigned int old_pos = i - 1; |
Behdad Esfahbod | 5828c45 | 2015-09-01 16:26:35 +0100 | [diff] [blame] | 1201 | if (old_pos < base && base <= new_pos) /* Shouldn't actually happen. */ |
| 1202 | base--; |
| 1203 | |
Behdad Esfahbod | 1a1dbe9 | 2012-07-16 15:40:33 -0400 | [diff] [blame] | 1204 | hb_glyph_info_t tmp = info[old_pos]; |
| 1205 | memmove (&info[old_pos], &info[old_pos + 1], (new_pos - old_pos) * sizeof (info[0])); |
| 1206 | info[new_pos] = tmp; |
Behdad Esfahbod | 5828c45 | 2015-09-01 16:26:35 +0100 | [diff] [blame] | 1207 | |
| 1208 | /* Note: this merge_clusters() is intentionally *after* the reordering. |
| 1209 | * Indic matra reordering is special and tricky... */ |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 1210 | buffer->merge_clusters (new_pos, hb_min (end, base + 1)); |
Behdad Esfahbod | 5828c45 | 2015-09-01 16:26:35 +0100 | [diff] [blame] | 1211 | |
Behdad Esfahbod | 921ce5b | 2012-07-16 15:26:56 -0400 | [diff] [blame] | 1212 | new_pos--; |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1213 | } |
Behdad Esfahbod | abb3239 | 2012-07-22 23:55:19 -0400 | [diff] [blame] | 1214 | } else { |
Behdad Esfahbod | e6b01a8 | 2012-07-23 00:11:26 -0400 | [diff] [blame] | 1215 | for (unsigned int i = start; i < base; i++) |
Behdad Esfahbod | abb3239 | 2012-07-22 23:55:19 -0400 | [diff] [blame] | 1216 | if (info[i].indic_position () == POS_PRE_M) { |
Behdad Esfahbod | 41248cc | 2019-05-07 20:54:31 -0700 | [diff] [blame] | 1217 | buffer->merge_clusters (i, hb_min (end, base + 1)); |
Behdad Esfahbod | abb3239 | 2012-07-22 23:55:19 -0400 | [diff] [blame] | 1218 | break; |
| 1219 | } |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1220 | } |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | |
| 1224 | /* o Reorder reph: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1225 | * |
| 1226 | * Reph’s original position is always at the beginning of the syllable, |
| 1227 | * (i.e. it is not reordered at the character reordering stage). However, |
| 1228 | * it will be reordered according to the basic-forms shaping results. |
| 1229 | * Possible positions for reph, depending on the script, are; after main, |
| 1230 | * before post-base consonant forms, and after post-base consonant forms. |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1231 | */ |
| 1232 | |
Behdad Esfahbod | 65a929b | 2013-10-15 18:08:05 +0200 | [diff] [blame] | 1233 | /* Two cases: |
| 1234 | * |
| 1235 | * - If repha is encoded as a sequence of characters (Ra,H or Ra,H,ZWJ), then |
| 1236 | * we should only move it if the sequence ligated to the repha form. |
| 1237 | * |
| 1238 | * - If repha is encoded separately and in the logical position, we should only |
| 1239 | * move it if it did NOT ligate. If it ligated, it's probably the font trying |
| 1240 | * to make it work without the reordering. |
| 1241 | */ |
Behdad Esfahbod | f5299ef | 2013-10-15 18:13:07 +0200 | [diff] [blame] | 1242 | if (start + 1 < end && |
| 1243 | info[start].indic_position() == POS_RA_TO_BECOME_REPH && |
Behdad Esfahbod | 3289e81 | 2022-06-09 17:46:15 -0600 | [diff] [blame] | 1244 | ((info[start].indic_category() == I_Cat(Repha)) ^ |
Behdad Esfahbod | 832a6f9 | 2014-06-04 16:57:42 -0400 | [diff] [blame] | 1245 | _hb_glyph_info_ligated_and_didnt_multiply (&info[start]))) |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1246 | { |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 1247 | unsigned int new_reph_pos; |
| 1248 | reph_position_t reph_pos = indic_plan->config->reph_pos; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1249 | |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1250 | /* 1. If reph should be positioned after post-base consonant forms, |
| 1251 | * proceed to step 5. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1252 | */ |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 1253 | if (reph_pos == REPH_POS_AFTER_POST) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1254 | { |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1255 | goto reph_step_5; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | /* 2. If the reph repositioning class is not after post-base: target |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1259 | * position is after the first explicit halant glyph between the |
| 1260 | * first post-reph consonant and last main consonant. If ZWJ or ZWNJ |
| 1261 | * are following this halant, position is moved after it. If such |
| 1262 | * position is found, this is the target position. Otherwise, |
| 1263 | * proceed to the next step. |
| 1264 | * |
| 1265 | * Note: in old-implementation fonts, where classifications were |
| 1266 | * fixed in shaping engine, there was no case where reph position |
| 1267 | * will be found on this step. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1268 | */ |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1269 | { |
| 1270 | new_reph_pos = start + 1; |
Behdad Esfahbod | 9761f9d | 2018-01-05 15:33:11 +0000 | [diff] [blame] | 1271 | while (new_reph_pos < base && !is_halant (info[new_reph_pos])) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1272 | new_reph_pos++; |
| 1273 | |
Behdad Esfahbod | 9761f9d | 2018-01-05 15:33:11 +0000 | [diff] [blame] | 1274 | if (new_reph_pos < base && is_halant (info[new_reph_pos])) |
Behdad Esfahbod | 1f91c39 | 2013-02-13 09:38:40 -0500 | [diff] [blame] | 1275 | { |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1276 | /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */ |
| 1277 | if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1])) |
| 1278 | new_reph_pos++; |
| 1279 | goto reph_move; |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | /* 3. If reph should be repositioned after the main consonant: find the |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1284 | * first consonant not ligated with main, or find the first |
Nathan Willis | 0dc03ef | 2017-12-05 17:43:09 +0000 | [diff] [blame] | 1285 | * consonant that is not a potential pre-base-reordering Ra. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1286 | */ |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 1287 | if (reph_pos == REPH_POS_AFTER_MAIN) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1288 | { |
Behdad Esfahbod | b504e06 | 2012-07-16 15:21:12 -0400 | [diff] [blame] | 1289 | new_reph_pos = base; |
Behdad Esfahbod | 34ae336 | 2012-07-20 16:17:28 -0400 | [diff] [blame] | 1290 | while (new_reph_pos + 1 < end && info[new_reph_pos + 1].indic_position() <= POS_AFTER_MAIN) |
Behdad Esfahbod | b504e06 | 2012-07-16 15:21:12 -0400 | [diff] [blame] | 1291 | new_reph_pos++; |
| 1292 | if (new_reph_pos < end) |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 1293 | goto reph_move; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | /* 4. If reph should be positioned before post-base consonant, find |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1297 | * first post-base classified consonant not ligated with main. If no |
| 1298 | * consonant is found, the target position should be before the |
| 1299 | * first matra, syllable modifier sign or vedic sign. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1300 | */ |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1301 | /* This is our take on what step 4 is trying to say (and failing, BADLY). */ |
Behdad Esfahbod | 11b0e20 | 2012-08-02 14:21:40 -0400 | [diff] [blame] | 1302 | if (reph_pos == REPH_POS_AFTER_SUB) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1303 | { |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1304 | new_reph_pos = base; |
Behdad Esfahbod | 8563099 | 2017-02-25 13:30:38 -0800 | [diff] [blame] | 1305 | while (new_reph_pos + 1 < end && |
Behdad Esfahbod | 6058f98 | 2017-10-19 11:39:52 -0700 | [diff] [blame] | 1306 | !( FLAG_UNSAFE (info[new_reph_pos + 1].indic_position()) & (FLAG (POS_POST_C) | FLAG (POS_AFTER_POST) | FLAG (POS_SMVD)))) |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 1307 | new_reph_pos++; |
| 1308 | if (new_reph_pos < end) |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 1309 | goto reph_move; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | /* 5. If no consonant is found in steps 3 or 4, move reph to a position |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1313 | * immediately before the first post-base matra, syllable modifier |
| 1314 | * sign or vedic sign that has a reordering class after the intended |
| 1315 | * reph position. For example, if the reordering position for reph |
| 1316 | * is post-main, it will skip above-base matras that also have a |
| 1317 | * post-main position. |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1318 | */ |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1319 | reph_step_5: |
| 1320 | { |
Behdad Esfahbod | d0e68db | 2012-07-20 11:25:41 -0400 | [diff] [blame] | 1321 | /* Copied from step 2. */ |
| 1322 | new_reph_pos = start + 1; |
Behdad Esfahbod | 9761f9d | 2018-01-05 15:33:11 +0000 | [diff] [blame] | 1323 | while (new_reph_pos < base && !is_halant (info[new_reph_pos])) |
Behdad Esfahbod | d0e68db | 2012-07-20 11:25:41 -0400 | [diff] [blame] | 1324 | new_reph_pos++; |
| 1325 | |
Behdad Esfahbod | 9761f9d | 2018-01-05 15:33:11 +0000 | [diff] [blame] | 1326 | if (new_reph_pos < base && is_halant (info[new_reph_pos])) |
Behdad Esfahbod | 1f91c39 | 2013-02-13 09:38:40 -0500 | [diff] [blame] | 1327 | { |
Behdad Esfahbod | d0e68db | 2012-07-20 11:25:41 -0400 | [diff] [blame] | 1328 | /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */ |
| 1329 | if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1])) |
| 1330 | new_reph_pos++; |
| 1331 | goto reph_move; |
| 1332 | } |
Behdad Esfahbod | 8df5636 | 2012-05-10 15:41:04 +0200 | [diff] [blame] | 1333 | } |
Behdad Esfahbod | e5de391 | 2020-06-17 16:54:23 -0700 | [diff] [blame] | 1334 | /* See https://github.com/harfbuzz/harfbuzz/issues/2298#issuecomment-615318654 */ |
Behdad Esfahbod | 8df5636 | 2012-05-10 15:41:04 +0200 | [diff] [blame] | 1335 | |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1336 | /* 6. Otherwise, reorder reph to the end of the syllable. |
| 1337 | */ |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1338 | { |
| 1339 | new_reph_pos = end - 1; |
| 1340 | while (new_reph_pos > start && info[new_reph_pos].indic_position() == POS_SMVD) |
| 1341 | new_reph_pos--; |
| 1342 | |
Behdad Esfahbod | 892eb78 | 2012-05-11 16:54:40 +0200 | [diff] [blame] | 1343 | /* |
| 1344 | * If the Reph is to be ending up after a Matra,Halant sequence, |
| 1345 | * position it before that Halant so it can interact with the Matra. |
| 1346 | * However, if it's a plain Consonant,Halant we shouldn't do that. |
| 1347 | * Uniscribe doesn't do this. |
| 1348 | * TEST: U+0930,U+094D,U+0915,U+094B,U+094D |
| 1349 | */ |
Behdad Esfahbod | 1bc7a8d | 2018-09-10 22:51:26 +0200 | [diff] [blame] | 1350 | if (!indic_plan->uniscribe_bug_compatible && |
Behdad Esfahbod | a1394a2 | 2019-05-12 15:47:46 -0700 | [diff] [blame] | 1351 | unlikely (is_halant (info[new_reph_pos]))) |
| 1352 | { |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1353 | for (unsigned int i = base + 1; i < new_reph_pos; i++) |
David Corbett | 260df1f | 2022-12-04 12:25:22 -0500 | [diff] [blame] | 1354 | if (FLAG_UNSAFE (info[i].indic_category()) & (FLAG (I_Cat(M)) | FLAG (I_Cat(MPst)))) |
| 1355 | { |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1356 | /* Ok, got it. */ |
| 1357 | new_reph_pos--; |
| 1358 | } |
| 1359 | } |
Behdad Esfahbod | a1394a2 | 2019-05-12 15:47:46 -0700 | [diff] [blame] | 1360 | |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1361 | goto reph_move; |
| 1362 | } |
| 1363 | |
| 1364 | reph_move: |
| 1365 | { |
| 1366 | /* Move */ |
Behdad Esfahbod | 5828c45 | 2015-09-01 16:26:35 +0100 | [diff] [blame] | 1367 | buffer->merge_clusters (start, new_reph_pos + 1); |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1368 | hb_glyph_info_t reph = info[start]; |
| 1369 | memmove (&info[start], &info[start + 1], (new_reph_pos - start) * sizeof (info[0])); |
| 1370 | info[new_reph_pos] = reph; |
Behdad Esfahbod | 5828c45 | 2015-09-01 16:26:35 +0100 | [diff] [blame] | 1371 | |
Behdad Esfahbod | f22b7e7 | 2013-02-13 07:32:46 -0500 | [diff] [blame] | 1372 | if (start < base && base <= new_reph_pos) |
| 1373 | base--; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1374 | } |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | |
Nathan Willis | 0dc03ef | 2017-12-05 17:43:09 +0000 | [diff] [blame] | 1378 | /* o Reorder pre-base-reordering consonants: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1379 | * |
Nathan Willis | 0dc03ef | 2017-12-05 17:43:09 +0000 | [diff] [blame] | 1380 | * If a pre-base-reordering consonant is found, reorder it according to |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1381 | * the following rules: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1382 | */ |
| 1383 | |
Nathan Willis | 0dc03ef | 2017-12-05 17:43:09 +0000 | [diff] [blame] | 1384 | if (try_pref && base + 1 < end) /* Otherwise there can't be any pre-base-reordering Ra. */ |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 1385 | { |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1386 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 1387 | if ((info[i].mask & indic_plan->mask_array[INDIC_PREF]) != 0) |
Behdad Esfahbod | 7881812 | 2012-07-16 15:49:08 -0400 | [diff] [blame] | 1388 | { |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1389 | /* 1. Only reorder a glyph produced by substitution during application |
| 1390 | * of the <pref> feature. (Note that a font may shape a Ra consonant with |
| 1391 | * the feature generally but block it in certain contexts.) |
| 1392 | */ |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 1393 | /* Note: We just check that something got substituted. We don't check that |
Behdad Esfahbod | 46a863d | 2013-10-27 23:24:50 +0100 | [diff] [blame] | 1394 | * the <pref> feature actually did it... |
| 1395 | * |
Behdad Esfahbod | 3c1666c | 2016-05-06 16:05:07 +0100 | [diff] [blame] | 1396 | * Reorder pref only if it ligated. */ |
| 1397 | if (_hb_glyph_info_ligated_and_didnt_multiply (&info[i])) |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1398 | { |
| 1399 | /* |
| 1400 | * 2. Try to find a target position the same way as for pre-base matra. |
| 1401 | * If it is found, reorder pre-base consonant glyph. |
| 1402 | * |
| 1403 | * 3. If position is not found, reorder immediately before main |
| 1404 | * consonant. |
| 1405 | */ |
| 1406 | |
| 1407 | unsigned int new_pos = base; |
Behdad Esfahbod | 88d3c98 | 2012-10-29 16:27:02 -0700 | [diff] [blame] | 1408 | /* Malayalam / Tamil do not have "half" forms or explicit virama forms. |
| 1409 | * The glyphs formed by 'half' are Chillus or ligated explicit viramas. |
| 1410 | * We want to position matra after them. |
| 1411 | */ |
| 1412 | if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL) |
Behdad Esfahbod | d90b8e8 | 2012-07-24 02:10:20 -0400 | [diff] [blame] | 1413 | { |
Behdad Esfahbod | 88d3c98 | 2012-10-29 16:27:02 -0700 | [diff] [blame] | 1414 | while (new_pos > start && |
David Corbett | 260df1f | 2022-12-04 12:25:22 -0500 | [diff] [blame] | 1415 | !(is_one_of (info[new_pos - 1], FLAG (I_Cat(M)) | FLAG (I_Cat(MPst)) | FLAG (I_Cat(H))))) |
Behdad Esfahbod | 88d3c98 | 2012-10-29 16:27:02 -0700 | [diff] [blame] | 1416 | new_pos--; |
Behdad Esfahbod | d90b8e8 | 2012-07-24 02:10:20 -0400 | [diff] [blame] | 1417 | } |
| 1418 | |
Behdad Esfahbod | 9761f9d | 2018-01-05 15:33:11 +0000 | [diff] [blame] | 1419 | if (new_pos > start && is_halant (info[new_pos - 1])) |
Behdad Esfahbod | 1f91c39 | 2013-02-13 09:38:40 -0500 | [diff] [blame] | 1420 | { |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1421 | /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ |
| 1422 | if (new_pos < end && is_joiner (info[new_pos])) |
| 1423 | new_pos++; |
Behdad Esfahbod | 1f91c39 | 2013-02-13 09:38:40 -0500 | [diff] [blame] | 1424 | } |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1425 | |
| 1426 | { |
| 1427 | unsigned int old_pos = i; |
Behdad Esfahbod | 5828c45 | 2015-09-01 16:26:35 +0100 | [diff] [blame] | 1428 | |
Behdad Esfahbod | e6b01a8 | 2012-07-23 00:11:26 -0400 | [diff] [blame] | 1429 | buffer->merge_clusters (new_pos, old_pos + 1); |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1430 | hb_glyph_info_t tmp = info[old_pos]; |
| 1431 | memmove (&info[new_pos + 1], &info[new_pos], (old_pos - new_pos) * sizeof (info[0])); |
| 1432 | info[new_pos] = tmp; |
Behdad Esfahbod | 5828c45 | 2015-09-01 16:26:35 +0100 | [diff] [blame] | 1433 | |
Behdad Esfahbod | f22b7e7 | 2013-02-13 07:32:46 -0500 | [diff] [blame] | 1434 | if (new_pos <= base && base < old_pos) |
| 1435 | base++; |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1436 | } |
| 1437 | } |
| 1438 | |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 1439 | break; |
Behdad Esfahbod | 7881812 | 2012-07-16 15:49:08 -0400 | [diff] [blame] | 1440 | } |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 1441 | } |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 1442 | |
| 1443 | |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 1444 | /* Apply 'init' to the Left Matra if it's a word start. */ |
David Corbett | 5a9cba9 | 2017-11-08 13:15:27 -0500 | [diff] [blame] | 1445 | if (info[start].indic_position () == POS_PRE_M) |
| 1446 | { |
| 1447 | if (!start || |
| 1448 | !(FLAG_UNSAFE (_hb_glyph_info_get_general_category (&info[start - 1])) & |
| 1449 | FLAG_RANGE (HB_UNICODE_GENERAL_CATEGORY_FORMAT, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK))) |
Behdad Esfahbod | dc480fc | 2019-07-02 15:17:56 -0700 | [diff] [blame] | 1450 | info[start].mask |= indic_plan->mask_array[INDIC_INIT]; |
David Corbett | 5a9cba9 | 2017-11-08 13:15:27 -0500 | [diff] [blame] | 1451 | else |
| 1452 | buffer->unsafe_to_break (start - 1, start + 1); |
| 1453 | } |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 1454 | |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 1455 | |
Behdad Esfahbod | 8ed248d | 2012-07-20 11:42:24 -0400 | [diff] [blame] | 1456 | /* |
| 1457 | * Finish off the clusters and go home! |
| 1458 | */ |
Behdad Esfahbod | 1bc7a8d | 2018-09-10 22:51:26 +0200 | [diff] [blame] | 1459 | if (indic_plan->uniscribe_bug_compatible) |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 1460 | { |
Behdad Esfahbod | 9ac6b01 | 2013-10-17 16:27:38 +0200 | [diff] [blame] | 1461 | switch ((hb_tag_t) plan->props.script) |
| 1462 | { |
| 1463 | case HB_SCRIPT_TAMIL: |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 1464 | break; |
Behdad Esfahbod | 9ac6b01 | 2013-10-17 16:27:38 +0200 | [diff] [blame] | 1465 | |
| 1466 | default: |
David Corbett | 78c5ae3 | 2022-06-25 13:32:04 -0400 | [diff] [blame] | 1467 | /* Uniscribe merges the entire syllable into a single cluster... Except for Tamil. |
n8willis | 40b05d7 | 2017-10-12 12:48:48 +0100 | [diff] [blame] | 1468 | * This means, half forms are submerged into the main consonant's cluster. |
Behdad Esfahbod | 9ac6b01 | 2013-10-17 16:27:38 +0200 | [diff] [blame] | 1469 | * This is unnecessary, and makes cursor positioning harder, but that's what |
| 1470 | * Uniscribe does. */ |
| 1471 | buffer->merge_clusters (start, end); |
| 1472 | break; |
| 1473 | } |
Behdad Esfahbod | 21d2803 | 2012-05-10 18:34:34 +0200 | [diff] [blame] | 1474 | } |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1475 | } |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1476 | |
| 1477 | |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 1478 | static bool |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 1479 | final_reordering_indic (const hb_ot_shape_plan_t *plan, |
| 1480 | hb_font_t *font HB_UNUSED, |
| 1481 | hb_buffer_t *buffer) |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1482 | { |
| 1483 | unsigned int count = buffer->len; |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 1484 | if (unlikely (!count)) return false; |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1485 | |
Simon Cozens | f19018d | 2020-09-17 15:08:32 +0100 | [diff] [blame] | 1486 | if (buffer->message (font, "start reordering indic final")) { |
| 1487 | foreach_syllable (buffer, start, end) |
| 1488 | final_reordering_syllable_indic (plan, buffer, start, end); |
Simon Cozens | 4bb6d54 | 2020-09-18 16:26:08 +0100 | [diff] [blame] | 1489 | (void) buffer->message (font, "end reordering indic final"); |
Simon Cozens | b50099b | 2020-09-17 14:25:30 +0100 | [diff] [blame] | 1490 | } |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1491 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1492 | HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category); |
| 1493 | HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position); |
Behdad Esfahbod | 27a8fe7 | 2022-11-16 17:49:44 -0700 | [diff] [blame] | 1494 | |
| 1495 | return false; |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | |
Behdad Esfahbod | 3014527 | 2013-10-15 13:47:27 +0200 | [diff] [blame] | 1499 | static void |
Behdad Esfahbod | 6d40eb8 | 2018-10-23 02:51:42 -0700 | [diff] [blame] | 1500 | preprocess_text_indic (const hb_ot_shape_plan_t *plan, |
| 1501 | hb_buffer_t *buffer, |
| 1502 | hb_font_t *font) |
| 1503 | { |
Behdad Esfahbod | 8bfb3e9 | 2022-06-23 13:28:07 -0600 | [diff] [blame] | 1504 | const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data; |
| 1505 | if (!indic_plan->uniscribe_bug_compatible) |
| 1506 | _hb_preprocess_text_vowel_constraints (plan, buffer, font); |
Behdad Esfahbod | 6d40eb8 | 2018-10-23 02:51:42 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Behdad Esfahbod | eba312c | 2012-11-16 12:39:23 -0800 | [diff] [blame] | 1509 | static bool |
| 1510 | decompose_indic (const hb_ot_shape_normalize_context_t *c, |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1511 | hb_codepoint_t ab, |
| 1512 | hb_codepoint_t *a, |
| 1513 | hb_codepoint_t *b) |
| 1514 | { |
| 1515 | switch (ab) |
| 1516 | { |
| 1517 | /* Don't decompose these. */ |
Behdad Esfahbod | 3cc48a4 | 2016-12-26 13:10:31 -0500 | [diff] [blame] | 1518 | case 0x0931u : return false; /* DEVANAGARI LETTER RRA */ |
Ebrahim Byagowi | 9925030 | 2018-04-13 12:43:29 +0430 | [diff] [blame] | 1519 | // https://github.com/harfbuzz/harfbuzz/issues/779 |
| 1520 | case 0x09DCu : return false; /* BENGALI LETTER RRA */ |
| 1521 | case 0x09DDu : return false; /* BENGALI LETTER RHA */ |
Behdad Esfahbod | 3cc48a4 | 2016-12-26 13:10:31 -0500 | [diff] [blame] | 1522 | case 0x0B94u : return false; /* TAMIL LETTER AU */ |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1523 | |
| 1524 | |
| 1525 | /* |
| 1526 | * Decompose split matras that don't have Unicode decompositions. |
| 1527 | */ |
| 1528 | |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1529 | #if 0 |
Behdad Esfahbod | 3cc48a4 | 2016-12-26 13:10:31 -0500 | [diff] [blame] | 1530 | /* Gujarati */ |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1531 | /* This one has no decomposition in Unicode, but needs no decomposition either. */ |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 1532 | /* case 0x0AC9u : return false; */ |
Behdad Esfahbod | 3cc48a4 | 2016-12-26 13:10:31 -0500 | [diff] [blame] | 1533 | |
| 1534 | /* Oriya */ |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 1535 | case 0x0B57u : *a = no decomp, -> RIGHT; return true; |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1536 | #endif |
| 1537 | } |
| 1538 | |
Behdad Esfahbod | ea512f7 | 2015-11-26 19:22:22 -0500 | [diff] [blame] | 1539 | return (bool) c->unicode->decompose (ab, a, b); |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1540 | } |
| 1541 | |
Behdad Esfahbod | eba312c | 2012-11-16 12:39:23 -0800 | [diff] [blame] | 1542 | static bool |
| 1543 | compose_indic (const hb_ot_shape_normalize_context_t *c, |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1544 | hb_codepoint_t a, |
| 1545 | hb_codepoint_t b, |
| 1546 | hb_codepoint_t *ab) |
| 1547 | { |
| 1548 | /* Avoid recomposing split matras. */ |
Behdad Esfahbod | eba312c | 2012-11-16 12:39:23 -0800 | [diff] [blame] | 1549 | if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (c->unicode->general_category (a))) |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1550 | return false; |
| 1551 | |
| 1552 | /* Composition-exclusion exceptions that we want to recompose. */ |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 1553 | if (a == 0x09AFu && b == 0x09BCu) { *ab = 0x09DFu; return true; } |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1554 | |
Behdad Esfahbod | ea512f7 | 2015-11-26 19:22:22 -0500 | [diff] [blame] | 1555 | return (bool) c->unicode->compose (a, b, ab); |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | |
Behdad Esfahbod | 44a7b3b | 2022-06-03 02:42:34 -0600 | [diff] [blame] | 1559 | const hb_ot_shaper_t _hb_ot_shaper_indic = |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 1560 | { |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 1561 | collect_features_indic, |
| 1562 | override_features_indic, |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 1563 | data_create_indic, |
| 1564 | data_destroy_indic, |
Behdad Esfahbod | 6d40eb8 | 2018-10-23 02:51:42 -0700 | [diff] [blame] | 1565 | preprocess_text_indic, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1566 | nullptr, /* postprocess_glyphs */ |
Behdad Esfahbod | 0736915 | 2012-11-13 12:35:35 -0800 | [diff] [blame] | 1567 | decompose_indic, |
| 1568 | compose_indic, |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 1569 | setup_masks_indic, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 1570 | nullptr, /* reorder_marks */ |
Behdad Esfahbod | c2712ff | 2022-07-13 13:34:11 -0600 | [diff] [blame] | 1571 | HB_TAG_NONE, /* gpos_tag */ |
| 1572 | HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT, |
Behdad Esfahbod | 71b4c99 | 2013-10-28 00:20:59 +0100 | [diff] [blame] | 1573 | HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE, |
Behdad Esfahbod | 865745b | 2012-11-14 13:48:26 -0800 | [diff] [blame] | 1574 | false, /* fallback_position */ |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 1575 | }; |
Behdad Esfahbod | 7aad536 | 2019-06-26 13:21:03 -0700 | [diff] [blame] | 1576 | |
| 1577 | |
| 1578 | #endif |