找出给定字体支持哪些字符 [英] Finding out what characters a given font supports

查看:101
本文介绍了找出给定字体支持哪些字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Linux上的TrueType或嵌入式OpenType字体中提取受支持的Unicode字符列表?

How do I extract the list of supported Unicode characters from a TrueType or embedded OpenType font on Linux?

是否可以使用工具或库来处理.ttf或.eot文件,并建立字体提供的代码点列表(例如U + 0123,U + 1234等)?

Is there a tool or a library I can use to process a .ttf or a .eot file and build a list of code points (like U+0123, U+1234, etc.) provided by the font?

推荐答案

以下是使用 FontTools 模块(您可以使用pip install fonttools之类的模块进行安装):

Here is a method using the FontTools module (which you can install with something like pip install fonttools):

#!/usr/bin/env python
from itertools import chain
import sys

from fontTools.ttLib import TTFont
from fontTools.unicode import Unicode

ttf = TTFont(sys.argv[1], 0, verbose=0, allowVID=0,
                ignoreDecompileErrors=True,
                fontNumber=-1)

chars = chain.from_iterable([y + (Unicode[y[0]],) for y in x.cmap.items()] for x in ttf["cmap"].tables)
print(list(chars))

# Use this for just checking if the font contains the codepoint given as
# second argument:
#char = int(sys.argv[2], 0)
#print(Unicode[char])
#print(char in (x[0] for x in chars))

ttf.close()

脚本以字体路径作为参数:

The script takes as argument the font path :

python checkfont.py /path/to/font.ttf

这篇关于找出给定字体支持哪些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆