Update [kern] feature with Python in FL

Marten Thavenius's picture

Is it possible to execute the FontLab 5 “Update [kern] feature” command with Python using some of the FL/Python methods or a MenuCommand from Python?

When generating class kerned instances from a MM design it is kind of boring to go into the Kerning Assistance dialog and push the “Update [kern] feature” button for all instances each time you build a new version of a family to be tested.

Any other recommendations to optimize this workflow if there is no Python way?

k.l.'s picture

Yes you can. The font object has a method


But then, you may also consider using AFDKO's function for generating the kern feature. I think it is in a separate module which you could call from your script.

k.l.'s picture

It seems that .MakeKernFeature() does not add a kern feature to the font directly. Rather, it returns a Feature object which needs to be added to the font's feature list in an additional step:

    f = fl.font
    kernFeature = f.MakeKernFeature()
    # delete existing kern feature:
    for feaIdx in range(len(f.features)-1,-1,-1):
        if features[feaIdx].tag == "kern":
              del features[feaIdx]
      # append new kern feature to feature list:


pvanderlaan's picture

Thanks, that's very helpful Karsten.

Is there also a method for compiling the OpenType features in FontLab?

Or is there documentation of all the Python objects in FontLab 5 somewhere online? Sadly the unofficial FontLab 4.5 Python reference hasn't been updated for ages...



k.l.'s picture

Hello! Recently I found OTCompile in the reference, so you could try using this by way of fl.CallCommand(). But I have not tried it yet. (I remember problems when reading fl.output in FLS5/Mac, so could not check if there are compilation errors.)

Best wishes, Karsten

Miguel Sousa's picture

In case you don't care about updating the 'kern' feature in the VFB file, but still want to have the OTF fonts generated with an up-to-date 'kern' feature, an alternative approach is to play around with the FontLab's Preferences (a.k.a. Options) via Python scripting. Here's the code snippet,

# Start the script by checking if the option 'Generate
# OpenType "kern" feature if it is undefined or outdated'
# is turned on. Turn it on if it's currently off.
revertPreferences = False
if (Options().TTEWriteKernFeature == 0):
    Options().TTEWriteKernFeature = 1
    revertPreferences = True

# Here make the script do whatever it needs to do,
# including generating the OT font(s)

# Finalize the script by reverting the option,
# in case it has been changed
if (revertPreferences == True):
    Options().TTEWriteKernFeature = 0

Syndicate content Syndicate content