Proof of Concept: Contextual Kerning UI for Glyphs 3

All present-day font editors lack the option to define contextual kerning using a UI. I made a bunch of scriptlets that together form a tool to implement contextual kerning for Glyphs 3, hijacking the normal kerning user interface after a contextual kerning "mode" was activated.

It saves the contextual kerning values in Glyphs’ "Numbers" (named data points that can have different values per master) that can be referenced in feature code as variables ("Tokens"). This also works in glyphsLib.

The tool is usable, but I wish that font editors would one day implement such functionality natively, so I labelled it "Proof of Concept". If you run into any trouble using this, please let me know.

https://github.com/yanone/Yanone-GlyphsApp-Scripts/tree/main/Contextual Kerning

Comments

  • Grzegorz Luk (gluk)
    Grzegorz Luk (gluk) Posts: 161
    edited December 2022
    brilliant idea! And thank your example on github (pos L' space T -40) I discovered that 'space' in most programs nowadays don't break contextual chain, like a years ago!

  • thanks to this thread I started trying contextual kerning and solved the problem of WWW.A WWW.H in my font. I can confirm that it works in Scribus, Firefox, Chrome, Inkscape (with small bug). Small thing and make me a day  :)

  • Looking into contextual kerning recently has made me wonder how commonly used it is. How often do you all take advantage of the feature? Obviously milage will vary from font to font, but there are definitely instances where normal kerning just doesn’t seem to cut it. And if you do use it, are there common combinations of troublesome characters you end up targeting?
  • Comma and especially period is one top use case for me

    Take a letter such as TVWY (and maybe P), followed by a period or comma, and then another letter from TVWY.

    WITHOUT the second letter, I might kern the period or comma tighter against the first letter. But WITH that second letter, I want to not have the letters collide and have the period or comma centered between them.
  • Nick Shinn
    Nick Shinn Posts: 2,207
    edited November 19
    Er, isn’t kerning fundamentally already contextual?

    If one substitutes a different glyph for better fit, that is what I call (after John Hudson) dynamic ligaturing

    I’ve used it occasionally in serifed typefaces, e.g. for the f combinations with following b, h, k and l.
  • John Hudson
    John Hudson Posts: 3,186
    Er, isn’t kerning fundamentally contextual?
    Contextual, in this case, implies that the value of a kern adjustment between two glyphs varies depending on some other factor, such as the presence of a third glyph.

    I use contextual spacing adjustments* a lot in fonts for various Indic scripts, but seldom in Latin. The classic Latin use case—which mirrors one of the things that happens in Indic scripts—would be applying a positive kern adjustment between two glyphs when one of them takes a dynamically positioned combining mark glyph. So, for example if one has a fairly tight Tr kern pair, one might contextually loosen it if the r takes a combining mark above.


    * Not all of these are pair positioning adjustments as typical of kerning; some are contextual adjustments affecting the spacing or position of a single glyph.
  • Nick Shinn
    Nick Shinn Posts: 2,207
    edited November 19
    Contextual, in this case, 

    So, not to be confused with Optical Kerning.

    Kerning is already optical and contextual, why not have a more specific terminology, less likely to confuse simple folk like me? 

  • No, pair kerning is not contextual; nothing outside the kern pair affects it.

    This sense of “contextual” is in tune with both the general dictionary definition of “context,” and is also native to the OpenType specification itself. The OpenType spec has used it this way since version 1.0 nearly 30 years ago, so now is a bit late to object to it.



  • John Hudson
    John Hudson Posts: 3,186
    I suppose Nick is thinking of kerning in terms of local context, i.e. of kerning as an adjustment to the general spacing of glyphs when next to specific other glyphs. That’s a reasonable sort of common usage, but it isn’t an adequate technical usage because the technologies that apply that adjustment do not express the adjustment in terms of context, whereas in those technologies contextual has a precise meaning.
  • Nick Shinn
    Nick Shinn Posts: 2,207
    edited November 20
    Yes indeed. That is why I would have preferred a technical meaning that was worded differently than the common meaning. Still, thanks for explaining, I will try to wrap my head around it!
  • Looking into contextual kerning recently has made me wonder how commonly used it is. How often do you all take advantage of the feature?
    I'm a strong believer in decomposing marks - outside of Latin, it's almost essential, but even for various Latin styles (for example, handwriting), you can reduce the glyph count, binary size, and OTL rule complexity; instead of having "a", "a.init", "a.medi", "a.fina", "agrave", "agrave.init", "agrave.medi"..., take all the tashkil off and just have four variants of "a" plus mark.

    The downside of that is that any kerning you do on accented characters then has to be contextual. Generally only a few pairs/triples are necessary and I'm happy enough writing the rules by hand, but I can see why an interface to contextual kerning would help people.

    OTOH, many of the problems can also be solved in a slightly different way with contextual anchor positioning (move the dot across a bit) or contextual substitution (use a flatter accent), and Glyphs supports both of these things well enough already. Whether these alternatives suitably maintain your text colour will depend on your design.
  • Mark Simonson
    Mark Simonson Posts: 1,734
    edited November 20
    I recall that Apple's GX fonts could handle kerning triplets (for cases like the ones @Thomas Phinney mentions), although I don't remember the details. And I've never made any GX fonts.
  • I found this discussion on contextual kerning quite engaging. Back in October 2022, I gave a talk at the ATypI Tech Talks Conference where I discussed a technique I referred to as "Variable Contextual Kerning – Triplets." Following that, I published a tutorial that explores this topic using FontCreator.

    It's exciting to see innovative approaches, as contextual kerning can indeed enhance the typographic quality of fonts, and having tools that simplify this process is beneficial for the community.

    Since FontCreator is now available for Mac users as well, I thought it might be helpful to share this resource. The tutorial provides step-by-step guidance on adding contextual kerning through the OpenType Designer feature in FontCreator.

    The variable feature code used is 100% compatible with the upcoming official Adobe OpenType Feature File Specification Additions for Variable Values, currently under review and expected to become official in the first half of 2025.

    Hope this adds to the conversation.