Duplicating kerning classes in Fontlab via script

Primary tabs

5 posts / 0 new
Last post
Matthew Butterick's picture
Joined: 28 Jul 2009 - 3:14pm
Duplicating kerning classes in Fontlab via script
0

So I see that a FL font object has a "classes" attribute that's a list of the classes in the font.

1) Is there a way to filter this list to only see kerning classes?

2) When I try to copy kerning classes via script, e.g. — 

fl.font2.classes = fl.font1.classes

This will copy the class members properly, but it loses the state of the left glyph / right glyph checkboxes in the class panel. Where does that data live?

Justin Callaghan's picture
Joined: 10 Oct 2003 - 12:49am
0

Filter for kerning classes by matching the first character of each class with an underscore:

classes = fl.font.classes
for c in range( len(classes) ):
class_text = classes[c]
if class_text[0] == "_":
print class_text

Chris Lozos's picture
Offline
Joined: 25 Feb 2004 - 11:00am
0

You can also save a copy of your classes as a text file from the "Classes" menu. In the upper left corner of the window is a tiny icon which when clicked reveals the option to "Save classes". You can either import this file completely as a replacement classes file, append some parts of it, or copy paste from a text editor the things you want.

Andreas Eigendorf's picture
Joined: 2 Sep 2006 - 4:12am
0

The FontLab Font object offers the folowing methods to access class attributes:

SetClassFlags(int class_index, bool left, bool right)
allows to set 'left' and 'right' properties of the kerning class
SetClassFlags(int class_index, bool lsb, bool rsb, bool width)
allows to set 'lsb', 'rsb' and 'width' properties of the metrics class
GetClassLeft(int class_index)
returns the 'left' property of the class
GetClassRight(int class_index)
returns the 'right' property of the class
GetClassMetricsFlags(int class_index)
returns the tuple containing LSB, RSB and Width flags of the metrics class
Matthew Butterick's picture
Joined: 28 Jul 2009 - 3:14pm
0

Thanks Eigi. Mission accomplished

# copy kern class information from source
kernClasses = []
kernClassesToBooleans = {}
for index, glyphClass in enumerate(sourceFLFont.classes):
if glyphClass.startswith("_"):
kernClasses.append(glyphClass)
kernClassesToBooleans[glyphClass] = (sourceFLFont.GetClassLeft(index), sourceFLFont.GetClassRight(index))

# clear target; copy classes
targetFLFont.classes = []
targetFLFont.classes = kernClasses

# copy booleans into target
for index, kernClass in enumerate(targetFLFont.classes):
leftBool, rightBool = kernClassesToBooleans[kernClass]
targetFLFont.SetClassFlags(index, leftBool, rightBool)