您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python unicode渲染:如何知道字体中是否缺少Unicode字符

python unicode渲染:如何知道字体中是否缺少Unicode字符

参见https://unix.stackexchange.com/questions/247108/how-to-find-out-which- unicode-codepoints-are-defined-in-a- ttf文件

简而言之,可以安装fonttools软件包,为它提供任何感兴趣的.ttf字体文件的路径,并检查字体文件的unicode映射表中是否包含感兴趣的unicode字符的长格式。

from fontTools.ttLib import TTFont
font = TTFont(fontpath)   # specify the path to the font in question


def char_in_font(unicode_char, font):
    for cmap in font['cmap'].tables:
        if cmap.isUnicode():
            if ord(unicode_char) in cmap.cmap:
                return True
    return False

然后只需调用char_in_font函数来检查字体中是否包含unicode字符。

python 2022/1/1 18:37:33 有293人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶