Skip to content

Commit

Permalink
Changes for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Jun 27, 2021
1 parent 7e221a5 commit d6d964b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Writer/PdfWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, Label
}
}

$result = new PdfResult($fpdf);

if ($logo instanceof LogoInterface) {
$this->addLogo($logo, $fpdf);
$result = $this->addLogo($logo, $result);
}

if ($label instanceof LabelInterface) {
Expand All @@ -80,11 +82,13 @@ public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, Label
$fpdf->Cell(0, 0, $label->getText(), 0, 0, 'C');
}

return new PdfResult($fpdf);
return $result;
}

private function addLogo(LogoInterface $logo, \FPDF $fpdf): void
private function addLogo(LogoInterface $logo, PdfResult $result): PdfResult
{
$fpdf = $result->getPdf();

$logoPath = $logo->getPath();
$logoHeight = $logo->getResizeToHeight();
$logoWidth = $logo->getResizeToWidth();
Expand All @@ -106,5 +110,7 @@ private function addLogo(LogoInterface $logo, \FPDF $fpdf): void
$logoY = $fpdf->GetPageHeight() / 2 - (int) $logoHeight / 2;

$fpdf->Image($logoPath, $logoX, $logoY, $logoWidth, $logoHeight);

return $result;
}
}
5 changes: 5 additions & 0 deletions src/Writer/Result/PdfResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public function __construct(\FPDF $fpdf)
$this->fpdf = $fpdf;
}

public function getPdf(): \FPDF
{
return $this->fpdf;
}

public function getString(): string
{
return $this->fpdf->Output('S');
Expand Down

0 comments on commit d6d964b

Please sign in to comment.