2 # -*- coding: utf-8 -*-
5 # Author: mshio <mshio@users.osdn.me>
12 from fontparser import font_diff
13 from listprinter import SimpleListPrinter
16 def print_new_glyph(archive, newfile, printer=None):
17 def fontfilepath_in_archive(archive_path, weight, ext='ttf'):
18 file_name = archive_path.split('/')[-1]
19 family_name, type_name, _ = file_name.split('-', 2)
21 return '{family}-{type_name}/{family}-{type_name}-{weight}.{ext}'.format(
22 family=family_name, type_name=type_name, weight=weight, ext=ext
25 def expand_archive(archive_path, fontfile_path):
26 f = tarfile.open(archive_path, 'r:gz')
27 f.extract(fontfile_path)
29 def clean_up(fontfile_path):
30 os.remove(fontfile_path)
31 os.rmdir(fontfile_path.split('/')[0])
33 def main(archive, newfile, printer):
34 font_path = fontfilepath_in_archive(archive, 'medium')
35 expand_archive(archive, font_path)
37 diff = font_diff(font_path, newfile)
41 if p == None: p = SimpleListPrinter(delimiter=0x3001)
44 print >>p.out, "%d char(s)" % len(diff)
46 main(archive, newfile, printer)
49 parser = argparse.ArgumentParser()
50 parser.add_argument('archive_file', help='path of an archived font file')
51 parser.add_argument('font_file', help='path of a font file')
53 return parser.parse_args()
55 if __name__ == '__main__':
57 print_new_glyph(args.archive_file, args.font_file)