From fec65e4e09fde2a700688ba581e0304011e65d2a Mon Sep 17 00:00:00 2001 From: Dominik Kohler Date: Tue, 3 Sep 2024 13:24:12 +0200 Subject: [PATCH] fixed wrong method name; make conversion linux-compatible --- src/PaymentPart/Output/FpdfOutput/FpdfOutput.php | 16 ++++++++-------- .../Output/TcPdfOutput/TcPdfOutput.php | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php b/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php index c1a7e731..d9a0a345 100644 --- a/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php +++ b/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php @@ -137,7 +137,7 @@ private function addInformationContentReceipt(): void // Title $this->fpdf->SetFont(self::FONT, 'B', self::FONT_SIZE_MAIN_TITLE); $this->SetXY(self::LEFT_PART_X, self::TITLE_Y); - $this->fpdf->MultiCell(0, 7, $this->toUtf8(Translation::get('receipt', $this->language))); + $this->fpdf->MultiCell(0, 7, $this->substituteUnsupportedCharacters(Translation::get('receipt', $this->language))); // Elements $this->setY(204); @@ -149,7 +149,7 @@ private function addInformationContentReceipt(): void // Acceptance section $this->fpdf->SetFont(self::FONT, 'B', self::FONT_SIZE_TITLE_RECEIPT); $this->SetXY(self::LEFT_PART_X, 274.3); - $this->fpdf->Cell(54, 0, $this->toUtf8(Translation::get('acceptancePoint', $this->language)), self::BORDER, '', self::ALIGN_RIGHT); + $this->fpdf->Cell(54, 0, $this->substituteUnsupportedCharacters(Translation::get('acceptancePoint', $this->language)), self::BORDER, '', self::ALIGN_RIGHT); } private function addInformationContent(): void @@ -157,7 +157,7 @@ private function addInformationContent(): void // Title $this->fpdf->SetFont(self::FONT, 'B', self::FONT_SIZE_MAIN_TITLE); $this->SetXY(self::RIGHT_PART_X, 195.2); - $this->fpdf->MultiCell(48, 7, $this->toUtf8(Translation::get('paymentPart', $this->language))); + $this->fpdf->MultiCell(48, 7, $this->substituteUnsupportedCharacters(Translation::get('paymentPart', $this->language))); // Elements $this->setY(197.3); @@ -229,7 +229,7 @@ private function addSeparatorContentIfNotPrintable(): void $this->fpdf->Line(62 + $this->offsetX, 193 + $this->offsetY, 62 + $this->offsetX, 296 + $this->offsetY); $this->fpdf->SetFont(self::FONT, '', self::FONT_SIZE_FURTHER_INFORMATION); $this->setY(189.6); - $this->fpdf->MultiCell(0, 0, $this->toUtf8(Translation::get('separate', $this->language)), self::BORDER, self::ALIGN_CENTER); + $this->fpdf->MultiCell(0, 0, $this->substituteUnsupportedCharacters(Translation::get('separate', $this->language)), self::BORDER, self::ALIGN_CENTER); } } @@ -273,7 +273,7 @@ private function setTextElement(Text $element, bool $isReceiptPart): void $this->fpdf->MultiCell( $isReceiptPart ? 54 : 0, $isReceiptPart ? 3.3 : 4, - str_replace('text.', '', $this->toUtf8($element->getText())), + str_replace('text.', '', $this->substituteUnsupportedCharacters($element->getText())), self::BORDER, self::ALIGN_LEFT ); @@ -286,7 +286,7 @@ private function setFurtherInformationElement(FurtherInformation $element): void $this->fpdf->MultiCell( 0, 4, - $this->toUtf8($element->getText()), + $this->substituteUnsupportedCharacters($element->getText()), self::BORDER, self::ALIGN_LEFT ); @@ -336,8 +336,8 @@ private function SetXY(float $x, float $y): void $this->fpdf->SetXY($x + $this->offsetX, $y + $this->offsetY); } - private function toUtf8(string $text): string + private function substituteUnsupportedCharacters(string $text): string { - return iconv('UTF-8', 'windows-1252', $text) ?: ''; + return mb_convert_encoding($text, 'ISO-8859-1', 'UTF-8'); } } diff --git a/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php b/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php index d87addf3..15a1bff2 100644 --- a/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php +++ b/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php @@ -283,7 +283,7 @@ private function setFurtherInformationElement(FurtherInformation $element): void { $this->tcPdf->SetFont(self::FONT, '', self::FONT_SIZE_FURTHER_INFORMATION); $this->printMultiCell( - $this->toUtf8($element->getText()), + $this->substituteUnsupportedCharacters($element->getText()), 0, 0, self::BORDER @@ -353,8 +353,8 @@ private function printLine(int $x1, int $y1, int $x2, int $y2): void $this->tcPdf->Line($x1+$this->offsetX, $y1+$this->offsetY, $x2+$this->offsetX, $y2+$this->offsetY); } - private function toUtf8(string $text): string + private function substituteUnsupportedCharacters(string $text): string { - return iconv('UTF-8', 'windows-1252', $text) ?: ''; + return mb_convert_encoding($text, 'ISO-8859-1', 'UTF-8'); } }