I’m looking for a Python way to draw interpolated shapes live.
I have a working script doing that using the CanvasView and interpolationProxy but it’s too slow (especially when drawing more than one instance).
I’m guessing that there must be a more effective way since Glyphs manages to preview all instances live without any lag (same goes for VariableFontPreview).
Is there a way to get these performances? And if not what would be the way to get higher performances when to drawing a path interpolation using python (I don’t know Objective C)?
The way I’m doing it now:
def draw(self, view): #New virtual instance thisInstance = GSInstance() #Associate to the font thisInstance.setFont_(Glyphs.fonts) #Calculate the incrementation between each step wght = value1 wdth = value2 #Set the position in the design space thisInstance.axes = [wght, wdth] #Get bezierpath of the interpolated glyph instanceFont = thisInstance.interpolatedFontProxy instanceGlyph = instanceFont.glyphs[Glyphs.font.selectedLayers.parent.name] instanceLayer = instanceGlyph.layers[instanceFont.fontMasterID()] #Add inteprolated path to array layerCopy = instanceLayer.copyDecomposedLayer() #Scale to the Canvas Size layerCopy.applyTransform([ scale, # x scale factor 0.0, # x skew factor 0.0, # y skew factor scale, # y scale factor valueX, # x position valueY # y position ]) layerCopy.bezierPath.fill()
I simplified/cleaned the code to make it more clear. In reality I’m drawing many glyph in the same canvas.
At first I tried using many canvas (with one interpolated path per canvas), but it didn’t make it better.