# -*- coding: utf-8 -*-
-# Author: mshio <mshio@users.sourceforge.jp>
+# Author: mshio <mshio@users.osdn.me>
-__version__ = '0.11'
+__version__ = '0.12'
import fontforge
-from types import MethodType
+def filter_glyphs(font_path, method):
+ forge = fontforge.open(font_path)
+ array = [method(forge[g]) for g in forge if g[0] is not '.' and forge[g].unicode > 0]
+ return [x for x in array if x]
-class FontParser:
- """
- An object in order to parse the characters in the specified font.
- """
- def __init__(self, font_path):
- self.forge = fontforge.open(font_path)
+def font_diff(old_font_path, new_font_path):
+ old = fontforge.open(old_font_path)
+ return filter_glyphs(new_font_path, lambda g: g.unicode if g.glyphname not in old else None)
- def parse(self, method):
- self.proc = MethodType(method, self, FontParser)
- f = self.forge
- for g in f:
- if g[0] != '.' and f[g].unicode > 0:
- self.proc(f[g])
-
-class FontDiffParser:
- def __init__(self, old_font_path, new_font_path):
- self.font_path = [old_font_path, new_font_path]
-
- def get_diff(self):
- buf = []
- old = fontforge.open(self.font_path[0])
-
- def collect(self, glyph_obj):
- if glyph_obj.glyphname not in old:
- buf.append(glyph_obj.unicode)
-
- FontParser(self.font_path[1]).parse(collect)
-
- return buf
+def all_of_kanjis(font_path):
+ return filter_glyphs(font_path, lambda g: g.unicode if 0x4e00 <= g.unicode <= 0x9fff else None)