Typophile

node 12334

unknown

ok, i guess it’s time for me to brush up on some scripting…

first of all, is there a macro for a group of .vfb files that will:
-Switch to “codepages”
-View by Name
-select MacOS Roman (and a variant to select MS windows 1252 Latin 1) -generate names -and lastly copy the currency (euro) to the Euro glyph position?

if not, how hard would it be for a beginner to write something that will do these for me in a batch? can anyone point me in the right direction? any help would be appreciated!!!

unknown

The best place to start is the fontlab-scripting list at letterror. If you search the archive you’ll find almost what you need. It will take some scripting and piecing together, but that list is the best place to start.

unknown

hasn’t anybody written “Learn Python for FontLab Fast”?

I checked out the Letterror mailing list and I agree that’s a great resource. However, I need to start from the beginning and move along at a faily quick clip so i can get mostly over the learning curve. I keep getting stuck at print “Hello World”. Not because that’s hard, but because I want to skip past that to something useful in terms writing FontLab macros and don’t know what point to skip to… any other tips, anyone?

unknown

Ah, no the “Learn Python for FontLab Fast” doesn’t exist. However, here are the links that I’m always referring to when I’m working on a script:

FontLab Python
Python 2.3 documentation
RoboFab Object Model
FontLab Scripting Archive

and lastly, the RoboFab documentation which will be in your RoboFab folder (if you have it installed) here: Documentation/robofabDocs/robofab.html

A quick plug for Typgraphica, there is a quick article up there now, which I wrote, that details an introduction to RoboFab.

Quickly, however. There are two things here. The first is a need to know something (and only a little something) about programming. O’Reilly is a good source of books on programming languages and theory. They have several good python books to get you up to speed. The second is the fontlab specific python. Personally, I find that using RoboFab can help speed things up a great, great deal. The FontLab python interface isn’t as clean or intuitive as the RoboFab one.

Example. Today I wanted to copy only the side-bearings from one of my fonts to another. Sounds simple, but trying to do it by exporting AFM files and the like doesn’t work, as you import widths that you don’t want. So in about 15 minutes I wrote this:


#FLM: Copy Font Side-bearing

#Imports
from robofab.world import OpenFont, CurrentFont
from robofab.interface.all.dialogs import Message

fontToChange = CurrentFont()
orignalMetricsFont = OpenFont(None, "Which font's sidebearings do you want?")
orignalMetrics = {}

for glyph in orignalMetricsFont:
[tab]orignalMetrics[glyph.name] = [glyph.leftMargin, glyph.rightMargin]
[tab]print orignalMetrics[glyph.name]
orignalMetricsFont.close()

for name, metrics in orignalMetrics.iteritems():
[tab]if fontToChange[name]:
[tab][tab]fontToChange[name].leftMargin = metrics[0]
[tab][tab]fontToChange[name].rightMargin = metrics[1]
fontToChange.update()
Message('Done changing side-bearings')

Replace [tab] with an actual tab

Much, much easier to do this in RoboFab than it is through FontLab’s python. Or by hand.

Captured from web.archive.org on 8 Aug 2005. view this capture