Skip to content

Commit

Permalink
#399 #416 Initial fix for header/footer showing on a page with no bod…
Browse files Browse the repository at this point in the history
…y rows.

With test proof.
  • Loading branch information
danfickle committed Nov 23, 2019
1 parent 884194c commit 3aa60aa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,30 @@ public void layout(LayoutContext c, int contentStart) {

if (running) {
if (isShouldMoveToNextPage(c)) {
if (getTable().getFirstBodyRow() == this) {
// XXX Performance problem here. This forces the table
// to move to the next page (which we want), but the initial
// table layout run still completes (which we don't)
getTable().setNeedPageClear(true);
} else {
setNeedPageClear(true);
}
}
c.setExtraSpaceTop(prevExtraTop);
c.setExtraSpaceBottom(prevExtraBottom);
}
}

@Override
public void setNeedPageClear(boolean needPageClear) {
if (needPageClear && getTable().getFirstBodyRow() == this) {
// Always move the table itself to a new page, if the first body
// row is moved. Otherwise, we can get header/footer with no body rows on
// a page. This is a fix for:
// https://github.com/danfickle/openhtmltopdf/issues/399

// XXX Performance problem here. This forces the table
// to move to the next page (which we want), but the initial
// table layout run still completes (which we don't)
getTable().setNeedPageClear(true);
} else {
super.setNeedPageClear(needPageClear);
}
}

private boolean isShouldMoveToNextPage(LayoutContext c) {
PageBox page = c.getRootLayer().getFirstPage(c, this);

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<style type="text/css">
@page {
margin: 25mm 10mm;
size: 210mm 297mm;
size: 70mm 297mm;
}
table {
width: 100%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,6 @@ public void testMissingHtml5BlockElements() throws IOException {
* https://github.com/danfickle/openhtmltopdf/issues/399
*/
@Test
@Ignore // Failing for now.
public void testIssue399TableHeaderFooterWithNoRows() throws IOException {
assertTrue(vt.runTest("issue-399-table-header-with-no-rows"));
}
Expand Down

0 comments on commit 3aa60aa

Please sign in to comment.