• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3from __future__ import print_function, division, absolute_import
4from fontTools.misc.py23 import *
5from fontTools.ttLib import TTFont
6from fontTools.ttx import makeOutputFileName
7import sys
8import os
9
10
11def make_output_name(filename):
12    with open(filename, "rb") as f:
13        f.seek(4)
14        sfntVersion = f.read(4)
15    assert len(sfntVersion) == 4, "not enough data"
16    ext = '.ttf' if sfntVersion == b"\x00\x01\x00\x00" else ".otf"
17    outfilename = makeOutputFileName(filename, outputDir=None, extension=ext)
18    return outfilename
19
20
21def main(args=None):
22    if args is None:
23        args = sys.argv[1:]
24    if len(args) < 1:
25        print("One argument, the input filename, must be provided.", file=sys.stderr)
26        return 1
27
28    filename = args[0]
29    outfilename = make_output_name(filename)
30
31    print("Processing %s => %s" % (filename, outfilename))
32
33    font = TTFont(filename, recalcBBoxes=False, recalcTimestamp=False)
34    font.flavor = None
35    font.save(outfilename, reorderTables=True)
36
37
38if __name__ == '__main__':
39    sys.exit(main())
40