Xgridfit is a high-level, XML-based language for gridfitting, or "hinting," TrueType fonts. It aims to provide these advantages over the manual instructing of glyphs:
- replace the cryptic "mnemonics" of the TrueType language with descriptive instruction names;
- provide for the naming of points, control values, variables, functions and function parameters;
- provide macro capability for the easy and efficient handling of similar visual features of glyphs;
- provide high-level instructions (e.g. "diagonal-stem") to supplement the primitive instructions of TrueType;
- provide high-level programming constructs;
- manage the stack behind the scenes;
- manage reference points and zone pointers behind the scenes;
- provide methods and tools for managing instructions in large font projects;
- edit and augment existing instructions in fonts;
- support the FontForge auto-instructor and TrueType debugger.
- provide a simple method for adding new instructions to fonts that already contain them.
In short, it conceals the assembly language-like character of the TrueType instruction set behind a friendly façade and provides many of the conveniences of a high-level programming language.
There is much to be said for XML as the base for a programming language. True, it is ugly and verbose, but its verbosity contributes to its legibility. Lots of people are comfortable with XML, or at least understand the basics of it. And a decent XML editor (I suggest Emacs with nxml-mode) will do most of your typing for you, giving you all the advantages of verbosity and few of the disadvantages.
The Xgridfit program compiles an XML source file into tables and instructions that relate to the gridfitting of glyphs. Its output is a Python script that can be run in FontForge to perform one or more the following tasks:
- open a FontForge source file or TrueType font;
- Set Blue values;
- Run the FontForge auto-hinter and auto-instructor;
- add the CVT (Control Value), fpgm (font program) and prep (pre-program) tables produced by the Xgridfit compiler (if desired, without disturbing any programming already present in the font);
- add the glyph programs produced by the compiler (again, without disturbing any glyph programs already present in the font);
- set entries relevant to TrueType instructions in the maxp table;
- save a FontForge source file or generate a TrueType font.
Xgridfit does have its limits. First of all, it cannot think for you: you still must understand the basics of TrueType gridfitting. Some limitations are those of the TrueType engine itself, which is not capable of run-time type-checking or type conversion. Other limitations, such as the absence of for- and while-loops, are due to the limitations of the XSLT language in which it is implemented.
But Xgridfit does a few things very well, in my experience at least: it speeds up TrueType development considerably, it makes TrueType programming much more legible than before, it makes it easy to revise and reuse existing TrueType code, and it does these things while offering a level of control over the glyph outline that you can't get from the graphical tools that I've seen.
Xgridfit will run under Linux, Mac OS X and Windows (with Cygwin). These programs/libraries are required or suggested:
- GNU Make to run the install script.
- FontForge. Required to install instructions in fonts. Python extensions should be enabled. (The pre-built executable for Cygwin does not include Python capabilities, so you must either build from source or set the compiler to produce FontForge scripts-- see documentation for the -l command-line option). If you want to be able to view the results of your programming in FontForge, you must build it against FreeType libraries with the bytecode interpreter enabled. (Note that there are patent issues here.)
- Python. Version 2.4 or higher. The Xgridfit executable and several utilities are Python programs; and the default output of the Xgridfit compiler is a Python script.
- libxml2 and libxslt. Your system probably has libxml2 installed, but you might have to install libxslt. It is possible to use other XSLT processors with the Xgridfit compiler, but libxslt is still required for various utilities.
- Python bindings for libxml2. In Debian and Debian-based Linux distributions, look for the package python-libxml2. In Fedora, look for libxml2-python.
- A few standard tools, which are almost certainly present on your system: Bash, sed, grep, mktemp.