Commit 391a58ba authored by wanli's avatar wanli

feat: evuefonttool.py新增字段

parent adc92e5a
......@@ -64,10 +64,9 @@ class EvueFontTool(object):
'advance': self.face.glyph.advance.x / 64,
'cols': self.face.glyph.bitmap.width,
'rows': self.face.glyph.bitmap.rows,
'bitmap': self.face.glyph.bitmap.buffer, # list[]
'count': len(self.face.glyph.bitmap.buffer),
}
return char_info
return char_info, self.face.glyph.bitmap.buffer
def dump(self, used_string):
# 遍历每一个字体
......@@ -75,6 +74,7 @@ class EvueFontTool(object):
'name': self.fontInfo.get("family"),
'info': self.fontInfo,
'text': used_string,
'charInfo': {},
'size': self.sizes,
'bitmap': {
'total': 0
......@@ -85,15 +85,22 @@ class EvueFontTool(object):
for size in self.sizes:
# 设置字体大小
self.face.set_char_size(size * 64, 0, self.FONT_DPI, 0)
char_info = self.charInfo(cur_char)
char_info, bitmap = self.charInfo(cur_char)
self.infos.append(char_info)
size_key = str(size)
if size_key not in dump_json['charInfo']:
dump_json['charInfo'][size_key] = {}
else:
dump_json['charInfo'][size_key].update({str(char_info.get('glyph')): char_info})
# 文件命名规则:./<output_dir>/<font-size>/<unicode-number>.bin
target_dir = self.output_dir.joinpath(str(size)).joinpath("{}.bin".format(char_info.get('glyph')))
if not target_dir.parent.exists():
target_dir.parent.mkdir()
with open(target_dir.resolve().as_posix(), 'wb+') as f:
f.write(struct.pack("%dB" % char_info['count'], *char_info['bitmap']))
f.write(struct.pack("%dB" % char_info['count'], *bitmap))
dump_json['bitmap'].update({
size: dump_json.get('bitmap').get(size, 0) + target_dir.stat().st_size
......@@ -106,7 +113,7 @@ class EvueFontTool(object):
pprint.pprint(dump_json)
# 在输出目录下,生成一个json索引文件
with open(self.output_dir.joinpath("fonts.json").resolve().as_posix(), "wb+") as f:
f.write(json.dumps(dump_json, ensure_ascii=False, indent=2).encode('utf-8'))
f.write(json.dumps(dump_json, ensure_ascii=False).encode('utf-8'))
def load(self, file):
pass
......@@ -131,9 +138,9 @@ class EvueFontTool(object):
if __name__ == '__main__':
print(mimetypes.guess_type(sys.argv[1])[0])
# print(mimetypes.guess_type(sys.argv[1])[0])
evueFontTool = EvueFontTool(sys.argv[1], sys.argv[2])
text = '中国'
text = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890中国'
# evueFontTool.test(text)
evueFontTool.dump(text)
pprint.pprint(evueFontTool.fontInfo)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment