fix(style-engine): resolve bold and italic from the complex-script toggles - #3958
Open
Nathaniel-260 wants to merge 1 commit into
Open
fix(style-engine): resolve bold and italic from the complex-script toggles#3958Nathaniel-260 wants to merge 1 commit into
Nathaniel-260 wants to merge 1 commit into
Conversation
โฆggles Hebrew and Arabic Word writes bold-for-complex-script as `w:bCs` alone whenever the styled selection is single-script, without `w:b`. Word renders such a run bold; SuperDoc read only `w:b`, so a document whose headings are bold in Word painted them at normal weight. Measured in Chrome on a real Hebrew document, against the packaged dist with this change applied to the compiled bundle and nothing else: all ten headings went from `font-weight: 400` to `700`. The document's heading styles carry `<w:bCs/>` with no `<w:b/>`, and its runs carry `<w:rtl/>` โ the shape Hebrew Word produces. `normalizeRunAttrsFromOoxml` is the seam: it already receives the full `RunProperties` โ `boldCs`, `iCs`, `cs`, `rtl` โ and the layout contract downstream carries a single `bold`, so the stack has to be selected here. Per ECMA-376 Annex I, `w:rPr/w:rtl` (ยง17.3.2.30) and `w:rPr/w:cs` (ยง17.3.2.7) each select the complex-script variants of the toggles. This is the `RunScriptContext` stack-selection that `direction-context.ts` describes as Wave 1b. The Latin toggle stays a fallback rather than being ignored. Word decides the stack per character, not per run: a run carrying only `w:b` is bold there for whatever Latin text it holds, and existing documents do carry `w:b` alone on right-to-left runs. Reading `w:bCs` strictly would turn those normal โ a regression in the opposite direction, and a wider one. Per-character parity needs the run text next to the properties, which this layer does not receive. That is also the measured limit of this change: a run whose Hebrew is implied only by its text, with neither `w:rtl` nor `w:cs` set, still resolves through the Latin toggles. Out of scope, and deliberately: `w:szCs` and `w:rFonts/@cs` are the other two members of the same stack. Both change size and font resolution for every right-to-left run, which is a much larger behavioural change than the toggles and deserves its own measurement.
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more โ On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
This was referenced Sep 1, 2026
palmoni5
pushed a commit
to Y-PLONI/otzaria-word-editor
that referenced
this pull request
Sep 3, 2026
ืกืงืืจื ืืืืืจืกืจืืช ืืฆืื ืฉโืืื ืขื ืื ืฉืืชืื `w:rPrChange`โ ืื ืืชืงืืื: ืืืื ื ื ืฉืืจ ืืฉื ืืืืจ ืฉืืฉ ืื `>`, ืืงืืืืืช ืฉืืื ื `w`, ืืืกืืืจื ืชืืืฉื ืฉืืืจืืื ืืืชื ืืชืืช ืืืคืก ืืื ืืชืื ืืชืื ืืืืกืืืจืื ืืืื. ืืืจืืขื ืืืืื โ ืืื ื ืฉื ืชืงืข ืขื 1 ืืืื ืืช ืืชืืงืื ืืืืชื ืืืื ืืขื ืกืืฃ ืืืืง, ืืฉืงื. ืืืื ืืืื ืืื ื ืกืืคืจ ืชืืื: **`rPr` ืืชืื `rPr` ืืื ืืืกืืืจืื**. ื-`CT_RPr` ืืืืืจ ืืืืื ืฉืืืื `rPr` ืืื `w:rPrChange`, ืืืื ืืงืื ืื ืืื ืืืืืจื. ืฉืืืฉ ืืจืื ืืฉืืืจื ื ืขืืืืช ืืืชื. ืืืืชื ืกืจืืงื ืชืืงื ื ืขืื ืฉืืืฉื: ืืชืืื ืืชืื ืืขืจืช XML ืืืชืื CDATA (ืขืจืืื ืฉื ืืงืกื ืืืฉืชืืฉ, ืื ืฉื ืขืืฆืื), `w:val='0'` ืืืจืืืืช ืืืืืืช ืฉื ืงืจื ืโืืืืงโ ืืืคื โืื ืืืืืฉโ ืืคืืจืฉ ืืืืืืฉ, ืืงืืืืืช ืฉืืื ื `w` โ ืฉื ืืชืืงืื ืื ืืืืืฅ ืืืืจื ืืื ืืืกืืฃ `w:b` ืฉื ืืื ืืฆื `ns0:b` ืงืืืืช. ืืืื ืกื ื ืืชืืช ืขืืฉืื ืืงืืืืืช ืฉื ื-`bCs` ืฉื ืืฆืื. ืืืืกืชืืืืืืืช ืืกืงืืจืช ืืกืื-ืืืื-ืืืืจ: `crc32` ืขืืจ ื-slice-by-4 (384ms ื- 5.6MB ืืื ืืชืื ืืฉืื ืฉืื ืืคืฉืจ ืืงืืืข), ืืคืื ืืืจืื ื-`join` ืืื ื-`+=`, ืืืืฉืชืืฉ ืจืืื ืขืืฉืื ืืฉืืจืช ืืืฆื ืฉืืืกืื ืฉืื ืฉืื ื โ ืขื ืื ืื ืืื `console` ืืืื, ืขื ืฉืื ืื ืฉื ืืชื ืืงืืืฅ ืฉืื. 53 ืืืืงืืช ืืืืื (ื-33), ืฉืขืจ `bold-cs-qa` 7/7. ืืฉืขืจ ื ืืฆื ืืชืืงื ืื ืืื ืืืืื ืืฉืื: ืื ืืงืจื ื ืืืจ ืืืืกืื ืฉืขื ืืืกื, ืืืืืจ ืืืชืืฆืจ ืฉื ืงืืืื. `w:rPrChange` ื ืืื 2โ2: ืืื ืืข ืฉืืืจ ืืช ืืืกืืืจืืืช ืืขืืฆืื, ืืืชืืงืื ืืื ื ื ืืืข ืื. ืืืืื ืงืืื ืขื โืืื ืืข ืืืืง rPrChangeโ ืืื ืจืืงืก ืฉืืืจ ืืฉืขืจ, ืื ืคืขืจ ืืื ืืข. ืืชืืงืื ืืืงืืื ืืื ืืข ืขืฆืื: superdoc/docx-editor#3958, ืืืคื ืื superdoc/docx-editor#3959.
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.
The bug
Hebrew and Arabic Word writes bold-for-complex-script as
w:bCsalone whenever thestyled selection is single-script โ no
w:balongside it. Word renders such a runbold. SuperDoc reads only
w:b, so a document whose headings are bold in Word ispainted at normal weight.
This is the shape of a real reported document (a Hebrew Torah-study text). Its
heading 2โheading 5styles are:and its runs carry
<w:rtl/>.Reproduce
Any Hebrew
.docxwhose headings were bolded in Word will do; the smallest recipe:selection is Hebrew only. Word writes
<w:bCs/>into the style with no<w:b/>.Word shows the heading bold; SuperDoc shows it at normal weight.
Measurement
Chrome, packaged dist,
getComputedStyleon the run element inside.superdoc-line:font-weight<w:b/>completed next to each<w:bCs/>The change
normalizeRunAttrsFromOoxmlis the seam. It already receives the fullRunPropertiesโboldCs,iCs,cs,rtlโ and everything downstream carries asingle
bold, so the formatting stack has to be selected here.Per ECMA-376 Annex I,
w:rPr/w:rtl(ยง17.3.2.30) andw:rPr/w:cs(ยง17.3.2.7) eachselect the complex-script variants of the character-formatting toggles. That is the
stack selection
contracts/src/direction-context.tsalready describes:resolveRunScriptContextdoes not exist yet; this covers the two toggles.Why the Latin toggle stays a fallback
Word decides the stack per character, not per run. A run carrying only
w:bis boldthere for whatever Latin text it holds, and plenty of existing documents carry
w:balone on right-to-left runs โ SuperDoc's own
format.applywrites them that way.Reading
w:bCsstrictly would turn those runs normal: a regression in the oppositedirection, and a wider one. Per-character parity needs the run text next to the
properties, which this layer does not receive.
Known limit
A run whose Hebrew is implied only by its text, with neither
w:rtlnorw:csset,still resolves through the Latin toggles. Measured: such a run stays at 400 with this
patch. Word picks the stack from the Unicode script of the text in that case, which
needs information this layer does not have.
Out of scope, deliberately
w:szCsandw:rFonts/@csare the other two members of the same stack. Both changesize and font resolution for every right-to-left run โ a much larger behavioural
change than the toggles, and one that deserves its own measurement.
Tests
Four cases added to
normalize.test.ts: the CS toggles on aw:rtlrun and on aw:csrun, the Latin toggles kept when no complex-script signal is present, and thefallback on a complex-script run with no CS variant.
What I ran locally (Windows, Node 22, Bun 1.3.13):
bun testinstyle-engineโ 182 passbun testinlayout-engine(964),word-layout(172),common(121),geometry-utils(7) โ all passvp fmt --checkon both changed files โ cleanNot run: the full
pnpm test.pnpmwill not start in my checkout, andbun testindocument-apipanics withinteger overflowโ it does the same on anunmodified tree here, so it is environmental and unrelated to this change.
Fixes #3959.