From 31f9afc7af5ec99276ba3eabd57192dbf8ee6ae1 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 11 Mar 2026 22:11:39 +0100 Subject: [PATCH] Fonts: search for fonts in system/user paths Local copies of fonts will still be prioritized, but this fallback allows us to eventually remove a few TrueType fonts from the repo and rely on system packages for fonts instead. --- src/displayapp/fonts/generate.py | 34 +++++++++++++++++++++++++++++++- src/resources/generate-fonts.py | 34 +++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/displayapp/fonts/generate.py b/src/displayapp/fonts/generate.py index 88bdacd61d..9378756d05 100755 --- a/src/displayapp/fonts/generate.py +++ b/src/displayapp/fonts/generate.py @@ -9,11 +9,43 @@ import argparse import subprocess +# Common system font locations to try when a font file is not found locally +COMMON_FONT_DIRS = [ + '/usr/share/fonts', + '/usr/local/share/fonts', + os.path.expanduser('~/.local/share/fonts'), + os.path.expanduser('~/.fonts'), +] + class Source(object): def __init__(self, d): self.file = d['file'] if not os.path.exists(self.file): - self.file = os.path.join(os.path.dirname(sys.argv[0]), self.file) + # First try relative to the script directory (previous behavior) + candidate = os.path.join(os.path.dirname(sys.argv[0]), self.file) + if os.path.exists(candidate): + self.file = candidate + else: + # Fallback: search common system font directories for a matching basename + name = os.path.basename(self.file) + found = None + for font_dir in COMMON_FONT_DIRS: + if not font_dir: + continue + font_dir = os.path.expanduser(font_dir) + if not os.path.isdir(font_dir): + continue + for root, _, files in os.walk(font_dir): + for f in files: + if f.lower() == name.lower(): + found = os.path.join(root, f) + break + if found: + break + if found: + break + if found: + self.file = found self.range = d.get('range') self.symbols = d.get('symbols') diff --git a/src/resources/generate-fonts.py b/src/resources/generate-fonts.py index 20408166d3..5df3b24808 100755 --- a/src/resources/generate-fonts.py +++ b/src/resources/generate-fonts.py @@ -9,11 +9,43 @@ import argparse import subprocess +# Common system font locations to try when a font file is not found locally +COMMON_FONT_DIRS = [ + '/usr/share/fonts', + '/usr/local/share/fonts', + os.path.expanduser('~/.local/share/fonts'), + os.path.expanduser('~/.fonts'), +] + class Source(object): def __init__(self, d): self.file = d['file'] if not os.path.exists(self.file): - self.file = os.path.join(os.path.dirname(sys.argv[0]), self.file) + # First try relative to the script directory (previous behavior) + candidate = os.path.join(os.path.dirname(sys.argv[0]), self.file) + if os.path.exists(candidate): + self.file = candidate + else: + # Fallback: search common system font directories for a matching basename + name = os.path.basename(self.file) + found = None + for font_dir in COMMON_FONT_DIRS: + if not font_dir: + continue + font_dir = os.path.expanduser(font_dir) + if not os.path.isdir(font_dir): + continue + for root, _, files in os.walk(font_dir): + for f in files: + if f.lower() == name.lower(): + found = os.path.join(root, f) + break + if found: + break + if found: + break + if found: + self.file = found self.range = d.get('range') self.symbols = d.get('symbols')