Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Support CSS "page-break-before" avoid and always for table rows #36

Open
wants to merge 2 commits into
base: wk_4.8.7
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 @@ -181,7 +181,9 @@ JSValue JSCanvasRenderingContext2D::setLineDash(ExecState* exec)
JSValue v = array->get(exec, i);
lineDash.append(v.toNumber(exec));
}
context->setLineDash(lineDash, lineDash[0]);
if (length > 0) {
context->setLineDash(lineDash, lineDash[0]);
}
return jsUndefined();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,49 @@ int RenderTableSection::layoutRows(int toAdd, int headHeight, int footHeight)
rowRequiredHeight = cellRequiredHeight;
}
}

int requiredHeight = max(logicalRowHeights[r], rowRequiredHeight);
if (requiredHeight >= availableHeight && requiredHeight < pageLogicalHeight) {
pageOffset += remainingLogicalHeight + headHeight;
if (requiredHeight > availableHeight) {
m_rowPos[r] += remainingLogicalHeight + headHeight;
bool breakAlways = rowRenderer->style()->pageBreakBefore() == PBALWAYS;

if (breakAlways || (requiredHeight >= availableHeight && requiredHeight < pageLogicalHeight)) {
if (rowRenderer->style()->pageBreakBefore() == PBAVOID) {
// We can't break a page here. Try to find a row at the same page (except first row) which we can break before.
int rowToBreakBefore = 0;

for (int r1 = r - 1; r1 > 0; --r1) {
RenderTableRow* row1Renderer = m_grid[r1].rowRenderer;

if (row1Renderer->style()->pageBreakBefore() != PBAVOID) {
rowToBreakBefore = r1;
break;
}
}

if (rowToBreakBefore > 0) {
// Check if rows from rowToBreakBefore to r even fit a single page - otherwise it doesn't make sense.

if (m_rowPos[r] - m_rowPos[rowToBreakBefore] + requiredHeight <= pageLogicalHeight - headHeight - footHeight - vspacing) {
int dy = m_rowPos[r] - m_rowPos[rowToBreakBefore] + remainingLogicalHeight + headHeight;

// Push all the rows from rowToBreakBefore to r for dy pixels down.
for (int r1 = rowToBreakBefore; r1 <= r; r1++) {
m_rowPos[r1] += dy;
}

pageOffset += dy;

remainingLogicalHeight = pageLogicalHeight - layoutState->pageLogicalOffset(m_rowPos[r]) % pageLogicalHeight;
availableHeight = remainingLogicalHeight - footHeight - vspacing;
}
}
}

if (breakAlways || requiredHeight >= availableHeight) {
pageOffset += remainingLogicalHeight + headHeight;

if (breakAlways || requiredHeight > availableHeight) {
m_rowPos[r] += remainingLogicalHeight + headHeight;
}
}
}
}
Expand Down