代码拉取完成,页面将自动刷新
from tkinter import messagebox
from itertools import chain
import sys
from fontTools.ttLib import TTFont
from fontTools.unicode import Unicode
def font_import(filename, font_id=-1, lang="en"):
#language localization
if lang == "zhs": #simplified chinese
message_title = "进度"
message_text = "已加载字体文件:"
elif lang == "zht": #traditional chinese
message_title = "進度"
message_text = "已加載字型文件:"
else:
message_title = "Progress"
message_text = "Loaded font file: "
messagebox.showinfo(message_title , message_text+filename)
#open font with given number
ttf = TTFont(filename, 0, allowVID=0,
ignoreDecompileErrors=True,
fontNumber=font_id)
#get chars from cmap
chars = chain.from_iterable([y + (Unicode[y[0]],) for y in x.cmap.items()] for x in ttf["cmap"].tables)
return chars
#close font
ttf.close()
def is_font(filename):
try: #open the font with TTFont
#if ttc or otc, fontNumber must be 0 (first font in otc)
if filename.lower().endswith(".otc") or filename.lower().endswith(".ttc"):
font = TTFont(filename, 0, allowVID=0,
ignoreDecompileErrors=True,
fontNumber=0)
else: #single font use fontNumber=-1
font = TTFont(filename, 0, allowVID=0,
ignoreDecompileErrors=True,
fontNumber=-1)
#close font
font.close()
return True
except:
return False
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。