from fontTools.ttLib import TTFont import sys font = TTFont(sys.argv[1]) order = font.getGlyphOrder() glyf = font["glyf"] gvar = font["gvar"] hMetrics = font['hmtx'].metrics vMetrics = getattr(font.get('vmtx'), 'metrics', None) for glyphname in order: tupleVarStore = gvar.variations.get(glyphname) coordinates, ctrl = glyf._getCoordinatesAndControls(glyphname, hMetrics, vMetrics) endPts = ctrl.endPts isComposite = glyf[glyphname].isComposite() for var in tupleVarStore: var.optimize(coordinates, endPts, isComposite) font.save("optimized-"+sys.argv[1])