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 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.
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.
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.