How to use Apple 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.

June 19, 20186 min read

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.)

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:

# Mount the font tools dmg as a volume on your Mac
hdiutil attach ~/Downloads/osxfonttools.dmg
# Navigate into the volume and copy
# the main .pkg file somewhere locally
# so you can manipulate it
cd /Volumes/OS\ X\ Font\ Tools/
pkgutil --expand OS\ X\ Font\ Tools.pkg ~/fontTools && cd ~/fontTools
# If you ls, here's what's in the file
# Distribution fontTools.pkg keyboardTools.pkg
# Resources fonttoolbox.pkg
# We'll be going into the fontTools.pkg first,
# and then going into the fontToolbox.pkg
# The fontTools.pkg includes the actual executables
# that we want to use to manipulate fonts
# navigate into the directory and use gunzip + tar
# to get at the files
cd fontTools.pkg
mv Payload Payload.gz && gunzip Payload && tar -xvf Payload
# If that command succeeded, you'll see the following output:
# x .
# x ./._.DS_Store
# x ./ftxanalyzer
# x ./ftxdiff
# x ./ftxdumperfuser
# x ./ftxdumpfond
# x ./ftxenhancer
# x ./ftxfissioner
# x ./ftxfusefond
# x ./ftxglyphadder
# x ./ftxinstalledfonts
# x ./ftxmakettc
# x ./ftxruler
# x ./ftxsplitter
# x ./ftxstamper
# x ./ftxsummarizer
# x ./ftxvalidator
# Additionally, all of those ftx* files will be in
# the current directory
# Move the executables to your local/bin so that
# they're in your bash path
mv ftx* /usr/local/bin
# At this point, you can successfully call any of the
# executables in your bash path, but they'll fail because
# they rely on FontToolbox.framework to be in /Library/Frameworks
# Navigate into the fonttoolbox.pkg directory and get at
# the payload like we did earlier
cd ../fonttoolbox.pkg
mv Payload Payload.gz && gunzip Payload && tar -xvf Payload
# This outputs a FontToolbox.framework folder in that directory
# Move that framework to the appropriate folder in /Library
# You need to sudo this command because of restrictions on the
# system level /Library folder
sudo mv FontToolbox.framework /Library/Frameworks/FontToolbox.framework
# If you made it this far, you should be able to use the
# Apple font tools from the command line!

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):


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

This article was originally published on Medium.