Skip to content

Commit

Permalink
thead & tfoot spacing bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafał Pośpiech committed May 6, 2019
1 parent 9400e97 commit ebddb28
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 233 deletions.
Binary file modified examples/ColSpan.pdf
Binary file not shown.
Binary file modified examples/Image.pdf
Binary file not shown.
402 changes: 212 additions & 190 deletions examples/Invoice.html

Large diffs are not rendered by default.

Binary file modified examples/Invoice.pdf
Binary file not shown.
Binary file modified examples/InvoiceTable.pdf
Binary file not shown.
5 changes: 1 addition & 4 deletions examples/RowSpan.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--<table style="font-size:12px;line-height:1.2;border-collapse:separate;width:100%">
<table style="font-size:12px;line-height:1.2;border-collapse:separate;width:100%">
<tr style="background-color:lightgray;border:1px solid black;">
<th>header</th>
<th>header</th>
Expand Down Expand Up @@ -179,7 +179,6 @@
</td>
</tr>
</table>
-->

<table style="font-size:12px;line-height:1.2;border:1px solid blue;border-collapse:separate;width:100%">
<tr>
Expand All @@ -192,7 +191,6 @@
</tr>
</table>

<!--
<table style="font-size:12px;line-height:1.2;border:1px solid blue;border-collapse:separate;width:100%">
<tr>
<td rowspan="2" style="border:1px solid red">row span 3</td>
Expand Down Expand Up @@ -262,4 +260,3 @@
<td style="border:1px solid red">3</td>
</tr>
</table>
-->
Binary file modified examples/RowSpan.pdf
Binary file not shown.
Binary file modified examples/TableClassNames.pdf
Binary file not shown.
1 change: 0 additions & 1 deletion lib/Html/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ public function parse()
$page->getBox()->spanAllRows();
}
$page->getBox()->getStyle()->fixDomTree();
//$page->getBox()->getStyle()->fixRowSpansSpacing();
$this->document->fixPageNumbers();
foreach ($this->document->getPages($groupIndex) as $page) {
$this->document->setCurrentPage($page);
Expand Down
4 changes: 3 additions & 1 deletion lib/Layout/TableBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,9 @@ public function measureHeight(bool $afterPageDividing = false)
$cell->getDimensions()->setHeight($height);
}
}
$rowGroupHeight = Math::add($rowGroupHeight, $row->getStyle()->getRules('border-spacing'));
if ($row->getStyle()->getRules('border-collapse') === 'separate') {
$rowGroupHeight = Math::add($rowGroupHeight, $row->getStyle()->getRules('border-spacing'));
}
$rowGroup->getDimensions()->setHeight($rowGroupHeight);
$tableHeight = Math::add($tableHeight, $rowGroupHeight);
}
Expand Down
40 changes: 3 additions & 37 deletions lib/Style/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class Style extends \YetiForcePDF\Base
'height' => 'auto',
'overflow' => 'visible',
'vertical-align' => 'baseline',
'line-height' => '1.2em',
'line-height' => '1.4em',
'background-color' => 'transparent',
'color' => '#000000',
'word-wrap' => 'normal',
Expand Down Expand Up @@ -561,7 +561,8 @@ class Style extends \YetiForcePDF\Base
'font-weight' => 'bold',
'text-align' => 'center',
'padding' => '1px',
'background-color' => '#ddd'
'background-color' => '#ddd',
'line-height' => '1.6em'
],
'thead' => [
'display' => 'table-header-group',
Expand Down Expand Up @@ -1584,41 +1585,6 @@ public function fixTables(bool $removeBottomBorders)
return $this;
}

/**
* Add border spacing to last column that was spanned.
*
* @return self
*/
public function fixRowSpansSpacing()
{
$box = $this->getBox();
if (!$box instanceof TableBox) {
$boxes = $box->getBoxesByType('TableBox');
}
foreach ($boxes as $box) {
$rowGroups = $box->getChildren(true, true);
$rowGroupsCount = count($rowGroups);
foreach ($rowGroups as $rowGroupIndex => $rowGroup) {
$columnHeightChanged = false;
$rows = $rowGroup->getChildren(true, true);
$rowsCount = count($rows);
foreach ($rows as $rowIndex => $row) {
$columns = $row->getChildren(true, true);
foreach ($columns as $columnIndex => $column) {
$columnStyle = $column->getStyle();
if ($columnStyle->getRules('border-collapse') === 'separate' && $rowIndex + $column->getRowSpan() === $rowsCount && $rowGroupIndex + 1 === $rowGroupsCount) {
$spacing = $columnStyle->getRules('border-spacing');
$columnStyle->setRule('padding-bottom', $spacing);
$column->measureHeight();
$rowGroup->measureHeight();
}
}
}
}
}
return $this;
}

/**
* Fix dom tree - after dom tree is parsed we must clean up or add some rules.
*
Expand Down

0 comments on commit ebddb28

Please sign in to comment.