Created
May 10, 2019 07:52
-
-
Save simoncozens/1995dafc0be5accbcf5292687e5f5329 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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