Hinting crossbars with the HTIC

TrueType instructions make it possible to dynamically fit glyph outlines into the available pixel grid. Unfortunately, not many open-source tools support the manual creation of TrueType programs. Hence I have implemented the Humble Type Instruction Compiler, which can translate simplified plain text instructions into optimized TrueType bytecode.

And because modern rasterizers either ignore or super-sample horizontal instructions, hints can be further simplified by instructing the vertical direction only, as demonstrated by ttfautohint. I have explored this approach with the Oxanium font family.

Pesky crossbars

One of the remaining tasks to tackle was the vertical placement of (cross)bars, after the top and bottom of a glyph is snapped to the blue zones. Ideally, the proportional position and sharpness of a crossbar remains consistent within the other snapped stems.

The following figure illustrates a few possible bar placements. Note that the weight of horizontal stems is not rounded, in order to remain consistent with the unhinted vertical stems.

Alternative bar placements

In the first approach, the bar is simply interpolated within the stretched glyph, without snapping it to the grid. While this is the most accurate, the bar often falls between pixels and we get a blurry mess.

The second approach is used by fonts like Ubuntu and FiraGO. After interpolation, the bottom side of each bar is snapped to the grid, to ensure that all stems are rendered consistently. But while snapping a predetermined side is simple and efficient, it causes undesired distortions of the glyph shape. In the example, it would have been more accurate to snap the top of the bar instead.

A custom function

A traditional way to fix distortions is the use of control values or delta instructions, which becomes an exponential problem as the number of glyphs and font weights increases. For Oxanium, I have instead implemented a function that automatically snaps the optimal side of the bar, and thus combines consistent stem weights with proportional accuracy.

Steps of the custom placement function

The function first interpolates the top and bottom points of the bar within the stretched glyph. However, this also stretches the weight of the bar. To unstretch it, the top and bottom points are aligned at their common center, before each point is moved outward again by half their original distance. From this ideal position, both points are snapped to the grid. The point that was moved by the smaller distance then becomes the reference, and the other point is moved away from it by their original distance.

0248610
E {
SVTCA[y]
MIAP[r] 0 baseline
MDRP[stem] 10
MIAP[r] 2 capHeight
MDRP[stem] 4
CALL ipBar 6 8 2 0
IUP[y]
}
Calling the function in the glyph program of E

While the definition of the function is a bit unwieldy, its use is simple and efficient, since the HTIC automatically maps the function name and consolidates the parameters. And because the bar placement is calculated relative to the respective glyph measurements, the same glyph program can be used for any font weight, including the variable font.

Rendered Oxanium-Regular