我修改了这个答案中的代码,制作了一个脚本,以查找包含特定字符的字体,如下:
#!/usr/bin/env python3
import os, sys
import unicodedata
from fontTools.ttLib import TTFont
from sys import platform
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
def test(char):
for fontpath in fonts:
font = TTFont(fontpath) # specify the path to the font in question
if char_in_font(char, font):
print(char + " "+ unicodedata.name(char) + " in " + fontpath)
if __name__ == '__main__':
if platform == "linux":
likelyPlaces = ['/usr/share/fonts', '/usr/local/share/fonts', '~/.fonts']
elif platform == "darwin":
likelyPlaces = ['/System/Library/Fonts', '/Library/Fonts', '~/Library/Fonts']
elif platform == "win32":
likelyPlaces = ['WHO KNOWS']
fonts = []
for place in likelyPlaces:
for root,dirs,files in os.walk(os.path.expanduser(place)):
for file in files:
if file.endswith(".ttf"): fonts.append(os.path.join(root,file))
# Check user has specified a character
if len(sys.argv) != 2:
sys.exit("Usage: findfont.py glyph")
test(sys.argv[1])
python3-fonttools
之后,你的脚本会列出所有包含该字符的字体。我可以选择每个字体并进行测试。谢谢。 - undefined
25CB
和26AB
?还是你想知道如何在ImageMagick命令中指定字体? - undefined