Skip to content

Instantly share code, notes, and snippets.

@vaguinerg
Last active June 24, 2025 17:56
Show Gist options
  • Save vaguinerg/28004e9a47555df081392c9453740e47 to your computer and use it in GitHub Desktop.
Save vaguinerg/28004e9a47555df081392c9453740e47 to your computer and use it in GitHub Desktop.
A lightweight Nim library for retrieving system-installed fonts across multiple platforms.
import os
const defaultFontsDirectories =
when defined(android):
["/system/fonts"]
elif defined(macosx):
[
"/Library/Fonts/",
"/System/Library/Fonts/",
"/Network/Library/Fonts/",
expandTilde("~/Library/Fonts/")
]
elif defined(windows):
[
getEnv("WINDIR", r"C:\Windows") & r"\Fonts\",
getEnv("WINDIR", r"C:\Windows") & r"\System32\Fonts\",
getEnv("USERPROFILE") & r"\AppData\Local\Microsoft\Windows\Fonts\"
]
else:
[
"/usr/share/fonts/",
"/usr/local/share/fonts/",
"/usr/lib/X11/fonts/",
"/usr/local/lib/X11/fonts/",
"/usr/X11R6/lib/X11/fonts/",
"/usr/local/X11R6/lib/X11/fonts/",
"/var/lib/fonts/",
expandTilde("~/.local/share/fonts/"),
expandTilde("~/.fonts/")
]
proc getSystemFonts*(): seq[string] =
result = @[]
for dir in defaultFontsDirectories:
for filePath in walkDirRec(dir, {pcFile, pcLinkToFile}):
if splitFile(filePath).ext in [".ttf", ".otf"]:
result.add(filePath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment