Repository navigation
fix(docx): keep a canvas's blocks as far down as it places them - #1087
Merged
Merged
Conversation
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.
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.
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:
directly under it.
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.
MintEditorialwith a header band is both: a canvas pulled 48pt up to the page's top edge, itsname 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.canvasWritesnow also walks the blocks a canvas writes as Word sets them,each its space below the one before:
CanvasWrites.spaceAboveis each block'syless where Wordset the one before (the first's below the corner), never below zero;
spacedis how far down thatreaches;
downKeptsays 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,spaceItsBlocksAsPlacedregisters thatspace for each block, and
writeChildrenowes it before the block with whatever is carried downto it.
space above it. As far as that space goes, the pull now comes out of it (
pulled), and is addedto what is carried down so the canvas's negative edge cancels it. Carried as a negative edge, a
table first lost it —
newTableowes 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.
height - spaced(CanvasWrites.reach), notheight - stacked. The"runs past its height" note reads the same number.
its top edge there (
holdAParagraphsTopEdgeOnItsPage) holds the first block's space too, andthat 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 edgepulls 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.
canvasLossesfor a canvas whose blocks read down: it is no longer named as "written from itscorner". 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 itscorner (
!downKept), and a first block pulled up past its place and past the space owed abovethe canvas. The page-top note is a second note, given after the canvas is written
(
opensThePageWithSpaceAbove). A canvas whoseblocks 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 therender-docx README say what such a canvas now keeps and what it does not.
Verification
word2pdf.ps1) and LibreOffice 26.8 on Windows againstthe engine's PDF, by baseline: banded
MintEditorial2 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.
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.
canvas reads down from an offset or a pulled-up corner.
DocxCanvasRoomTestpins the gaps (with a block margin in the foot), the pulled-upcanvas 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 rowunder 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.
the one dropping the gaps also fails
MintEditorialBandedDocxTest. The source is restored bytefor 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.clean verifyas 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.