How to Auto-Hint All Glyphs in FontForge with Python

This article explains how to automate the auto-hinting process for an entire font using FontForge's Python scripting module. By writing a short, standalone script, you can load a font, select every glyph, calculate optimized PostScript or TrueType hinting instructions, and output the updated font file without manually using the graphical user interface.

The Python Script

To auto-hint every glyph, open the target font, select all glyphs, and execute the autoHint() method on the selection.

import fontforge

# Load your font file (.sfd, .ttf, .otf, etc.)
font = fontforge.open("input_font.ttf")

# Select all glyphs in the font database
font.selection.all()

# Apply auto-hinting to the current selection
font.autoHint()

# Generate the hinted font output
font.generate("hinted_font.ttf")

# Close the font file
font.close()

Alternative: Per-Glyph Iteration

If you need finer control—such as skipping specific glyph slots or logging hints as they process—iterate through the glyph list individually:

import fontforge

font = fontforge.open("input_font.ttf")

for glyph in font.glyphs():
    glyph.autoHint()

font.generate("hinted_font.ttf")
font.close()

Running the Script

FontForge provides its own Python environment. Run your script from your command-line interface using the -script flag:

fontforge -script autohint_script.py

If you are using FontForge installed as a standard Python module (import fontforge) inside an existing Python environment, execute the script with your system's Python interpreter instead:

python autohint_script.py