OSDN Git Service

convert all of fontparser classes into functions
[sawarabi-fonts/sawarabi-fonts.git] / script / fontparser.py
1 # -*- coding: utf-8 -*-
2
3 # Author: mshio <mshio@users.osdn.me>
4
5 __version__ = '0.12'
6
7 import fontforge
8
9 def filter_glyphs(font_path, method):
10     forge = fontforge.open(font_path)
11     array = [method(forge[g]) for g in forge if g[0] is not '.' and forge[g].unicode > 0]
12     return [x for x in array if x]
13
14 def font_diff(old_font_path, new_font_path):
15     old = fontforge.open(old_font_path)
16     return filter_glyphs(new_font_path, lambda g: g.unicode if g.glyphname not in old else None)
17
18 def all_of_kanjis(font_path):
19     return filter_glyphs(font_path, lambda g: g.unicode if 0x4e00 <= g.unicode <= 0x9fff else None)