Contextual Kerning

  • by Rainer Erich Scheichelbauer
  • Tutorial
  • – Modified on

So, you have optimized the sidebearings of your glyphs, then added kerning pairs where necessary. But still, you come across some cases where the white space between the letters still isn’t optimal in certain glyph triplets.

There are some usual suspects. For instance, when a glyph with a negative RSB is followed by a space and a glyph with a negative LSB, e.g. f space T, f space V and f space W. In these cases, the word space gets eaten up by the surrounding negative sidebearings. To a reader, the result may look like a forgotten space. So the white space needs to be increased a bit.

Or take the L quoteright A triplet, where the apostrophe (we assume quoteright will be used for the apostrophe) usually ends up too close to the A and too far away from the L. We need to fix that:

contextkern-1

Typical triplets usually include space, punctuation and quotes, like period quoteright space. Also, it’s not necessarily always triplets, it can be quadruplets too, like f period space V etc. Of course, the mileage varies greatly depending on the design. The only way to find out which combinations you need is to have long texts set in your typeface, preferably with lots of punctuation in different languages, and look for spots where the white space seems messed up.

Contextual kerning lookup

Enter the kern feature. Glyphs actually creates it automatically for you at export time, using all the kerning pairs you created. Now, you can add some extra kerning on top of the existing kerning by adding a separate lookup to the kern feature.

contextkern-2

To do that, go into Edit > Font Info > Features and add a new feature called kern by clicking on the plus button in the bottom left of the window. Now let’s assume we want to fix the triplets containing f space as well as the L quoteright A combo, which is important for languages like French and Italian. Okay, here’s what we put into kern:

pos f' 50 space [T V W Y];
pos L' -40 quoteright' 80 [A Aacute Agrave];

The first line looks for an f followed by a word space, but only before T, V, W or Y. Only in that case will the f space pair get an additional white space of 50 units.

The second line looks for an L, followed by an apostrophe and an A, with or without an accent. in that case, the apostrophe is shoved into the L by 40 units, while the space between the apostrophe and the A is increased by 80 units, effectively moving the apostrophe closer to the L, and increasing the space between L and A, preventing them from colliding with each other.

This is called a chaining contextual positioning with a marked subrun. If you’re familiar with AFDKO feature coding, the structure of the positioning rules may surprise you. The kerning values are not placed at the end of the line, but right between the names of the affected glyphs. Also, as with any contextual rule, some glyphs need to be marked with a ‘dumb quote’. In this case, we need to mark every glyph that is followed by a kerning value.

Technicalities

Under the hood, Glyphs adds a lookup called kernCustom to the end of the kern feature:

contextkern-3

The sequence of marked glyphs, the ‘marked subrun’, must not be interrupted by unmarked glyphs. That means you can have x x' x' x' x but not x' x' x x' x'. Otherwise you get this error: ‘Unsupported contextual GPOS target sequence: only one run of marked glyphs is supported’.

And you cannot mix regular kerning with contextual kerning, because they are two different lookup types. If you do mix them, you will receive this error: ‘Lookup type different from previous rules in this lookup block’.

Two minor drawbacks

Since our lookup is feature code that gets injected into every instance at export time, the contextual kerning does not interpolate. But that is not much of a biggie, usually. Remember that the additional contextual kerning does not replace the other kerning pairs you already have, but it gets added on top of them.

Except for regular, non-contextual kerning, Glyphs does not give you GPOS preview in the edit view. That’s bad luck for us contextual kerners. But there’s an easy workaround: Just keep exporting your fonts to the Adobe Fonts folder and you can test your kerning triplets, quadruplets and quintuplets in InDesign right away. After all, this is where it counts because it’s where people are going to use it.

SAMPLE FONT: PLAYFAIR DISPLAY, COURTESY OF CLAUS EGGERS SØRENSEN.