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