Coverage Report

Created: 2024-05-14 19:38

/src/harfbuzz/src/hb-ot-shaper-indic.cc
Line
Count
Source (jump to first uncovered line)
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
325k
{
45
325k
  hb_codepoint_t u = info.codepoint;
46
325k
  unsigned int type = hb_indic_get_categories (u);
47
48
325k
  info.indic_category() = (indic_category_t) (type & 0xFFu);
49
325k
  info.indic_position() = (indic_position_t) (type >> 8);
50
325k
}
51
52
53
static inline bool
54
is_one_of (const hb_glyph_info_t &info, unsigned int flags)
55
7.06M
{
56
  /* If it ligated, all bets are off. */
57
7.06M
  if (_hb_glyph_info_ligated (&info)) return false;
58
7.05M
  return !!(FLAG_UNSAFE (info.indic_category()) & flags);
59
7.06M
}
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
4.88M
#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
4.88M
{
73
4.88M
  return is_one_of (info, CONSONANT_FLAGS_INDIC);
74
4.88M
}
75
76
3.28M
#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
1.79M
{
81
1.79M
  return is_one_of (info, JOINER_FLAGS);
82
1.79M
}
83
84
static inline bool
85
is_halant (const hb_glyph_info_t &info)
86
295k
{
87
295k
  return is_one_of (info, FLAG (I_Cat(H)));
88
295k
}
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
100k
  {
94
100k
    zero_context = zero_context_;
95
100k
    lookups = map->get_stage_lookups (0/*GSUB*/,
96
100k
              map->get_feature_stage (0/*GSUB*/, feature_tag));
97
100k
  }
98
99
  bool would_substitute (const hb_codepoint_t *glyphs,
100
       unsigned int          glyphs_count,
101
       hb_face_t            *face) const
102
2.81M
  {
103
2.81M
    for (const auto &lookup : lookups)
104
4.13M
      if (hb_ot_layout_lookup_would_substitute (face, lookup.index, glyphs, glyphs_count, zero_context))
105
34.4k
  return true;
106
2.78M
    return false;
107
2.81M
  }
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
20.0k
{
242
20.0k
  hb_ot_map_builder_t *map = &plan->map;
243
244
  /* Do this before any lookups have been applied. */
245
20.0k
  map->add_gsub_pause (setup_syllables_indic);
246
247
20.0k
  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
20.0k
  map->enable_feature (HB_TAG('c','c','m','p'), F_PER_SYLLABLE);
251
252
253
20.0k
  unsigned int i = 0;
254
20.0k
  map->add_gsub_pause (initial_reordering_indic);
255
256
241k
  for (; i < INDIC_BASIC_FEATURES; i++) {
257
220k
    map->add_feature (indic_features[i]);
258
220k
    map->add_gsub_pause (nullptr);
259
220k
  }
260
261
20.0k
  map->add_gsub_pause (final_reordering_indic);
262
263
140k
  for (; i < INDIC_NUM_FEATURES; i++)
264
120k
    map->add_feature (indic_features[i]);
265
20.0k
}
266
267
static void
268
override_features_indic (hb_ot_shape_planner_t *plan)
269
20.0k
{
270
20.0k
  plan->map.disable_feature (HB_TAG('l','i','g','a'));
271
20.0k
  plan->map.add_gsub_pause (hb_syllabic_clear_var); // Don't need syllables anymore, use stop to free buffer var
272
20.0k
}
273
274
275
struct indic_shape_plan_t
276
{
277
  bool load_virama_glyph (hb_font_t *font, hb_codepoint_t *pglyph) const
278
19.8k
  {
279
19.8k
    hb_codepoint_t glyph = virama_glyph;
280
19.8k
    if (unlikely (glyph == (hb_codepoint_t) -1))
281
19.8k
    {
282
19.8k
      if (!config->virama || !font->get_nominal_glyph (config->virama, &glyph))
283
14.9k
  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
19.8k
      virama_glyph = (int) glyph;
290
19.8k
    }
291
292
19.8k
    *pglyph = glyph;
293
19.8k
    return glyph != 0;
294
19.8k
  }
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_int_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
20.0k
{
318
20.0k
  indic_shape_plan_t *indic_plan = (indic_shape_plan_t *) hb_calloc (1, sizeof (indic_shape_plan_t));
319
20.0k
  if (unlikely (!indic_plan))
320
36
    return nullptr;
321
322
20.0k
  indic_plan->config = &indic_configs[0];
323
119k
  for (unsigned int i = 1; i < ARRAY_LENGTH (indic_configs); i++)
324
119k
    if (plan->props.script == indic_configs[i].script) {
325
20.0k
      indic_plan->config = &indic_configs[i];
326
20.0k
      break;
327
20.0k
    }
328
329
20.0k
  indic_plan->is_old_spec = indic_plan->config->has_old_spec && ((plan->map.chosen_script[0] & 0x000000FFu) != '2');
330
20.0k
#ifndef HB_NO_UNISCRIBE_BUG_COMPATIBLE
331
20.0k
  indic_plan->uniscribe_bug_compatible = hb_options ().uniscribe_bug_compatible;
332
20.0k
#endif
333
20.0k
  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
20.0k
  bool zero_context = !indic_plan->is_old_spec && plan->props.script != HB_SCRIPT_MALAYALAM;
345
20.0k
  indic_plan->rphf.init (&plan->map, HB_TAG('r','p','h','f'), zero_context);
346
20.0k
  indic_plan->pref.init (&plan->map, HB_TAG('p','r','e','f'), zero_context);
347
20.0k
  indic_plan->blwf.init (&plan->map, HB_TAG('b','l','w','f'), zero_context);
348
20.0k
  indic_plan->pstf.init (&plan->map, HB_TAG('p','s','t','f'), zero_context);
349
20.0k
  indic_plan->vatu.init (&plan->map, HB_TAG('v','a','t','u'), zero_context);
350
351
360k
  for (unsigned int i = 0; i < ARRAY_LENGTH (indic_plan->mask_array); i++)
352
340k
    indic_plan->mask_array[i] = (indic_features[i].flags & F_GLOBAL) ?
353
200k
         0 : plan->map.get_1_mask (indic_features[i].tag);
354
355
20.0k
  return indic_plan;
356
20.0k
}
357
358
static void
359
data_destroy_indic (void *data)
360
20.0k
{
361
20.0k
  hb_free (data);
362
20.0k
}
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
329k
{
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
329k
  hb_codepoint_t glyphs[3] = {virama, consonant, virama};
385
329k
  if (indic_plan->blwf.would_substitute (glyphs  , 2, face) ||
386
329k
      indic_plan->blwf.would_substitute (glyphs+1, 2, face) ||
387
329k
      indic_plan->vatu.would_substitute (glyphs  , 2, face) ||
388
329k
      indic_plan->vatu.would_substitute (glyphs+1, 2, face))
389
7.57k
    return POS_BELOW_C;
390
322k
  if (indic_plan->pstf.would_substitute (glyphs  , 2, face) ||
391
322k
      indic_plan->pstf.would_substitute (glyphs+1, 2, face))
392
1.03k
    return POS_POST_C;
393
321k
  if (indic_plan->pref.would_substitute (glyphs  , 2, face) ||
394
321k
      indic_plan->pref.would_substitute (glyphs+1, 2, face))
395
24.4k
    return POS_POST_C;
396
296k
  return POS_BASE_C;
397
321k
}
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
20.0k
{
404
20.0k
  HB_BUFFER_ALLOCATE_VAR (buffer, indic_category);
405
20.0k
  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
20.0k
  unsigned int count = buffer->len;
411
20.0k
  hb_glyph_info_t *info = buffer->info;
412
345k
  for (unsigned int i = 0; i < count; i++)
413
325k
    set_indic_properties (info[i]);
414
20.0k
}
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
19.8k
{
421
19.8k
  HB_BUFFER_ALLOCATE_VAR (buffer, syllable);
422
19.8k
  find_syllables_indic (buffer);
423
19.8k
  foreach_syllable (buffer, start, end)
424
1.80M
    buffer->unsafe_to_break (start, end);
425
19.8k
  return false;
426
19.8k
}
427
428
static int
429
compare_indic_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb)
430
5.37M
{
431
5.37M
  int a = pa->indic_position();
432
5.37M
  int b = pb->indic_position();
433
434
5.37M
  return (int) a - (int) b;
435
5.37M
}
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
19.8k
{
444
19.8k
  const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
445
446
19.8k
  hb_codepoint_t virama;
447
19.8k
  if (indic_plan->load_virama_glyph (font, &virama))
448
4.90k
  {
449
4.90k
    hb_face_t *face = font->face;
450
4.90k
    unsigned int count = buffer->len;
451
4.90k
    hb_glyph_info_t *info = buffer->info;
452
2.39M
    for (unsigned int i = 0; i < count; i++)
453
2.38M
      if (info[i].indic_position() == POS_BASE_C)
454
329k
      {
455
329k
  hb_codepoint_t consonant = info[i].codepoint;
456
329k
  info[i].indic_position() = consonant_position_from_face (indic_plan, consonant, virama, face);
457
329k
      }
458
4.90k
  }
459
19.8k
}
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
225k
{
471
225k
  const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
472
225k
  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
225k
  if (buffer->props.script == HB_SCRIPT_KANNADA &&
479
225k
      start + 3 <= end &&
480
225k
      is_one_of (info[start  ], FLAG (I_Cat(Ra))) &&
481
225k
      is_one_of (info[start+1], FLAG (I_Cat(H))) &&
482
225k
      is_one_of (info[start+2], FLAG (I_Cat(ZWJ))))
483
37
  {
484
37
    buffer->merge_clusters (start+1, start+3);
485
37
    hb_glyph_info_t tmp = info[start+1];
486
37
    info[start+1] = info[start+2];
487
37
    info[start+2] = tmp;
488
37
  }
489
490
  /* 1. Find base consonant:
491
   *
492
   * The shaping engine finds the base consonant of the syllable, using the
493
   * following algorithm: starting from the end of the syllable, move backwards
494
   * until a consonant is found that does not have a below-base or post-base
495
   * form (post-base forms have to follow below-base forms), or that is not a
496
   * pre-base-reordering Ra, or arrive at the first consonant. The consonant
497
   * stopped at will be the base.
498
   *
499
   *   o If the syllable starts with Ra + Halant (in a script that has Reph)
500
   *     and has more than one consonant, Ra is excluded from candidates for
501
   *     base consonants.
502
   */
503
504
225k
  unsigned int base = end;
505
225k
  bool has_reph = false;
506
507
225k
  {
508
    /* -> If the syllable starts with Ra + Halant (in a script that has Reph)
509
     *    and has more than one consonant, Ra is excluded from candidates for
510
     *    base consonants. */
511
225k
    unsigned int limit = start;
512
225k
    if (indic_plan->mask_array[INDIC_RPHF] &&
513
225k
  start + 3 <= end &&
514
225k
  (
515
2.52k
   (indic_plan->config->reph_mode == REPH_MODE_IMPLICIT && !is_joiner (info[start + 2])) ||
516
2.52k
   (indic_plan->config->reph_mode == REPH_MODE_EXPLICIT && info[start + 2].indic_category() == I_Cat(ZWJ))
517
2.52k
  ))
518
1.71k
    {
519
      /* See if it matches the 'rphf' feature. */
520
1.71k
      hb_codepoint_t glyphs[3] = {info[start].codepoint,
521
1.71k
          info[start + 1].codepoint,
522
1.71k
          indic_plan->config->reph_mode == REPH_MODE_EXPLICIT ?
523
1.69k
            info[start + 2].codepoint : 0};
524
1.71k
      if (indic_plan->rphf.would_substitute (glyphs, 2, face) ||
525
1.71k
    (indic_plan->config->reph_mode == REPH_MODE_EXPLICIT &&
526
1.60k
     indic_plan->rphf.would_substitute (glyphs, 3, face)))
527
105
      {
528
105
  limit += 2;
529
105
  while (limit < end && is_joiner (info[limit]))
530
0
    limit++;
531
105
  base = start;
532
105
  has_reph = true;
533
105
      }
534
223k
    } else if (indic_plan->config->reph_mode == REPH_MODE_LOG_REPHA && info[start].indic_category() == I_Cat(Repha))
535
49.0k
    {
536
49.0k
  limit += 1;
537
49.3k
  while (limit < end && is_joiner (info[limit]))
538
293
    limit++;
539
49.0k
  base = start;
540
49.0k
  has_reph = true;
541
49.0k
    }
542
543
225k
    {
544
      /* -> starting from the end of the syllable, move backwards */
545
225k
      unsigned int i = end;
546
225k
      bool seen_below = false;
547
926k
      do {
548
926k
  i--;
549
  /* -> until a consonant is found */
550
926k
  if (is_consonant (info[i]))
551
131k
  {
552
    /* -> that does not have a below-base or post-base form
553
     * (post-base forms have to follow below-base forms), */
554
131k
    if (info[i].indic_position() != POS_BELOW_C &&
555
131k
        (info[i].indic_position() != POS_POST_C || seen_below))
556
128k
    {
557
128k
      base = i;
558
128k
      break;
559
128k
    }
560
3.27k
    if (info[i].indic_position() == POS_BELOW_C)
561
1.39k
      seen_below = true;
562
563
    /* -> or that is not a pre-base-reordering Ra,
564
     *
565
     * IMPLEMENTATION NOTES:
566
     *
567
     * Our pre-base-reordering Ra's are marked POS_POST_C, so will be skipped
568
     * by the logic above already.
569
     */
570
571
    /* -> or arrive at the first consonant. The consonant stopped at will
572
     * be the base. */
573
3.27k
    base = i;
574
3.27k
  }
575
795k
  else
576
795k
  {
577
    /* A ZWJ after a Halant stops the base search, and requests an explicit
578
     * half form.
579
     * A ZWJ before a Halant, requests a subjoined form instead, and hence
580
     * search continues.  This is particularly important for Bengali
581
     * sequence Ra,H,Ya that should form Ya-Phalaa by subjoining Ya. */
582
795k
    if (start < i &&
583
795k
        info[i].indic_category() == I_Cat(ZWJ) &&
584
795k
        info[i - 1].indic_category() == I_Cat(H))
585
636
      break;
586
795k
  }
587
926k
      } while (i > limit);
588
225k
    }
589
590
    /* -> If the syllable starts with Ra + Halant (in a script that has Reph)
591
     *    and has more than one consonant, Ra is excluded from candidates for
592
     *    base consonants.
593
     *
594
     *  Only do this for unforced Reph. (ie. not for Ra,H,ZWJ. */
595
225k
    if (has_reph && base == start && limit - base <= 2) {
596
      /* Have no other consonant, so Reph is not formed and Ra becomes base. */
597
36.8k
      has_reph = false;
598
36.8k
    }
599
225k
  }
600
601
602
  /* 2. Decompose and reorder Matras:
603
   *
604
   * Each matra and any syllable modifier sign in the syllable are moved to the
605
   * appropriate position relative to the consonant(s) in the syllable. The
606
   * shaping engine decomposes two- or three-part matras into their constituent
607
   * parts before any repositioning. Matra characters are classified by which
608
   * consonant in a conjunct they have affinity for and are reordered to the
609
   * following positions:
610
   *
611
   *   o Before first half form in the syllable
612
   *   o After subjoined consonants
613
   *   o After post-form consonant
614
   *   o After main consonant (for above marks)
615
   *
616
   * IMPLEMENTATION NOTES:
617
   *
618
   * The normalize() routine has already decomposed matras for us, so we don't
619
   * need to worry about that.
620
   */
621
622
623
  /* 3.  Reorder marks to canonical order:
624
   *
625
   * Adjacent nukta and halant or nukta and vedic sign are always repositioned
626
   * if necessary, so that the nukta is first.
627
   *
628
   * IMPLEMENTATION NOTES:
629
   *
630
   * We don't need to do this: the normalize() routine already did this for us.
631
   */
632
633
634
  /* Reorder characters */
635
636
965k
  for (unsigned int i = start; i < base; i++)
637
740k
    info[i].indic_position() = hb_min (POS_PRE_C, (indic_position_t) info[i].indic_position());
638
639
225k
  if (base < end)
640
167k
    info[base].indic_position() = POS_BASE_C;
641
642
  /* Handle beginning Ra */
643
225k
  if (has_reph)
644
12.2k
    info[start].indic_position() = POS_RA_TO_BECOME_REPH;
645
646
  /* For old-style Indic script tags, move the first post-base Halant after
647
   * last consonant.
648
   *
649
   * Reports suggest that in some scripts Uniscribe does this only if there
650
   * is *not* a Halant after last consonant already.  We know that is the
651
   * case for Kannada, while it reorders unconditionally in other scripts,
652
   * eg. Malayalam, Bengali, and Devanagari.  We don't currently know about
653
   * other scripts, so we block Kannada.
654
   *
655
   * Kannada test case:
656
   * U+0C9A,U+0CCD,U+0C9A,U+0CCD
657
   * With some versions of Lohit Kannada.
658
   * https://bugs.freedesktop.org/show_bug.cgi?id=59118
659
   *
660
   * Malayalam test case:
661
   * U+0D38,U+0D4D,U+0D31,U+0D4D,U+0D31,U+0D4D
662
   * With lohit-ttf-20121122/Lohit-Malayalam.ttf
663
   *
664
   * Bengali test case:
665
   * U+0998,U+09CD,U+09AF,U+09CD
666
   * With Windows XP vrinda.ttf
667
   * https://github.com/harfbuzz/harfbuzz/issues/1073
668
   *
669
   * Devanagari test case:
670
   * U+091F,U+094D,U+0930,U+094D
671
   * With chandas.ttf
672
   * https://github.com/harfbuzz/harfbuzz/issues/1071
673
   */
674
225k
  if (indic_plan->is_old_spec)
675
146k
  {
676
146k
    bool disallow_double_halants = buffer->props.script == HB_SCRIPT_KANNADA;
677
584k
    for (unsigned int i = base + 1; i < end; i++)
678
441k
      if (info[i].indic_category() == I_Cat(H))
679
3.07k
      {
680
3.07k
  unsigned int j;
681
5.93k
  for (j = end - 1; j > i; j--)
682
2.97k
    if (is_consonant (info[j]) ||
683
2.97k
        (disallow_double_halants && info[j].indic_category() == I_Cat(H)))
684
127
      break;
685
3.07k
  if (info[j].indic_category() != I_Cat(H) && j > i) {
686
    /* Move Halant to after last consonant. */
687
2
    hb_glyph_info_t t = info[i];
688
2
    memmove (&info[i], &info[i + 1], (j - i) * sizeof (info[0]));
689
2
    info[j] = t;
690
2
  }
691
3.07k
  break;
692
3.07k
      }
693
146k
  }
694
695
  /* Attach misc marks to previous char to move with them. */
696
225k
  {
697
225k
    indic_position_t last_pos = POS_START;
698
1.71M
    for (unsigned int i = start; i < end; i++)
699
1.48M
    {
700
1.48M
      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)))))
701
76.1k
      {
702
76.1k
  info[i].indic_position() = last_pos;
703
76.1k
  if (unlikely (info[i].indic_category() == I_Cat(H) &&
704
76.1k
          info[i].indic_position() == POS_PRE_M))
705
1.03k
  {
706
    /*
707
     * Uniscribe doesn't move the Halant with Left Matra.
708
     * TEST: U+092B,U+093F,U+094D
709
     * We follow.
710
     */
711
3.68k
    for (unsigned int j = i; j > start; j--)
712
3.14k
      if (info[j - 1].indic_position() != POS_PRE_M) {
713
491
        info[i].indic_position() = info[j - 1].indic_position();
714
491
        break;
715
491
      }
716
1.03k
  }
717
1.40M
      } else if (info[i].indic_position() != POS_SMVD) {
718
1.39M
  if (info[i].indic_category() == I_Cat(MPst) &&
719
1.39M
      i > start && info[i - 1].indic_category() == I_Cat(SM))
720
42
    info[i - 1].indic_position() = info[i].indic_position();
721
1.39M
  last_pos = (indic_position_t) info[i].indic_position();
722
1.39M
      }
723
1.48M
    }
724
225k
  }
725
  /* For post-base consonants let them own anything before them
726
   * since the last consonant or matra. */
727
225k
  {
728
225k
    unsigned int last = base;
729
802k
    for (unsigned int i = base + 1; i < end; i++)
730
577k
      if (is_consonant (info[i]))
731
1.17k
      {
732
1.20k
  for (unsigned int j = last + 1; j < i; j++)
733
28
    if (info[j].indic_position() < POS_SMVD)
734
1.17k
      info[j].indic_position() = info[i].indic_position();
735
1.17k
  last = i;
736
576k
      } else if (FLAG_UNSAFE (info[i].indic_category()) & (FLAG (I_Cat(M)) | FLAG (I_Cat(MPst))))
737
117k
  last = i;
738
225k
  }
739
740
741
225k
  {
742
    /* Use syllable() for sort accounting temporarily. */
743
225k
    unsigned int syllable = info[start].syllable();
744
1.71M
    for (unsigned int i = start; i < end; i++)
745
1.48M
      info[i].syllable() = i - start;
746
747
    /* Sit tight, rock 'n roll! */
748
225k
    hb_stable_sort (info + start, end - start, compare_indic_order);
749
750
    /* Find base again; also flip left-matra sequence. */
751
225k
    unsigned first_left_matra = end;
752
225k
    unsigned last_left_matra = end;
753
225k
    base = end;
754
1.06M
    for (unsigned int i = start; i < end; i++)
755
1.01M
    {
756
1.01M
      if (info[i].indic_position() == POS_BASE_C)
757
166k
      {
758
166k
  base = i;
759
166k
  break;
760
166k
      }
761
843k
      else if (info[i].indic_position() == POS_PRE_M)
762
191k
      {
763
191k
        if (first_left_matra == end)
764
4.42k
    first_left_matra = i;
765
191k
  last_left_matra = i;
766
191k
      }
767
1.01M
    }
768
    /* https://github.com/harfbuzz/harfbuzz/issues/3863 */
769
225k
    if (first_left_matra < last_left_matra)
770
1.79k
    {
771
      /* No need to merge clusters, handled later. */
772
1.79k
      buffer->reverse_range (first_left_matra, last_left_matra + 1);
773
      /* Reverse back nuktas, etc. */
774
1.79k
      unsigned i = first_left_matra;
775
190k
      for (unsigned j = i; j <= last_left_matra; j++)
776
188k
  if (FLAG_UNSAFE (info[j].indic_category()) & (FLAG (I_Cat(M)) | FLAG (I_Cat(MPst))))
777
187k
  {
778
187k
    buffer->reverse_range (i, j + 1);
779
187k
    i = j + 1;
780
187k
  }
781
1.79k
    }
782
783
    /* Things are out-of-control for post base positions, they may shuffle
784
     * around like crazy.  In old-spec mode, we move halants around, so in
785
     * that case merge all clusters after base.  Otherwise, check the sort
786
     * order and merge as needed.
787
     * For pre-base stuff, we handle cluster issues in final reordering.
788
     *
789
     * We could use buffer->sort() for this, if there was no special
790
     * reordering of pre-base stuff happening later...
791
     * We don't want to merge_clusters all of that, which buffer->sort()
792
     * would.  Here's a concrete example:
793
     *
794
     * Assume there's a pre-base consonant and explicit Halant before base,
795
     * followed by a prebase-reordering (left) Matra:
796
     *
797
     *   C,H,ZWNJ,B,M
798
     *
799
     * At this point in reordering we would have:
800
     *
801
     *   M,C,H,ZWNJ,B
802
     *
803
     * whereas in final reordering we will bring the Matra closer to Base:
804
     *
805
     *   C,H,ZWNJ,M,B
806
     *
807
     * That's why we don't want to merge-clusters anything before the Base
808
     * at this point.  But if something moved from after Base to before it,
809
     * we should merge clusters from base to them.  In final-reordering, we
810
     * only move things around before base, and merge-clusters up to base.
811
     * These two merge-clusters from the two sides of base will interlock
812
     * to merge things correctly.  See:
813
     * https://github.com/harfbuzz/harfbuzz/issues/2272
814
     */
815
225k
    if (indic_plan->is_old_spec || end - start > 127)
816
146k
      buffer->merge_clusters (base, end);
817
78.7k
    else
818
78.7k
    {
819
      /* Note!  syllable() is a one-byte field. */
820
139k
      for (unsigned int i = base; i < end; i++)
821
60.2k
  if (info[i].syllable() != 255)
822
60.1k
  {
823
60.1k
    unsigned int min = i;
824
60.1k
    unsigned int max = i;
825
60.1k
    unsigned int j = start + info[i].syllable();
826
60.4k
    while (j != i)
827
337
    {
828
337
      min = hb_min (min, j);
829
337
      max = hb_max (max, j);
830
337
      unsigned int next = start + info[j].syllable();
831
337
      info[j].syllable() = 255; /* So we don't process j later again. */
832
337
      j = next;
833
337
    }
834
60.1k
    buffer->merge_clusters (hb_max (base, min), max + 1);
835
60.1k
  }
836
78.7k
    }
837
838
    /* Put syllable back in. */
839
1.71M
    for (unsigned int i = start; i < end; i++)
840
1.48M
      info[i].syllable() = syllable;
841
225k
  }
842
843
  /* Setup masks now */
844
845
225k
  {
846
225k
    hb_mask_t mask;
847
848
    /* Reph */
849
237k
    for (unsigned int i = start; i < end && info[i].indic_position() == POS_RA_TO_BECOME_REPH; i++)
850
12.6k
      info[i].mask |= indic_plan->mask_array[INDIC_RPHF];
851
852
    /* Pre-base */
853
225k
    mask = indic_plan->mask_array[INDIC_HALF];
854
225k
    if (!indic_plan->is_old_spec &&
855
225k
  indic_plan->config->blwf_mode == BLWF_MODE_PRE_AND_POST)
856
78.8k
      mask |= indic_plan->mask_array[INDIC_BLWF];
857
1.06M
    for (unsigned int i = start; i < base; i++)
858
843k
      info[i].mask  |= mask;
859
    /* Base */
860
225k
    mask = 0;
861
225k
    if (base < end)
862
166k
      info[base].mask |= mask;
863
    /* Post-base */
864
225k
    mask = indic_plan->mask_array[INDIC_BLWF] |
865
225k
     indic_plan->mask_array[INDIC_ABVF] |
866
225k
     indic_plan->mask_array[INDIC_PSTF];
867
699k
    for (unsigned int i = base + 1; i < end; i++)
868
474k
      info[i].mask  |= mask;
869
225k
  }
870
871
225k
  if (indic_plan->is_old_spec &&
872
225k
      buffer->props.script == HB_SCRIPT_DEVANAGARI)
873
29.8k
  {
874
    /* Old-spec eye-lash Ra needs special handling.  From the
875
     * spec:
876
     *
877
     * "The feature 'below-base form' is applied to consonants
878
     * having below-base forms and following the base consonant.
879
     * The exception is vattu, which may appear below half forms
880
     * as well as below the base glyph. The feature 'below-base
881
     * form' will be applied to all such occurrences of Ra as well."
882
     *
883
     * Test case: U+0924,U+094D,U+0930,U+094d,U+0915
884
     * with Sanskrit 2003 font.
885
     *
886
     * However, note that Ra,Halant,ZWJ is the correct way to
887
     * request eyelash form of Ra, so we wouldbn't inhibit it
888
     * in that sequence.
889
     *
890
     * Test case: U+0924,U+094D,U+0930,U+094d,U+200D,U+0915
891
     */
892
46.1k
    for (unsigned int i = start; i + 1 < base; i++)
893
16.2k
      if (info[i  ].indic_category() == I_Cat(Ra) &&
894
16.2k
    info[i+1].indic_category() == I_Cat(H)  &&
895
16.2k
    (i + 2 == base ||
896
609
     info[i+2].indic_category() != I_Cat(ZWJ)))
897
513
      {
898
513
  info[i  ].mask |= indic_plan->mask_array[INDIC_BLWF];
899
513
  info[i+1].mask |= indic_plan->mask_array[INDIC_BLWF];
900
513
      }
901
29.8k
  }
902
903
225k
  unsigned int pref_len = 2;
904
225k
  if (indic_plan->mask_array[INDIC_PREF] && base + pref_len < end)
905
4.97k
  {
906
    /* Find a Halant,Ra sequence and mark it for pre-base-reordering processing. */
907
246k
    for (unsigned int i = base + 1; i + pref_len - 1 < end; i++) {
908
242k
      hb_codepoint_t glyphs[2];
909
727k
      for (unsigned int j = 0; j < pref_len; j++)
910
484k
  glyphs[j] = info[i + j].codepoint;
911
242k
      if (indic_plan->pref.would_substitute (glyphs, pref_len, face))
912
1.28k
      {
913
3.85k
  for (unsigned int j = 0; j < pref_len; j++)
914
2.57k
    info[i++].mask |= indic_plan->mask_array[INDIC_PREF];
915
1.28k
  break;
916
1.28k
      }
917
242k
    }
918
4.97k
  }
919
920
  /* Apply ZWJ/ZWNJ effects */
921
1.48M
  for (unsigned int i = start + 1; i < end; i++)
922
1.26M
    if (is_joiner (info[i])) {
923
12.1k
      bool non_joiner = info[i].indic_category() == I_Cat(ZWNJ);
924
12.1k
      unsigned int j = i;
925
926
3.34M
      do {
927
3.34M
  j--;
928
929
  /* ZWJ/ZWNJ should disable CJCT.  They do that by simply
930
   * being there, since we don't skip them for the CJCT
931
   * feature (ie. F_MANUAL_ZWJ) */
932
933
  /* A ZWNJ disables HALF. */
934
3.34M
  if (non_joiner)
935
102k
    info[j].mask &= ~indic_plan->mask_array[INDIC_HALF];
936
937
3.34M
      } while (j > start && !is_consonant (info[j]));
938
12.1k
    }
939
225k
}
940
941
static void
942
initial_reordering_standalone_cluster (const hb_ot_shape_plan_t *plan,
943
               hb_face_t *face,
944
               hb_buffer_t *buffer,
945
               unsigned int start, unsigned int end)
946
160k
{
947
  /* We treat placeholder/dotted-circle as if they are consonants, so we
948
   * should just chain.  Only if not in compatibility mode that is... */
949
950
160k
  const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
951
160k
  if (indic_plan->uniscribe_bug_compatible)
952
0
  {
953
    /* For dotted-circle, this is what Uniscribe does:
954
     * If dotted-circle is the last glyph, it just does nothing.
955
     * Ie. It doesn't form Reph. */
956
0
    if (buffer->info[end - 1].indic_category() == I_Cat(DOTTEDCIRCLE))
957
0
      return;
958
0
  }
959
960
160k
  initial_reordering_consonant_syllable (plan, face, buffer, start, end);
961
160k
}
962
963
static void
964
initial_reordering_syllable_indic (const hb_ot_shape_plan_t *plan,
965
           hb_face_t *face,
966
           hb_buffer_t *buffer,
967
           unsigned int start, unsigned int end)
968
1.80M
{
969
1.80M
  indic_syllable_type_t syllable_type = (indic_syllable_type_t) (buffer->info[start].syllable() & 0x0F);
970
1.80M
  switch (syllable_type)
971
1.80M
  {
972
34.8k
    case indic_vowel_syllable: /* We made the vowels look like consonants.  So let's call the consonant logic! */
973
64.4k
    case indic_consonant_syllable:
974
64.4k
     initial_reordering_consonant_syllable (plan, face, buffer, start, end);
975
64.4k
     break;
976
977
106k
    case indic_broken_cluster: /* We already inserted dotted-circles, so just call the standalone_cluster. */
978
160k
    case indic_standalone_cluster:
979
160k
     initial_reordering_standalone_cluster (plan, face, buffer, start, end);
980
160k
     break;
981
982
466
    case indic_symbol_cluster:
983
1.57M
    case indic_non_indic_cluster:
984
1.57M
      break;
985
1.80M
  }
986
1.80M
}
987
988
static bool
989
initial_reordering_indic (const hb_ot_shape_plan_t *plan,
990
        hb_font_t *font,
991
        hb_buffer_t *buffer)
992
19.8k
{
993
19.8k
  bool ret = false;
994
19.8k
  if (!buffer->message (font, "start reordering indic initial"))
995
0
    return ret;
996
997
19.8k
  update_consonant_positions_indic (plan, font, buffer);
998
19.8k
  if (hb_syllabic_insert_dotted_circles (font, buffer,
999
19.8k
           indic_broken_cluster,
1000
19.8k
           I_Cat(DOTTEDCIRCLE),
1001
19.8k
           I_Cat(Repha),
1002
19.8k
           POS_END))
1003
929
    ret = true;
1004
1005
19.8k
  foreach_syllable (buffer, start, end)
1006
1.80M
    initial_reordering_syllable_indic (plan, font->face, buffer, start, end);
1007
1008
19.8k
  (void) buffer->message (font, "end reordering indic initial");
1009
1010
19.8k
  return ret;
1011
19.8k
}
1012
1013
static void
1014
final_reordering_syllable_indic (const hb_ot_shape_plan_t *plan,
1015
         hb_buffer_t *buffer,
1016
         unsigned int start, unsigned int end)
1017
1.80M
{
1018
1.80M
  const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
1019
1.80M
  hb_glyph_info_t *info = buffer->info;
1020
1021
1022
  /* This function relies heavily on halant glyphs.  Lots of ligation
1023
   * and possibly multiple substitutions happened prior to this
1024
   * phase, and that might have messed up our properties.  Recover
1025
   * from a particular case of that where we're fairly sure that a
1026
   * class of I_Cat(H) is desired but has been lost. */
1027
  /* We don't call load_virama_glyph(), since we know it's already
1028
   * loaded. */
1029
1.80M
  hb_codepoint_t virama_glyph = indic_plan->virama_glyph;
1030
1.80M
  if (virama_glyph)
1031
224k
  {
1032
3.29M
    for (unsigned int i = start; i < end; i++)
1033
3.07M
      if (info[i].codepoint == virama_glyph &&
1034
3.07M
    _hb_glyph_info_ligated (&info[i]) &&
1035
3.07M
    _hb_glyph_info_multiplied (&info[i]))
1036
1.88k
      {
1037
  /* This will make sure that this glyph passes is_halant() test. */
1038
1.88k
  info[i].indic_category() = I_Cat(H);
1039
1.88k
  _hb_glyph_info_clear_ligated_and_multiplied (&info[i]);
1040
1.88k
      }
1041
224k
  }
1042
1043
1044
  /* 4. Final reordering:
1045
   *
1046
   * After the localized forms and basic shaping forms GSUB features have been
1047
   * applied (see below), the shaping engine performs some final glyph
1048
   * reordering before applying all the remaining font features to the entire
1049
   * syllable.
1050
   */
1051
1052
1.80M
  bool try_pref = !!indic_plan->mask_array[INDIC_PREF];
1053
1054
  /* Find base again */
1055
1.80M
  unsigned int base;
1056
2.85M
  for (base = start; base < end; base++)
1057
2.79M
    if (info[base].indic_position() >= POS_BASE_C)
1058
1.74M
    {
1059
1.74M
      if (try_pref && base + 1 < end)
1060
51.0k
      {
1061
5.87M
  for (unsigned int i = base + 1; i < end; i++)
1062
5.82M
    if ((info[i].mask & indic_plan->mask_array[INDIC_PREF]) != 0)
1063
1.28k
    {
1064
1.28k
      if (!(_hb_glyph_info_substituted (&info[i]) &&
1065
1.28k
      _hb_glyph_info_ligated_and_didnt_multiply (&info[i])))
1066
1.28k
      {
1067
        /* Ok, this was a 'pref' candidate but didn't form any.
1068
         * Base is around here... */
1069
1.28k
        base = i;
1070
1.28k
        while (base < end && is_halant (info[base]))
1071
5
    base++;
1072
1.28k
        info[base].indic_position() = POS_BASE_C;
1073
1074
1.28k
        try_pref = false;
1075
1.28k
      }
1076
1.28k
      break;
1077
1.28k
    }
1078
51.0k
      }
1079
      /* For Malayalam, skip over unformed below- (but NOT post-) forms. */
1080
1.74M
      if (buffer->props.script == HB_SCRIPT_MALAYALAM)
1081
1.21M
      {
1082
1.25M
  for (unsigned int i = base + 1; i < end; i++)
1083
100k
  {
1084
477k
    while (i < end && is_joiner (info[i]))
1085
377k
      i++;
1086
100k
    if (i == end || !is_halant (info[i]))
1087
52.1k
      break;
1088
47.9k
    i++; /* Skip halant. */
1089
48.0k
    while (i < end && is_joiner (info[i]))
1090
77
      i++;
1091
47.9k
    if (i < end && is_consonant (info[i]) && info[i].indic_position() == POS_BELOW_C)
1092
10
    {
1093
10
      base = i;
1094
10
      info[base].indic_position() = POS_BASE_C;
1095
10
    }
1096
47.9k
  }
1097
1.21M
      }
1098
1099
1.74M
      if (start < base && info[base].indic_position() > POS_BASE_C)
1100
333
  base--;
1101
1.74M
      break;
1102
1.74M
    }
1103
1.80M
  if (base == end && start < base &&
1104
1.80M
      is_one_of (info[base - 1], FLAG (I_Cat(ZWJ))))
1105
692
    base--;
1106
1.80M
  if (base < end)
1107
1.74M
    while (start < base &&
1108
1.74M
     is_one_of (info[base], (FLAG (I_Cat(N)) | FLAG (I_Cat(H)))))
1109
349
      base--;
1110
1111
1112
  /*   o Reorder matras:
1113
   *
1114
   *     If a pre-base matra character had been reordered before applying basic
1115
   *     features, the glyph can be moved closer to the main consonant based on
1116
   *     whether half-forms had been formed. Actual position for the matra is
1117
   *     defined as “after last standalone halant glyph, after initial matra
1118
   *     position and before the main consonant”. If ZWJ or ZWNJ follow this
1119
   *     halant, position is moved after it.
1120
   *
1121
   * IMPLEMENTATION NOTES:
1122
   *
1123
   * It looks like the last sentence is wrong.  Testing, with Windows 7 Uniscribe
1124
   * and Devanagari shows that the behavior is best described as:
1125
   *
1126
   * "If ZWJ follows this halant, matra is NOT repositioned after this halant.
1127
   *  If ZWNJ follows this halant, position is moved after it."
1128
   *
1129
   * Test case, with Adobe Devanagari or Nirmala UI:
1130
   *
1131
   *   U+091F,U+094D,U+200C,U+092F,U+093F
1132
   *   (Matra moves to the middle, after ZWNJ.)
1133
   *
1134
   *   U+091F,U+094D,U+200D,U+092F,U+093F
1135
   *   (Matra does NOT move, stays to the left.)
1136
   *
1137
   * https://github.com/harfbuzz/harfbuzz/issues/1070
1138
   */
1139
1140
1.80M
  if (start + 1 < end && start < base) /* Otherwise there can't be any pre-base matra characters. */
1141
36.9k
  {
1142
    /* If we lost track of base, alas, position before last thingy. */
1143
36.9k
    unsigned int new_pos = base == end ? base - 2 : base - 1;
1144
1145
    /* Malayalam / Tamil do not have "half" forms or explicit virama forms.
1146
     * The glyphs formed by 'half' are Chillus or ligated explicit viramas.
1147
     * We want to position matra after them.
1148
     */
1149
36.9k
    if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL)
1150
9.89k
    {
1151
10.1k
    search:
1152
12.6k
      while (new_pos > start &&
1153
12.6k
       !(is_one_of (info[new_pos], (FLAG (I_Cat(M)) | FLAG (I_Cat(MPst)) | FLAG (I_Cat(H))))))
1154
2.42k
  new_pos--;
1155
1156
      /* If we found no Halant we are done.
1157
       * Otherwise only proceed if the Halant does
1158
       * not belong to the Matra itself! */
1159
10.1k
      if (is_halant (info[new_pos]) &&
1160
10.1k
    info[new_pos].indic_position() != POS_PRE_M)
1161
1.48k
      {
1162
#if 0 // See comment above
1163
  /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */
1164
  if (new_pos + 1 < end && is_joiner (info[new_pos + 1]))
1165
    new_pos++;
1166
#endif
1167
1.48k
  if (new_pos + 1 < end)
1168
1.48k
  {
1169
    /* -> If ZWJ follows this halant, matra is NOT repositioned after this halant. */
1170
1.48k
    if (info[new_pos + 1].indic_category() == I_Cat(ZWJ))
1171
484
    {
1172
      /* Keep searching. */
1173
484
      if (new_pos > start)
1174
295
      {
1175
295
        new_pos--;
1176
295
        goto search;
1177
295
      }
1178
484
    }
1179
    /* -> If ZWNJ follows this halant, position is moved after it.
1180
     *
1181
     * IMPLEMENTATION NOTES:
1182
     *
1183
     * This is taken care of by the state-machine. A Halant,ZWNJ is a terminating
1184
     * sequence for a consonant syllable; any pre-base matras occurring after it
1185
     * will belong to the subsequent syllable.
1186
     */
1187
1.48k
  }
1188
1.48k
      }
1189
8.70k
      else
1190
8.70k
  new_pos = start; /* No move. */
1191
10.1k
    }
1192
1193
36.9k
    if (start < new_pos && info[new_pos].indic_position () != POS_PRE_M)
1194
9.07k
    {
1195
      /* Now go see if there's actually any matras... */
1196
769k
      for (unsigned int i = new_pos; i > start; i--)
1197
760k
  if (info[i - 1].indic_position () == POS_PRE_M)
1198
13.2k
  {
1199
13.2k
    unsigned int old_pos = i - 1;
1200
13.2k
    if (old_pos < base && base <= new_pos) /* Shouldn't actually happen. */
1201
0
      base--;
1202
1203
13.2k
    hb_glyph_info_t tmp = info[old_pos];
1204
13.2k
    memmove (&info[old_pos], &info[old_pos + 1], (new_pos - old_pos) * sizeof (info[0]));
1205
13.2k
    info[new_pos] = tmp;
1206
1207
    /* Note: this merge_clusters() is intentionally *after* the reordering.
1208
     * Indic matra reordering is special and tricky... */
1209
13.2k
    buffer->merge_clusters (new_pos, hb_min (end, base + 1));
1210
1211
13.2k
    new_pos--;
1212
13.2k
  }
1213
27.8k
    } else {
1214
76.7k
      for (unsigned int i = start; i < base; i++)
1215
52.3k
  if (info[i].indic_position () == POS_PRE_M) {
1216
3.40k
    buffer->merge_clusters (i, hb_min (end, base + 1));
1217
3.40k
    break;
1218
3.40k
  }
1219
27.8k
    }
1220
36.9k
  }
1221
1222
1223
  /*   o Reorder reph:
1224
   *
1225
   *     Reph’s original position is always at the beginning of the syllable,
1226
   *     (i.e. it is not reordered at the character reordering stage). However,
1227
   *     it will be reordered according to the basic-forms shaping results.
1228
   *     Possible positions for reph, depending on the script, are; after main,
1229
   *     before post-base consonant forms, and after post-base consonant forms.
1230
   */
1231
1232
  /* Two cases:
1233
   *
1234
   * - If repha is encoded as a sequence of characters (Ra,H or Ra,H,ZWJ), then
1235
   *   we should only move it if the sequence ligated to the repha form.
1236
   *
1237
   * - If repha is encoded separately and in the logical position, we should only
1238
   *   move it if it did NOT ligate.  If it ligated, it's probably the font trying
1239
   *   to make it work without the reordering.
1240
   */
1241
1.80M
  if (start + 1 < end &&
1242
1.80M
      info[start].indic_position() == POS_RA_TO_BECOME_REPH &&
1243
1.80M
      ((info[start].indic_category() == I_Cat(Repha)) ^
1244
12.1k
       _hb_glyph_info_ligated_and_didnt_multiply (&info[start])))
1245
12.0k
  {
1246
12.0k
    unsigned int new_reph_pos;
1247
12.0k
    reph_position_t reph_pos = indic_plan->config->reph_pos;
1248
1249
    /*       1. If reph should be positioned after post-base consonant forms,
1250
     *          proceed to step 5.
1251
     */
1252
12.0k
    if (reph_pos == REPH_POS_AFTER_POST)
1253
0
    {
1254
0
      goto reph_step_5;
1255
0
    }
1256
1257
    /*       2. If the reph repositioning class is not after post-base: target
1258
     *          position is after the first explicit halant glyph between the
1259
     *          first post-reph consonant and last main consonant. If ZWJ or ZWNJ
1260
     *          are following this halant, position is moved after it. If such
1261
     *          position is found, this is the target position. Otherwise,
1262
     *          proceed to the next step.
1263
     *
1264
     *          Note: in old-implementation fonts, where classifications were
1265
     *          fixed in shaping engine, there was no case where reph position
1266
     *          will be found on this step.
1267
     */
1268
12.0k
    {
1269
12.0k
      new_reph_pos = start + 1;
1270
198k
      while (new_reph_pos < base && !is_halant (info[new_reph_pos]))
1271
186k
  new_reph_pos++;
1272
1273
12.0k
      if (new_reph_pos < base && is_halant (info[new_reph_pos]))
1274
209
      {
1275
  /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */
1276
209
  if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1]))
1277
0
    new_reph_pos++;
1278
209
  goto reph_move;
1279
209
      }
1280
12.0k
    }
1281
1282
    /*       3. If reph should be repositioned after the main consonant: find the
1283
     *          first consonant not ligated with main, or find the first
1284
     *          consonant that is not a potential pre-base-reordering Ra.
1285
     */
1286
11.8k
    if (reph_pos == REPH_POS_AFTER_MAIN)
1287
11.8k
    {
1288
11.8k
      new_reph_pos = base;
1289
108k
      while (new_reph_pos + 1 < end && info[new_reph_pos + 1].indic_position() <= POS_AFTER_MAIN)
1290
96.1k
  new_reph_pos++;
1291
11.8k
      if (new_reph_pos < end)
1292
11.7k
  goto reph_move;
1293
11.8k
    }
1294
1295
    /*       4. If reph should be positioned before post-base consonant, find
1296
     *          first post-base classified consonant not ligated with main. If no
1297
     *          consonant is found, the target position should be before the
1298
     *          first matra, syllable modifier sign or vedic sign.
1299
     */
1300
    /* This is our take on what step 4 is trying to say (and failing, BADLY). */
1301
76
    if (reph_pos == REPH_POS_AFTER_SUB)
1302
0
    {
1303
0
      new_reph_pos = base;
1304
0
      while (new_reph_pos + 1 < end &&
1305
0
       !( FLAG_UNSAFE (info[new_reph_pos + 1].indic_position()) & (FLAG (POS_POST_C) | FLAG (POS_AFTER_POST) | FLAG (POS_SMVD))))
1306
0
  new_reph_pos++;
1307
0
      if (new_reph_pos < end)
1308
0
  goto reph_move;
1309
0
    }
1310
1311
    /*       5. If no consonant is found in steps 3 or 4, move reph to a position
1312
     *          immediately before the first post-base matra, syllable modifier
1313
     *          sign or vedic sign that has a reordering class after the intended
1314
     *          reph position. For example, if the reordering position for reph
1315
     *          is post-main, it will skip above-base matras that also have a
1316
     *          post-main position.
1317
     */
1318
76
    reph_step_5:
1319
76
    {
1320
      /* Copied from step 2. */
1321
76
      new_reph_pos = start + 1;
1322
1.03k
      while (new_reph_pos < base && !is_halant (info[new_reph_pos]))
1323
956
  new_reph_pos++;
1324
1325
76
      if (new_reph_pos < base && is_halant (info[new_reph_pos]))
1326
0
      {
1327
  /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */
1328
0
  if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1]))
1329
0
    new_reph_pos++;
1330
0
  goto reph_move;
1331
0
      }
1332
76
    }
1333
    /* See https://github.com/harfbuzz/harfbuzz/issues/2298#issuecomment-615318654 */
1334
1335
    /*       6. Otherwise, reorder reph to the end of the syllable.
1336
     */
1337
76
    {
1338
76
      new_reph_pos = end - 1;
1339
76
      while (new_reph_pos > start && info[new_reph_pos].indic_position() == POS_SMVD)
1340
0
  new_reph_pos--;
1341
1342
      /*
1343
       * If the Reph is to be ending up after a Matra,Halant sequence,
1344
       * position it before that Halant so it can interact with the Matra.
1345
       * However, if it's a plain Consonant,Halant we shouldn't do that.
1346
       * Uniscribe doesn't do this.
1347
       * TEST: U+0930,U+094D,U+0915,U+094B,U+094D
1348
       */
1349
76
      if (!indic_plan->uniscribe_bug_compatible &&
1350
76
    unlikely (is_halant (info[new_reph_pos])))
1351
0
      {
1352
0
  for (unsigned int i = base + 1; i < new_reph_pos; i++)
1353
0
    if (FLAG_UNSAFE (info[i].indic_category()) & (FLAG (I_Cat(M)) | FLAG (I_Cat(MPst))))
1354
0
    {
1355
      /* Ok, got it. */
1356
0
      new_reph_pos--;
1357
0
    }
1358
0
      }
1359
1360
76
      goto reph_move;
1361
76
    }
1362
1363
12.0k
    reph_move:
1364
12.0k
    {
1365
      /* Move */
1366
12.0k
      buffer->merge_clusters (start, new_reph_pos + 1);
1367
12.0k
      hb_glyph_info_t reph = info[start];
1368
12.0k
      memmove (&info[start], &info[start + 1], (new_reph_pos - start) * sizeof (info[0]));
1369
12.0k
      info[new_reph_pos] = reph;
1370
1371
12.0k
      if (start < base && base <= new_reph_pos)
1372
11.7k
  base--;
1373
12.0k
    }
1374
12.0k
  }
1375
1376
1377
  /*   o Reorder pre-base-reordering consonants:
1378
   *
1379
   *     If a pre-base-reordering consonant is found, reorder it according to
1380
   *     the following rules:
1381
   */
1382
1383
1.80M
  if (try_pref && base + 1 < end) /* Otherwise there can't be any pre-base-reordering Ra. */
1384
56.4k
  {
1385
5.87M
    for (unsigned int i = base + 1; i < end; i++)
1386
5.82M
      if ((info[i].mask & indic_plan->mask_array[INDIC_PREF]) != 0)
1387
5
      {
1388
  /*       1. Only reorder a glyph produced by substitution during application
1389
   *          of the <pref> feature. (Note that a font may shape a Ra consonant with
1390
   *          the feature generally but block it in certain contexts.)
1391
   */
1392
  /* Note: We just check that something got substituted.  We don't check that
1393
   * the <pref> feature actually did it...
1394
   *
1395
   * Reorder pref only if it ligated. */
1396
5
  if (_hb_glyph_info_ligated_and_didnt_multiply (&info[i]))
1397
5
  {
1398
    /*
1399
     *       2. Try to find a target position the same way as for pre-base matra.
1400
     *          If it is found, reorder pre-base consonant glyph.
1401
     *
1402
     *       3. If position is not found, reorder immediately before main
1403
     *          consonant.
1404
     */
1405
1406
5
    unsigned int new_pos = base;
1407
    /* Malayalam / Tamil do not have "half" forms or explicit virama forms.
1408
     * The glyphs formed by 'half' are Chillus or ligated explicit viramas.
1409
     * We want to position matra after them.
1410
     */
1411
5
    if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL)
1412
2
    {
1413
2
      while (new_pos > start &&
1414
2
       !(is_one_of (info[new_pos - 1], FLAG (I_Cat(M)) | FLAG (I_Cat(MPst)) | FLAG (I_Cat(H)))))
1415
0
        new_pos--;
1416
2
    }
1417
1418
5
    if (new_pos > start && is_halant (info[new_pos - 1]))
1419
0
    {
1420
      /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */
1421
0
      if (new_pos < end && is_joiner (info[new_pos]))
1422
0
        new_pos++;
1423
0
    }
1424
1425
5
    {
1426
5
      unsigned int old_pos = i;
1427
1428
5
      buffer->merge_clusters (new_pos, old_pos + 1);
1429
5
      hb_glyph_info_t tmp = info[old_pos];
1430
5
      memmove (&info[new_pos + 1], &info[new_pos], (old_pos - new_pos) * sizeof (info[0]));
1431
5
      info[new_pos] = tmp;
1432
1433
5
      if (new_pos <= base && base < old_pos)
1434
5
        base++;
1435
5
    }
1436
5
  }
1437
1438
5
  break;
1439
5
      }
1440
56.4k
  }
1441
1442
1443
  /* Apply 'init' to the Left Matra if it's a word start. */
1444
1.80M
  if (info[start].indic_position () == POS_PRE_M)
1445
3.85k
  {
1446
3.85k
    if (!start ||
1447
3.85k
  !(FLAG_UNSAFE (_hb_glyph_info_get_general_category (&info[start - 1])) &
1448
3.33k
   FLAG_RANGE (HB_UNICODE_GENERAL_CATEGORY_FORMAT, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)))
1449
1.85k
      info[start].mask |= indic_plan->mask_array[INDIC_INIT];
1450
2.00k
    else
1451
2.00k
      buffer->unsafe_to_break (start - 1, start + 1);
1452
3.85k
  }
1453
1454
1455
  /*
1456
   * Finish off the clusters and go home!
1457
   */
1458
1.80M
  if (indic_plan->uniscribe_bug_compatible)
1459
0
  {
1460
0
    switch ((hb_tag_t) plan->props.script)
1461
0
    {
1462
0
      case HB_SCRIPT_TAMIL:
1463
0
  break;
1464
1465
0
      default:
1466
  /* Uniscribe merges the entire syllable into a single cluster... Except for Tamil.
1467
   * This means, half forms are submerged into the main consonant's cluster.
1468
   * This is unnecessary, and makes cursor positioning harder, but that's what
1469
   * Uniscribe does. */
1470
0
  buffer->merge_clusters (start, end);
1471
0
  break;
1472
0
    }
1473
0
  }
1474
1.80M
}
1475
1476
1477
static bool
1478
final_reordering_indic (const hb_ot_shape_plan_t *plan,
1479
      hb_font_t *font HB_UNUSED,
1480
      hb_buffer_t *buffer)
1481
19.7k
{
1482
19.7k
  unsigned int count = buffer->len;
1483
19.7k
  if (unlikely (!count)) return false;
1484
1485
19.6k
  if (buffer->message (font, "start reordering indic final")) {
1486
19.6k
    foreach_syllable (buffer, start, end)
1487
1.80M
      final_reordering_syllable_indic (plan, buffer, start, end);
1488
19.6k
    (void) buffer->message (font, "end reordering indic final");
1489
19.6k
  }
1490
1491
19.6k
  HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category);
1492
19.6k
  HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position);
1493
1494
19.6k
  return false;
1495
19.7k
}
1496
1497
1498
static void
1499
preprocess_text_indic (const hb_ot_shape_plan_t *plan,
1500
           hb_buffer_t              *buffer,
1501
           hb_font_t                *font)
1502
20.0k
{
1503
20.0k
  const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
1504
20.0k
  if (!indic_plan->uniscribe_bug_compatible)
1505
20.0k
    _hb_preprocess_text_vowel_constraints (plan, buffer, font);
1506
20.0k
}
1507
1508
static bool
1509
decompose_indic (const hb_ot_shape_normalize_context_t *c,
1510
     hb_codepoint_t  ab,
1511
     hb_codepoint_t *a,
1512
     hb_codepoint_t *b)
1513
329k
{
1514
329k
  switch (ab)
1515
329k
  {
1516
    /* Don't decompose these. */
1517
1.14k
    case 0x0931u  : return false; /* DEVANAGARI LETTER RRA */
1518
    // https://github.com/harfbuzz/harfbuzz/issues/779
1519
950
    case 0x09DCu  : return false; /* BENGALI LETTER RRA */
1520
924
    case 0x09DDu  : return false; /* BENGALI LETTER RHA */
1521
806
    case 0x0B94u  : return false; /* TAMIL LETTER AU */
1522
1523
1524
    /*
1525
     * Decompose split matras that don't have Unicode decompositions.
1526
     */
1527
1528
#if 0
1529
    /* Gujarati */
1530
    /* This one has no decomposition in Unicode, but needs no decomposition either. */
1531
    /* case 0x0AC9u  : return false; */
1532
1533
    /* Oriya */
1534
    case 0x0B57u  : *a = no decomp, -> RIGHT; return true;
1535
#endif
1536
329k
  }
1537
1538
325k
  return (bool) c->unicode->decompose (ab, a, b);
1539
329k
}
1540
1541
static bool
1542
compose_indic (const hb_ot_shape_normalize_context_t *c,
1543
         hb_codepoint_t  a,
1544
         hb_codepoint_t  b,
1545
         hb_codepoint_t *ab)
1546
62.7k
{
1547
  /* Avoid recomposing split matras. */
1548
62.7k
  if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (c->unicode->general_category (a)))
1549
19.2k
    return false;
1550
1551
  /* Composition-exclusion exceptions that we want to recompose. */
1552
43.4k
  if (a == 0x09AFu && b == 0x09BCu) { *ab = 0x09DFu; return true; }
1553
1554
43.2k
  return (bool) c->unicode->compose (a, b, ab);
1555
43.4k
}
1556
1557
1558
const hb_ot_shaper_t _hb_ot_shaper_indic =
1559
{
1560
  collect_features_indic,
1561
  override_features_indic,
1562
  data_create_indic,
1563
  data_destroy_indic,
1564
  preprocess_text_indic,
1565
  nullptr, /* postprocess_glyphs */
1566
  decompose_indic,
1567
  compose_indic,
1568
  setup_masks_indic,
1569
  nullptr, /* reorder_marks */
1570
  HB_TAG_NONE, /* gpos_tag */
1571
  HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT,
1572
  HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE,
1573
  false, /* fallback_position */
1574
};
1575
1576
1577
#endif