Skip to content

Commit

Permalink
fixed wrong method name; make conversion use mbstring module
Browse files Browse the repository at this point in the history
  • Loading branch information
kohlerdominik committed Sep 4, 2024
1 parent ea61dac commit d85d48b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
17 changes: 9 additions & 8 deletions src/PaymentPart/Output/FpdfOutput/FpdfOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -149,15 +149,15 @@ 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
{
// 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);
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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->convertEncoding($element->getText())),
self::BORDER,
self::ALIGN_LEFT
);
Expand All @@ -286,7 +286,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
);
Expand Down Expand Up @@ -336,8 +336,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) ?: '';
// Helvetica has no unicode support
return mb_convert_encoding($text, 'Windows-1252', 'UTF-8');
}
}
7 changes: 4 additions & 3 deletions src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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->convertEncoding($element->getText()),
0,
0,
self::BORDER
Expand Down Expand Up @@ -353,8 +353,9 @@ 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 convertEncoding(string $text): string
{
return iconv('UTF-8', 'windows-1252', $text) ?: '';
// Helvetica has no unicode support
return mb_convert_encoding($text, 'Windows-1252', 'UTF-8');
}
}

0 comments on commit d85d48b

Please sign in to comment.