Update Font Version Strings Using FontForge Python
Updating font version strings is essential for tracking font releases, managing typography projects, and avoiding system font cache conflicts. This guide provides a direct, scriptable method using FontForge's Python API to automate the modification of font version numbers and their corresponding OpenType metadata fields.
Understanding Font Version Fields
In FontForge, a font version is stored in two primary places:
- Font Revision (
headtable): A decimal value stored as a string or float in FontForge (e.g.,"1.002"). - Version String (
nametable, Name ID 5): A human-readable string typically formatted as"Version 1.002"or"Version 1.002;Build 2023".
To ensure system compatibility, both fields should be updated concurrently.
The Python Script
The following script opens an existing font file, updates both the
font revision attribute and the OpenType name table version
string, and generates an updated font file.
import sys
import fontforge
def update_font_version(font_path, output_path, new_version_number):
"""
Updates the version strings of a given font file.
:param font_path: Path to the input font file (.ttf, .otf)
:param output_path: Path where the modified font will be saved
:param new_version_number: Version number as a string (e.g., "1.002")
"""
# Open the font
font = fontforge.open(font_path)
# 1. Update the font revision in the 'head' table
font.version = new_version_number
# 2. Format the OpenType Name ID 5 string
version_string = f"Version {new_version_number}"
# 3. Update the 'name' table (Name ID 5)
# FontForge allows updating SFNT names using language and string name
font.appendSFNTName('English (US)', 'Version', version_string)
# 4. Generate the updated font file
font.generate(output_path)
font.close()
print(f"Successfully updated {font_path} to version {new_version_number}")
if __name__ == "__main__":
if len(sys.argv) < 4:
print("Usage: fontforge -script update_version.py <input_font> <output_font> <version>")
sys.exit(1)
input_file = sys.argv[1]
output_file = sys.argv[2]
version = sys.argv[3]
update_font_version(input_file, output_file, version)How to Run the Script
Because FontForge includes its own embedded Python interpreter, the
script is most reliably executed using the
fontforge -script command flag:
fontforge -script update_version.py input.ttf output.ttf 1.002If you have FontForge installed as a system-level Python module
(import fontforge works in standard Python), you can run it
directly:
python3 update_version.py input.ttf output.ttf 1.002Batch Updating Multiple Fonts
To update an entire directory of fonts at once, you can iterate through files matching standard font extensions:
import os
import glob
import fontforge
VERSION = "2.000"
FONT_DIR = "./fonts/*.ttf"
for font_file in glob.glob(FONT_DIR):
font = fontforge.open(font_file)
font.version = VERSION
font.appendSFNTName('English (US)', 'Version', f"Version {VERSION}")
font.generate(font_file)
font.close()
print(f"Updated {font_file} to {VERSION}")This overwrites the original files in-place with the updated metadata tables intact.