Change Em Square Size in FontForge Python

This article explains how to programmatically adjust the em square (units per em) of a font using FontForge's Python scripting module. You will learn how to scale the em size proportionally—which resizes the glyph outlines along with the font metrics—as well as how to alter the em square without scaling the existing glyph designs by adjusting the font's ascent and descent values directly.

Proportional Em Square Scaling

The most common way to change the em size in FontForge is by assigning a new integer value directly to the em attribute of the font object. When you change this property, FontForge automatically scales all glyph outlines, kerning, ascent, and descent proportionally to fit the new coordinate space.

import fontforge

# Open the font file
font = fontforge.open("input_font.ttf")

# Check the current em size (typically 1000 or 2048)
print(f"Current em size: {font.em}")

# Set the new em square size
# Standard TrueType sizes are usually 1024 or 2048; PostScript/CFF uses 1000.
font.em = 1000

# Save or generate the modified font
font.generate("output_font.ttf")
font.close()

Changing Em Size Without Scaling Glyphs

If you need to change the total em square size without altering the physical scale of the glyph outlines, modify the ascent and descent properties individually. In FontForge, the em size is defined as the sum of the ascent and descent (em = ascent + descent). Setting these values directly bypasses the automatic glyph outline transformation.

import fontforge

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

# Set ascent and descent independently (e.g., to create an em square of 2048)
font.ascent = 1638
font.descent = 410

# Verify the new em size
print(f"Updated em size: {font.em}")

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

Running the Script

FontForge uses its own embedded Python interpreter. Run your script through the command line using the fontforge executable with the -script flag:

fontforge -script adjust_em.py