Created
March 21, 2023 08:54
-
-
Save teshanshanuka/11c6145dd6b00ffca79c717525dc39b2 to your computer and use it in GitHub Desktop.
Find characters by description (regex) from font
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python3 | |
# Author: Teshan Liyanage <[email protected]> | |
# 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