fonttools 0.1.0

A library for reading, manipulating and writing OpenType font files
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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])