diff --git a/src/hb-ot-shape-complex-indic.cc b/src/hb-ot-shape-complex-indic.cc index d90d23889..d0c3c0992 100644 --- a/src/hb-ot-shape-complex-indic.cc +++ b/src/hb-ot-shape-complex-indic.cc @@ -895,22 +895,37 @@ final_reordering_syllable (hb_buffer_t *buffer, * halant, position is moved after it. */ - if (start < base) /* Otherwise there can't be any pre-base matra characters. */ + if (start + 1 < end && start < base) /* Otherwise there can't be any pre-base matra characters. */ { - unsigned int new_pos = base - 1; - while (new_pos > start && - !(is_one_of (info[new_pos], (FLAG (OT_M) | FLAG (OT_H) | FLAG (OT_Coeng))))) - new_pos--; - /* If we found no Halant we are done (just need to update clusters). - * Otherwise only proceed if the Halant does - * not belong to the Matra itself! */ - if (is_halant_or_coeng (info[new_pos]) && - info[new_pos].indic_position() != POS_PRE_M) - { - /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ - if (new_pos + 1 < end && is_joiner (info[new_pos + 1])) - new_pos++; + /* If we lost track of base, alas, position before last thingy. */ + unsigned int new_pos = base == end ? base - 2 : base - 1; + /* Malayalam does not have "half" forms or explicit virama forms. + * The glyphs formed by 'half' are Chillus. We want to position + * matra after them all. + */ + if (buffer->props.script != HB_SCRIPT_MALAYALAM) + { + while (new_pos > start && + !(is_one_of (info[new_pos], (FLAG (OT_M) | FLAG (OT_H) | FLAG (OT_Coeng))))) + new_pos--; + + /* If we found no Halant we are done. + * Otherwise only proceed if the Halant does + * not belong to the Matra itself! */ + if (is_halant_or_coeng (info[new_pos]) && + info[new_pos].indic_position() != POS_PRE_M) + { + /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ + if (new_pos + 1 < end && is_joiner (info[new_pos + 1])) + new_pos++; + } + else + new_pos = start; /* No move. */ + } + + if (start < new_pos) + { /* Now go see if there's actually any matras... */ for (unsigned int i = new_pos; i > start; i--) if (info[i - 1].indic_position () == POS_PRE_M) diff --git a/test/shaping/texts/in-tree/shaper-indic/indic/script-malayalam/misc/misc.txt b/test/shaping/texts/in-tree/shaper-indic/indic/script-malayalam/misc/misc.txt index 3072b0ae6..ffb408d32 100644 --- a/test/shaping/texts/in-tree/shaper-indic/indic/script-malayalam/misc/misc.txt +++ b/test/shaping/texts/in-tree/shaper-indic/indic/script-malayalam/misc/misc.txt @@ -58,3 +58,4 @@ ള്‍ ള്യം ള്ള +ല്‍പ്പേ