Summary
Any --font flag (docx styles set --font, docx edit --font, docx create --style-font, whatever calls applyRunFont) only writes w:ascii / w:hAnsi / w:cs on <w:rFonts>. It intentionally leaves w:eastAsia untouched — per the docstring on applyRunFont in src/core/ast/document/styles.tsx:
/** Point a `<w:rFonts>` at `fontName` for the Latin/ASCII script: set
* `w:ascii`/`w:hAnsi`/`w:cs` and DROP any `w:asciiTheme`/`w:hAnsiTheme`/
* `w:cstheme` reference (an explicit font must beat the theme). East-Asian /
* complex-script fallbacks (`w:eastAsia`) are left alone. Shared by
* `setDefaultFont`, `overrideStyleFonts`, and the `Fonts` lens's body/note walk. */
export function applyRunFont(rFonts: XmlNode, fontName: string): void {
rFonts.setAttribute("w:ascii", fontName);
rFonts.setAttribute("w:hAnsi", fontName);
rFonts.setAttribute("w:cs", fontName);
delete rFonts.attributes["w:asciiTheme"];
delete rFonts.attributes["w:hAnsiTheme"];
delete rFonts.attributes["w:cstheme"];
}
For a document whose visible text is Latin, this is invisible — nothing renders through w:eastAsia anyway. For a document whose visible text is Chinese/Japanese/Korean, it's the opposite: the change appears to do nothing, because CJK glyph shaping resolves through w:eastAsia (or its w:eastAsiaTheme fallback when no explicit w:eastAsia is set), never through w:ascii/w:hAnsi.
Repro
docx create doc.docx --from - with a heading whose text is Chinese (e.g. # 标题). The built-in Heading 1 style ships with w:rFonts w:eastAsiaTheme="majorEastAsia" w:asciiTheme="majorHAnsi" ... (no explicit w:ascii/w:eastAsia).
docx styles set doc.docx --at Heading1 --font SimSun
- Inspect the result:
docx raw part get doc.docx --name word/styles.xml shows Heading1's <w:rFonts> now has explicit w:ascii="SimSun" w:hAnsi="SimSun" w:cs="SimSun", but w:eastAsiaTheme="majorEastAsia" is still there and there is no explicit w:eastAsia.
- Open in real Word (or render with a Word-faithful renderer): the Chinese heading text is still rendered in the theme's East Asian font (e.g. 等线/微软雅黑), not SimSun — even though
docx styles --at Heading1 / a naive XML read makes it look like the font is "set". docx render's LibreOffice-based rasterizer did not reproduce this discrepancy for us, which made the bug easy to miss during verification — only inspecting the raw word/styles.xml XML surfaced it.
Impact
Any CJK-primary document (the majority of the visible content is Chinese/Japanese/Korean) gets zero visible effect from --font on headings/styles unless the user already knows to separately patch w:eastAsia via docx raw part edit. There's currently no CLI surface (no --font-east-asia/--cjk-font/similar) to set it directly — raw part edit string-replace is the only way today, which is fragile (unscoped match blast radius across word/styles.xml) and not discoverable.
Suggested fix
Add an explicit East-Asian-script font control alongside --font, e.g. --font-east-asia NAME (or --font-cjk), wired through the same RunFormat/applyRunFormatToRpr path --font already uses, applying to w:eastAsia and dropping w:eastAsiaTheme the same way applyRunFont does for the Latin attrs. Happy to open a PR — have a patch ready that:
- extracts a parallel
applyRunFontEastAsia(rFonts, fontName) next to applyRunFont
- threads a new optional
fontEastAsia field through RunFormat
- adds
--font-east-asia to the shared style/run-format flag parser used by styles set, styles create, and edit
- updates README/CLAUDE.md docs and adds a CJK fixture + assertion to the existing font fidelity test
Found this while generating/patching Chinese-language .docx deliverables (software copyright registration materials) with docx-cli 0.21.0 (confirmed still present in 0.25.0 — no font-scope-related commits between the two in the changelog).
Summary
Any
--fontflag (docx styles set --font,docx edit --font,docx create --style-font, whatever callsapplyRunFont) only writesw:ascii/w:hAnsi/w:cson<w:rFonts>. It intentionally leavesw:eastAsiauntouched — per the docstring onapplyRunFontinsrc/core/ast/document/styles.tsx:For a document whose visible text is Latin, this is invisible — nothing renders through
w:eastAsiaanyway. For a document whose visible text is Chinese/Japanese/Korean, it's the opposite: the change appears to do nothing, because CJK glyph shaping resolves throughw:eastAsia(or itsw:eastAsiaThemefallback when no explicitw:eastAsiais set), never throughw:ascii/w:hAnsi.Repro
docx create doc.docx --from -with a heading whose text is Chinese (e.g.# 标题). The built-inHeading 1style ships withw:rFonts w:eastAsiaTheme="majorEastAsia" w:asciiTheme="majorHAnsi" ...(no explicitw:ascii/w:eastAsia).docx styles set doc.docx --at Heading1 --font SimSundocx raw part get doc.docx --name word/styles.xmlshowsHeading1's<w:rFonts>now has explicitw:ascii="SimSun" w:hAnsi="SimSun" w:cs="SimSun", butw:eastAsiaTheme="majorEastAsia"is still there and there is no explicitw:eastAsia.docx styles --at Heading1/ a naive XML read makes it look like the font is "set".docx render's LibreOffice-based rasterizer did not reproduce this discrepancy for us, which made the bug easy to miss during verification — only inspecting the rawword/styles.xmlXML surfaced it.Impact
Any CJK-primary document (the majority of the visible content is Chinese/Japanese/Korean) gets zero visible effect from
--fonton headings/styles unless the user already knows to separately patchw:eastAsiaviadocx raw part edit. There's currently no CLI surface (no--font-east-asia/--cjk-font/similar) to set it directly —raw part editstring-replace is the only way today, which is fragile (unscoped match blast radius acrossword/styles.xml) and not discoverable.Suggested fix
Add an explicit East-Asian-script font control alongside
--font, e.g.--font-east-asia NAME(or--font-cjk), wired through the sameRunFormat/applyRunFormatToRprpath--fontalready uses, applying tow:eastAsiaand droppingw:eastAsiaThemethe same wayapplyRunFontdoes for the Latin attrs. Happy to open a PR — have a patch ready that:applyRunFontEastAsia(rFonts, fontName)next toapplyRunFontfontEastAsiafield throughRunFormat--font-east-asiato the shared style/run-format flag parser used bystyles set,styles create, andeditFound this while generating/patching Chinese-language
.docxdeliverables (software copyright registration materials) with docx-cli 0.21.0 (confirmed still present in 0.25.0 — no font-scope-related commits between the two in the changelog).