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 | 3ed4634 | 2012-04-19 22:34:06 -0400 | [diff] [blame] | 27 | #include "hb-ot-shape-complex-indic-private.hh" |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 28 | #include "hb-ot-shape-private.hh" |
Behdad Esfahbod | 352372a | 2011-07-30 19:04:02 -0400 | [diff] [blame] | 29 | |
Behdad Esfahbod | a3e04be | 2012-07-16 13:47:19 -0400 | [diff] [blame] | 30 | #define OLD_INDIC_TAG(script) (((hb_tag_t) script) | 0x20000000) |
| 31 | #define IS_OLD_INDIC_TAG(tag) ( \ |
| 32 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_BENGALI) || \ |
| 33 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_DEVANAGARI) || \ |
| 34 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_GUJARATI) || \ |
| 35 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_GURMUKHI) || \ |
| 36 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_KANNADA) || \ |
| 37 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_MALAYALAM) || \ |
| 38 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_ORIYA) || \ |
| 39 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_TAMIL) || \ |
| 40 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_TELUGU) \ |
| 41 | ) |
Behdad Esfahbod | a2b471d | 2012-06-05 15:17:44 -0400 | [diff] [blame] | 42 | struct indic_options_t |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 43 | { |
Behdad Esfahbod | a2b471d | 2012-06-05 15:17:44 -0400 | [diff] [blame] | 44 | int initialized : 1; |
| 45 | int uniscribe_bug_compatible : 1; |
| 46 | }; |
| 47 | |
| 48 | union indic_options_union_t { |
| 49 | int i; |
| 50 | indic_options_t opts; |
| 51 | }; |
| 52 | ASSERT_STATIC (sizeof (int) == sizeof (indic_options_union_t)); |
| 53 | |
| 54 | static indic_options_union_t |
| 55 | indic_options_init (void) |
| 56 | { |
| 57 | indic_options_union_t u; |
| 58 | u.i = 0; |
| 59 | u.opts.initialized = 1; |
| 60 | |
| 61 | char *c = getenv ("HB_OT_INDIC_OPTIONS"); |
| 62 | u.opts.uniscribe_bug_compatible = c && strstr (c, "uniscribe-bug-compatible"); |
| 63 | |
| 64 | return u; |
| 65 | } |
| 66 | |
| 67 | inline indic_options_t |
| 68 | indic_options (void) |
| 69 | { |
| 70 | static indic_options_union_t options; |
| 71 | |
| 72 | if (unlikely (!options.i)) { |
| 73 | /* This is idempotent and threadsafe. */ |
| 74 | options = indic_options_init (); |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 75 | } |
| 76 | |
Behdad Esfahbod | a2b471d | 2012-06-05 15:17:44 -0400 | [diff] [blame] | 77 | return options.opts; |
| 78 | } |
| 79 | |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 80 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 81 | static int |
| 82 | compare_codepoint (const void *pa, const void *pb) |
| 83 | { |
| 84 | hb_codepoint_t a = * (hb_codepoint_t *) pa; |
| 85 | hb_codepoint_t b = * (hb_codepoint_t *) pb; |
| 86 | |
| 87 | return a < b ? -1 : a == b ? 0 : +1; |
| 88 | } |
| 89 | |
| 90 | static indic_position_t |
| 91 | consonant_position (hb_codepoint_t u) |
| 92 | { |
| 93 | consonant_position_t *record; |
| 94 | |
Behdad Esfahbod | 0de771b | 2012-07-16 13:39:36 -0400 | [diff] [blame] | 95 | /* Khmer does not have pre-base half forms. */ |
| 96 | if (0x1780 <= u && u <= 0x17FF) |
| 97 | return POS_BELOW_C; |
| 98 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 99 | record = (consonant_position_t *) bsearch (&u, consonant_positions, |
| 100 | ARRAY_LENGTH (consonant_positions), |
| 101 | sizeof (consonant_positions[0]), |
| 102 | compare_codepoint); |
| 103 | |
Behdad Esfahbod | dbccf87 | 2012-05-09 17:24:39 +0200 | [diff] [blame] | 104 | return record ? record->position : POS_BASE_C; |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Behdad Esfahbod | 352372a | 2011-07-30 19:04:02 -0400 | [diff] [blame] | 107 | static bool |
| 108 | is_ra (hb_codepoint_t u) |
| 109 | { |
| 110 | return !!bsearch (&u, ra_chars, |
| 111 | ARRAY_LENGTH (ra_chars), |
| 112 | sizeof (ra_chars[0]), |
| 113 | compare_codepoint); |
| 114 | } |
| 115 | |
Behdad Esfahbod | 9ee27a9 | 2011-07-31 11:10:14 -0400 | [diff] [blame] | 116 | static bool |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 117 | is_joiner (const hb_glyph_info_t &info) |
Behdad Esfahbod | 9ee27a9 | 2011-07-31 11:10:14 -0400 | [diff] [blame] | 118 | { |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 119 | return !!(FLAG (info.indic_category()) & (FLAG (OT_ZWJ) | FLAG (OT_ZWNJ))); |
| 120 | } |
| 121 | |
| 122 | static bool |
| 123 | is_consonant (const hb_glyph_info_t &info) |
| 124 | { |
Behdad Esfahbod | 1a1fa8c | 2012-05-10 12:20:21 +0200 | [diff] [blame] | 125 | /* Note: |
| 126 | * |
Behdad Esfahbod | 18c06e1 | 2012-05-11 20:02:14 +0200 | [diff] [blame] | 127 | * We treat Vowels and placeholders as if they were consonants. This is safe because Vowels |
Behdad Esfahbod | c5306b6 | 2012-05-10 12:07:33 +0200 | [diff] [blame] | 128 | * cannot happen in a consonant syllable. The plus side however is, we can call the |
| 129 | * consonant syllable logic from the vowel syllable function and get it all right! */ |
Behdad Esfahbod | 18c06e1 | 2012-05-11 20:02:14 +0200 | [diff] [blame] | 130 | return !!(FLAG (info.indic_category()) & (FLAG (OT_C) | FLAG (OT_Ra) | FLAG (OT_V) | FLAG (OT_NBSP) | FLAG (OT_DOTTEDCIRCLE))); |
Behdad Esfahbod | 9ee27a9 | 2011-07-31 11:10:14 -0400 | [diff] [blame] | 131 | } |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 132 | |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 133 | struct feature_list_t { |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 134 | hb_tag_t tag; |
| 135 | hb_bool_t is_global; |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | static const feature_list_t |
| 139 | indic_basic_features[] = |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 140 | { |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 141 | {HB_TAG('n','u','k','t'), true}, |
| 142 | {HB_TAG('a','k','h','n'), false}, |
| 143 | {HB_TAG('r','p','h','f'), false}, |
Behdad Esfahbod | 1ac075b | 2012-05-09 11:06:47 +0200 | [diff] [blame] | 144 | {HB_TAG('r','k','r','f'), true}, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 145 | {HB_TAG('p','r','e','f'), false}, |
| 146 | {HB_TAG('b','l','w','f'), false}, |
| 147 | {HB_TAG('h','a','l','f'), false}, |
Behdad Esfahbod | 29f106d | 2012-07-16 12:05:35 -0400 | [diff] [blame] | 148 | {HB_TAG('a','b','v','f'), false}, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 149 | {HB_TAG('p','s','t','f'), false}, |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 150 | {HB_TAG('c','j','c','t'), false}, |
Behdad Esfahbod | 1d6846d | 2012-05-13 18:09:29 +0200 | [diff] [blame] | 151 | {HB_TAG('v','a','t','u'), true}, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | /* Same order as the indic_basic_features array */ |
| 155 | enum { |
| 156 | _NUKT, |
| 157 | AKHN, |
| 158 | RPHF, |
Behdad Esfahbod | df6d45c | 2012-05-09 11:38:31 +0200 | [diff] [blame] | 159 | _RKRF, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 160 | PREF, |
| 161 | BLWF, |
| 162 | HALF, |
Behdad Esfahbod | 29f106d | 2012-07-16 12:05:35 -0400 | [diff] [blame] | 163 | ABVF, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 164 | PSTF, |
Behdad Esfahbod | 1d6846d | 2012-05-13 18:09:29 +0200 | [diff] [blame] | 165 | CJCT, |
| 166 | VATU |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 167 | }; |
| 168 | |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 169 | static const feature_list_t |
| 170 | indic_other_features[] = |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 171 | { |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 172 | {HB_TAG('i','n','i','t'), false}, |
| 173 | {HB_TAG('p','r','e','s'), true}, |
| 174 | {HB_TAG('a','b','v','s'), true}, |
| 175 | {HB_TAG('b','l','w','s'), true}, |
| 176 | {HB_TAG('p','s','t','s'), true}, |
| 177 | {HB_TAG('h','a','l','n'), true}, |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 178 | |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 179 | {HB_TAG('d','i','s','t'), true}, |
| 180 | {HB_TAG('a','b','v','m'), true}, |
| 181 | {HB_TAG('b','l','w','m'), true}, |
| 182 | }; |
| 183 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 184 | |
| 185 | static void |
| 186 | initial_reordering (const hb_ot_map_t *map, |
| 187 | hb_face_t *face, |
| 188 | hb_buffer_t *buffer, |
| 189 | void *user_data HB_UNUSED); |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 190 | static void |
| 191 | final_reordering (const hb_ot_map_t *map, |
| 192 | hb_face_t *face, |
| 193 | hb_buffer_t *buffer, |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 194 | void *user_data HB_UNUSED); |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 195 | |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 196 | void |
Behdad Esfahbod | 9f377ed | 2012-05-13 16:13:44 +0200 | [diff] [blame] | 197 | _hb_ot_shape_complex_collect_features_indic (hb_ot_map_builder_t *map, |
| 198 | const hb_segment_properties_t *props HB_UNUSED) |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 199 | { |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 200 | map->add_bool_feature (HB_TAG('l','o','c','l')); |
Behdad Esfahbod | a54a550 | 2011-07-20 16:42:10 -0400 | [diff] [blame] | 201 | /* The Indic specs do not require ccmp, but we apply it here since if |
| 202 | * there is a use of it, it's typically at the beginning. */ |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 203 | map->add_bool_feature (HB_TAG('c','c','m','p')); |
| 204 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 205 | map->add_gsub_pause (initial_reordering, NULL); |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 206 | |
Behdad Esfahbod | 412b918 | 2012-05-09 11:07:18 +0200 | [diff] [blame] | 207 | for (unsigned int i = 0; i < ARRAY_LENGTH (indic_basic_features); i++) { |
Behdad Esfahbod | 76f7681 | 2011-07-07 22:25:25 -0400 | [diff] [blame] | 208 | map->add_bool_feature (indic_basic_features[i].tag, indic_basic_features[i].is_global); |
Behdad Esfahbod | 412b918 | 2012-05-09 11:07:18 +0200 | [diff] [blame] | 209 | map->add_gsub_pause (NULL, NULL); |
| 210 | } |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 211 | |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 212 | map->add_gsub_pause (final_reordering, NULL); |
| 213 | |
Behdad Esfahbod | 412b918 | 2012-05-09 11:07:18 +0200 | [diff] [blame] | 214 | for (unsigned int i = 0; i < ARRAY_LENGTH (indic_other_features); i++) { |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 215 | map->add_bool_feature (indic_other_features[i].tag, indic_other_features[i].is_global); |
Behdad Esfahbod | 412b918 | 2012-05-09 11:07:18 +0200 | [diff] [blame] | 216 | map->add_gsub_pause (NULL, NULL); |
| 217 | } |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 218 | } |
| 219 | |
Behdad Esfahbod | 867361c | 2011-06-17 18:35:46 -0400 | [diff] [blame] | 220 | |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 221 | hb_ot_shape_normalization_mode_t |
| 222 | _hb_ot_shape_complex_normalization_preference_indic (void) |
Behdad Esfahbod | 02cdf74 | 2011-07-21 12:23:12 -0400 | [diff] [blame] | 223 | { |
| 224 | /* We want split matras decomposed by the common shaping logic. */ |
Behdad Esfahbod | 11138cc | 2012-04-05 17:25:19 -0400 | [diff] [blame] | 225 | return HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED; |
Behdad Esfahbod | 02cdf74 | 2011-07-21 12:23:12 -0400 | [diff] [blame] | 226 | } |
| 227 | |
Behdad Esfahbod | 867361c | 2011-06-17 18:35:46 -0400 | [diff] [blame] | 228 | |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 229 | void |
Behdad Esfahbod | 9f377ed | 2012-05-13 16:13:44 +0200 | [diff] [blame] | 230 | _hb_ot_shape_complex_setup_masks_indic (hb_ot_map_t *map HB_UNUSED, |
| 231 | hb_buffer_t *buffer, |
Behdad Esfahbod | 3f18236 | 2012-05-13 16:20:10 +0200 | [diff] [blame] | 232 | hb_font_t *font HB_UNUSED) |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 233 | { |
Behdad Esfahbod | 9f9bcce | 2011-07-28 17:06:46 -0400 | [diff] [blame] | 234 | HB_BUFFER_ALLOCATE_VAR (buffer, indic_category); |
| 235 | HB_BUFFER_ALLOCATE_VAR (buffer, indic_position); |
| 236 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 237 | /* We cannot setup masks here. We save information about characters |
| 238 | * and setup masks later on in a pause-callback. */ |
| 239 | |
| 240 | unsigned int count = buffer->len; |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 241 | for (unsigned int i = 0; i < count; i++) |
| 242 | { |
Behdad Esfahbod | 92332e5 | 2012-05-09 17:40:00 +0200 | [diff] [blame] | 243 | hb_glyph_info_t &info = buffer->info[i]; |
| 244 | unsigned int type = get_indic_categories (info.codepoint); |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 245 | |
Behdad Esfahbod | 92332e5 | 2012-05-09 17:40:00 +0200 | [diff] [blame] | 246 | info.indic_category() = type & 0x0F; |
| 247 | info.indic_position() = type >> 4; |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 248 | |
Behdad Esfahbod | 3399a06 | 2012-05-11 17:54:26 +0200 | [diff] [blame] | 249 | /* The spec says U+0952 is OT_A. However, testing shows that Uniscribe |
| 250 | * treats U+0951..U+0952 all as OT_VD. |
| 251 | * TESTS: |
| 252 | * U+092E,U+0947,U+0952 |
| 253 | * U+092E,U+0952,U+0947 |
| 254 | * U+092E,U+0947,U+0951 |
| 255 | * U+092E,U+0951,U+0947 |
| 256 | * */ |
| 257 | if (unlikely (hb_in_range<hb_codepoint_t> (info.codepoint, 0x0951, 0x0954))) |
| 258 | info.indic_category() = OT_VD; |
| 259 | |
Behdad Esfahbod | 92332e5 | 2012-05-09 17:40:00 +0200 | [diff] [blame] | 260 | if (info.indic_category() == OT_C) { |
| 261 | info.indic_position() = consonant_position (info.codepoint); |
| 262 | if (is_ra (info.codepoint)) |
| 263 | info.indic_category() = OT_Ra; |
Behdad Esfahbod | 7d09c98 | 2012-07-16 16:45:22 -0400 | [diff] [blame] | 264 | } else if (info.indic_category() == OT_RS) { |
| 265 | info.indic_position() = POS_ABOVE_M; |
Behdad Esfahbod | 92332e5 | 2012-05-09 17:40:00 +0200 | [diff] [blame] | 266 | } else if (info.indic_category() == OT_SM || |
| 267 | info.indic_category() == OT_VD) { |
| 268 | info.indic_position() = POS_SMVD; |
| 269 | } else if (unlikely (info.codepoint == 0x200C)) |
| 270 | info.indic_category() = OT_ZWNJ; |
| 271 | else if (unlikely (info.codepoint == 0x200D)) |
| 272 | info.indic_category() = OT_ZWJ; |
Behdad Esfahbod | 18c06e1 | 2012-05-11 20:02:14 +0200 | [diff] [blame] | 273 | else if (unlikely (info.codepoint == 0x25CC)) |
| 274 | info.indic_category() = OT_DOTTEDCIRCLE; |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 275 | } |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 276 | } |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 277 | |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 278 | static int |
| 279 | compare_indic_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) |
| 280 | { |
| 281 | int a = pa->indic_position(); |
| 282 | int b = pb->indic_position(); |
| 283 | |
| 284 | return a < b ? -1 : a == b ? 0 : +1; |
| 285 | } |
Behdad Esfahbod | 867361c | 2011-06-17 18:35:46 -0400 | [diff] [blame] | 286 | |
Behdad Esfahbod | 7ea58db | 2012-05-11 18:58:57 +0200 | [diff] [blame] | 287 | /* Rules from: |
| 288 | * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */ |
| 289 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 290 | static void |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 291 | initial_reordering_consonant_syllable (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *basic_mask_array, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 292 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 293 | { |
Behdad Esfahbod | ee58f3b | 2011-07-30 19:15:53 -0400 | [diff] [blame] | 294 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 295 | |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 296 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 297 | /* 1. Find base consonant: |
| 298 | * |
| 299 | * The shaping engine finds the base consonant of the syllable, using the |
| 300 | * following algorithm: starting from the end of the syllable, move backwards |
| 301 | * until a consonant is found that does not have a below-base or post-base |
| 302 | * form (post-base forms have to follow below-base forms), or that is not a |
| 303 | * pre-base reordering Ra, or arrive at the first consonant. The consonant |
| 304 | * stopped at will be the base. |
| 305 | * |
| 306 | * o If the syllable starts with Ra + Halant (in a script that has Reph) |
| 307 | * and has more than one consonant, Ra is excluded from candidates for |
| 308 | * base consonants. |
| 309 | */ |
| 310 | |
Behdad Esfahbod | 5e72071 | 2011-07-31 17:51:50 -0400 | [diff] [blame] | 311 | unsigned int base = end; |
Behdad Esfahbod | 76b3409 | 2012-05-09 11:43:43 +0200 | [diff] [blame] | 312 | bool has_reph = false; |
| 313 | |
Behdad Esfahbod | 76b3409 | 2012-05-09 11:43:43 +0200 | [diff] [blame] | 314 | { |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 315 | /* -> If the syllable starts with Ra + Halant (in a script that has Reph) |
| 316 | * and has more than one consonant, Ra is excluded from candidates for |
| 317 | * base consonants. */ |
| 318 | unsigned int limit = start; |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 319 | if (basic_mask_array[RPHF] && |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 320 | start + 3 <= end && |
| 321 | info[start].indic_category() == OT_Ra && |
| 322 | info[start + 1].indic_category() == OT_H && |
| 323 | !is_joiner (info[start + 2])) |
| 324 | { |
| 325 | limit += 2; |
| 326 | base = start; |
| 327 | has_reph = true; |
| 328 | }; |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 329 | |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 330 | /* -> starting from the end of the syllable, move backwards */ |
| 331 | unsigned int i = end; |
| 332 | do { |
| 333 | i--; |
| 334 | /* -> until a consonant is found */ |
| 335 | if (is_consonant (info[i])) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 336 | { |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 337 | /* -> that does not have a below-base or post-base form |
| 338 | * (post-base forms have to follow below-base forms), */ |
| 339 | if (info[i].indic_position() != POS_BELOW_C && |
| 340 | info[i].indic_position() != POS_POST_C) |
| 341 | { |
| 342 | base = i; |
| 343 | break; |
| 344 | } |
| 345 | |
| 346 | /* -> or that is not a pre-base reordering Ra, |
| 347 | * |
| 348 | * TODO |
| 349 | */ |
| 350 | |
| 351 | /* -> or arrive at the first consonant. The consonant stopped at will |
| 352 | * be the base. */ |
| 353 | base = i; |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 354 | } |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 355 | else |
| 356 | if (is_joiner (info[i])) |
| 357 | break; |
| 358 | } while (i > limit); |
| 359 | if (base < start) |
| 360 | base = start; /* Just in case... */ |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 361 | |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 362 | |
| 363 | /* -> If the syllable starts with Ra + Halant (in a script that has Reph) |
| 364 | * and has more than one consonant, Ra is excluded from candidates for |
| 365 | * base consonants. */ |
| 366 | if (has_reph && base == start) { |
| 367 | /* Have no other consonant, so Reph is not formed and Ra becomes base. */ |
| 368 | has_reph = false; |
| 369 | } |
Behdad Esfahbod | 5e4e21f | 2012-05-13 16:46:08 +0200 | [diff] [blame] | 370 | } |
Behdad Esfahbod | 3d25079 | 2012-05-10 11:37:42 +0200 | [diff] [blame] | 371 | |
| 372 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 373 | /* 2. Decompose and reorder Matras: |
| 374 | * |
| 375 | * Each matra and any syllable modifier sign in the cluster are moved to the |
| 376 | * appropriate position relative to the consonant(s) in the cluster. The |
| 377 | * shaping engine decomposes two- or three-part matras into their constituent |
| 378 | * parts before any repositioning. Matra characters are classified by which |
| 379 | * consonant in a conjunct they have affinity for and are reordered to the |
| 380 | * following positions: |
| 381 | * |
| 382 | * o Before first half form in the syllable |
| 383 | * o After subjoined consonants |
| 384 | * o After post-form consonant |
| 385 | * o After main consonant (for above marks) |
| 386 | * |
| 387 | * IMPLEMENTATION NOTES: |
| 388 | * |
| 389 | * The normalize() routine has already decomposed matras for us, so we don't |
| 390 | * need to worry about that. |
| 391 | */ |
| 392 | |
| 393 | |
| 394 | /* 3. Reorder marks to canonical order: |
| 395 | * |
| 396 | * Adjacent nukta and halant or nukta and vedic sign are always repositioned |
| 397 | * if necessary, so that the nukta is first. |
| 398 | * |
| 399 | * IMPLEMENTATION NOTES: |
| 400 | * |
| 401 | * We don't need to do this: the normalize() routine already did this for us. |
| 402 | */ |
| 403 | |
| 404 | |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 405 | /* Reorder characters */ |
| 406 | |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 407 | for (unsigned int i = start; i < base; i++) |
Behdad Esfahbod | dbccf87 | 2012-05-09 17:24:39 +0200 | [diff] [blame] | 408 | info[i].indic_position() = POS_PRE_C; |
| 409 | info[base].indic_position() = POS_BASE_C; |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 410 | |
Behdad Esfahbod | fd06bf5 | 2011-07-30 20:14:44 -0400 | [diff] [blame] | 411 | /* Handle beginning Ra */ |
Behdad Esfahbod | 5e4e21f | 2012-05-13 16:46:08 +0200 | [diff] [blame] | 412 | if (has_reph) |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 413 | info[start].indic_position() = POS_RA_TO_BECOME_REPH; |
Behdad Esfahbod | fd06bf5 | 2011-07-30 20:14:44 -0400 | [diff] [blame] | 414 | |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 415 | /* For old-style Indic script tags, move the first post-base Halant after |
| 416 | * last consonant. */ |
Behdad Esfahbod | a3e04be | 2012-07-16 13:47:19 -0400 | [diff] [blame] | 417 | if (IS_OLD_INDIC_TAG (map->get_chosen_script (0))) { |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 418 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 419 | if (info[i].indic_category() == OT_H) { |
| 420 | unsigned int j; |
| 421 | for (j = end - 1; j > i; j--) |
Behdad Esfahbod | 190eb31 | 2012-05-10 12:17:16 +0200 | [diff] [blame] | 422 | if (is_consonant (info[j])) |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 423 | break; |
| 424 | if (j > i) { |
| 425 | /* Move Halant to after last consonant. */ |
| 426 | hb_glyph_info_t t = info[i]; |
| 427 | memmove (&info[i], &info[i + 1], (j - i) * sizeof (info[0])); |
| 428 | info[j] = t; |
| 429 | } |
| 430 | break; |
| 431 | } |
| 432 | } |
| 433 | |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 434 | /* Attach ZWJ, ZWNJ, nukta, and halant to previous char to move with them. */ |
Behdad Esfahbod | a2b471d | 2012-06-05 15:17:44 -0400 | [diff] [blame] | 435 | if (!indic_options ().uniscribe_bug_compatible) |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 436 | { |
| 437 | /* Please update the Uniscribe branch when touching this! */ |
| 438 | for (unsigned int i = start + 1; i < end; i++) |
| 439 | if ((FLAG (info[i].indic_category()) & (FLAG (OT_ZWNJ) | FLAG (OT_ZWJ) | FLAG (OT_N) | FLAG (OT_H)))) |
| 440 | info[i].indic_position() = info[i - 1].indic_position(); |
| 441 | } else { |
Behdad Esfahbod | 67ea29a | 2012-05-11 16:51:23 +0200 | [diff] [blame] | 442 | /* |
| 443 | * Uniscribe doesn't move the Halant with Left Matra. |
| 444 | * TEST: U+092B,U+093F,U+094DE |
| 445 | */ |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 446 | /* Please update the non-Uniscribe branch when touching this! */ |
| 447 | for (unsigned int i = start + 1; i < end; i++) |
| 448 | if ((FLAG (info[i].indic_category()) & (FLAG (OT_ZWNJ) | FLAG (OT_ZWJ) | FLAG (OT_N) | FLAG (OT_H)))) { |
| 449 | info[i].indic_position() = info[i - 1].indic_position(); |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 450 | if (info[i].indic_category() == OT_H && info[i].indic_position() == POS_PRE_M) |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 451 | for (unsigned int j = i; j > start; j--) |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 452 | if (info[j - 1].indic_position() != POS_PRE_M) { |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 453 | info[i].indic_position() = info[j - 1].indic_position(); |
| 454 | break; |
| 455 | } |
| 456 | } |
| 457 | } |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 458 | |
| 459 | /* We do bubble-sort, skip malicious clusters attempts */ |
Behdad Esfahbod | b99d63a | 2012-05-10 11:32:52 +0200 | [diff] [blame] | 460 | if (end - start < 64) |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 461 | { |
| 462 | /* Sit tight, rock 'n roll! */ |
Behdad Esfahbod | d3637ed | 2012-05-10 10:51:38 +0200 | [diff] [blame] | 463 | hb_bubble_sort (info + start, end - start, compare_indic_order); |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 464 | /* Find base again */ |
| 465 | base = end; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 466 | for (unsigned int i = start; i < end; i++) |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 467 | if (info[i].indic_position() == POS_BASE_C) { |
| 468 | base = i; |
| 469 | break; |
| 470 | } |
| 471 | } |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 472 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 473 | /* Setup masks now */ |
| 474 | |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 475 | { |
| 476 | hb_mask_t mask; |
| 477 | |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 478 | /* Reph */ |
Behdad Esfahbod | 668c604 | 2012-05-11 15:34:13 +0200 | [diff] [blame] | 479 | for (unsigned int i = start; i < end && info[i].indic_position() == POS_RA_TO_BECOME_REPH; i++) |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 480 | info[i].mask |= basic_mask_array[RPHF]; |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 481 | |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 482 | /* Pre-base */ |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 483 | mask = basic_mask_array[HALF] | basic_mask_array[AKHN] | basic_mask_array[CJCT]; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 484 | for (unsigned int i = start; i < base; i++) |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 485 | info[i].mask |= mask; |
| 486 | /* Base */ |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 487 | mask = basic_mask_array[AKHN] | basic_mask_array[CJCT]; |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 488 | info[base].mask |= mask; |
| 489 | /* Post-base */ |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 490 | mask = basic_mask_array[BLWF] | basic_mask_array[ABVF] | basic_mask_array[PSTF] | basic_mask_array[CJCT]; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 491 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 492 | info[i].mask |= mask; |
| 493 | } |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 494 | |
Behdad Esfahbod | 17d7de9 | 2012-07-16 15:20:15 -0400 | [diff] [blame] | 495 | /* XXX This will not match for old-Indic spec since the Halant-Ra order is reversed already. */ |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame^] | 496 | if (basic_mask_array[PREF] && base + 3 <= end) |
Behdad Esfahbod | 17d7de9 | 2012-07-16 15:20:15 -0400 | [diff] [blame] | 497 | { |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame^] | 498 | /* Find a Halant,Ra sequence and mark it fore pre-base reordering processing. */ |
| 499 | for (unsigned int i = base + 1; i + 1 < end; i++) |
| 500 | if (info[i].indic_category() == OT_H && |
| 501 | info[i + 1].indic_category() == OT_Ra) |
| 502 | { |
| 503 | info[i].mask |= basic_mask_array[PREF]; |
| 504 | info[i + 1].mask |= basic_mask_array[PREF]; |
| 505 | break; |
| 506 | } |
Behdad Esfahbod | 17d7de9 | 2012-07-16 15:20:15 -0400 | [diff] [blame] | 507 | } |
| 508 | |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 509 | /* Apply ZWJ/ZWNJ effects */ |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 510 | for (unsigned int i = start + 1; i < end; i++) |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 511 | if (is_joiner (info[i])) { |
| 512 | bool non_joiner = info[i].indic_category() == OT_ZWNJ; |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 513 | unsigned int j = i; |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 514 | |
| 515 | do { |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 516 | j--; |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 517 | |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 518 | info[j].mask &= ~basic_mask_array[CJCT]; |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 519 | if (non_joiner) |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 520 | info[j].mask &= ~basic_mask_array[HALF]; |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 521 | |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 522 | } while (j > start && !is_consonant (info[j])); |
| 523 | } |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | |
| 527 | static void |
Behdad Esfahbod | 9f377ed | 2012-05-13 16:13:44 +0200 | [diff] [blame] | 528 | initial_reordering_vowel_syllable (const hb_ot_map_t *map, |
| 529 | hb_buffer_t *buffer, |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 530 | hb_mask_t *basic_mask_array, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 531 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 532 | { |
Behdad Esfahbod | c5306b6 | 2012-05-10 12:07:33 +0200 | [diff] [blame] | 533 | /* We made the vowels look like consonants. So let's call the consonant logic! */ |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 534 | initial_reordering_consonant_syllable (map, buffer, basic_mask_array, start, end); |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | static void |
Behdad Esfahbod | 9f377ed | 2012-05-13 16:13:44 +0200 | [diff] [blame] | 538 | initial_reordering_standalone_cluster (const hb_ot_map_t *map, |
| 539 | hb_buffer_t *buffer, |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 540 | hb_mask_t *basic_mask_array, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 541 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 542 | { |
Behdad Esfahbod | 18c06e1 | 2012-05-11 20:02:14 +0200 | [diff] [blame] | 543 | /* We treat NBSP/dotted-circle as if they are consonants, so we should just chain. |
| 544 | * Only if not in compatibility mode that is... */ |
| 545 | |
Behdad Esfahbod | a2b471d | 2012-06-05 15:17:44 -0400 | [diff] [blame] | 546 | if (indic_options ().uniscribe_bug_compatible) |
Behdad Esfahbod | 18c06e1 | 2012-05-11 20:02:14 +0200 | [diff] [blame] | 547 | { |
| 548 | /* For dotted-circle, this is what Uniscribe does: |
| 549 | * If dotted-circle is the last glyph, it just does nothing. |
| 550 | * Ie. It doesn't form Reph. */ |
| 551 | if (buffer->info[end - 1].indic_category() == OT_DOTTEDCIRCLE) |
| 552 | return; |
| 553 | } |
| 554 | |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 555 | initial_reordering_consonant_syllable (map, buffer, basic_mask_array, start, end); |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | static void |
Behdad Esfahbod | 9f377ed | 2012-05-13 16:13:44 +0200 | [diff] [blame] | 559 | initial_reordering_non_indic (const hb_ot_map_t *map HB_UNUSED, |
| 560 | hb_buffer_t *buffer HB_UNUSED, |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 561 | hb_mask_t *basic_mask_array HB_UNUSED, |
Behdad Esfahbod | 3f18236 | 2012-05-13 16:20:10 +0200 | [diff] [blame] | 562 | unsigned int start HB_UNUSED, unsigned int end HB_UNUSED) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 563 | { |
| 564 | /* Nothing to do right now. If we ever switch to using the output |
| 565 | * buffer in the reordering process, we'd need to next_glyph() here. */ |
| 566 | } |
| 567 | |
| 568 | #include "hb-ot-shape-complex-indic-machine.hh" |
| 569 | |
| 570 | static void |
| 571 | initial_reordering (const hb_ot_map_t *map, |
Behdad Esfahbod | 3f18236 | 2012-05-13 16:20:10 +0200 | [diff] [blame] | 572 | hb_face_t *face HB_UNUSED, |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 573 | hb_buffer_t *buffer, |
| 574 | void *user_data HB_UNUSED) |
| 575 | { |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 576 | hb_mask_t basic_mask_array[ARRAY_LENGTH (indic_basic_features)] = {0}; |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 577 | unsigned int num_masks = ARRAY_LENGTH (indic_basic_features); |
| 578 | for (unsigned int i = 0; i < num_masks; i++) |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 579 | basic_mask_array[i] = map->get_1_mask (indic_basic_features[i].tag); |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 580 | |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 581 | find_syllables (map, buffer, basic_mask_array); |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 582 | } |
| 583 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 584 | static void |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 585 | final_reordering_syllable (hb_buffer_t *buffer, |
| 586 | hb_mask_t init_mask, hb_mask_t pref_mask, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 587 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 588 | { |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 589 | hb_glyph_info_t *info = buffer->info; |
| 590 | |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 591 | /* 4. Final reordering: |
| 592 | * |
| 593 | * After the localized forms and basic shaping forms GSUB features have been |
| 594 | * applied (see below), the shaping engine performs some final glyph |
| 595 | * reordering before applying all the remaining font features to the entire |
| 596 | * cluster. |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 597 | */ |
| 598 | |
| 599 | /* Find base again */ |
| 600 | unsigned int base = end; |
| 601 | for (unsigned int i = start; i < end; i++) |
| 602 | if (info[i].indic_position() == POS_BASE_C) { |
| 603 | base = i; |
| 604 | break; |
| 605 | } |
| 606 | |
Behdad Esfahbod | 4705a70 | 2012-05-10 13:09:08 +0200 | [diff] [blame] | 607 | unsigned int start_of_last_cluster = base; |
| 608 | |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 609 | /* o Reorder matras: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 610 | * |
| 611 | * If a pre-base matra character had been reordered before applying basic |
| 612 | * features, the glyph can be moved closer to the main consonant based on |
| 613 | * whether half-forms had been formed. Actual position for the matra is |
| 614 | * defined as “after last standalone halant glyph, after initial matra |
| 615 | * position and before the main consonant”. If ZWJ or ZWNJ follow this |
| 616 | * halant, position is moved after it. |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 617 | */ |
| 618 | |
Behdad Esfahbod | 362d3db | 2012-07-16 15:15:28 -0400 | [diff] [blame] | 619 | if (start < base) /* Otherwise there can't be any pre-base matra characters. */ |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 620 | { |
Behdad Esfahbod | 921ce5b | 2012-07-16 15:26:56 -0400 | [diff] [blame] | 621 | unsigned int new_pos = base - 1; |
| 622 | while (new_pos > start && |
| 623 | !(FLAG (info[new_pos].indic_category()) & (FLAG (OT_M) | FLAG (OT_H)))) |
| 624 | new_pos--; |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 625 | /* If we found no Halant we are done. Otherwise only proceed if the Halant does |
| 626 | * not belong to the Matra itself! */ |
Behdad Esfahbod | 921ce5b | 2012-07-16 15:26:56 -0400 | [diff] [blame] | 627 | if (info[new_pos].indic_category() == OT_H && |
| 628 | info[new_pos].indic_position() != POS_PRE_M) { |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 629 | /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ |
Behdad Esfahbod | 921ce5b | 2012-07-16 15:26:56 -0400 | [diff] [blame] | 630 | if (new_pos + 1 < end && is_joiner (info[new_pos + 1])) |
| 631 | new_pos++; |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 632 | |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 633 | /* Now go see if there's actually any matras... */ |
Behdad Esfahbod | 921ce5b | 2012-07-16 15:26:56 -0400 | [diff] [blame] | 634 | for (unsigned int i = new_pos; i > start; i--) |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 635 | if (info[i - 1].indic_position () == POS_PRE_M) |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 636 | { |
Behdad Esfahbod | 1a1dbe9 | 2012-07-16 15:40:33 -0400 | [diff] [blame] | 637 | unsigned int old_pos = i - 1; |
| 638 | hb_glyph_info_t tmp = info[old_pos]; |
| 639 | memmove (&info[old_pos], &info[old_pos + 1], (new_pos - old_pos) * sizeof (info[0])); |
| 640 | info[new_pos] = tmp; |
Behdad Esfahbod | 921ce5b | 2012-07-16 15:26:56 -0400 | [diff] [blame] | 641 | start_of_last_cluster = MIN (new_pos, start_of_last_cluster); |
| 642 | new_pos--; |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 643 | } |
| 644 | } |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | |
| 648 | /* o Reorder reph: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 649 | * |
| 650 | * Reph’s original position is always at the beginning of the syllable, |
| 651 | * (i.e. it is not reordered at the character reordering stage). However, |
| 652 | * it will be reordered according to the basic-forms shaping results. |
| 653 | * Possible positions for reph, depending on the script, are; after main, |
| 654 | * before post-base consonant forms, and after post-base consonant forms. |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 655 | */ |
| 656 | |
| 657 | /* If there's anything after the Ra that has the REPH pos, it ought to be halant. |
| 658 | * Which means that the font has failed to ligate the Reph. In which case, we |
| 659 | * shouldn't move. */ |
| 660 | if (start + 1 < end && |
| 661 | info[start].indic_position() == POS_RA_TO_BECOME_REPH && |
| 662 | info[start + 1].indic_position() != POS_RA_TO_BECOME_REPH) |
| 663 | { |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 664 | unsigned int new_reph_pos; |
| 665 | |
| 666 | enum reph_position_t { |
Behdad Esfahbod | f893672 | 2012-05-11 21:10:03 +0200 | [diff] [blame] | 667 | REPH_AFTER_MAIN, |
| 668 | REPH_BEFORE_SUBSCRIPT, |
| 669 | REPH_AFTER_SUBSCRIPT, |
| 670 | REPH_BEFORE_POSTSCRIPT, |
Behdad Esfahbod | 9fc7a11 | 2012-06-04 08:28:19 -0400 | [diff] [blame] | 671 | REPH_AFTER_POSTSCRIPT |
Behdad Esfahbod | f893672 | 2012-05-11 21:10:03 +0200 | [diff] [blame] | 672 | } reph_pos; |
| 673 | |
| 674 | /* XXX Figure out old behavior too */ |
Behdad Esfahbod | 7f852b6 | 2012-05-11 23:10:31 +0200 | [diff] [blame] | 675 | switch ((hb_tag_t) buffer->props.script) |
Behdad Esfahbod | f893672 | 2012-05-11 21:10:03 +0200 | [diff] [blame] | 676 | { |
| 677 | case HB_SCRIPT_MALAYALAM: |
| 678 | case HB_SCRIPT_ORIYA: |
| 679 | reph_pos = REPH_AFTER_MAIN; |
| 680 | break; |
| 681 | |
| 682 | case HB_SCRIPT_GURMUKHI: |
| 683 | reph_pos = REPH_BEFORE_SUBSCRIPT; |
| 684 | break; |
| 685 | |
| 686 | case HB_SCRIPT_BENGALI: |
| 687 | reph_pos = REPH_AFTER_SUBSCRIPT; |
| 688 | break; |
| 689 | |
| 690 | default: |
| 691 | case HB_SCRIPT_DEVANAGARI: |
| 692 | case HB_SCRIPT_GUJARATI: |
| 693 | reph_pos = REPH_BEFORE_POSTSCRIPT; |
| 694 | break; |
| 695 | |
| 696 | case HB_SCRIPT_KANNADA: |
| 697 | case HB_SCRIPT_TAMIL: |
| 698 | case HB_SCRIPT_TELUGU: |
| 699 | reph_pos = REPH_AFTER_POSTSCRIPT; |
| 700 | break; |
| 701 | } |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 702 | |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 703 | /* 1. If reph should be positioned after post-base consonant forms, |
| 704 | * proceed to step 5. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 705 | */ |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 706 | if (reph_pos == REPH_AFTER_POSTSCRIPT) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 707 | { |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 708 | goto reph_step_5; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /* 2. If the reph repositioning class is not after post-base: target |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 712 | * position is after the first explicit halant glyph between the |
| 713 | * first post-reph consonant and last main consonant. If ZWJ or ZWNJ |
| 714 | * are following this halant, position is moved after it. If such |
| 715 | * position is found, this is the target position. Otherwise, |
| 716 | * proceed to the next step. |
| 717 | * |
| 718 | * Note: in old-implementation fonts, where classifications were |
| 719 | * fixed in shaping engine, there was no case where reph position |
| 720 | * will be found on this step. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 721 | */ |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 722 | { |
| 723 | new_reph_pos = start + 1; |
| 724 | while (new_reph_pos < base && info[new_reph_pos].indic_category() != OT_H) |
| 725 | new_reph_pos++; |
| 726 | |
| 727 | if (new_reph_pos < base && info[new_reph_pos].indic_category() == OT_H) { |
| 728 | /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */ |
| 729 | if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1])) |
| 730 | new_reph_pos++; |
| 731 | goto reph_move; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | /* 3. If reph should be repositioned after the main consonant: find the |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 736 | * first consonant not ligated with main, or find the first |
| 737 | * consonant that is not a potential pre-base reordering Ra. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 738 | */ |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 739 | if (reph_pos == REPH_AFTER_MAIN) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 740 | { |
Behdad Esfahbod | b504e06 | 2012-07-16 15:21:12 -0400 | [diff] [blame] | 741 | new_reph_pos = base; |
| 742 | /* XXX Skip potential pre-base reordering Ra. */ |
| 743 | while (new_reph_pos < end && |
| 744 | !( FLAG (info[new_reph_pos + 1].indic_position()) & (FLAG (POS_BELOW_C) | FLAG (POS_POST_C) | FLAG (POS_POST_M) | FLAG (POS_SMVD)))) |
| 745 | new_reph_pos++; |
| 746 | if (new_reph_pos < end) |
| 747 | goto reph_move; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /* 4. If reph should be positioned before post-base consonant, find |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 751 | * first post-base classified consonant not ligated with main. If no |
| 752 | * consonant is found, the target position should be before the |
| 753 | * first matra, syllable modifier sign or vedic sign. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 754 | */ |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 755 | /* This is our take on what step 4 is trying to say (and failing, BADLY). */ |
| 756 | if (reph_pos == REPH_AFTER_SUBSCRIPT) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 757 | { |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 758 | new_reph_pos = base; |
| 759 | while (new_reph_pos < end && |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 760 | !( FLAG (info[new_reph_pos + 1].indic_position()) & (FLAG (POS_POST_C) | FLAG (POS_POST_M) | FLAG (POS_SMVD)))) |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 761 | new_reph_pos++; |
| 762 | if (new_reph_pos < end) |
| 763 | goto reph_move; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /* 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] | 767 | * immediately before the first post-base matra, syllable modifier |
| 768 | * sign or vedic sign that has a reordering class after the intended |
| 769 | * reph position. For example, if the reordering position for reph |
| 770 | * is post-main, it will skip above-base matras that also have a |
| 771 | * post-main position. |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 772 | */ |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 773 | reph_step_5: |
| 774 | { |
| 775 | /* XXX */ |
Behdad Esfahbod | 8df5636 | 2012-05-10 15:41:04 +0200 | [diff] [blame] | 776 | } |
| 777 | |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 778 | /* 6. Otherwise, reorder reph to the end of the syllable. |
| 779 | */ |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 780 | { |
| 781 | new_reph_pos = end - 1; |
| 782 | while (new_reph_pos > start && info[new_reph_pos].indic_position() == POS_SMVD) |
| 783 | new_reph_pos--; |
| 784 | |
Behdad Esfahbod | 892eb78 | 2012-05-11 16:54:40 +0200 | [diff] [blame] | 785 | /* |
| 786 | * If the Reph is to be ending up after a Matra,Halant sequence, |
| 787 | * position it before that Halant so it can interact with the Matra. |
| 788 | * However, if it's a plain Consonant,Halant we shouldn't do that. |
| 789 | * Uniscribe doesn't do this. |
| 790 | * TEST: U+0930,U+094D,U+0915,U+094B,U+094D |
| 791 | */ |
Behdad Esfahbod | a2b471d | 2012-06-05 15:17:44 -0400 | [diff] [blame] | 792 | if (!indic_options ().uniscribe_bug_compatible && |
Behdad Esfahbod | 892eb78 | 2012-05-11 16:54:40 +0200 | [diff] [blame] | 793 | unlikely (info[new_reph_pos].indic_category() == OT_H)) { |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 794 | for (unsigned int i = base + 1; i < new_reph_pos; i++) |
| 795 | if (info[i].indic_category() == OT_M) { |
| 796 | /* Ok, got it. */ |
| 797 | new_reph_pos--; |
| 798 | } |
| 799 | } |
| 800 | goto reph_move; |
| 801 | } |
| 802 | |
| 803 | reph_move: |
| 804 | { |
| 805 | /* Move */ |
| 806 | hb_glyph_info_t reph = info[start]; |
| 807 | memmove (&info[start], &info[start + 1], (new_reph_pos - start) * sizeof (info[0])); |
| 808 | info[new_reph_pos] = reph; |
| 809 | start_of_last_cluster = start; /* Yay, one big cluster! */ |
| 810 | } |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | |
| 814 | /* o Reorder pre-base reordering consonants: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 815 | * |
| 816 | * If a pre-base reordering consonant is found, reorder it according to |
| 817 | * the following rules: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 818 | */ |
| 819 | |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 820 | if (pref_mask && base + 1 < end) /* Otherwise there can't be any pre-base reordering Ra. */ |
| 821 | { |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame^] | 822 | for (unsigned int i = base + 1; i < end; i++) |
| 823 | if ((info[i].mask & pref_mask) != 0) |
Behdad Esfahbod | 7881812 | 2012-07-16 15:49:08 -0400 | [diff] [blame] | 824 | { |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame^] | 825 | /* 1. Only reorder a glyph produced by substitution during application |
| 826 | * of the <pref> feature. (Note that a font may shape a Ra consonant with |
| 827 | * the feature generally but block it in certain contexts.) |
| 828 | */ |
| 829 | if (i + 1 == end || (info[i + 1].mask & pref_mask) == 0) |
| 830 | { |
| 831 | /* |
| 832 | * 2. Try to find a target position the same way as for pre-base matra. |
| 833 | * If it is found, reorder pre-base consonant glyph. |
| 834 | * |
| 835 | * 3. If position is not found, reorder immediately before main |
| 836 | * consonant. |
| 837 | */ |
| 838 | |
| 839 | unsigned int new_pos = base; |
| 840 | while (new_pos > start + 1 && |
| 841 | !(FLAG (info[new_pos - 1].indic_category()) & (FLAG (OT_M) | FLAG (OT_H)))) |
| 842 | new_pos--; |
| 843 | |
| 844 | if (new_pos > start && info[new_pos - 1].indic_category() == OT_H) |
| 845 | /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ |
| 846 | if (new_pos < end && is_joiner (info[new_pos])) |
| 847 | new_pos++; |
| 848 | |
| 849 | { |
| 850 | unsigned int old_pos = i; |
| 851 | hb_glyph_info_t tmp = info[old_pos]; |
| 852 | memmove (&info[new_pos + 1], &info[new_pos], (old_pos - new_pos) * sizeof (info[0])); |
| 853 | info[new_pos] = tmp; |
| 854 | start_of_last_cluster = MIN (new_pos, start_of_last_cluster); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | break; |
Behdad Esfahbod | 7881812 | 2012-07-16 15:49:08 -0400 | [diff] [blame] | 859 | } |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 860 | } |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 861 | |
| 862 | |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 863 | /* Apply 'init' to the Left Matra if it's a word start. */ |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 864 | if (info[start].indic_position () == POS_PRE_M && |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 865 | (!start || |
Behdad Esfahbod | eace47b | 2012-05-13 15:54:43 +0200 | [diff] [blame] | 866 | !(FLAG (_hb_glyph_info_get_general_category (&info[start - 1])) & |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 867 | (FLAG (HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER) | |
| 868 | FLAG (HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER) | |
| 869 | FLAG (HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER) | |
| 870 | FLAG (HB_UNICODE_GENERAL_CATEGORY_TITLECASE_LETTER) | |
| 871 | FLAG (HB_UNICODE_GENERAL_CATEGORY_UPPERCASE_LETTER) | |
| 872 | FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) | |
| 873 | FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | |
| 874 | FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK))))) |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 875 | info[start].mask |= init_mask; |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 876 | |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 877 | |
Behdad Esfahbod | 21d2803 | 2012-05-10 18:34:34 +0200 | [diff] [blame] | 878 | |
| 879 | /* Finish off the clusters and go home! */ |
| 880 | |
Behdad Esfahbod | a2b471d | 2012-06-05 15:17:44 -0400 | [diff] [blame] | 881 | if (!indic_options ().uniscribe_bug_compatible) |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 882 | { |
Behdad Esfahbod | 21d2803 | 2012-05-10 18:34:34 +0200 | [diff] [blame] | 883 | /* This is what Uniscribe does. Ie. add cluster boundaries after Halant,ZWNJ. |
| 884 | * This means, half forms are submerged into the main consonants cluster. |
| 885 | * This is unnecessary, and makes cursor positioning harder, but that's what |
| 886 | * Uniscribe does. */ |
| 887 | unsigned int cluster_start = start; |
| 888 | for (unsigned int i = start + 1; i < start_of_last_cluster; i++) |
| 889 | if (info[i - 1].indic_category() == OT_H && info[i].indic_category() == OT_ZWNJ) { |
| 890 | i++; |
| 891 | buffer->merge_clusters (cluster_start, i); |
| 892 | cluster_start = i; |
| 893 | } |
| 894 | start_of_last_cluster = cluster_start; |
| 895 | } |
| 896 | |
| 897 | buffer->merge_clusters (start_of_last_cluster, end); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 898 | } |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 899 | |
| 900 | |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 901 | static void |
| 902 | final_reordering (const hb_ot_map_t *map, |
Behdad Esfahbod | 3f18236 | 2012-05-13 16:20:10 +0200 | [diff] [blame] | 903 | hb_face_t *face HB_UNUSED, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 904 | hb_buffer_t *buffer, |
| 905 | void *user_data HB_UNUSED) |
| 906 | { |
| 907 | unsigned int count = buffer->len; |
| 908 | if (!count) return; |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 909 | |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 910 | hb_mask_t init_mask = map->get_1_mask (HB_TAG('i','n','i','t')); |
| 911 | hb_mask_t pref_mask = map->get_1_mask (HB_TAG('p','r','e','f')); |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 912 | |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 913 | hb_glyph_info_t *info = buffer->info; |
| 914 | unsigned int last = 0; |
Behdad Esfahbod | cee7187 | 2012-05-11 11:41:39 +0200 | [diff] [blame] | 915 | unsigned int last_syllable = info[0].syllable(); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 916 | for (unsigned int i = 1; i < count; i++) |
Behdad Esfahbod | cee7187 | 2012-05-11 11:41:39 +0200 | [diff] [blame] | 917 | if (last_syllable != info[i].syllable()) { |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 918 | final_reordering_syllable (buffer, init_mask, pref_mask, last, i); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 919 | last = i; |
Behdad Esfahbod | cee7187 | 2012-05-11 11:41:39 +0200 | [diff] [blame] | 920 | last_syllable = info[last].syllable(); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 921 | } |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 922 | final_reordering_syllable (buffer, init_mask, pref_mask, last, count); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 923 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 924 | HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category); |
| 925 | HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position); |
| 926 | } |
| 927 | |
| 928 | |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 929 | |