Finding out what characters a given font supports

前端 未结 12 1586
你的背包
你的背包 2020-11-30 22:24

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

Is there a tool or a library I can use to process a .tt

12条回答
  •  情书的邮戳
    2020-11-30 22:46

    If you want to get all characters supported by a font, you may use the following (based on Janus's answer)

    from fontTools.ttLib import TTFont
    
    def get_font_characters(font_path):
        with TTFont(font_path) as font:
            characters = {chr(y[0]) for x in font["cmap"].tables for y in x.cmap.items()}
        return characters
    

提交回复
热议问题