- getting the interpolated font of an instance
- appending this as a new master in the main font
- looping through glyphs of the added master, and setting the blank layer equal to the same layer of the interpolated font
- setting the kerning in the main font’s new master equal to the kerning of the interpolated font’s master
In the Python API, that looks like this:
instanceFont = Font.instances.interpolatedFont Font.masters.append(instanceFont.masters) newMasterID = instanceFont.masters.id for glyph in Font.glyphs: instanceGlyph = instanceFont.glyphs[glyph.name] glyph.layers[newMasterID] = instanceGlyph.layers[newMasterID] Font.kerning[newMasterID] = instanceFont.kerning[newMasterID]
I’m now trying to do something similar with the Core API in order to manipulate a font source during a build process. I’ve been able to get the interpolated font from an instance and append it as a new master (steps 1 and 2 from above), but I’m getting stuck on step 3.
# get interpolated font currentLightFont = font.generateInstance_error_(font.instances(), None) # get master of interpolated font currentLightFontMasterID = currentLightFont.fontMasters().id() # add master of interpolated font as master to main font font.addFontMaster_(currentLightFont.fontMasters()) # loop through glyphs for index,glyph in enumerate(font.glyphs()): # get interpolated font's glyph at this index instanceGlyph = currentLightFont.glyphs()[index] ## 🚨here's where I get stuck. This won't work, probably because PyObjC requires more explicit setting methods: glyph.layerForKey_(currentLightFontMasterID) = instanceGlyph.layerForKey_(currentLightFontMasterID) ## Returns: SyntaxError: can't assign to function call ## 🚨I figure I may need to draw a new path with a pen, but this doesn't work: glyph.layerForKey_(currentLightFontMasterID).drawBezierPath(instanceGlyph.layerForKey_(currentLightFontMasterID).bezierData()) ## 🚨neither does this: glyph.layerForKey_(currentLightFontMasterID).drawInPen_(instanceGlyph.layerForKey_(currentLightFontMasterID).drawBezierPath()) ## 🚨additionally, the paths() property doesn't seem to yield any data, so I'm not sure whether I can save those to draw in later: print(glyph.layerForKey_(currentLightFontMasterID).paths()) ## returns: None print(instanceGlyph.layerForKey_(currentLightFontMasterID).paths()) ## returns: None
Am I on the right path in trying to use a pen to draw in bezier info from the interpolated font? I suspect this may be the way to go, as I don’t see any sort of specific “add layer data” method. However, it’s pretty unclear whether this is correct, or whether it’s way off. If this is the right direction, I would love to see an example of how to do it, if possible.
I suspect I may have similar trouble on step 4, duplicating kerning, because there is not clear “set kerning data” method. Will I have to loop through kerning, using
setKerningForFontMasterID:LeftKey:RightKey:Value:direction, or is there some simpler way?
Thank you for any pointers on this!