找出字体支持的字符 [英] Finding out what characters a font supports

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

问题描述

如何在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天全站免登陆