Repository navigation
fix(layout): move rowSpan groups only where all pages have the same margin - #1117
Merged
Merged
Conversation
…argin Since #1105 a table moves a group of rows held together by rowSpan cells to the next page instead of cutting inside it, if the group fits an empty page of the current page's size. With per-page margins the next page can be shorter. A 184.35pt group that 2.5.3 cut on page 1 moved to a 100pt page 2 and threw AtomicNodeTooLargeException. A group that moved to a page that could hold it could also send a later row to a page that could not hold that row. - Where page margins differ, splitTable cuts after the last row that fits, as in 2.5.3. A spanning cell can again run past the bottom margin, and the next page can again open with the rest of the rows it covers. A DOCX export starts no Word section there. Where every page has the same margin, the rule from #1105 does not change. - PageGeometry.hasUniformMargin (package-private) compares the margins the pages end up with, so a rule that changes nothing does not count. A rule with another margin for a page the document never reaches does. Negative zero equals zero. - prepareTable reads the answer once and keeps it in the prepared table, and every head and tail keeps it too. SplitRequest and the height tableFirstSliceHeight returns do not change. No public API change.
The height that box moves and keepWithNext count for a table that opens with a rowSpan group is the whole group, but the split can cut inside it. So a box or heading can also stay on a page when the table moves to the next one. The comment on box moves and the Javadoc of tableFirstSliceHeight now say so. Only comments change.
The split moves a group only if it fits an empty page below the repeated header rows. The Javadoc of splitTable and tableFirstSliceHeight left the header rows out. The class comment of TableRowSpanPageMarginsTest said that every table with different page margins lays out as in 2.5.3, but only the cut is the same. Only comments change.
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
Since #1105 a table moves a group of rows held together by
rowSpancells to the next page instead of cutting inside it, when the group fits an empty page. It measures the group against the page it is on. With per-page margins the next page, or a later one, can be shorter, so some tables that 2.5.3 laid out now throwAtomicNodeTooLargeException. Both examples use 400×400 pages with 20pt margins and a 200pt spacer, so page 1 has 160pt left for a 184.35pt group (rows of 124.55pt and 59.80pt):developmoves the group to page 2 and throws, 184.35 on 100.developmoves the group to page 2, so the later row goes to page 3 and throws, 124.55 on 100.In the second example the group fits the page it moves to, so checking the next page's height would not be enough.
In an earlier pass, a group could also move to a page with a column narrower than the table. The next pass then failed with the table-width error, a known limit in #1116.
What changed
The rule. A group moves only where every page has the same margins. #1105's rule is unchanged there. Where margins differ, the cut falls after the last row that fits, as in 2.5.3.
PageGeometry.hasUniformMargin()(new, package-private) compares the margins the pages end up with, after header and footer space is reserved. All four sides count, with no tolerance (-0.0equals0.0).from(1, …)).prepareTablereads the answer once and keeps it inPreparedTableLayout. Every head and tail keeps it too, so all pieces of a table follow one rule. Without a page geometry, the margins count as the same.cutOutsideSpanGroupsreturns the cut unchanged where margins differ.SplitRequestand the values in it do not change, and only the table split reads the new flag.tableFirstSliceHeightreturns the same value as before. Its Javadoc, and a comment on box moves inLayoutCompiler, now say that the split can cut inside the group this value counts, so a heading or box can move when its table would not, or stay when it does.The cost
If any page's margins differ, every table in the document goes back to 2.5.3's cut, even between two pages with the same margins. One cover page with its own margin is enough.
developkeeps some of these groups whole. As in 2.5.3:Known limits
This PR does not change these:
keepWithNextand a box's move to the next page still count the table's whole first group. Where margins differ, they can move although the table could start on this page, or stay although the table moves. If they move, the table can be refused on the next page. Example: 400×400 with 20pt margins, where pages 2 and later hold 100pt; a 180pt spacer, akeepWithNextsection with a one-line heading, and a group with rows of 120pt and 60pt. 2.5.3 makes 2 pages, with the heading and the first row on page 1.developand this PR throw, 180 on 100. With 2.5.3's first-slice height put back where margins differ, this PR lays the example out as 2.5.3 does. The comparison below covers boxes, but notkeepWithNext.developand this PR throw, 210 on 100.developlaid the document out.Compared with 2.5.3 and develop
I compared the published 2.5.3 jars,
develop(610c102) and this PR locally on 58,000 generated documents. The generator is not part of the tests. The documents have tables with and withoutrowSpan, some with repeated headers, plus text, shapes and spacers. All sets but the third also have one level of sections. The first also has rows, stacks and page breaks. The third and fourth are built from the same random numbers as the second, so the sets are not independent. None haskeepWithNextor page references.developI compared exact numbers, spanning cells included. Where margins are the same, every result matchesdevelop. Where they differ, every result matchesdevelopwith group moves turned off."Fit" means that 2.5.3 placed every fragment (text, shapes, table rows) above the bottom margin, to 0.6pt. For tables the check sees only row boxes. It does not see spanning cells or spacers, so the last two rows count those separately, in every document each version lays out.
develop→ this PRdevelop/ this PRdevelop/ this PR"Refused" counts every exception. The counts below are for the first three sets. They are all 0 in the fourth.
develop: 25 / 90 / 94. 2.5.3 also refused 19 / 84 / 90 of them. Of those it laid out, 1 / 5 / 3 fit and 5 / 1 / 1 did not. This PR lays out 24 / 109 / 119 thatdeveloprefuses.develop. Against 2.5.3, it is 1 / 2 / 0, all because of fix(layout): draw a box's decoration on its own box and keep atomic blocks and closing insets on the page they land on #1107's rules for moving a box and for closing insets.Verification
./mvnw -B -ntp clean test -pl :graph-compose-qa -am→ BUILD SUCCESS, 6,541 tests, 0 failures, 4 skipped (core 968, render-pdf 351, render-docx 2,851, testing 5, render-pptx 233, templates 128, qa 2,005). No snapshot or visual baseline moved. No existing assertion changed.DocxPageMarginSectionsTestpasses unedited, but one of its comments is now out of date. It says the layout cuts inside a span only when the rows do not fit an empty page.PageGeometryTest(+22): 5 sets of overrides that leave one margin and 14 that leave two, an open-ended range, negative zero, and 6,174 override lists checked page by page.TableSpanGroupPageMarginsTest(new, core, 8): the same tables split both ways, with and without a repeated header. Heads, tails and a tail of a tail keep the rule.TableRowSpanPageMarginsTest(new, qa, 15): whole documents.develop.developand fail on 2.5.3.MultiPassCapacityRefusalTest(+1). Its 256ptrowSpandocument keeps its layout, but its first pass now cuts the group and refuses nothing. A new document, with rows of 238pt and 78pt, covers arowSpantable that is refused only in the first pass.TableRowSpanSplitTestpasses the new record component to a constructor. Its class comment andTableRowSpanPageBreakTest's now say that their rule needs the same margins on every page.I ran 35 sabotages, covering 28 different breaks: 24 against the core tests and 11 against qa, with seven run against both. A failing test caught each run, and the sources were restored byte-identical.
The 141 example layouts and the 859 distinct layouts from the template tests match
develop. Two examples userowSpan, and no template does. 7 and 69 of these layouts have margins that differ. None has both.No public API change: japicmp for core and
extract-api.mjs --from-reactor --checkpass.Lane: shared-engine (table split).