38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
import faces from '../fonts.json';
|
|
|
|
const buffers = new Map();
|
|
|
|
export async function loadTemplateFonts() {
|
|
await Promise.all(faces.map(async (face) => {
|
|
const response = await fetch(`/fonts/${face.file}`);
|
|
if (!response.ok) throw new Error(`Schriftdatei fehlt: ${face.file} (HTTP ${response.status})`);
|
|
const bytes = await response.arrayBuffer();
|
|
// One set of OTF bytes for both native shaping and browser painting.
|
|
const font = new FontFace(face.alias, bytes, { style: face.style, weight: '400' });
|
|
await font.load();
|
|
document.fonts.add(font);
|
|
buffers.set(face.file, bytes);
|
|
}));
|
|
await document.fonts.ready;
|
|
window.__betterofficeFontsReady = true;
|
|
}
|
|
|
|
export const measurementFontProvider = {
|
|
resolve(family, bold, italic) {
|
|
const normalized = family.toLowerCase();
|
|
// Empty paragraphs in this template inherit Calibri. Give those paragraphs
|
|
// the same brand metrics instead of allowing synthetic line measurements.
|
|
let face = faces.find((f) =>
|
|
(f.alias.toLowerCase() === normalized || f.family.toLowerCase() === normalized ||
|
|
(normalized === 'calibri' && f.alias === 'SuisseIntlLight')) &&
|
|
f.style === (italic ? 'italic' : 'normal'));
|
|
if (bold && !italic && face) face = faces.find((f) => f.alias === 'SuisseIntlSemiBold');
|
|
if (!face || (bold && italic)) throw new Error(`Nicht unterstützte Schrift: ${family} (bold=${bold}, italic=${italic})`);
|
|
return async () => {
|
|
const bytes = buffers.get(face.file);
|
|
if (!bytes) throw new Error(`Schrift wurde nicht geladen: ${face.file}`);
|
|
return bytes;
|
|
};
|
|
},
|
|
};
|