Python-fontforge is definitely a godsend
After the Robothon, and being very impressed with the power of Robofab and its
associated toys, i was looking for a similar toolkit for GNU/Linux systems.
Didn’t have to look very hard — actually, only had to look back: i had dabbled
with the **python-fontforge library** some months ago while building
[Lettersoup][ls].
The fontforge Python module is a beautiful hidden treasure in the turf of FLOSS
typography. Going along with George Williams’s characteristic [subtlety and low
profile][gw], it’s hard to find any mention of it anywhere, even inside the
free software press.
Given the excitement surrounding Robofab, it’s only fitting that the FLOSS
typography camp takes the time to rear its head towards python-fontforge.
Actually, there’s a few reasons for it to be of interest to anyone remotely
interested in coding type, even those who are used to FontLab for that; here’s
a few reasons why:
* It snugly ties the loose ends to form a truly **free, non-proprietary
toolchain** for type design work. The Fontforge application is already a
wonderful and complete editor. With python-fontforge, scripting is no longer an
exclusive of FontLab.
* Unlike Python scripting in FontLab, scripts written using the fontforge
module can be run **independently of the GUI application**. No dialogues, no
drop-down menus, no chrome in the way — just as scripting should be.
* The **[documentation][doc]** is dense, packed into one big HTML page, but
very rich and complete; if one knows what’s needed but can’t find the right
command, it’s surely in there (and if not, the [fontforge-devel][ml] mailing
list will be quick to enlighten you).
* It’s totally ready to work with **Spiro splines**, a wonderful alternative to
bézier curves to design type and lots of other beautiful shapes. If you haven’t
heard of them, you [totally need to][spiro]. I mean, right now.
* There’s an embrionary **[repository][scripts]** of python-fontforge scripts
over at SourceForge. Hopefully, it will grow as more people notice the power of
this hidden gem.
Some months ago, i hastily made a script to turn a set of SVG files (named
[a-z].svg) into a .ttf file. Here’s the code, for what it might be worth.
#!/usr/bin/env python
# svg2ttf v0.1
#
# copyleft 2008-2009 ricardo lafuente
#
# generate a .ttf file from a set of .svg files with the lowercase alphabet
#
# before running this script, create a blank font file in Fontforge
# (make a New font and save it as it is) and change the BLANK_FONT location
#
# you might also want to edit the metadata (title, license, etc.) before
# saving it, or just edit the blank.sfd file afterwards
#
# finally, change the LETTERS_DIR value to the folder where your .svg
# files are; they ought to be named [a-z].svg
LETTERS_DIR = ‘~/Desktop/svgletters/’
BLANK_FONT = ‘~/Desktop/blank.sfd’
letters = ‘abcdefghijklmnopqrstuvwxyz’
# right-o, here we go
import fontforge
# open a blank font template
# TODO: dynamically generate the space character
font = fontforge.open(BLANK_FONT)
for letter in letters:
# make new glyph
font.createMappedChar(letter)
# import outline file
# notice that font[glyphname] returns the appropriate glyph
# fontforge is awesome :o)
font[letter].importOutlines(LETTERS_DIR + ‘/’ + letter + ‘.svg’)
# same spacing for each letter, this is a hack after all
font[letter].left_side_bearing = 15
font[letter].right_side_bearing = 15
# generate TrueType hints
# font[letter].autoInstr()
# create the output truetype file
font.generate(‘output.ttf’)
Have you worked with python-fontforge? Blogged about it? Made an awesome script
or two? Let me know in the comments section — i’m pretty sure i’m not alone in
my fascination :-)
**Update**: Dear feed readers, please pardon my multi-post ineptitude; i’m
still trying to get the hang of posting through [vim](http://www.vim.org) –
one less mistake i’ll be making in the future.
[nudge]: http://betatype.com/node/18 (Interpolated Nudge macro)
[ls]: http://tinkerhouse.net/lettersoup
[gw]: http://ospublish.constantvzw.org/type/i-think-the-ideas-behind-it-are-beautiful-in-my-mind
[doc]: http://fontforge.sourceforge.net/python.html
[ml]: https://lists.sourceforge.net/lists/listinfo/fontforge-devel
[spiro]: http://www.levien.com/spiro/
[scripts]: http://fontforge.wiki.sourceforge.net/scripts
hey looking nice script , if it succesfully run can prove to great help in my college project
but it showing some error
./svg2ttf: line 16: LETTERS_DIR: command not found
./svg2ttf: line 17: BLANK_FONT: command not found
./svg2ttf: line 19: letters: command not found
./svg2ttf: line 26: syntax error near unexpected token
('font = fontforge.open(BLANK_FONT)’./svg2ttf: line 26:
i m using on ubuntu 8.10
kindly help me , my email id vinay.rks@gmail.com
My fault — i had forgotten to include the ‘shebang’ line in the very beginning; without it, the bash interpreter was trying to read it as a bash script, instead of calling Python.
Now corrected, many thanks :) (alternatively, you could run it using the ‘python svg2ttf’ command)
This is great! Thanks for this blog. I am starting development and this will be a big help.
This is great. Thank you.