Coverage Report

Created: 2025-11-09 06:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/harfbuzz/src/hb-ot-shaper-indic.cc
Line
Count
Source
1
/*
2
 * Copyright © 2011,2012  Google, Inc.
3
 *
4
 *  This is part of HarfBuzz, a text shaping library.
5
 *
6
 * Permission is hereby granted, without written agreement and without
7
 * license or royalty fees, to use, copy, modify, and distribute this
8
 * software and its documentation for any purpose, provided that the
9
 * above copyright notice and the following two paragraphs appear in
10
 * all copies of this software.
11
 *
12
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16
 * DAMAGE.
17
 *
18
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23
 *
24
 * Google Author(s): Behdad Esfahbod
25
 */
26
27
#include "hb.hh"
28
29
#ifndef HB_NO_OT_SHAPE
30
31
#include "hb-ot-shaper-indic.hh"
32
#include "hb-ot-shaper-indic-machine.hh"
33
#include "hb-ot-shaper-vowel-constraints.hh"
34
#include "hb-ot-layout.hh"
35
36
37
/*
38
 * Indic shaper.
39
 */
40
41
42
static inline void
43
set_indic_properties (hb_glyph_info_t &info)
44
47.6k
{
45
47.6k
  hb_codepoint_t u = info.codepoint;
46
47.6k
  unsigned int type = hb_indic_get_categories (u);
47
48
47.6k
  info.indic_category() = (indic_category_t) (type & 0xFFu);
49
47.6k
  info.indic_position() = (indic_position_t) (type >> 8);
50
47.6k
}
51
52
53
static inline bool
54
is_one_of (const hb_glyph_info_t &info, unsigned int flags)
55
3.34M
{
56
  /* If it ligated, all bets are off. */
57
3.34M
  if (_hb_glyph_info_ligated (&info)) return false;
58
3.15M
  return !!(FLAG_UNSAFE (info.indic_category()) & flags);
59
3.34M
}
60
61
/* Note:
62
 *
63
 * We treat Vowels and placeholders as if they were consonants.  This is safe because Vowels
64
 * cannot happen in a consonant syllable.  The plus side however is, we can call the
65
 * consonant syllable logic from the vowel syllable function and get it all right!
66
 *
67
 * Keep in sync with consonant_categories in the generator. */
68
2.35M
#define CONSONANT_FLAGS_INDIC (FLAG (I_Cat(C)) | FLAG (I_Cat(CS)) | FLAG (I_Cat(Ra)) | FLAG (I_Cat(CM)) | FLAG (I_Cat(V)) | FLAG (I_Cat(PLACEHOLDER)) | FLAG (I_Cat(DOTTEDCIRCLE)))
69
70
static inline bool
71
is_consonant (const hb_glyph_info_t &info)
72
2.35M
{
73
2.35M
  return is_one_of (info, CONSONANT_FLAGS_INDIC);
74
2.35M
}
75
76
1.62M
#define JOINER_FLAGS (FLAG (I_Cat(ZWJ)) | FLAG (I_Cat(ZWNJ)))
77
78
static inline bool
79
is_joiner (const hb_glyph_info_t &info)
80
704k
{
81
704k
  return is_one_of (info, JOINER_FLAGS);
82
704k
}
83
84
static inline bool
85
is_halant (const hb_glyph_info_t &info)
86
216k
{
87
216k
  return is_one_of (info, FLAG (I_Cat(H)));
88
216k
}
89
90
struct hb_indic_would_substitute_feature_t
91
{
92
  void init (const hb_ot_map_t *map, hb_tag_t feature_tag, bool zero_context_)
93
14.5k
  {
94
14.5k
    zero_context = zero_context_;
95
14.5k
    lookups = map->get_stage_lookups (0/*GSUB*/,
96
14.5k
              map->get_feature_stage (0/*GSUB*/, feature_tag));
97
14.5k
  }
98
99
  bool would_substitute (const hb_codepoint_t *glyphs,
100
       unsigned int          glyphs_count,
101
       hb_face_t            *face) const
102
470k
  {
103
470k
    for (const auto &lookup : lookups)
104
1.21M
      if (hb_ot_layout_lookup_would_substitute (face, lookup.index, glyphs, glyphs_count, zero_context))
105
30.8k
  return true;
106
439k
    return false;
107
470k
  }
108
109
  private:
110
  hb_array_t<const hb_ot_map_t::lookup_map_t> lookups;
111
  bool zero_context;
112
};
113
114
115
/*
116
 * Indic configurations.  Note that we do not want to keep every single script-specific
117
 * behavior in these tables necessarily.  This should mainly be used for per-script
118
 * properties that are cheaper keeping here, than in the code.  Ie. if, say, one and
119
 * only one script has an exception, that one script can be if'ed directly in the code,
120
 * instead of adding a new flag in these structs.
121
 */
122
123
enum reph_position_t {
124
  REPH_POS_AFTER_MAIN  = POS_AFTER_MAIN,
125
  REPH_POS_BEFORE_SUB  = POS_BEFORE_SUB,
126
  REPH_POS_AFTER_SUB   = POS_AFTER_SUB,
127
  REPH_POS_BEFORE_POST = POS_BEFORE_POST,
128
  REPH_POS_AFTER_POST  = POS_AFTER_POST
129
};
130
enum reph_mode_t {
131
  REPH_MODE_IMPLICIT,  /* Reph formed out of initial Ra,H sequence. */
132
  REPH_MODE_EXPLICIT,  /* Reph formed out of initial Ra,H,ZWJ sequence. */
133
  REPH_MODE_LOG_REPHA  /* Encoded Repha character, needs reordering. */
134
};
135
enum blwf_mode_t {
136
  BLWF_MODE_PRE_AND_POST, /* Below-forms feature applied to pre-base and post-base. */
137
  BLWF_MODE_POST_ONLY     /* Below-forms feature applied to post-base only. */
138
};
139
struct indic_config_t
140
{
141
  hb_script_t     script;
142
  bool            has_old_spec;
143
  hb_codepoint_t  virama;
144
  reph_position_t reph_pos;
145
  reph_mode_t     reph_mode;
146
  blwf_mode_t     blwf_mode;
147
};
148
149
static const indic_config_t indic_configs[] =
150
{
151
  /* Default.  Should be first. */
152
  {HB_SCRIPT_INVALID, false,      0,REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
153
  {HB_SCRIPT_DEVANAGARI,true, 0x094Du,REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
154
  {HB_SCRIPT_BENGALI, true, 0x09CDu,REPH_POS_AFTER_SUB,  REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
155
  {HB_SCRIPT_GURMUKHI,  true, 0x0A4Du,REPH_POS_BEFORE_SUB, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
156
  {HB_SCRIPT_GUJARATI,  true, 0x0ACDu,REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
157
  {HB_SCRIPT_ORIYA, true, 0x0B4Du,REPH_POS_AFTER_MAIN, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
158
  {HB_SCRIPT_TAMIL, true, 0x0BCDu,REPH_POS_AFTER_POST, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
159
  {HB_SCRIPT_TELUGU,  true, 0x0C4Du,REPH_POS_AFTER_POST, REPH_MODE_EXPLICIT, BLWF_MODE_POST_ONLY},
160
  {HB_SCRIPT_KANNADA, true, 0x0CCDu,REPH_POS_AFTER_POST, REPH_MODE_IMPLICIT, BLWF_MODE_POST_ONLY},
161
  {HB_SCRIPT_MALAYALAM, true, 0x0D4Du,REPH_POS_AFTER_MAIN, REPH_MODE_LOG_REPHA,BLWF_MODE_PRE_AND_POST},
162
};
163
164
165
static const hb_ot_map_feature_t
166
indic_features[] =
167
{
168
  /*
169
   * Basic features.
170
   * These features are applied in order, one at a time, after initial_reordering,
171
   * constrained to the syllable.
172
   */
173
  {HB_TAG('n','u','k','t'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE},
174
  {HB_TAG('a','k','h','n'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE},
175
  {HB_TAG('r','p','h','f'),        F_MANUAL_JOINERS | F_PER_SYLLABLE},
176
  {HB_TAG('r','k','r','f'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE},
177
  {HB_TAG('p','r','e','f'),        F_MANUAL_JOINERS | F_PER_SYLLABLE},
178
  {HB_TAG('b','l','w','f'),        F_MANUAL_JOINERS | F_PER_SYLLABLE},
179
  {HB_TAG('a','b','v','f'),        F_MANUAL_JOINERS | F_PER_SYLLABLE},
180
  {HB_TAG('h','a','l','f'),        F_MANUAL_JOINERS | F_PER_SYLLABLE},
181
  {HB_TAG('p','s','t','f'),        F_MANUAL_JOINERS | F_PER_SYLLABLE},
182
  {HB_TAG('v','a','t','u'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE},
183
  {HB_TAG('c','j','c','t'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE},
184
  /*
185
   * Other features.
186
   * These features are applied all at once, after final_reordering, constrained
187
   * to the syllable.
188
   * Default Bengali font in Windows for example has intermixed
189
   * lookups for init,pres,abvs,blws features.
190
   */
191
  {HB_TAG('i','n','i','t'),        F_MANUAL_JOINERS | F_PER_SYLLABLE},
192
  {HB_TAG('p','r','e','s'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE},
193
  {HB_TAG('a','b','v','s'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE},
194
  {HB_TAG('b','l','w','s'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE},
195
  {HB_TAG('p','s','t','s'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE},
196
  {HB_TAG('h','a','l','n'), F_GLOBAL_MANUAL_JOINERS | F_PER_SYLLABLE},
197
};
198
199
/*
200
 * Must be in the same order as the indic_features array.
201
 */
202
enum {
203
  _INDIC_NUKT,
204
  _INDIC_AKHN,
205
  INDIC_RPHF,
206
  _INDIC_RKRF,
207
  INDIC_PREF,
208
  INDIC_BLWF,
209
  INDIC_ABVF,
210
  INDIC_HALF,
211
  INDIC_PSTF,
212
  _INDIC_VATU,
213
  _INDIC_CJCT,
214
215
  INDIC_INIT,
216
  _INDIC_PRES,
217
  _INDIC_ABVS,
218
  _INDIC_BLWS,
219
  _INDIC_PSTS,
220
  _INDIC_HALN,
221
222
  INDIC_NUM_FEATURES,
223
  INDIC_BASIC_FEATURES = INDIC_INIT, /* Don't forget to update this! */
224
};
225
226
static bool
227
setup_syllables_indic (const hb_ot_shape_plan_t *plan,
228
           hb_font_t *font,
229
           hb_buffer_t *buffer);
230
static bool
231
initial_reordering_indic (const hb_ot_shape_plan_t *plan,
232
        hb_font_t *font,
233
        hb_buffer_t *buffer);
234
static bool
235
final_reordering_indic (const hb_ot_shape_plan_t *plan,
236
      hb_font_t *font,
237
      hb_buffer_t *buffer);
238
239
static void
240
collect_features_indic (hb_ot_shape_planner_t *plan)
241
2.91k
{
242
2.91k
  hb_ot_map_builder_t *map = &plan->map;
243
244
  /* Do this before any lookups have been applied. */
245
2.91k
  map->add_gsub_pause (setup_syllables_indic);
246
247
2.91k
  map->enable_feature (HB_TAG('l','o','c','l'), F_PER_SYLLABLE);
248
  /* The Indic specs do not require ccmp, but we apply it here since if
249
   * there is a use of it, it's typically at the beginning. */
250
2.91k
  map->enable_feature (HB_TAG('c','c','m','p'), F_PER_SYLLABLE);
251
252
253
2.91k
  unsigned int i = 0;
254
2.91k
  map->add_gsub_pause (initial_reordering_indic);
255
256
34.9k
  for (; i < INDIC_BASIC_FEATURES; i++) {
257
32.0k
    map->add_feature (indic_features[i]);
258
32.0k
    map->add_gsub_pause (nullptr);
259
32.0k
  }
260
261
2.91k
  map->add_gsub_pause (final_reordering_indic);
262
263
20.4k
  for (; i < INDIC_NUM_FEATURES; i++)
264
17.4k
    map->add_feature (indic_features[i]);
265
2.91k
}
266
267
static void
268
override_features_indic (hb_ot_shape_planner_t *plan)
269
2.91k
{
270
2.91k
  plan->map.disable_feature (HB_TAG('l','i','g','a'));
271
2.91k
  plan->map.add_gsub_pause (hb_syllabic_clear_var); // Don't need syllables anymore, use stop to free buffer var
272
2.91k
}
273
274
275
struct indic_shape_plan_t
276
{
277
  bool load_virama_glyph (hb_font_t *font, hb_codepoint_t *pglyph) const
278
2.89k
  {
279
2.89k
    hb_codepoint_t glyph = virama_glyph;
280
2.89k
    if (unlikely (glyph == (hb_codepoint_t) -1))
281
2.89k
    {
282
2.89k
      if (!config->virama || !font->get_nominal_glyph (config->virama, &glyph))
283
2.66k
  glyph = 0;
284
      /* Technically speaking, the spec says we should apply 'locl' to virama too.
285
       * Maybe one day... */
286
287
      /* Our get_nominal_glyph() function needs a font, so we can't get the virama glyph
288
       * during shape planning...  Instead, overwrite it here. */
289
2.89k
      virama_glyph = (int) glyph;
290
2.89k
    }
291
292
2.89k
    *pglyph = glyph;
293
2.89k
    return glyph != 0;
294
2.89k
  }
295
296
  const indic_config_t *config;
297
298
  bool is_old_spec;
299
#ifndef HB_NO_UNISCRIBE_BUG_COMPATIBLE
300
  bool uniscribe_bug_compatible;
301
#else
302
  static constexpr bool uniscribe_bug_compatible = false;
303
#endif
304
  mutable hb_atomic_t<hb_codepoint_t> virama_glyph;
305
306
  hb_indic_would_substitute_feature_t rphf;
307
  hb_indic_would_substitute_feature_t pref;
308
  hb_indic_would_substitute_feature_t blwf;
309
  hb_indic_would_substitute_feature_t pstf;
310
  hb_indic_would_substitute_feature_t vatu;
311
312
  hb_mask_t mask_array[INDIC_NUM_FEATURES];
313
};
314
315
static void *
316
data_create_indic (const hb_ot_shape_plan_t *plan)
317
2.91k
{
318
2.91k
  indic_shape_plan_t *indic_plan = (indic_shape_plan_t *) hb_calloc (1, sizeof (indic_shape_plan_t));
319
2.91k
  if (unlikely (!indic_plan))
320
7
    return nullptr;
321
322
2.90k
  indic_plan->config = &indic_configs[0];
323
15.9k
  for (unsigned int i = 1; i < ARRAY_LENGTH (indic_configs); i++)
324
15.9k
    if (plan->props.script == indic_configs[i].script) {
325
2.90k
      indic_plan->config = &indic_configs[i];
326
2.90k
      break;
327
2.90k
    }
328
329
2.90k
  indic_plan->is_old_spec = indic_plan->config->has_old_spec && ((plan->map.chosen_script[0] & 0x000000FFu) != '2');
330
2.90k
#ifndef HB_NO_UNISCRIBE_BUG_COMPATIBLE
331
2.90k
  indic_plan->uniscribe_bug_compatible = hb_options ().uniscribe_bug_compatible;
332
2.90k
#endif
333
2.90k
  indic_plan->virama_glyph = -1;
334
335
  /* Use zero-context would_substitute() matching for new-spec of the main
336
   * Indic scripts, and scripts with one spec only, but not for old-specs.
337
   * The new-spec for all dual-spec scripts says zero-context matching happens.
338
   *
339
   * However, testing with Malayalam shows that old and new spec both allow
340
   * context.  Testing with Bengali new-spec however shows that it doesn't.
341
   * So, the heuristic here is the way it is.  It should *only* be changed,
342
   * as we discover more cases of what Windows does.  DON'T TOUCH OTHERWISE.
343
   */
344
2.90k
  bool zero_context = !indic_plan->is_old_spec && plan->props.script != HB_SCRIPT_MALAYALAM;
345
2.90k
  indic_plan->rphf.init (&plan->map, HB_TAG('r','p','h','f'), zero_context);
346
2.90k
  indic_plan->pref.init (&plan->map, HB_TAG('p','r','e','f'), zero_context);
347
2.90k
  indic_plan->blwf.init (&plan->map, HB_TAG('b','l','w','f'), zero_context);
348
2.90k
  indic_plan->pstf.init (&plan->map, HB_TAG('p','s','t','f'), zero_context);
349
2.90k
  indic_plan->vatu.init (&plan->map, HB_TAG('v','a','t','u'), zero_context);
350
351
52.3k
  for (unsigned int i = 0; i < ARRAY_LENGTH (indic_plan->mask_array); i++)
352
49.4k
    indic_plan->mask_array[i] = (indic_features[i].flags & F_GLOBAL) ?
353
29.0k
         0 : plan->map.get_1_mask (indic_features[i].tag);
354
355
2.90k
  return indic_plan;
356
2.91k
}
357
358
static void
359
data_destroy_indic (void *data)
360
2.90k
{
361
2.90k
  hb_free (data);
362
2.90k
}
363
364
static indic_position_t
365
consonant_position_from_face (const indic_shape_plan_t *indic_plan,
366
            const hb_codepoint_t consonant,
367
            const hb_codepoint_t virama,
368
            hb_face_t *face)
369
45.8k
{
370
  /* For old-spec, the order of glyphs is Consonant,Virama,
371
   * whereas for new-spec, it's Virama,Consonant.  However,
372
   * some broken fonts (like Free Sans) simply copied lookups
373
   * from old-spec to new-spec without modification.
374
   * And oddly enough, Uniscribe seems to respect those lookups.
375
   * Eg. in the sequence U+0924,U+094D,U+0930, Uniscribe finds
376
   * base at 0.  The font however, only has lookups matching
377
   * 930,94D in 'blwf', not the expected 94D,930 (with new-spec
378
   * table).  As such, we simply match both sequences.  Seems
379
   * to work.
380
   *
381
   * Vatu is done as well, for:
382
   * https://github.com/harfbuzz/harfbuzz/issues/1587
383
   */
384
45.8k
  hb_codepoint_t glyphs[3] = {virama, consonant, virama};
385
45.8k
  if (indic_plan->blwf.would_substitute (glyphs  , 2, face) ||
386
45.8k
      indic_plan->blwf.would_substitute (glyphs+1, 2, face) ||
387
45.7k
      indic_plan->vatu.would_substitute (glyphs  , 2, face) ||
388
45.7k
      indic_plan->vatu.would_substitute (glyphs+1, 2, face))
389
20
    return POS_BELOW_C;
390
45.7k
  if (indic_plan->pstf.would_substitute (glyphs  , 2, face) ||
391
34.7k
      indic_plan->pstf.would_substitute (glyphs+1, 2, face))
392
11.0k
    return POS_POST_C;
393
34.7k
  if (indic_plan->pref.would_substitute (glyphs  , 2, face) ||
394
16.5k
      indic_plan->pref.would_substitute (glyphs+1, 2, face))
395
18.2k
    return POS_POST_C;
396
16.4k
  return POS_BASE_C;
397
34.7k
}
398
399
static void
400
setup_masks_indic (const hb_ot_shape_plan_t *plan HB_UNUSED,
401
       hb_buffer_t              *buffer,
402
       hb_font_t                *font HB_UNUSED)
403
2.90k
{
404
2.90k
  HB_BUFFER_ALLOCATE_VAR (buffer, indic_category);
405
2.90k
  HB_BUFFER_ALLOCATE_VAR (buffer, indic_position);
406
407
  /* We cannot setup masks here.  We save information about characters
408
   * and setup masks later on in a pause-callback. */
409
410
2.90k
  unsigned int count = buffer->len;
411
2.90k
  hb_glyph_info_t *info = buffer->info;
412
50.5k
  for (unsigned int i = 0; i < count; i++)
413
47.6k
    set_indic_properties (info[i]);
414
2.90k
}
415
416
static bool
417
setup_syllables_indic (const hb_ot_shape_plan_t *plan HB_UNUSED,
418
           hb_font_t *font HB_UNUSED,
419
           hb_buffer_t *buffer)
420
2.89k
{
421
2.89k
  HB_BUFFER_ALLOCATE_VAR (buffer, syllable);
422
2.89k
  find_syllables_indic (buffer);
423
2.89k
  foreach_syllable (buffer, start, end)
424
2.03M
    buffer->unsafe_to_break (start, end);
425
2.89k
  return false;
426
2.89k
}
427
428
static int
429
compare_indic_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb)
430
4.43M
{
431
4.43M
  int a = pa->indic_position();
432
4.43M
  int b = pb->indic_position();
433
434
4.43M
  return (int) a - (int) b;
435
4.43M
}
436
437
438
439
static void
440
update_consonant_positions_indic (const hb_ot_shape_plan_t *plan,
441
          hb_font_t         *font,
442
          hb_buffer_t       *buffer)
443
2.89k
{
444
2.89k
  const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
445
446
2.89k
  hb_codepoint_t virama;
447
2.89k
  if (indic_plan->load_virama_glyph (font, &virama))
448
228
  {
449
228
    hb_face_t *face = font->face;
450
228
    unsigned int count = buffer->len;
451
228
    hb_glyph_info_t *info = buffer->info;
452
639k
    for (unsigned int i = 0; i < count; i++)
453
638k
      if (info[i].indic_position() == POS_BASE_C)
454
45.8k
      {
455
45.8k
  hb_codepoint_t consonant = info[i].codepoint;
456
45.8k
  info[i].indic_position() = consonant_position_from_face (indic_plan, consonant, virama, face);
457
45.8k
      }
458
228
  }
459
2.89k
}
460
461
462
/* Rules from:
463
 * https://docs.microsqoft.com/en-us/typography/script-development/devanagari */
464
465
static void
466
initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan,
467
               hb_face_t *face,
468
               hb_buffer_t *buffer,
469
               unsigned int start, unsigned int end)
470
248k
{
471
248k
  const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
472
248k
  hb_glyph_info_t *info = buffer->info;
473
474
  /* https://github.com/harfbuzz/harfbuzz/issues/435#issuecomment-335560167
475
   * // For compatibility with legacy usage in Kannada,
476
   * // Ra+h+ZWJ must behave like Ra+ZWJ+h...
477
   */
478
248k
  if (buffer->props.script == HB_SCRIPT_KANNADA &&
479
20.8k
      start + 3 <= end &&
480
668
      is_one_of (info[start  ], FLAG (I_Cat(Ra))) &&
481
72
      is_one_of (info[start+1], FLAG (I_Cat(H))) &&
482
52
      is_one_of (info[start+2], FLAG (I_Cat(ZWJ))))
483
7
  {
484
7
    buffer->merge_clusters (start+1, start+3);
485
7
    hb_swap (info[start+1], info[start+2]);
486
7
  }
487
488
  /* 1. Find base consonant:
489
   *
490
   * The shaping engine finds the base consonant of the syllable, using the
491
   * following algorithm: starting from the end of the syllable, move backwards
492
   * until a consonant is found that does not have a below-base or post-base
493
   * form (post-base forms have to follow below-base forms), or that is not a
494
   * pre-base-reordering Ra, or arrive at the first consonant. The consonant
495
   * stopped at will be the base.
496
   *
497
   *   o If the syllable starts with Ra + Halant (in a script that has Reph)
498
   *     and has more than one consonant, Ra is excluded from candidates for
499
   *     base consonants.
500
   */
501
502
248k
  unsigned int base = end;
503
248k
  bool has_reph = false;
504
505
248k
  {
506
    /* -> If the syllable starts with Ra + Halant (in a script that has Reph)
507
     *    and has more than one consonant, Ra is excluded from candidates for
508
     *    base consonants. */
509
248k
    unsigned int limit = start;
510
248k
    if (indic_plan->mask_array[INDIC_RPHF] &&
511
2.74k
  start + 3 <= end &&
512
762
  (
513
762
   (indic_plan->config->reph_mode == REPH_MODE_IMPLICIT && !is_joiner (info[start + 2])) ||
514
382
   (indic_plan->config->reph_mode == REPH_MODE_EXPLICIT && info[start + 2].indic_category() == I_Cat(ZWJ))
515
762
  ))
516
698
    {
517
      /* See if it matches the 'rphf' feature. */
518
698
      hb_codepoint_t glyphs[3] = {info[start].codepoint,
519
698
          info[start + 1].codepoint,
520
698
          indic_plan->config->reph_mode == REPH_MODE_EXPLICIT ?
521
380
            info[start + 2].codepoint : 0};
522
698
      if (indic_plan->rphf.would_substitute (glyphs, 2, face) ||
523
547
    (indic_plan->config->reph_mode == REPH_MODE_EXPLICIT &&
524
268
     indic_plan->rphf.would_substitute (glyphs, 3, face)))
525
200
      {
526
200
  limit += 2;
527
544
  while (limit < end && is_joiner (info[limit]))
528
344
    limit++;
529
200
  base = start;
530
200
  has_reph = true;
531
200
      }
532
248k
    } else if (indic_plan->config->reph_mode == REPH_MODE_LOG_REPHA && info[start].indic_category() == I_Cat(Repha))
533
24.1k
    {
534
24.1k
  limit += 1;
535
24.7k
  while (limit < end && is_joiner (info[limit]))
536
624
    limit++;
537
24.1k
  base = start;
538
24.1k
  has_reph = true;
539
24.1k
    }
540
541
248k
    {
542
      /* -> starting from the end of the syllable, move backwards */
543
248k
      unsigned int i = end;
544
248k
      bool seen_below = false;
545
843k
      do {
546
843k
  i--;
547
  /* -> until a consonant is found */
548
843k
  if (is_consonant (info[i]))
549
209k
  {
550
    /* -> that does not have a below-base or post-base form
551
     * (post-base forms have to follow below-base forms), */
552
209k
    if (info[i].indic_position() != POS_BELOW_C &&
553
209k
        (info[i].indic_position() != POS_POST_C || seen_below))
554
180k
    {
555
180k
      base = i;
556
180k
      break;
557
180k
    }
558
29.3k
    if (info[i].indic_position() == POS_BELOW_C)
559
20
      seen_below = true;
560
561
    /* -> or that is not a pre-base-reordering Ra,
562
     *
563
     * IMPLEMENTATION NOTES:
564
     *
565
     * Our pre-base-reordering Ra's are marked POS_POST_C, so will be skipped
566
     * by the logic above already.
567
     */
568
569
    /* -> or arrive at the first consonant. The consonant stopped at will
570
     * be the base. */
571
29.3k
    base = i;
572
29.3k
  }
573
633k
  else
574
633k
  {
575
    /* A ZWJ after a Halant stops the base search, and requests an explicit
576
     * half form.
577
     * A ZWJ before a Halant, requests a subjoined form instead, and hence
578
     * search continues.  This is particularly important for Bengali
579
     * sequence Ra,H,Ya that should form Ya-Phalaa by subjoining Ya. */
580
633k
    if (start < i &&
581
567k
        info[i].indic_category() == I_Cat(ZWJ) &&
582
4.63k
        info[i - 1].indic_category() == I_Cat(H))
583
410
      break;
584
633k
  }
585
843k
      } while (i > limit);
586
248k
    }
587
588
    /* -> If the syllable starts with Ra + Halant (in a script that has Reph)
589
     *    and has more than one consonant, Ra is excluded from candidates for
590
     *    base consonants.
591
     *
592
     *  Only do this for unforced Reph. (ie. not for Ra,H,ZWJ. */
593
248k
    if (has_reph && base == start && limit - base <= 2) {
594
      /* Have no other consonant, so Reph is not formed and Ra becomes base. */
595
18.9k
      has_reph = false;
596
18.9k
    }
597
248k
  }
598
599
600
  /* 2. Decompose and reorder Matras:
601
   *
602
   * Each matra and any syllable modifier sign in the syllable are moved to the
603
   * appropriate position relative to the consonant(s) in the syllable. The
604
   * shaping engine decomposes two- or three-part matras into their constituent
605
   * parts before any repositioning. Matra characters are classified by which
606
   * consonant in a conjunct they have affinity for and are reordered to the
607
   * following positions:
608
   *
609
   *   o Before first half form in the syllable
610
   *   o After subjoined consonants
611
   *   o After post-form consonant
612
   *   o After main consonant (for above marks)
613
   *
614
   * IMPLEMENTATION NOTES:
615
   *
616
   * The normalize() routine has already decomposed matras for us, so we don't
617
   * need to worry about that.
618
   */
619
620
621
  /* 3.  Reorder marks to canonical order:
622
   *
623
   * Adjacent nukta and halant or nukta and vedic sign are always repositioned
624
   * if necessary, so that the nukta is first.
625
   *
626
   * IMPLEMENTATION NOTES:
627
   *
628
   * We don't need to do this: the normalize() routine already did this for us.
629
   */
630
631
632
  /* Reorder characters */
633
634
552k
  for (unsigned int i = start; i < base; i++)
635
303k
    info[i].indic_position() = hb_min (POS_PRE_C, (indic_position_t) info[i].indic_position());
636
637
248k
  if (base < end)
638
199k
    info[base].indic_position() = POS_BASE_C;
639
640
  /* Handle beginning Ra */
641
248k
  if (has_reph)
642
5.45k
    info[start].indic_position() = POS_RA_TO_BECOME_REPH;
643
644
  /* For old-style Indic script tags, move the first post-base Halant after
645
   * last consonant.
646
   *
647
   * Reports suggest that in some scripts Uniscribe does this only if there
648
   * is *not* a Halant after last consonant already.  We know that is the
649
   * case for Kannada, while it reorders unconditionally in other scripts,
650
   * eg. Malayalam, Bengali, and Devanagari.  We don't currently know about
651
   * other scripts, so we block Kannada.
652
   *
653
   * Kannada test case:
654
   * U+0C9A,U+0CCD,U+0C9A,U+0CCD
655
   * With some versions of Lohit Kannada.
656
   * https://bugs.freedesktop.org/show_bug.cgi?id=59118
657
   *
658
   * Malayalam test case:
659
   * U+0D38,U+0D4D,U+0D31,U+0D4D,U+0D31,U+0D4D
660
   * With lohit-ttf-20121122/Lohit-Malayalam.ttf
661
   *
662
   * Bengali test case:
663
   * U+0998,U+09CD,U+09AF,U+09CD
664
   * With Windows XP vrinda.ttf
665
   * https://github.com/harfbuzz/harfbuzz/issues/1073
666
   *
667
   * Devanagari test case:
668
   * U+091F,U+094D,U+0930,U+094D
669
   * With chandas.ttf
670
   * https://github.com/harfbuzz/harfbuzz/issues/1071
671
   */
672
248k
  if (indic_plan->is_old_spec)
673
229k
  {
674
229k
    bool disallow_double_halants = buffer->props.script == HB_SCRIPT_KANNADA;
675
350k
    for (unsigned int i = base + 1; i < end; i++)
676
121k
      if (info[i].indic_category() == I_Cat(H))
677
373
      {
678
373
  unsigned int j;
679
5.26k
  for (j = end - 1; j > i; j--)
680
4.93k
    if (is_consonant (info[j]) ||
681
4.91k
        (disallow_double_halants && info[j].indic_category() == I_Cat(H)))
682
41
      break;
683
373
  if (info[j].indic_category() != I_Cat(H) && j > i) {
684
    /* Move Halant to after last consonant. */
685
13
    hb_glyph_info_t t = info[i];
686
13
    memmove (&info[i], &info[i + 1], (j - i) * sizeof (info[0]));
687
13
    info[j] = t;
688
13
  }
689
373
  break;
690
373
      }
691
229k
  }
692
693
  /* Attach misc marks to previous char to move with them. */
694
248k
  {
695
248k
    indic_position_t last_pos = POS_START;
696
1.16M
    for (unsigned int i = start; i < end; i++)
697
916k
    {
698
916k
      if ((FLAG_UNSAFE (info[i].indic_category()) & (JOINER_FLAGS | FLAG (I_Cat(N)) | FLAG (I_Cat(RS)) | FLAG (I_Cat(CM)) | FLAG (I_Cat(H)))))
699
69.1k
      {
700
69.1k
  info[i].indic_position() = last_pos;
701
69.1k
  if (unlikely (info[i].indic_category() == I_Cat(H) &&
702
69.1k
          info[i].indic_position() == POS_PRE_M))
703
5.81k
  {
704
    /*
705
     * Uniscribe doesn't move the Halant with Left Matra.
706
     * TEST: U+092B,U+093F,U+094D
707
     * We follow.
708
     */
709
54.5M
    for (unsigned int j = i; j > start; j--)
710
54.5M
      if (info[j - 1].indic_position() != POS_PRE_M) {
711
875
        info[i].indic_position() = info[j - 1].indic_position();
712
875
        break;
713
875
      }
714
5.81k
  }
715
846k
      } else if (info[i].indic_position() != POS_SMVD) {
716
832k
  if (info[i].indic_category() == I_Cat(MPst) &&
717
276
      i > start && info[i - 1].indic_category() == I_Cat(SM))
718
11
    info[i - 1].indic_position() = info[i].indic_position();
719
832k
  last_pos = (indic_position_t) info[i].indic_position();
720
832k
      }
721
916k
    }
722
248k
  }
723
  /* For post-base consonants let them own anything before them
724
   * since the last consonant or matra. */
725
248k
  {
726
248k
    unsigned int last = base;
727
661k
    for (unsigned int i = base + 1; i < end; i++)
728
412k
      if (is_consonant (info[i]))
729
30.1k
      {
730
31.7k
  for (unsigned int j = last + 1; j < i; j++)
731
1.68k
    if (info[j].indic_position() < POS_SMVD)
732
30.1k
      info[j].indic_position() = info[i].indic_position();
733
30.1k
  last = i;
734
382k
      } else if (FLAG_UNSAFE (info[i].indic_category()) & (FLAG (I_Cat(M)) | FLAG (I_Cat(MPst))))
735
111k
  last = i;
736
248k
  }
737
738
739
248k
  {
740
    /* Use syllable() for sort accounting temporarily. */
741
248k
    unsigned int syllable = info[start].syllable();
742
1.16M
    for (unsigned int i = start; i < end; i++)
743
916k
      info[i].syllable() = i - start;
744
745
    /* Sit tight, rock 'n roll! */
746
248k
    hb_stable_sort (info + start, end - start, compare_indic_order);
747
748
    /* Find base again; also flip left-matra sequence. */
749
248k
    unsigned first_left_matra = end;
750
248k
    unsigned last_left_matra = end;
751
248k
    base = end;
752
566k
    for (unsigned int i = start; i < end; i++)
753
517k
    {
754
517k
      if (info[i].indic_position() == POS_BASE_C)
755
199k
      {
756
199k
  base = i;
757
199k
  break;
758
199k
      }
759
317k
      else if (info[i].indic_position() == POS_PRE_M)
760
36.7k
      {
761
36.7k
        if (first_left_matra == end)
762
459
    first_left_matra = i;
763
36.7k
  last_left_matra = i;
764
36.7k
      }
765
517k
    }
766
    /* https://github.com/harfbuzz/harfbuzz/issues/3863 */
767
248k
    if (first_left_matra < last_left_matra)
768
211
    {
769
      /* No need to merge clusters, handled later. */
770
211
      buffer->reverse_range (first_left_matra, last_left_matra + 1);
771
      /* Reverse back nuktas, etc. */
772
211
      unsigned i = first_left_matra;
773
36.7k
      for (unsigned j = i; j <= last_left_matra; j++)
774
36.5k
  if (FLAG_UNSAFE (info[j].indic_category()) & (FLAG (I_Cat(M)) | FLAG (I_Cat(MPst))))
775
25.7k
  {
776
25.7k
    buffer->reverse_range (i, j + 1);
777
25.7k
    i = j + 1;
778
25.7k
  }
779
211
    }
780
781
    /* Things are out-of-control for post base positions, they may shuffle
782
     * around like crazy.  In old-spec mode, we move halants around, so in
783
     * that case merge all clusters after base.  Otherwise, check the sort
784
     * order and merge as needed.
785
     * For pre-base stuff, we handle cluster issues in final reordering.
786
     *
787
     * We could use buffer->sort() for this, if there was no special
788
     * reordering of pre-base stuff happening later...
789
     * We don't want to merge_clusters all of that, which buffer->sort()
790
     * would.  Here's a concrete example:
791
     *
792
     * Assume there's a pre-base consonant and explicit Halant before base,
793
     * followed by a prebase-reordering (left) Matra:
794
     *
795
     *   C,H,ZWNJ,B,M
796
     *
797
     * At this point in reordering we would have:
798
     *
799
     *   M,C,H,ZWNJ,B
800
     *
801
     * whereas in final reordering we will bring the Matra closer to Base:
802
     *
803
     *   C,H,ZWNJ,M,B
804
     *
805
     * That's why we don't want to merge-clusters anything before the Base
806
     * at this point.  But if something moved from after Base to before it,
807
     * we should merge clusters from base to them.  In final-reordering, we
808
     * only move things around before base, and merge-clusters up to base.
809
     * These two merge-clusters from the two sides of base will interlock
810
     * to merge things correctly.  See:
811
     * https://github.com/harfbuzz/harfbuzz/issues/2272
812
     */
813
248k
    if (indic_plan->is_old_spec || end - start > 127)
814
230k
      buffer->merge_clusters (base, end);
815
18.7k
    else
816
18.7k
    {
817
      /* Note!  syllable() is a one-byte field. */
818
72.6k
      for (unsigned int i = base; i < end; i++)
819
53.9k
  if (info[i].syllable() != 255)
820
53.8k
  {
821
53.8k
    unsigned int min = i;
822
53.8k
    unsigned int max = i;
823
53.8k
    unsigned int j = start + info[i].syllable();
824
54.2k
    while (j != i)
825
337
    {
826
337
      min = hb_min (min, j);
827
337
      max = hb_max (max, j);
828
337
      unsigned int next = start + info[j].syllable();
829
337
      info[j].syllable() = 255; /* So we don't process j later again. */
830
337
      j = next;
831
337
    }
832
53.8k
    buffer->merge_clusters (hb_max (base, min), max + 1);
833
53.8k
  }
834
18.7k
    }
835
836
    /* Put syllable back in. */
837
1.16M
    for (unsigned int i = start; i < end; i++)
838
916k
      info[i].syllable() = syllable;
839
248k
  }
840
841
  /* Setup masks now */
842
843
248k
  {
844
248k
    hb_mask_t mask;
845
846
    /* Reph */
847
256k
    for (unsigned int i = start; i < end && info[i].indic_position() == POS_RA_TO_BECOME_REPH; i++)
848
7.45k
      info[i].mask |= indic_plan->mask_array[INDIC_RPHF];
849
850
    /* Pre-base */
851
248k
    mask = indic_plan->mask_array[INDIC_HALF];
852
248k
    if (!indic_plan->is_old_spec &&
853
19.7k
  indic_plan->config->blwf_mode == BLWF_MODE_PRE_AND_POST)
854
19.6k
      mask |= indic_plan->mask_array[INDIC_BLWF];
855
566k
    for (unsigned int i = start; i < base; i++)
856
317k
      info[i].mask  |= mask;
857
    /* Base */
858
248k
    mask = 0;
859
248k
    if (base < end)
860
199k
      info[base].mask |= mask;
861
    /* Post-base */
862
248k
    mask = indic_plan->mask_array[INDIC_BLWF] |
863
248k
     indic_plan->mask_array[INDIC_ABVF] |
864
248k
     indic_plan->mask_array[INDIC_PSTF];
865
647k
    for (unsigned int i = base + 1; i < end; i++)
866
398k
      info[i].mask  |= mask;
867
248k
  }
868
869
248k
  if (indic_plan->is_old_spec &&
870
229k
      buffer->props.script == HB_SCRIPT_DEVANAGARI)
871
56.4k
  {
872
    /* Old-spec eye-lash Ra needs special handling.  From the
873
     * spec:
874
     *
875
     * "The feature 'below-base form' is applied to consonants
876
     * having below-base forms and following the base consonant.
877
     * The exception is vattu, which may appear below half forms
878
     * as well as below the base glyph. The feature 'below-base
879
     * form' will be applied to all such occurrences of Ra as well."
880
     *
881
     * Test case: U+0924,U+094D,U+0930,U+094d,U+0915
882
     * with Sanskrit 2003 font.
883
     *
884
     * However, note that Ra,Halant,ZWJ is the correct way to
885
     * request eyelash form of Ra, so we wouldbn't inhibit it
886
     * in that sequence.
887
     *
888
     * Test case: U+0924,U+094D,U+0930,U+094d,U+200D,U+0915
889
     */
890
90.9k
    for (unsigned int i = start; i + 1 < base; i++)
891
34.4k
      if (info[i  ].indic_category() == I_Cat(Ra) &&
892
320
    info[i+1].indic_category() == I_Cat(H)  &&
893
40
    (i + 2 == base ||
894
29
     info[i+2].indic_category() != I_Cat(ZWJ)))
895
21
      {
896
21
  info[i  ].mask |= indic_plan->mask_array[INDIC_BLWF];
897
21
  info[i+1].mask |= indic_plan->mask_array[INDIC_BLWF];
898
21
      }
899
56.4k
  }
900
901
248k
  unsigned int pref_len = 2;
902
248k
  if (indic_plan->mask_array[INDIC_PREF] && base + pref_len < end)
903
4.38k
  {
904
    /* Find a Halant,Ra sequence and mark it for pre-base-reordering processing. */
905
157k
    for (unsigned int i = base + 1; i + pref_len - 1 < end; i++) {
906
154k
      hb_codepoint_t glyphs[2];
907
462k
      for (unsigned int j = 0; j < pref_len; j++)
908
308k
  glyphs[j] = info[i + j].codepoint;
909
154k
      if (indic_plan->pref.would_substitute (glyphs, pref_len, face))
910
1.31k
      {
911
3.95k
  for (unsigned int j = 0; j < pref_len; j++)
912
2.63k
    info[i++].mask |= indic_plan->mask_array[INDIC_PREF];
913
1.31k
  break;
914
1.31k
      }
915
154k
    }
916
4.38k
  }
917
918
  /* Apply ZWJ/ZWNJ effects */
919
916k
  for (unsigned int i = start + 1; i < end; i++)
920
667k
    if (is_joiner (info[i])) {
921
6.54k
      bool non_joiner = info[i].indic_category() == I_Cat(ZWNJ);
922
6.54k
      unsigned int j = i;
923
924
1.09M
      do {
925
1.09M
  j--;
926
927
  /* ZWJ/ZWNJ should disable CJCT.  They do that by simply
928
   * being there, since we don't skip them for the CJCT
929
   * feature (ie. F_MANUAL_ZWJ) */
930
931
  /* A ZWNJ disables HALF. */
932
1.09M
  if (non_joiner)
933
340k
    info[j].mask &= ~indic_plan->mask_array[INDIC_HALF];
934
935
1.09M
      } while (j > start && !is_consonant (info[j]));
936
6.54k
    }
937
248k
}
938
939
static void
940
initial_reordering_standalone_cluster (const hb_ot_shape_plan_t *plan,
941
               hb_face_t *face,
942
               hb_buffer_t *buffer,
943
               unsigned int start, unsigned int end)
944
107k
{
945
  /* We treat placeholder/dotted-circle as if they are consonants, so we
946
   * should just chain.  Only if not in compatibility mode that is... */
947
948
107k
  const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
949
107k
  if (indic_plan->uniscribe_bug_compatible)
950
0
  {
951
    /* For dotted-circle, this is what Uniscribe does:
952
     * If dotted-circle is the last glyph, it just does nothing.
953
     * Ie. It doesn't form Reph. */
954
0
    if (buffer->info[end - 1].indic_category() == I_Cat(DOTTEDCIRCLE))
955
0
      return;
956
0
  }
957
958
107k
  initial_reordering_consonant_syllable (plan, face, buffer, start, end);
959
107k
}
960
961
static void
962
initial_reordering_syllable_indic (const hb_ot_shape_plan_t *plan,
963
           hb_face_t *face,
964
           hb_buffer_t *buffer,
965
           unsigned int start, unsigned int end)
966
2.02M
{
967
2.02M
  indic_syllable_type_t syllable_type = (indic_syllable_type_t) (buffer->info[start].syllable() & 0x0F);
968
2.02M
  switch (syllable_type)
969
2.02M
  {
970
104k
    case indic_vowel_syllable: /* We made the vowels look like consonants.  So let's call the consonant logic! */
971
141k
    case indic_consonant_syllable:
972
141k
     initial_reordering_consonant_syllable (plan, face, buffer, start, end);
973
141k
     break;
974
975
73.9k
    case indic_broken_cluster: /* We already inserted dotted-circles, so just call the standalone_cluster. */
976
107k
    case indic_standalone_cluster:
977
107k
     initial_reordering_standalone_cluster (plan, face, buffer, start, end);
978
107k
     break;
979
980
21.9k
    case indic_symbol_cluster:
981
1.77M
    case indic_non_indic_cluster:
982
1.77M
      break;
983
2.02M
  }
984
2.02M
}
985
986
static bool
987
initial_reordering_indic (const hb_ot_shape_plan_t *plan,
988
        hb_font_t *font,
989
        hb_buffer_t *buffer)
990
2.89k
{
991
2.89k
  bool ret = false;
992
2.89k
  if (!buffer->message (font, "start reordering indic initial"))
993
0
    return ret;
994
995
2.89k
  update_consonant_positions_indic (plan, font, buffer);
996
2.89k
  if (hb_syllabic_insert_dotted_circles (font, buffer,
997
2.89k
           indic_broken_cluster,
998
2.89k
           I_Cat(DOTTEDCIRCLE),
999
2.89k
           I_Cat(Repha),
1000
2.89k
           POS_END))
1001
138
    ret = true;
1002
1003
2.89k
  foreach_syllable (buffer, start, end)
1004
2.02M
    initial_reordering_syllable_indic (plan, font->face, buffer, start, end);
1005
1006
2.89k
  (void) buffer->message (font, "end reordering indic initial");
1007
1008
2.89k
  return ret;
1009
2.89k
}
1010
1011
static void
1012
final_reordering_syllable_indic (const hb_ot_shape_plan_t *plan,
1013
         hb_buffer_t *buffer,
1014
         unsigned int start, unsigned int end)
1015
2.02M
{
1016
2.02M
  const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
1017
2.02M
  hb_glyph_info_t *info = buffer->info;
1018
1019
1020
  /* This function relies heavily on halant glyphs.  Lots of ligation
1021
   * and possibly multiple substitutions happened prior to this
1022
   * phase, and that might have messed up our properties.  Recover
1023
   * from a particular case of that where we're fairly sure that a
1024
   * class of I_Cat(H) is desired but has been lost. */
1025
  /* We don't call load_virama_glyph(), since we know it's already
1026
   * loaded. */
1027
2.02M
  hb_codepoint_t virama_glyph = indic_plan->virama_glyph;
1028
2.02M
  if (virama_glyph)
1029
73.4k
  {
1030
1.51M
    for (unsigned int i = start; i < end; i++)
1031
1.43M
      if (info[i].codepoint == virama_glyph &&
1032
42.7k
    _hb_glyph_info_ligated (&info[i]) &&
1033
27.3k
    _hb_glyph_info_multiplied (&info[i]))
1034
27.3k
      {
1035
  /* This will make sure that this glyph passes is_halant() test. */
1036
27.3k
  info[i].indic_category() = I_Cat(H);
1037
27.3k
  _hb_glyph_info_clear_ligated_and_multiplied (&info[i]);
1038
27.3k
      }
1039
73.4k
  }
1040
1041
1042
  /* 4. Final reordering:
1043
   *
1044
   * After the localized forms and basic shaping forms GSUB features have been
1045
   * applied (see below), the shaping engine performs some final glyph
1046
   * reordering before applying all the remaining font features to the entire
1047
   * syllable.
1048
   */
1049
1050
2.02M
  bool try_pref = !!indic_plan->mask_array[INDIC_PREF];
1051
1052
  /* Find base again */
1053
2.02M
  unsigned int base;
1054
2.57M
  for (base = start; base < end; base++)
1055
2.52M
    if (info[base].indic_position() >= POS_BASE_C)
1056
1.97M
    {
1057
1.97M
      if (try_pref && base + 1 < end)
1058
11.1k
      {
1059
1.09M
  for (unsigned int i = base + 1; i < end; i++)
1060
1.08M
    if ((info[i].mask & indic_plan->mask_array[INDIC_PREF]) != 0)
1061
1.30k
    {
1062
1.30k
      if (!(_hb_glyph_info_substituted (&info[i]) &&
1063
1.29k
      _hb_glyph_info_ligated_and_didnt_multiply (&info[i])))
1064
1.16k
      {
1065
        /* Ok, this was a 'pref' candidate but didn't form any.
1066
         * Base is around here... */
1067
1.16k
        base = i;
1068
9.07k
        while (base < end && is_halant (info[base]))
1069
7.90k
    base++;
1070
1.16k
        if (base < end)
1071
1.07k
    info[base].indic_position() = POS_BASE_C;
1072
1073
1.16k
        try_pref = false;
1074
1.16k
      }
1075
1.30k
      break;
1076
1.30k
    }
1077
11.1k
  if (base == end)
1078
89
    break;
1079
11.1k
      }
1080
      /* For Malayalam, skip over unformed below- (but NOT post-) forms. */
1081
1.97M
      if (buffer->props.script == HB_SCRIPT_MALAYALAM)
1082
425k
      {
1083
430k
  for (unsigned int i = base + 1; i < end; i++)
1084
19.5k
  {
1085
25.1k
    while (i < end && is_joiner (info[i]))
1086
5.58k
      i++;
1087
19.5k
    if (i == end || !is_halant (info[i]))
1088
14.5k
      break;
1089
5.04k
    i++; /* Skip halant. */
1090
5.33k
    while (i < end && is_joiner (info[i]))
1091
287
      i++;
1092
5.04k
    if (i < end && is_consonant (info[i]) && info[i].indic_position() == POS_BELOW_C)
1093
0
    {
1094
0
      base = i;
1095
0
      info[base].indic_position() = POS_BASE_C;
1096
0
    }
1097
5.04k
  }
1098
425k
      }
1099
1100
1.97M
      if (start < base && info[base].indic_position() > POS_BASE_C)
1101
42
  base--;
1102
1.97M
      break;
1103
1.97M
    }
1104
2.02M
  if (base == end && start < base &&
1105
49.3k
      is_one_of (info[base - 1], FLAG (I_Cat(ZWJ))))
1106
389
    base--;
1107
2.02M
  if (base < end)
1108
1.97M
    while (start < base &&
1109
7.23k
     is_one_of (info[base], (FLAG (I_Cat(N)) | FLAG (I_Cat(H)))))
1110
162
      base--;
1111
1112
1113
  /*   o Reorder matras:
1114
   *
1115
   *     If a pre-base matra character had been reordered before applying basic
1116
   *     features, the glyph can be moved closer to the main consonant based on
1117
   *     whether half-forms had been formed. Actual position for the matra is
1118
   *     defined as “after last standalone halant glyph, after initial matra
1119
   *     position and before the main consonant”. If ZWJ or ZWNJ follow this
1120
   *     halant, position is moved after it.
1121
   *
1122
   * IMPLEMENTATION NOTES:
1123
   *
1124
   * It looks like the last sentence is wrong.  Testing, with Windows 7 Uniscribe
1125
   * and Devanagari shows that the behavior is best described as:
1126
   *
1127
   * "If ZWJ follows this halant, matra is NOT repositioned after this halant.
1128
   *  If ZWNJ follows this halant, position is moved after it."
1129
   *
1130
   * Test case, with Adobe Devanagari or Nirmala UI:
1131
   *
1132
   *   U+091F,U+094D,U+200C,U+092F,U+093F
1133
   *   (Matra moves to the middle, after ZWNJ.)
1134
   *
1135
   *   U+091F,U+094D,U+200D,U+092F,U+093F
1136
   *   (Matra does NOT move, stays to the left.)
1137
   *
1138
   * https://github.com/harfbuzz/harfbuzz/issues/1070
1139
   */
1140
1141
2.02M
  if (start + 1 < end && start < base) /* Otherwise there can't be any pre-base matra characters. */
1142
35.1k
  {
1143
    /* If we lost track of base, alas, position before last thingy. */
1144
35.1k
    unsigned int new_pos = base == end ? base - 2 : base - 1;
1145
1146
    /* Malayalam / Tamil do not have "half" forms or explicit virama forms.
1147
     * The glyphs formed by 'half' are Chillus or ligated explicit viramas.
1148
     * We want to position matra after them.
1149
     */
1150
35.1k
    if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL)
1151
20.4k
    {
1152
20.7k
    search:
1153
29.4k
      while (new_pos > start &&
1154
9.74k
       !(is_one_of (info[new_pos], (FLAG (I_Cat(M)) | FLAG (I_Cat(MPst)) | FLAG (I_Cat(H))))))
1155
8.65k
  new_pos--;
1156
1157
      /* If we found no Halant we are done.
1158
       * Otherwise only proceed if the Halant does
1159
       * not belong to the Matra itself! */
1160
20.7k
      if (is_halant (info[new_pos]) &&
1161
834
    info[new_pos].indic_position() != POS_PRE_M)
1162
827
      {
1163
#if 0 // See comment above
1164
  /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */
1165
  if (new_pos + 1 < end && is_joiner (info[new_pos + 1]))
1166
    new_pos++;
1167
#endif
1168
827
  if (new_pos + 1 < end)
1169
827
  {
1170
    /* -> If ZWJ follows this halant, matra is NOT repositioned after this halant. */
1171
827
    if (info[new_pos + 1].indic_category() == I_Cat(ZWJ))
1172
382
    {
1173
      /* Keep searching. */
1174
382
      if (new_pos > start)
1175
325
      {
1176
325
        new_pos--;
1177
325
        goto search;
1178
325
      }
1179
382
    }
1180
    /* -> If ZWNJ follows this halant, position is moved after it.
1181
     *
1182
     * IMPLEMENTATION NOTES:
1183
     *
1184
     * This is taken care of by the state-machine. A Halant,ZWNJ is a terminating
1185
     * sequence for a consonant syllable; any pre-base matras occurring after it
1186
     * will belong to the subsequent syllable.
1187
     */
1188
827
  }
1189
827
      }
1190
19.9k
      else
1191
19.9k
  new_pos = start; /* No move. */
1192
20.7k
    }
1193
1194
35.1k
    if (start < new_pos && info[new_pos].indic_position () != POS_PRE_M)
1195
2.31k
    {
1196
      /* Now go see if there's actually any matras... */
1197
362k
      for (unsigned int i = new_pos; i > start; i--)
1198
360k
  if (info[i - 1].indic_position () == POS_PRE_M)
1199
4.58k
  {
1200
4.58k
    unsigned int old_pos = i - 1;
1201
4.58k
    if (old_pos < base && base <= new_pos) /* Shouldn't actually happen. */
1202
0
      base--;
1203
1204
4.58k
    hb_glyph_info_t tmp = info[old_pos];
1205
4.58k
    memmove (&info[old_pos], &info[old_pos + 1], (new_pos - old_pos) * sizeof (info[0]));
1206
4.58k
    info[new_pos] = tmp;
1207
1208
    /* Note: this merge_clusters() is intentionally *after* the reordering.
1209
     * Indic matra reordering is special and tricky... */
1210
4.58k
    buffer->merge_clusters (new_pos, hb_min (end, base + 1));
1211
1212
4.58k
    new_pos--;
1213
4.58k
  }
1214
32.8k
    } else {
1215
172k
      for (unsigned int i = start; i < base; i++)
1216
139k
  if (info[i].indic_position () == POS_PRE_M) {
1217
345
    buffer->merge_clusters (i, hb_min (end, base + 1));
1218
345
    break;
1219
345
  }
1220
32.8k
    }
1221
35.1k
  }
1222
1223
1224
  /*   o Reorder reph:
1225
   *
1226
   *     Reph’s original position is always at the beginning of the syllable,
1227
   *     (i.e. it is not reordered at the character reordering stage). However,
1228
   *     it will be reordered according to the basic-forms shaping results.
1229
   *     Possible positions for reph, depending on the script, are; after main,
1230
   *     before post-base consonant forms, and after post-base consonant forms.
1231
   */
1232
1233
  /* Two cases:
1234
   *
1235
   * - If repha is encoded as a sequence of characters (Ra,H or Ra,H,ZWJ), then
1236
   *   we should only move it if the sequence ligated to the repha form.
1237
   *
1238
   * - If repha is encoded separately and in the logical position, we should only
1239
   *   move it if it did NOT ligate.  If it ligated, it's probably the font trying
1240
   *   to make it work without the reordering.
1241
   */
1242
2.02M
  if (start + 1 < end &&
1243
52.4k
      info[start].indic_position() == POS_RA_TO_BECOME_REPH &&
1244
5.43k
      ((info[start].indic_category() == I_Cat(Repha)) ^
1245
5.43k
       _hb_glyph_info_ligated_and_didnt_multiply (&info[start])))
1246
4.78k
  {
1247
4.78k
    unsigned int new_reph_pos;
1248
4.78k
    reph_position_t reph_pos = indic_plan->config->reph_pos;
1249
1250
    /*       1. If reph should be positioned after post-base consonant forms,
1251
     *          proceed to step 5.
1252
     */
1253
4.78k
    if (reph_pos == REPH_POS_AFTER_POST)
1254
15
    {
1255
15
      goto reph_step_5;
1256
15
    }
1257
1258
    /*       2. If the reph repositioning class is not after post-base: target
1259
     *          position is after the first explicit halant glyph between the
1260
     *          first post-reph consonant and last main consonant. If ZWJ or ZWNJ
1261
     *          are following this halant, position is moved after it. If such
1262
     *          position is found, this is the target position. Otherwise,
1263
     *          proceed to the next step.
1264
     *
1265
     *          Note: in old-implementation fonts, where classifications were
1266
     *          fixed in shaping engine, there was no case where reph position
1267
     *          will be found on this step.
1268
     */
1269
4.77k
    {
1270
4.77k
      new_reph_pos = start + 1;
1271
131k
      while (new_reph_pos < base && !is_halant (info[new_reph_pos]))
1272
126k
  new_reph_pos++;
1273
1274
4.77k
      if (new_reph_pos < base && is_halant (info[new_reph_pos]))
1275
646
      {
1276
  /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */
1277
646
  if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1]))
1278
6
    new_reph_pos++;
1279
646
  goto reph_move;
1280
646
      }
1281
4.77k
    }
1282
1283
    /*       3. If reph should be repositioned after the main consonant: find the
1284
     *          first consonant not ligated with main, or find the first
1285
     *          consonant that is not a potential pre-base-reordering Ra.
1286
     */
1287
4.12k
    if (reph_pos == REPH_POS_AFTER_MAIN)
1288
4.11k
    {
1289
4.11k
      new_reph_pos = base;
1290
7.51k
      while (new_reph_pos + 1 < end && info[new_reph_pos + 1].indic_position() <= POS_AFTER_MAIN)
1291
3.39k
  new_reph_pos++;
1292
4.11k
      if (new_reph_pos < end)
1293
4.05k
  goto reph_move;
1294
4.11k
    }
1295
1296
    /*       4. If reph should be positioned before post-base consonant, find
1297
     *          first post-base classified consonant not ligated with main. If no
1298
     *          consonant is found, the target position should be before the
1299
     *          first matra, syllable modifier sign or vedic sign.
1300
     */
1301
    /* This is our take on what step 4 is trying to say (and failing, BADLY). */
1302
77
    if (reph_pos == REPH_POS_AFTER_SUB)
1303
10
    {
1304
10
      new_reph_pos = base;
1305
11
      while (new_reph_pos + 1 < end &&
1306
5
       !( FLAG_UNSAFE (info[new_reph_pos + 1].indic_position()) & (FLAG (POS_POST_C) | FLAG (POS_AFTER_POST) | FLAG (POS_SMVD))))
1307
1
  new_reph_pos++;
1308
10
      if (new_reph_pos < end)
1309
10
  goto reph_move;
1310
10
    }
1311
1312
    /*       5. If no consonant is found in steps 3 or 4, move reph to a position
1313
     *          immediately before the first post-base matra, syllable modifier
1314
     *          sign or vedic sign that has a reordering class after the intended
1315
     *          reph position. For example, if the reordering position for reph
1316
     *          is post-main, it will skip above-base matras that also have a
1317
     *          post-main position.
1318
     */
1319
82
    reph_step_5:
1320
82
    {
1321
      /* Copied from step 2. */
1322
82
      new_reph_pos = start + 1;
1323
38.8k
      while (new_reph_pos < base && !is_halant (info[new_reph_pos]))
1324
38.7k
  new_reph_pos++;
1325
1326
82
      if (new_reph_pos < base && is_halant (info[new_reph_pos]))
1327
4
      {
1328
  /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */
1329
4
  if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1]))
1330
0
    new_reph_pos++;
1331
4
  goto reph_move;
1332
4
      }
1333
82
    }
1334
    /* See https://github.com/harfbuzz/harfbuzz/issues/2298#issuecomment-615318654 */
1335
1336
    /*       6. Otherwise, reorder reph to the end of the syllable.
1337
     */
1338
78
    {
1339
78
      new_reph_pos = end - 1;
1340
82
      while (new_reph_pos > start && info[new_reph_pos].indic_position() == POS_SMVD)
1341
4
  new_reph_pos--;
1342
1343
      /*
1344
       * If the Reph is to be ending up after a Matra,Halant sequence,
1345
       * position it before that Halant so it can interact with the Matra.
1346
       * However, if it's a plain Consonant,Halant we shouldn't do that.
1347
       * Uniscribe doesn't do this.
1348
       * TEST: U+0930,U+094D,U+0915,U+094B,U+094D
1349
       */
1350
78
      if (!indic_plan->uniscribe_bug_compatible &&
1351
78
    unlikely (is_halant (info[new_reph_pos])))
1352
1
      {
1353
1
  for (unsigned int i = base + 1; i < new_reph_pos; i++)
1354
0
    if (FLAG_UNSAFE (info[i].indic_category()) & (FLAG (I_Cat(M)) | FLAG (I_Cat(MPst))))
1355
0
    {
1356
      /* Ok, got it. */
1357
0
      new_reph_pos--;
1358
0
    }
1359
1
      }
1360
1361
78
      goto reph_move;
1362
82
    }
1363
1364
4.78k
    reph_move:
1365
4.78k
    {
1366
      /* Move */
1367
4.78k
      buffer->merge_clusters (start, new_reph_pos + 1);
1368
4.78k
      hb_glyph_info_t reph = info[start];
1369
4.78k
      memmove (&info[start], &info[start + 1], (new_reph_pos - start) * sizeof (info[0]));
1370
4.78k
      info[new_reph_pos] = reph;
1371
1372
4.78k
      if (start < base && base <= new_reph_pos)
1373
4.07k
  base--;
1374
4.78k
    }
1375
4.78k
  }
1376
1377
1378
  /*   o Reorder pre-base-reordering consonants:
1379
   *
1380
   *     If a pre-base-reordering consonant is found, reorder it according to
1381
   *     the following rules:
1382
   */
1383
1384
2.02M
  if (try_pref && base + 1 < end) /* Otherwise there can't be any pre-base-reordering Ra. */
1385
13.0k
  {
1386
1.09M
    for (unsigned int i = base + 1; i < end; i++)
1387
1.08M
      if ((info[i].mask & indic_plan->mask_array[INDIC_PREF]) != 0)
1388
133
      {
1389
  /*       1. Only reorder a glyph produced by substitution during application
1390
   *          of the <pref> feature. (Note that a font may shape a Ra consonant with
1391
   *          the feature generally but block it in certain contexts.)
1392
   */
1393
  /* Note: We just check that something got substituted.  We don't check that
1394
   * the <pref> feature actually did it...
1395
   *
1396
   * Reorder pref only if it ligated. */
1397
133
  if (_hb_glyph_info_ligated_and_didnt_multiply (&info[i]))
1398
133
  {
1399
    /*
1400
     *       2. Try to find a target position the same way as for pre-base matra.
1401
     *          If it is found, reorder pre-base consonant glyph.
1402
     *
1403
     *       3. If position is not found, reorder immediately before main
1404
     *          consonant.
1405
     */
1406
1407
133
    unsigned int new_pos = base;
1408
    /* Malayalam / Tamil do not have "half" forms or explicit virama forms.
1409
     * The glyphs formed by 'half' are Chillus or ligated explicit viramas.
1410
     * We want to position matra after them.
1411
     */
1412
133
    if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL)
1413
33
    {
1414
123
      while (new_pos > start &&
1415
110
       !(is_one_of (info[new_pos - 1], FLAG (I_Cat(M)) | FLAG (I_Cat(MPst)) | FLAG (I_Cat(H)))))
1416
90
        new_pos--;
1417
33
    }
1418
1419
133
    if (new_pos > start && is_halant (info[new_pos - 1]))
1420
0
    {
1421
      /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */
1422
0
      if (new_pos < end && is_joiner (info[new_pos]))
1423
0
        new_pos++;
1424
0
    }
1425
1426
133
    {
1427
133
      unsigned int old_pos = i;
1428
1429
133
      buffer->merge_clusters (new_pos, old_pos + 1);
1430
133
      hb_glyph_info_t tmp = info[old_pos];
1431
133
      memmove (&info[new_pos + 1], &info[new_pos], (old_pos - new_pos) * sizeof (info[0]));
1432
133
      info[new_pos] = tmp;
1433
1434
133
      if (new_pos <= base && base < old_pos)
1435
133
        base++;
1436
133
    }
1437
133
  }
1438
1439
133
  break;
1440
133
      }
1441
13.0k
  }
1442
1443
1444
  /* Apply 'init' to the Left Matra if it's a word start. */
1445
2.02M
  if (info[start].indic_position () == POS_PRE_M)
1446
342
  {
1447
342
    if (!start ||
1448
282
  !(FLAG_UNSAFE (_hb_glyph_info_get_general_category (&info[start - 1])) &
1449
282
   FLAG_RANGE (HB_UNICODE_GENERAL_CATEGORY_FORMAT, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)))
1450
177
      info[start].mask |= indic_plan->mask_array[INDIC_INIT];
1451
165
    else
1452
165
      buffer->unsafe_to_break (start - 1, start + 1);
1453
342
  }
1454
1455
1456
  /*
1457
   * Finish off the clusters and go home!
1458
   */
1459
2.02M
  if (indic_plan->uniscribe_bug_compatible)
1460
0
  {
1461
0
    switch ((hb_tag_t) plan->props.script)
1462
0
    {
1463
0
      case HB_SCRIPT_TAMIL:
1464
0
  break;
1465
1466
0
      default:
1467
  /* Uniscribe merges the entire syllable into a single cluster... Except for Tamil.
1468
   * This means, half forms are submerged into the main consonant's cluster.
1469
   * This is unnecessary, and makes cursor positioning harder, but that's what
1470
   * Uniscribe does. */
1471
0
  buffer->merge_clusters (start, end);
1472
0
  break;
1473
0
    }
1474
0
  }
1475
2.02M
}
1476
1477
1478
static bool
1479
final_reordering_indic (const hb_ot_shape_plan_t *plan,
1480
      hb_font_t *font HB_UNUSED,
1481
      hb_buffer_t *buffer)
1482
2.87k
{
1483
2.87k
  unsigned int count = buffer->len;
1484
2.87k
  if (unlikely (!count)) return false;
1485
1486
2.87k
  if (buffer->message (font, "start reordering indic final")) {
1487
2.87k
    foreach_syllable (buffer, start, end)
1488
2.02M
      final_reordering_syllable_indic (plan, buffer, start, end);
1489
2.87k
    (void) buffer->message (font, "end reordering indic final");
1490
2.87k
  }
1491
1492
2.87k
  HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category);
1493
2.87k
  HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position);
1494
1495
2.87k
  return false;
1496
2.87k
}
1497
1498
1499
static void
1500
preprocess_text_indic (const hb_ot_shape_plan_t *plan,
1501
           hb_buffer_t              *buffer,
1502
           hb_font_t                *font)
1503
2.90k
{
1504
2.90k
  const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
1505
2.90k
  if (!indic_plan->uniscribe_bug_compatible)
1506
2.90k
    _hb_preprocess_text_vowel_constraints (plan, buffer, font);
1507
2.90k
}
1508
1509
static bool
1510
decompose_indic (const hb_ot_shape_normalize_context_t *c,
1511
     hb_codepoint_t  ab,
1512
     hb_codepoint_t *a,
1513
     hb_codepoint_t *b)
1514
47.7k
{
1515
47.7k
  switch (ab)
1516
47.7k
  {
1517
    /* Don't decompose these. */
1518
23
    case 0x0931u  : return false; /* DEVANAGARI LETTER RRA */
1519
    // https://github.com/harfbuzz/harfbuzz/issues/779
1520
11
    case 0x09DCu  : return false; /* BENGALI LETTER RRA */
1521
10
    case 0x09DDu  : return false; /* BENGALI LETTER RHA */
1522
21
    case 0x0B94u  : return false; /* TAMIL LETTER AU */
1523
1524
1525
    /*
1526
     * Decompose split matras that don't have Unicode decompositions.
1527
     */
1528
1529
#if 0
1530
    /* Gujarati */
1531
    /* This one has no decomposition in Unicode, but needs no decomposition either. */
1532
    /* case 0x0AC9u  : return false; */
1533
1534
    /* Oriya */
1535
    case 0x0B57u  : *a = no decomp, -> RIGHT; return true;
1536
#endif
1537
47.7k
  }
1538
1539
47.6k
  return (bool) c->unicode->decompose (ab, a, b);
1540
47.7k
}
1541
1542
static bool
1543
compose_indic (const hb_ot_shape_normalize_context_t *c,
1544
         hb_codepoint_t  a,
1545
         hb_codepoint_t  b,
1546
         hb_codepoint_t *ab)
1547
6.58k
{
1548
  /* Avoid recomposing split matras. */
1549
6.58k
  if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (c->unicode->general_category (a)))
1550
1.46k
    return false;
1551
1552
  /* Composition-exclusion exceptions that we want to recompose. */
1553
5.12k
  if (a == 0x09AFu && b == 0x09BCu) { *ab = 0x09DFu; return true; }
1554
1555
5.11k
  return (bool) c->unicode->compose (a, b, ab);
1556
5.12k
}
1557
1558
1559
const hb_ot_shaper_t _hb_ot_shaper_indic =
1560
{
1561
  collect_features_indic,
1562
  override_features_indic,
1563
  data_create_indic,
1564
  data_destroy_indic,
1565
  preprocess_text_indic,
1566
  nullptr, /* postprocess_glyphs */
1567
  decompose_indic,
1568
  compose_indic,
1569
  setup_masks_indic,
1570
  nullptr, /* reorder_marks */
1571
  HB_TAG_NONE, /* gpos_tag */
1572
  HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT,
1573
  HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE,
1574
  false, /* fallback_position */
1575
};
1576
1577
1578
#endif