CAD and EMF-family formats cannot embed browser webfonts directly. Use rasterizeFontTextNodes() to preserve exact text appearance for those targets.
Code
import {
extractIRWithAssets,
rasterizeFontTextNodes,
renderIR,
DWGWriter,
EMFWriter
} from "@node-projects/layout2vector";
async function exportCadWithFontFidelity(root) {
const bounds = root.getBoundingClientRect();
const { ir, fontAssets } = await extractIRWithAssets(root, {
includeFonts: true,
includeText: true,
includeImages: true
});
const fallbackIr = await rasterizeFontTextNodes(ir, fontAssets, {
scale: 2
});
const dwgBytes = await renderIR(fallbackIr, new DWGWriter({
maxY: Math.ceil(bounds.height)
}));
const emfBytes = await renderIR(fallbackIr, new EMFWriter({
width: bounds.width,
height: bounds.height
}));
return { dwgBytes, emfBytes };
}