diff --git a/composer.json b/composer.json index a6d3b2d6..4710c75a 100644 --- a/composer.json +++ b/composer.json @@ -7,12 +7,12 @@ "php": "~8.0.0|~8.1.0|~8.2.0|~8.3.0", "ext-dom": "*", "ext-bcmath": "*", - "ext-iconv": "*", "symfony/validator": "^4.4|^5.0|^6.0|^7.0", "symfony/intl": "^4.4|^5.0|^6.0|^7.0", "kmukku/php-iso11649": "^1.5", "endroid/qr-code": "^4.4.4|^5.0", - "symfony/polyfill-intl-icu": "^1.23" + "symfony/polyfill-intl-icu": "^1.23", + "symfony/polyfill-mbstring": "^1.30" }, "require-dev": { "phpunit/phpunit": "^9.0", diff --git a/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php b/src/PaymentPart/Output/FpdfOutput/FpdfOutput.php index c1a7e731..35cb88d5 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->convertEncoding(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->convertEncoding(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->convertEncoding(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->convertEncoding(Translation::get('separate', $this->language)), self::BORDER, self::ALIGN_CENTER); } } @@ -258,9 +258,7 @@ private function setTitleElement(Title $element, bool $isReceiptPart): void $this->fpdf->MultiCell( 0, 2.8, - iconv( - 'UTF-8', - 'windows-1252', + $this->convertEncoding( Translation::get(str_replace('text.', '', $element->getTitle()), $this->language) ) ); @@ -273,7 +271,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->convertEncoding($element->getText())), self::BORDER, self::ALIGN_LEFT ); @@ -286,7 +284,7 @@ private function setFurtherInformationElement(FurtherInformation $element): void $this->fpdf->MultiCell( 0, 4, - $this->toUtf8($element->getText()), + $this->convertEncoding($element->getText()), self::BORDER, self::ALIGN_LEFT ); @@ -336,8 +334,9 @@ 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 convertEncoding(string $text): string { - return iconv('UTF-8', 'windows-1252', $text) ?: ''; + // FPDF does not support unicode. + return mb_convert_encoding($text, 'CP1252', 'UTF-8'); } } diff --git a/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php b/src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php index d87addf3..ef5ee89c 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()), + $element->getText(), 0, 0, self::BORDER @@ -352,9 +352,4 @@ 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 - { - return iconv('UTF-8', 'windows-1252', $text) ?: ''; - } }