Skip to content

fix(docx): keep a canvas's blocks as far down as it places them - #1087

Merged
DemchaAV merged 6 commits into
developfrom
fix/docx-canvas-flow
Nov 25, 2026
Merged

DemchaAV merged 6 commits into
developfrom
fix/docx-canvas-flow

Conversation

@DemchaAV

@DemchaAV DemchaAV commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Why

#1086 left a canvas whose blocks read down - a CV's name over its title - in the body's flow,
where a reader of the flow reaches its text, and wrote it as its contents: one block under
another from its corner, with the room its height leaves below that stack owed after it.

That loses two things the page has:

  • The distance between blocks. A block placed lower than the foot of the one before stood
    directly under it.
  • Where the canvas starts. A canvas pulled up by a negative top margin has its corner above
    the page's margin, where Word cannot start a paragraph. Word sets the first block at the margin,
    and the room owed under the last, measured from the corner, came out the margin's depth too large.

MintEditorial with a header band is both: a canvas pulled 48pt up to the page's top edge, its
name 48pt down it and its title 3pt under the name. Measured by baseline against the engine's PDF,
the title stood 2.9pt high in Word 16 and 3.3pt high in LibreOffice 26.8, the band's rule 3pt high,
and the masthead owed 48pt more room under it than the page holds. The row under it no longer
fitted the first page: the CV took three pages in both editors where the engine takes two, and the
paired cover letter's lines stood 48pt low.

What changed

  • DocxSemanticBackend.canvasWrites now also walks the blocks a canvas writes as Word sets them,
    each its space below the one before: CanvasWrites.spaceAbove is each block's y less where Word
    set the one before (the first's below the corner), never below zero; spaced is how far down that
    reaches; downKept says whether no block was placed higher than Word can set it.
  • writeCanvas: for a canvas written as its contents whose blocks read down
    (CanvasWrites.readsDown) and whose layout is measured, spaceItsBlocksAsPlaced registers that
    space for each block, and writeChildren owes it before the block with whatever is carried down
    to it.
  • A negative top edge (margin plus padding) pulls the canvas up, and its first block down by the
    space above it. As far as that space goes, the pull now comes out of it (pulled), and is added
    to what is carried down so the canvas's negative edge cancels it. Carried as a negative edge, a
    table first lost it — newTable owes no space below zero, and Word has no space above a table —
    and stood that far low. In the Mint masthead the pull and the name's 48pt cancel, and the name
    stands at the page's margin. A pull deeper than that space is still carried, and named where it
    is lost: a paragraph takes it out of the space owed above the canvas as far as that goes, and
    anything else drops it.
  • The room owed under it is height - spaced (CanvasWrites.reach), not height - stacked. The
    "runs past its height" note reads the same number.
  • On a page the canvas opens, Word drops a paragraph's space above, so the line that already holds
    its top edge there (holdAParagraphsTopEdgeOnItsPage) holds the first block's space too, and
    that share comes out of the first block's space and out of the edge the line holds
    (topEdgeHeld): the block owes none of it again, a table first included. Where a negative edge
    pulls the canvas past the page's margin, that line would hold nothing above the margin, and is
    not written: the space left above the first block, the canvas's padding included, is written
    above that block. A table, a row or a panel first holds it in a line of its own; where a
    paragraph opens the page with it, Word drops it, and the report says so. Whether it does is read
    back from what the canvas wrote first, not guessed from the first block's type.
  • canvasLosses for a canvas whose blocks read down: it is no longer named as "written from its
    corner". It is named for what it still loses: a block placed elsewhere than at its left edge
    (CanvasWrites.placedAcross), a block placed higher than the foot of the one before or than its
    corner (!downKept), and a first block pulled up past its place and past the space owed above
    the canvas. The page-top note is a second note, given after the canvas is written
    (opensThePageWithSpaceAbove). A canvas whose
    blocks do not read down keeps the old note and the old stacking.

No public API change. CHANGELOG, docs/recipes/docx-export.md, the capability details and the
render-docx README say what such a canvas now keeps and what it does not.

Verification

  • Re-measured before the fix, Word 16 (word2pdf.ps1) and LibreOffice 26.8 on Windows against
    the engine's PDF, by baseline: banded MintEditorial 2 pages in the engine, 3 in both editors,
    101 of 102 lines off by more than 2pt in Word; banded cover letter 9 of 10 lines 48pt low.
  • After: the banded CV is 2 pages in both editors, its 102 lines within 0.24pt in Word and 1.3pt
    in LibreOffice - the numbers the CV without a band measures, line for line - and the rule at
    123.8pt where the engine draws it. The banded letter's lines are within 0.18pt and 1.3pt. The
    final code writes both documents byte for byte as the build measured.
  • Corpus: 105 documents byte-identical, report notes 1718 -> 1718, on the final code. No corpus
    canvas reads down from an offset or a pulled-up corner.
  • Tests: DocxCanvasRoomTest pins the gaps (with a block margin in the foot), the pulled-up
    canvas at the page's top and under a paragraph, a table first under a pulled-up canvas, a table
    and a paragraph first under a pull deeper than their space, and one the space owed above covers, a first block placed above the corner, a canvas the layout moves
    to a new page — a paragraph first with and without a pull, a table first with and without a
    pull, a row and a section first with a pull, a pulled-up canvas with padding — a reading-down canvas in a row's cell, and a canvas that does not read down still
    stacking from its corner. MintEditorialBandedDocxTest (qa) pins Word's distance from the margin to the row
    under the banded masthead against the layout's. Of four tests that pinned the old note for
    canvases that read down, three now pin the narrower one and one, whose caption sits at the left
    edge, pins no note.
  • Sabotages: 18 of 18 caught, each by the test written for its rule (1 test run, 1 failure each);
    the one dropping the gaps also fails MintEditorialBandedDocxTest. The source is restored byte
    for byte.
  • ./mvnw -B -ntp test -pl :graph-compose-render-docx -am: core 845, render-pdf 347, render-docx 2821 tests, 0 failures.
  • ./mvnw -B -ntp test -f qa/pom.xml: 1927 tests, 0 failures.
  • Full local gate (reactor clean verify as CI runs it, the JDK 17 knowledge checks, core javadoc run fresh,
    install and the examples tests): passed.

Lane: shared-engine (render-docx writer only); no layout or public API change.

A canvas written as its contents wrote what it holds one block under
another from its corner, and owed under the last the room its height
left below that stack. A canvas whose blocks read down but are set apart
lost the distances between them, and one pulled up by a negative top
margin owed that margin's depth too much room below: Word starts its
first block at the page's margin, not at the corner above it.
MintEditorial with a header band - a canvas pulled 48pt up to the page's
top edge, its name 48pt down it and its title 3pt under the name - set
its title 2.9pt high in Word 16 and 3.3pt in LibreOffice 26.8, and owed
48pt more room under the masthead than the page holds; the row under it
no longer fitted the first page, and the CV took three pages where the
page takes two.

A canvas whose blocks read down now owes above each block the distance
it places it below where Word set the one before, the first below its
corner, and owes under the last the room it leaves below where Word set
it. On a page the canvas opens, where Word drops a paragraph's space
above, the line holding its top edge holds its first block's space too.
How far across it places them is still not carried; the report names a
canvas that places a block elsewhere than at its left edge, or higher
than Word can set it, instead of naming every one set apart.

A canvas whose blocks do not read down, written as its contents, still
stacks them from its corner as before.
A canvas whose blocks read down owes above its first block the space it
places it below its corner, and its negative top margin was carried down
as a negative edge beside it. A paragraph first sums the two, but a
table first owes no space below zero, so the edge was dropped while the
space was still owed: under a canvas pulled up 20pt, a table placed at
the page's margin stood 20pt low, and the report named nothing. The pull
now comes out of the first block's space, and nothing below zero is
carried down.

Where such a canvas opens a later page, the line holding its top edge
holds nothing above the page's margin, so the space left above its first
block stands at the page's top, where Word drops it. The report names
that, and names a block placed higher than the foot of the one before or
than the corner, instead of calling the whole canvas written from its
corner.
On a page a canvas opens, the line holding its top edge holds the space
above its first block too, and the edge it held was carried back as a
negative edge while that space was still owed. A paragraph first summed
the two to nothing, but a table first drops a negative edge, so under a
canvas the layout moved to a new page a table placed 20pt down it got
the 20pt twice: once in the line and once below it. The line's share
now comes out of the first block's space and out of the edge the line
holds, so nothing is owed twice and nothing below zero is carried.

The report says where the page-top space is dropped only once the line
is written, and only where a paragraph opens the page: a table first
holds the space above it in a line of its own there. It also names a
first block other than a paragraph that a negative top margin pulls up
further than the space placed above it, which Word sets that much
lower, and a block placed above the foot before it or the corner is
named as written at that foot or corner.
The notes for a canvas whose blocks read down decided by the first
block's type. A negative top margin pulling the first block further up
than the space placed above it was named only for a block other than a
paragraph, but a paragraph takes that pull out of the space owed above
it only as far as that goes, and stood the rest lower unnamed. And the
space dropped at the top of a page a pulled-up canvas opens was named
only for a paragraph first, though a section or any other block whose
first line opens the page loses it there too.

The pull past the first space is now named whatever the first block is,
as setting it up to that much lower, and the page-top note is given for
any first block but a table, which holds the space above it in a line of
its own.
Where a canvas pulled up past the page's margin opens a later page, the
space above its first block was named as dropped at the page's top by
the first block's type, which is not what decides it: a row or a panel
first holds that space in a line of its own, as a table does, and was
named for a loss Word does not have. The note is now given after the
canvas is written, where the first thing it wrote on the page is a
paragraph opening it with space above, not a held line or a table.

Such a canvas no longer writes the line holding its top edge there,
which held only its padding, nothing above the margin: with padding its
first block stood that padding's depth from where the page sets it. The
space left above the first block, the padding included, is written above
that block, where a table or a row holds it and a paragraph's is named.

A pull past the first block's space is named for a paragraph first only
past the space owed above the canvas, which the paragraph takes it from.
…graph only

The space owed above a canvas covers the pull of its negative top margin past its first block's space only where that block is a paragraph, which takes the pull out of that space; a table first drops it whatever is owed. The CHANGELOG, the recipe and the capability details now say so.
@DemchaAV
DemchaAV marked this pull request as ready for review November 25, 2026 18:23
@DemchaAV
DemchaAV merged commit 6603bcf into develop Nov 25, 2026
13 checks passed
@DemchaAV
DemchaAV deleted the fix/docx-canvas-flow branch November 25, 2026 22:28
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