OSDN Git Service

adds new_glyphs.py
authormshio <mshio@54a90f34-5e62-402c-8eae-46c47f0b2e07>
Sun, 9 Dec 2012 03:44:16 +0000 (03:44 +0000)
committermshio <mshio@54a90f34-5e62-402c-8eae-46c47f0b2e07>
Sun, 9 Dec 2012 03:44:16 +0000 (03:44 +0000)
git-svn-id: svn+ssh://svn.osdn.net/svnroot/sawarabi-fonts/trunk@26 54a90f34-5e62-402c-8eae-46c47f0b2e07

script/new_glyphs.py [new file with mode: 0644]

diff --git a/script/new_glyphs.py b/script/new_glyphs.py
new file mode 100644 (file)
index 0000000..6a9ce22
--- /dev/null
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import fontforge
+import os
+import sys
+import tarfile
+
+def get_fontfilename_in_archive(string):
+  name = string.split('/')[-1]
+  p = name.split('-')
+  family = p[0]
+  type = p[1]
+
+  return '%s-%s/%s-%s-medium.ttf' % (family, type, family, type)
+
+def get_glyph_list(fontfile):
+  ret = []
+  font = fontforge.open(fontfile)
+  for g in font:
+    glyph = font[g]
+    ret.append(glyph.unicode)
+  font.close()
+  return ret
+
+def remove_dep_item(list1, list2):
+  for l in list1:
+    list2.remove(l)
+
+  return list2
+
+def print_result_list(list):
+  out = sys.stdout
+  col = 0
+  dec = 0
+  for n in list:
+    if n < 0 or n > sys.maxunicode:
+      continue
+    if col != 0:
+      out.write('、')
+    col = col + 1
+    out.write(unichr(n).encode('utf-8'))
+    if col == 10:
+      col = 0
+      dec = dec + 1
+      out.write('\n')
+  if col != 0:
+    out.write('\n')
+  out.write('%d chars\n' % (dec * 10 + col))
+
+
+if __name__ == '__main__':
+  if len(sys.argv) != 3:
+    print 'usage: %s tar.gz-file font-file' % sys.argv[0]
+    sys.exit(1)
+
+  archive = sys.argv[1]
+  newfile = sys.argv[2]
+
+  fontfile = get_fontfilename_in_archive(archive)
+  f = tarfile.open(archive, 'r:gz')
+  f.extract(fontfile)
+
+  oldglyphs = get_glyph_list(fontfile)
+  newglyphs = get_glyph_list(newfile)
+
+  result = remove_dep_item(oldglyphs, newglyphs)
+  print_result_list(result)
+
+  os.remove(fontfile)
+  os.rmdir(fontfile.split('/')[0])