Skip to content

New in FontLab 8: Scripts & extensions

Write and use Python 3 scripts. Seamlessly interchange with other font editing apps like Glyphs or RoboFont.

Perform global transformations with the powerful TypeRig library. Create fonts for the entire Unicode 14 standard.

Python

Python 3.10

New FontLab now uses Python 3.10 instead of the legacy Python 2.7. FontLab 8 uses its own built-in version of Python 3.10 on both macOS and Windows. You don’t have to install Python yourself. Place your FontLab-specific packages in the python/3.10/site-packages folder inside the user data folder.

If Python is working correctly, the About box (FontLab 8 > About FontLab 8 on macOS, Help > About FontLab 8 on Windows) now shows which Python version FontLab is using.

As a result of the switch from Python 2.7 to 3.10, scripting works several times faster.

Python scripting on macOS

FontLab 8 or macOS uses its own built-in Python. You don’t have to install Python yourself.

If you want to use pip to install additional Python packages that you import into your FontLab scripts, you may also install the most recent Python 3.10.x from Python.org, or the most recent Python 3.10.x from Homebrew with brew install python@3.10.

Then, in Terminal, install general-purpose packages with python3 -m pip install PACKAGENAME or python3 -m pip install --user packagename, and FontLab should recognize them.

FontLab 8 for macOS looks for Python packages and modules in these folders, in this sequence:

  • python/3.10/site-packages inside the user data folder, which by default is ~/Library/Application Support/FontLab/FontLab 8/ and which you can customize in Preferences > General
  • Contents/Resources/python/3.10/site-packages inside the FontLab 8.app
  • ~/Library/Python/3.10/lib/python/site-packages, which is the location for packages installed with python3 -m pip install --user if you have Python 3.10 installed from Python.org or Homebrew
  • /usr/local/lib/python3.10/site-packages, which is the location for packages installed with python3 -m pip install if you have Python 3.10 installed from Homebrew
  • /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/, which is the location for packages installed with python3 -m pip install if you have Python 3.10 installed from Python.org

Python scripting on Windows

FontLab 8 or macOS uses its own built-in Python. You don’t have to install Python yourself.

To use pip to install additional Python packages that can you import into your FontLab scripts, install the most recent Python 3.10.x from Python.org. Install the 64-bit (x64) or 32-bit (x86) version of Python, depending on the version of FontLab 8 that you use.

After the installation, you may want to click Start, in the search box type environment and choose Edit the system environment variables. In the System Properties dialog, choose Environment Variables and in the System variables section, double-click Path. Click New and paste %USERPROFILE%\AppData\Local\Programs\Python\Python310\. Click OK to close all dialogs.

Then, in the Command Prompt, install general-purpose packages with python -m pip install PACKAGENAME or python -m pip install --user packagename, and FontLab should recognize them.

FontLab 8 for Windows looks for Python packages and modules in these folders, in this sequence:

  • python/3.10/site-packages inside the user data folder, which by default is C:/Users/%USERNAME%/Documents/FontLab/FontLab 8/ and which you can customize in Preferences > General
  • Resources/python/3.10/site-packages inside the FontLab 8 app folder such as C:/Program Files/Fontlab/FontLab 8/
  • C:/Users/%USERNAME%/AppData/Local/Programs/Python/Python310/lib/site-packages, which is the location for packages installed with python -m pip install if you have Python 3.10 installed from Python.org
  • Lib folder inside the FontLab 8 app folder
  • C:/Users/%USERNAME%/AppData/Roaming/Python/Python310/site-packages, which is the location for packages installed with python -m pip install --user if you have Python 3.10 installed from Python.org

Troubleshooting your Python packages

  1. To use Python in FontLab 8 on macOS 10.13 High Sierra, you need to apply a small fix, read more.
  2. FontLab 8 uses Python 3.10 — not Python 3.9 or 3.11 or any other version. If you have any other version of Python installed, and you want to use pip-installed packages in FontLab, install the most recent Python 3.10.x from Python.org, and re-install the Python packages for this Python version.
  3. You may manipulate the sys.path list in startupScript.py to add or remove paths in which FontLab looks for packages and modules.

Installing and using scripts

New When you choose Scripts > Update / Install Scripts, the new Extend FontLab website opens in your browser.

You can download and install TypeRig and other scripts and resources from the website. We will be adding new scripts and resources there.

TypeRig

New Vassil Kateliev has updated his powerful TypeRig Python package to work in FontLab 8. Visit Extend FontLab website to download and install TypeRig.

fontTools

New FontLab 8 bundles the January 2022 version of fontTools (4.29.1), instead of the ancient 3.43.2. Thanks to that, variable fonts export faster and are more optimized.

FontLab bundles a special version of the fontTools package which you can import as import fontlab_private.fontTools. This is done so that FontLab’s internal functionality does not conflict with any version of fontTools that you may have installed.

If you need to use fontTools in your own scripting, you may use it like so:

try:
    # Try to use pip-installed fontTools
    from fontTools import ttLib
except ImportError:
    # If it's not available, use FontLab-bundled fontTools
    from fontlab_private.fontTools import ttLib

Preferences in Python

Direct access to preferences

The fontlab built-in module contains the flPreferences class that offers direct access to over 340 FontLab preference attributes.

For example, if you use the dark UI theme, you can toggle the Glyph window between the light and the dark theme:

from fontlab import *
pref = flPreferences()
pref.generalDarkGlyph = not pref.generalDarkGlyph

Extended access to preferences

New FontLab now also offers extended access to over 400 preference attributes. You can save() the current preferences to a Python dict, modify the values of the dict and load() the dict back into the preferences. For example:

from fontlab import *
prefd = flPreferences().save()
prefd["general.dark_glyph"] = not prefd["general.dark_glyph"]
flPreferences().load(prefd)
flWorkspace.instance().updateActiveViewport()

We recommend that you use direct access to preferences. Use extended access only if direct access does not expose the preferences that you need. For example, prefd.get("profiles", tuple()) returns a Python tuple with all custom export profiles.

Scripting panel

Clearing Output panel whenever you run a script

New If you turn on the new Clear Output Panel toggle in the menu of the Scripting panel, every time you run a script that you have open in the panel, FontLab clears the Output panel. This is useful as you develop your script.

Run current script from collapsed Scripting panel

New If you collapse the Scripting panel, its header (if it’s horizontal) shows a Run button. This way, you can quickly run the same script again and again.

If you’ve loaded a script from the panel’s sidebar, or if you’ve written a script and have saved it, the collapsed panel also shows the name of the script.

Find next in Scripting panel

New If you’re in the Scripting panel and you press CmdF or CtrlF, FontLab jumps to the panel search box. Type a string and press Enter to find the first occurrence of the string. Press CmdG or CtrlG to find the next occurrence.

Python hooks

If you place a file named startupScript.py directly inside your user data folder, FontLab will execute the code in this file at the beginning of each Python script that you run from the Scripts menu or the Scripting panel. You may place commonly-used imports there.

New If you place the file named initScript.py in your user data folder, FontLab will execute this script once, right after you run the FontLab app. You may place code there that registers custom handlers, connects functions to Qt signals, checks for updates for your own code etc.

Output panel

HTML in Output panel

New If you use print in Python to print text into the Output panel, and the text contains the characters < and >, FontLab interprets the text as HTML and renders that HTML in the panel.

New If you use the print function in Python to print text into the Output panel, and the text contains HTML links formed like <a href="protocol:content">text</a>, the links in the panel will be clickable.

  • If protocol is glyph, then content can be a glyph name. If you click such a link and the glyph exists, FontLab opens the glyph in the current window.
  • If protocol is class, then content can be a class name. If you click the link and the class exists, FontLab opens the Classes panel and highlights the class.
  • If protocol is file, then content can be a file or folder path. If you click the click, FontLab reveals the path in the Finder / File Explorer. FontLab does not open the file in the associated app, only navigates to the file in the system file browser. When you use the file protocol, the path can immediately follow the :. You don’t need to use // or /// after the colon, or to escape spaces.

protocol can be any URL scheme protocol such as https. On macOS, it can be any custom URI scheme registered with the system. If you click the link, FontLab will delegate the handling of the link to the system. For example:

  • If the link is <a href="https://fontlab.com">website</a>, FontLab will open the link in the default browser.
  • On macOS, if the link is <a href="x-dictionary:‽:com.apple.dictionary.Wikipedia">‽</a>">look up</a> and you click it, macOS opens the Dictionary app and looks up the character (interrobang) in the Wikipedia.
  • On macOS, if the link is <a href="x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility">open Accessibility preferences</a> and you click it, macOS opens System Preferences > Security & Privacy > Privacy > Accessibility.

If you run a script that prints links multiple times, only the links from the last run will be clickable.

Integrated libraries

New FontLab 8 uses 2022 versions of the ICU, HarfBuzz and FreeType libraries. Thanks to that, FontLab supports new writing systems added in Unicode 14, and includes other improvements.

New FontLab 8 uses the 2022 version of the Qt 5.15 framework. FontLab 7 used Qt 5.9. Thanks to that, FontLab handles high-DPI system settings on Windows better, and includes other improvements.