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 | 49c5ec5 | 2012-07-23 20:14:13 -0400 | [diff] [blame] | 29 | #include "hb-ot-layout-private.hh" |
Behdad Esfahbod | 352372a | 2011-07-30 19:04:02 -0400 | [diff] [blame] | 30 | |
Behdad Esfahbod | 1d00204 | 2012-08-02 05:01:11 -0400 | [diff] [blame] | 31 | |
Behdad Esfahbod | a3e04be | 2012-07-16 13:47:19 -0400 | [diff] [blame] | 32 | #define OLD_INDIC_TAG(script) (((hb_tag_t) script) | 0x20000000) |
| 33 | #define IS_OLD_INDIC_TAG(tag) ( \ |
Behdad Esfahbod | 1d00204 | 2012-08-02 05:01:11 -0400 | [diff] [blame] | 34 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_BENGALI) || \ |
| 35 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_DEVANAGARI) || \ |
| 36 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_GUJARATI) || \ |
| 37 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_GURMUKHI) || \ |
| 38 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_KANNADA) || \ |
| 39 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_MALAYALAM) || \ |
| 40 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_ORIYA) || \ |
| 41 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_TAMIL) || \ |
| 42 | (tag) == OLD_INDIC_TAG (HB_SCRIPT_TELUGU) || \ |
| 43 | 0) |
| 44 | |
| 45 | |
Behdad Esfahbod | a2b471d | 2012-06-05 15:17:44 -0400 | [diff] [blame] | 46 | struct indic_options_t |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 47 | { |
Behdad Esfahbod | a2b471d | 2012-06-05 15:17:44 -0400 | [diff] [blame] | 48 | int initialized : 1; |
| 49 | int uniscribe_bug_compatible : 1; |
| 50 | }; |
| 51 | |
| 52 | union indic_options_union_t { |
| 53 | int i; |
| 54 | indic_options_t opts; |
| 55 | }; |
| 56 | ASSERT_STATIC (sizeof (int) == sizeof (indic_options_union_t)); |
| 57 | |
| 58 | static indic_options_union_t |
| 59 | indic_options_init (void) |
| 60 | { |
| 61 | indic_options_union_t u; |
| 62 | u.i = 0; |
| 63 | u.opts.initialized = 1; |
| 64 | |
| 65 | char *c = getenv ("HB_OT_INDIC_OPTIONS"); |
| 66 | u.opts.uniscribe_bug_compatible = c && strstr (c, "uniscribe-bug-compatible"); |
| 67 | |
| 68 | return u; |
| 69 | } |
| 70 | |
| 71 | inline indic_options_t |
| 72 | indic_options (void) |
| 73 | { |
| 74 | static indic_options_union_t options; |
| 75 | |
| 76 | if (unlikely (!options.i)) { |
| 77 | /* This is idempotent and threadsafe. */ |
| 78 | options = indic_options_init (); |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Behdad Esfahbod | a2b471d | 2012-06-05 15:17:44 -0400 | [diff] [blame] | 81 | return options.opts; |
| 82 | } |
| 83 | |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 84 | |
Behdad Esfahbod | 9ccc638 | 2012-07-19 12:32:16 -0400 | [diff] [blame] | 85 | |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 86 | struct feature_list_t { |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 87 | hb_tag_t tag; |
| 88 | hb_bool_t is_global; |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 89 | }; |
| 90 | |
Behdad Esfahbod | d5c4edc | 2012-07-17 10:40:59 -0400 | [diff] [blame] | 91 | /* These features are applied one at a time, given the order in this table. */ |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 92 | static const feature_list_t |
| 93 | indic_basic_features[] = |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 94 | { |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 95 | {HB_TAG('n','u','k','t'), true}, |
Behdad Esfahbod | e047534 | 2012-07-19 20:24:14 -0400 | [diff] [blame] | 96 | {HB_TAG('a','k','h','n'), true}, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 97 | {HB_TAG('r','p','h','f'), false}, |
Behdad Esfahbod | 1ac075b | 2012-05-09 11:06:47 +0200 | [diff] [blame] | 98 | {HB_TAG('r','k','r','f'), true}, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 99 | {HB_TAG('p','r','e','f'), false}, |
| 100 | {HB_TAG('b','l','w','f'), false}, |
| 101 | {HB_TAG('h','a','l','f'), false}, |
Behdad Esfahbod | 29f106d | 2012-07-16 12:05:35 -0400 | [diff] [blame] | 102 | {HB_TAG('a','b','v','f'), false}, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 103 | {HB_TAG('p','s','t','f'), false}, |
Behdad Esfahbod | 0201e0a | 2012-07-17 13:55:10 -0400 | [diff] [blame] | 104 | {HB_TAG('c','f','a','r'), false}, |
Behdad Esfahbod | 20b68e6 | 2012-07-20 10:47:46 -0400 | [diff] [blame] | 105 | {HB_TAG('c','j','c','t'), true}, |
Behdad Esfahbod | 1d6846d | 2012-05-13 18:09:29 +0200 | [diff] [blame] | 106 | {HB_TAG('v','a','t','u'), true}, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | /* Same order as the indic_basic_features array */ |
| 110 | enum { |
| 111 | _NUKT, |
Behdad Esfahbod | e047534 | 2012-07-19 20:24:14 -0400 | [diff] [blame] | 112 | _AKHN, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 113 | RPHF, |
Behdad Esfahbod | df6d45c | 2012-05-09 11:38:31 +0200 | [diff] [blame] | 114 | _RKRF, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 115 | PREF, |
| 116 | BLWF, |
| 117 | HALF, |
Behdad Esfahbod | 29f106d | 2012-07-16 12:05:35 -0400 | [diff] [blame] | 118 | ABVF, |
Behdad Esfahbod | c7fe56a | 2011-06-24 19:05:34 -0400 | [diff] [blame] | 119 | PSTF, |
Behdad Esfahbod | 0201e0a | 2012-07-17 13:55:10 -0400 | [diff] [blame] | 120 | CFAR, |
Behdad Esfahbod | 20b68e6 | 2012-07-20 10:47:46 -0400 | [diff] [blame] | 121 | _CJCT, |
Behdad Esfahbod | 1d6846d | 2012-05-13 18:09:29 +0200 | [diff] [blame] | 122 | VATU |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 123 | }; |
| 124 | |
Behdad Esfahbod | d5c4edc | 2012-07-17 10:40:59 -0400 | [diff] [blame] | 125 | /* These features are applied all at once. */ |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 126 | static const feature_list_t |
| 127 | indic_other_features[] = |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 128 | { |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 129 | {HB_TAG('i','n','i','t'), false}, |
| 130 | {HB_TAG('p','r','e','s'), true}, |
| 131 | {HB_TAG('a','b','v','s'), true}, |
| 132 | {HB_TAG('b','l','w','s'), true}, |
| 133 | {HB_TAG('p','s','t','s'), true}, |
| 134 | {HB_TAG('h','a','l','n'), true}, |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 135 | |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 136 | {HB_TAG('d','i','s','t'), true}, |
| 137 | {HB_TAG('a','b','v','m'), true}, |
| 138 | {HB_TAG('b','l','w','m'), true}, |
| 139 | }; |
| 140 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 141 | |
| 142 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 143 | initial_reordering (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 144 | hb_font_t *font, |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 145 | hb_buffer_t *buffer); |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 146 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 147 | final_reordering (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 148 | hb_font_t *font, |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 149 | hb_buffer_t *buffer); |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 150 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 151 | static void |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 152 | collect_features_indic (hb_ot_shape_planner_t *plan) |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 153 | { |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 154 | hb_ot_map_builder_t *map = &plan->map; |
| 155 | |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 156 | map->add_bool_feature (HB_TAG('l','o','c','l')); |
Behdad Esfahbod | a54a550 | 2011-07-20 16:42:10 -0400 | [diff] [blame] | 157 | /* The Indic specs do not require ccmp, but we apply it here since if |
| 158 | * there is a use of it, it's typically at the beginning. */ |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 159 | map->add_bool_feature (HB_TAG('c','c','m','p')); |
| 160 | |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 161 | map->add_gsub_pause (initial_reordering); |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 162 | |
Behdad Esfahbod | 412b918 | 2012-05-09 11:07:18 +0200 | [diff] [blame] | 163 | for (unsigned int i = 0; i < ARRAY_LENGTH (indic_basic_features); i++) { |
Behdad Esfahbod | 76f7681 | 2011-07-07 22:25:25 -0400 | [diff] [blame] | 164 | map->add_bool_feature (indic_basic_features[i].tag, indic_basic_features[i].is_global); |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 165 | map->add_gsub_pause (NULL); |
Behdad Esfahbod | 412b918 | 2012-05-09 11:07:18 +0200 | [diff] [blame] | 166 | } |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 167 | |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 168 | map->add_gsub_pause (final_reordering); |
Behdad Esfahbod | f6fd378 | 2011-07-08 00:22:40 -0400 | [diff] [blame] | 169 | |
Behdad Esfahbod | d5c4edc | 2012-07-17 10:40:59 -0400 | [diff] [blame] | 170 | for (unsigned int i = 0; i < ARRAY_LENGTH (indic_other_features); i++) |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 171 | map->add_bool_feature (indic_other_features[i].tag, indic_other_features[i].is_global); |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 172 | } |
| 173 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 174 | static void |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 175 | override_features_indic (hb_ot_shape_planner_t *plan) |
Behdad Esfahbod | d96838e | 2012-07-16 20:26:57 -0400 | [diff] [blame] | 176 | { |
Behdad Esfahbod | af92b4c | 2012-07-16 20:31:24 -0400 | [diff] [blame] | 177 | /* Uniscribe does not apply 'kern'. */ |
| 178 | if (indic_options ().uniscribe_bug_compatible) |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 179 | plan->map.add_feature (HB_TAG('k','e','r','n'), 0, true); |
Behdad Esfahbod | d96838e | 2012-07-16 20:26:57 -0400 | [diff] [blame] | 180 | } |
| 181 | |
Behdad Esfahbod | 867361c | 2011-06-17 18:35:46 -0400 | [diff] [blame] | 182 | |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 183 | struct would_apply_feature_t |
| 184 | { |
| 185 | would_apply_feature_t (const hb_ot_map_t *map, hb_tag_t feature_tag) |
| 186 | { |
| 187 | map->get_stage_lookups (0/*GSUB*/, |
| 188 | map->get_feature_stage (0/*GSUB*/, feature_tag), |
| 189 | &lookups, &count); |
| 190 | } |
| 191 | |
| 192 | inline bool would_substitute (hb_codepoint_t *glyphs, |
| 193 | unsigned int glyphs_count, |
| 194 | hb_face_t *face) const |
| 195 | { |
| 196 | for (unsigned int i = 0; i < count; i++) |
| 197 | if (hb_ot_layout_would_substitute_lookup_fast (face, glyphs, glyphs_count, lookups[i].index)) |
| 198 | return true; |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | private: |
| 203 | const hb_ot_map_t::lookup_map_t *lookups; |
| 204 | unsigned int count; |
| 205 | }; |
| 206 | |
| 207 | struct indic_shape_plan_t |
| 208 | { |
| 209 | indic_shape_plan_t (const hb_ot_shape_plan_t *plan) : |
| 210 | pref (&plan->map, HB_TAG('p','r','e','f')), |
| 211 | blwf (&plan->map, HB_TAG('b','l','w','f')), |
| 212 | pstf (&plan->map, HB_TAG('p','s','t','f')), |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame^] | 213 | is_old_spec (IS_OLD_INDIC_TAG (plan->map.get_chosen_script (0))), |
| 214 | virama_glyph ((hb_codepoint_t) -1) |
| 215 | { |
| 216 | switch ((int) plan->props.script) { |
| 217 | case HB_SCRIPT_DEVANAGARI:virama = 0x094D; break; |
| 218 | case HB_SCRIPT_BENGALI: virama = 0x09CD; break; |
| 219 | case HB_SCRIPT_GURMUKHI: virama = 0x0A4D; break; |
| 220 | case HB_SCRIPT_GUJARATI: virama = 0x0ACD; break; |
| 221 | case HB_SCRIPT_ORIYA: virama = 0x0B4D; break; |
| 222 | case HB_SCRIPT_TAMIL: virama = 0x0BCD; break; |
| 223 | case HB_SCRIPT_TELUGU: virama = 0x0C4D; break; |
| 224 | case HB_SCRIPT_KANNADA: virama = 0x0CCD; break; |
| 225 | case HB_SCRIPT_MALAYALAM: virama = 0x0D4D; break; |
| 226 | case HB_SCRIPT_SINHALA: virama = 0x0DCA; break; |
| 227 | case HB_SCRIPT_KHMER: virama = 0x17D2; break; |
| 228 | default: virama = 0; break; |
| 229 | } |
| 230 | } |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 231 | |
| 232 | would_apply_feature_t pref; |
| 233 | would_apply_feature_t blwf; |
| 234 | would_apply_feature_t pstf; |
| 235 | bool is_old_spec; |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame^] | 236 | hb_codepoint_t virama; |
| 237 | hb_codepoint_t virama_glyph; |
| 238 | |
| 239 | inline bool get_virama_glyph (hb_font_t *font, hb_codepoint_t *pglyph) const |
| 240 | { |
| 241 | hb_codepoint_t glyph = virama_glyph; |
| 242 | if (unlikely (virama_glyph == (hb_codepoint_t) -1)) |
| 243 | { |
| 244 | if (!font->get_glyph (virama, 0, &glyph)) |
| 245 | glyph = 0; |
| 246 | /* Technically speaking, the spec says we should apply 'locl' to virama too. |
| 247 | * Maybe one day... */ |
| 248 | |
| 249 | /* Our get_glyph() function needs a font, so we can't get the virama glyph |
| 250 | * during shape planning... Instead, overwrite it here. It's safe. Don't worry! */ |
| 251 | (const_cast<indic_shape_plan_t *> (this))->virama_glyph = glyph; |
| 252 | } |
| 253 | |
| 254 | *pglyph = glyph; |
| 255 | return glyph != 0; |
| 256 | } |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 257 | }; |
| 258 | |
| 259 | static void * |
| 260 | data_create_indic (const hb_ot_shape_plan_t *plan) |
| 261 | { |
| 262 | indic_shape_plan_t *data = (indic_shape_plan_t *) calloc (1, sizeof (indic_shape_plan_t)); |
| 263 | if (unlikely (!data)) |
| 264 | return NULL; |
| 265 | |
| 266 | /* Mixing C++ and C, oh well... */ |
| 267 | indic_shape_plan_t indic_plan (plan); |
| 268 | |
| 269 | *data = indic_plan; |
| 270 | return data; |
| 271 | } |
| 272 | |
| 273 | static void |
| 274 | data_destroy_indic (void *data) |
| 275 | { |
| 276 | free (data); |
| 277 | } |
| 278 | |
| 279 | static indic_position_t |
| 280 | consonant_position_from_face (const indic_shape_plan_t *indic_plan, |
| 281 | hb_codepoint_t *glyphs, unsigned int glyphs_len, |
| 282 | hb_face_t *face) |
| 283 | { |
| 284 | if (indic_plan->pref.would_substitute (glyphs, ARRAY_LENGTH (glyphs), face)) return POS_BELOW_C; |
| 285 | if (indic_plan->blwf.would_substitute (glyphs, ARRAY_LENGTH (glyphs), face)) return POS_BELOW_C; |
| 286 | if (indic_plan->pstf.would_substitute (glyphs, ARRAY_LENGTH (glyphs), face)) return POS_POST_C; |
| 287 | return POS_BASE_C; |
| 288 | } |
| 289 | |
| 290 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 291 | static void |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 292 | setup_masks_indic (const hb_ot_shape_plan_t *plan HB_UNUSED, |
| 293 | hb_buffer_t *buffer, |
| 294 | hb_font_t *font HB_UNUSED) |
Behdad Esfahbod | 24eacf1 | 2012-08-02 08:42:11 -0400 | [diff] [blame] | 295 | { |
| 296 | HB_BUFFER_ALLOCATE_VAR (buffer, indic_category); |
| 297 | HB_BUFFER_ALLOCATE_VAR (buffer, indic_position); |
| 298 | |
| 299 | /* We cannot setup masks here. We save information about characters |
| 300 | * and setup masks later on in a pause-callback. */ |
| 301 | |
| 302 | unsigned int count = buffer->len; |
| 303 | for (unsigned int i = 0; i < count; i++) |
| 304 | set_indic_properties (buffer->info[i]); |
| 305 | } |
| 306 | |
| 307 | static int |
| 308 | compare_indic_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) |
| 309 | { |
| 310 | int a = pa->indic_position(); |
| 311 | int b = pb->indic_position(); |
| 312 | |
| 313 | return a < b ? -1 : a == b ? 0 : +1; |
| 314 | } |
| 315 | |
| 316 | |
| 317 | |
| 318 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 319 | update_consonant_positions (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 320 | hb_buffer_t *buffer, |
| 321 | hb_font_t *font) |
| 322 | { |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 323 | 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] | 324 | |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 325 | unsigned int consonant_pos = indic_plan->is_old_spec ? 0 : 1; |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 326 | hb_codepoint_t glyphs[2]; |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame^] | 327 | if (indic_plan->get_virama_glyph (font, &glyphs[1 - consonant_pos])) |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 328 | { |
| 329 | hb_face_t *face = font->face; |
| 330 | unsigned int count = buffer->len; |
| 331 | for (unsigned int i = 0; i < count; i++) |
| 332 | if (buffer->info[i].indic_position() == POS_BASE_C) { |
Behdad Esfahbod | 24eacf1 | 2012-08-02 08:42:11 -0400 | [diff] [blame] | 333 | glyphs[consonant_pos] = buffer->info[i].codepoint; |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 334 | buffer->info[i].indic_position() = consonant_position_from_face (indic_plan, glyphs, 2, face); |
Behdad Esfahbod | 8ef3d53 | 2012-08-02 07:53:18 -0400 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
Behdad Esfahbod | 867361c | 2011-06-17 18:35:46 -0400 | [diff] [blame] | 339 | |
Behdad Esfahbod | 7ea58db | 2012-05-11 18:58:57 +0200 | [diff] [blame] | 340 | /* Rules from: |
| 341 | * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */ |
| 342 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 343 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 344 | initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan, hb_buffer_t *buffer, hb_mask_t *basic_mask_array, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 345 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 346 | { |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame^] | 347 | 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] | 348 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 349 | |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 350 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 351 | /* 1. Find base consonant: |
| 352 | * |
| 353 | * The shaping engine finds the base consonant of the syllable, using the |
| 354 | * following algorithm: starting from the end of the syllable, move backwards |
| 355 | * until a consonant is found that does not have a below-base or post-base |
| 356 | * form (post-base forms have to follow below-base forms), or that is not a |
| 357 | * pre-base reordering Ra, or arrive at the first consonant. The consonant |
| 358 | * stopped at will be the base. |
| 359 | * |
| 360 | * o If the syllable starts with Ra + Halant (in a script that has Reph) |
| 361 | * and has more than one consonant, Ra is excluded from candidates for |
| 362 | * base consonants. |
| 363 | */ |
| 364 | |
Behdad Esfahbod | 5e72071 | 2011-07-31 17:51:50 -0400 | [diff] [blame] | 365 | unsigned int base = end; |
Behdad Esfahbod | 76b3409 | 2012-05-09 11:43:43 +0200 | [diff] [blame] | 366 | bool has_reph = false; |
| 367 | |
Behdad Esfahbod | 76b3409 | 2012-05-09 11:43:43 +0200 | [diff] [blame] | 368 | { |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 369 | /* -> If the syllable starts with Ra + Halant (in a script that has Reph) |
| 370 | * and has more than one consonant, Ra is excluded from candidates for |
| 371 | * base consonants. */ |
| 372 | unsigned int limit = start; |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 373 | if (basic_mask_array[RPHF] && |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 374 | start + 3 <= end && |
| 375 | info[start].indic_category() == OT_Ra && |
| 376 | info[start + 1].indic_category() == OT_H && |
Behdad Esfahbod | f31d97e | 2012-07-20 14:13:35 -0400 | [diff] [blame] | 377 | (unlikely (buffer->props.script == HB_SCRIPT_SINHALA || buffer->props.script == HB_SCRIPT_TELUGU) ? |
| 378 | info[start + 2].indic_category() == OT_ZWJ /* In Sinhala & Telugu, form Reph only if ZWJ is present */: |
Behdad Esfahbod | 3285e10 | 2012-07-18 17:22:14 -0400 | [diff] [blame] | 379 | !is_joiner (info[start + 2] /* In other scripts, any joiner blocks Reph formation */ ) |
| 380 | )) |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 381 | { |
| 382 | limit += 2; |
Behdad Esfahbod | 3285e10 | 2012-07-18 17:22:14 -0400 | [diff] [blame] | 383 | while (limit < end && is_joiner (info[limit])) |
| 384 | limit++; |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 385 | base = start; |
| 386 | has_reph = true; |
| 387 | }; |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 388 | |
Behdad Esfahbod | 14dbdd9 | 2012-07-18 13:13:03 -0400 | [diff] [blame] | 389 | enum base_position_t { |
| 390 | BASE_FIRST, |
| 391 | BASE_LAST |
| 392 | } base_pos; |
| 393 | |
| 394 | switch ((hb_tag_t) buffer->props.script) |
| 395 | { |
Behdad Esfahbod | 34c2150 | 2012-07-23 23:51:29 -0400 | [diff] [blame] | 396 | case HB_SCRIPT_SINHALA: |
Behdad Esfahbod | 14dbdd9 | 2012-07-18 13:13:03 -0400 | [diff] [blame] | 397 | case HB_SCRIPT_KHMER: |
| 398 | base_pos = BASE_FIRST; |
| 399 | break; |
| 400 | |
| 401 | default: |
| 402 | base_pos = BASE_LAST; |
| 403 | break; |
| 404 | } |
| 405 | |
| 406 | if (base_pos == BASE_LAST) |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 407 | { |
| 408 | /* -> starting from the end of the syllable, move backwards */ |
| 409 | unsigned int i = end; |
Behdad Esfahbod | 92a1ad7 | 2012-07-20 18:38:27 -0400 | [diff] [blame] | 410 | bool seen_below = false; |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 411 | do { |
| 412 | i--; |
| 413 | /* -> until a consonant is found */ |
| 414 | if (is_consonant (info[i])) |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 415 | { |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 416 | /* -> that does not have a below-base or post-base form |
| 417 | * (post-base forms have to follow below-base forms), */ |
| 418 | if (info[i].indic_position() != POS_BELOW_C && |
Behdad Esfahbod | 92a1ad7 | 2012-07-20 18:38:27 -0400 | [diff] [blame] | 419 | (info[i].indic_position() != POS_POST_C || seen_below)) |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 420 | { |
| 421 | base = i; |
| 422 | break; |
| 423 | } |
Behdad Esfahbod | 92a1ad7 | 2012-07-20 18:38:27 -0400 | [diff] [blame] | 424 | if (info[i].indic_position() == POS_BELOW_C) |
| 425 | seen_below = true; |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 426 | |
| 427 | /* -> or that is not a pre-base reordering Ra, |
| 428 | * |
Behdad Esfahbod | 25e302d | 2012-07-17 14:25:14 -0400 | [diff] [blame] | 429 | * IMPLEMENTATION NOTES: |
| 430 | * |
| 431 | * Our pre-base reordering Ra's are marked POS_BELOW, so will be skipped |
| 432 | * by the logic above already. |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 433 | */ |
| 434 | |
| 435 | /* -> or arrive at the first consonant. The consonant stopped at will |
| 436 | * be the base. */ |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 437 | base = i; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 438 | } |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 439 | else |
Behdad Esfahbod | a9e45c3 | 2012-07-20 11:04:15 -0400 | [diff] [blame] | 440 | { |
Behdad Esfahbod | 88f413b | 2012-07-24 03:04:36 -0400 | [diff] [blame] | 441 | /* A ZWJ after a Halant stops the base search, and requests an explicit |
| 442 | * half form. |
| 443 | * A ZWJ before a Halant, requests a subjoined form instead, and hence |
| 444 | * search continues. This is particularly important for Bengali |
| 445 | * sequence Ra,H,Ya that shouls form Ya-Phalaa by subjoining Ya. */ |
| 446 | if (start < i && |
| 447 | info[i].indic_category() == OT_ZWJ && |
| 448 | info[i - 1].indic_category() == OT_H) |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 449 | break; |
Behdad Esfahbod | a9e45c3 | 2012-07-20 11:04:15 -0400 | [diff] [blame] | 450 | } |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 451 | } while (i > limit); |
| 452 | } |
| 453 | else |
| 454 | { |
| 455 | /* In scripts without half forms (eg. Khmer), the first consonant is always the base. */ |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 456 | |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 457 | if (!has_reph) |
| 458 | base = limit; |
Behdad Esfahbod | 34c2150 | 2012-07-23 23:51:29 -0400 | [diff] [blame] | 459 | |
| 460 | /* Find the last base consonant that is not blocked by ZWJ. If there is |
Behdad Esfahbod | 71fd5e8 | 2012-07-24 00:21:16 -0400 | [diff] [blame] | 461 | * a ZWJ right before a base consonant, that would request a subjoined form. */ |
Behdad Esfahbod | 34c2150 | 2012-07-23 23:51:29 -0400 | [diff] [blame] | 462 | for (unsigned int i = limit; i < end; i++) |
| 463 | if (is_consonant (info[i]) && info[i].indic_position() == POS_BASE_C) |
Behdad Esfahbod | 71fd5e8 | 2012-07-24 00:21:16 -0400 | [diff] [blame] | 464 | { |
| 465 | if (limit < i && info[i - 1].indic_category() == OT_ZWJ) |
| 466 | break; |
| 467 | else |
| 468 | base = i; |
| 469 | } |
Behdad Esfahbod | 34c2150 | 2012-07-23 23:51:29 -0400 | [diff] [blame] | 470 | |
| 471 | /* Mark all subsequent consonants as below. */ |
| 472 | for (unsigned int i = base + 1; i < end; i++) |
| 473 | if (is_consonant (info[i]) && info[i].indic_position() == POS_BASE_C) |
| 474 | info[i].indic_position() = POS_BELOW_C; |
Behdad Esfahbod | 5d32690 | 2012-07-17 14:23:28 -0400 | [diff] [blame] | 475 | } |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 476 | |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 477 | /* -> If the syllable starts with Ra + Halant (in a script that has Reph) |
| 478 | * and has more than one consonant, Ra is excluded from candidates for |
Behdad Esfahbod | 2278eef | 2012-07-24 00:26:43 -0400 | [diff] [blame] | 479 | * base consonants. |
| 480 | * |
| 481 | * Only do this for unforced Reph. (ie. not for Ra,H,ZWJ. */ |
| 482 | if (has_reph && base == start && start + 2 == limit) { |
Behdad Esfahbod | 617f4ac | 2012-05-13 16:48:03 +0200 | [diff] [blame] | 483 | /* Have no other consonant, so Reph is not formed and Ra becomes base. */ |
| 484 | has_reph = false; |
| 485 | } |
Behdad Esfahbod | 5e4e21f | 2012-05-13 16:46:08 +0200 | [diff] [blame] | 486 | } |
Behdad Esfahbod | 2278eef | 2012-07-24 00:26:43 -0400 | [diff] [blame] | 487 | |
Behdad Esfahbod | 34c2150 | 2012-07-23 23:51:29 -0400 | [diff] [blame] | 488 | if (base < end) |
| 489 | info[base].indic_position() = POS_BASE_C; |
Behdad Esfahbod | 3d25079 | 2012-05-10 11:37:42 +0200 | [diff] [blame] | 490 | |
| 491 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 492 | /* 2. Decompose and reorder Matras: |
| 493 | * |
| 494 | * Each matra and any syllable modifier sign in the cluster are moved to the |
| 495 | * appropriate position relative to the consonant(s) in the cluster. The |
| 496 | * shaping engine decomposes two- or three-part matras into their constituent |
| 497 | * parts before any repositioning. Matra characters are classified by which |
| 498 | * consonant in a conjunct they have affinity for and are reordered to the |
| 499 | * following positions: |
| 500 | * |
| 501 | * o Before first half form in the syllable |
| 502 | * o After subjoined consonants |
| 503 | * o After post-form consonant |
| 504 | * o After main consonant (for above marks) |
| 505 | * |
| 506 | * IMPLEMENTATION NOTES: |
| 507 | * |
| 508 | * The normalize() routine has already decomposed matras for us, so we don't |
| 509 | * need to worry about that. |
| 510 | */ |
| 511 | |
| 512 | |
| 513 | /* 3. Reorder marks to canonical order: |
| 514 | * |
| 515 | * Adjacent nukta and halant or nukta and vedic sign are always repositioned |
| 516 | * if necessary, so that the nukta is first. |
| 517 | * |
| 518 | * IMPLEMENTATION NOTES: |
| 519 | * |
| 520 | * We don't need to do this: the normalize() routine already did this for us. |
| 521 | */ |
| 522 | |
| 523 | |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 524 | /* Reorder characters */ |
| 525 | |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 526 | for (unsigned int i = start; i < base; i++) |
Behdad Esfahbod | 900cf3d | 2012-07-20 10:18:23 -0400 | [diff] [blame] | 527 | info[i].indic_position() = MIN (POS_PRE_C, (indic_position_t) info[i].indic_position()); |
Behdad Esfahbod | 55f70eb | 2012-07-17 12:50:13 -0400 | [diff] [blame] | 528 | |
Behdad Esfahbod | 075d671 | 2012-07-18 15:41:53 -0400 | [diff] [blame] | 529 | if (base < end) |
| 530 | info[base].indic_position() = POS_BASE_C; |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 531 | |
Behdad Esfahbod | 55f70eb | 2012-07-17 12:50:13 -0400 | [diff] [blame] | 532 | /* Mark final consonants. A final consonant is one appearing after a matra, |
| 533 | * like in Khmer. */ |
| 534 | for (unsigned int i = base + 1; i < end; i++) |
| 535 | if (info[i].indic_category() == OT_M) { |
| 536 | for (unsigned int j = i + 1; j < end; j++) |
| 537 | if (is_consonant (info[j])) { |
| 538 | info[j].indic_position() = POS_FINAL_C; |
| 539 | break; |
| 540 | } |
| 541 | break; |
| 542 | } |
| 543 | |
Behdad Esfahbod | fd06bf5 | 2011-07-30 20:14:44 -0400 | [diff] [blame] | 544 | /* Handle beginning Ra */ |
Behdad Esfahbod | 5e4e21f | 2012-05-13 16:46:08 +0200 | [diff] [blame] | 545 | if (has_reph) |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 546 | info[start].indic_position() = POS_RA_TO_BECOME_REPH; |
Behdad Esfahbod | fd06bf5 | 2011-07-30 20:14:44 -0400 | [diff] [blame] | 547 | |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 548 | /* For old-style Indic script tags, move the first post-base Halant after |
| 549 | * last consonant. */ |
Behdad Esfahbod | 914ffaa | 2012-08-02 11:03:39 -0400 | [diff] [blame^] | 550 | if (indic_plan->is_old_spec) { |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 551 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 552 | if (info[i].indic_category() == OT_H) { |
| 553 | unsigned int j; |
| 554 | for (j = end - 1; j > i; j--) |
Behdad Esfahbod | 190eb31 | 2012-05-10 12:17:16 +0200 | [diff] [blame] | 555 | if (is_consonant (info[j])) |
Behdad Esfahbod | f5bc272 | 2011-07-30 21:08:10 -0400 | [diff] [blame] | 556 | break; |
| 557 | if (j > i) { |
| 558 | /* Move Halant to after last consonant. */ |
| 559 | hb_glyph_info_t t = info[i]; |
| 560 | memmove (&info[i], &info[i + 1], (j - i) * sizeof (info[0])); |
| 561 | info[j] = t; |
| 562 | } |
| 563 | break; |
| 564 | } |
| 565 | } |
| 566 | |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 567 | /* Attach misc marks to previous char to move with them. */ |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 568 | { |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 569 | indic_position_t last_pos = POS_START; |
| 570 | for (unsigned int i = start; i < end; i++) |
| 571 | { |
| 572 | if ((FLAG (info[i].indic_category()) & (JOINER_FLAGS | FLAG (OT_N) | FLAG (OT_RS) | HALANT_OR_COENG_FLAGS))) |
| 573 | { |
| 574 | info[i].indic_position() = last_pos; |
| 575 | if (unlikely (indic_options ().uniscribe_bug_compatible && |
| 576 | info[i].indic_category() == OT_H && |
| 577 | info[i].indic_position() == POS_PRE_M)) |
| 578 | { |
| 579 | /* |
| 580 | * Uniscribe doesn't move the Halant with Left Matra. |
| 581 | * TEST: U+092B,U+093F,U+094DE |
| 582 | */ |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 583 | for (unsigned int j = i; j > start; j--) |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 584 | if (info[j - 1].indic_position() != POS_PRE_M) { |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 585 | info[i].indic_position() = info[j - 1].indic_position(); |
| 586 | break; |
| 587 | } |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 588 | } |
| 589 | } else if (info[i].indic_position() != POS_SMVD) { |
| 590 | last_pos = (indic_position_t) info[i].indic_position(); |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 591 | } |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 592 | } |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 593 | } |
Behdad Esfahbod | 74ccc6a | 2012-07-17 11:16:19 -0400 | [diff] [blame] | 594 | /* Re-attach ZWJ, ZWNJ, and halant to next char, for after-base consonants. */ |
| 595 | { |
| 596 | unsigned int last_halant = end; |
| 597 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | deb521d | 2012-07-17 11:37:32 -0400 | [diff] [blame] | 598 | if (is_halant_or_coeng (info[i])) |
Behdad Esfahbod | 74ccc6a | 2012-07-17 11:16:19 -0400 | [diff] [blame] | 599 | last_halant = i; |
| 600 | else if (is_consonant (info[i])) { |
| 601 | for (unsigned int j = last_halant; j < i; j++) |
Behdad Esfahbod | 81202bd | 2012-07-20 15:10:02 -0400 | [diff] [blame] | 602 | if (info[j].indic_position() != POS_SMVD) |
| 603 | info[j].indic_position() = info[i].indic_position(); |
Behdad Esfahbod | 74ccc6a | 2012-07-17 11:16:19 -0400 | [diff] [blame] | 604 | } |
| 605 | } |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 606 | |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 607 | { |
Behdad Esfahbod | 7b2a7da | 2012-07-22 23:58:55 -0400 | [diff] [blame] | 608 | /* Things are out-of-control for post base positions, they may shuffle |
| 609 | * around like crazy, so merge clusters. For pre-base stuff, we handle |
| 610 | * cluster issues in final reordering. */ |
| 611 | buffer->merge_clusters (base, end); |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 612 | /* Sit tight, rock 'n roll! */ |
Behdad Esfahbod | d3637ed | 2012-05-10 10:51:38 +0200 | [diff] [blame] | 613 | hb_bubble_sort (info + start, end - start, compare_indic_order); |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 614 | /* Find base again */ |
| 615 | base = end; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 616 | for (unsigned int i = start; i < end; i++) |
Behdad Esfahbod | a391ff5 | 2012-05-10 11:31:20 +0200 | [diff] [blame] | 617 | if (info[i].indic_position() == POS_BASE_C) { |
| 618 | base = i; |
| 619 | break; |
| 620 | } |
| 621 | } |
Behdad Esfahbod | 45d6f29 | 2011-07-30 14:44:30 -0400 | [diff] [blame] | 622 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 623 | /* Setup masks now */ |
| 624 | |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 625 | { |
| 626 | hb_mask_t mask; |
| 627 | |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 628 | /* Reph */ |
Behdad Esfahbod | 668c604 | 2012-05-11 15:34:13 +0200 | [diff] [blame] | 629 | 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] | 630 | info[i].mask |= basic_mask_array[RPHF]; |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 631 | |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 632 | /* Pre-base */ |
Behdad Esfahbod | 20b68e6 | 2012-07-20 10:47:46 -0400 | [diff] [blame] | 633 | mask = basic_mask_array[HALF]; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 634 | for (unsigned int i = start; i < base; i++) |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 635 | info[i].mask |= mask; |
| 636 | /* Base */ |
Behdad Esfahbod | 20b68e6 | 2012-07-20 10:47:46 -0400 | [diff] [blame] | 637 | mask = 0; |
Behdad Esfahbod | 075d671 | 2012-07-18 15:41:53 -0400 | [diff] [blame] | 638 | if (base < end) |
| 639 | info[base].mask |= mask; |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 640 | /* Post-base */ |
Behdad Esfahbod | 20b68e6 | 2012-07-20 10:47:46 -0400 | [diff] [blame] | 641 | mask = basic_mask_array[BLWF] | basic_mask_array[ABVF] | basic_mask_array[PSTF]; |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 642 | for (unsigned int i = base + 1; i < end; i++) |
Behdad Esfahbod | 2816839 | 2011-07-31 16:00:35 -0400 | [diff] [blame] | 643 | info[i].mask |= mask; |
| 644 | } |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 645 | |
Behdad Esfahbod | 17d7de9 | 2012-07-16 15:20:15 -0400 | [diff] [blame] | 646 | /* XXX This will not match for old-Indic spec since the Halant-Ra order is reversed already. */ |
Behdad Esfahbod | 5f0eaaa | 2012-07-20 15:47:24 -0400 | [diff] [blame] | 647 | if (basic_mask_array[PREF] && base + 2 < end) |
Behdad Esfahbod | 17d7de9 | 2012-07-16 15:20:15 -0400 | [diff] [blame] | 648 | { |
Behdad Esfahbod | 771a8f5 | 2012-07-23 20:07:50 -0400 | [diff] [blame] | 649 | /* Find a Halant,Ra sequence and mark it for pre-base reordering processing. */ |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 650 | for (unsigned int i = base + 1; i + 1 < end; i++) |
Behdad Esfahbod | deb521d | 2012-07-17 11:37:32 -0400 | [diff] [blame] | 651 | if (is_halant_or_coeng (info[i]) && |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 652 | info[i + 1].indic_category() == OT_Ra) |
| 653 | { |
Behdad Esfahbod | 0201e0a | 2012-07-17 13:55:10 -0400 | [diff] [blame] | 654 | info[i++].mask |= basic_mask_array[PREF]; |
| 655 | info[i++].mask |= basic_mask_array[PREF]; |
| 656 | |
| 657 | /* Mark the subsequent stuff with 'cfar'. Used in Khmer. |
| 658 | * Read the feature spec. |
| 659 | * This allows distinguishing the following cases with MS Khmer fonts: |
| 660 | * U+1784,U+17D2,U+179A,U+17D2,U+1782 |
| 661 | * U+1784,U+17D2,U+1782,U+17D2,U+179A |
| 662 | */ |
| 663 | for (; i < end; i++) |
| 664 | info[i].mask |= basic_mask_array[CFAR]; |
| 665 | |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 666 | break; |
| 667 | } |
Behdad Esfahbod | 17d7de9 | 2012-07-16 15:20:15 -0400 | [diff] [blame] | 668 | } |
| 669 | |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 670 | /* Apply ZWJ/ZWNJ effects */ |
Behdad Esfahbod | 3c2ea94 | 2012-05-11 16:23:38 +0200 | [diff] [blame] | 671 | for (unsigned int i = start + 1; i < end; i++) |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 672 | if (is_joiner (info[i])) { |
| 673 | bool non_joiner = info[i].indic_category() == OT_ZWNJ; |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 674 | unsigned int j = i; |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 675 | |
| 676 | do { |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 677 | j--; |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 678 | |
Behdad Esfahbod | 20b68e6 | 2012-07-20 10:47:46 -0400 | [diff] [blame] | 679 | /* A ZWJ disables CJCT, however, it's mere presence is enough |
| 680 | * to disable ligation. No explicit action needed. */ |
| 681 | |
| 682 | /* A ZWNJ disables HALF. */ |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 683 | if (non_joiner) |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 684 | info[j].mask &= ~basic_mask_array[HALF]; |
Behdad Esfahbod | 6b37bc8 | 2011-07-31 15:57:00 -0400 | [diff] [blame] | 685 | |
Behdad Esfahbod | 9da0487 | 2011-07-31 13:46:44 -0400 | [diff] [blame] | 686 | } while (j > start && !is_consonant (info[j])); |
| 687 | } |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | |
| 691 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 692 | initial_reordering_vowel_syllable (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | 9f377ed | 2012-05-13 16:13:44 +0200 | [diff] [blame] | 693 | hb_buffer_t *buffer, |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 694 | hb_mask_t *basic_mask_array, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 695 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 696 | { |
Behdad Esfahbod | c5306b6 | 2012-05-10 12:07:33 +0200 | [diff] [blame] | 697 | /* We made the vowels look like consonants. So let's call the consonant logic! */ |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 698 | initial_reordering_consonant_syllable (plan, buffer, basic_mask_array, start, end); |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 702 | initial_reordering_standalone_cluster (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | 9f377ed | 2012-05-13 16:13:44 +0200 | [diff] [blame] | 703 | hb_buffer_t *buffer, |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 704 | hb_mask_t *basic_mask_array, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 705 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 706 | { |
Behdad Esfahbod | 18c06e1 | 2012-05-11 20:02:14 +0200 | [diff] [blame] | 707 | /* We treat NBSP/dotted-circle as if they are consonants, so we should just chain. |
| 708 | * Only if not in compatibility mode that is... */ |
| 709 | |
Behdad Esfahbod | a2b471d | 2012-06-05 15:17:44 -0400 | [diff] [blame] | 710 | if (indic_options ().uniscribe_bug_compatible) |
Behdad Esfahbod | 18c06e1 | 2012-05-11 20:02:14 +0200 | [diff] [blame] | 711 | { |
| 712 | /* For dotted-circle, this is what Uniscribe does: |
| 713 | * If dotted-circle is the last glyph, it just does nothing. |
| 714 | * Ie. It doesn't form Reph. */ |
| 715 | if (buffer->info[end - 1].indic_category() == OT_DOTTEDCIRCLE) |
| 716 | return; |
| 717 | } |
| 718 | |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 719 | initial_reordering_consonant_syllable (plan, buffer, basic_mask_array, start, end); |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 723 | initial_reordering_non_indic (const hb_ot_shape_plan_t *plan HB_UNUSED, |
Behdad Esfahbod | 9f377ed | 2012-05-13 16:13:44 +0200 | [diff] [blame] | 724 | hb_buffer_t *buffer HB_UNUSED, |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 725 | hb_mask_t *basic_mask_array HB_UNUSED, |
Behdad Esfahbod | 3f18236 | 2012-05-13 16:20:10 +0200 | [diff] [blame] | 726 | unsigned int start HB_UNUSED, unsigned int end HB_UNUSED) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 727 | { |
| 728 | /* Nothing to do right now. If we ever switch to using the output |
| 729 | * buffer in the reordering process, we'd need to next_glyph() here. */ |
| 730 | } |
| 731 | |
| 732 | #include "hb-ot-shape-complex-indic-machine.hh" |
| 733 | |
| 734 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 735 | initial_reordering (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | 24eacf1 | 2012-08-02 08:42:11 -0400 | [diff] [blame] | 736 | hb_font_t *font, |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 737 | hb_buffer_t *buffer) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 738 | { |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 739 | update_consonant_positions (plan, buffer, font); |
Behdad Esfahbod | 24eacf1 | 2012-08-02 08:42:11 -0400 | [diff] [blame] | 740 | |
Behdad Esfahbod | 70fe77b | 2012-07-16 14:52:18 -0400 | [diff] [blame] | 741 | hb_mask_t basic_mask_array[ARRAY_LENGTH (indic_basic_features)] = {0}; |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 742 | unsigned int num_masks = ARRAY_LENGTH (indic_basic_features); |
| 743 | for (unsigned int i = 0; i < num_masks; i++) |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 744 | basic_mask_array[i] = plan->map.get_1_mask (indic_basic_features[i].tag); |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 745 | |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 746 | find_syllables (plan, buffer, basic_mask_array); |
Behdad Esfahbod | b9ddbd5 | 2011-06-02 17:43:12 -0400 | [diff] [blame] | 747 | } |
| 748 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 749 | static void |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 750 | final_reordering_syllable (hb_buffer_t *buffer, |
| 751 | hb_mask_t init_mask, hb_mask_t pref_mask, |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 752 | unsigned int start, unsigned int end) |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 753 | { |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 754 | hb_glyph_info_t *info = buffer->info; |
| 755 | |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 756 | /* 4. Final reordering: |
| 757 | * |
| 758 | * After the localized forms and basic shaping forms GSUB features have been |
| 759 | * applied (see below), the shaping engine performs some final glyph |
| 760 | * reordering before applying all the remaining font features to the entire |
| 761 | * cluster. |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 762 | */ |
| 763 | |
| 764 | /* Find base again */ |
Behdad Esfahbod | 5f0eaaa | 2012-07-20 15:47:24 -0400 | [diff] [blame] | 765 | unsigned int base; |
| 766 | for (base = start; base < end; base++) |
| 767 | if (info[base].indic_position() >= POS_BASE_C) { |
| 768 | if (start < base && info[base].indic_position() > POS_BASE_C) |
| 769 | base--; |
| 770 | break; |
| 771 | } |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 772 | |
Behdad Esfahbod | 4705a70 | 2012-05-10 13:09:08 +0200 | [diff] [blame] | 773 | |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 774 | /* o Reorder matras: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 775 | * |
| 776 | * If a pre-base matra character had been reordered before applying basic |
| 777 | * features, the glyph can be moved closer to the main consonant based on |
| 778 | * whether half-forms had been formed. Actual position for the matra is |
| 779 | * defined as “after last standalone halant glyph, after initial matra |
| 780 | * position and before the main consonant”. If ZWJ or ZWNJ follow this |
| 781 | * halant, position is moved after it. |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 782 | */ |
| 783 | |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 784 | 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] | 785 | { |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 786 | /* If we lost track of base, alas, position before last thingy. */ |
| 787 | unsigned int new_pos = base == end ? base - 2 : base - 1; |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 788 | |
Behdad Esfahbod | 65c43ac | 2012-07-24 03:36:47 -0400 | [diff] [blame] | 789 | /* Malayalam does not have "half" forms or explicit virama forms. |
| 790 | * The glyphs formed by 'half' are Chillus. We want to position |
| 791 | * matra after them all. |
| 792 | */ |
| 793 | if (buffer->props.script != HB_SCRIPT_MALAYALAM) |
| 794 | { |
| 795 | while (new_pos > start && |
| 796 | !(is_one_of (info[new_pos], (FLAG (OT_M) | FLAG (OT_H) | FLAG (OT_Coeng))))) |
| 797 | new_pos--; |
| 798 | |
| 799 | /* If we found no Halant we are done. |
| 800 | * Otherwise only proceed if the Halant does |
| 801 | * not belong to the Matra itself! */ |
| 802 | if (is_halant_or_coeng (info[new_pos]) && |
| 803 | info[new_pos].indic_position() != POS_PRE_M) |
| 804 | { |
| 805 | /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ |
| 806 | if (new_pos + 1 < end && is_joiner (info[new_pos + 1])) |
| 807 | new_pos++; |
| 808 | } |
| 809 | else |
| 810 | new_pos = start; /* No move. */ |
| 811 | } |
| 812 | |
| 813 | if (start < new_pos) |
| 814 | { |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 815 | /* Now go see if there's actually any matras... */ |
Behdad Esfahbod | 921ce5b | 2012-07-16 15:26:56 -0400 | [diff] [blame] | 816 | for (unsigned int i = new_pos; i > start; i--) |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 817 | if (info[i - 1].indic_position () == POS_PRE_M) |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 818 | { |
Behdad Esfahbod | 1a1dbe9 | 2012-07-16 15:40:33 -0400 | [diff] [blame] | 819 | unsigned int old_pos = i - 1; |
| 820 | hb_glyph_info_t tmp = info[old_pos]; |
| 821 | memmove (&info[old_pos], &info[old_pos + 1], (new_pos - old_pos) * sizeof (info[0])); |
| 822 | info[new_pos] = tmp; |
Behdad Esfahbod | 921ce5b | 2012-07-16 15:26:56 -0400 | [diff] [blame] | 823 | new_pos--; |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 824 | } |
Behdad Esfahbod | 2cc933a | 2012-07-23 08:22:55 -0400 | [diff] [blame] | 825 | buffer->merge_clusters (new_pos, MIN (end, base + 1)); |
Behdad Esfahbod | abb3239 | 2012-07-22 23:55:19 -0400 | [diff] [blame] | 826 | } else { |
Behdad Esfahbod | e6b01a8 | 2012-07-23 00:11:26 -0400 | [diff] [blame] | 827 | for (unsigned int i = start; i < base; i++) |
Behdad Esfahbod | abb3239 | 2012-07-22 23:55:19 -0400 | [diff] [blame] | 828 | if (info[i].indic_position () == POS_PRE_M) { |
Behdad Esfahbod | 2cc933a | 2012-07-23 08:22:55 -0400 | [diff] [blame] | 829 | buffer->merge_clusters (i, MIN (end, base + 1)); |
Behdad Esfahbod | abb3239 | 2012-07-22 23:55:19 -0400 | [diff] [blame] | 830 | break; |
| 831 | } |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 832 | } |
Behdad Esfahbod | 4ac9e98 | 2012-05-10 12:53:53 +0200 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | |
| 836 | /* o Reorder reph: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 837 | * |
| 838 | * Reph’s original position is always at the beginning of the syllable, |
| 839 | * (i.e. it is not reordered at the character reordering stage). However, |
| 840 | * it will be reordered according to the basic-forms shaping results. |
| 841 | * Possible positions for reph, depending on the script, are; after main, |
| 842 | * before post-base consonant forms, and after post-base consonant forms. |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 843 | */ |
| 844 | |
| 845 | /* If there's anything after the Ra that has the REPH pos, it ought to be halant. |
| 846 | * Which means that the font has failed to ligate the Reph. In which case, we |
| 847 | * shouldn't move. */ |
| 848 | if (start + 1 < end && |
| 849 | info[start].indic_position() == POS_RA_TO_BECOME_REPH && |
| 850 | info[start + 1].indic_position() != POS_RA_TO_BECOME_REPH) |
| 851 | { |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 852 | unsigned int new_reph_pos; |
| 853 | |
| 854 | enum reph_position_t { |
Behdad Esfahbod | f893672 | 2012-05-11 21:10:03 +0200 | [diff] [blame] | 855 | REPH_AFTER_MAIN, |
| 856 | REPH_BEFORE_SUBSCRIPT, |
| 857 | REPH_AFTER_SUBSCRIPT, |
| 858 | REPH_BEFORE_POSTSCRIPT, |
Behdad Esfahbod | 9fc7a11 | 2012-06-04 08:28:19 -0400 | [diff] [blame] | 859 | REPH_AFTER_POSTSCRIPT |
Behdad Esfahbod | f893672 | 2012-05-11 21:10:03 +0200 | [diff] [blame] | 860 | } reph_pos; |
| 861 | |
| 862 | /* XXX Figure out old behavior too */ |
Behdad Esfahbod | 7f852b6 | 2012-05-11 23:10:31 +0200 | [diff] [blame] | 863 | switch ((hb_tag_t) buffer->props.script) |
Behdad Esfahbod | f893672 | 2012-05-11 21:10:03 +0200 | [diff] [blame] | 864 | { |
| 865 | case HB_SCRIPT_MALAYALAM: |
| 866 | case HB_SCRIPT_ORIYA: |
Behdad Esfahbod | 34c2150 | 2012-07-23 23:51:29 -0400 | [diff] [blame] | 867 | case HB_SCRIPT_SINHALA: |
Behdad Esfahbod | f893672 | 2012-05-11 21:10:03 +0200 | [diff] [blame] | 868 | reph_pos = REPH_AFTER_MAIN; |
| 869 | break; |
| 870 | |
| 871 | case HB_SCRIPT_GURMUKHI: |
| 872 | reph_pos = REPH_BEFORE_SUBSCRIPT; |
| 873 | break; |
| 874 | |
| 875 | case HB_SCRIPT_BENGALI: |
| 876 | reph_pos = REPH_AFTER_SUBSCRIPT; |
| 877 | break; |
| 878 | |
| 879 | default: |
| 880 | case HB_SCRIPT_DEVANAGARI: |
| 881 | case HB_SCRIPT_GUJARATI: |
| 882 | reph_pos = REPH_BEFORE_POSTSCRIPT; |
| 883 | break; |
| 884 | |
| 885 | case HB_SCRIPT_KANNADA: |
| 886 | case HB_SCRIPT_TAMIL: |
| 887 | case HB_SCRIPT_TELUGU: |
| 888 | reph_pos = REPH_AFTER_POSTSCRIPT; |
| 889 | break; |
| 890 | } |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 891 | |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 892 | /* 1. If reph should be positioned after post-base consonant forms, |
| 893 | * proceed to step 5. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 894 | */ |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 895 | if (reph_pos == REPH_AFTER_POSTSCRIPT) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 896 | { |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 897 | goto reph_step_5; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | /* 2. If the reph repositioning class is not after post-base: target |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 901 | * position is after the first explicit halant glyph between the |
| 902 | * first post-reph consonant and last main consonant. If ZWJ or ZWNJ |
| 903 | * are following this halant, position is moved after it. If such |
| 904 | * position is found, this is the target position. Otherwise, |
| 905 | * proceed to the next step. |
| 906 | * |
| 907 | * Note: in old-implementation fonts, where classifications were |
| 908 | * fixed in shaping engine, there was no case where reph position |
| 909 | * will be found on this step. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 910 | */ |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 911 | { |
| 912 | new_reph_pos = start + 1; |
Behdad Esfahbod | deb521d | 2012-07-17 11:37:32 -0400 | [diff] [blame] | 913 | while (new_reph_pos < base && !is_halant_or_coeng (info[new_reph_pos])) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 914 | new_reph_pos++; |
| 915 | |
Behdad Esfahbod | deb521d | 2012-07-17 11:37:32 -0400 | [diff] [blame] | 916 | if (new_reph_pos < base && is_halant_or_coeng (info[new_reph_pos])) { |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 917 | /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */ |
| 918 | if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1])) |
| 919 | new_reph_pos++; |
| 920 | goto reph_move; |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | /* 3. If reph should be repositioned after the main consonant: find the |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 925 | * first consonant not ligated with main, or find the first |
| 926 | * consonant that is not a potential pre-base reordering Ra. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 927 | */ |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 928 | if (reph_pos == REPH_AFTER_MAIN) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 929 | { |
Behdad Esfahbod | b504e06 | 2012-07-16 15:21:12 -0400 | [diff] [blame] | 930 | new_reph_pos = base; |
| 931 | /* XXX Skip potential pre-base reordering Ra. */ |
Behdad Esfahbod | 34ae336 | 2012-07-20 16:17:28 -0400 | [diff] [blame] | 932 | 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] | 933 | new_reph_pos++; |
| 934 | if (new_reph_pos < end) |
| 935 | goto reph_move; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | /* 4. If reph should be positioned before post-base consonant, find |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 939 | * first post-base classified consonant not ligated with main. If no |
| 940 | * consonant is found, the target position should be before the |
| 941 | * first matra, syllable modifier sign or vedic sign. |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 942 | */ |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 943 | /* This is our take on what step 4 is trying to say (and failing, BADLY). */ |
| 944 | if (reph_pos == REPH_AFTER_SUBSCRIPT) |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 945 | { |
Behdad Esfahbod | 9d0d319 | 2012-05-11 21:36:32 +0200 | [diff] [blame] | 946 | new_reph_pos = base; |
| 947 | while (new_reph_pos < end && |
Behdad Esfahbod | be8b9f5 | 2012-07-19 12:11:12 -0400 | [diff] [blame] | 948 | !( FLAG (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] | 949 | new_reph_pos++; |
| 950 | if (new_reph_pos < end) |
| 951 | goto reph_move; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | /* 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] | 955 | * immediately before the first post-base matra, syllable modifier |
| 956 | * sign or vedic sign that has a reordering class after the intended |
| 957 | * reph position. For example, if the reordering position for reph |
| 958 | * is post-main, it will skip above-base matras that also have a |
| 959 | * post-main position. |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 960 | */ |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 961 | reph_step_5: |
| 962 | { |
Behdad Esfahbod | d0e68db | 2012-07-20 11:25:41 -0400 | [diff] [blame] | 963 | /* Copied from step 2. */ |
| 964 | new_reph_pos = start + 1; |
| 965 | while (new_reph_pos < base && !is_halant_or_coeng (info[new_reph_pos])) |
| 966 | new_reph_pos++; |
| 967 | |
| 968 | if (new_reph_pos < base && is_halant_or_coeng (info[new_reph_pos])) { |
| 969 | /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */ |
| 970 | if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1])) |
| 971 | new_reph_pos++; |
| 972 | goto reph_move; |
| 973 | } |
Behdad Esfahbod | 8df5636 | 2012-05-10 15:41:04 +0200 | [diff] [blame] | 974 | } |
| 975 | |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 976 | /* 6. Otherwise, reorder reph to the end of the syllable. |
| 977 | */ |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 978 | { |
| 979 | new_reph_pos = end - 1; |
| 980 | while (new_reph_pos > start && info[new_reph_pos].indic_position() == POS_SMVD) |
| 981 | new_reph_pos--; |
| 982 | |
Behdad Esfahbod | 892eb78 | 2012-05-11 16:54:40 +0200 | [diff] [blame] | 983 | /* |
| 984 | * If the Reph is to be ending up after a Matra,Halant sequence, |
| 985 | * position it before that Halant so it can interact with the Matra. |
| 986 | * However, if it's a plain Consonant,Halant we shouldn't do that. |
| 987 | * Uniscribe doesn't do this. |
| 988 | * TEST: U+0930,U+094D,U+0915,U+094B,U+094D |
| 989 | */ |
Behdad Esfahbod | a2b471d | 2012-06-05 15:17:44 -0400 | [diff] [blame] | 990 | if (!indic_options ().uniscribe_bug_compatible && |
Behdad Esfahbod | deb521d | 2012-07-17 11:37:32 -0400 | [diff] [blame] | 991 | unlikely (is_halant_or_coeng (info[new_reph_pos]))) { |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 992 | for (unsigned int i = base + 1; i < new_reph_pos; i++) |
| 993 | if (info[i].indic_category() == OT_M) { |
| 994 | /* Ok, got it. */ |
| 995 | new_reph_pos--; |
| 996 | } |
| 997 | } |
| 998 | goto reph_move; |
| 999 | } |
| 1000 | |
| 1001 | reph_move: |
| 1002 | { |
Behdad Esfahbod | e6b01a8 | 2012-07-23 00:11:26 -0400 | [diff] [blame] | 1003 | /* Yay, one big cluster! Merge before moving. */ |
| 1004 | buffer->merge_clusters (start, end); |
| 1005 | |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1006 | /* Move */ |
| 1007 | hb_glyph_info_t reph = info[start]; |
| 1008 | memmove (&info[start], &info[start + 1], (new_reph_pos - start) * sizeof (info[0])); |
| 1009 | info[new_reph_pos] = reph; |
Behdad Esfahbod | 02b2922 | 2012-05-10 21:44:50 +0200 | [diff] [blame] | 1010 | } |
Behdad Esfahbod | dbb1058 | 2012-05-10 13:45:52 +0200 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | |
| 1014 | /* o Reorder pre-base reordering consonants: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1015 | * |
| 1016 | * If a pre-base reordering consonant is found, reorder it according to |
| 1017 | * the following rules: |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1018 | */ |
| 1019 | |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 1020 | if (pref_mask && base + 1 < end) /* Otherwise there can't be any pre-base reordering Ra. */ |
| 1021 | { |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1022 | for (unsigned int i = base + 1; i < end; i++) |
| 1023 | if ((info[i].mask & pref_mask) != 0) |
Behdad Esfahbod | 7881812 | 2012-07-16 15:49:08 -0400 | [diff] [blame] | 1024 | { |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1025 | /* 1. Only reorder a glyph produced by substitution during application |
| 1026 | * of the <pref> feature. (Note that a font may shape a Ra consonant with |
| 1027 | * the feature generally but block it in certain contexts.) |
| 1028 | */ |
| 1029 | if (i + 1 == end || (info[i + 1].mask & pref_mask) == 0) |
| 1030 | { |
| 1031 | /* |
| 1032 | * 2. Try to find a target position the same way as for pre-base matra. |
| 1033 | * If it is found, reorder pre-base consonant glyph. |
| 1034 | * |
| 1035 | * 3. If position is not found, reorder immediately before main |
| 1036 | * consonant. |
| 1037 | */ |
| 1038 | |
| 1039 | unsigned int new_pos = base; |
Behdad Esfahbod | 0afb84c | 2012-07-24 01:44:47 -0400 | [diff] [blame] | 1040 | while (new_pos > start && |
| 1041 | !(is_one_of (info[new_pos - 1], FLAG(OT_M) | HALANT_OR_COENG_FLAGS))) |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1042 | new_pos--; |
| 1043 | |
Behdad Esfahbod | d90b8e8 | 2012-07-24 02:10:20 -0400 | [diff] [blame] | 1044 | /* In Khmer coeng model, a V,Ra can go *after* matras. If it goes after a |
| 1045 | * split matra, it should be reordered to *before* the left part of such matra. */ |
| 1046 | if (new_pos > start && info[new_pos - 1].indic_category() == OT_M) |
| 1047 | { |
| 1048 | unsigned int old_pos = i; |
| 1049 | for (unsigned int i = base + 1; i < old_pos; i++) |
| 1050 | if (info[i].indic_category() == OT_M) |
| 1051 | { |
| 1052 | new_pos--; |
| 1053 | break; |
| 1054 | } |
| 1055 | } |
| 1056 | |
Behdad Esfahbod | deb521d | 2012-07-17 11:37:32 -0400 | [diff] [blame] | 1057 | if (new_pos > start && is_halant_or_coeng (info[new_pos - 1])) |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1058 | /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ |
| 1059 | if (new_pos < end && is_joiner (info[new_pos])) |
| 1060 | new_pos++; |
| 1061 | |
| 1062 | { |
| 1063 | unsigned int old_pos = i; |
Behdad Esfahbod | e6b01a8 | 2012-07-23 00:11:26 -0400 | [diff] [blame] | 1064 | buffer->merge_clusters (new_pos, old_pos + 1); |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1065 | hb_glyph_info_t tmp = info[old_pos]; |
| 1066 | memmove (&info[new_pos + 1], &info[new_pos], (old_pos - new_pos) * sizeof (info[0])); |
| 1067 | info[new_pos] = tmp; |
Behdad Esfahbod | 8e7b588 | 2012-07-16 17:04:46 -0400 | [diff] [blame] | 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | break; |
Behdad Esfahbod | 7881812 | 2012-07-16 15:49:08 -0400 | [diff] [blame] | 1072 | } |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 1073 | } |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 1074 | |
| 1075 | |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 1076 | /* Apply 'init' to the Left Matra if it's a word start. */ |
Behdad Esfahbod | 6a091df | 2012-05-11 21:42:27 +0200 | [diff] [blame] | 1077 | if (info[start].indic_position () == POS_PRE_M && |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 1078 | (!start || |
Behdad Esfahbod | eace47b | 2012-05-13 15:54:43 +0200 | [diff] [blame] | 1079 | !(FLAG (_hb_glyph_info_get_general_category (&info[start - 1])) & |
Behdad Esfahbod | 2c372b8 | 2012-07-20 13:37:48 -0400 | [diff] [blame] | 1080 | FLAG_RANGE (HB_UNICODE_GENERAL_CATEGORY_FORMAT, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)))) |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 1081 | info[start].mask |= init_mask; |
Behdad Esfahbod | a913b02 | 2012-05-11 20:59:26 +0200 | [diff] [blame] | 1082 | |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 1083 | |
Behdad Esfahbod | 8ed248d | 2012-07-20 11:42:24 -0400 | [diff] [blame] | 1084 | /* |
| 1085 | * Finish off the clusters and go home! |
| 1086 | */ |
Behdad Esfahbod | decf6ff | 2012-07-20 13:51:31 -0400 | [diff] [blame] | 1087 | if (indic_options ().uniscribe_bug_compatible) |
Behdad Esfahbod | ebe2973 | 2012-05-11 16:43:12 +0200 | [diff] [blame] | 1088 | { |
Behdad Esfahbod | 30c3d5e | 2012-07-20 13:56:32 -0400 | [diff] [blame] | 1089 | /* Uniscribe merges the entire cluster. |
Behdad Esfahbod | 21d2803 | 2012-05-10 18:34:34 +0200 | [diff] [blame] | 1090 | * This means, half forms are submerged into the main consonants cluster. |
| 1091 | * This is unnecessary, and makes cursor positioning harder, but that's what |
| 1092 | * Uniscribe does. */ |
Behdad Esfahbod | e6b01a8 | 2012-07-23 00:11:26 -0400 | [diff] [blame] | 1093 | buffer->merge_clusters (start, end); |
Behdad Esfahbod | 21d2803 | 2012-05-10 18:34:34 +0200 | [diff] [blame] | 1094 | } |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1095 | } |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1096 | |
| 1097 | |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1098 | static void |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 1099 | final_reordering (const hb_ot_shape_plan_t *plan, |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 1100 | hb_font_t *font HB_UNUSED, |
Behdad Esfahbod | 3e38c0f | 2012-08-02 09:44:18 -0400 | [diff] [blame] | 1101 | hb_buffer_t *buffer) |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1102 | { |
| 1103 | unsigned int count = buffer->len; |
| 1104 | if (!count) return; |
Behdad Esfahbod | e7be057 | 2011-07-31 15:18:57 -0400 | [diff] [blame] | 1105 | |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 1106 | hb_mask_t init_mask = plan->map.get_1_mask (HB_TAG('i','n','i','t')); |
| 1107 | hb_mask_t pref_mask = plan->map.get_1_mask (HB_TAG('p','r','e','f')); |
Behdad Esfahbod | eed903b | 2012-05-11 20:50:53 +0200 | [diff] [blame] | 1108 | |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1109 | hb_glyph_info_t *info = buffer->info; |
| 1110 | unsigned int last = 0; |
Behdad Esfahbod | cee7187 | 2012-05-11 11:41:39 +0200 | [diff] [blame] | 1111 | unsigned int last_syllable = info[0].syllable(); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1112 | for (unsigned int i = 1; i < count; i++) |
Behdad Esfahbod | cee7187 | 2012-05-11 11:41:39 +0200 | [diff] [blame] | 1113 | if (last_syllable != info[i].syllable()) { |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 1114 | final_reordering_syllable (buffer, init_mask, pref_mask, last, i); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1115 | last = i; |
Behdad Esfahbod | cee7187 | 2012-05-11 11:41:39 +0200 | [diff] [blame] | 1116 | last_syllable = info[last].syllable(); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1117 | } |
Behdad Esfahbod | 46e645e | 2012-07-16 15:30:05 -0400 | [diff] [blame] | 1118 | final_reordering_syllable (buffer, init_mask, pref_mask, last, count); |
Behdad Esfahbod | ef24cc8 | 2012-05-09 17:56:03 +0200 | [diff] [blame] | 1119 | |
Behdad Esfahbod | 743807a | 2011-07-29 16:37:02 -0400 | [diff] [blame] | 1120 | HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category); |
| 1121 | HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position); |
| 1122 | } |
| 1123 | |
| 1124 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 1125 | const hb_ot_complex_shaper_t _hb_ot_complex_shaper_indic = |
| 1126 | { |
| 1127 | "indic", |
| 1128 | collect_features_indic, |
| 1129 | override_features_indic, |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 1130 | data_create_indic, |
| 1131 | data_destroy_indic, |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 1132 | NULL, /* normalization_preference */ |
| 1133 | setup_masks_indic, |
Behdad Esfahbod | 1e7d860 | 2012-07-31 23:41:06 -0400 | [diff] [blame] | 1134 | false, /* zero_width_attached_marks */ |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 1135 | }; |