Skip to content

Commit

Permalink
Draft fixes text justify
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Mar 25, 2024
1 parent 5855213 commit 07edd43
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
10 changes: 8 additions & 2 deletions examples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,7 @@

// add a text column with automatic line breaking

$bfont3 = $pdf->font->insert($pdf->pon, 'times', '', 14);

$bfont3 = $pdf->font->insert($pdf->pon, 'courier', '', 14);
$pdf->page->addContent($bfont3['out']);

$txt3 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'."\n".'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
Expand All @@ -1112,6 +1111,10 @@
);
$pdf->page->addContent($txtbox);


$bfont4 = $pdf->font->insert($pdf->pon, 'dejavusans', '', 14);
$pdf->page->addContent($bfont4['out']);

// block of text between two page regions
$pdf->addTextCol(
$txt3,
Expand Down Expand Up @@ -1147,6 +1150,9 @@
],
];

$bfont4 = $pdf->font->insert($pdf->pon, 'freeserif', 'I', 14);
$pdf->page->addContent($bfont4['out']);

$pdf->setDefaultCellPadding(1,1,1,1);
$txtcell = $pdf->getTextCell(
'Lorem ipsum dolor sit amet', // string $txt,
Expand Down
23 changes: 12 additions & 11 deletions src/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,34 +865,35 @@ protected function getJustifiedString(
float $width = 0,
): string {
$pwidth = $this->toPoints($width);
$spacewidth = (($pwidth - $dim['totwidth'] + $dim['totspacewidth']) / ($dim['spaces'] ?: 1));
if (! $this->isunicode) {

if ((!$this->isunicode) || $this->font->isCurrentByteFont()) {
if ($this->isunicode) {
$txt = $this->uniconv->latinArrToStr($this->uniconv->uniArrToLatinArr($ordarr));
}
$txt = $this->encrypt->escapeString($txt);
$txt = $this->getOutTextShowing($txt, 'Tj');
if ($pwidth > 0) {
return $this->getOutTextStateOperatorTw($txt, $this->toPoints($spacewidth));
$spacewidth = (($pwidth - $dim['totwidth']) / ($dim['spaces'] ?: 1));
return $this->getOutTextStateOperatorTw($txt, $spacewidth);
}

$this->lasttxtbbox['width'] = $this->toUnit($dim['totwidth']);
return $txt;
}

if ($this->font->isCurrentByteFont()) {
$txt = $this->uniconv->latinArrToStr($this->uniconv->uniArrToLatinArr($ordarr));
} else {
$unistr = implode('', $this->uniconv->ordArrToChrArr($ordarr));
$txt = $this->uniconv->toUTF16BE($unistr);
}

$unistr = implode('', $this->uniconv->ordArrToChrArr($ordarr));
$txt = $this->uniconv->toUTF16BE($unistr);
$txt = $this->encrypt->escapeString($txt);

if ($pwidth <= 0) {
$this->lasttxtbbox['width'] = $this->toUnit($dim['totwidth']);
return $this->getOutTextShowing($txt, 'Tj');
}

$fontsize = $this->font->getCurrentFont()['size'] ?: 1;
$spacewidth = (($pwidth - $dim['totwidth'] + $dim['totspacewidth']) / ($dim['spaces'] ?: 1));
$spacewidth = -1000 * $spacewidth / $fontsize;
$txt = str_replace(chr(0) . chr(32), ') ' . sprintf('%F', $spacewidth) . ' (', $txt);

return $this->getOutTextShowing($txt, 'TJ');
}

Expand Down

0 comments on commit 07edd43

Please sign in to comment.