SOLVED GlyphConstruction as script: x = a&\b gives traceback if no kerning pair is present



  • Im using the utterly convenient glyphConstruction in a python script (ParseGlyphConstructionListFromString, GlyphConstructionBuilder). When I construct a Glyph (x = a&\b) using a pair of glyphs that has not been kerned I get a traceback.

    I'm simply wondering, is this to be expected should it just work, even if a and b are not kerned?

    Also, print(font.kerning[("a", "b")]) triggers a traceback. Should it not be a simple None if a and b is not an existing kerning pair?

    (I use if ("a", "b") in font.kerning: first, then see if I should use the \ or not to trigger kerning in my constructions)

    Traceback (most recent call last):
      File "countrycodes and glyph names 03.py", line 63, in <module>
      File "/Users/martin/Library/Application Support/RoboFontPy3/plugins/GlyphConstruction.roboFontExt/lib/glyphConstruction.py", line 1185, in GlyphConstructionBuilder
      File "/Users/martin/Library/Application Support/RoboFontPy3/plugins/GlyphConstruction.roboFontExt/lib/glyphConstruction.py", line 974, in kernValueForGlyphPair
      File "/Applications/RoboFont3.4b.app/Contents/Resources/lib/python3.7/fontParts/base/kerning.py", line 255, in __contains__
      File "/Applications/RoboFont3.4b.app/Contents/Resources/lib/python3.7/fontParts/base/base.py", line 319, in __contains__
      File "/Applications/RoboFont3.4b.app/Contents/Resources/lib/python3.7/fontParts/base/normalizers.py", line 129, in normalizeKerningKey
    TypeError: Kerning key items must be strings, not NoneType.
    

    When I type x = a&\b via the Glyph Builder UI all goes well.


  • admin

    should be fixed here: https://github.com/typemytype/GlyphConstruction/commit/01c7c9362561822a68073305c69c9fbc054ddf13

    Getting kerning is advised to use font.kerning.get(pair) where it does not fail. This is similar to a normal dict.

    Or you can also check first if pair in font.kerning: ...

    thanks!