Skip to content

Commit ebddb28

Browse files
author
Rafał Pośpiech
committed
thead & tfoot spacing bugfix
1 parent 9400e97 commit ebddb28

11 files changed

+219
-233
lines changed

examples/ColSpan.pdf

0 Bytes
Binary file not shown.

examples/Image.pdf

0 Bytes
Binary file not shown.

examples/Invoice.html

+212-190
Large diffs are not rendered by default.

examples/Invoice.pdf

943 Bytes
Binary file not shown.

examples/InvoiceTable.pdf

0 Bytes
Binary file not shown.

examples/RowSpan.html

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--<table style="font-size:12px;line-height:1.2;border-collapse:separate;width:100%">
1+
<table style="font-size:12px;line-height:1.2;border-collapse:separate;width:100%">
22
<tr style="background-color:lightgray;border:1px solid black;">
33
<th>header</th>
44
<th>header</th>
@@ -179,7 +179,6 @@
179179
</td>
180180
</tr>
181181
</table>
182-
-->
183182

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

195-
<!--
196194
<table style="font-size:12px;line-height:1.2;border:1px solid blue;border-collapse:separate;width:100%">
197195
<tr>
198196
<td rowspan="2" style="border:1px solid red">row span 3</td>
@@ -262,4 +260,3 @@
262260
<td style="border:1px solid red">3</td>
263261
</tr>
264262
</table>
265-
-->

examples/RowSpan.pdf

557 KB
Binary file not shown.

examples/TableClassNames.pdf

0 Bytes
Binary file not shown.

lib/Html/Parser.php

-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ public function parse()
241241
$page->getBox()->spanAllRows();
242242
}
243243
$page->getBox()->getStyle()->fixDomTree();
244-
//$page->getBox()->getStyle()->fixRowSpansSpacing();
245244
$this->document->fixPageNumbers();
246245
foreach ($this->document->getPages($groupIndex) as $page) {
247246
$this->document->setCurrentPage($page);

lib/Layout/TableBox.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,9 @@ public function measureHeight(bool $afterPageDividing = false)
13491349
$cell->getDimensions()->setHeight($height);
13501350
}
13511351
}
1352-
$rowGroupHeight = Math::add($rowGroupHeight, $row->getStyle()->getRules('border-spacing'));
1352+
if ($row->getStyle()->getRules('border-collapse') === 'separate') {
1353+
$rowGroupHeight = Math::add($rowGroupHeight, $row->getStyle()->getRules('border-spacing'));
1354+
}
13531355
$rowGroup->getDimensions()->setHeight($rowGroupHeight);
13541356
$tableHeight = Math::add($tableHeight, $rowGroupHeight);
13551357
}

lib/Style/Style.php

+3-37
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class Style extends \YetiForcePDF\Base
166166
'height' => 'auto',
167167
'overflow' => 'visible',
168168
'vertical-align' => 'baseline',
169-
'line-height' => '1.2em',
169+
'line-height' => '1.4em',
170170
'background-color' => 'transparent',
171171
'color' => '#000000',
172172
'word-wrap' => 'normal',
@@ -561,7 +561,8 @@ class Style extends \YetiForcePDF\Base
561561
'font-weight' => 'bold',
562562
'text-align' => 'center',
563563
'padding' => '1px',
564-
'background-color' => '#ddd'
564+
'background-color' => '#ddd',
565+
'line-height' => '1.6em'
565566
],
566567
'thead' => [
567568
'display' => 'table-header-group',
@@ -1584,41 +1585,6 @@ public function fixTables(bool $removeBottomBorders)
15841585
return $this;
15851586
}
15861587

1587-
/**
1588-
* Add border spacing to last column that was spanned.
1589-
*
1590-
* @return self
1591-
*/
1592-
public function fixRowSpansSpacing()
1593-
{
1594-
$box = $this->getBox();
1595-
if (!$box instanceof TableBox) {
1596-
$boxes = $box->getBoxesByType('TableBox');
1597-
}
1598-
foreach ($boxes as $box) {
1599-
$rowGroups = $box->getChildren(true, true);
1600-
$rowGroupsCount = count($rowGroups);
1601-
foreach ($rowGroups as $rowGroupIndex => $rowGroup) {
1602-
$columnHeightChanged = false;
1603-
$rows = $rowGroup->getChildren(true, true);
1604-
$rowsCount = count($rows);
1605-
foreach ($rows as $rowIndex => $row) {
1606-
$columns = $row->getChildren(true, true);
1607-
foreach ($columns as $columnIndex => $column) {
1608-
$columnStyle = $column->getStyle();
1609-
if ($columnStyle->getRules('border-collapse') === 'separate' && $rowIndex + $column->getRowSpan() === $rowsCount && $rowGroupIndex + 1 === $rowGroupsCount) {
1610-
$spacing = $columnStyle->getRules('border-spacing');
1611-
$columnStyle->setRule('padding-bottom', $spacing);
1612-
$column->measureHeight();
1613-
$rowGroup->measureHeight();
1614-
}
1615-
}
1616-
}
1617-
}
1618-
}
1619-
return $this;
1620-
}
1621-
16221588
/**
16231589
* Fix dom tree - after dom tree is parsed we must clean up or add some rules.
16241590
*

0 commit comments

Comments
 (0)