tools: Schriften plattformunabhängig finden, Setup für macOS dokumentieren

- tools/fontpicker.py sucht DejaVu über WESTREICHE_FONT_DIR, Linux-Pfade und
  ~/Library/Fonts statt festem /usr/share/fonts/truetype/dejavu
- PDF-Skripte (Almanach, Liturgie, SL-Tabellen, SL-Schirm) nutzen den Finder
- tools/requirements.txt (reportlab, markdown, pillow) + Setup-Abschnitt in
  AGENTS.md inkl. ghostscript, pandoc und font-dejavu für macOS
This commit is contained in:
torsten 2026-11-20 17:30:35 +01:00
parent 2dd6295caf
commit 7ab88b6d73
6 changed files with 91 additions and 3 deletions

55
tools/fontpicker.py Normal file
View file

@ -0,0 +1,55 @@
"""Findet das Verzeichnis mit den DejaVu-Schriften – Linux (Desktop) wie macOS.
Reihenfolge:
1. Umgebungsvariable ``WESTREICHE_FONT_DIR`` (manueller Override),
2. übliche Installationspfade (Linux-Distributionen, Homebrew-Cask auf macOS),
3. Rückfall: Suche per ``fc-list``/``mdfind``-freier Kandidatenliste im Home-Verzeichnis.
Die PDF-Skripte registrieren ihre Schriften damit unabhängig vom Betriebssystem.
"""
from __future__ import annotations
import os
from pathlib import Path
CANDIDATES = (
"/usr/share/fonts/truetype/dejavu", # Debian/Ubuntu
"/usr/share/fonts/dejavu", # Fedora/Arch
"/usr/share/fonts/TTF", # Arch
"/usr/local/share/fonts/dejavu",
"/opt/homebrew/share/fonts", # Homebrew (macOS, arm64)
"/usr/local/share/fonts", # Homebrew (macOS, intel)
"~/Library/Fonts", # macOS: `brew install --cask font-dejavu`
"/Library/Fonts",
"/System/Library/Fonts/Supplemental",
)
NEEDED = ("DejaVuSerif.ttf", "DejaVuSans.ttf")
HINT = (
"DejaVu-Schriften nicht gefunden. Installation:\n"
" macOS: brew install --cask font-dejavu\n"
" Debian: sudo apt install fonts-dejavu\n"
" oder: WESTREICHE_FONT_DIR=/pfad/zu/den/ttf exportieren"
)
def _enough(path: Path) -> bool:
return all((path / name).is_file() for name in NEEDED)
def font_dir() -> Path:
env = os.environ.get("WESTREICHE_FONT_DIR")
if env:
candidate = Path(env).expanduser()
if _enough(candidate):
return candidate
raise SystemExit(f"WESTREICHE_FONT_DIR={env} enthält keine DejaVu-Schriften.\n{HINT}")
for raw in CANDIDATES:
candidate = Path(raw).expanduser()
if _enough(candidate):
return candidate
raise SystemExit(HINT)