OSDN Git Service

e15e3dd35936b9af246245cd57b75593fac8ebaa
[sawarabi-fonts/sawarabi-fonts.git] / script / new_glyphs.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # $Id$
5 # Author: mshio <mshio@users.sourceforge.jp>
6
7 __version__ = '0.11'
8
9 import os
10 import sys
11 import tarfile
12 from fontparser import FontDiffParser
13 from listprinter import SimpleListPrinter
14
15
16 def print_new_glyph(archive, newfile, printer=None):
17   def fontfilepath_in_archive(archive_path, weight, ext='ttf'):
18     filenm = archive_path.split('/')[-1]
19     p = filenm.split('-')
20     family_name = p[0]
21     type_name = p[1]
22
23     return '%s-%s/%s-%s-%s.%s' % (family_name, type_name,
24                                   family_name, type_name, weight, ext)
25
26   def expand_archive(archive_path, fontfile_path):
27     f = tarfile.open(archive_path, 'r:gz')
28     f.extract(fontfile_path)
29
30   def clean_up(fontfile_path):
31     os.remove(fontfile_path)
32     os.rmdir(fontfile_path.split('/')[0])
33
34   def main(archive, newfile, printer):
35     font_path = fontfilepath_in_archive(archive, 'medium')
36     expand_archive(archive, font_path)
37
38     parser = FontDiffParser(font_path, newfile)
39     diff = parser.get_diff()
40     clean_up(font_path)
41
42     p = printer
43     if p == None: p = SimpleListPrinter(delimiter=0x3001)
44     p.output(diff)
45     print >>p.out
46     print >>p.out, "%d char(s)" % len(diff)
47
48   main(archive, newfile, printer)
49
50 if __name__ == '__main__':
51   if len(sys.argv) != 3:
52     print 'usage: %s tar.gz-file font-file' % sys.argv[0]
53     sys.exit(1)
54
55   archive = sys.argv[1]
56   newfile = sys.argv[2]
57
58   print_new_glyph(archive, newfile)