Skip to content

Commit

Permalink
Long table bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafał Pośpiech committed Mar 7, 2019
1 parent 3606ccc commit be5a5f3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
Binary file modified examples/LongTable.pdf
Binary file not shown.
3 changes: 3 additions & 0 deletions lib/Layout/TableBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Layout/TableCellBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Layout/TableWrapperBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
43 changes: 38 additions & 5 deletions lib/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
}
Expand All @@ -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
Expand Down

0 comments on commit be5a5f3

Please sign in to comment.