Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#399 #416 Initial fix for header/footer showing on page without body rows #418

Open
wants to merge 6 commits into
base: open-dev-v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public int numEffCols() {
}

public int spanOfEffCol(int effCol) {
return ((ColumnData)_columns.get(effCol)).getSpan();
return _columns.get(effCol).getSpan();
}

public int colToEffCol(int col) {
Expand Down Expand Up @@ -171,7 +171,7 @@ public void splitColumn(int pos, int firstSpan) {
newColumn.setSpan(firstSpan);
_columns.add(pos, newColumn);

ColumnData leftOver = (ColumnData)_columns.get(pos+1);
ColumnData leftOver = _columns.get(pos+1);
leftOver.setSpan(leftOver.getSpan() - firstSpan);

for (TableSectionBox section : getTableSections()) {
Expand Down Expand Up @@ -616,6 +616,7 @@ protected void calcLayoutHeight(LayoutContext c, BorderPropertySet border,
}
}

@Override
public void reset(LayoutContext c) {
super.reset(c);

Expand Down Expand Up @@ -947,6 +948,7 @@ public FixedTableLayout(TableBox table) {
_table = table;
}

@Override
public void reset() {
_widths = null;
}
Expand Down Expand Up @@ -1003,7 +1005,7 @@ private int calcWidthArray(LayoutContext c) {
TableRowBox firstRow = _table.getFirstRow();
if (firstRow != null) {
for (Iterator<TableCellBox> j = firstRow.getChildIteratorOfType(TableCellBox.class); j.hasNext();) {
TableCellBox cell = (TableCellBox) j.next();
TableCellBox cell = j.next();
Length w = cell.getOuterStyleWidth(c);
int span = cell.getStyle().getColSpan();
long effWidth = 0;
Expand All @@ -1016,7 +1018,7 @@ private int calcWidthArray(LayoutContext c) {
while (usedSpan < span) {
int eSpan = _table.spanOfEffCol(cCol + i);

Length columnWidth = (Length) _widths.get(cCol + i);
Length columnWidth = _widths.get(cCol + i);
// only set if no col element has already set it.
if (columnWidth.isVariable() && !w.isVariable()) {
_widths.set(cCol + i, new Length(w.value() * eSpan, w.type()));
Expand Down Expand Up @@ -1052,7 +1054,7 @@ public void calcMinMaxWidth(LayoutContext c) {

boolean haveNonFixed = false;
for (int i = 0; i < _widths.size(); i++) {
Length w = (Length)_widths.get(i);
Length w = _widths.get(i);
if (! w.isFixed()) {
haveNonFixed = true;
break;
Expand All @@ -1077,7 +1079,7 @@ public void layout(LayoutContext c) {

// first assign fixed width
for ( int i = 0; i < nEffCols; i++ ) {
Length l = (Length)_widths.get(i);
Length l = _widths.get(i);
if ( l.isFixed() ) {
calcWidth[i] = l.value();
available -= l.value();
Expand All @@ -1088,7 +1090,7 @@ public void layout(LayoutContext c) {
if ( available > 0 ) {
int totalPercent = 0;
for ( int i = 0; i < nEffCols; i++ ) {
Length l = (Length)_widths.get(i);
Length l = _widths.get(i);
if ( l.isPercent() ) {
totalPercent += l.value();
}
Expand All @@ -1101,7 +1103,7 @@ public void layout(LayoutContext c) {
}

for ( int i = 0; available > 0 && i < nEffCols; i++ ) {
Length l = (Length)_widths.get(i);
Length l = _widths.get(i);
if ( l.isPercent() ) {
long w = base * l.value() / totalPercent;
available -= w;
Expand All @@ -1114,14 +1116,14 @@ public void layout(LayoutContext c) {
if ( available > 0 ) {
int totalVariable = 0;
for ( int i = 0; i < nEffCols; i++ ) {
Length l = (Length)_widths.get(i);
Length l = _widths.get(i);
if ( l.isVariable() ) {
totalVariable++;
}
}

for ( int i = 0; available > 0 && i < nEffCols; i++ ) {
Length l = (Length)_widths.get(i);
Length l = _widths.get(i);
if ( l.isVariable() ) {
int w = available / totalVariable;
available -= w;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.openhtmltopdf.css.style.derived.BorderPropertySet;
import com.openhtmltopdf.css.style.derived.RectPropertySet;
import com.openhtmltopdf.layout.CollapsedBorderSide;
import com.openhtmltopdf.layout.FloatManager;
import com.openhtmltopdf.layout.LayoutContext;
import com.openhtmltopdf.render.BlockBox;
import com.openhtmltopdf.render.BorderPainter;
Expand Down Expand Up @@ -222,12 +221,7 @@ public void moveContent(LayoutContext c, final int deltaY) {
b.setY(b.getY() + deltaY);
}

getPersistentBFC().getFloatManager().performFloatOperation(
new FloatManager.FloatOperation() {
public void operate(Box floater) {
floater.setY(floater.getY() + deltaY);
}
});
getPersistentBFC().getFloatManager().performFloatOperation(floater -> floater.setY(floater.getY() + deltaY));

calcChildLocations();
}
Expand Down Expand Up @@ -790,6 +784,7 @@ private Rectangle getCollapsedBorderBounds(CssContext c) {
return bounds;
}

@Override
public Rectangle getPaintingClipEdge(CssContext c) {
if (hasCollapsedPaintingBorder()) {
return getCollapsedBorderBounds(c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,27 @@ public TableColumn(Element element, CalculatedStyle style) {
_style = style;
}

@Override
public Element getElement() {
return _element;
}

@Override
public String getPseudoElementOrClass() {
return null;
}

@Override
public CalculatedStyle getStyle() {
return _style;
}

@Override
public void setElement(Element e) {
_element = e;
}

@Override
public void setStyle(CalculatedStyle style) {
_style = style;
}
Expand Down
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 All @@ -127,6 +137,7 @@ private boolean isShouldMoveToNextPage(LayoutContext c) {
return true;
}

@Override
public void analyzePageBreaks(LayoutContext c, ContentLimitContainer container) {
if (getTable().getStyle().isPaginateTable()) {
_contentLimitContainer = new ContentLimitContainer(c, getAbsY());
Expand Down Expand Up @@ -191,6 +202,7 @@ private void calcExtraSpaceBottom(LayoutContext c) {
_extraSpaceBottom = maxBorderAndPadding;
}

@Override
protected void layoutChildren(LayoutContext c, int contentStart) {
setState(Box.CHILDREN_FLUX);
ensureChildren(c);
Expand Down Expand Up @@ -307,6 +319,7 @@ private int calcMiddleBottomDeltaY(TableCellBox cell, IdentValue verticalAlign)
}
}

@Override
protected void calcLayoutHeight(
LayoutContext c, BorderPropertySet border,
RectPropertySet margin, RectPropertySet padding) {
Expand Down Expand Up @@ -452,6 +465,7 @@ private void layoutCell(LayoutContext c, TableCellBox cell, int contentStart) {
cell.layout(c, contentStart);
}

@Override
public void initStaticPos(LayoutContext c, BlockBox parent, int childOffset) {
setX(0);

Expand Down Expand Up @@ -499,6 +513,7 @@ public void setHaveBaseline(boolean haveBaseline) {
_haveBaseline = haveBaseline;
}

@Override
protected String getExtraBoxDescription() {
if (isHaveBaseline()) {
return "(baseline=" + getBaseline() + ") ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ private void addCell(TableRowBox row, TableCellBox cell, int cRow) {
cell.setCol(getTable().effColToCol(col));
}

@Override
public void reset(LayoutContext c) {
super.reset(c);
_grid.clear();
Expand Down Expand Up @@ -313,4 +314,13 @@ public int getOriginalAbsY() {
public void setOriginalAbsY(int originalAbsY) {
_originalAbsY = originalAbsY;
}

@Override
public void setNeedPageClear(boolean needPageClear) {
if (needPageClear && isHeader()) {
getTable().setNeedPageClear(true);
} else {
super.setNeedPageClear(needPageClear);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,10 @@ private void calcClearance(LayoutContext c) {

private void calcExtraPageClearance(LayoutContext c) {
if (c.isPageBreaksAllowed() &&
c.getExtraSpaceTop() > 0 && (getStyle().isSpecifiedAsBlock() || getStyle().isListItem())) {
c.getExtraSpaceTop() > 0 &&
(getStyle().isSpecifiedAsBlock() ||
getStyle().isListItem())) {

PageBox first = c.getRootLayer().getFirstPage(c, this);
if (first != null && first.getTop() + c.getExtraSpaceTop() > getAbsY()) {
int diff = first.getTop() + c.getExtraSpaceTop() - getAbsY();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void updateBottom(int bottom) {
}
}

@Override
public String toString() {
return "[top=" + _top + ", bottom=" + _bottom + "]";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
public class ContentLimitContainer {
private ContentLimitContainer _parent;

private int _initialPageNo;
private List _contentLimits = new ArrayList();
private final int _initialPageNo;
private final List<ContentLimit> _contentLimits = new ArrayList<>();

private PageBox _lastPage;

Expand Down Expand Up @@ -57,7 +57,7 @@ private ContentLimit getContentLimit(int pageNo, boolean addAsNeeded) {

int target = pageNo - _initialPageNo;
if (target >= 0 && target < _contentLimits.size()) {
return (ContentLimit)_contentLimits.get(pageNo - _initialPageNo);
return _contentLimits.get(pageNo - _initialPageNo);
} else {
return null;
}
Expand Down Expand Up @@ -125,6 +125,7 @@ public boolean isContainsMultiplePages() {
return _contentLimits.size() > 1;
}

@Override
public String toString() {
return "[initialPageNo=" + _initialPageNo + ", limits=" + _contentLimits + "]";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ tbody {
thead {
display: table-header-group;
vertical-align: middle;
page-break-inside: avoid;
}

tfoot {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<html>
<head>
<style>
@page {
size: 200px 200px;
}
body {
border: 1px solid orange;
}
table {
-fs-table-paginate: paginate;
}
th {
background-color: red;
}
td {
background-color: blue;
}
th, td {
border: 1px solid black;
}
thead {
page-break-inside: auto;
}
</style>
</head>
<body>
<div style="height: 70px;"></div>

<table>
<thead>
<tr><th>HA</th><th>HB</th></tr>
</thead>
<tbody>
<tr><td>a</td><td>b</td></tr>
<tr><td>c</td><td>d</td></tr>
</tbody>
</table>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<html>
<head>
<style>
@page {
size: 200px 200px;
}
body {
border: 1px solid orange;
}
table {
-fs-table-paginate: paginate;
}
th {
background-color: red;
}
td {
background-color: blue;
}
th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<div style="height: 70px;"></div>

<table>
<thead>
<tr><th>HA</th><th>HB</th></tr>
</thead>
<tbody>
<tr><td>a</td><td>b</td></tr>
<tr><td>c</td><td>d</td></tr>
</tbody>
</table>

</body>
</html>
Loading