Skip to content

fix(docx): set a canvas's side-by-side text where the page sets it - #1086

Merged
DemchaAV merged 5 commits into
developfrom
fix/docx-canvas-text-positions
Nov 25, 2026
Merged

DemchaAV merged 5 commits into
developfrom
fix/docx-canvas-text-positions

Conversation

@DemchaAV

@DemchaAV DemchaAV commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Why

A canvas (addCanvas, CanvasLayerNode) was written to DOCX as its contents: its drawings stood where it placed them, and its text one block under another from its corner. A canvas that places its text side by side or out of reading order — a poster, a slide — came out with all of it stacked at its left edge.

Measured by baseline against the engine's PDF, in Word 16 and LibreOffice 26.8:

  • TwinOutputExample (one 960×540pt page that is one canvas): Word set every one of its 43 lines, and LibreOffice every one it set, as much as 820pt across and 222pt down from the page.
  • MavenBannerPptxExample: the first page is a canvas; its caption went to page 2, and the four flow pages after it each came one page later — 6 pages in both editors where the page has 5.

What changed

DocxSemanticBackend.writeCanvas now writes such a canvas over its page (writeCanvasOverItsPage) — the path a block laid over the flow already takes (laidOverTheFlow / writeTextOverTheFlow, LumaStudioInvoice's sidebar): its drawings stand where the page draws them, each paragraph in a text box where the page sets it, anchored in a paragraph on its page.

Its room in the flow:

  • opening a page the layout moves it to, or one a page break starts — an empty line of exact height holding the space above it there, its box and its bottom margin (holdItsRoomInALine), whether or not anything follows it. Word and LibreOffice drop a paragraph's space above at the top of a page: owed as that space, the paragraph under a canvas moved to a new page stood 139.8pt high in both, and after a page break 119.8pt; held in the line, within 0.3pt. The bottom margin is in the line because, owed below it, the line fitted at the foot of the page above where the canvas did not;
  • alone on its page (aloneOnItsPage: the layout puts nothing else there) — the same line, which is then what carries its text boxes on that page. Owed as space, a cover filling the first page before a paragraph on the second, and the first of two pages that are each a canvas, had nothing written on their page and their text was dropped. Carried by a page break's paragraph or the closing one instead, both at the page's top, a box placed from the page's edge whose top fell within that paragraph's line was set on its baseline by Word — 7pt high — and not by LibreOffice;
  • a page break right after the line goes in the line (writePageBreak): its own paragraph, under a line filling its page, stood on the next page and broke it again — three canvas pages split by breaks came out as four in both editors. Where the next page is set against other margins (pageMargins), DocxPageMarginSections ends the section with that line and now takes its page break out, as it takes out a break's own paragraph's — kept, it would open a blank page before the section's own break — and the line keeps its height;
  • followed on a page it shares — owed as space to the next block (holdTheSpaceOf), as for a canvas that only draws;
  • nothing following on a page it shares — nothing is written; the paragraphs above it, the closing paragraph or a page break's stand on its page, and the canvas is recorded for hangBelowTheFlow, so a closing paragraph after a table stands below what it draws.

A line in the middle of a page is not written: it sets the paragraph under it 0.3pt low in both editors (its first line is raised into the space above it, which a line leaves none of).

It applies only where that path can carry the canvas (writesOverItsPage) and where the flow cannot:

  • the canvas places its text side by side or out of reading order: a block it writes starts above the foot of the one before it (CanvasWrites.readsDown, new). A canvas whose blocks read down one under another stays in the flow, where a reader of the flow reaches its text — MintEditorial's masthead with a header band (name over title) is that, and is written as before;
  • it stands in the body's flow — not in a table cell, a painted panel, a band, a stack of one layer or another overlay — on one page;
  • everything it holds is drawing or a plain paragraph (floatable): a link, a bookmark, an anchor, a picture, a table, a list or any other block keeps it written as its contents, named as before.

Report: the canvas is named written over its page: …, and each paragraph placed by its canvas where one block under another would not stand: set in a text box where the page sets it, anchored … — the over-the-flow lead (laid over the flow, which gives it no room) is not true of a canvas, which holds its room.

No public API changes.

Measured after

Document Word 16 LibreOffice 26.8
TwinOutputExample 41 lines within 0.6pt 41 lines within 0.4pt
MavenBannerPptxExample page 1 24 lines within 0.5pt, 5 pages 24 lines within 0.7pt, 5 pages
CanvasLayerExample 12 lines within 0.3pt 12 lines within 0.3pt
probes: a canvas moved to a new page, after a page break, last in the flow, a cover before a paragraph and before a page break, two page-sized canvases, three split by page breaks every line within 0.7pt, page counts as the engine's the same

Two paragraphs break otherwise, by the text-box path's existing width rule (a box of several lines is its width plus the editor's 2pt): TwinOutputExample's Lead, set at 12.3pt and written at 12.5pt — a Word file holds a size to the half point — breaks a word sooner in both editors, and CanvasLayerExample's centred citation, whose first line the engine broke within a point of its 443pt width, takes one more word in both. MintEditorial with a header band writes the same bytes as before.

LibreOffice here is the Windows 26.8 build, not CI's 24.2. CI's DOCX Fidelity (LibreOffice) job runs the corpus on 24.2; the corpus has no canvas that places its text side by side, so it does not reach this path.

Tests

  • DocxCanvasOverItsPageTest (new, 16): paragraphs set in text boxes at the canvas's places (page-relative x, offsets between boxes), none in the flow, boxes in front of the text; the canvas and paragraph notes; a canvas stacking from its corner, and one whose blocks read down, stay in the flow; a link or a picture keeps it as its contents; as a shape container's layer, in a stack of one layer, in a painted panel and in a table cell it is written as its contents; the room line where it opens a page the layout moves it to and after a page break; no room held before a page break; a cover and two page-sized canvases carried on their own pages with nothing dropped; a page break after a canvas alone on its page written in its line; last after a table, the closing paragraph set below what it draws.
  • DocxPageMarginSectionsTest.aPageBreakInTheLineBeforeOtherMarginsBecomesTheSectionsBreakAndTheLineKeepsItsHeight: no page break left, the section ends with the line, which keeps its height and carries the text boxes.
  • DocxCanvasRoomTest.aCanvasWrittenOverItsPageHoldsItsWholeRoom: the flow after it stands its margins and height below, as on the page.
  • Sabotages, each caught by the test written for it; the source restored byte-identical.
  • Corpus (105 documents): byte-identical DOCX, notes unchanged.

A canvas was written to DOCX as its contents: its drawings where it
placed them, its text one block under another from its corner. A canvas
that places its text side by side or out of reading order came out with
all of it stacked at its left edge - TwinOutputExample's 43 lines as much
as 820pt off in Word 16 and LibreOffice, the Maven banner's caption on
the next page and the four pages after it one page later.

Such a canvas in the body's flow, holding only drawing and plain
paragraphs, is now written over its page, as a block laid over the flow
is: its drawings where the page draws them, each paragraph in a text box
where the page sets it. The flow holds the canvas's room where something
follows it, in an exact-height line where the canvas opens a page, whose
top Word and LibreOffice drop a paragraph's space above at.

A canvas whose blocks read down one under another - a CV's name over its
title - stays in the flow, where a reader of the flow reaches its text;
so does one anywhere else, or holding a link, a picture, a table or any
other block. Each is named as before.
A canvas written over its page owed its room as space to the next block,
so a canvas alone on its page - a cover before a paragraph on the next
page, the first of two pages that are each a canvas - wrote nothing on
that page, and its text boxes, carried by a paragraph on their page, were
dropped. Such a canvas now holds its room in the exact-height line it
already writes where it opens a page, and the line carries them there.

A canvas last in the flow is recorded as written over it, so a closing
paragraph after a table stands below what it draws.

The canvas report test keeps its single caption without a link: one
block always reads down, so the link was never what kept it in the flow.
A canvas alone on its page and not followed there - a cover or a slide
before a page break, a deck's last page - wrote no room line, so its
text boxes were carried by the page break's paragraph or the closing
one, set at the page's top. Word set a box placed from the page's edge
whose top fell within that paragraph's line on the line's baseline, 7pt
high; LibreOffice did not. It now writes its line whether or not
anything follows it, and the line carries them.

A page break right after that line goes in the line: its own paragraph,
under a line filling its page, stood on the next page and broke it
again - three canvas pages split by breaks came out as four in Word and
LibreOffice.
…tion

A page set against other margins than the page before starts a Word
section, ended by the paragraph before it. A page break written in that
paragraph - the one after a canvas alone on its page now goes in the
line holding its room - stayed in front of the section's own break and
would open a blank page. It is taken out, as a page break's own
paragraph's is; the paragraph keeps its height and what it carries.

The canvas's report note now says its room is in the flow where the flow
holds it: nothing is written for a canvas nothing follows on a page it
shares.
@DemchaAV
DemchaAV marked this pull request as ready for review November 25, 2026 15:00
@DemchaAV
DemchaAV merged commit 4053907 into develop Nov 25, 2026
13 checks passed
@DemchaAV
DemchaAV deleted the fix/docx-canvas-text-positions branch November 25, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant