contextual kerning in RB, MM?



  • Hi,
    I would like to kern A space V but not A space and space A. Is there way how to do it? I know you can do it directly in OpenType. Can somehow be merged kerning feature file with a MM kerning? Or can I do it directly in RoboFont using Python? Thanks!


  • admin

    hello @jansindl3r,

    you could try converting the font’s kerning into kern feature code with MetricsMachine:

    import metricsMachine
    font = metricsMachine.CurrentFont()
    kernFea = font.kerning.compileFeatureText()
    

    …then add your triplets there, and add the kern feature to the font features.

    good luck! let us know if it works



  • @gferreira thanks! I see that all the features are strings. It would be nice to have some sort of parser that creates classes or a dictionary out of it so I can just say features['kern'].append('blablabla')

    As a first prototype this works well. It's a bit clumsy though. The SpaceCenter preview doesn't preview it, but it exports correctly and FeaturePreview extension shows it correctly as well.

    import metricsMachine
    
    font = metricsMachine.CurrentFont()
    kernFea = font.kerning.compileFeatureText()
    
    closer = '} kern;'
    additions = [
        "pos V space' V -125"
        ]
    additions = [' '*4+i+';' for i in additions]
    additions = '\n'.join(additions)
    kernFea = kernFea.replace(closer, f'{additions}\n{closer}')
    font.features.text = kernFea
    

  • admin

    That is possible with fontTools feaLib. See https://fonttools.readthedocs.io/en/latest/feaLib/