feat(export): wire DOCX export through DocxFontEmbedder

Embeds regular + bold TTF of the active monospace family into pandoc's
DOCX output. ODT uses pandoc's built-in font handling; RTF has no font
embedding capability (documented limitation).
This commit is contained in:
2026-08-23 19:31:33 +05:30
parent e5e14c88ce
commit f04a20252f
+16 -1
View File
@@ -10,6 +10,7 @@ const PdfFontHeader = require('./main/PdfFontHeader');
const MonospaceFontConfig = require('./main/MonospaceFontConfig');
const ExportCss = require('./main/ExportCss');
const EpubFontEmbedder = require('./main/EpubFontEmbedder');
const DocxFontEmbedder = require('./main/DocxFontEmbedder');
// Add MiKTeX to PATH for LaTeX support
if (process.platform === 'win32') {
@@ -2748,7 +2749,21 @@ function performExportWithOptions(format, options) {
});
} else if (format === 'docx') {
pandocCmd += ' -t docx';
exportWithPandoc(pandocCmd, outputFile, format, () => {
exportWithPandoc(pandocCmd, outputFile, format, async () => {
// Embed the active monospace TTF into the DOCX so code blocks render in
// JetBrains Mono / Fira Code regardless of the viewer's installed fonts.
try {
const familyKey = readSettingsJsonCached().monospaceFont || 'jetbrains-mono';
const family = familyKey === 'fira-code' ? 'Fira Code' : 'JetBrains Mono';
const regular = MonospaceFontConfig.getMonoFontTtfPath(familyKey, 400);
const bold = MonospaceFontConfig.getMonoFontTtfPath(familyKey, 700);
const fonts = [];
if (regular) fonts.push({ path: regular, family, weight: 400 });
if (bold) fonts.push({ path: bold, family, weight: 700 });
if (fonts.length) await DocxFontEmbedder.embed(outputFile, fonts);
} catch (embedErr) {
if (typeof console !== 'undefined') console.warn('[docx] font embed failed:', embedErr.message);
}
if (tempInputFile) {
try {
fs.unlinkSync(tempInputFile);