Files
vibemake-pcb-studio/qa/perf/node_outline_faces.mts
T
likang 7e01147566
CI / typecheck + test + build (push) Has been cancelled
Initial commit: import VibeMake PCB Studio
2026-11-03 11:20:08 +08:00

38 lines
1.4 KiB
TypeScript

// `OUTLINE_FONT::LoadFont`'s face source for node: fontconfig's catalogue
// answered from the bundled files on disk, the same faces the browser
// fetches — so a qa run resolves the outline fonts KiCad's oracle used.
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { findFont } from '@ziroeda/common/font/fontconfig.js';
import { OUTLINE_FONT } from '@ziroeda/common/font/outline_font.js';
import { type OutlineFace, parseOutlineFace } from '@ziroeda/common/font/outline_face.js';
const fontsDir = fileURLToPath(new URL('../../designer/public/fonts/', import.meta.url));
const faces = new Map<string, OutlineFace | null>();
export function installNodeOutlineFaces(): void {
OUTLINE_FONT.faceSource = (fontName, bold, italic) => {
const found = findFont(fontName, bold, italic);
if (!found) return null;
let face = faces.get(found.file.file);
if (face === undefined) {
try {
const bytes = readFileSync(fontsDir + found.file.file);
face = parseOutlineFace(
bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength),
);
} catch {
face = null;
}
faces.set(found.file.file, face);
}
if (!face) return null;
return {
face,
fileName: found.file.file,
fakeBold: found.fakeBold,
fakeItalic: found.fakeItalic,
};
};
}