Skip to content

Instantly share code, notes, and snippets.

@simoncozens
Created May 10, 2019 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simoncozens/1995dafc0be5accbcf5292687e5f5329 to your computer and use it in GitHub Desktop.
Save simoncozens/1995dafc0be5accbcf5292687e5f5329 to your computer and use it in GitHub Desktop.
from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
from fontTools.ttLib import TTFont
from Lib.fontTools.varLib.iup import iup_delta_optimize, _iup_contour_bound_forced_set
font = TTFont("NotoSerifHebrew-GX.ttf")
gvar = font["gvar"]
glyf = font["glyf"]
total = 0
saved = 0
for gname, g in glyf.glyphs.items():
if g.numberOfContours < 1: continue
points = list(g.coordinates)
points.extend(((0,0),(0,0))*2) # Add four phantom points
ends = g.endPtsOfContours
for v in gvar.variations[gname]:
optimized = iup_delta_optimize(v.coordinates, points, ends, tolerance = 0.5)
total += len(g.coordinates)
saved += len(list(filter(lambda x: x is None, optimized)))
print("Saved: %i/%i (%f%%)" % (saved, total, 100.0*(saved / float(total))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment