I developed a very small font where I have ABCDEFGH as my basic glyphs. I would like to script a ligature sub… for example, if I type AG, I’d get ABCDEFG as result. if I type EH, I’d get EFGH.
I’ve tried this but it doesn’t work:
feature liga {
sub A G by A B C D E F G;
sub E H by E F G H;
} liga;
I read many tutorials online but still I’m struggling with this. Any help is appreciated, Thanks a lot.
A ligature substitution substitutes one glyph for two or more. So you need to construct a glyph A_B_C_D_E_F_G (you can make it out of components), and another E_F_G_H, and then make the rule like this:
feature liga {
sub A G by A_B_C_D_E_F_G ;
sub E H by E_F_G_H ;
} liga ;
You can read about the various lookup types here. What you want, a lookup that substitutes several glyphs for several glyphs, is unfortunately not there. It will be tedious but economical in terms of space to do what you want with ligatures made of components.
As @psb6m suggested, ligatures are typically multiple glyphs that get substituted by a single glyph. This is a many-to-one substitution.
OpenType does not offer a many-to-many substitution as you want, but it can be simulated by placing a lookup in the Prefix section and referencing that from the ligature feature:
Here, you match the pattern A G in the liga feature. The ' single quote marks the G as the glyph that should get replaced and the lookup some_ lookup after the pattern references a lookup that you have defined in the prefix which substitutes the G by all of the desired glyphs, including the G itself.
One caveat, a thing I noticed about Adobe some time ago, borne out by a little testing just now: they seem to have disabled one-to-many substitutions for some reason. Maybe figuring it isn’t needed in English script? So it doesn’t seem to work in the Adobe suite.