2 * Copyright © 2011,2012 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
24 * Google Author(s): Behdad Esfahbod
29 #ifndef HB_NO_OT_SHAPE
31 #include "hb-ot-shape-complex-indic.hh"
32 #include "hb-ot-shape-complex-indic-machine.hh"
33 #include "hb-ot-shape-complex-vowel-constraints.hh"
34 #include "hb-ot-layout.hh"
43 * Indic configurations. Note that we do not want to keep every single script-specific
44 * behavior in these tables necessarily. This should mainly be used for per-script
45 * properties that are cheaper keeping here, than in the code. Ie. if, say, one and
46 * only one script has an exception, that one script can be if'ed directly in the code,
47 * instead of adding a new flag in these structs.
50 enum base_position_t {
51 BASE_POS_LAST_SINHALA,
54 enum reph_position_t {
55 REPH_POS_AFTER_MAIN = POS_AFTER_MAIN,
56 REPH_POS_BEFORE_SUB = POS_BEFORE_SUB,
57 REPH_POS_AFTER_SUB = POS_AFTER_SUB,
58 REPH_POS_BEFORE_POST = POS_BEFORE_POST,
59 REPH_POS_AFTER_POST = POS_AFTER_POST
62 REPH_MODE_IMPLICIT, /* Reph formed out of initial Ra,H sequence. */
63 REPH_MODE_EXPLICIT, /* Reph formed out of initial Ra,H,ZWJ sequence. */
64 REPH_MODE_LOG_REPHA /* Encoded Repha character, needs reordering. */
67 BLWF_MODE_PRE_AND_POST, /* Below-forms feature applied to pre-base and post-base. */
68 BLWF_MODE_POST_ONLY /* Below-forms feature applied to post-base only. */
74 hb_codepoint_t virama;
75 base_position_t base_pos;
76 reph_position_t reph_pos;
77 reph_mode_t reph_mode;
78 blwf_mode_t blwf_mode;
81 static const indic_config_t indic_configs[] =
83 /* Default. Should be first. */
84 {HB_SCRIPT_INVALID, false, 0,BASE_POS_LAST, REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
85 {HB_SCRIPT_DEVANAGARI,true, 0x094Du,BASE_POS_LAST, REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
86 {HB_SCRIPT_BENGALI, true, 0x09CDu,BASE_POS_LAST, REPH_POS_AFTER_SUB, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
87 {HB_SCRIPT_GURMUKHI, true, 0x0A4Du,BASE_POS_LAST, REPH_POS_BEFORE_SUB, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
88 {HB_SCRIPT_GUJARATI, true, 0x0ACDu,BASE_POS_LAST, REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
89 {HB_SCRIPT_ORIYA, true, 0x0B4Du,BASE_POS_LAST, REPH_POS_AFTER_MAIN, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
90 {HB_SCRIPT_TAMIL, true, 0x0BCDu,BASE_POS_LAST, REPH_POS_AFTER_POST, REPH_MODE_IMPLICIT, BLWF_MODE_PRE_AND_POST},
91 {HB_SCRIPT_TELUGU, true, 0x0C4Du,BASE_POS_LAST, REPH_POS_AFTER_POST, REPH_MODE_EXPLICIT, BLWF_MODE_POST_ONLY},
92 {HB_SCRIPT_KANNADA, true, 0x0CCDu,BASE_POS_LAST, REPH_POS_AFTER_POST, REPH_MODE_IMPLICIT, BLWF_MODE_POST_ONLY},
93 {HB_SCRIPT_MALAYALAM, true, 0x0D4Du,BASE_POS_LAST, REPH_POS_AFTER_MAIN, REPH_MODE_LOG_REPHA,BLWF_MODE_PRE_AND_POST},
94 {HB_SCRIPT_SINHALA, false,0x0DCAu,BASE_POS_LAST_SINHALA,
95 REPH_POS_AFTER_POST, REPH_MODE_EXPLICIT, BLWF_MODE_PRE_AND_POST},
104 static const hb_ot_map_feature_t
109 * These features are applied in order, one at a time, after initial_reordering,
110 * constrained to the syllable.
112 {HB_TAG('n','u','k','t'), F_GLOBAL_MANUAL_JOINERS},
113 {HB_TAG('a','k','h','n'), F_GLOBAL_MANUAL_JOINERS},
114 {HB_TAG('r','p','h','f'), F_MANUAL_JOINERS},
115 {HB_TAG('r','k','r','f'), F_GLOBAL_MANUAL_JOINERS},
116 {HB_TAG('p','r','e','f'), F_MANUAL_JOINERS},
117 {HB_TAG('b','l','w','f'), F_MANUAL_JOINERS},
118 {HB_TAG('a','b','v','f'), F_MANUAL_JOINERS},
119 {HB_TAG('h','a','l','f'), F_MANUAL_JOINERS},
120 {HB_TAG('p','s','t','f'), F_MANUAL_JOINERS},
121 {HB_TAG('v','a','t','u'), F_GLOBAL_MANUAL_JOINERS},
122 {HB_TAG('c','j','c','t'), F_GLOBAL_MANUAL_JOINERS},
125 * These features are applied all at once, after final_reordering, constrained
127 * Default Bengali font in Windows for example has intermixed
128 * lookups for init,pres,abvs,blws features.
130 {HB_TAG('i','n','i','t'), F_MANUAL_JOINERS},
131 {HB_TAG('p','r','e','s'), F_GLOBAL_MANUAL_JOINERS},
132 {HB_TAG('a','b','v','s'), F_GLOBAL_MANUAL_JOINERS},
133 {HB_TAG('b','l','w','s'), F_GLOBAL_MANUAL_JOINERS},
134 {HB_TAG('p','s','t','s'), F_GLOBAL_MANUAL_JOINERS},
135 {HB_TAG('h','a','l','n'), F_GLOBAL_MANUAL_JOINERS},
139 * Must be in the same order as the indic_features array.
162 INDIC_BASIC_FEATURES = INDIC_INIT, /* Don't forget to update this! */
166 setup_syllables_indic (const hb_ot_shape_plan_t *plan,
168 hb_buffer_t *buffer);
170 initial_reordering_indic (const hb_ot_shape_plan_t *plan,
172 hb_buffer_t *buffer);
174 final_reordering_indic (const hb_ot_shape_plan_t *plan,
176 hb_buffer_t *buffer);
179 collect_features_indic (hb_ot_shape_planner_t *plan)
181 hb_ot_map_builder_t *map = &plan->map;
183 /* Do this before any lookups have been applied. */
184 map->add_gsub_pause (setup_syllables_indic);
186 map->enable_feature (HB_TAG('l','o','c','l'));
187 /* The Indic specs do not require ccmp, but we apply it here since if
188 * there is a use of it, it's typically at the beginning. */
189 map->enable_feature (HB_TAG('c','c','m','p'));
193 map->add_gsub_pause (initial_reordering_indic);
195 for (; i < INDIC_BASIC_FEATURES; i++) {
196 map->add_feature (indic_features[i]);
197 map->add_gsub_pause (nullptr);
200 map->add_gsub_pause (final_reordering_indic);
202 for (; i < INDIC_NUM_FEATURES; i++)
203 map->add_feature (indic_features[i]);
205 map->add_gsub_pause (_hb_clear_syllables);
209 override_features_indic (hb_ot_shape_planner_t *plan)
211 plan->map.disable_feature (HB_TAG('l','i','g','a'));
215 struct indic_shape_plan_t
217 bool load_virama_glyph (hb_font_t *font, hb_codepoint_t *pglyph) const
219 hb_codepoint_t glyph = virama_glyph.get_relaxed ();
220 if (unlikely (glyph == (hb_codepoint_t) -1))
222 if (!config->virama || !font->get_nominal_glyph (config->virama, &glyph))
224 /* Technically speaking, the spec says we should apply 'locl' to virama too.
225 * Maybe one day... */
227 /* Our get_nominal_glyph() function needs a font, so we can't get the virama glyph
228 * during shape planning... Instead, overwrite it here. */
229 virama_glyph.set_relaxed ((int) glyph);
236 const indic_config_t *config;
239 #ifndef HB_NO_UNISCRIBE_BUG_COMPATIBLE
240 bool uniscribe_bug_compatible;
242 static constexpr bool uniscribe_bug_compatible = false;
244 mutable hb_atomic_int_t virama_glyph;
246 hb_indic_would_substitute_feature_t rphf;
247 hb_indic_would_substitute_feature_t pref;
248 hb_indic_would_substitute_feature_t blwf;
249 hb_indic_would_substitute_feature_t pstf;
250 hb_indic_would_substitute_feature_t vatu;
252 hb_mask_t mask_array[INDIC_NUM_FEATURES];
256 data_create_indic (const hb_ot_shape_plan_t *plan)
258 indic_shape_plan_t *indic_plan = (indic_shape_plan_t *) hb_calloc (1, sizeof (indic_shape_plan_t));
259 if (unlikely (!indic_plan))
262 indic_plan->config = &indic_configs[0];
263 for (unsigned int i = 1; i < ARRAY_LENGTH (indic_configs); i++)
264 if (plan->props.script == indic_configs[i].script) {
265 indic_plan->config = &indic_configs[i];
269 indic_plan->is_old_spec = indic_plan->config->has_old_spec && ((plan->map.chosen_script[0] & 0x000000FFu) != '2');
270 #ifndef HB_NO_UNISCRIBE_BUG_COMPATIBLE
271 indic_plan->uniscribe_bug_compatible = hb_options ().uniscribe_bug_compatible;
273 indic_plan->virama_glyph.set_relaxed (-1);
275 /* Use zero-context would_substitute() matching for new-spec of the main
276 * Indic scripts, and scripts with one spec only, but not for old-specs.
277 * The new-spec for all dual-spec scripts says zero-context matching happens.
279 * However, testing with Malayalam shows that old and new spec both allow
280 * context. Testing with Bengali new-spec however shows that it doesn't.
281 * So, the heuristic here is the way it is. It should *only* be changed,
282 * as we discover more cases of what Windows does. DON'T TOUCH OTHERWISE.
284 bool zero_context = !indic_plan->is_old_spec && plan->props.script != HB_SCRIPT_MALAYALAM;
285 indic_plan->rphf.init (&plan->map, HB_TAG('r','p','h','f'), zero_context);
286 indic_plan->pref.init (&plan->map, HB_TAG('p','r','e','f'), zero_context);
287 indic_plan->blwf.init (&plan->map, HB_TAG('b','l','w','f'), zero_context);
288 indic_plan->pstf.init (&plan->map, HB_TAG('p','s','t','f'), zero_context);
289 indic_plan->vatu.init (&plan->map, HB_TAG('v','a','t','u'), zero_context);
291 for (unsigned int i = 0; i < ARRAY_LENGTH (indic_plan->mask_array); i++)
292 indic_plan->mask_array[i] = (indic_features[i].flags & F_GLOBAL) ?
293 0 : plan->map.get_1_mask (indic_features[i].tag);
299 data_destroy_indic (void *data)
304 static indic_position_t
305 consonant_position_from_face (const indic_shape_plan_t *indic_plan,
306 const hb_codepoint_t consonant,
307 const hb_codepoint_t virama,
310 /* For old-spec, the order of glyphs is Consonant,Virama,
311 * whereas for new-spec, it's Virama,Consonant. However,
312 * some broken fonts (like Free Sans) simply copied lookups
313 * from old-spec to new-spec without modification.
314 * And oddly enough, Uniscribe seems to respect those lookups.
315 * Eg. in the sequence U+0924,U+094D,U+0930, Uniscribe finds
316 * base at 0. The font however, only has lookups matching
317 * 930,94D in 'blwf', not the expected 94D,930 (with new-spec
318 * table). As such, we simply match both sequences. Seems
321 * Vatu is done as well, for:
322 * https://github.com/harfbuzz/harfbuzz/issues/1587
324 hb_codepoint_t glyphs[3] = {virama, consonant, virama};
325 if (indic_plan->blwf.would_substitute (glyphs , 2, face) ||
326 indic_plan->blwf.would_substitute (glyphs+1, 2, face) ||
327 indic_plan->vatu.would_substitute (glyphs , 2, face) ||
328 indic_plan->vatu.would_substitute (glyphs+1, 2, face))
330 if (indic_plan->pstf.would_substitute (glyphs , 2, face) ||
331 indic_plan->pstf.would_substitute (glyphs+1, 2, face))
333 if (indic_plan->pref.would_substitute (glyphs , 2, face) ||
334 indic_plan->pref.would_substitute (glyphs+1, 2, face))
340 setup_masks_indic (const hb_ot_shape_plan_t *plan HB_UNUSED,
342 hb_font_t *font HB_UNUSED)
344 HB_BUFFER_ALLOCATE_VAR (buffer, indic_category);
345 HB_BUFFER_ALLOCATE_VAR (buffer, indic_position);
347 /* We cannot setup masks here. We save information about characters
348 * and setup masks later on in a pause-callback. */
350 unsigned int count = buffer->len;
351 hb_glyph_info_t *info = buffer->info;
352 for (unsigned int i = 0; i < count; i++)
353 set_indic_properties (info[i]);
357 setup_syllables_indic (const hb_ot_shape_plan_t *plan HB_UNUSED,
358 hb_font_t *font HB_UNUSED,
361 find_syllables_indic (buffer);
362 foreach_syllable (buffer, start, end)
363 buffer->unsafe_to_break (start, end);
367 compare_indic_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb)
369 int a = pa->indic_position();
370 int b = pb->indic_position();
372 return a < b ? -1 : a == b ? 0 : +1;
378 update_consonant_positions_indic (const hb_ot_shape_plan_t *plan,
382 const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
384 if (indic_plan->config->base_pos != BASE_POS_LAST)
387 hb_codepoint_t virama;
388 if (indic_plan->load_virama_glyph (font, &virama))
390 hb_face_t *face = font->face;
391 unsigned int count = buffer->len;
392 hb_glyph_info_t *info = buffer->info;
393 for (unsigned int i = 0; i < count; i++)
394 if (info[i].indic_position() == POS_BASE_C)
396 hb_codepoint_t consonant = info[i].codepoint;
397 info[i].indic_position() = consonant_position_from_face (indic_plan, consonant, virama, face);
404 * https://docs.microsqoft.com/en-us/typography/script-development/devanagari */
407 initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan,
410 unsigned int start, unsigned int end)
412 const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
413 hb_glyph_info_t *info = buffer->info;
415 /* https://github.com/harfbuzz/harfbuzz/issues/435#issuecomment-335560167
416 * // For compatibility with legacy usage in Kannada,
417 * // Ra+h+ZWJ must behave like Ra+ZWJ+h...
419 if (buffer->props.script == HB_SCRIPT_KANNADA &&
421 is_one_of (info[start ], FLAG (OT_Ra)) &&
422 is_one_of (info[start+1], FLAG (OT_H)) &&
423 is_one_of (info[start+2], FLAG (OT_ZWJ)))
425 buffer->merge_clusters (start+1, start+3);
426 hb_glyph_info_t tmp = info[start+1];
427 info[start+1] = info[start+2];
431 /* 1. Find base consonant:
433 * The shaping engine finds the base consonant of the syllable, using the
434 * following algorithm: starting from the end of the syllable, move backwards
435 * until a consonant is found that does not have a below-base or post-base
436 * form (post-base forms have to follow below-base forms), or that is not a
437 * pre-base-reordering Ra, or arrive at the first consonant. The consonant
438 * stopped at will be the base.
440 * o If the syllable starts with Ra + Halant (in a script that has Reph)
441 * and has more than one consonant, Ra is excluded from candidates for
445 unsigned int base = end;
446 bool has_reph = false;
449 /* -> If the syllable starts with Ra + Halant (in a script that has Reph)
450 * and has more than one consonant, Ra is excluded from candidates for
451 * base consonants. */
452 unsigned int limit = start;
453 if (indic_plan->mask_array[INDIC_RPHF] &&
456 (indic_plan->config->reph_mode == REPH_MODE_IMPLICIT && !is_joiner (info[start + 2])) ||
457 (indic_plan->config->reph_mode == REPH_MODE_EXPLICIT && info[start + 2].indic_category() == OT_ZWJ)
460 /* See if it matches the 'rphf' feature. */
461 hb_codepoint_t glyphs[3] = {info[start].codepoint,
462 info[start + 1].codepoint,
463 indic_plan->config->reph_mode == REPH_MODE_EXPLICIT ?
464 info[start + 2].codepoint : 0};
465 if (indic_plan->rphf.would_substitute (glyphs, 2, face) ||
466 (indic_plan->config->reph_mode == REPH_MODE_EXPLICIT &&
467 indic_plan->rphf.would_substitute (glyphs, 3, face)))
470 while (limit < end && is_joiner (info[limit]))
475 } else if (indic_plan->config->reph_mode == REPH_MODE_LOG_REPHA && info[start].indic_category() == OT_Repha)
478 while (limit < end && is_joiner (info[limit]))
484 switch (indic_plan->config->base_pos)
488 /* -> starting from the end of the syllable, move backwards */
489 unsigned int i = end;
490 bool seen_below = false;
493 /* -> until a consonant is found */
494 if (is_consonant (info[i]))
496 /* -> that does not have a below-base or post-base form
497 * (post-base forms have to follow below-base forms), */
498 if (info[i].indic_position() != POS_BELOW_C &&
499 (info[i].indic_position() != POS_POST_C || seen_below))
504 if (info[i].indic_position() == POS_BELOW_C)
507 /* -> or that is not a pre-base-reordering Ra,
509 * IMPLEMENTATION NOTES:
511 * Our pre-base-reordering Ra's are marked POS_POST_C, so will be skipped
512 * by the logic above already.
515 /* -> or arrive at the first consonant. The consonant stopped at will
521 /* A ZWJ after a Halant stops the base search, and requests an explicit
523 * A ZWJ before a Halant, requests a subjoined form instead, and hence
524 * search continues. This is particularly important for Bengali
525 * sequence Ra,H,Ya that should form Ya-Phalaa by subjoining Ya. */
527 info[i].indic_category() == OT_ZWJ &&
528 info[i - 1].indic_category() == OT_H)
535 case BASE_POS_LAST_SINHALA:
537 /* Sinhala base positioning is slightly different from main Indic, in that:
538 * 1. Its ZWJ behavior is different,
539 * 2. We don't need to look into the font for consonant positions.
545 /* Find the last base consonant that is not blocked by ZWJ. If there is
546 * a ZWJ right before a base consonant, that would request a subjoined form. */
547 for (unsigned int i = limit; i < end; i++)
548 if (is_consonant (info[i]))
550 if (limit < i && info[i - 1].indic_category() == OT_ZWJ)
556 /* Mark all subsequent consonants as below. */
557 for (unsigned int i = base + 1; i < end; i++)
558 if (is_consonant (info[i]))
559 info[i].indic_position() = POS_BELOW_C;
564 /* -> If the syllable starts with Ra + Halant (in a script that has Reph)
565 * and has more than one consonant, Ra is excluded from candidates for
568 * Only do this for unforced Reph. (ie. not for Ra,H,ZWJ. */
569 if (has_reph && base == start && limit - base <= 2) {
570 /* Have no other consonant, so Reph is not formed and Ra becomes base. */
576 /* 2. Decompose and reorder Matras:
578 * Each matra and any syllable modifier sign in the syllable are moved to the
579 * appropriate position relative to the consonant(s) in the syllable. The
580 * shaping engine decomposes two- or three-part matras into their constituent
581 * parts before any repositioning. Matra characters are classified by which
582 * consonant in a conjunct they have affinity for and are reordered to the
583 * following positions:
585 * o Before first half form in the syllable
586 * o After subjoined consonants
587 * o After post-form consonant
588 * o After main consonant (for above marks)
590 * IMPLEMENTATION NOTES:
592 * The normalize() routine has already decomposed matras for us, so we don't
593 * need to worry about that.
597 /* 3. Reorder marks to canonical order:
599 * Adjacent nukta and halant or nukta and vedic sign are always repositioned
600 * if necessary, so that the nukta is first.
602 * IMPLEMENTATION NOTES:
604 * We don't need to do this: the normalize() routine already did this for us.
608 /* Reorder characters */
610 for (unsigned int i = start; i < base; i++)
611 info[i].indic_position() = hb_min (POS_PRE_C, (indic_position_t) info[i].indic_position());
614 info[base].indic_position() = POS_BASE_C;
616 /* Mark final consonants. A final consonant is one appearing after a matra.
617 * Happens in Sinhala. */
618 for (unsigned int i = base + 1; i < end; i++)
619 if (info[i].indic_category() == OT_M) {
620 for (unsigned int j = i + 1; j < end; j++)
621 if (is_consonant (info[j])) {
622 info[j].indic_position() = POS_FINAL_C;
628 /* Handle beginning Ra */
630 info[start].indic_position() = POS_RA_TO_BECOME_REPH;
632 /* For old-style Indic script tags, move the first post-base Halant after
635 * Reports suggest that in some scripts Uniscribe does this only if there
636 * is *not* a Halant after last consonant already. We know that is the
637 * case for Kannada, while it reorders unconditionally in other scripts,
638 * eg. Malayalam, Bengali, and Devanagari. We don't currently know about
639 * other scripts, so we block Kannada.
642 * U+0C9A,U+0CCD,U+0C9A,U+0CCD
643 * With some versions of Lohit Kannada.
644 * https://bugs.freedesktop.org/show_bug.cgi?id=59118
646 * Malayalam test case:
647 * U+0D38,U+0D4D,U+0D31,U+0D4D,U+0D31,U+0D4D
648 * With lohit-ttf-20121122/Lohit-Malayalam.ttf
651 * U+0998,U+09CD,U+09AF,U+09CD
652 * With Windows XP vrinda.ttf
653 * https://github.com/harfbuzz/harfbuzz/issues/1073
655 * Devanagari test case:
656 * U+091F,U+094D,U+0930,U+094D
658 * https://github.com/harfbuzz/harfbuzz/issues/1071
660 if (indic_plan->is_old_spec)
662 bool disallow_double_halants = buffer->props.script == HB_SCRIPT_KANNADA;
663 for (unsigned int i = base + 1; i < end; i++)
664 if (info[i].indic_category() == OT_H)
667 for (j = end - 1; j > i; j--)
668 if (is_consonant (info[j]) ||
669 (disallow_double_halants && info[j].indic_category() == OT_H))
671 if (info[j].indic_category() != OT_H && j > i) {
672 /* Move Halant to after last consonant. */
673 hb_glyph_info_t t = info[i];
674 memmove (&info[i], &info[i + 1], (j - i) * sizeof (info[0]));
681 /* Attach misc marks to previous char to move with them. */
683 indic_position_t last_pos = POS_START;
684 for (unsigned int i = start; i < end; i++)
686 if ((FLAG_UNSAFE (info[i].indic_category()) & (JOINER_FLAGS | FLAG (OT_N) | FLAG (OT_RS) | MEDIAL_FLAGS | FLAG (OT_H))))
688 info[i].indic_position() = last_pos;
689 if (unlikely (info[i].indic_category() == OT_H &&
690 info[i].indic_position() == POS_PRE_M))
693 * Uniscribe doesn't move the Halant with Left Matra.
694 * TEST: U+092B,U+093F,U+094DE
695 * We follow. This is important for the Sinhala
696 * U+0DDA split matra since it decomposes to U+0DD9,U+0DCA
697 * where U+0DD9 is a left matra and U+0DCA is the virama.
698 * We don't want to move the virama with the left matra.
699 * TEST: U+0D9A,U+0DDA
701 for (unsigned int j = i; j > start; j--)
702 if (info[j - 1].indic_position() != POS_PRE_M) {
703 info[i].indic_position() = info[j - 1].indic_position();
707 } else if (info[i].indic_position() != POS_SMVD) {
708 last_pos = (indic_position_t) info[i].indic_position();
712 /* For post-base consonants let them own anything before them
713 * since the last consonant or matra. */
715 unsigned int last = base;
716 for (unsigned int i = base + 1; i < end; i++)
717 if (is_consonant (info[i]))
719 for (unsigned int j = last + 1; j < i; j++)
720 if (info[j].indic_position() < POS_SMVD)
721 info[j].indic_position() = info[i].indic_position();
723 } else if (info[i].indic_category() == OT_M)
729 /* Use syllable() for sort accounting temporarily. */
730 unsigned int syllable = info[start].syllable();
731 for (unsigned int i = start; i < end; i++)
732 info[i].syllable() = i - start;
734 /* Sit tight, rock 'n roll! */
735 hb_stable_sort (info + start, end - start, compare_indic_order);
736 /* Find base again */
738 for (unsigned int i = start; i < end; i++)
739 if (info[i].indic_position() == POS_BASE_C)
744 /* Things are out-of-control for post base positions, they may shuffle
745 * around like crazy. In old-spec mode, we move halants around, so in
746 * that case merge all clusters after base. Otherwise, check the sort
747 * order and merge as needed.
748 * For pre-base stuff, we handle cluster issues in final reordering.
750 * We could use buffer->sort() for this, if there was no special
751 * reordering of pre-base stuff happening later...
752 * We don't want to merge_clusters all of that, which buffer->sort()
753 * would. Here's a concrete example:
755 * Assume there's a pre-base consonant and explicit Halant before base,
756 * followed by a prebase-reordering (left) Matra:
760 * At this point in reordering we would have:
764 * whereas in final reordering we will bring the Matra closer to Base:
768 * That's why we don't want to merge-clusters anything before the Base
769 * at this point. But if something moved from after Base to before it,
770 * we should merge clusters from base to them. In final-reordering, we
771 * only move things around before base, and merge-clusters up to base.
772 * These two merge-clusters from the two sides of base will interlock
773 * to merge things correctly. See:
774 * https://github.com/harfbuzz/harfbuzz/issues/2272
776 if (indic_plan->is_old_spec || end - start > 127)
777 buffer->merge_clusters (base, end);
780 /* Note! syllable() is a one-byte field. */
781 for (unsigned int i = base; i < end; i++)
782 if (info[i].syllable() != 255)
784 unsigned int min = i;
785 unsigned int max = i;
786 unsigned int j = start + info[i].syllable();
789 min = hb_min (min, j);
790 max = hb_max (max, j);
791 unsigned int next = start + info[j].syllable();
792 info[j].syllable() = 255; /* So we don't process j later again. */
795 buffer->merge_clusters (hb_max (base, min), max + 1);
799 /* Put syllable back in. */
800 for (unsigned int i = start; i < end; i++)
801 info[i].syllable() = syllable;
804 /* Setup masks now */
810 for (unsigned int i = start; i < end && info[i].indic_position() == POS_RA_TO_BECOME_REPH; i++)
811 info[i].mask |= indic_plan->mask_array[INDIC_RPHF];
814 mask = indic_plan->mask_array[INDIC_HALF];
815 if (!indic_plan->is_old_spec &&
816 indic_plan->config->blwf_mode == BLWF_MODE_PRE_AND_POST)
817 mask |= indic_plan->mask_array[INDIC_BLWF];
818 for (unsigned int i = start; i < base; i++)
819 info[i].mask |= mask;
823 info[base].mask |= mask;
825 mask = indic_plan->mask_array[INDIC_BLWF] |
826 indic_plan->mask_array[INDIC_ABVF] |
827 indic_plan->mask_array[INDIC_PSTF];
828 for (unsigned int i = base + 1; i < end; i++)
829 info[i].mask |= mask;
832 if (indic_plan->is_old_spec &&
833 buffer->props.script == HB_SCRIPT_DEVANAGARI)
835 /* Old-spec eye-lash Ra needs special handling. From the
838 * "The feature 'below-base form' is applied to consonants
839 * having below-base forms and following the base consonant.
840 * The exception is vattu, which may appear below half forms
841 * as well as below the base glyph. The feature 'below-base
842 * form' will be applied to all such occurrences of Ra as well."
844 * Test case: U+0924,U+094D,U+0930,U+094d,U+0915
845 * with Sanskrit 2003 font.
847 * However, note that Ra,Halant,ZWJ is the correct way to
848 * request eyelash form of Ra, so we wouldbn't inhibit it
851 * Test case: U+0924,U+094D,U+0930,U+094d,U+200D,U+0915
853 for (unsigned int i = start; i + 1 < base; i++)
854 if (info[i ].indic_category() == OT_Ra &&
855 info[i+1].indic_category() == OT_H &&
857 info[i+2].indic_category() != OT_ZWJ))
859 info[i ].mask |= indic_plan->mask_array[INDIC_BLWF];
860 info[i+1].mask |= indic_plan->mask_array[INDIC_BLWF];
864 unsigned int pref_len = 2;
865 if (indic_plan->mask_array[INDIC_PREF] && base + pref_len < end)
867 /* Find a Halant,Ra sequence and mark it for pre-base-reordering processing. */
868 for (unsigned int i = base + 1; i + pref_len - 1 < end; i++) {
869 hb_codepoint_t glyphs[2];
870 for (unsigned int j = 0; j < pref_len; j++)
871 glyphs[j] = info[i + j].codepoint;
872 if (indic_plan->pref.would_substitute (glyphs, pref_len, face))
874 for (unsigned int j = 0; j < pref_len; j++)
875 info[i++].mask |= indic_plan->mask_array[INDIC_PREF];
881 /* Apply ZWJ/ZWNJ effects */
882 for (unsigned int i = start + 1; i < end; i++)
883 if (is_joiner (info[i])) {
884 bool non_joiner = info[i].indic_category() == OT_ZWNJ;
890 /* ZWJ/ZWNJ should disable CJCT. They do that by simply
891 * being there, since we don't skip them for the CJCT
892 * feature (ie. F_MANUAL_ZWJ) */
894 /* A ZWNJ disables HALF. */
896 info[j].mask &= ~indic_plan->mask_array[INDIC_HALF];
898 } while (j > start && !is_consonant (info[j]));
903 initial_reordering_standalone_cluster (const hb_ot_shape_plan_t *plan,
906 unsigned int start, unsigned int end)
908 /* We treat placeholder/dotted-circle as if they are consonants, so we
909 * should just chain. Only if not in compatibility mode that is... */
911 const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
912 if (indic_plan->uniscribe_bug_compatible)
914 /* For dotted-circle, this is what Uniscribe does:
915 * If dotted-circle is the last glyph, it just does nothing.
916 * Ie. It doesn't form Reph. */
917 if (buffer->info[end - 1].indic_category() == OT_DOTTEDCIRCLE)
921 initial_reordering_consonant_syllable (plan, face, buffer, start, end);
925 initial_reordering_syllable_indic (const hb_ot_shape_plan_t *plan,
928 unsigned int start, unsigned int end)
930 indic_syllable_type_t syllable_type = (indic_syllable_type_t) (buffer->info[start].syllable() & 0x0F);
931 switch (syllable_type)
933 case indic_vowel_syllable: /* We made the vowels look like consonants. So let's call the consonant logic! */
934 case indic_consonant_syllable:
935 initial_reordering_consonant_syllable (plan, face, buffer, start, end);
938 case indic_broken_cluster: /* We already inserted dotted-circles, so just call the standalone_cluster. */
939 case indic_standalone_cluster:
940 initial_reordering_standalone_cluster (plan, face, buffer, start, end);
943 case indic_symbol_cluster:
944 case indic_non_indic_cluster:
950 initial_reordering_indic (const hb_ot_shape_plan_t *plan,
954 if (!buffer->message (font, "start reordering indic initial"))
957 update_consonant_positions_indic (plan, font, buffer);
958 hb_syllabic_insert_dotted_circles (font, buffer,
959 indic_broken_cluster,
964 foreach_syllable (buffer, start, end)
965 initial_reordering_syllable_indic (plan, font->face, buffer, start, end);
967 (void) buffer->message (font, "end reordering indic initial");
971 final_reordering_syllable_indic (const hb_ot_shape_plan_t *plan,
973 unsigned int start, unsigned int end)
975 const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data;
976 hb_glyph_info_t *info = buffer->info;
979 /* This function relies heavily on halant glyphs. Lots of ligation
980 * and possibly multiple substitutions happened prior to this
981 * phase, and that might have messed up our properties. Recover
982 * from a particular case of that where we're fairly sure that a
983 * class of OT_H is desired but has been lost. */
984 /* We don't call load_virama_glyph(), since we know it's already
986 hb_codepoint_t virama_glyph = indic_plan->virama_glyph.get_relaxed ();
989 for (unsigned int i = start; i < end; i++)
990 if (info[i].codepoint == virama_glyph &&
991 _hb_glyph_info_ligated (&info[i]) &&
992 _hb_glyph_info_multiplied (&info[i]))
994 /* This will make sure that this glyph passes is_halant() test. */
995 info[i].indic_category() = OT_H;
996 _hb_glyph_info_clear_ligated_and_multiplied (&info[i]);
1001 /* 4. Final reordering:
1003 * After the localized forms and basic shaping forms GSUB features have been
1004 * applied (see below), the shaping engine performs some final glyph
1005 * reordering before applying all the remaining font features to the entire
1009 bool try_pref = !!indic_plan->mask_array[INDIC_PREF];
1011 /* Find base again */
1013 for (base = start; base < end; base++)
1014 if (info[base].indic_position() >= POS_BASE_C)
1016 if (try_pref && base + 1 < end)
1018 for (unsigned int i = base + 1; i < end; i++)
1019 if ((info[i].mask & indic_plan->mask_array[INDIC_PREF]) != 0)
1021 if (!(_hb_glyph_info_substituted (&info[i]) &&
1022 _hb_glyph_info_ligated_and_didnt_multiply (&info[i])))
1024 /* Ok, this was a 'pref' candidate but didn't form any.
1025 * Base is around here... */
1027 while (base < end && is_halant (info[base]))
1029 info[base].indic_position() = POS_BASE_C;
1036 /* For Malayalam, skip over unformed below- (but NOT post-) forms. */
1037 if (buffer->props.script == HB_SCRIPT_MALAYALAM)
1039 for (unsigned int i = base + 1; i < end; i++)
1041 while (i < end && is_joiner (info[i]))
1043 if (i == end || !is_halant (info[i]))
1045 i++; /* Skip halant. */
1046 while (i < end && is_joiner (info[i]))
1048 if (i < end && is_consonant (info[i]) && info[i].indic_position() == POS_BELOW_C)
1051 info[base].indic_position() = POS_BASE_C;
1056 if (start < base && info[base].indic_position() > POS_BASE_C)
1060 if (base == end && start < base &&
1061 is_one_of (info[base - 1], FLAG (OT_ZWJ)))
1064 while (start < base &&
1065 is_one_of (info[base], (FLAG (OT_N) | FLAG (OT_H))))
1069 /* o Reorder matras:
1071 * If a pre-base matra character had been reordered before applying basic
1072 * features, the glyph can be moved closer to the main consonant based on
1073 * whether half-forms had been formed. Actual position for the matra is
1074 * defined as “after last standalone halant glyph, after initial matra
1075 * position and before the main consonant”. If ZWJ or ZWNJ follow this
1076 * halant, position is moved after it.
1078 * IMPLEMENTATION NOTES:
1080 * It looks like the last sentence is wrong. Testing, with Windows 7 Uniscribe
1081 * and Devanagari shows that the behavior is best described as:
1083 * "If ZWJ follows this halant, matra is NOT repositioned after this halant.
1084 * If ZWNJ follows this halant, position is moved after it."
1086 * Test case, with Adobe Devanagari or Nirmala UI:
1088 * U+091F,U+094D,U+200C,U+092F,U+093F
1089 * (Matra moves to the middle, after ZWNJ.)
1091 * U+091F,U+094D,U+200D,U+092F,U+093F
1092 * (Matra does NOT move, stays to the left.)
1094 * https://github.com/harfbuzz/harfbuzz/issues/1070
1097 if (start + 1 < end && start < base) /* Otherwise there can't be any pre-base matra characters. */
1099 /* If we lost track of base, alas, position before last thingy. */
1100 unsigned int new_pos = base == end ? base - 2 : base - 1;
1102 /* Malayalam / Tamil do not have "half" forms or explicit virama forms.
1103 * The glyphs formed by 'half' are Chillus or ligated explicit viramas.
1104 * We want to position matra after them.
1106 if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL)
1109 while (new_pos > start &&
1110 !(is_one_of (info[new_pos], (FLAG (OT_M) | FLAG (OT_H)))))
1113 /* If we found no Halant we are done.
1114 * Otherwise only proceed if the Halant does
1115 * not belong to the Matra itself! */
1116 if (is_halant (info[new_pos]) &&
1117 info[new_pos].indic_position() != POS_PRE_M)
1119 #if 0 // See comment above
1120 /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */
1121 if (new_pos + 1 < end && is_joiner (info[new_pos + 1]))
1124 if (new_pos + 1 < end)
1126 /* -> If ZWJ follows this halant, matra is NOT repositioned after this halant. */
1127 if (info[new_pos + 1].indic_category() == OT_ZWJ)
1129 /* Keep searching. */
1130 if (new_pos > start)
1136 /* -> If ZWNJ follows this halant, position is moved after it.
1138 * IMPLEMENTATION NOTES:
1140 * This is taken care of by the state-machine. A Halant,ZWNJ is a terminating
1141 * sequence for a consonant syllable; any pre-base matras occurring after it
1142 * will belong to the subsequent syllable.
1147 new_pos = start; /* No move. */
1150 if (start < new_pos && info[new_pos].indic_position () != POS_PRE_M)
1152 /* Now go see if there's actually any matras... */
1153 for (unsigned int i = new_pos; i > start; i--)
1154 if (info[i - 1].indic_position () == POS_PRE_M)
1156 unsigned int old_pos = i - 1;
1157 if (old_pos < base && base <= new_pos) /* Shouldn't actually happen. */
1160 hb_glyph_info_t tmp = info[old_pos];
1161 memmove (&info[old_pos], &info[old_pos + 1], (new_pos - old_pos) * sizeof (info[0]));
1162 info[new_pos] = tmp;
1164 /* Note: this merge_clusters() is intentionally *after* the reordering.
1165 * Indic matra reordering is special and tricky... */
1166 buffer->merge_clusters (new_pos, hb_min (end, base + 1));
1171 for (unsigned int i = start; i < base; i++)
1172 if (info[i].indic_position () == POS_PRE_M) {
1173 buffer->merge_clusters (i, hb_min (end, base + 1));
1182 * Reph’s original position is always at the beginning of the syllable,
1183 * (i.e. it is not reordered at the character reordering stage). However,
1184 * it will be reordered according to the basic-forms shaping results.
1185 * Possible positions for reph, depending on the script, are; after main,
1186 * before post-base consonant forms, and after post-base consonant forms.
1191 * - If repha is encoded as a sequence of characters (Ra,H or Ra,H,ZWJ), then
1192 * we should only move it if the sequence ligated to the repha form.
1194 * - If repha is encoded separately and in the logical position, we should only
1195 * move it if it did NOT ligate. If it ligated, it's probably the font trying
1196 * to make it work without the reordering.
1198 if (start + 1 < end &&
1199 info[start].indic_position() == POS_RA_TO_BECOME_REPH &&
1200 ((info[start].indic_category() == OT_Repha) ^
1201 _hb_glyph_info_ligated_and_didnt_multiply (&info[start])))
1203 unsigned int new_reph_pos;
1204 reph_position_t reph_pos = indic_plan->config->reph_pos;
1206 /* 1. If reph should be positioned after post-base consonant forms,
1207 * proceed to step 5.
1209 if (reph_pos == REPH_POS_AFTER_POST)
1214 /* 2. If the reph repositioning class is not after post-base: target
1215 * position is after the first explicit halant glyph between the
1216 * first post-reph consonant and last main consonant. If ZWJ or ZWNJ
1217 * are following this halant, position is moved after it. If such
1218 * position is found, this is the target position. Otherwise,
1219 * proceed to the next step.
1221 * Note: in old-implementation fonts, where classifications were
1222 * fixed in shaping engine, there was no case where reph position
1223 * will be found on this step.
1226 new_reph_pos = start + 1;
1227 while (new_reph_pos < base && !is_halant (info[new_reph_pos]))
1230 if (new_reph_pos < base && is_halant (info[new_reph_pos]))
1232 /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */
1233 if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1]))
1239 /* 3. If reph should be repositioned after the main consonant: find the
1240 * first consonant not ligated with main, or find the first
1241 * consonant that is not a potential pre-base-reordering Ra.
1243 if (reph_pos == REPH_POS_AFTER_MAIN)
1245 new_reph_pos = base;
1246 while (new_reph_pos + 1 < end && info[new_reph_pos + 1].indic_position() <= POS_AFTER_MAIN)
1248 if (new_reph_pos < end)
1252 /* 4. If reph should be positioned before post-base consonant, find
1253 * first post-base classified consonant not ligated with main. If no
1254 * consonant is found, the target position should be before the
1255 * first matra, syllable modifier sign or vedic sign.
1257 /* This is our take on what step 4 is trying to say (and failing, BADLY). */
1258 if (reph_pos == REPH_POS_AFTER_SUB)
1260 new_reph_pos = base;
1261 while (new_reph_pos + 1 < end &&
1262 !( FLAG_UNSAFE (info[new_reph_pos + 1].indic_position()) & (FLAG (POS_POST_C) | FLAG (POS_AFTER_POST) | FLAG (POS_SMVD))))
1264 if (new_reph_pos < end)
1268 /* 5. If no consonant is found in steps 3 or 4, move reph to a position
1269 * immediately before the first post-base matra, syllable modifier
1270 * sign or vedic sign that has a reordering class after the intended
1271 * reph position. For example, if the reordering position for reph
1272 * is post-main, it will skip above-base matras that also have a
1273 * post-main position.
1277 /* Copied from step 2. */
1278 new_reph_pos = start + 1;
1279 while (new_reph_pos < base && !is_halant (info[new_reph_pos]))
1282 if (new_reph_pos < base && is_halant (info[new_reph_pos]))
1284 /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */
1285 if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1]))
1290 /* See https://github.com/harfbuzz/harfbuzz/issues/2298#issuecomment-615318654 */
1292 /* 6. Otherwise, reorder reph to the end of the syllable.
1295 new_reph_pos = end - 1;
1296 while (new_reph_pos > start && info[new_reph_pos].indic_position() == POS_SMVD)
1300 * If the Reph is to be ending up after a Matra,Halant sequence,
1301 * position it before that Halant so it can interact with the Matra.
1302 * However, if it's a plain Consonant,Halant we shouldn't do that.
1303 * Uniscribe doesn't do this.
1304 * TEST: U+0930,U+094D,U+0915,U+094B,U+094D
1306 if (!indic_plan->uniscribe_bug_compatible &&
1307 unlikely (is_halant (info[new_reph_pos])))
1309 for (unsigned int i = base + 1; i < new_reph_pos; i++)
1310 if (info[i].indic_category() == OT_M) {
1322 buffer->merge_clusters (start, new_reph_pos + 1);
1323 hb_glyph_info_t reph = info[start];
1324 memmove (&info[start], &info[start + 1], (new_reph_pos - start) * sizeof (info[0]));
1325 info[new_reph_pos] = reph;
1327 if (start < base && base <= new_reph_pos)
1333 /* o Reorder pre-base-reordering consonants:
1335 * If a pre-base-reordering consonant is found, reorder it according to
1336 * the following rules:
1339 if (try_pref && base + 1 < end) /* Otherwise there can't be any pre-base-reordering Ra. */
1341 for (unsigned int i = base + 1; i < end; i++)
1342 if ((info[i].mask & indic_plan->mask_array[INDIC_PREF]) != 0)
1344 /* 1. Only reorder a glyph produced by substitution during application
1345 * of the <pref> feature. (Note that a font may shape a Ra consonant with
1346 * the feature generally but block it in certain contexts.)
1348 /* Note: We just check that something got substituted. We don't check that
1349 * the <pref> feature actually did it...
1351 * Reorder pref only if it ligated. */
1352 if (_hb_glyph_info_ligated_and_didnt_multiply (&info[i]))
1355 * 2. Try to find a target position the same way as for pre-base matra.
1356 * If it is found, reorder pre-base consonant glyph.
1358 * 3. If position is not found, reorder immediately before main
1362 unsigned int new_pos = base;
1363 /* Malayalam / Tamil do not have "half" forms or explicit virama forms.
1364 * The glyphs formed by 'half' are Chillus or ligated explicit viramas.
1365 * We want to position matra after them.
1367 if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL)
1369 while (new_pos > start &&
1370 !(is_one_of (info[new_pos - 1], FLAG(OT_M) | FLAG (OT_H))))
1374 if (new_pos > start && is_halant (info[new_pos - 1]))
1376 /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */
1377 if (new_pos < end && is_joiner (info[new_pos]))
1382 unsigned int old_pos = i;
1384 buffer->merge_clusters (new_pos, old_pos + 1);
1385 hb_glyph_info_t tmp = info[old_pos];
1386 memmove (&info[new_pos + 1], &info[new_pos], (old_pos - new_pos) * sizeof (info[0]));
1387 info[new_pos] = tmp;
1389 if (new_pos <= base && base < old_pos)
1399 /* Apply 'init' to the Left Matra if it's a word start. */
1400 if (info[start].indic_position () == POS_PRE_M)
1403 !(FLAG_UNSAFE (_hb_glyph_info_get_general_category (&info[start - 1])) &
1404 FLAG_RANGE (HB_UNICODE_GENERAL_CATEGORY_FORMAT, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)))
1405 info[start].mask |= indic_plan->mask_array[INDIC_INIT];
1407 buffer->unsafe_to_break (start - 1, start + 1);
1412 * Finish off the clusters and go home!
1414 if (indic_plan->uniscribe_bug_compatible)
1416 switch ((hb_tag_t) plan->props.script)
1418 case HB_SCRIPT_TAMIL:
1419 case HB_SCRIPT_SINHALA:
1423 /* Uniscribe merges the entire syllable into a single cluster... Except for Tamil & Sinhala.
1424 * This means, half forms are submerged into the main consonant's cluster.
1425 * This is unnecessary, and makes cursor positioning harder, but that's what
1426 * Uniscribe does. */
1427 buffer->merge_clusters (start, end);
1435 final_reordering_indic (const hb_ot_shape_plan_t *plan,
1436 hb_font_t *font HB_UNUSED,
1437 hb_buffer_t *buffer)
1439 unsigned int count = buffer->len;
1440 if (unlikely (!count)) return;
1442 if (buffer->message (font, "start reordering indic final")) {
1443 foreach_syllable (buffer, start, end)
1444 final_reordering_syllable_indic (plan, buffer, start, end);
1445 (void) buffer->message (font, "end reordering indic final");
1448 HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category);
1449 HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position);
1454 preprocess_text_indic (const hb_ot_shape_plan_t *plan,
1455 hb_buffer_t *buffer,
1458 _hb_preprocess_text_vowel_constraints (plan, buffer, font);
1462 decompose_indic (const hb_ot_shape_normalize_context_t *c,
1469 /* Don't decompose these. */
1470 case 0x0931u : return false; /* DEVANAGARI LETTER RRA */
1471 // https://github.com/harfbuzz/harfbuzz/issues/779
1472 case 0x09DCu : return false; /* BENGALI LETTER RRA */
1473 case 0x09DDu : return false; /* BENGALI LETTER RHA */
1474 case 0x0B94u : return false; /* TAMIL LETTER AU */
1478 * Decompose split matras that don't have Unicode decompositions.
1483 /* This one has no decomposition in Unicode, but needs no decomposition either. */
1484 /* case 0x0AC9u : return false; */
1487 case 0x0B57u : *a = no decomp, -> RIGHT; return true;
1491 if ((ab == 0x0DDAu || hb_in_range<hb_codepoint_t> (ab, 0x0DDCu, 0x0DDEu)))
1494 * Sinhala split matras... Let the fun begin.
1496 * These four characters have Unicode decompositions. However, Uniscribe
1497 * decomposes them "Khmer-style", that is, it uses the character itself to
1498 * get the second half. The first half of all four decompositions is always
1501 * Now, there are buggy fonts, namely, the widely used lklug.ttf, that are
1502 * broken with Uniscribe. But we need to support them. As such, we only
1503 * do the Uniscribe-style decomposition if the character is transformed into
1504 * its "sec.half" form by the 'pstf' feature. Otherwise, we fall back to
1505 * Unicode decomposition.
1507 * Note that we can't unconditionally use Unicode decomposition. That would
1508 * break some other fonts, that are designed to work with Uniscribe, and
1509 * don't have positioning features for the Unicode-style decomposition.
1513 * The Uniscribe behavior is now documented in the newly published Sinhala
1516 * https://docs.microsoft.com/en-us/typography/script-development/sinhala#shaping
1520 const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) c->plan->data;
1521 hb_codepoint_t glyph;
1522 if (indic_plan->uniscribe_bug_compatible ||
1523 (c->font->get_nominal_glyph (ab, &glyph) &&
1524 indic_plan->pstf.would_substitute (&glyph, 1, c->font->face)))
1526 /* Ok, safe to use Uniscribe-style decomposition. */
1533 return (bool) c->unicode->decompose (ab, a, b);
1537 compose_indic (const hb_ot_shape_normalize_context_t *c,
1542 /* Avoid recomposing split matras. */
1543 if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (c->unicode->general_category (a)))
1546 /* Composition-exclusion exceptions that we want to recompose. */
1547 if (a == 0x09AFu && b == 0x09BCu) { *ab = 0x09DFu; return true; }
1549 return (bool) c->unicode->compose (a, b, ab);
1553 const hb_ot_complex_shaper_t _hb_ot_complex_shaper_indic =
1555 collect_features_indic,
1556 override_features_indic,
1559 preprocess_text_indic,
1560 nullptr, /* postprocess_glyphs */
1561 HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT,
1565 HB_TAG_NONE, /* gpos_tag */
1566 nullptr, /* reorder_marks */
1567 HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE,
1568 false, /* fallback_position */