Minor Truetype Font Editing on a Mac
(also: how to fix Consolas' baseline)Update December 5, 2011: Changed download link to the most recent version of Apple Font Tool suite, which is now x86 compatible.
With the release of Windows Vista, Microsoft included six new fonts that they commissioned for the occasion. They are the new defaults for Vista and Office. They’ve also made them available for Mac through Office as well as a handful of free (as in beer) utilities. I got them by following these instructions.
These new modern fonts are explicitly designed for display on computer screens with ClearType. Although Apple has a different philosophy on font rendering, the same basic premise is used in OS X. Besides all that (or, rather, because of it) these fonts are very pretty.
But there’s a problem, and you can see it in the image above. When packaging these fonts up for the Mac, Microsoft goofed on the baseline for Consolas. The icon previews below show it much more obviously.
In short: it’s annoying. And wrong. And the fix is after the break.
A bunch of Mac geeks across the web have run into this, but nobody has solved it completely. After stumbling across an oblique reference to some sort of metrics table embedded in the font, I started looking for a way to edit it. That’s when I happened across Apple’s suite of command line font editing tools. The main “workhorse” of the suite is ftxdumperfuser
, but it doesn’t edit the TTF files directly. Rather, it ‘dumps’ the TrueType data into plain text (xml) tables that you can edit and then ‘fuses’ the changes back into the font. Google has surprisingly little on this suite… it wasn’t easy to find (Hence this post).
Now, before going any further, a word of warning: Corrupted fonts can be very very bad. I did all this with an uninstalled font outside of the */Library/Fonts
directory. OS X is much more robust with font management than it used to be (Font Book will catch corruption before installing a font), but a corrupt font can still really mess stuff up. Continue at your own risk…
Download Apple’s OS X Font Tools—it will install the tools into /usr/bin
and the documentation into /Developer/Documentation/FontTools
.
Fire up Terminal, and navigate to the folder where you moved the Consolas*.ttf fonts. Now, you want to dump (-A d
) the height metrics (hhea
) table (-t
) into an editable xml file:
ftxdumperfuser -t hhea -A d Consolas.ttf
This creates an xml file in that directory titled Consolas.hhea.xml. Now the table parameters are editable! Open that xml file and correct the ascender, descender, and lineGap metrics:
And then fuse (-A f) it back into the font:
ftxdumperfuser -t hhea -A f Consolas.ttf
Repeat for each member of the family, and you’re done!
It’s a pretty cool suite. Emboldened by my success, I decided to modify a few glyphs that had been bugging me. I had previously tried to edit the TTF using the free FontForge, but never had any success recompiling it back into a complete proper font. The result always failed Font Book’s validation and often would display gibberish if I overrode it. I believe that the FontForge’s TTF import implementation isn’t quite complete, so it wasn’t exporting the complete font information.
With the 'glyf'
table, you can edit the raw hex that describes the contours of each glyph. So, I edited the glyphs I wanted in FontForge, and exported the TTF. While the font file didn’t work as a whole it still contained all the proper glyf information. I dumped the glyph info, grabbed the one I wanted, subbed it into the dump from the original, and fused it back together. And it worked! Now I have a proper baseline, and a Monaco style ‘l’ without the lower left serif (and the ‘i,’ too, for consistency).
Here’s the Hex data I used (139 is defined as the glyphRefID in the ‘cmap’ table for ‘i’, and 142 is ‘l’):
Consolas.glyf.xml:
...
Consolas Bold.glyf.xml:
...
Posted by Matt on Sunday, March 15, 2009