Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011,2012,2013 Google, Inc. |
| 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-myanmar-machine.hh" |
Behdad Esfahbod | 899ca24 | 2022-06-05 01:52:31 -0600 | [diff] [blame] | 32 | #include "hb-ot-shaper-indic.hh" |
| 33 | #include "hb-ot-layout.hh" |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 34 | |
| 35 | |
| 36 | /* |
| 37 | * Myanmar shaper. |
| 38 | */ |
| 39 | |
Behdad Esfahbod | d414fb3 | 2022-06-10 00:50:47 -0600 | [diff] [blame] | 40 | |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 41 | static const hb_tag_t |
Behdad Esfahbod | d8b5353 | 2019-07-02 15:09:26 -0700 | [diff] [blame] | 42 | myanmar_basic_features[] = |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 43 | { |
| 44 | /* |
| 45 | * Basic features. |
Behdad Esfahbod | 62a535f | 2021-08-03 10:11:27 -0600 | [diff] [blame] | 46 | * These features are applied in order, one at a time, after reordering, |
| 47 | * constrained to the syllable. |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 48 | */ |
| 49 | HB_TAG('r','p','h','f'), |
| 50 | HB_TAG('p','r','e','f'), |
| 51 | HB_TAG('b','l','w','f'), |
| 52 | HB_TAG('p','s','t','f'), |
Behdad Esfahbod | ee9c3a1 | 2013-02-15 06:22:26 -0500 | [diff] [blame] | 53 | }; |
| 54 | static const hb_tag_t |
Behdad Esfahbod | d8b5353 | 2019-07-02 15:09:26 -0700 | [diff] [blame] | 55 | myanmar_other_features[] = |
Behdad Esfahbod | ee9c3a1 | 2013-02-15 06:22:26 -0500 | [diff] [blame] | 56 | { |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 57 | /* |
| 58 | * Other features. |
Behdad Esfahbod | 982c2f4 | 2018-10-26 15:40:12 -0700 | [diff] [blame] | 59 | * These features are applied all at once, after clearing syllables. |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 60 | */ |
| 61 | HB_TAG('p','r','e','s'), |
| 62 | HB_TAG('a','b','v','s'), |
| 63 | HB_TAG('b','l','w','s'), |
| 64 | HB_TAG('p','s','t','s'), |
Behdad Esfahbod | 3583fb0 | 2018-09-23 22:33:38 -0400 | [diff] [blame] | 65 | }; |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 66 | |
Behdad Esfahbod | 899ca24 | 2022-06-05 01:52:31 -0600 | [diff] [blame] | 67 | static inline void |
| 68 | set_myanmar_properties (hb_glyph_info_t &info) |
| 69 | { |
| 70 | hb_codepoint_t u = info.codepoint; |
| 71 | unsigned int type = hb_indic_get_categories (u); |
Behdad Esfahbod | 899ca24 | 2022-06-05 01:52:31 -0600 | [diff] [blame] | 72 | |
Behdad Esfahbod | 37217fc | 2022-06-09 16:43:50 -0600 | [diff] [blame] | 73 | info.myanmar_category() = (myanmar_category_t) (type & 0xFFu); |
Behdad Esfahbod | 899ca24 | 2022-06-05 01:52:31 -0600 | [diff] [blame] | 74 | } |
| 75 | |
Behdad Esfahbod | 10a5485 | 2022-06-10 06:34:56 -0600 | [diff] [blame] | 76 | |
| 77 | static inline bool |
| 78 | is_one_of_myanmar (const hb_glyph_info_t &info, unsigned int flags) |
| 79 | { |
| 80 | /* If it ligated, all bets are off. */ |
| 81 | if (_hb_glyph_info_ligated (&info)) return false; |
Behdad Esfahbod | 1404900 | 2022-06-11 03:53:47 -0600 | [diff] [blame] | 82 | return !!(FLAG_UNSAFE (info.myanmar_category()) & flags); |
Behdad Esfahbod | 10a5485 | 2022-06-10 06:34:56 -0600 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /* Note: |
| 86 | * |
| 87 | * We treat Vowels and placeholders as if they were consonants. This is safe because Vowels |
| 88 | * cannot happen in a consonant syllable. The plus side however is, we can call the |
| 89 | * consonant syllable logic from the vowel syllable function and get it all right! |
| 90 | * |
| 91 | * Keep in sync with consonant_categories in the generator. */ |
| 92 | #define CONSONANT_FLAGS_MYANMAR (FLAG (M_Cat(C)) | FLAG (M_Cat(CS)) | FLAG (M_Cat(Ra)) | /* FLAG (M_Cat(CM)) | */ FLAG (M_Cat(IV)) | FLAG (M_Cat(GB)) | FLAG (M_Cat(DOTTEDCIRCLE))) |
| 93 | |
| 94 | static inline bool |
| 95 | is_consonant_myanmar (const hb_glyph_info_t &info) |
| 96 | { |
| 97 | return is_one_of_myanmar (info, CONSONANT_FLAGS_MYANMAR); |
| 98 | } |
| 99 | |
| 100 | |
Seigo Nonaka | c62d6f4 | 2023-03-01 19:52:57 +0900 | [diff] [blame] | 101 | static bool |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 102 | setup_syllables_myanmar (const hb_ot_shape_plan_t *plan, |
| 103 | hb_font_t *font, |
| 104 | hb_buffer_t *buffer); |
Seigo Nonaka | c62d6f4 | 2023-03-01 19:52:57 +0900 | [diff] [blame] | 105 | static bool |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 106 | reorder_myanmar (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | 982c2f4 | 2018-10-26 15:40:12 -0700 | [diff] [blame] | 107 | hb_font_t *font, |
| 108 | hb_buffer_t *buffer); |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 109 | |
| 110 | static void |
| 111 | collect_features_myanmar (hb_ot_shape_planner_t *plan) |
| 112 | { |
| 113 | hb_ot_map_builder_t *map = &plan->map; |
| 114 | |
| 115 | /* Do this before any lookups have been applied. */ |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 116 | map->add_gsub_pause (setup_syllables_myanmar); |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 117 | |
Behdad Esfahbod | 044d7a0 | 2022-03-28 12:38:56 -0600 | [diff] [blame] | 118 | map->enable_feature (HB_TAG('l','o','c','l'), F_PER_SYLLABLE); |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 119 | /* The Indic specs do not require ccmp, but we apply it here since if |
| 120 | * there is a use of it, it's typically at the beginning. */ |
Behdad Esfahbod | 044d7a0 | 2022-03-28 12:38:56 -0600 | [diff] [blame] | 121 | map->enable_feature (HB_TAG('c','c','m','p'), F_PER_SYLLABLE); |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 122 | |
| 123 | |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 124 | map->add_gsub_pause (reorder_myanmar); |
Behdad Esfahbod | 3583fb0 | 2018-09-23 22:33:38 -0400 | [diff] [blame] | 125 | |
Behdad Esfahbod | d8b5353 | 2019-07-02 15:09:26 -0700 | [diff] [blame] | 126 | for (unsigned int i = 0; i < ARRAY_LENGTH (myanmar_basic_features); i++) |
Behdad Esfahbod | ee9c3a1 | 2013-02-15 06:22:26 -0500 | [diff] [blame] | 127 | { |
Behdad Esfahbod | 044d7a0 | 2022-03-28 12:38:56 -0600 | [diff] [blame] | 128 | map->enable_feature (myanmar_basic_features[i], F_MANUAL_ZWJ | F_PER_SYLLABLE); |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 129 | map->add_gsub_pause (nullptr); |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 130 | } |
Behdad Esfahbod | 15543f7 | 2022-06-04 10:55:50 -0600 | [diff] [blame] | 131 | map->add_gsub_pause (hb_syllabic_clear_var); // Don't need syllables anymore, use stop to free buffer var |
Behdad Esfahbod | 3583fb0 | 2018-09-23 22:33:38 -0400 | [diff] [blame] | 132 | |
Behdad Esfahbod | d8b5353 | 2019-07-02 15:09:26 -0700 | [diff] [blame] | 133 | for (unsigned int i = 0; i < ARRAY_LENGTH (myanmar_other_features); i++) |
| 134 | map->enable_feature (myanmar_other_features[i], F_MANUAL_ZWJ); |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 135 | } |
| 136 | |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 137 | static void |
| 138 | setup_masks_myanmar (const hb_ot_shape_plan_t *plan HB_UNUSED, |
Ebrahim Byagowi | 0558413 | 2019-10-01 13:49:55 +0330 | [diff] [blame] | 139 | hb_buffer_t *buffer, |
| 140 | hb_font_t *font HB_UNUSED) |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 141 | { |
| 142 | HB_BUFFER_ALLOCATE_VAR (buffer, myanmar_category); |
| 143 | HB_BUFFER_ALLOCATE_VAR (buffer, myanmar_position); |
| 144 | |
Simon Cozens | 9e59c40 | 2022-04-20 16:56:34 +0100 | [diff] [blame] | 145 | /* No masks, we just save information about characters. */ |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 146 | |
| 147 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 148 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 149 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 150 | set_myanmar_properties (info[i]); |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 151 | } |
| 152 | |
Seigo Nonaka | c62d6f4 | 2023-03-01 19:52:57 +0900 | [diff] [blame] | 153 | static bool |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 154 | setup_syllables_myanmar (const hb_ot_shape_plan_t *plan HB_UNUSED, |
| 155 | hb_font_t *font HB_UNUSED, |
| 156 | hb_buffer_t *buffer) |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 157 | { |
Behdad Esfahbod | 15543f7 | 2022-06-04 10:55:50 -0600 | [diff] [blame] | 158 | HB_BUFFER_ALLOCATE_VAR (buffer, syllable); |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 159 | find_syllables_myanmar (buffer); |
Behdad Esfahbod | 9e005c5 | 2017-08-10 18:45:33 -0700 | [diff] [blame] | 160 | foreach_syllable (buffer, start, end) |
| 161 | buffer->unsafe_to_break (start, end); |
Seigo Nonaka | c62d6f4 | 2023-03-01 19:52:57 +0900 | [diff] [blame] | 162 | return false; |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | static int |
| 166 | compare_myanmar_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) |
| 167 | { |
| 168 | int a = pa->myanmar_position(); |
| 169 | int b = pb->myanmar_position(); |
| 170 | |
Behdad Esfahbod | 39c132a | 2022-06-10 07:12:39 -0600 | [diff] [blame] | 171 | return (int) a - (int) b; |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | |
| 175 | /* Rules from: |
Ebrahim Byagowi | f24b0b9 | 2018-04-12 13:40:45 +0430 | [diff] [blame] | 176 | * https://docs.microsoft.com/en-us/typography/script-development/myanmar */ |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 177 | |
| 178 | static void |
Behdad Esfahbod | 56f71ff | 2015-07-22 11:58:11 +0100 | [diff] [blame] | 179 | initial_reordering_consonant_syllable (hb_buffer_t *buffer, |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 180 | unsigned int start, unsigned int end) |
| 181 | { |
| 182 | hb_glyph_info_t *info = buffer->info; |
| 183 | |
| 184 | unsigned int base = end; |
| 185 | bool has_reph = false; |
| 186 | |
| 187 | { |
| 188 | unsigned int limit = start; |
| 189 | if (start + 3 <= end && |
Behdad Esfahbod | 899ca24 | 2022-06-05 01:52:31 -0600 | [diff] [blame] | 190 | info[start ].myanmar_category() == M_Cat(Ra) && |
| 191 | info[start+1].myanmar_category() == M_Cat(As) && |
| 192 | info[start+2].myanmar_category() == M_Cat(H)) |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 193 | { |
| 194 | limit += 3; |
| 195 | base = start; |
| 196 | has_reph = true; |
| 197 | } |
| 198 | |
| 199 | { |
| 200 | if (!has_reph) |
| 201 | base = limit; |
| 202 | |
| 203 | for (unsigned int i = limit; i < end; i++) |
Behdad Esfahbod | 10a5485 | 2022-06-10 06:34:56 -0600 | [diff] [blame] | 204 | if (is_consonant_myanmar (info[i])) |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 205 | { |
| 206 | base = i; |
| 207 | break; |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /* Reorder! */ |
| 213 | { |
| 214 | unsigned int i = start; |
| 215 | for (; i < start + (has_reph ? 3 : 0); i++) |
| 216 | info[i].myanmar_position() = POS_AFTER_MAIN; |
| 217 | for (; i < base; i++) |
| 218 | info[i].myanmar_position() = POS_PRE_C; |
| 219 | if (i < end) |
| 220 | { |
| 221 | info[i].myanmar_position() = POS_BASE_C; |
| 222 | i++; |
| 223 | } |
Behdad Esfahbod | 5d957ff | 2021-09-20 11:33:01 -0600 | [diff] [blame] | 224 | myanmar_position_t pos = POS_AFTER_MAIN; |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 225 | /* The following loop may be ugly, but it implements all of |
| 226 | * Myanmar reordering! */ |
| 227 | for (; i < end; i++) |
| 228 | { |
Behdad Esfahbod | 899ca24 | 2022-06-05 01:52:31 -0600 | [diff] [blame] | 229 | if (info[i].myanmar_category() == M_Cat(MR)) /* Pre-base reordering */ |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 230 | { |
| 231 | info[i].myanmar_position() = POS_PRE_C; |
| 232 | continue; |
| 233 | } |
Behdad Esfahbod | a6c82d4 | 2022-06-09 13:04:28 -0600 | [diff] [blame] | 234 | if (info[i].myanmar_category() == M_Cat(VPre)) /* Left matra */ |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 235 | { |
Behdad Esfahbod | a6c82d4 | 2022-06-09 13:04:28 -0600 | [diff] [blame] | 236 | info[i].myanmar_position() = POS_PRE_M; |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 237 | continue; |
| 238 | } |
Behdad Esfahbod | 899ca24 | 2022-06-05 01:52:31 -0600 | [diff] [blame] | 239 | if (info[i].myanmar_category() == M_Cat(VS)) |
David Corbett | ccb0367 | 2018-02-02 12:04:04 -0500 | [diff] [blame] | 240 | { |
| 241 | info[i].myanmar_position() = info[i - 1].myanmar_position(); |
| 242 | continue; |
| 243 | } |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 244 | |
Behdad Esfahbod | 899ca24 | 2022-06-05 01:52:31 -0600 | [diff] [blame] | 245 | if (pos == POS_AFTER_MAIN && info[i].myanmar_category() == M_Cat(VBlw)) |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 246 | { |
| 247 | pos = POS_BELOW_C; |
| 248 | info[i].myanmar_position() = pos; |
| 249 | continue; |
| 250 | } |
| 251 | |
Behdad Esfahbod | 899ca24 | 2022-06-05 01:52:31 -0600 | [diff] [blame] | 252 | if (pos == POS_BELOW_C && info[i].myanmar_category() == M_Cat(A)) |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 253 | { |
| 254 | info[i].myanmar_position() = POS_BEFORE_SUB; |
| 255 | continue; |
| 256 | } |
Behdad Esfahbod | 899ca24 | 2022-06-05 01:52:31 -0600 | [diff] [blame] | 257 | if (pos == POS_BELOW_C && info[i].myanmar_category() == M_Cat(VBlw)) |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 258 | { |
| 259 | info[i].myanmar_position() = pos; |
| 260 | continue; |
| 261 | } |
Behdad Esfahbod | 899ca24 | 2022-06-05 01:52:31 -0600 | [diff] [blame] | 262 | if (pos == POS_BELOW_C && info[i].myanmar_category() != M_Cat(A)) |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 263 | { |
Ebrahim Byagowi | a0b4ac4 | 2019-08-24 17:57:14 +0430 | [diff] [blame] | 264 | pos = POS_AFTER_SUB; |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 265 | info[i].myanmar_position() = pos; |
| 266 | continue; |
| 267 | } |
| 268 | info[i].myanmar_position() = pos; |
| 269 | } |
| 270 | } |
| 271 | |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 272 | /* Sit tight, rock 'n roll! */ |
Behdad Esfahbod | c403d63 | 2015-09-01 16:15:25 +0100 | [diff] [blame] | 273 | buffer->sort (start, end, compare_myanmar_order); |
Seigo Nonaka | c62d6f4 | 2023-03-01 19:52:57 +0900 | [diff] [blame] | 274 | |
| 275 | /* Flip left-matra sequence. */ |
| 276 | unsigned first_left_matra = end; |
| 277 | unsigned last_left_matra = end; |
| 278 | for (unsigned int i = start; i < end; i++) |
| 279 | { |
| 280 | if (info[i].myanmar_position() == POS_PRE_M) |
| 281 | { |
| 282 | if (first_left_matra == end) |
| 283 | first_left_matra = i; |
| 284 | last_left_matra = i; |
| 285 | } |
| 286 | } |
| 287 | /* https://github.com/harfbuzz/harfbuzz/issues/3863 */ |
| 288 | if (first_left_matra < last_left_matra) |
| 289 | { |
| 290 | /* No need to merge clusters, done already? */ |
| 291 | buffer->reverse_range (first_left_matra, last_left_matra + 1); |
| 292 | /* Reverse back VS, etc. */ |
| 293 | unsigned i = first_left_matra; |
| 294 | for (unsigned j = i; j <= last_left_matra; j++) |
| 295 | if (info[j].myanmar_category() == M_Cat(VPre)) |
| 296 | { |
| 297 | buffer->reverse_range (i, j + 1); |
| 298 | i = j + 1; |
| 299 | } |
| 300 | } |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | static void |
Behdad Esfahbod | d8b5353 | 2019-07-02 15:09:26 -0700 | [diff] [blame] | 304 | reorder_syllable_myanmar (const hb_ot_shape_plan_t *plan HB_UNUSED, |
| 305 | hb_face_t *face HB_UNUSED, |
| 306 | hb_buffer_t *buffer, |
| 307 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 308 | { |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 309 | myanmar_syllable_type_t syllable_type = (myanmar_syllable_type_t) (buffer->info[start].syllable() & 0x0F); |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 310 | switch (syllable_type) { |
Behdad Esfahbod | 56f71ff | 2015-07-22 11:58:11 +0100 | [diff] [blame] | 311 | |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 312 | case myanmar_broken_cluster: /* We already inserted dotted-circles, so just call the consonant_syllable. */ |
| 313 | case myanmar_consonant_syllable: |
Behdad Esfahbod | 56f71ff | 2015-07-22 11:58:11 +0100 | [diff] [blame] | 314 | initial_reordering_consonant_syllable (buffer, start, end); |
| 315 | break; |
| 316 | |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 317 | case myanmar_non_myanmar_cluster: |
Behdad Esfahbod | 56f71ff | 2015-07-22 11:58:11 +0100 | [diff] [blame] | 318 | break; |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | |
Seigo Nonaka | c62d6f4 | 2023-03-01 19:52:57 +0900 | [diff] [blame] | 322 | static bool |
Behdad Esfahbod | d115a9e | 2019-07-02 14:42:45 -0700 | [diff] [blame] | 323 | reorder_myanmar (const hb_ot_shape_plan_t *plan, |
| 324 | hb_font_t *font, |
| 325 | hb_buffer_t *buffer) |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 326 | { |
Seigo Nonaka | c62d6f4 | 2023-03-01 19:52:57 +0900 | [diff] [blame] | 327 | bool ret = false; |
Behdad Esfahbod | 0ddade4 | 2021-01-15 19:13:47 -0700 | [diff] [blame] | 328 | if (buffer->message (font, "start reordering myanmar")) |
| 329 | { |
Seigo Nonaka | c62d6f4 | 2023-03-01 19:52:57 +0900 | [diff] [blame] | 330 | if (hb_syllabic_insert_dotted_circles (font, buffer, |
| 331 | myanmar_broken_cluster, |
| 332 | M_Cat(DOTTEDCIRCLE))) |
| 333 | ret = true; |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 334 | |
Simon Cozens | b50099b | 2020-09-17 14:25:30 +0100 | [diff] [blame] | 335 | foreach_syllable (buffer, start, end) |
| 336 | reorder_syllable_myanmar (plan, font->face, buffer, start, end); |
Simon Cozens | 428c111 | 2020-09-18 16:24:47 +0100 | [diff] [blame] | 337 | (void) buffer->message (font, "end reordering myanmar"); |
Simon Cozens | b50099b | 2020-09-17 14:25:30 +0100 | [diff] [blame] | 338 | } |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 339 | |
| 340 | HB_BUFFER_DEALLOCATE_VAR (buffer, myanmar_category); |
| 341 | HB_BUFFER_DEALLOCATE_VAR (buffer, myanmar_position); |
Seigo Nonaka | c62d6f4 | 2023-03-01 19:52:57 +0900 | [diff] [blame] | 342 | |
| 343 | return ret; |
Behdad Esfahbod | 98628ca | 2013-02-11 13:36:23 -0500 | [diff] [blame] | 344 | } |
| 345 | |
Behdad Esfahbod | 71b4c99 | 2013-10-28 00:20:59 +0100 | [diff] [blame] | 346 | |
Behdad Esfahbod | 44a7b3b | 2022-06-03 02:42:34 -0600 | [diff] [blame] | 347 | const hb_ot_shaper_t _hb_ot_shaper_myanmar = |
Behdad Esfahbod | 00c5c4a | 2018-10-11 20:15:31 -0400 | [diff] [blame] | 348 | { |
| 349 | collect_features_myanmar, |
Khaled Hosny | 7d64b09 | 2020-09-12 21:17:18 +0200 | [diff] [blame] | 350 | nullptr, /* override_features */ |
Behdad Esfahbod | 00c5c4a | 2018-10-11 20:15:31 -0400 | [diff] [blame] | 351 | nullptr, /* data_create */ |
| 352 | nullptr, /* data_destroy */ |
| 353 | nullptr, /* preprocess_text */ |
| 354 | nullptr, /* postprocess_glyphs */ |
Behdad Esfahbod | 00c5c4a | 2018-10-11 20:15:31 -0400 | [diff] [blame] | 355 | nullptr, /* decompose */ |
| 356 | nullptr, /* compose */ |
| 357 | setup_masks_myanmar, |
Behdad Esfahbod | 00c5c4a | 2018-10-11 20:15:31 -0400 | [diff] [blame] | 358 | nullptr, /* reorder_marks */ |
Behdad Esfahbod | c2712ff | 2022-07-13 13:34:11 -0600 | [diff] [blame] | 359 | HB_TAG_NONE, /* gpos_tag */ |
| 360 | HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT, |
Behdad Esfahbod | 00c5c4a | 2018-10-11 20:15:31 -0400 | [diff] [blame] | 361 | HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY, |
| 362 | false, /* fallback_position */ |
| 363 | }; |
| 364 | |
| 365 | |
Seigo Nonaka | c62d6f4 | 2023-03-01 19:52:57 +0900 | [diff] [blame] | 366 | #ifndef HB_NO_OT_SHAPER_MYANMAR_ZAWGYI |
Behdad Esfahbod | bdb53ca | 2018-10-11 20:20:00 -0400 | [diff] [blame] | 367 | /* Ugly Zawgyi encoding. |
| 368 | * Disable all auto processing. |
| 369 | * https://github.com/harfbuzz/harfbuzz/issues/1162 */ |
Behdad Esfahbod | 44a7b3b | 2022-06-03 02:42:34 -0600 | [diff] [blame] | 370 | const hb_ot_shaper_t _hb_ot_shaper_myanmar_zawgyi = |
Behdad Esfahbod | bdb53ca | 2018-10-11 20:20:00 -0400 | [diff] [blame] | 371 | { |
| 372 | nullptr, /* collect_features */ |
| 373 | nullptr, /* override_features */ |
| 374 | nullptr, /* data_create */ |
| 375 | nullptr, /* data_destroy */ |
| 376 | nullptr, /* preprocess_text */ |
| 377 | nullptr, /* postprocess_glyphs */ |
Behdad Esfahbod | bdb53ca | 2018-10-11 20:20:00 -0400 | [diff] [blame] | 378 | nullptr, /* decompose */ |
| 379 | nullptr, /* compose */ |
| 380 | nullptr, /* setup_masks */ |
Behdad Esfahbod | bdb53ca | 2018-10-11 20:20:00 -0400 | [diff] [blame] | 381 | nullptr, /* reorder_marks */ |
Behdad Esfahbod | c2712ff | 2022-07-13 13:34:11 -0600 | [diff] [blame] | 382 | HB_TAG_NONE, /* gpos_tag */ |
| 383 | HB_OT_SHAPE_NORMALIZATION_MODE_NONE, |
Behdad Esfahbod | bdb53ca | 2018-10-11 20:20:00 -0400 | [diff] [blame] | 384 | HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE, |
| 385 | false, /* fallback_position */ |
| 386 | }; |
Seigo Nonaka | c62d6f4 | 2023-03-01 19:52:57 +0900 | [diff] [blame] | 387 | #endif |
Behdad Esfahbod | 7aad536 | 2019-06-26 13:21:03 -0700 | [diff] [blame] | 388 | |
| 389 | |
| 390 | #endif |