FontLab Remote

A neat feature in RoboFab for FontLab on MacOS. RoboFab can install an AppleEvent handler in FontLab to make FontLab respond to calls from other applications. There is code to communicate with FontLab using this AppleEvent and to make it execute code and exchange data such as glyphs. How useful this remote stuff is depends on what you want to do with it. We thought it was cool. The ‘remote’ relates to one application controlling another. Both applications need to run on the same machine, it does not mean that FontLab is accepting commands over a network for instance. For that we need another tool.

How?

Step 1: Start the remote stuff in FontLab

The first thing you need to do is start the AppleEvent support in FontLab. That’s done by importing the remote module:

# start the remote stuff in FontLab
import robofab.tools.remote
FontLabRemote is on.

Step 2: Start the Python IDE

You can now send commands, bits of code and entire glyphs to FontLab from the Python IDE:

# first, try a bit of python code
from robofab.tools.remote import runFontLabRemote
print runFontLabRemote("print 1+1")
2

The function runFontLabRemote() sends a piece of Python code to FontLab’s python interpreter and has it executed. In this example the code is print 1+1. The result, the output of FontLab running this piece of code is then returned to the Python IDE. Note that the output is always a string. Depending on the code you throw at FontLab it could even contain tracebacks or other output.

When FontLab receives and executes a remote command, it will print a note to the FontLab Output window:

< executing remote command >
< executing remote command >
< executing remote command >

That means that FontLab is doing remote stuff.

Step 3: Teleporting a Glyph

The remote module has support to send and receive Glyphs. For the next example open a new font in FontLab first (command N), then run the following code in the Python IDE. Make sure you have a UFO font handy somewhere:

from robofab.tools.remote import transmitGlyph
 
# Pick a UFO font:
f = OpenFont()
 
# one to beam up, Scotty!
transmitGlyph(f['n'])

If all went well, you now have the n from your UFO copied to the right slot in your FontLab font. As noted earlier, if all you want to do is import some glyphs from a UFO into FontLab there is absolutely no need to use all this remote stuff.

Why?

The remote module only takes care of the communication with FontLab. Possible applications which could be built on top of this are:

  • Use FontLab to perform outline operations such as remove overlap.
  • Use FontLab to batch process font generation.
  • Build an external editor to augment the functionality of FontLab.

As noted before, the remote stuff only works on MacOS.

Example

Example in which a glyph from a UFO opened in plain Python is copied to FontLab. After removing overlap the glyph is returned and inserted in the UFO:

# robofab manual
# Fontlabremote howto
# usage examples
 
#FLM: Remove overlap from Remote Glyph.
 
from robofab.world import OpenFont
from robofab.tools.remote import transmitGlyph, receiveGlyph, 
runFontLabRemote
 
# Pick a UFO font:
f = OpenFont()
 
print "Number of contours before", len(f['A'])
 
# call FontLab to make a new font
startNewFontCode = """from robofab.world import NewFont
f = NewFont()
f.info.fullName = 'Temporary Font generated by RoboFab Remote'"""
 
print runFontLabRemote(startNewFontCode)
 
# send a glyph to FontLab,
# it will be inserted in the CurrentFont.
transmitGlyph(f['A'])
f.removeGlyph('A')
 
# send instructions to remove overlap for this glyph
overlapCode = """from robofab.world import CurrentFont
from robofab.tools.remote import transmitGlyph
f = CurrentFont()
f["A"].removeOverlap()
f.update()
transmitGlyph(f['A'])
"""
 
# send the code and catch the output
x = runFontLabRemote(overlapCode)
# interpret the output
receiveGlyph(x, f)
print "Number of contours after: ", len(f['A'])
 
# send instructions to FontLab to close the font again.
closeFontCode = """from robofab.world import CurrentFont
f = CurrentFont()
f.close(None)
"""
print runFontLabRemote(closeFontCode)
print 'done!'

Possible results:

Number of contours before: 6
Number of contours after:  4

Note

While experimenting with robofab.tools.remote we found that after some time it’s possible that FontLab grows weary of the remote fussing and the scripts stop working. Restarting FontLab usually solves that situation.