diff --git a/examples/LongTable.pdf b/examples/LongTable.pdf index 117a7d4..4b3c65d 100644 Binary files a/examples/LongTable.pdf and b/examples/LongTable.pdf differ diff --git a/lib/Layout/TableBox.php b/lib/Layout/TableBox.php index e50527d..bee43a5 100644 --- a/lib/Layout/TableBox.php +++ b/lib/Layout/TableBox.php @@ -1158,6 +1158,9 @@ public function measureWidth() */ public function measureHeight(bool $afterPageDividing = false) { + if ($this->wasCut()) { + return $this; + } foreach ($this->getCells() as $cell) { $cell->measureHeight(); } diff --git a/lib/Layout/TableCellBox.php b/lib/Layout/TableCellBox.php index b65bda3..3c6288a 100644 --- a/lib/Layout/TableCellBox.php +++ b/lib/Layout/TableCellBox.php @@ -70,7 +70,9 @@ public function measureWidth() */ public function measureHeight(bool $afterPageDividing = false) { - //$this->applyStyleWidth(); + if ($this->wasCut()) { + return $this; + } foreach ($this->getChildren() as $child) { $child->measureHeight(); } diff --git a/lib/Layout/TableWrapperBox.php b/lib/Layout/TableWrapperBox.php index dee023f..79714d7 100644 --- a/lib/Layout/TableWrapperBox.php +++ b/lib/Layout/TableWrapperBox.php @@ -93,6 +93,9 @@ public function measureWidth() */ public function measureHeight(bool $afterPageDividing = false) { + if ($this->wasCut()) { + return $this; + } $maxHeight = '0'; foreach ($this->getChildren() as $child) { $child->measureHeight(); diff --git a/lib/Page.php b/lib/Page.php index 05fc70a..1144f93 100644 --- a/lib/Page.php +++ b/lib/Page.php @@ -1001,7 +1001,16 @@ public function cutBelow(Box $child, string $yPos) return $this; } - public function cutBox($box, $yPos, $cloned) + /** + * Cut box. + * + * @param Box $box + * @param string $yPos + * @param Box $cloned + * + * @return Box + */ + public function cutBox(Box $box, string $yPos, Box $cloned) { foreach ($box->getChildren() as $child) { if (!$child->isForMeasurement() || !$child->isRenderable()) { @@ -1032,7 +1041,7 @@ public function cutBox($box, $yPos, $cloned) * * @param Box[]|null $boxes * - * @return Box[] cloned boxes + * @return Box[]|null cloned boxes */ public function cloneAndDivideChildrenAfterY(string $yPos, array $boxes = null) { @@ -1053,7 +1062,7 @@ public function cloneAndDivideChildrenAfterY(string $yPos, array $boxes = null) $cloned->clearChildren(); $boxCoords = $box->getCoordinates(); if ($box instanceof TableWrapperBox && Math::comp($boxCoords->getY(), $yPos) <= 0 && Math::comp($boxCoords->getEndY(), $yPos) > 0) { - $cloned = $this->divideTable($box); + $cloned = $this->divideTable($box, $yPos, $cloned); } else { $cloned = $this->cutBox($box, $yPos, $cloned); } @@ -1062,16 +1071,40 @@ public function cloneAndDivideChildrenAfterY(string $yPos, array $boxes = null) return $clonedBoxes; } + /** + * Treat table like div? - just cut. + * + * @param TableWrapperBox $tableWrapperBox + * @param string $yPos + * + * @return bool + */ + public function treatTableLikeDiv(TableWrapperBox $tableWrapperBox, string $yPos) + { + $cells = $tableWrapperBox->getBoxesByType('TableCellBox'); + foreach ($cells as $cell) { + if (Math::comp($cell->getCoordinates()->getEndY(), $yPos)>0) { + return true; + } + } + return false; + } + /** * Divide overflowed table. * - * @param Box $tableChild + * @param Box $tableChild + * @param string $yPos + * @param Box $cloned * * @return TableWrapperBox */ - protected function divideTable(Box $tableChild) + protected function divideTable(Box $tableChild, string $yPos, Box $cloned) { $tableWrapperBox = $tableChild->getClosestByType('TableWrapperBox'); + if ($this->treatTableLikeDiv($tableWrapperBox, $yPos)) { + return $this->cutBox($tableWrapperBox, $yPos, $cloned); + } $pageEnd = Math::add($this->getDimensions()->getHeight(), (string) $this->margins['top']); if (Math::comp($tableWrapperBox->getCoordinates()->getY(), $pageEnd) >= 0) { // if table is below page do nothing - it will be moved to the next page and then again checked