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

Fix: page breaking on rows with rowspan. #2090

Open
wants to merge 1 commit into
base: master
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Frame.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public function get_next_sibling()
}

/**
* @return FrameList|Frame[]
* @return FrameList|Frame[] !! TODO fixup doc. It never returns Frame[]
*/
public function get_children()
{
Expand Down
36 changes: 36 additions & 0 deletions src/FrameDecorator/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@ protected function _page_break_allowed(Frame $frame)
$p = $p->find_block_parent();
}

// Avoid page break for table row if specified
if ($frame->get_style()->page_break_before === "avoid") {
Helpers::dompdf_debug("page-break", "before: avoid for table-row");

return false;
}


// Avoid breaking before the first row of a table
if ($table && $table->get_first_child() === $frame || $table->get_first_child()->get_first_child() === $frame) {
Helpers::dompdf_debug("page-break", "table: first-row");
Expand All @@ -438,6 +446,34 @@ protected function _page_break_allowed(Frame $frame)
return false;
}

// Prevent page breaking on rowspan cells. If child frames count of this table row less then column count of table , than it is likely that row touched by previous rowspan, prevent page from breaking
if($table && $table->get_cellmap() && $table->get_cellmap()->frame_exists_in_cellmap($frame) && $table->get_cellmap()->get_num_cols() > iterator_count($frame->get_children())) {
$cellmap = $table->get_cellmap();
$table_columns_count = $cellmap->get_num_cols();

$row_number = $cellmap->get_spanned_cells($frame)["rows"][0];

// Iterate through previous rows, to find and check spanned cell
$prev_row = $frame;
while($prev_row && $table_columns_count > iterator_count($prev_row->get_children())) {
$prev_row = $prev_row->get_prev_sibling();
}

// Check that we don't rollback all the way up to first row
if($prev_row) {
// Looking for spanned cell in row
foreach($prev_row->get_children() as $child) {
$frame_rows = $cellmap->get_spanned_cells($child)["rows"];
if($frame_rows && in_array($row_number, $frame_rows)) {
Helpers::dompdf_debug("page-break", "table-row: contains verified spanned cell");

return false;
}
}
}
}


Helpers::dompdf_debug("page-break", "table-row/row-groups: break allowed");

return true;
Expand Down