From 4e416dbc4df150c5fdcabcce8813f3f0957d764d Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 27 May 2021 15:24:31 +0200 Subject: [PATCH] Add fint-font script --- scripts/find-font.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 scripts/find-font.py diff --git a/scripts/find-font.py b/scripts/find-font.py new file mode 100644 index 0000000..7858364 --- /dev/null +++ b/scripts/find-font.py @@ -0,0 +1,38 @@ +#!/bin/python +# +# Based on: https://superuser.com/a/1452828 + +import unicodedata +from itertools import chain +# from os import walk, path +import os +from fontTools.ttLib import TTFont + +def find_fonts_in(path): + fonts = [] + for root,dirs,files in os.walk(path): + for file in files: + if file.endswith(".ttf"): fonts.append(os.path.join(root,file)) + return fonts + +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(ch, fonts): + for fontpath in fonts: + font = TTFont(fontpath) + if char_in_font(ch, font): + print(ch + " "+ unicodedata.name(ch) + " in " + fontpath) + +if __name__ =='__main__': + font_dirs = [ "/usr/share/fonts/" + , "/usr/local/share/fonts/" + , "~/.local/share/fonts" + ] + fonts = [font for font_dir in font_dirs for font in find_fonts_in(font_dir)] + + test(u'🪞', fonts)