SOLVED Check Kerning



  • Hi,

    I want to improve my script for generating images of sample texts in (tiny)DrawBot directly from the ufo.
    Is there an easy way to check if two glyphs has a kerning value?

    thanks


  • admin

    There is the kerning attribute of a font
    see http://www.robofab.org/objects/kerning.html

    f = CurrentFont()
    print f.kerning[('A', 'V')]
    

    If there is group kerning, maybe you should flatten the kerning dict in a temporary dict.
    If the kerning is only available in the features, best is to compile the font it and read it back into RoboFont.

    good luck!



  • Merci.
    Indeed, there is some group-group and glyph-group and glyph-glyph kerning. So no way to get directly a value out the ufo?
    Will try the temp dict.

    Thanks Frederik!



  • This is a super late reply, but I wanted to know this for another task, and the thread didn’t really tell me how to find kerning info, because (at least currently) f.kerning[('A', 'V')] requires you to look up kerning by group names, not just glyph names.

    Here’s a RoboFont script that will work to find kerning values for any two glyphs, just by there glyph names:

    from ufoLib2 import Font
    from fontTools.ufoLib.kerning import lookupKerningValue
    
    # open the font with ufoLib2
    font = Font(CurrentFont().path)
    
    # show kerning value
    print(lookupKerningValue(("A","V"), font.kerning, font.groups))
    

    To run the script outside of RoboFont, just feed in a file path for the font:

    from ufoLib2 import Font
    from fontTools.ufoLib.kerning import lookupKerningValue
    
    # open the font with ufoLib2
    # replace the path with a relevant one
    font = Font("src/ufo/sans/Recursive Sans-Casual A.ufo")
    
    # show kerning value
    print(lookupKerningValue(("A","V"), font.kerning, font.groups))
    

  • admin

    FYI: fontParts has font.kerning.find(("A", "V")) dont know why its not in the documentation.