Skip to content

fix(rendering): apply superscript/subscript font-size scaling during layout#2340

Open
gpardhivvarma wants to merge 3 commits intosuperdoc-dev:mainfrom
gpardhivvarma:fix/superscript-subscript-font-size
Open

fix(rendering): apply superscript/subscript font-size scaling during layout#2340
gpardhivvarma wants to merge 3 commits intosuperdoc-dev:mainfrom
gpardhivvarma:fix/superscript-subscript-font-size

Conversation

@gpardhivvarma
Copy link
Contributor

Summary

  • Root cause: The 65% font-size reduction for superscript/subscript was applied as a post-processing DOM patch in PresentationEditor.#applyVertAlignToLayout(), but text was measured and laid out at full font size — causing oversized appearance
  • Added vertAlign and baselineShift to the TextRun contract (RunMarks) so the layout engine sees them
  • computeRunAttrs() and applyTextStyleMark() now extract vertAlign/position and apply the 0.65× font-size scale at conversion time, before measurement
  • DOM painter's applyRunStyles() renders vertical-align: super/sub/baseline or custom vertical-align: Xpt directly
  • Removed the ~100-line #applyVertAlignToLayout() post-processing patch from PresentationEditor

Test plan

  • Open a DOCX with superscript text (e.g. "1st", "2nd", ordinals) — verify characters render at correct reduced size
  • Open a DOCX with subscript text (e.g. chemical formulas like H₂O) — verify correct sizing and positioning
  • Open a DOCX with custom baseline position offsets — verify text shifts correctly
  • Verify no layout regressions with pnpm test:layout
  • Run pnpm test — all unit tests pass (verified: 2,240 tests across pm-adapter + painter-dom)

…layout

The 65% font-size reduction for superscript/subscript was applied as a
post-processing DOM patch, but text was measured at full size — causing
oversized rendering. Move vertAlign and baselineShift into the TextRun
contract so the layout engine measures at the correct scaled size, and
the DOM painter applies vertical-align CSS directly.
Copy link
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gpardhivvarma solid approach — moving this into the rendering pipeline is the right call.

two things to fix in files not touched by the diff:

  1. renderer.ts:6464deriveBlockVersion() doesn't include vertAlign or baselineShift in the hash. switching between superscript and subscript won't visually update because both use the same scaled font size, so the hash stays identical and the DOM is reused.

  2. tracked-changes.ts:325resetRunFormatting() doesn't clear vertAlign or baselineShift. if someone adds superscript in a tracked change, "original" mode will still show it as superscript instead of the old formatting.

no tests added — would be good to cover the new scaling and CSS output in computeRunAttrs, applyTextStyleMark, and applyRunStyles.

left one inline comment.

- Extract 0.65 to SUBSCRIPT_SUPERSCRIPT_SCALE constant in constants.ts
- Add vertAlign/baselineShift to deriveBlockVersion() hash for both
  paragraph and table runs so changes trigger DOM updates
- Clear vertAlign/baselineShift in resetRunFormatting() for tracked
  changes original mode
- Add tests for computeRunAttrs, applyTextStyleMark, and DOM painter
  vertical-align CSS rendering
@gpardhivvarma
Copy link
Contributor Author

@caio-pizzol please review this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants