OSDN Git Service

update many glyphs
[sawarabi-fonts/sawarabi-fonts.git] / script / fontparser.py
1 # -*- coding: utf-8 -*-
2
3 # Author: mshio <mshio@users.sourceforge.jp>
4
5 __version__ = '0.11'
6
7 import fontforge
8 from types import MethodType
9
10
11 class FontParser:
12     """
13     An object in order to parse the characters in the specified font.
14     """
15     def __init__(self, font_path):
16         self.forge = fontforge.open(font_path)
17
18     def parse(self, method):
19         self.proc = MethodType(method, self, FontParser)
20         f = self.forge
21         for g in f:
22             if g[0] != '.' and f[g].unicode > 0:
23                 self.proc(f[g])
24
25 class FontDiffParser:
26     def __init__(self, old_font_path, new_font_path):
27         self.font_path = [old_font_path, new_font_path]
28
29     def get_diff(self):
30         buf = []
31         old = fontforge.open(self.font_path[0])
32
33         def collect(self, glyph_obj):
34             if glyph_obj.glyphname not in old:
35                 buf.append(glyph_obj.unicode)
36
37         FontParser(self.font_path[1]).parse(collect)
38
39         return buf