-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix font finder not working on linux
- Loading branch information
Showing
3 changed files
with
95 additions
and
32 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
|
||
def find_installed_ttfs(): | ||
installed_font_ttfs = [] | ||
|
||
if os.name == 'nt': # Windows | ||
# Find all installed font TTFs | ||
# There are two places to check: | ||
# - System fonts (Windows) | ||
# - User installed fonts (AppData) | ||
|
||
import winreg | ||
for registry_hive in [winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER]: | ||
reg = winreg.ConnectRegistry(None, registry_hive) | ||
key = winreg.OpenKey(reg, r'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts', 0, winreg.KEY_READ) | ||
|
||
for i in range(0, winreg.QueryInfoKey(key)[1]): | ||
ttf = winreg.EnumValue(key, i)[1] | ||
|
||
if '\\' not in ttf: | ||
ttf = os.path.join(os.environ['WINDIR'], 'Fonts', ttf) | ||
|
||
installed_font_ttfs.append(ttf) | ||
elif os.name == 'posix': # Linux | ||
# Common directories where fonts are installed on Linux | ||
font_dirs = [ | ||
'/usr/share/fonts', | ||
'/usr/local/share/fonts', | ||
os.path.expanduser('~/.fonts'), | ||
os.path.expanduser('~/.local/share/fonts') | ||
] | ||
|
||
for font_dir in font_dirs: | ||
for root, _, files in os.walk(font_dir): | ||
for file in files: | ||
if file.lower().endswith('.ttf'): | ||
installed_font_ttfs.append(os.path.join(root, file)) | ||
|
||
return installed_font_ttfs |
This file was deleted.
Oops, something went wrong.