How to Export Font Metrics from FontForge
FontForge allows you to export various font metrics files, including Adobe Font Metrics (AFM), Printer Font Metrics (PFM), and TeX Font Metrics (TFM). This guide provides a direct, step-by-step walkthrough on how to generate these metric files alongside or independently of your font files using FontForge's graphical interface and scripting tools.
Exporting Metrics via the Graphical Interface
To generate font metrics files using the FontForge desktop application:
- Open your font project in FontForge (
File>Open). - Navigate to the top menu and select File > Generate Fonts....
- In the export dialog, select the main font format you are building (such as PostScript Type 1, TrueType, or OpenType).
- Click the Options button next to the format selection dropdown.
- In the Options window, locate the metrics options:
- Check AFM to generate an Adobe Font Metrics file
(
.afm). - Check PFM if you need a Windows Printer Font
Metrics file (
.pfm). - Check TFM if you require a TeX Font Metrics file
(
.tfm).
- Check AFM to generate an Adobe Font Metrics file
(
- Click OK to close the Options dialog.
- Choose the destination directory and file name, then click Generate. FontForge will create the font file along with the corresponding metrics files in the specified directory.
Exporting Only Metrics (Without Changing Outlines)
If you only need the metrics data and do not intend to modify your primary font distribution:
- Go to File > Generate Fonts....
- Select PostScript Type 1 (Binary) or another standard format.
- In Options, check the metric formats you require (e.g., AFM).
- Generate the files to a temporary folder, retain the generated
.afmor.tfmfile, and delete the unwanted font binary.
Exporting Metrics via Scripting
For automated build pipelines, FontForge’s Python module allows you to export metrics programmatically:
import fontforge
# Open the font file
font = fontforge.open("MyFont.sfd")
# Generate font with AFM metrics enabled
# The 'afm' flag instructs FontForge to write the .afm file
font.generate("MyFont.otf", flags=("afm",))Metrics Data Included
When FontForge generates an AFM or TFM file, it extracts:
- Glyph Dimensions: Bounding boxes, advance widths, and heights for every glyph.
- Kerning Pairs: Kerning tables defined in the font’s lookups.
- Font-Level Information: Italic angles, underline positions, x-height, and cap-height.
Ensure all kerning tables and glyph metrics are finalized in Metrics > Window before exporting to ensure the generated metrics files contain accurate layout data.