Skip to content

Commit

Permalink
Improve user-facing wording of PrintOptions methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sprain committed Nov 7, 2024
1 parent 27c295a commit 632bafa
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 59 deletions.
5 changes: 4 additions & 1 deletion example/FpdfOutput/fpdf-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
$printOptions = new PrintOptions();
$printOptions
->setPrintable(false) // true to remove lines for printing on a perforated stationery
->setSeparatorSymbol(false); // true to show scissors instead of text
->setDisplayTextDownArrows(false) // true to show arrows next to separation text, if shown
->setDisplayScissors(false) // true to show scissors instead of separation text
->setPositionScissorsAtBottom(false) // true to place scissors at the bottom, if shown
;

// 5. Generate the output
$output
Expand Down
5 changes: 4 additions & 1 deletion example/HtmlOutput/html-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
$printOptions = new PrintOptions();
$printOptions
->setPrintable(false) // true to remove lines for printing on a perforated stationery
->setSeparatorSymbol(false); // true to show scissors instead of text
->setDisplayTextDownArrows(false) // true to show arrows next to separation text, if shown
->setDisplayScissors(false) // true to show scissors instead of separation text
->setPositionScissorsAtBottom(false) // true to place scissors at the bottom, if shown
;

// 4. Create a full payment part in HTML
$html = $output
Expand Down
5 changes: 4 additions & 1 deletion example/TcPdfOutput/tcpdf-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
$printOptions = new PrintOptions();
$printOptions
->setPrintable(false) // true to remove lines for printing on a perforated stationery
->setSeparatorSymbol(false); // true to show scissors instead of text
->setDisplayTextDownArrows(false) // true to show arrows next to separation text, if shown
->setDisplayScissors(false) // true to show scissors instead of separation text
->setPositionScissorsAtBottom(false) // true to place scissors at the bottom, if shown
;

// 5. Generate the output
$output
Expand Down
14 changes: 8 additions & 6 deletions src/PaymentPart/Output/FpdfOutput/FpdfOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,30 +250,32 @@ private function addSeparatorContentIfNotPrintable(): void
}
}

if ($layout->hasSeparatorSymbol()) {
if ($layout->isDisplayScissors()) {
$this->fpdf->SetFont(self::FONT_UNICODE, '', self::FONT_SIZE_SCISSORS);

// horizontal scissors
$this->setXY(2 + $this->offsetX + 5, 193 + $this->offsetY + 0.2);
$this->fpdf->Cell(1, 0, self::FONT_UNICODE_CHAR_SCISSORS, 0, 0, 'C');

// vertical scissors
if (!method_exists($this->fpdf, 'swissQrBillTextWithRotation')) {
throw new MissingTraitException('Missing FpdfTrait in this fpdf instance. See fpdf-example.php within this library.');
}
if ($layout->getVerticalSeparatorSymbolPosition() === VerticalSeparatorSymbolPosition::TOP) {
$this->fpdf->swissQrBillTextWithRotation(62 + $this->offsetX - 1.7, 193 + $this->offsetY + 4, self::FONT_UNICODE_CHAR_SCISSORS, -90);
} else {
if ($layout->isPositionScissorsAtBottom()) {
$this->fpdf->swissQrBillTextWithRotation(62 + $this->offsetX + 1.7, 193 + $this->offsetY + 90, self::FONT_UNICODE_CHAR_SCISSORS, 90);
} else {
$this->fpdf->swissQrBillTextWithRotation(62 + $this->offsetX - 1.7, 193 + $this->offsetY + 4, self::FONT_UNICODE_CHAR_SCISSORS, -90);
}
}

if ($layout->hasText()) {
if ($layout->isDisplayText()) {
$this->fpdf->SetFont($this->getFont(), '', self::FONT_SIZE_FURTHER_INFORMATION);
$y = 189.6;
$this->setY($y);
$separateText = $this->convertEncoding(Translation::get('separate', $this->language));
$this->fpdf->MultiCell(0, 0, $separateText, self::BORDER, self::ALIGN_CENTER);

if ($layout->hasTextDownArrows()) {
if ($layout->isDisplayTextDownArrows()) {
$textWidth = $this->fpdf->GetStringWidth($separateText);
$arrowMargin = 3;
$yoffset = 0.6;
Expand Down
9 changes: 5 additions & 4 deletions src/PaymentPart/Output/HtmlOutput/HtmlOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,19 @@ private function hideSeparatorContentIfPrintable(string $paymentPart): string
// draw nothing
$printableStyles = PrintableStylesTemplate::TEMPLATE;
} else {
if ($layout->hasSeparatorSymbol()) {
if ($layout->isDisplayScissors()) {
// draw scissors
$printableStyles = PrintableStylesTemplate::TEMPLATE_SCISSORS;
if ($layout->getVerticalSeparatorSymbolPosition() === VerticalSeparatorSymbolPosition::BOTTOM) {
if ($layout->isPositionScissorsAtBottom()) {
// draw vertical scissors at bottom
$printableStyles .= PrintableStylesTemplate::TEMPLATE_VERTICAL_SCISSORS_DOWN;
}
}
if (!$layout->hasText()) {

if (!$layout->isDisplayText()) {
// hide text
$printableStyles .= PrintableStylesTemplate::TEMPLATE_HIDE_TEXT;
} elseif ($layout->hasTextDownArrows()) {
} elseif ($layout->isDisplayTextDownArrows()) {
// text not hidden and draw text arrows
$printableStyles .= PrintableStylesTemplate::TEMPLATE_TEXT_DOWN_ARROWS;
}
Expand Down
60 changes: 22 additions & 38 deletions src/PaymentPart/Output/PrintOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,13 @@ final class LineStyle
public const NONE = 'NONE';
}

/**
* @internal
*/
final class VerticalSeparatorSymbolPosition
{
public const TOP = 'TOP';
public const BOTTOM = 'BOTTOM';
}

final class PrintOptions
{
private bool $isPrintable = false;
private bool $hasSeparatorSymbol = false;
private bool $hasTextDownArrows = false;
private bool $hasText = true;
private string $verticalSeparatorSymbolPosition = VerticalSeparatorSymbolPosition::TOP;
private bool $displayScissors = false;
private bool $positionScissorsAtBottom = false;
private bool $displayTextDownArrows = false;
private bool $displayText = true;
private string $lineStyle = LineStyle::SOLID;

public function isPrintable(): bool
Expand All @@ -42,52 +33,45 @@ public function setPrintable(bool $isPrintable): self
return $this;
}

public function hasSeparatorSymbol(): bool
public function isDisplayScissors(): bool
{
return $this->hasSeparatorSymbol;
return $this->displayScissors;
}

public function setSeparatorSymbol(bool $hasSeparatorSymbol): self
public function setDisplayScissors(bool $displayScissors): self
{
$this->hasSeparatorSymbol = $hasSeparatorSymbol;
$this->displayScissors = $displayScissors;

return $this;
}

public function hasTextDownArrows(): bool
public function isPositionScissorsAtBottom(): bool
{
return $this->hasTextDownArrows;
return $this->positionScissorsAtBottom;
}

public function setTextDownArrows(bool $hasTextDownArrows): self
public function setPositionScissorsAtBottom(bool $positionScissorsAtBottom): self
{
$this->hasTextDownArrows = $hasTextDownArrows;
$this->positionScissorsAtBottom = $positionScissorsAtBottom;

return $this;
}

public function hasText(): bool
public function isDisplayTextDownArrows(): bool
{
return $this->hasText;
return $this->displayTextDownArrows;
}

public function setText(bool $hasText): self
public function setDisplayTextDownArrows(bool $displayTextDownArrows): self
{
$this->hasText = $hasText;
$this->displayTextDownArrows = $displayTextDownArrows;

return $this;
}

public function getVerticalSeparatorSymbolPosition(): string
public function isDisplayText(): bool
{
return $this->verticalSeparatorSymbolPosition;
}

public function setVerticalSeparatorSymbolPosition(string $verticalSeparatorSymbolPosition): self
{
$this->verticalSeparatorSymbolPosition = $verticalSeparatorSymbolPosition;

return $this;
return $this->displayText;
}

public function getLineStyle(): string
Expand All @@ -100,15 +84,15 @@ public function getLineStyle(): string
*/
public function consolidate(): void
{
$this->lineStyle = $this->hasSeparatorSymbol ? LineStyle::DASHED : LineStyle::SOLID;
$this->lineStyle = $this->displayScissors ? LineStyle::DASHED : LineStyle::SOLID;

if ($this->isPrintable) {
$this->lineStyle = LineStyle::NONE;
}

if ($this->hasSeparatorSymbol) {
$this->hasText = false;
$this->hasTextDownArrows = false;
if ($this->displayScissors) {
$this->displayText = false;
$this->displayTextDownArrows = false;
}
}
}
17 changes: 9 additions & 8 deletions src/PaymentPart/Output/TcPdfOutput/TcPdfOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,36 +243,37 @@ private function addSeparatorContentIfNotPrintable(): void
$this->printLine($xmiddle, $y, $xmiddle, $yend);
}

if ($layout->hasSeparatorSymbol()) {
if ($layout->isDisplayScissors()) {
$this->tcPdf->setFont(self::FONT_UNICODE, '', self::FONT_SIZE_SCISSORS);
// horizontal scissors
$this->setY($y);
$this->setX($xstart + 3);
$this->tcPdf->Cell(0, 10, self::FONT_UNICODE_CHAR_SCISSORS, 0, 0, 'L', false, '', 0, false, 'C');
// vertical scissors
if ($layout->getVerticalSeparatorSymbolPosition() === VerticalSeparatorSymbolPosition::TOP) {
$this->setY($y + 3);
if ($layout->isPositionScissorsAtBottom()) {
$this->setY($yend - 15);
$this->setX($xmiddle);
$this->tcPdf->StartTransform();
$this->tcPdf->Rotate(-90);
$this->tcPdf->Rotate(90);
$this->tcPdf->Cell(0, 10, self::FONT_UNICODE_CHAR_SCISSORS, 0, 0, 'L', false, '', 0, false, 'C');
$this->tcPdf->StopTransform();
} else {
$this->setY($yend - 15);
$this->setY($y + 3);
$this->setX($xmiddle);
$this->tcPdf->StartTransform();
$this->tcPdf->Rotate(90);
$this->tcPdf->Rotate(-90);
$this->tcPdf->Cell(0, 10, self::FONT_UNICODE_CHAR_SCISSORS, 0, 0, 'L', false, '', 0, false, 'C');
$this->tcPdf->StopTransform();
}
}
if ($layout->hasText()) {

if ($layout->isDisplayText()) {
$this->tcPdf->SetFont($this->getFont(), '', self::FONT_SIZE_FURTHER_INFORMATION);
$this->setY($y - 5);
$this->setX($xstart + 3);
$this->printCell(Translation::get('separate', $this->language), 200, 0, 0, self::ALIGN_CENTER);

if ($layout->hasTextDownArrows()) {
if ($layout->isDisplayTextDownArrows()) {
$textWidth = $this->tcPdf->GetStringWidth(Translation::get('separate', $this->language));
$arrowMargin = 3;
$yoffset = 5.5;
Expand Down

0 comments on commit 632bafa

Please sign in to comment.