赞
踩
- ############### 判断字体中是否都包含字典中的字符 ################
- from fontTools.ttLib import TTFont
- import os
- from shutil import copyfile
- from fontTools.ttLib.sfnt import DirectoryEntry
- with open('/data/git/ocr-platform/statistic/TextGenerator/TextGenerator/process/dicts/chinese_dict.txt','r') as f1:
- dict_chinese=f1.readline()
- f1.close()
- print(len(dict_chinese))
-
- font_fd='/data/git/ocr-platform/statistic/TextGenerator/TextGenerator/fonts/general_en/'
- save_fd='/data/git/ocr-platform/statistic/TextGenerator/TextGenerator/fonts/cn/'
- # fontType = "/data/git/ocr-platform/statistic/TextGenerator/TextGenerator/fonts/general_en_del/ARIAL.ttf"
- for font_name in os.listdir(font_fd):
- if font_name.endswith('.ttf') or font_name.endswith('.TTF'):
- fontType=font_fd+font_name
- print('###################')
- print(fontType)
- font = TTFont(fontType)
- uniMap = font['cmap'].tables[0].ttFont.getBestCmap()
- # print (ord('1') in uniMap.keys()) #True
- glyfMapDict = TTFont(fontType)['glyf']
- # print(len(glyfMapDict[uniMap[ord('1')]].getCoordinates(0)[0]))#23
- count=0
- for c in dict_chinese:
- # print(c)
- if uniMap is not None:
- if ord(c) in uniMap.keys():
- count+=1
- pass
- else:
- if font_name=='simsun.ttf':
- print(c)
- if count==len(dict_chinese):
- print(save_fd+font_name)
- copyfile(fontType, save_fd+font_name)

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。