Commit ef9821e
authored
fix(converter): preserve theme rFonts on DOCX round-trip (SD-2894) (#3225)
* fix(converter): preserve theme rFonts on DOCX round-trip (SD-2894)
The cascade's font-slot dedup only handled the ascii/asciiTheme pair, so a
higher-priority style with hAnsiTheme/eastAsiaTheme/cstheme would still leave
the lower-priority concrete name in place. Word reads the concrete value as
an override that defeats per-script theme resolution — Latin body text mapped
to majorBidi rendered as Calibri Light instead of the per-script font
(Times New Roman for Hebrew/Arab).
Extend the dedup to all four <w:rFonts> slots, and add the same logic to
calculateInlineRunPropertiesPlugin so theme refs from the imported run survive
the mark-driven recompute that runs on initial load.
Verified with a round-trip integration test on the customer fixture: asciiTheme
count 65 → 65 (was dropping to ~25 before the fix), no concrete font
substitutions on runs that originally carried theme references.
* fix(super-editor): respect explicit font changes on themed runs (SD-2894 review)
Addresses Luccas's PR review feedback on #3225.
P1: when text imported with w:*Theme rFonts is later given a concrete font by
the user, mergeFontFamilyPreservingThemeRefs unconditionally restored the old
theme reference and dropped the user's choice. setFontFamily('Arial') on themed
text appeared to do nothing on export.
Fix: gate the merge on whether the mark-derived value still encodes to the same
OOXML mark as the run's existing fontFamily. If they match, the marks are a
faithful re-derivation of the import and we preserve the theme. If they differ,
the user has overridden — drop the theme and keep the new concrete value.
DRY: FONT_FAMILY_THEME_PAIRS in the plugin duplicated FONT_SLOT_THEME_PAIRS in
style-engine cascade.ts. Export the cascade constant through
@superdoc/style-engine/ooxml and consume it from the plugin so the four-slot
mapping has a single source of truth.
Tests: two new AAA cases in calculateInlineRunPropertiesPlugin.test.js lock
both directions of the contract — preserve theme when marks re-encode the
import, drop theme on user override.
* fix(super-editor): narrow user-override gate to primary fontFamily slot (SD-2894)
The previous gate (f046df9) compared the full encoded textStyle attrs between
markFromMarks and markFromExisting. That over-fired on imported runs whose
existing.fontFamily mixed theme refs with a concrete per-script slot
(e.g. { asciiTheme, hAnsiTheme, cstheme, eastAsia: 'Arial' }): the mark
re-decode produces a full concrete shape including a `cs:` slot, which the
encoder turns into `csFontFamily` on markFromMarks but not on markFromExisting,
so JSON.stringify(attrs) mismatched and the theme was dropped.
Browser round-trip of the SD-2894 customer fixture: 65/65/65 -> 62/62/62
theme attrs, with 3 `w:ascii="Calibri Light"` substitutions. Regression of the
original PR.
Fix: compare only `markFromMarks.attrs.fontFamily` against
`markFromExisting.attrs.fontFamily`. That is the primary user-override signal;
per-script extras don't indicate user intent (the toolbar sets all four slots
to the same family). Confirmed in browser:
- customer fixture round-trip: 65/65/65, zero CL substitutions
- Luccas user-override repro: setFontFamily('Arial') -> exported
<w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:eastAsia="Arial" w:cs="Arial"/>
Adds a third regression test pinning the mixed theme+concrete-per-script case
that the suite previously missed (because the integration test uses
isHeadless: true which bypasses the plugin entirely).
* test(super-editor): mutation matrix for SD-2894 theme rFonts round-trip
13 parametrized scenarios pin every shape of existing.fontFamily x mark-decoded
shape that the plugin must handle on round-trip:
Group A — theme preservation when marks re-encode the imported value:
A1: all 4 theme slots
A2: 3 theme slots (ascii/hAnsi/cs) — SD-2894 customer fixture shape
A3: 3 themes + concrete eastAsia — the regression case the gate now handles
A4: ascii-only theme
A5: hAnsi-only theme
A6: cs-only theme (lowercase `cstheme` OOXML quirk)
A7: eastAsia-only theme
Group B — user override drops theme refs:
B1: all 4 themes + Arial
B2: customer shape + Arial (Luccas's case)
B3: mixed theme+concrete + Arial
Group C — no-theme baselines:
C1: pure concrete unchanged
C2: pure concrete + different concrete
C3: empty existing
The universal encoder mock mirrors resolveDocxFontFamily's behaviour: any
theme ref wins for the primary slot, falling back to concrete ascii/hAnsi/etc.
Per-script extras (eastAsiaFontFamily/csFontFamily) attach only when concrete
slot value differs from primary fontFamily — same emission rule as the real
encoder in super-converter/styles.js.
These scenarios are the basis for catching any future drift in the gate
logic or merge helper — both the import-preservation path and the
user-override path are locked at every shape we ship.
* test(style-engine): pin 4-slot theme/concrete dedup; document plugin limitation
Addresses two codex review findings on PR #3225:
(1) Cascade test coverage: the original SD-2894 bug was that combineRunProperties'
slot dedup only handled (ascii, asciiTheme) correctly; hAnsi/eastAsia/cs leaked.
Existing cascade tests didn't directly exercise the four-slot behaviour. Adds:
- one test per slot for the "theme drops concrete" direction
- one test per slot for the "concrete drops theme" direction
- an Athenaintelligence-customer-shape test
- an export assertion pinning FONT_SLOT_THEME_PAIRS so it stays in sync with
the super-editor plugin that re-imports it
These prevent any single-slot regression of the original SD-2894 fix.
(2) Per-script gate limitation: the plugin's gate + merge pair operate at the
fontFamily-key level, not per-slot. A user action that mutates only
eastAsiaFontFamily or csFontFamily without changing the primary fontFamily
will pass the gate. Documented as an AIDEV-NOTE on mergeFontFamilyPreservingThemeRefs.
We accept the trade-off because (a) the toolbar's setFontFamily always changes
the primary, (b) no current API or paste path produces this shape against a
themed import, (c) the prior attempt at increased precision (f046df9) regressed
the customer fixture (3 of 65 runs); narrowing to per-slot would re-open that
risk without a concrete reproduction. If a real customer scenario surfaces,
file a follow-up with the fixture and rework into per-slot decisions then.1 parent 1515843 commit ef9821e
7 files changed
Lines changed: 740 additions & 13 deletions
File tree
- packages
- layout-engine/style-engine/src
- ooxml
- super-editor/src/editors/v1
- extensions/run
- tests
- data
- import-export
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
155 | 258 | | |
156 | 259 | | |
157 | 260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
107 | 142 | | |
108 | 143 | | |
109 | 144 | | |
110 | 145 | | |
111 | 146 | | |
112 | 147 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
121 | 152 | | |
122 | 153 | | |
123 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
| |||
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
21 | | - | |
| 26 | + | |
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
| |||
Lines changed: 96 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
31 | 111 | | |
32 | 112 | | |
33 | 113 | | |
| |||
536 | 616 | | |
537 | 617 | | |
538 | 618 | | |
539 | | - | |
540 | | - | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
541 | 622 | | |
542 | | - | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
543 | 636 | | |
544 | 637 | | |
545 | 638 | | |
| |||
0 commit comments