Understanding how ligatures (and other such substitutions) happen

I’m trying to learn and understand how fonts work, such as SIL fonts. I’ve troubles understanding how ligature concretely happen. My apologies if this is the wrong forum to ask this question.

For example, how does the combination of “f” + “i” becomes either “fi” (two glyphs side-by-side) or a ligature (“f” and “i” combined into one glyph). (I’ve read in great details Understanding characters, keystrokes, codepoints and glyphs)

Thank you very much in advance!

This happens by rules built into the logic of the font. Many of our fonts include both Graphite and OpenType logic, and while the syntax is different, the effect is the same: two (or more) glyphs in sequence get replaced by a single (ligature) glyph.

In OpenType, a Ligature Substitution lookup is used. Lookups, however, have to be included in a feature for them to be executed. For ligatures, some common features used for this purpose are dlig, liga, and rlig – each has different implications as to whether it is enabled by default or not.

Thank you Bob for your swift answer!
Maybe my question doesn’t make sense but “what” calls this logic to replace/substitute glyphs? By “what”, I mean: is it the software displaying the text using that font, or is it the underlying OS, or something else entirely?

TTFs handle ligatures, like “fi”, so do smart fonts with Graphite, so “what” does call either the substitution feature of a TTF or the Graphite rendering engine?


The “what” will depend on how the application is constructed. Most apps don’t do their own text rendering but depend on application libraries/APIs to do that work. On Windows in the old days everything went through system APIs and then through the Uniscribe library. There are other alternatives today – many opensource applications use Harfbuzz (directly or indirectly) to convert a character stream to a set of positioned glyphs. Depending on how it is compiled, Harfbuzz can handle both Graphite and OpenType fonts.

To get more detailed than that, you probably need to specify what OS and software development environment you’re using.

Thanks again for your swift answer. I’m looking for something for C (if possible C99 or even C89) but I’d also happy with code examples in Java. As for the operating system, Windows by “default”.

Perhaps look at A simple shaping example: HarfBuzz Manual to see if this example is the sort of thing you are seeking. If so you can dig deeper into the Harfbuzz manual (https://harfbuzz.github.io).