Skip to content

Commit

Permalink
Properly skip checking for page breaks on empty text nodes (#2506)
Browse files Browse the repository at this point in the history
Before, page breaks before empty text nodes were not allowed, but they
were still checked; and as they report their line height as the space
needed, they could force a page break, which then would continue to
search backwards in the tree for an element that allowed a page break
(even though it would fit on the current page).

Based on work in #1356
Fixes #2468
  • Loading branch information
Mellthas committed Sep 6, 2021
1 parent a799821 commit 3cb71d2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/FrameDecorator/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,6 @@ protected function _page_break_allowed(Frame $frame)
return false;
}

// Skip breaks on empty text nodes
if ($frame->is_text_node() && $frame->get_node()->nodeValue == "") {
return false;
}

Helpers::dompdf_debug("page-break", "inline: break allowed");

return true;
Expand Down Expand Up @@ -498,7 +493,10 @@ protected function _page_break_allowed(Frame $frame)
*/
function check_page_break(Frame $frame)
{
if ($this->_page_full || $frame->_already_pushed) {
if ($this->_page_full || $frame->_already_pushed
// Never check for breaks on empty text nodes
|| ($frame->is_text_node() && $frame->get_node()->nodeValue === "")
) {
return false;
}

Expand Down Expand Up @@ -586,7 +584,13 @@ function check_page_break(Frame $frame)
break;
}

if ($next = $iter->get_prev_sibling()) {
$next = $iter->get_prev_sibling();
// Skip empty text nodes
while ($next && $next->is_text_node() && $next->get_node()->nodeValue === "") {
$next = $next->get_prev_sibling();
}

if ($next) {
Helpers::dompdf_debug("page-break", "following prev sibling.");

if ($next->is_table() && !$iter->is_table()) {
Expand Down

0 comments on commit 3cb71d2

Please sign in to comment.