Skip to content

Commit

Permalink
Properly skip checking for page breaks on empty text nodes
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 dompdf#1356
Fixes dompdf#2468
  • Loading branch information
Mellthas committed Aug 1, 2021
1 parent dd09636 commit 95f1cb1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/FrameDecorator/Page.php
Expand Up @@ -398,11 +398,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 @@ -468,7 +463,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 @@ -556,7 +554,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 95f1cb1

Please sign in to comment.