Skip to content

Commit

Permalink
table cell min width bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafał Pośpiech committed Apr 24, 2019
1 parent 0562e34 commit b35e4dd
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 3 deletions.
33 changes: 33 additions & 0 deletions examples/LongCellText.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<table class="inventory-table" style="border-collapse:collapse;width:100%">
<tr>
<th class="col-type-ItemNumber" style="border:1px solid #ddd">No.</th>
<th class="col-type-Name" style="border:1px solid #ddd">Item name</th>
<th class="col-type-Quantity" style="border:1px solid #ddd">Quantity</th>
<th class="col-type-Value" style="border:1px solid #ddd">Unit</th>
<th class="col-type-UnitPrice" style="border:1px solid #ddd">Unit price</th>
<th class="col-type-TotalPrice" style="border:1px solid #ddd">Net</th>
<th class="col-type-NetPrice" style="border:1px solid #ddd">Price after discount</th>
</tr>
<tr class="row row-1">
<td class="col-type-ItemNumber" style="border:1px solid #ddd;font-weight:bold;">1</td>
<td class="col-type-Name" style="border:1px solid #ddd;padding:0px 4px;">
<strong>Steca Power Tarom12/24/48V 55-140ATak każe przyzwoitość). nikt lepiej zna się tłocz i wzgląd męża dla Rosyi
straszną jak przystało drugich wiek, urodzenie, cnoty, obyczaje chowa i rozmyślał: Ogiński z jego pamięć droga do
rąk muskała włosów.</strong>
</td>
<td class="col-type-Quantity" style="border:1px solid #ddd;padding:0px 4px;text-align:right;">921.00</td>
<td class="col-type-Value" style="border:1px solid #ddd;padding:0px 4px;">m</td>
<td class="col-type-UnitPrice" style="border:1px solid #ddd;padding:0px 4px;text-align:right;">33 809.80 £</td>
<td class="col-type-TotalPrice" style="border:1px solid #ddd;padding:0px 4px;text-align:right;">67 354.30 £</td>
<td class="col-type-NetPrice" style="border:1px solid #ddd;padding:0px 4px;text-align:right;">38 668.50 £</td>
</tr>
<tr>
<th style="padding:0px 4px;text-align:right;"></th>
<th style="padding:0px 4px;text-align:right;"></th>
<th style="padding:0px 4px;text-align:right;"></th>
<th style="padding:0px 4px;text-align:right;"></th>
<th style="padding:0px 4px;text-align:right;"></th>
<th style="padding:0px 4px;text-align:right;border:1px solid #ddd;">67 354.30 £</th>
<th style="padding:0px 4px;text-align:right;border:1px solid #ddd;">38 668.50 £</th>
</tr>
</table>
Binary file added examples/LongCellText.pdf
Binary file not shown.
12 changes: 12 additions & 0 deletions examples/LongCellText.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$loader = require '../vendor/autoload.php';
$files = ['LongCellText'];
foreach ($files as $file) {
$document = (new YetiForcePDF\Document())->init();
$document->loadHtml(file_get_contents($file . '.html'));
$time = microtime(true);
$pdfFile = $document->render();
echo microtime(true) - $time;
file_put_contents($file . '.pdf', $pdfFile);
}
Binary file modified examples/SimpleTable.pdf
Binary file not shown.
17 changes: 16 additions & 1 deletion lib/Layout/TableBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,23 @@ protected function shrinkToFit(string $availableSpace, int $step)
case 2:
// minimal stays minimal, pixels stays untouched, auto columns decreasing
$toAutoDisposition = Math::sub($nonPercentageSpace, $totalPixelWidth);
$nonMinWidthColumns = [];
foreach ($this->autoColumns as $columnIndex => $columns) {
$ratio = Math::div($this->contentWidths[$columnIndex], $autoColumnsMaxWidth);
$columnWidth = Math::mul($toAutoDisposition, $ratio);
if (Math::comp($this->minWidths[$columnIndex], $columnWidth) > 0) {
$toAutoDisposition = Math::sub($toAutoDisposition, Math::sub($this->minWidths[$columnIndex], $columnWidth));
$columnWidth = $this->minWidths[$columnIndex];
foreach ($columns as $column) {
$columnDimensions = $column->getDimensions();
$columnDimensions->setWidth(Math::add($columnWidth, $column->getStyle()->getHorizontalPaddingsWidth()));
$column->getFirstChild()->getDimensions()->setWidth($columnDimensions->getInnerWidth());
}
} else {
$nonMinWidthColumns[$columnIndex] = $columns;
}
}
foreach ($nonMinWidthColumns as $columnIndex => $columns) {
$ratio = Math::div($this->contentWidths[$columnIndex], $autoColumnsMaxWidth);
$columnWidth = Math::mul($toAutoDisposition, $ratio);
foreach ($columns as $column) {
Expand Down Expand Up @@ -1140,7 +1156,6 @@ protected function tryPreferred(string $leftSpace, bool $outerWidthSet)
$leftSpace = Math::sub($leftSpace, $addToPercents);
$leftPercent = Math::sub('100', $totalPercentages);
$restHave = $this->getCurrentOthersWidth();
// if 25% = $currentPercentsWidth
if (Math::comp($totalPercentages, '0') > 0) {
$onePercent = Math::div($currentPercentsWidth, $totalPercentages);
$restMustHave = Math::mul($leftPercent, $onePercent);
Expand Down
4 changes: 2 additions & 2 deletions lib/Style/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ public function getParentOriginalValue(string $ruleName)
protected function importSelectors()
{
$element = $this->getElement();
if($element && !empty($element->getClassNames())){
if ($element && !empty($element->getClassNames())) {
return $this->document->getCssSelectorRules($element->getClassNames());
}
return [];
Expand Down Expand Up @@ -1416,7 +1416,7 @@ protected function parse()
}
}
$this->originalRules[$ruleName] = $ruleValue;
if(isset($selectorRules[$ruleName])){
if (isset($selectorRules[$ruleName])) {
$ruleValue = $selectorRules[$ruleName];
}
if (!isset($inherited[$ruleName]) || isset($selectorRules[$ruleName])) {
Expand Down

0 comments on commit b35e4dd

Please sign in to comment.