Skip to content

fix(layout-engine): honor tblpPr anchor frames for floating tables (SD-2562)#2877

Open
caio-pizzol wants to merge 1 commit intomainfrom
caio/sd-2562-feature-render-table-placements-to-account-for
Open

fix(layout-engine): honor tblpPr anchor frames for floating tables (SD-2562)#2877
caio-pizzol wants to merge 1 commit intomainfrom
caio/sd-2562-feature-render-table-placements-to-account-for

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

Floating tables with `w:tblpPr` now honor `horzAnchor`/`vertAnchor` when SuperDoc resolves their position. Previously every anchor was treated as paragraph-relative, so `vertAnchor="page"` tables rendered near the anchor paragraph instead of at the page-relative position Word shows.

  • Extract the X/Y math into `computeTableAnchorX` and a new `computeTableAnchorY` in `floating-objects.ts`; call both from the paragraph-anchored and paragraphless placement paths.
  • Drop the single-column special case in `computeTableAnchorX` — page-anchored `tblpX` now measures from page edge 0 regardless of column count (fixes GH#2800 reporter XML).
  • Stop double-counting `offsetV` in `registerTable` — `computeTableAnchorY` already applies it when resolving exclusion zone Y.
  • Clarify JSDoc: `alignV` picks the reference edge/center, `offsetV` is additive from there (matches Word's actual behavior).

Validated against Microsoft Word's COM-reported positions for 13 `tblpPr` fixtures covering every `horzAnchor × vertAnchor × tblpX/tblpXSpec × tblpY/tblpYSpec` combination. The SD-2562 core case (`vertAnchor="page" tblpY=2880`) now renders at `(288, 192)`, matching Word exactly; previously rendered at `(288, 380)`.

Rejected: symptom-fix that special-cased `vertAnchor="page"` only (would leave horizontal axis, `margin` anchors, and tblpXSpec still broken — they share the same 30-line code block).
Must stay the same: paragraph-anchored legacy clamp (`Math.max(paragraphStartY, cursorY)`) preserved to avoid overlapping already-laid paragraph content on multi-page spans. Strict OOXML paragraph behavior (allow overlap) is follow-up work.
Review: correctness of the new `computeTableAnchorY` helper and whether the fragment rendering X math changed under any existing integration-test fixture.
Verified: `pnpm --filter @superdoc/layout-engine test` → 626 pass (+11 new). Dev-app verification on 13 fixtures matches Word ground truth.

…D-2562)

Resolve floating-table placement through vRelativeFrom/hRelativeFrom/alignH/alignV
instead of treating every anchor as paragraph-relative. Extract position math into
computeTableAnchorX and a new computeTableAnchorY in floating-objects.ts and call them
from both the paragraph-anchored and paragraphless code paths.

Also:
- Drop the single-column special case in computeTableAnchorX so page-anchored tblpX
  measures from page edge 0 regardless of column count (fixes GH#2800 reporter XML).
- Stop double-counting offsetV in registerTable — computeTableAnchorY already applies it.
- Clarify JSDoc: alignV picks the reference edge/center, offsetV is additive from there
  (matches Word's actual behavior).

Validated against Microsoft Word's COM-reported positions for 13 tblpPr fixtures
covering all horzAnchor x vertAnchor x tblpX/tblpXSpec x tblpY/tblpYSpec combinations.
All 626 unit tests pass (+11 new).
@linear
Copy link
Copy Markdown

linear bot commented Apr 20, 2026

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56afb81669

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/layout-engine/layout-engine/src/index.ts
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

Floating tables (w:tblpPr) render in document flow order, ignoring absolute position

2 participants