Kerning glyphs with negative sidebearings in initial/final position

Adam JagoszAdam Jagosz Posts: 688
edited September 2018 in Technique and Theory
So is that even a thing? I felt like it would make sense when I was testing my font using the famous Pablo Impallari's template:
The solution is pretty straightforward, but requires us to keep the list of all glyphs in the font within a class (here any):
<b>feature </b>kern {<br>&nbsp;&nbsp;&nbsp; <b>lookup </b>kerning1 {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>ignore pos</b> <i>@any</i> [ f f.swsh j p y ]';<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>pos </b>f' <60 0 60 0> ;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>pos </b>f.swsh' <510 0 510 0> ;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>pos </b>j' <235 0 235 0>;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>pos </b>p' <20 0 20 0>;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>pos </b>y' <25 0 25 0>;<br>&nbsp;&nbsp;&nbsp; } kerning1;<br>&nbsp;&nbsp;&nbsp; <b>lookup </b>kerning2 {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>ignore pos </b>[ f f.swsh ]' <i>@any</i>;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>pos </b>f' <0 0 60 0> ;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>pos </b>f.swsh' <0 0 190 0> ;<br>&nbsp;&nbsp;&nbsp; } kerning2;<br>} <b>kern</b>;
This will increase the left sidebearing at the beginning of the glyph run and the right sidebearing at the end.

Is this approach at all practical or useful, have you ever implemented this or something similar? Is there an easy way to do this in any of the apps/tools you use? Now that I come to think of it, you could just write a script checking the sidebearings in all glyphs and applying appropriate kerning.

One way of thinking is that resolving such issues is responsibility of the layout engine or the typesetter. But obviously most people are not even aware this could be an issue:

Fixing a bug like above wouldn't be really obvious, I think at least some (if not most) design environments just take the advance width of the text as equivalent of the bounding box.

From my experiments, MS Word uses advance width to center text. So text with applied kerning of this kind would be centered more precisely, if that is what you'd want. (Besides, I often find myself centering text in InDesign manually because the unique shapes of sidebearings (even positive) make for an illusion of misalignment... but that's another pair of shoes).


  • Try to change any formatting in the middle of the string. Like set on letter before the j in Bold. That will trigger your kerning. 
  • John HudsonJohn Hudson Posts: 2,940
    edited September 2018
    Trying to trigger any behaviour based on start- or end-of-line context is problematic, because OpenType Layout lookups have no line layout knowledge. You can fake it, using the kind of context statements you have here, but those substitutions are going to occur at all glyph run boundaries, not just at the beginnings ands end of lines.

    I used a similar mechanism for line-initial/terminal swashes and ornaments in the Gabriola font, but am wary about recommending it for any critical functionality such as spacing.
  • I had similar issue with several Arabic letters, what I did is instead space the glyphs for line boundary situation, and kern them with other Arabic characters as needed. This is more cumbersome, but also more reliable and also makes sure the glyphs don’t overlap with text set in other fonts around them.
  • Just to expand on John’s comment: some apps break glyph runs at every word space! So those apps will get your beginning/end of line effect on ever word.
  • Adam JagoszAdam Jagosz Posts: 688
    edited September 2018
    Try to change any formatting in the middle of the string. Like set on letter before the j in Bold. That will trigger your kerning.
    Good point, but “any” is not a good word — it depends. Even adjacent HTML spans are not necessarily treated as separate runs, for instance, positioning marks and even substitutions work on Windows in Firefox (though not Edge or Opera): Codepen.

    As to Microsoft Office Word, similarly, just changing color or applying underline or crosstroke doesn't break the glyph run — you'd have to change font size or the font altogether. The same in InDesign:
    Here coloring half of the ligature didn't go all that well, and for the best. Those software designers are smarter then you would think. the glyphs for line boundary situation, and kern them with other Arabic characters as needed.
    I always felt like this approach was the best bet. Making the font work as good as possible without OT, choose the solutions that incur minimal damage, and only then polish it up with OT. So... why does nobody do that? Those f's should not hang over by default in an “invincible” font. I guess it's just because too much space after an f is deemed a greater damage than an f cut off at the end of a run.
    Probably this logic made more sense with your Arabic work than with Latin. Suppose you wanted to embolden half of a word, and the second half begins with the problematic character. Now it doesn't matter if it is kerned away from the beginning of a glyph run, or spaced generously by default: it is spaced away from the first half, and it's a lose-lose — better not to come up with weird ideas trying to save the world.
    For what it's worth, such positioning could be included... as a stylistic set. A nice substitute of the software “center by bounding box”/“align bounding box with margin” switches. Come to think of it, a CSS property like this could be useful too.

Sign In or Register to comment.