import sys
import os
import json
from fontTools.ttLib import TTFont, sfnt
from fontTools.misc.timeTools import timestampNow
sfnt.USE_ZOPFLI = True
if len(sys.argv) < 2:
print("Usage: %s <font file>" % sys.argv[0])
sys.exit(1)
font_file = sys.argv[1]
font_name = os.path.splitext(os.path.basename(font_file))[0]
font = TTFont(font_file, recalcBBoxes=False, recalcTimestamp=False)
font['head'].created = 0
font['head'].modified = 0
if 'FFTM' in font:
del font['FFTM']
if 'GDEF' in font:
del font['GDEF']
font['name'].names = [record for record in font['name'].names if record.platformID != 1]
font['cmap'].tables = [table for table in font['cmap'].tables if table.platformID != 1]
glyf = font['glyf']
ascent = int(max(glyf[c].yMax for c in font.getGlyphOrder() if hasattr(glyf[c], "yMax")))
descent = -int(min(glyf[c].yMin for c in font.getGlyphOrder() if hasattr(glyf[c], "yMin")))
font['OS/2'].usWinAscent = ascent
font['OS/2'].usWinDescent = descent
font['hhea'].ascent = ascent
font['hhea'].descent = -descent
font.save(font_file, reorderTables=None)
font.flavor = 'woff'
font.save(os.path.join('woff', font_name + '.woff'), reorderTables=None)
font.flavor = 'woff2'
font.save(os.path.join('woff2', font_name + '.woff2'), reorderTables=None)