Scripting with Python»
FontLab VI Python API»
The FontLab VI Python API docs are in “early draft” state, and is available at:
We currently consider the Python scripting functionality within FontLab VI experimental. The API docs are not complete, but they give you a broad overview of what’s possible.
FontLab now has three APIs:
The fontlab module allows access to the high-level font objects within FontLab VI, including access to some user interface elements. It has some compatibility with the RoboFab API. (In early pre-release versions of the app, this was called fg_world.)
The fontgate module operates on a slightly lower level, the FontGate library, which is our shared “font engine” that apps like FontLab VI or TransType use. (In early pre-release versions of the app, this was called pyfontgate.)
The relationship between fontlab and fontgate APIs will be clarified in the future.
FontLab VI also has an FL module that aims to be backwards-compatible with the Python API of FontLab Studio 5. However, this module will not be fully compatible with the FLS5 API — since FontLab VI is a complete rewrite with a different internal structure, it’s not possible for us to provide full compatibility. But many objects and classes will work, though some may work slightly differently.
We intend to publish some little scripts and snippets, and more info here.
Here’s a first little script that loads the fontforge Python module from within FontLab VI, opens an .sfd font within the FontForge module and “ports” a glyph into FontLab VI using the RoboFab-compatible Pen protocol.
import fontforge as ff
import fontlab as fl
import fontgate as fg
flf = fl.CurrentFont()
flg = flf["C"]
fff = ff.open("example.sfd")
ffg = fff["A"]
flp = flg.getPen()
ffp = ffg.glyphPen()
To write a Python script in FontLab:
- Open the Scripting panel.
- Click on the local menu button and choose New Script.
- Write or paste your program. For example:
#FLVI: Sample script print "\nWelcome to FontLab VI!\n" import fontlab f=fontlab.CurrentFont() if f.values() != None: print "Glyph list:\n", f.values()
- Choose Save Script As in the local menu to save your script.
Click on the first button on the right-hand side of the Scripting panel’s local toolbar to open the List of scripts. The List of scripts may include folders containing your script files. Remember that it will be empty until you add some folders here.
To add a folder with scripts, click on the + button. In the standard Open dialog box, select the folder with scripts and click on Open. You can add any folder from your hard disk. If it contains at least one file with a .py extension it will appear in the Scripts list:
Any scripts you add here will become available in the Scripts Menu, from where you can run them quickly without opening the Scripting panel.
To remove a folder with all its scripts, select it in the list and click on the – button.
To update the list contents (after you moved or renamed script files in Finder), click on the Refresh folders button.
To open a script for editing, simply double-click on it in the list.
To run the currently opened script, click on the Run button on the local toolbar.