Reordering in levels 0 and 1

Another common operation in some shapers is glyph reordering. In order to maintain a monotonic cluster sequence when glyph reordering takes place, HarfBuzz merges the clusters of everything in the reordering sequence.

For example, let us again start with the character sequence (top row) and initial cluster values (bottom row):


If D is reordered to the position immediately before B, then HarfBuzz merges the B, C, and D clusters — all the clusters between the final position of the reordered glyph and its original position. This means that we get:


as the final cluster sequence.

Merging this many clusters is not ideal, but it is the only sensible way for HarfBuzz to maintain the guarantee that the sequence of cluster values remains monotonic and to retain the true relationship between glyphs and characters.