File size: 841 Bytes
ef4c36f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 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);
}
}
}
|