How to Export WOFF and WOFF2 from FontForge
Exporting web font formats like WOFF and WOFF2 directly from FontForge allows designers and developers to prepare custom typefaces for fast, modern web rendering. This guide details the step-by-step process of configuring and generating these compressed formats using FontForge’s graphical interface, as well as an automated command-line method for batch processing.
Prerequisites
To generate WOFF and WOFF2 files, ensure you are running an
up-to-date version of FontForge. Modern releases come pre-compiled with
the necessary compression libraries (libbrotli for WOFF2
and zlib for standard WOFF). If WOFF2 is missing from your
export options, update to the latest build available for your operating
system.
Step-by-Step GUI Export
Open Your Font File Launch FontForge, go to File > Open, and select your existing font file (
.ttf,.otf, or.sfd).Verify Font Metadata Before exporting, confirm that your font's naming and metrics are intact:
- Navigate to Element > Font Info.
- Under PS Names, confirm that the Family Name, Weight, and Fontname fields are populated correctly to avoid web rendering conflicts.
- Click OK to close the window.
Open the Export Window Go to File > Generate Fonts... (or press
Ctrl+Shift+G/Cmd+Shift+G).Select the Web Format
- Beneath the file directory browser, find the format dropdown menu (it typically defaults to TrueType or OpenType).
- For standard Web Open Font Format: Select Web App Format (WOFF).
- For the modern, highly compressed format: Select Web App Format 2 (WOFF2).
Configure Generation Options
- Click the Options button next to the format dropdown.
- Ensure standard flags such as Validate Before Saving and Round to Int are checked or unchecked according to your project's technical specifications.
- Click OK.
Generate the File
- Choose your desired output directory and file name.
- Click Generate.
- If a validation warning pops up, review any non-fatal glyph warnings. For standard web deployment, minor glyph errors can often be bypassed by clicking Generate again in the warning dialog.
Repeat this process for each font style and weight you need to deploy.
Exporting via Python Scripting
FontForge includes a Python module, allowing you to batch convert multiple desktop font files to WOFF and WOFF2 without opening the user interface.
Save the following code as convert_to_webfonts.py:
import fontforge
import sys
def convert_font(input_path):
# Open the source font
font = fontforge.open(input_path)
# Base output filename without extension
base_name = input_path.rsplit('.', 1)[0]
# Generate WOFF
font.generate(f"{base_name}.woff")
# Generate WOFF2
font.generate(f"{base_name}.woff2")
font.close()
print(f"Generated WOFF and WOFF2 for {input_path}")
if __name__ == "__main__":
if len(sys.argv) > 1:
convert_font(sys.argv[1])
else:
print("Usage: fontforge -script convert_to_webfonts.py fontfile.ttf")Run the script from your terminal using:
fontforge -script convert_to_webfonts.py MyFont-Regular.ttfThis creates both MyFont-Regular.woff and
MyFont-Regular.woff2 in the same directory as the source
font.