How to Save a Font File in FontForge Using Python
This guide explains how to save and export font files using the
Python scripting module in FontForge. Depending on whether you want to
save your project in the native FontForge format or export it as a
standard font like TrueType or OpenType, FontForge provides two distinct
methods: save() and generate().
Saving the Native
Spline Font Database (.sfd)
To save your font project in FontForge's native format
(.sfd), use the save() method on the font
object. This preserves all internal FontForge metadata, guides, and undo
history.
import fontforge
# Open or create a font
font = fontforge.open("MyFont.sfd")
# Save modifications back to the SFD file
font.save("MyFont_Updated.sfd")If you do not specify a filename inside save(), it
overwrites the currently open file.
Exporting Usable Font
Files (.ttf, .otf, .woff)
To compile and save the font as a standard, installable font file,
use the generate() method. FontForge automatically detects
the output format based on the file extension you provide.
import fontforge
font = fontforge.open("MyFont.sfd")
# Export as OpenType (CFF)
font.generate("MyFont.otf")
# Export as TrueType
font.generate("MyFont.ttf")
# Export as Web Open Font Format
font.generate("MyFont.woff")The generate() method can also accept optional flags,
such as bitmap formats or validation settings, but passing the target
file path with the desired extension is the standard command required to
save a working font file.