如何找出哪种字体可以显示这些字符? [英] How to find out which font can display these characters?
本文介绍了如何找出哪种字体可以显示这些字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
⚫⚪Unicode U + 26ABUnicode U + 26AA
这两个字符可以在终端中显示,我想使用 convert
(imagemagick命令)将那些文本转换为图片.
但是 convert
只能使用一种特殊字体,不能使用后备字体.
转换-list字体
那我怎么找到哪种字体可以显示那些字符呢?
解决方案
我修改了
⚫⚪
Unicode U+26AB
Unicode U+26AA
This two characters can be display in terminal, I want use convert
(imagemagick command) to convert those text into picture.
But convert
only can use one special font, not fallback font could be used.
convert -list font
So how can I find which font could display those characters?
解决方案
I adapted the code in this answer, to make a script to find which font contains a particular character as follows:
#!/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])
So, I can now call it as follows to find the font containing your two circles:
这篇关于如何找出哪种字体可以显示这些字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文