Skip to content

Lookup Type 2 — Multiple Substitution

Multiple Substitution is a GSUB rule that replaces a single glyph with a sequence of two or more glyphs.

sub fi by f i;

Rules are written inside a feature block. Used in the ccmp feature, for example:

feature ccmp {
sub fi by f i;
} ccmp;

Unicode encodes some ligatures as characters in their own right. fi (U+FB01) is one of them: an independent character, distinct from the sequence of f and i.

cmap can map each character to only one glyph, so this character is also a single glyph in the font. This rule is the only way to get back to the two glyphs f and i. Among GSUB rules, this is the only type that can make the glyph sequence longer than the input.

Once the glyph is decomposed, features that target f and i (such as smcp and sups) just work. If it stays whole, you need a dedicated variant of the ligature glyph for every such feature. The difference is drawing one glyph per combination versus one glyph per component.

In writing systems like Thai, where a single character is made of several components with marks stacked on top, the difference grows even larger. Decompose into components, and positioning can be left to GPOS.

sub <glyph> by <glyph sequence>;
  • <glyph> — the single glyph being replaced.
  • <glyph sequence> — the two or more glyphs that replace it, written in the order they appear after the substitution.

Glyph classes are not allowed in <glyph sequence>. If they were, the rule would be ambiguous about which sequence to substitute.

sub is the short form of substitute. These two rules are the same:

substitute fi by f i;
sub fi by f i;

The syntax is similar to Lookup Type 4, but there is no need to state the Lookup Type. The compiler determines it from the shape of the rule.

# one glyph → two glyphs = Multiple Substitution (Lookup Type 2)
sub fi by f i;
# two glyphs → one glyph = Ligature Substitution (Lookup Type 4)
sub f i by fi;
Without rules
fish fish flow flow
With rules
fish fish flow flow
Compiling…

The OpenType specification recommends implementing the following features with this lookup type.

  • ccmp — Glyph Composition/Decomposition. Decomposes a single glyph into multiple glyphs before other features run.
  • stch — Stretching Glyph Decomposition. Decomposes a glyph that stretches to the width of the enclosed text, such as the Syriac Abbreviation Mark, into a sequence of an odd number of glyphs.