RoboFab Kerning - Add Pair ?

ReginaldV's picture

Is it possible to add a kerning pair using RoboFab ?

I'm using class kerning but I quickly wanted to add kerning for pairs like AC, DA, AG, AQ, QA once I have kerned OAO

I was thinking something like


addpair('A','C') = AO

k.l.'s picture

Have you checked the RoboFab site? The RoboFab documentation at is pretty good.
As regards kerning, see especially and
I haven't used it for some time now, but in a RoboFab font object, kerning is a dictionary which you access like this

# import the font class:
from robofab import CurrentFont
# turn the current FLS font into a RoboFab font object:
f = CurrentFont()
# get at kerning in the current font:
kerning = f.kerning

and then you should be able to either directly add kerning to this kerning object/dict like

# note that the key is a tuple:
kerning[ ('glyphA','glyphB') ] = 10

or, alternatively, create a new temporary kerning dictionary which you feed with additional kerning pairs, and finally update the font's kerning dictionary with the new one

newKerning = {}
newKerning[ ('glyphA','glyphB') ] = 10

and don't forget to update the font


ReginaldV's picture


Thanks for your reply - Yes I've been to the Robofab site and got all the documentation. I got the code working to create a new pair but I still need to work out how capture a value that already exists.

In my example here I'm trying to use the kerning value for 'AO' and create a new pair for 'AC' with the same value.

The Robofab documentation says that get(aPair) is used to get a value for a pair, I don't know if my syntax is wrong or this is the wrong way to do it.

from import CurrentFont
f = CurrentFont()
kerning = f.kerning
AO = kerning.get('A','O')

kerning[('A','C')] = AO


andyclymer's picture

Since the kerning object works like a standard Python dictionary you don't have to use get(), you can call a value out like this:

AO = kerning[('A', 'O')]

...or even better, combine that with making a new dictionary entry:

kerning[('A', 'C')] = kerning[('A', 'O')]

If an entry already existed for ('A', 'C') then it would now be replaced, or if there wasn't an entry yet a new one would have been created. Then, check your work to see if it did what you wanted:

print kerning[('A', 'C')]
print kerning[('A', 'O')]

...the two of those should now be the same.

Hope that helps,

ReginaldV's picture

andy Thanks for the reply - I just worked out how to do.

I did it slightly differently from the way you said to make it easier to read.

from import CurrentFont
f = CurrentFont()
kerning = f.kerning
OA = kerning[('O','A')]
AO = kerning[('A','O')]
OV = kerning[('O','V')]
VO = kerning[('V','O')]
OW = kerning[('O','W')]
WO = kerning[('W','O')]
OY = kerning[('O','Y')]
YO = kerning[('Y','O')]
OX = kerning[('O','X')]
XO = kerning[('X','O')]
OT = kerning[('O','T')]
TO = kerning[('T','O')]
KO = kerning[('K','O')]
kerning[('A','C')] = kerning[('A','G')] = kerning[('A','Q')] = kerning[('A','OE')] = AO
kerning[('D','A')] = kerning[('Q','A')] = OA
kerning[('V','C')] = kerning[('V','G')] = kerning[('V','Q')] = kerning[('V','OE')] = VO
kerning[('D','V')] = kerning[('Q','V')] = OV
kerning[('W','C')] = kerning[('W','G')] = kerning[('W','Q')] = kerning[('W','OE')] = WO
kerning[('D','W')] = kerning[('Q','W')] = OW
kerning[('Y','C')] = kerning[('Y','G')] = kerning[('Y','Q')] = kerning[('Y','OE')] = YO
kerning[('D','Y')] = kerning[('Q','Y')] = OY
kerning[('X','C')] = kerning[('X','G')] = kerning[('X','Q')] = kerning[('X','OE')] = XO
kerning[('D','X')] = kerning[('Q','X')] = OX
kerning[('T','C')] = kerning[('T','G')] = kerning[('T','Q')] = kerning[('T','OE')] = TO
kerning[('D','T')] = kerning[('Q','T')] = OT
kerning[('K','C')] = kerning[('K','K')] = kerning[('K','Q')] = kerning[('K','OE')] = KO

PabloImpallari's picture

Awesome, thanks!

Syndicate content Syndicate content