OSDN Git Service

add lists of education kanji
[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
41     p = printer
42     if p == None: p = SimpleListPrinter(delimiter=0x3001)
43     p.output(diff)
44     print
45     print "%d char(s)" % len(diff)
46
47   main(archive, newfile, printer)
48
49 if __name__ == '__main__':
50   if len(sys.argv) != 3:
51     print 'usage: %s tar.gz-file font-file' % sys.argv[0]
52     sys.exit(1)
53
54   archive = sys.argv[1]
55   newfile = sys.argv[2]
56
57   print_new_glyph(archive, newfile)