How to use Apple’s font tools to tweak a font

I used Apple’s font tools to fix the line-height of a font for an iOS app. Here’s how I did it.

Recently I was working on embedding a custom font into the Neighbor iOS app. I discovered that the font I was trying to embed had an issue with the rendered line height, and looked terrible on an multi-line string. Rather than trying to convert everything to an attributed string, I decided to try to make changes to the font itself. Here are the steps I took to make that happen, and some gotchas I ran into:

(I’m assuming that you’re using macOS if you’re reading this. I don’t know if this would work on any other operating system.)

Note: after this article was written, I was directed to a download page for a more current version of Apple Font Tools that installs without any issues. I haven’t tested that install, so your mileage will vary, but that might be something to try before doing steps 1 and 2. Thanks @mhuletdev for pointing this out to me.

1. Download Apple’s (free!) Font Tools

Turns out that Apple has a set of command line font tools that (among other things) enable you to manipulate a font as an xml file. You can find those tools on Apple’s developer font page. On the bottom right you’ll find “Download the Apple Font Tool Suite”. You’ll need an Apple developer account to access the files (you can get an account for free).

Once you log in, download the OS X Font Tools released in 2011. The file to download is “OS X Font Tools Release 4, beta 1.dmg”. You’ll notice that this was released 7 years ago–this is the first gotcha that we’ll have to get around.

2. Install the Font Tools

Because the tools were released so long ago (and haven’t been updated since then), installing the font tools isn’t straightforward, but it’s still possible. Here’s a gist with all the steps you’ll need:

3. Use the font tools to modify a file

Now that the font tools are up and running, you’re off to the races! In my particular font, the spacing between the line was really poor, so I decided to work on increasing the ascender property of the font.

In order to edit the properties, you have to convert a font into an xml file, edit the file, and convert it back. I’m working with a font called Sailec, so you’ll see that as the font name in the commands I use. I’ve also not tried to run these from another directory, because I’m fairly sure that you need to have the xml file output in the same directory (for when you convert it back)

3a. Convert the font to xml

To convert a font, you run:

ftxdumperfuser -t hhea -A d {font_name}

This outputs an xml document with a table called hheaTable. Here’s what the Apple documentation describes this table as:

The 'hhea' table contains information needed to layout fonts whose characters are written horizontally, that is, either left to right or right to left. This table contains information that is general to the font as a whole. Information which pertains to specific glyphs is given in the 'hmtx' table defined below.

The table looks like this (in my case):

<hheaTable
versionMajor=”1"
versionMinor=”0"
ascender=”750"
descender=”-250"
lineGap=”250"
advanceWidthMax=”1226"
minLeftSideBearing=”-209"
minRightSideBearing=”-210"
xMaxExtent=”1188"
caretSlopeRise=”1"
caretSlopeRun=”0"
caretOffset=”0"
metricDataFormat=”0"
numberOfHMetrics=”497"
/>

I increased the ascender property, and after some trial and error, I found that 1000 worked best for my use case and for this font.

3b. Convert the xml back to a font

To convert it back to a font (with the changed values), you use the command:

ftxdumperfuser -t hhea -A f {font}

This takes the values from the hhea table that you just edited and modifies the font to use those values.

Additional Reading