How to Merge Kerning Classes in FontForge

While FontForge does not provide a direct one-click "Merge Classes" command, you can merge two kerning classes into one through the Font Info dialog or by using the FontForge Python scripting API. Merging is achieved by combining the glyph lists of both classes into a single target class, verifying the kerning offsets, and removing the redundant class. This guide explains how to perform this consolidation using the graphical interface and Python.

Merging Kerning Classes Using the GUI

To manually combine two classes within FontForge's user interface, follow these steps:

  1. Open the Lookups Window:
    • Go to Element > Font Info (or press Ctrl+Shift+F / Cmd+Shift+F).
    • In the left sidebar, click on Lookups.
    • Switch to the GPOS tab at the top.
  2. Locate the Kerning Subtable:
    • Expand the horizontal kerning feature (usually tagged as 'kern' Horizontal Kerning).
    • Select the subtable containing the pair-to-pair or class-to-class kerning data.
    • Click the Edit Data button to open the Kerning Class window.
  3. Combine the Glyphs:
    • Identify the two classes you want to merge (Class A and Class B).
    • Open Class B, select all glyph names listed in its field, and copy them.
    • Open Class A and paste the copied glyph names into the glyph list, ensuring names are separated by spaces.
    • Click OK to update Class A.
  4. Delete the Redundant Class:
    • Select the now-redundant Class B.
    • Click Delete to remove it from the subtable.
    • Ensure that the kerning values assigned to Class A are accurate for all newly included glyphs.
  5. Apply Changes:
    • Click OK in the Kerning Class editor window, then click OK in the Font Info dialog to save your structural changes to the font database.

Merging Kerning Classes with Python Scripting

If you manage large fonts or multiple class pairs, FontForge’s Python module allows you to automate the process by manipulating the class tuple directly:

import fontforge

font = fontforge.open("font.sfd")

# Example lookup and subtable names
subtable = "kern_horizontal_class"

# Get current classes: returns a tuple of lists containing glyph names
first_classes, second_classes = font.getLookupSubtable(subtable)

# Combine two class lists (e.g., merging index 2 into index 1)
first_classes[1].extend(first_classes[2])
del first_classes[2]

# Update the subtable with modified classes
font.alterLookupSubtable(subtable, (first_classes, second_classes))
font.save("font.sfd")

Important Considerations Before Merging

  • Kerning Value Discrepancies: If the two original classes had different kerning values against other classes or individual glyphs, merging them forces all member glyphs to share the same offsets. Note any manual exceptions before deleting the secondary class.
  • First vs. Second Operand: Kerning lookups treat the left glyph (first operand) and right glyph (second operand) as separate sets. Ensure you are merging classes that reside on the same side of the kerning pairs.