blob: 15b00b080ad3fdc7ca45ead1f8eb99f5670b8dfd [file] [log] [blame]
Behdad Esfahbodb9ddbd52011-06-02 17:43:12 -04001/*
Behdad Esfahbod27aba592012-05-24 15:00:01 -04002 * Copyright © 2011,2012 Google, Inc.
Behdad Esfahbodb9ddbd52011-06-02 17:43:12 -04003 *
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 Esfahbod3ed46342012-04-19 22:34:06 -040027#include "hb-ot-shape-complex-indic-private.hh"
Behdad Esfahbod49c5ec52012-07-23 20:14:13 -040028#include "hb-ot-layout-private.hh"
Behdad Esfahbod352372a2011-07-30 19:04:02 -040029
Behdad Esfahbod1d002042012-08-02 05:01:11 -040030
Behdad Esfahbod11b0e202012-08-02 14:21:40 -040031/*
32 * Global Indic shaper options.
33 */
Behdad Esfahbod1d002042012-08-02 05:01:11 -040034
Behdad Esfahboda2b471d2012-06-05 15:17:44 -040035struct indic_options_t
Behdad Esfahbodebe29732012-05-11 16:43:12 +020036{
Behdad Esfahboda2b471d2012-06-05 15:17:44 -040037 int initialized : 1;
38 int uniscribe_bug_compatible : 1;
39};
40
41union indic_options_union_t {
42 int i;
43 indic_options_t opts;
44};
45ASSERT_STATIC (sizeof (int) == sizeof (indic_options_union_t));
46
47static indic_options_union_t
48indic_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 Esfahboda02d8642012-08-08 18:04:29 -040060static inline indic_options_t
Behdad Esfahboda2b471d2012-06-05 15:17:44 -040061indic_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 Esfahbodebe29732012-05-11 16:43:12 +020068 }
69
Behdad Esfahboda2b471d2012-06-05 15:17:44 -040070 return options.opts;
71}
72
Behdad Esfahbodebe29732012-05-11 16:43:12 +020073
Behdad Esfahbod11b0e202012-08-02 14:21:40 -040074/*
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
82enum base_position_t {
83 BASE_POS_FIRST,
84 BASE_POS_LAST
85};
86enum 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};
95enum 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};
101struct 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
111static 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 Esfahbod9ccc6382012-07-19 12:32:16 -0400133
Behdad Esfahbodeed903b2012-05-11 20:50:53 +0200134struct feature_list_t {
Behdad Esfahbodc7fe56a2011-06-24 19:05:34 -0400135 hb_tag_t tag;
136 hb_bool_t is_global;
Behdad Esfahbodeed903b2012-05-11 20:50:53 +0200137};
138
139static const feature_list_t
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400140indic_features[] =
Behdad Esfahbodb9ddbd52011-06-02 17:43:12 -0400141{
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400142 /*
143 * Basic features.
144 * These features are applied in order, one at a time, after initial_reordering.
145 */
Behdad Esfahbodc7fe56a2011-06-24 19:05:34 -0400146 {HB_TAG('n','u','k','t'), true},
Behdad Esfahbode0475342012-07-19 20:24:14 -0400147 {HB_TAG('a','k','h','n'), true},
Behdad Esfahbodc7fe56a2011-06-24 19:05:34 -0400148 {HB_TAG('r','p','h','f'), false},
Behdad Esfahbod1ac075b2012-05-09 11:06:47 +0200149 {HB_TAG('r','k','r','f'), true},
Behdad Esfahbodc7fe56a2011-06-24 19:05:34 -0400150 {HB_TAG('p','r','e','f'), false},
Behdad Esfahbodc7fe56a2011-06-24 19:05:34 -0400151 {HB_TAG('h','a','l','f'), false},
Behdad Esfahbod167b6252012-08-05 21:16:26 -0700152 {HB_TAG('b','l','w','f'), false},
Behdad Esfahbod29f106d2012-07-16 12:05:35 -0400153 {HB_TAG('a','b','v','f'), false},
Behdad Esfahbodc7fe56a2011-06-24 19:05:34 -0400154 {HB_TAG('p','s','t','f'), false},
Behdad Esfahbod0201e0a2012-07-17 13:55:10 -0400155 {HB_TAG('c','f','a','r'), false},
Behdad Esfahbod20b68e62012-07-20 10:47:46 -0400156 {HB_TAG('c','j','c','t'), true},
Behdad Esfahbod1d6846d2012-05-13 18:09:29 +0200157 {HB_TAG('v','a','t','u'), true},
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400158 /*
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 Esfahbodc7fe56a2011-06-24 19:05:34 -0400172};
173
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400174/*
175 * Must be in the same order as the indic_features array.
176 */
Behdad Esfahbodc7fe56a2011-06-24 19:05:34 -0400177enum {
178 _NUKT,
Behdad Esfahbode0475342012-07-19 20:24:14 -0400179 _AKHN,
Behdad Esfahbodc7fe56a2011-06-24 19:05:34 -0400180 RPHF,
Behdad Esfahboddf6d45c2012-05-09 11:38:31 +0200181 _RKRF,
Behdad Esfahbodc7fe56a2011-06-24 19:05:34 -0400182 PREF,
Behdad Esfahbodc7fe56a2011-06-24 19:05:34 -0400183 HALF,
Behdad Esfahbod167b6252012-08-05 21:16:26 -0700184 BLWF,
Behdad Esfahbod29f106d2012-07-16 12:05:35 -0400185 ABVF,
Behdad Esfahbodc7fe56a2011-06-24 19:05:34 -0400186 PSTF,
Behdad Esfahbod0201e0a2012-07-17 13:55:10 -0400187 CFAR,
Behdad Esfahbod20b68e62012-07-20 10:47:46 -0400188 _CJCT,
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400189 _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 Esfahbodb9ddbd52011-06-02 17:43:12 -0400203};
204
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400205static void
Behdad Esfahbod8bb5deb2012-08-02 10:07:58 -0400206initial_reordering (const hb_ot_shape_plan_t *plan,
Behdad Esfahbodafbcc242012-08-02 08:36:40 -0400207 hb_font_t *font,
Behdad Esfahbod3e38c0f2012-08-02 09:44:18 -0400208 hb_buffer_t *buffer);
Behdad Esfahbodf6fd3782011-07-08 00:22:40 -0400209static void
Behdad Esfahbod8bb5deb2012-08-02 10:07:58 -0400210final_reordering (const hb_ot_shape_plan_t *plan,
Behdad Esfahbodafbcc242012-08-02 08:36:40 -0400211 hb_font_t *font,
Behdad Esfahbod3e38c0f2012-08-02 09:44:18 -0400212 hb_buffer_t *buffer);
Behdad Esfahbodb9ddbd52011-06-02 17:43:12 -0400213
Behdad Esfahbod693918e2012-07-30 21:08:51 -0400214static void
Behdad Esfahbod16c6a272012-08-02 09:38:28 -0400215collect_features_indic (hb_ot_shape_planner_t *plan)
Behdad Esfahbodb9ddbd52011-06-02 17:43:12 -0400216{
Behdad Esfahbod16c6a272012-08-02 09:38:28 -0400217 hb_ot_map_builder_t *map = &plan->map;
218
Behdad Esfahbodf6fd3782011-07-08 00:22:40 -0400219 map->add_bool_feature (HB_TAG('l','o','c','l'));
Behdad Esfahboda54a5502011-07-20 16:42:10 -0400220 /* 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 Esfahbodf6fd3782011-07-08 00:22:40 -0400222 map->add_bool_feature (HB_TAG('c','c','m','p'));
223
Behdad Esfahbodf6fd3782011-07-08 00:22:40 -0400224
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400225 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 Esfahbod3e38c0f2012-08-02 09:44:18 -0400229 map->add_gsub_pause (NULL);
Behdad Esfahbod412b9182012-05-09 11:07:18 +0200230 }
Behdad Esfahbod3e38c0f2012-08-02 09:44:18 -0400231 map->add_gsub_pause (final_reordering);
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400232 for (; i < INDIC_NUM_FEATURES; i++) {
233 map->add_bool_feature (indic_features[i].tag, indic_features[i].is_global);
234 }
Behdad Esfahbodb9ddbd52011-06-02 17:43:12 -0400235}
236
Behdad Esfahbod693918e2012-07-30 21:08:51 -0400237static void
Behdad Esfahbod16c6a272012-08-02 09:38:28 -0400238override_features_indic (hb_ot_shape_planner_t *plan)
Behdad Esfahbodd96838e2012-07-16 20:26:57 -0400239{
Behdad Esfahbodaf92b4c2012-07-16 20:31:24 -0400240 /* Uniscribe does not apply 'kern'. */
241 if (indic_options ().uniscribe_bug_compatible)
Behdad Esfahbod16c6a272012-08-02 09:38:28 -0400242 plan->map.add_feature (HB_TAG('k','e','r','n'), 0, true);
Behdad Esfahbodd96838e2012-07-16 20:26:57 -0400243}
244
Behdad Esfahbod867361c2011-06-17 18:35:46 -0400245
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400246struct would_substitute_feature_t
Behdad Esfahboda8c6da92012-08-02 10:46:34 -0400247{
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400248 inline void init (const hb_ot_map_t *map, hb_tag_t feature_tag)
Behdad Esfahboda8c6da92012-08-02 10:46:34 -0400249 {
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 Esfahbodb5584ee2012-08-23 16:26:07 -0400257 bool zero_context,
Behdad Esfahboda8c6da92012-08-02 10:46:34 -0400258 hb_face_t *face) const
259 {
260 for (unsigned int i = 0; i < count; i++)
Behdad Esfahbodb5584ee2012-08-23 16:26:07 -0400261 if (hb_ot_layout_would_substitute_lookup_fast (face, lookups[i].index, glyphs, glyphs_count, zero_context))
Behdad Esfahboda8c6da92012-08-02 10:46:34 -0400262 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
271struct indic_shape_plan_t
272{
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400273 ASSERT_POD ();
Behdad Esfahbod914ffaa2012-08-02 11:03:39 -0400274
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 Esfahbod11b0e202012-08-02 14:21:40 -0400280 if (!config->virama || !font->get_glyph (config->virama, 0, &glyph))
Behdad Esfahbod914ffaa2012-08-02 11:03:39 -0400281 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 Esfahbod85fc6c42012-08-02 12:21:44 -0400293
Behdad Esfahbod11b0e202012-08-02 14:21:40 -0400294 const indic_config_t *config;
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400295
296 bool is_old_spec;
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400297 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 Esfahboda8c6da92012-08-02 10:46:34 -0400304};
305
306static void *
307data_create_indic (const hb_ot_shape_plan_t *plan)
308{
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400309 indic_shape_plan_t *indic_plan = (indic_shape_plan_t *) calloc (1, sizeof (indic_shape_plan_t));
310 if (unlikely (!indic_plan))
Behdad Esfahboda8c6da92012-08-02 10:46:34 -0400311 return NULL;
312
Behdad Esfahbod11b0e202012-08-02 14:21:40 -0400313 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 Esfahbod85fc6c42012-08-02 12:21:44 -0400318 }
Behdad Esfahbod11b0e202012-08-02 14:21:40 -0400319
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 Esfahboda8c6da92012-08-02 10:46:34 -0400322
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400323 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 Esfahboda8c6da92012-08-02 10:46:34 -0400331}
332
333static void
334data_destroy_indic (void *data)
335{
336 free (data);
337}
338
339static indic_position_t
340consonant_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 Esfahbodb5584ee2012-08-23 16:26:07 -0400344 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 Esfahboda8c6da92012-08-02 10:46:34 -0400348 return POS_BASE_C;
349}
350
351
Behdad Esfahbod693918e2012-07-30 21:08:51 -0400352static void
Behdad Esfahbod16c6a272012-08-02 09:38:28 -0400353setup_masks_indic (const hb_ot_shape_plan_t *plan HB_UNUSED,
354 hb_buffer_t *buffer,
355 hb_font_t *font HB_UNUSED)
Behdad Esfahbod24eacf12012-08-02 08:42:11 -0400356{
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
368static int
369compare_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
379static void
Behdad Esfahbod8bb5deb2012-08-02 10:07:58 -0400380update_consonant_positions (const hb_ot_shape_plan_t *plan,
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400381 hb_font_t *font,
382 hb_buffer_t *buffer)
Behdad Esfahbod8ef3d532012-08-02 07:53:18 -0400383{
Behdad Esfahboda8c6da92012-08-02 10:46:34 -0400384 const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
Behdad Esfahbod8ef3d532012-08-02 07:53:18 -0400385
Behdad Esfahboda8c6da92012-08-02 10:46:34 -0400386 unsigned int consonant_pos = indic_plan->is_old_spec ? 0 : 1;
Behdad Esfahbod8ef3d532012-08-02 07:53:18 -0400387 hb_codepoint_t glyphs[2];
Behdad Esfahbod914ffaa2012-08-02 11:03:39 -0400388 if (indic_plan->get_virama_glyph (font, &glyphs[1 - consonant_pos]))
Behdad Esfahbod8ef3d532012-08-02 07:53:18 -0400389 {
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 Esfahbod24eacf12012-08-02 08:42:11 -0400394 glyphs[consonant_pos] = buffer->info[i].codepoint;
Behdad Esfahboda8c6da92012-08-02 10:46:34 -0400395 buffer->info[i].indic_position() = consonant_position_from_face (indic_plan, glyphs, 2, face);
Behdad Esfahbod8ef3d532012-08-02 07:53:18 -0400396 }
397 }
398}
399
Behdad Esfahbod867361c2011-06-17 18:35:46 -0400400
Behdad Esfahbod7ea58db2012-05-11 18:58:57 +0200401/* Rules from:
402 * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */
403
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400404static void
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400405initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan, hb_buffer_t *buffer,
Behdad Esfahbodef24cc82012-05-09 17:56:03 +0200406 unsigned int start, unsigned int end)
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400407{
Behdad Esfahbod914ffaa2012-08-02 11:03:39 -0400408 const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
Behdad Esfahbodee58f3b2011-07-30 19:15:53 -0400409 hb_glyph_info_t *info = buffer->info;
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400410
Behdad Esfahbod617f4ac2012-05-13 16:48:03 +0200411
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400412 /* 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 Esfahbod5e720712011-07-31 17:51:50 -0400426 unsigned int base = end;
Behdad Esfahbod76b34092012-05-09 11:43:43 +0200427 bool has_reph = false;
428
Behdad Esfahbod76b34092012-05-09 11:43:43 +0200429 {
Behdad Esfahbod617f4ac2012-05-13 16:48:03 +0200430 /* -> 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 Esfahbod85fc6c42012-08-02 12:21:44 -0400434 if (indic_plan->mask_array[RPHF] &&
Behdad Esfahbod617f4ac2012-05-13 16:48:03 +0200435 start + 3 <= end &&
436 info[start].indic_category() == OT_Ra &&
437 info[start + 1].indic_category() == OT_H &&
Behdad Esfahbod11b0e202012-08-02 14:21:40 -0400438 (/* 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 Esfahbod3285e102012-07-18 17:22:14 -0400441 ))
Behdad Esfahbod617f4ac2012-05-13 16:48:03 +0200442 {
443 limit += 2;
Behdad Esfahbod3285e102012-07-18 17:22:14 -0400444 while (limit < end && is_joiner (info[limit]))
445 limit++;
Behdad Esfahbod617f4ac2012-05-13 16:48:03 +0200446 base = start;
447 has_reph = true;
448 };
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400449
Behdad Esfahbod23b0e9d2012-08-26 14:30:18 -0400450 switch (indic_plan->config->base_pos)
Behdad Esfahbod14dbdd92012-07-18 13:13:03 -0400451 {
Behdad Esfahbod11b0e202012-08-02 14:21:40 -0400452 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 Esfahbod14dbdd92012-07-18 13:13:03 -0400525
526 default:
Behdad Esfahbod11b0e202012-08-02 14:21:40 -0400527 abort ();
Behdad Esfahbod5d326902012-07-17 14:23:28 -0400528 }
Behdad Esfahbod3c2ea942012-05-11 16:23:38 +0200529
Behdad Esfahbod617f4ac2012-05-13 16:48:03 +0200530 /* -> 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 Esfahbod2278eef2012-07-24 00:26:43 -0400532 * 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 Esfahbod617f4ac2012-05-13 16:48:03 +0200536 /* Have no other consonant, so Reph is not formed and Ra becomes base. */
537 has_reph = false;
538 }
Behdad Esfahbod5e4e21f2012-05-13 16:46:08 +0200539 }
Behdad Esfahbod2278eef2012-07-24 00:26:43 -0400540
Behdad Esfahbod34c21502012-07-23 23:51:29 -0400541 if (base < end)
542 info[base].indic_position() = POS_BASE_C;
Behdad Esfahbod3d250792012-05-10 11:37:42 +0200543
544
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400545 /* 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 Esfahbod45d6f292011-07-30 14:44:30 -0400577 /* Reorder characters */
578
Behdad Esfahbod3c2ea942012-05-11 16:23:38 +0200579 for (unsigned int i = start; i < base; i++)
Behdad Esfahbod900cf3d2012-07-20 10:18:23 -0400580 info[i].indic_position() = MIN (POS_PRE_C, (indic_position_t) info[i].indic_position());
Behdad Esfahbod55f70eb2012-07-17 12:50:13 -0400581
Behdad Esfahbod075d6712012-07-18 15:41:53 -0400582 if (base < end)
583 info[base].indic_position() = POS_BASE_C;
Behdad Esfahbod45d6f292011-07-30 14:44:30 -0400584
Behdad Esfahbod55f70eb2012-07-17 12:50:13 -0400585 /* 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 Esfahbodfd06bf52011-07-30 20:14:44 -0400597 /* Handle beginning Ra */
Behdad Esfahbod5e4e21f2012-05-13 16:46:08 +0200598 if (has_reph)
Behdad Esfahboddbb10582012-05-10 13:45:52 +0200599 info[start].indic_position() = POS_RA_TO_BECOME_REPH;
Behdad Esfahbodfd06bf52011-07-30 20:14:44 -0400600
Behdad Esfahbodf5bc2722011-07-30 21:08:10 -0400601 /* For old-style Indic script tags, move the first post-base Halant after
602 * last consonant. */
Behdad Esfahbod914ffaa2012-08-02 11:03:39 -0400603 if (indic_plan->is_old_spec) {
Behdad Esfahbod3c2ea942012-05-11 16:23:38 +0200604 for (unsigned int i = base + 1; i < end; i++)
Behdad Esfahbodf5bc2722011-07-30 21:08:10 -0400605 if (info[i].indic_category() == OT_H) {
606 unsigned int j;
607 for (j = end - 1; j > i; j--)
Behdad Esfahbod190eb312012-05-10 12:17:16 +0200608 if (is_consonant (info[j]))
Behdad Esfahbodf5bc2722011-07-30 21:08:10 -0400609 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 Esfahbod81202bd2012-07-20 15:10:02 -0400620 /* Attach misc marks to previous char to move with them. */
Behdad Esfahbodebe29732012-05-11 16:43:12 +0200621 {
Behdad Esfahbod81202bd2012-07-20 15:10:02 -0400622 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 Esfahbodebe29732012-05-11 16:43:12 +0200636 for (unsigned int j = i; j > start; j--)
Behdad Esfahbod6a091df2012-05-11 21:42:27 +0200637 if (info[j - 1].indic_position() != POS_PRE_M) {
Behdad Esfahbodebe29732012-05-11 16:43:12 +0200638 info[i].indic_position() = info[j - 1].indic_position();
639 break;
640 }
Behdad Esfahbod81202bd2012-07-20 15:10:02 -0400641 }
642 } else if (info[i].indic_position() != POS_SMVD) {
643 last_pos = (indic_position_t) info[i].indic_position();
Behdad Esfahbodebe29732012-05-11 16:43:12 +0200644 }
Behdad Esfahbod81202bd2012-07-20 15:10:02 -0400645 }
Behdad Esfahbodebe29732012-05-11 16:43:12 +0200646 }
Behdad Esfahbod74ccc6a2012-07-17 11:16:19 -0400647 /* 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 Esfahboddeb521d2012-07-17 11:37:32 -0400651 if (is_halant_or_coeng (info[i]))
Behdad Esfahbod74ccc6a2012-07-17 11:16:19 -0400652 last_halant = i;
653 else if (is_consonant (info[i])) {
654 for (unsigned int j = last_halant; j < i; j++)
Behdad Esfahbod81202bd2012-07-20 15:10:02 -0400655 if (info[j].indic_position() != POS_SMVD)
656 info[j].indic_position() = info[i].indic_position();
Behdad Esfahbod74ccc6a2012-07-17 11:16:19 -0400657 }
658 }
Behdad Esfahbod45d6f292011-07-30 14:44:30 -0400659
Behdad Esfahboda391ff52012-05-10 11:31:20 +0200660 {
Behdad Esfahbod7b2a7da2012-07-22 23:58:55 -0400661 /* 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 Esfahboda391ff52012-05-10 11:31:20 +0200665 /* Sit tight, rock 'n roll! */
Behdad Esfahbodd3637ed2012-05-10 10:51:38 +0200666 hb_bubble_sort (info + start, end - start, compare_indic_order);
Behdad Esfahboda391ff52012-05-10 11:31:20 +0200667 /* Find base again */
668 base = end;
Behdad Esfahbod3c2ea942012-05-11 16:23:38 +0200669 for (unsigned int i = start; i < end; i++)
Behdad Esfahboda391ff52012-05-10 11:31:20 +0200670 if (info[i].indic_position() == POS_BASE_C) {
671 base = i;
672 break;
673 }
674 }
Behdad Esfahbod45d6f292011-07-30 14:44:30 -0400675
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400676 /* Setup masks now */
677
Behdad Esfahbod28168392011-07-31 16:00:35 -0400678 {
679 hb_mask_t mask;
680
Behdad Esfahboddbb10582012-05-10 13:45:52 +0200681 /* Reph */
Behdad Esfahbod668c6042012-05-11 15:34:13 +0200682 for (unsigned int i = start; i < end && info[i].indic_position() == POS_RA_TO_BECOME_REPH; i++)
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400683 info[i].mask |= indic_plan->mask_array[RPHF];
Behdad Esfahboddbb10582012-05-10 13:45:52 +0200684
Behdad Esfahbod28168392011-07-31 16:00:35 -0400685 /* Pre-base */
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400686 mask = indic_plan->mask_array[HALF];
Behdad Esfahbod3c2ea942012-05-11 16:23:38 +0200687 for (unsigned int i = start; i < base; i++)
Behdad Esfahbod28168392011-07-31 16:00:35 -0400688 info[i].mask |= mask;
689 /* Base */
Behdad Esfahbod20b68e62012-07-20 10:47:46 -0400690 mask = 0;
Behdad Esfahbod075d6712012-07-18 15:41:53 -0400691 if (base < end)
692 info[base].mask |= mask;
Behdad Esfahbod28168392011-07-31 16:00:35 -0400693 /* Post-base */
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400694 mask = indic_plan->mask_array[BLWF] | indic_plan->mask_array[ABVF] | indic_plan->mask_array[PSTF];
Behdad Esfahbod3c2ea942012-05-11 16:23:38 +0200695 for (unsigned int i = base + 1; i < end; i++)
Behdad Esfahbod28168392011-07-31 16:00:35 -0400696 info[i].mask |= mask;
697 }
Behdad Esfahbod9da04872011-07-31 13:46:44 -0400698
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400699 if (indic_plan->mask_array[PREF] && base + 2 < end)
Behdad Esfahbod17d7de92012-07-16 15:20:15 -0400700 {
Behdad Esfahbod771a8f52012-07-23 20:07:50 -0400701 /* Find a Halant,Ra sequence and mark it for pre-base reordering processing. */
Behdad Esfahbod8e7b5882012-07-16 17:04:46 -0400702 for (unsigned int i = base + 1; i + 1 < end; i++)
Behdad Esfahbod6732d622012-08-23 15:19:45 -0400703 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 Esfahbod8e7b5882012-07-16 17:04:46 -0400705 {
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400706 info[i++].mask |= indic_plan->mask_array[PREF];
707 info[i++].mask |= indic_plan->mask_array[PREF];
Behdad Esfahbod0201e0a2012-07-17 13:55:10 -0400708
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 Esfahbod85fc6c42012-08-02 12:21:44 -0400716 info[i].mask |= indic_plan->mask_array[CFAR];
Behdad Esfahbod0201e0a2012-07-17 13:55:10 -0400717
Behdad Esfahbod8e7b5882012-07-16 17:04:46 -0400718 break;
719 }
Behdad Esfahbod17d7de92012-07-16 15:20:15 -0400720 }
721
Behdad Esfahbod9da04872011-07-31 13:46:44 -0400722 /* Apply ZWJ/ZWNJ effects */
Behdad Esfahbod3c2ea942012-05-11 16:23:38 +0200723 for (unsigned int i = start + 1; i < end; i++)
Behdad Esfahbod9da04872011-07-31 13:46:44 -0400724 if (is_joiner (info[i])) {
725 bool non_joiner = info[i].indic_category() == OT_ZWNJ;
Behdad Esfahbod6b37bc82011-07-31 15:57:00 -0400726 unsigned int j = i;
Behdad Esfahbod9da04872011-07-31 13:46:44 -0400727
728 do {
Behdad Esfahbod9da04872011-07-31 13:46:44 -0400729 j--;
Behdad Esfahbod6b37bc82011-07-31 15:57:00 -0400730
Behdad Esfahbod20b68e62012-07-20 10:47:46 -0400731 /* 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 Esfahbod6b37bc82011-07-31 15:57:00 -0400735 if (non_joiner)
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400736 info[j].mask &= ~indic_plan->mask_array[HALF];
Behdad Esfahbod6b37bc82011-07-31 15:57:00 -0400737
Behdad Esfahbod9da04872011-07-31 13:46:44 -0400738 } while (j > start && !is_consonant (info[j]));
739 }
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400740}
741
742
743static void
Behdad Esfahbod8bb5deb2012-08-02 10:07:58 -0400744initial_reordering_vowel_syllable (const hb_ot_shape_plan_t *plan,
Behdad Esfahbod9f377ed2012-05-13 16:13:44 +0200745 hb_buffer_t *buffer,
Behdad Esfahbodef24cc82012-05-09 17:56:03 +0200746 unsigned int start, unsigned int end)
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400747{
Behdad Esfahbodc5306b62012-05-10 12:07:33 +0200748 /* We made the vowels look like consonants. So let's call the consonant logic! */
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400749 initial_reordering_consonant_syllable (plan, buffer, start, end);
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400750}
751
752static void
Behdad Esfahbod8bb5deb2012-08-02 10:07:58 -0400753initial_reordering_standalone_cluster (const hb_ot_shape_plan_t *plan,
Behdad Esfahbod9f377ed2012-05-13 16:13:44 +0200754 hb_buffer_t *buffer,
Behdad Esfahbodef24cc82012-05-09 17:56:03 +0200755 unsigned int start, unsigned int end)
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400756{
Behdad Esfahbod18c06e12012-05-11 20:02:14 +0200757 /* 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 Esfahboda2b471d2012-06-05 15:17:44 -0400760 if (indic_options ().uniscribe_bug_compatible)
Behdad Esfahbod18c06e12012-05-11 20:02:14 +0200761 {
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 Esfahbod85fc6c42012-08-02 12:21:44 -0400769 initial_reordering_consonant_syllable (plan, buffer, start, end);
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400770}
771
772static void
Behdad Esfahbod327d14e2012-08-31 16:49:34 -0400773initial_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 Esfahbod743807a2011-07-29 16:37:02 -0400776{
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 Esfahbod327d14e2012-08-31 16:49:34 -0400781
782enum syllable_type_t {
783 consonant_syllable,
784 vowel_syllable,
785 standalone_cluster,
786 broken_cluster,
787 non_indic_cluster,
788};
789
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400790#include "hb-ot-shape-complex-indic-machine.hh"
791
792static void
Behdad Esfahbod327d14e2012-08-31 16:49:34 -0400793initial_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
807static void
Behdad Esfahbod8bb5deb2012-08-02 10:07:58 -0400808initial_reordering (const hb_ot_shape_plan_t *plan,
Behdad Esfahbod24eacf12012-08-02 08:42:11 -0400809 hb_font_t *font,
Behdad Esfahbod3e38c0f2012-08-02 09:44:18 -0400810 hb_buffer_t *buffer)
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400811{
Behdad Esfahbod327d14e2012-08-31 16:49:34 -0400812 unsigned int count = buffer->len;
813 if (unlikely (!count)) return;
814
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400815 update_consonant_positions (plan, font, buffer);
816 find_syllables (plan, buffer);
Behdad Esfahbod327d14e2012-08-31 16:49:34 -0400817
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 Esfahbodb9ddbd52011-06-02 17:43:12 -0400828}
829
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400830static void
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400831final_reordering_syllable (const hb_ot_shape_plan_t *plan,
832 hb_buffer_t *buffer,
Behdad Esfahbodef24cc82012-05-09 17:56:03 +0200833 unsigned int start, unsigned int end)
Behdad Esfahbod743807a2011-07-29 16:37:02 -0400834{
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -0400835 const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
Behdad Esfahbod4ac9e982012-05-10 12:53:53 +0200836 hb_glyph_info_t *info = buffer->info;
837
Behdad Esfahbode7be0572011-07-31 15:18:57 -0400838 /* 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 Esfahbod4ac9e982012-05-10 12:53:53 +0200844 */
845
846 /* Find base again */
Behdad Esfahbod5f0eaaa2012-07-20 15:47:24 -0400847 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 Esfahbod4ac9e982012-05-10 12:53:53 +0200854
Behdad Esfahbod4705a702012-05-10 13:09:08 +0200855
Behdad Esfahbod4ac9e982012-05-10 12:53:53 +0200856 /* o Reorder matras:
Behdad Esfahbode7be0572011-07-31 15:18:57 -0400857 *
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 Esfahbod4ac9e982012-05-10 12:53:53 +0200864 */
865
Behdad Esfahbod65c43ac2012-07-24 03:36:47 -0400866 if (start + 1 < end && start < base) /* Otherwise there can't be any pre-base matra characters. */
Behdad Esfahbod9d0d3192012-05-11 21:36:32 +0200867 {
Behdad Esfahbod65c43ac2012-07-24 03:36:47 -0400868 /* If we lost track of base, alas, position before last thingy. */
869 unsigned int new_pos = base == end ? base - 2 : base - 1;
Behdad Esfahbod4ac9e982012-05-10 12:53:53 +0200870
Behdad Esfahbod65c43ac2012-07-24 03:36:47 -0400871 /* 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 Esfahbod9d0d3192012-05-11 21:36:32 +0200897 /* Now go see if there's actually any matras... */
Behdad Esfahbod921ce5b2012-07-16 15:26:56 -0400898 for (unsigned int i = new_pos; i > start; i--)
Behdad Esfahbod6a091df2012-05-11 21:42:27 +0200899 if (info[i - 1].indic_position () == POS_PRE_M)
Behdad Esfahbod9d0d3192012-05-11 21:36:32 +0200900 {
Behdad Esfahbod1a1dbe92012-07-16 15:40:33 -0400901 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 Esfahbod921ce5b2012-07-16 15:26:56 -0400905 new_pos--;
Behdad Esfahbod9d0d3192012-05-11 21:36:32 +0200906 }
Behdad Esfahbod2cc933a2012-07-23 08:22:55 -0400907 buffer->merge_clusters (new_pos, MIN (end, base + 1));
Behdad Esfahbodabb32392012-07-22 23:55:19 -0400908 } else {
Behdad Esfahbode6b01a82012-07-23 00:11:26 -0400909 for (unsigned int i = start; i < base; i++)
Behdad Esfahbodabb32392012-07-22 23:55:19 -0400910 if (info[i].indic_position () == POS_PRE_M) {
Behdad Esfahbod2cc933a2012-07-23 08:22:55 -0400911 buffer->merge_clusters (i, MIN (end, base + 1));
Behdad Esfahbodabb32392012-07-22 23:55:19 -0400912 break;
913 }
Behdad Esfahbod9d0d3192012-05-11 21:36:32 +0200914 }
Behdad Esfahbod4ac9e982012-05-10 12:53:53 +0200915 }
916
917
918 /* o Reorder reph:
Behdad Esfahbode7be0572011-07-31 15:18:57 -0400919 *
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 Esfahboddbb10582012-05-10 13:45:52 +0200925 */
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 Esfahbod11b0e202012-08-02 14:21:40 -0400934 unsigned int new_reph_pos;
935 reph_position_t reph_pos = indic_plan->config->reph_pos;
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200936
Behdad Esfahbod11b0e202012-08-02 14:21:40 -0400937 /* XXX Figure out old behavior too */
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200938
Behdad Esfahboddbb10582012-05-10 13:45:52 +0200939 /* 1. If reph should be positioned after post-base consonant forms,
940 * proceed to step 5.
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200941 */
Behdad Esfahbod11b0e202012-08-02 14:21:40 -0400942 if (reph_pos == REPH_POS_AFTER_POST)
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200943 {
Behdad Esfahbod9d0d3192012-05-11 21:36:32 +0200944 goto reph_step_5;
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200945 }
946
947 /* 2. If the reph repositioning class is not after post-base: target
Behdad Esfahboddbb10582012-05-10 13:45:52 +0200948 * 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 Esfahbod02b29222012-05-10 21:44:50 +0200957 */
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200958 {
959 new_reph_pos = start + 1;
Behdad Esfahboddeb521d2012-07-17 11:37:32 -0400960 while (new_reph_pos < base && !is_halant_or_coeng (info[new_reph_pos]))
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200961 new_reph_pos++;
962
Behdad Esfahboddeb521d2012-07-17 11:37:32 -0400963 if (new_reph_pos < base && is_halant_or_coeng (info[new_reph_pos])) {
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200964 /* ->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 Esfahboddbb10582012-05-10 13:45:52 +0200972 * first consonant not ligated with main, or find the first
973 * consonant that is not a potential pre-base reordering Ra.
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200974 */
Behdad Esfahbod11b0e202012-08-02 14:21:40 -0400975 if (reph_pos == REPH_POS_AFTER_MAIN)
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200976 {
Behdad Esfahbodb504e062012-07-16 15:21:12 -0400977 new_reph_pos = base;
978 /* XXX Skip potential pre-base reordering Ra. */
Behdad Esfahbod34ae3362012-07-20 16:17:28 -0400979 while (new_reph_pos + 1 < end && info[new_reph_pos + 1].indic_position() <= POS_AFTER_MAIN)
Behdad Esfahbodb504e062012-07-16 15:21:12 -0400980 new_reph_pos++;
981 if (new_reph_pos < end)
982 goto reph_move;
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200983 }
984
985 /* 4. If reph should be positioned before post-base consonant, find
Behdad Esfahboddbb10582012-05-10 13:45:52 +0200986 * 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 Esfahbod02b29222012-05-10 21:44:50 +0200989 */
Behdad Esfahbod9d0d3192012-05-11 21:36:32 +0200990 /* This is our take on what step 4 is trying to say (and failing, BADLY). */
Behdad Esfahbod11b0e202012-08-02 14:21:40 -0400991 if (reph_pos == REPH_POS_AFTER_SUB)
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200992 {
Behdad Esfahbod9d0d3192012-05-11 21:36:32 +0200993 new_reph_pos = base;
994 while (new_reph_pos < end &&
Behdad Esfahbodbe8b9f52012-07-19 12:11:12 -0400995 !( FLAG (info[new_reph_pos + 1].indic_position()) & (FLAG (POS_POST_C) | FLAG (POS_AFTER_POST) | FLAG (POS_SMVD))))
Behdad Esfahbod9d0d3192012-05-11 21:36:32 +0200996 new_reph_pos++;
997 if (new_reph_pos < end)
998 goto reph_move;
Behdad Esfahbod02b29222012-05-10 21:44:50 +0200999 }
1000
1001 /* 5. If no consonant is found in steps 3 or 4, move reph to a position
Behdad Esfahboddbb10582012-05-10 13:45:52 +02001002 * 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 Esfahboddbb10582012-05-10 13:45:52 +02001007 */
Behdad Esfahbod02b29222012-05-10 21:44:50 +02001008 reph_step_5:
1009 {
Behdad Esfahbodd0e68db2012-07-20 11:25:41 -04001010 /* 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 Esfahbod8df56362012-05-10 15:41:04 +02001021 }
1022
Behdad Esfahbod02b29222012-05-10 21:44:50 +02001023 /* 6. Otherwise, reorder reph to the end of the syllable.
1024 */
Behdad Esfahbod02b29222012-05-10 21:44:50 +02001025 {
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 Esfahbod892eb782012-05-11 16:54:40 +02001030 /*
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 Esfahboda2b471d2012-06-05 15:17:44 -04001037 if (!indic_options ().uniscribe_bug_compatible &&
Behdad Esfahboddeb521d2012-07-17 11:37:32 -04001038 unlikely (is_halant_or_coeng (info[new_reph_pos]))) {
Behdad Esfahbod02b29222012-05-10 21:44:50 +02001039 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 Esfahbode6b01a82012-07-23 00:11:26 -04001050 /* Yay, one big cluster! Merge before moving. */
1051 buffer->merge_clusters (start, end);
1052
Behdad Esfahbod02b29222012-05-10 21:44:50 +02001053 /* 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 Esfahbod02b29222012-05-10 21:44:50 +02001057 }
Behdad Esfahboddbb10582012-05-10 13:45:52 +02001058 }
1059
1060
1061 /* o Reorder pre-base reordering consonants:
Behdad Esfahbode7be0572011-07-31 15:18:57 -04001062 *
1063 * If a pre-base reordering consonant is found, reorder it according to
1064 * the following rules:
Behdad Esfahbode7be0572011-07-31 15:18:57 -04001065 */
1066
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -04001067 if (indic_plan->mask_array[PREF] && base + 1 < end) /* Otherwise there can't be any pre-base reordering Ra. */
Behdad Esfahbod46e645e2012-07-16 15:30:05 -04001068 {
Behdad Esfahbod8e7b5882012-07-16 17:04:46 -04001069 for (unsigned int i = base + 1; i < end; i++)
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -04001070 if ((info[i].mask & indic_plan->mask_array[PREF]) != 0)
Behdad Esfahbod78818122012-07-16 15:49:08 -04001071 {
Behdad Esfahbod8e7b5882012-07-16 17:04:46 -04001072 /* 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 Esfahbod85fc6c42012-08-02 12:21:44 -04001076 if (i + 1 == end || (info[i + 1].mask & indic_plan->mask_array[PREF]) == 0)
Behdad Esfahbod8e7b5882012-07-16 17:04:46 -04001077 {
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 Esfahbod0afb84c2012-07-24 01:44:47 -04001087 while (new_pos > start &&
1088 !(is_one_of (info[new_pos - 1], FLAG(OT_M) | HALANT_OR_COENG_FLAGS)))
Behdad Esfahbod8e7b5882012-07-16 17:04:46 -04001089 new_pos--;
1090
Behdad Esfahbodd90b8e82012-07-24 02:10:20 -04001091 /* 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 Esfahboddeb521d2012-07-17 11:37:32 -04001104 if (new_pos > start && is_halant_or_coeng (info[new_pos - 1]))
Behdad Esfahbod8e7b5882012-07-16 17:04:46 -04001105 /* -> 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 Esfahbode6b01a82012-07-23 00:11:26 -04001111 buffer->merge_clusters (new_pos, old_pos + 1);
Behdad Esfahbod8e7b5882012-07-16 17:04:46 -04001112 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 Esfahbod8e7b5882012-07-16 17:04:46 -04001115 }
1116 }
1117
1118 break;
Behdad Esfahbod78818122012-07-16 15:49:08 -04001119 }
Behdad Esfahbod46e645e2012-07-16 15:30:05 -04001120 }
Behdad Esfahbodeed903b2012-05-11 20:50:53 +02001121
1122
Behdad Esfahboda913b022012-05-11 20:59:26 +02001123 /* Apply 'init' to the Left Matra if it's a word start. */
Behdad Esfahbod6a091df2012-05-11 21:42:27 +02001124 if (info[start].indic_position () == POS_PRE_M &&
Behdad Esfahboda913b022012-05-11 20:59:26 +02001125 (!start ||
Behdad Esfahbodeace47b2012-05-13 15:54:43 +02001126 !(FLAG (_hb_glyph_info_get_general_category (&info[start - 1])) &
Behdad Esfahbod2c372b82012-07-20 13:37:48 -04001127 FLAG_RANGE (HB_UNICODE_GENERAL_CATEGORY_FORMAT, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK))))
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -04001128 info[start].mask |= indic_plan->mask_array[INIT];
Behdad Esfahboda913b022012-05-11 20:59:26 +02001129
Behdad Esfahbodeed903b2012-05-11 20:50:53 +02001130
Behdad Esfahbod8ed248d2012-07-20 11:42:24 -04001131 /*
1132 * Finish off the clusters and go home!
1133 */
Behdad Esfahboddecf6ff2012-07-20 13:51:31 -04001134 if (indic_options ().uniscribe_bug_compatible)
Behdad Esfahbodebe29732012-05-11 16:43:12 +02001135 {
Behdad Esfahbod30c3d5e2012-07-20 13:56:32 -04001136 /* Uniscribe merges the entire cluster.
Behdad Esfahbod21d28032012-05-10 18:34:34 +02001137 * 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 Esfahbode6b01a82012-07-23 00:11:26 -04001140 buffer->merge_clusters (start, end);
Behdad Esfahbod21d28032012-05-10 18:34:34 +02001141 }
Behdad Esfahbodef24cc82012-05-09 17:56:03 +02001142}
Behdad Esfahbode7be0572011-07-31 15:18:57 -04001143
1144
Behdad Esfahbodef24cc82012-05-09 17:56:03 +02001145static void
Behdad Esfahbod8bb5deb2012-08-02 10:07:58 -04001146final_reordering (const hb_ot_shape_plan_t *plan,
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -04001147 hb_font_t *font,
Behdad Esfahbod3e38c0f2012-08-02 09:44:18 -04001148 hb_buffer_t *buffer)
Behdad Esfahbodef24cc82012-05-09 17:56:03 +02001149{
1150 unsigned int count = buffer->len;
Behdad Esfahbod327d14e2012-08-31 16:49:34 -04001151 if (unlikely (!count)) return;
Behdad Esfahbode7be0572011-07-31 15:18:57 -04001152
Behdad Esfahbodef24cc82012-05-09 17:56:03 +02001153 hb_glyph_info_t *info = buffer->info;
1154 unsigned int last = 0;
Behdad Esfahbodcee71872012-05-11 11:41:39 +02001155 unsigned int last_syllable = info[0].syllable();
Behdad Esfahbodef24cc82012-05-09 17:56:03 +02001156 for (unsigned int i = 1; i < count; i++)
Behdad Esfahbodcee71872012-05-11 11:41:39 +02001157 if (last_syllable != info[i].syllable()) {
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -04001158 final_reordering_syllable (plan, buffer, last, i);
Behdad Esfahbodef24cc82012-05-09 17:56:03 +02001159 last = i;
Behdad Esfahbodcee71872012-05-11 11:41:39 +02001160 last_syllable = info[last].syllable();
Behdad Esfahbodef24cc82012-05-09 17:56:03 +02001161 }
Behdad Esfahbod85fc6c42012-08-02 12:21:44 -04001162 final_reordering_syllable (plan, buffer, last, count);
Behdad Esfahbodef24cc82012-05-09 17:56:03 +02001163
Behdad Esfahbod80cd9232012-08-23 12:06:14 -04001164 /* Zero syllables now... */
1165 for (unsigned int i = 0; i < count; i++)
1166 info[i].syllable() = 0;
1167
Behdad Esfahbod743807a2011-07-29 16:37:02 -04001168 HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category);
1169 HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position);
1170}
1171
1172
Behdad Esfahbod693918e2012-07-30 21:08:51 -04001173const hb_ot_complex_shaper_t _hb_ot_complex_shaper_indic =
1174{
1175 "indic",
1176 collect_features_indic,
1177 override_features_indic,
Behdad Esfahboda8c6da92012-08-02 10:46:34 -04001178 data_create_indic,
1179 data_destroy_indic,
Behdad Esfahbod9f9f04c2012-08-11 18:34:13 -04001180 NULL, /* preprocess_text */
Behdad Esfahbod693918e2012-07-30 21:08:51 -04001181 NULL, /* normalization_preference */
1182 setup_masks_indic,
Behdad Esfahbod1e7d8602012-07-31 23:41:06 -04001183 false, /* zero_width_attached_marks */
Behdad Esfahbod693918e2012-07-30 21:08:51 -04001184};