Skip to content

Instantly share code, notes, and snippets.

@teshanshanuka
Created March 21, 2023 08:54
Show Gist options
  • Save teshanshanuka/11c6145dd6b00ffca79c717525dc39b2 to your computer and use it in GitHub Desktop.
Save teshanshanuka/11c6145dd6b00ffca79c717525dc39b2 to your computer and use it in GitHub Desktop.
Find characters by description (regex) from font
#!python3
# Author: Teshan Liyanage <teshanuka@gmail.com>
# Usage: ./search_font.py '^git'
import freetype, sys, re
def findg(f, s):
ret = []
for c,g in f.get_chars():
gn = f.get_glyph_name(g).decode()
if re.search(s, gn):
ret.append((c, gn))
return ret
# Possible font locations - /usr/local/share/fonts, /opt/powerline-fonts, ~/.local/share/fonts/, /usr/share/fonts
fc = freetype.Face("/usr/local/share/fonts/f/Fira_Code_Regular_Nerd_Font_Complete_Mono.ttf")
for c, d in findg(fc, sys.argv[1]):
print(chr(c), d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment