8000 Workaround for float reflows limit by Fl0Cri · Pull Request #3714 · dompdf/dompdf · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/Dompdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ public function render()

$canvas = $this->canvas;

LineBox::reset_float_reflow_limit(); // FIXME smelly hack

$root_frame = $this->tree->get_root();
$root = Factory::decorate_root($root_frame, $this);
foreach ($this->tree as $frame) {
Expand Down
24 changes: 21 additions & 3 deletions src/LineBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ class LineBox
*/
public $inline = false;

/**
* @var int
*/
public static $max_float_reflows = 10000;

/**
* FIXME smelly hack, used by the get_float_offsets method.
*
* @var int
*/
private static $float_offset_anti_infinite_loop = 10000;

/**
* @param Block $frame the Block containing this line
* @param float $y
Expand Down Expand Up @@ -152,10 +164,16 @@ public function get_floats_inside(Page $root): array
return $childs;
}

public function get_float_offsets(): void
/**
* Resets the anti-infinite-loop counter for the get_float_offsets method.
*/
public static function reset_float_reflow_limit(): void
{
static $anti_infinite_loop = 10000; // FIXME smelly hack
self::$float_offset_anti_infinite_loop = self::$max_float_reflows;
}

public function get_float_offsets(): void
{
$reflower = $this->_block_frame->get_reflower();

if (!$reflower) {
Expand Down Expand Up @@ -201,7 +219,7 @@ public function get_float_offsets(): void
}

// If the child is still shifted by the floating element
if ($anti_infinite_loop-- > 0 &&
if (self::$float_offset_anti_infinite_loop-- > 0 &&
$floating_frame->get_position("y") + $floating_frame->get_margin_height() >= $this->y &&
$block->get_position("x") + $block->get_margin_width() >= $floating_frame->get_position("x")
) {
Expand Down
0