Skip to content

Commit

Permalink
Recovered test option in addText #128 and properly calculate 'full' j…
Browse files Browse the repository at this point in the history
…ustification for the last line
  • Loading branch information
ole1986 committed Oct 15, 2019
1 parent 2012c05 commit 00db904
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/Cezpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -1947,7 +1947,9 @@ public function ezText($text, $size = 0, $options = array(), $test = 0)
}

$lines = preg_split("[\r\n|\r|\n]", $text);
foreach ($lines as $line) {
$c = count($lines);
for ($i = 0; $i < $c; $i++) {
$line = $lines[$i];
$start = 1;
while (strlen($line) || $start) {
$start = 0;
Expand All @@ -1971,6 +1973,14 @@ public function ezText($text, $size = 0, $options = array(), $test = 0)
} else {
$right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array($options) && isset($options['right'])) ? $options['right'] : 0);
}

if ($just == 'full' && $c == $i + 1) {
$tmp = $this->addText($left, $this->y, $size, $line, $right - $left, $just, 0, 0, 1);
if (!strlen($tmp)) {
$just = "left";
}
}

$line = $this->addText($left, $this->y, $size, $line, $right - $left, $just, 0, 0, $test);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/Cpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -3003,9 +3003,10 @@ public function addText($x, $y, $size, $text, $width = 0, $justification = 'left
return $v['text'];
}, $parts));

// only adjust full, when 90 percent of the width is used
if (($justification == 'full' && ($orgWidth / 100 * 90) < ($orgWidth - $width)) || $justification != 'full') {
$this->adjustWrapText($parsedText, $orgWidth - $width, $orgWidth, $x, $wordSpaceAdjust, $justification);
$this->adjustWrapText($parsedText, $orgWidth - $width, $orgWidth, $x, $wordSpaceAdjust, $justification);

if ($test) {
return $text;
}

foreach (array_filter($this->callback, function ($v) {
Expand Down

0 comments on commit 00db904

Please sign in to comment.