Kerning Macro, Fontlab API

RachelR's picture

Hi all

I wrote this Robofab macro to copy kerning from one pair to others.

I am using Class kerning put I kern OAO and then use the macro to copy those values to AC, AG, AQ etc.

It speeds the process up and ensures I don't miss pairs

#Upper/UpperKern---------------
#
from robofab.world import CurrentFont
f = CurrentFont()
kerning = f.kerning
#
if kerning[('A','O')]:
AO = kerning[('A','O')]
kerning[('A','C')] = kerning[('A','G')] = kerning[('A','Q')] = kerning[('A','OE')] = AO

if kerning[('O','A')]:
OA = kerning[('O','A')]
kerning[('D','A')] = kerning[('Q','A')] = OA

… …

Problem with this macro is it doesn't work with MM fonts. The value from one master is copied to the other.

The value for 'AO' could be different across masters but the macro copies the same value to both masters.

The Fontlab API KerningPair class says it's MM compatible but doesn't give any examples of how to use it.

http://e-font.de/flpydoc/

Does anyone know how I could use FL's API to copy the value of kerning pairs to other pairs.

Jens Kutilek's picture

You are using Robofab for your macro, so you’d want to look at the Robofab docs rather than the FontLab API: http://www.robofab.org/objects/kerning.html

I’m not sure if Robofab handles MultipleMaster VFBs.

Another solution would be to simply put C, G, Q, Πetc. in the right side kerning class for O ;)

RachelR's picture

Robofab doesn't handle kerning in MM fonts, I think Fontlab API does.

My macro was done using Robofab but I would like to do the same thing with FL API.

I could do the class thing but it wouldn't fit in with my work flow.

twardoch's picture

Here's an example of creating an MM kerning pair using the FontLab Python API:

f = fl.font	# Set current font to "f"
g1name = "A"	# First glyph's name is "A"
g2name = "W"	# Second glyph's name is "W"
g1i = f.FindGlyph(g1name)	# Find glyph index for "A" glyph
g2i = f.FindGlyph(g2name)	# Find glyph index for "W" glyph
if g1i > -1 and g2i > -1:	# If both glyphs exist
  g1 = f.glyphs[g1i]		# Assign first glyph object
  kp = KerningPair(g2i)		# Blank kerning pair referring to "W"
  if g1.layers_number == 4: 	# Check if first glyph has 4 masters
    kp.values = [-35, -32, -30, -28]	# Assign values for 4 masters
    g1.kerning.append(kp)	# Add kerning pair to fist glyph

(It's possible to write this code more efficiently, but this is the "safest" and most verbatim method that should show how it works.)

RachelR's picture

Thanks adam, that looks perfect

Syndicate content Syndicate content