feat(docx): CJK typography presets (typography.preset=zh-body/zh-first-indent) - #378
Open
ylz92871-dotcom wants to merge 1 commit into
Open
ylz92871-dotcom wants to merge 1 commit into
ylz92871-dotcom wants to merge 1 commit into
Conversation
…t-indent) zh-body: eastAsia SimSun on runs + mark, atLeast single rhythm, spaceAfter 0. zh-first-indent: w:firstLineChars=200 (2 chars), clears w:firstLine. Tests: CJK preset suite green (eastAsia SimSun, atLeast/0, firstLineChars 200); XLSX numeric-fit regression green; publish single-file smoke.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds two named CJK typography presets for DOCX paragraph
set:typography.preset=zh-body— pins an East Asian body face (SimSun/宋体) on every run and the paragraph mark, and sets a CJK-friendly body rhythm:lineRule=atLeast, single line (240),spaceAfter=0.typography.preset=zh-first-indent— setsw:ind/@w:firstLineChars=200(exactly 2 characters, regardless of font size) and clears any hardw:firstLineso the char-relative rule is the only indent source.Unknown values throw with the supported list (
zh-body,zh-first-indent).Why
Chinese-language documents need these two settings on essentially every body paragraph:
w:firstLinein twips drifts whenever the font size changes, whilew:firstLineCharsstays correct at any size.Today this requires raw OOXML edits (
raw-set); this makes it a single paragraph Set key with the same ergonomics as the existingindent/lineSpacingprops.How to verify
Actual terminal output (before any preset — East Asia font falls back to docDefaults 等线):
After
typography.preset=zh-bodyon p[1] — eastAsia explicitly pinned to SimSun on the paragraph mark and the run, rhythm switched to atLeast/single/no-space-after:After
typography.preset=zh-first-indenton p[2] — char-relative 2-char first-line indent:Opening the resulting
demo.docxin Word shows the body paragraph in 宋体 with single spacing and the second paragraph indented exactly 2 characters.Implementation
src/officecli/Handlers/Word/WordHandler.Set.Element.cs— newcase "typography.preset"next toind.hanging. The presets are compound (they need both the paragraph's runs and the paragraph mark in hand), so they live at the Set.Element level rather thanApplyParagraphLevelProperty.src/officecli/Handlers/Word/WordHandler.Helpers.Style.cs—ApplyTypography_Body_Zhhelper: run-levelrFonts/@w:eastAsia="SimSun"(respecting CT_RPr child order), the same face on the paragraph-mark rPr,w:spacing= atLeast/240/after 0, plus a warning noting the font change so the set reports applied-with-notice.src/officecli/CommandBuilder.cs—"typography.preset"added toKnownPropsso suggestion/error paths recognize the key.No other behavior changes; nothing else touched.
Tests
Verified with a local test harness (kept repo-untracked, matching d8e7630's "local-only test project" policy):
eastAsia=SimSunon runs,lineRule=atLeast+spaceAfter=0,firstLineChars=200with a hardw:firstLinecleared — all green (CJK DOCX typography-preset tests passed.).XLSX numeric-fit issue tests passed.).dotnet build -c Release— 0 errors.dotnet publish -c Release— single-file exe smoke OK (runs, reports version).