Scripting for production

Production

In the production phase of a font it all comes together: moving stuff around, naming, interpolations, quality control, generating, database work, it pays to invest some time (or money) in some really good scripts. Each foundry and designer has their own preferred ways of doing things. It's impossible to describe one production process and please everyone. So instead we're going to look at some of the things you probably have to do anyway. You will have to match and adapt for your own methods.

Production scripts can save a lot of time. But be careful: it is costly to make mistakes with your production sources. Make sure to test production scripts first on duplicate data, preferably in a different folder. Doing something "quickly" to a massive kerning table only to discover it was your only copy, and the action was wrong — will not save you any time. Like carpentry: measure twice, cut once.

Batch processing

Here are some examples of applying changes to several fonts at once using AllFonts(). Keep in mind that this applies to all fonts you have open in FontLab. So make sure to close any fonts that you don't want treated this way before running the script.

Obviously you can extend these to do lots more.

This is a more complex script. It iterates through all open fonts, collects some data in each and finally asks for a place to save all the data in a text file.

This asks for a folder, then proceeds to save all open fonts in this folder.

Here you can pick two fonts from the open fonts. The script will create a new, third font, and make interpolations with the interpolation factors in the values = [.3, .6] list. The interpolated font is then saved in the same folder as the first master.

This touches on a slippery problem which can cause a lot of confusion. Robofab can only tell FontLab fonts apart from their path attribute, the place where each font is saved. A newly created font has not been saved yet, so it has no path. The effect is that when you have more than one new, unsaved font open, Robofab can't tell them apart (for a couple of reasons) and will continue to work with the first one. It will look like nothing is happening when you run a script. The way around this is to make sure you save each font you created with a script before creating another one. This is safer anyway.

Here are some useful bits for batch processing fonts which are not open, but in a file. This script is a way to make python collect all files of a particular kind in a folder or folders within that folder. You can use the walker function outside of this script too, it's a useful thing to know.

Moving stuff around

The moving, merging and splitting of fonts. The first example moves selected glyphs in the same font and renames them. Note that if you remove the line f.removeGlyph(g.name) the same script effectively copies the glyphs. Also new in this script: it iterates through the whole font and checks for each glyph if the g.selected attribute is 1 or 0. If it is 0, the glyph is not selected in the font window. If it is 1, is is selected. It then proceeds to create a new glyph name, and calls f.insertGlyph() method which takes a glyph as parameter. The optional parameter as is to be able to insert the glyph under a different name. If you don't pass a parameter for as, the font will insert the glyph under its own name. The glyph can come from the same font, or a different font, or be an orphan glyph.

.sc from robofab.world import CurrentFont f = CurrentFont() for g in f: if g.selected == 0: continue newName = g.name+".sc" print "moving", g.name, "to", newName f.insertGlyph(g, as=newName) f.removeGlyph(g.name) f.update() ]]>

Generating font binaries

This will generate CFF flavored OpenType fonts for all open files.

The script above generates fonts too, but is a bit more robust. FontLab sometimes crashes when it has to generate a long list of fonts and they're all open at the same time. This script asks you for a folder of .vfb sources (which in itself can be a useful ingredient for your own scripts). Then it will open them one by one and generate the fonts in the flavor indicated in the line f.generate('mactype1', dstDir). A list of types and their names can be found in the robofab documentation how-to page on generating fonts. This script also creates a new folder to store the generated fonts in, sorted by type.

Merging

Here's an script, quite complex, for combining two fonts into one. Maybe not for the newbie, but if you're into it try to figure out how it works. It uses a couple of new concepts, like Sets and DigestPens. If it is too complicated: don't worry.

Dealing with Robofab limitations

A handful of FontLab's own glyph and font methods are not supported in RoboFab. The reasons for this vary, some of them are very FontLab specific (for instance fl.productnumber or fl.username), but most of the missing stuff was just not needed very often — the following examples show how to get access to all functionality and attributes in the FontLab layer.

FontLab layer

To get to the FontLab layer, Robofab's Font and Glyph objects have a naked() method which returns the FontLab object. Note that you can still use the Robofab functionality like CurrentFont, CurrentGlyph, pens etc. The FontLab layer is documented here. Maybe you remember the naked() method from the cookie cutter example.

]]>

Other things you need to dig deeper for. Note that some of these objects appear to be broken.

  • PostScript hints: the vertical and horizontal hint zones as well as blue values can be read and set. ,] ]]>
  • All name fields: the FontLab table of OpenType names, the naming record, is available. See also the the FontLab reference for NameRecord
  • Encodings.The FontLab Encoding object. See also the the FontLab reference for Encoding ... eacute 233 ecircumflex 234 edieresis 235 igrave 236 iacute 237 icircumflex 238 ..etc.. ]]>