如何找出哪种字体可以显示这些字符?

3
⚫⚪
Unicode U+26AB
Unicode U+26AA

enter image description here

这两个字符可以在终端中显示,我想使用convert(一个imagemagick命令)将这些文本转换为图片。

但是convert只能使用一种特殊字体,不能使用回退字体。

convert -list font

那么我该如何找到能够显示这些字符的字体呢?


不确定你的问题是什么。你想知道字体的名称吗?还是想知道如何生成Unicode字符?或者你想知道黑色和白色圆圈的Unicode符号 - 我认为它们分别是25CB26AB?还是你想知道如何在ImageMagick命令中指定字体? - undefined
我想要一个真正的字体名称,可以在我的终端中显示这两个字符,就像屏幕截图中显示的那样。当然,默认的终端字体无法显示它,必须使用一些备用字体系列。 - undefined
2个回答

3

我修改了这个答案中的代码,制作了一个脚本,以查找包含特定字符的字体,如下:

#!/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])

因此,现在我可以使用以下方法来查找包含您的两个圆的字体:

enter image description here


是的,在安装了python3-fonttools之后,你的脚本会列出所有包含该字符的字体。我可以选择每个字体并进行测试。谢谢。 - undefined

2
你可以使用 fc-list 命令:
fc-list :charset=26AA,26AB

它将列出支持两种字符的已安装字体。

另请参见此处我的答案,其中包含更多细节。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接