Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion app/styles.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Handling of styles.

import std/[strformat, strutils, decls]
import std/[strformat, strutils, decls, os]
import screen, input
import nimscript/common

Expand Down Expand Up @@ -36,7 +36,19 @@ type

proc findFontFile(name: string): Path =
##[Returns the absolute path of the font file named `name`.tff.
First searches in 'fonts/' directory next to the executable,
then falls back to system font directories.
Otherwise, raises `IOError`.]##

# 1. First, try to find font in 'fonts/' directory next to executable
let exeDir = os.getAppDir()
let localFontsDir = exeDir / "fonts"
if localFontsDir.dirExists:
let toMatch = name.Path.addFileExt("ttf")
for file in localFontsDir.Path.walkDirRec({pcFile, pcLinkToFile}):
if file.extractFilename == toMatch.extractFilename: return file

# 2. Fall back to system fonts
const AllFonts = when defined(linux): Path"/usr/share/fonts/truetype/"
elif defined(windows): Path r"C:\Windows\Fonts\"
elif defined(openIndiana): Path"/usr/share/fonts/TrueType/"
Expand Down