FontForge Python Extension API Documentation

FontForge provides a dedicated Python extension that allows users to programmatically create, edit, inspect, and convert font files. This guide details the primary documentation sources available for navigating the FontForge Python extension API, including the official online reference manuals, built-in interactive shell helpers, underlying source code, and community-maintained examples.

Official Online Documentation

The primary documentation for the FontForge Python module is published as part of the official FontForge manual. It is structured into multiple functional sections:

  • Module Overview: Explains how to import and initialize the fontforge module both within the FontForge graphical interface and inside external standalone Python scripts.
  • Core Object References: Detailed pages covering the primary classes used in font manipulation, including fontforge.font, fontforge.glyph, fontforge.contour, fontforge.point, and fontforge.layer.
  • Methods and Attributes: Exhaustive listings of properties (such as metrics, Unicode values, and glyph names) and functions (such as auto-tracing, generating output formats, and applying transformations).
  • Constants and Enums: Tables defining font flags, lookup types, OpenType table tags, and validation states.

Built-in Python Introspection

Because the extension exposes compiled Python C bindings, complete runtime documentation is accessible directly through the Python interpreter. Developers can use Python's built-in inspection utilities to review functions, signatures, and docstrings without leaving the terminal:

  • Interactive Help: Running help(fontforge) provides a comprehensive index of the module's exposed classes, functions, and documentation strings.
  • Class Inspection: Inspecting individual components using commands like help(fontforge.font) or help(fontforge.glyph) displays available methods, expected parameters, and attribute behaviors.
  • Namespace Enumeration: Executing dir(fontforge) returns all accessible attributes, constants, and sub-objects present in the specific compiled version in use.

Transition Documentation from Legacy Scripting

FontForge originally used a proprietary scripting language (.pe scripts). The official documentation includes dedicated transition guides that map legacy scripting commands to their modern Python equivalents. This section is particularly useful for translating older FontForge scripts and workflows into standard Python 3 code.

C Source Code and Header Files

When online documentation lacks details regarding edge cases, default parameters, or return values, the FontForge source code serves as the ultimate reference. The Python API bindings are primarily implemented in C within the FontForge source tree:

  • fontforge/python.c: Implements the main module functions and glue logic between Python and FontForge's internal data structures.
  • Class-specific files: Files such as fontforge/pyfont.c and fontforge/pyglyph.c define the exact method tables, parameter parsing logic, and exception-raising conditions for the respective API objects.

Example Scripts and Developer Resources

The FontForge source repository maintains an examples directory featuring complete automation scripts. These show real-world implementations of tasks such as batch font conversion, automated metric adjustments, OpenType feature file merging, and glyph generation. Additionally, type design forums and public open-source font repositories frequently maintain functional boilerplate scripts demonstrating standard API usage patterns.