Tag Archives: code

Optical kerning demo

I’ve finally found the time to get the RoboFab libraries for Python working for me, and I’ve coded the core of the optical kerning algorithm that’s been rattling around in my head for a few years. My test input font consists of six characters meant to imitate A, V, H, O, t, X and a diamond shape. I was only expecting the algorithm to generate approximate kernings that would need to be tweaked by hand, but surprise, surprise; it’s almost perfect:


The only problem really is the tXt kerning, and that’s more an artifact of the too-regular, sans-serif shape of the glyphs.

The algorithm takes 1.7 2.6 seconds (wall time) to generate kern pairs for the 49 36 combinations of these seven six glyphs (including the time to read the font off disk, and convert it to UFO, and write that back to disk). That works out to faster than 0.036 0.072 seconds per glyph pair. Implementing the algorithm in C and caching the most common digraphs/kerning pairs might make it fast enough to use in a text-editing or layout program. (Struck out items are from before I added the diamond glyph and re-wrote some parts of the algorithm to be cleverer.)

Next step is to clean it up into a real application and run it on a full set of glyphs from a serif font, and compare the result with the font’s hand-kerning.

A good, fast optical kerning algorithm would even let you kern together different faces and different sizes. Wow, this is exciting.