Erik van Blokland 3646055ea2 initial import
git-svn-id: http://svn.robofab.com/trunk@1 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c
2008-01-07 17:40:34 +00:00

114 lines
4.1 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<xml>
<include src="settings/generic.xml" />
<synopsis name="FontLab Remote" description="use AppleEvents to control FontLab in Mac OSX" keywords="lib, howto, fontlab" />
<title>FontLab Remote</title>
<div class="content">
<h1>FontLab Remote</h1>
<p>
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.
</p>
<h2>How?</h2> <h3>Step 1: Start the remote stuff in FontLab</h3>
<p>
The first thing you need to do is start the AppleEvent support in FontLab. That's done by importing the remote module.
</p>
<python><![CDATA[
# start the remote stuff in FontLab
import robofab.tools.remote
]]></python>
<python type="output"><![CDATA[
FontLabRemote is on.
]]></python>
<h3>Step 2: Start the Python IDE</h3>
<p>
You can now send commands, bits of code and entire glyphs to FontLab from the Python IDE.
</p>
<python><![CDATA[
# first, try a bit of python code
from robofab.tools.remote import runFontLabRemote
print runFontLabRemote("print 1+1")
]]></python>
<python type="output"><![CDATA[
2
]]></python>
<p>
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.
</p>
<p>
When FontLab receives and executes a remote command, it will print a note to the FontLab Output window.
</p>
<python type="output"><![CDATA[
< executing remote command >
< executing remote command >
< executing remote command >
]]></python>
<p>
That means that FontLab is doing remote stuff.
</p>
<h3>Step 3: Teleporting a Glyph</h3>
<p>
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.
</p>
<python><![CDATA[
from robofab.tools.remote import transmitGlyph
# Pick a UFO font:
f = OpenFont()
# one to beam up, Scotty!
transmitGlyph(f['n'])
]]></python>
<p>
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.
</p>
<h2>Why?</h2>
<p>
The remote module only takes care of the communication with FontLab. Possible applications which could be built on top of this are:
</p>
<ul>
<li>
Use FontLab to perform outline operations such as remove overlap.
</li>
<li>
Use FontLab to batch process font generation.
</li>
<li>
Build an external editor to augment the functionality of FontLab
</li>
</ul>
<p>
As noted before, the remote stuff only works on MacOS.
</p>
<h2>Example</h2>
<p>
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.
</p>
<pythonsource src="examples/usageFlremote.py"/>
<python type="output"><![CDATA[
# possible results:
Number of contours before: 6
Number of contours after: 4
]]></python>
<h2>Notes</h2>
<p>
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.
</p>
</div>
</xml>