Test if glyphs are in kerning group

Pretty sure this is an easy one, but did not find any documentation on this: How do I get a kerning value for two glyphs (layers thereof) if they are in a kerning group?

Check it the glyph has a kerning group and leftLayer.leftKerningExeptionForLayer_(rightLayer).

I don’t get it, Sorry. Here’s what I want to do: make Drawbot draw a word in a font that is not installed on the system. To make it simpler for me, the kerning values should be stored in a list that is then used in a drawing loop. Here the loop to write the list:

kernList = []
        
for i in range (len(word)):
        kernList.append(current_font.kerningForPair(current_master.id, word[i-1], word[i]))
        
print(kernList)

Look at the documentation for the kerningForPair() method:
http://docu.glyphsapp.com/#kerningForPair

It requires a glyph name (≠ the character in the word, careful!) or a group name (starts with @). So you first need to get the glyph name from the character (perhaps glyphInfoForUnicode() can help here), and then, check for the presence of the glyph in the font, and if it is present, get its kern groups. A glyph has leftKerningGroup and rightKerningGroup attributes. Then check for kern values with kerningForPair() for all possible combinations: rightgroup-leftgroup, rightgroup-glyph, glyph-leftgroup, glyph-glyph.

Thank you, I will look into those.

or use this:

kerning = leftLayer.rightKerningForLayer_(rightLayer)
if kerning > 10000:
    kerning = 0

I wouldn’t store it in a list. Just call the above method inside the loop. And always test if the value is bigger than 100000. Then set it to zero.

1 Like

I tried to fix the reference problem with

word = u’someString’

for i in range(len(word)):
thisLetter = current_font.glyphs[word[i]]

which gives me a GSGlyph object, but of course only for glyphs that have easy names.

Is there a function that converts strings to proper glyph names?
If you type in for example “é” on your keyboard in Glyphs GUI it also can match the corresponding glyph object or layer. Or do I have to write a dict that matches “odd” input to proper glyph names?

Took me a long time to get that glyphInfoForUnicode() needs ord© as input and not hex(ord©) haha RIP

1 Like