import { registerFont } from "canvas"; let loaded = false; // ponytail: real TTFs installed by the Dockerfile — FreeType cannot read @fontsource's .woff, // which fell back to a missing family and rendered every glyph as a tofu box. const FONT_DIR = process.env.CAPTION_FONT_DIR || "/usr/share/fonts/truetype/reel"; const FONTS = [ { file: `${FONT_DIR}/Anton-Regular.ttf`, family: "Anton" }, { file: `${FONT_DIR}/Oswald.ttf`, family: "Oswald" }, ]; export function loadFonts() { if (loaded) return; loaded = true; for (const font of FONTS) { try { registerFont(font.file, { family: font.family }); } catch (error) { // loud on purpose: a missing font means unreadable captions, not a cosmetic downgrade console.error(`Failed to register font ${font.family} from ${font.file}:`, error); } } }