diff --git a/phpstan.neon.dist b/phpstan.neon.dist index dcd3a5c..39931fe 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,4 +2,5 @@ parameters: level: 8 paths: - %currentWorkingDirectory%/src + - %currentWorkingDirectory%/tests checkMissingIterableValueType: false diff --git a/src/Weez/Zpl/Model/Element/ZebraText.php b/src/Weez/Zpl/Model/Element/ZebraText.php index e532990..cd17a03 100644 --- a/src/Weez/Zpl/Model/Element/ZebraText.php +++ b/src/Weez/Zpl/Model/Element/ZebraText.php @@ -46,6 +46,11 @@ class ZebraText extends ZebraElement */ protected $text; + /** + * @var bool + */ + protected $allowHexadecimal; + /** * @var PrinterOptions */ @@ -71,8 +76,26 @@ public function __construct($positionX, $positionY, $text, $fontSize = null, $ze $this->positionY = $positionY; $this->fieldBlock = $fieldBlock; $this->printerOptions = new PrinterOptions(); + $this->allowHexadecimal = true; + } + + /** + * @return bool + */ + public function isAllowHexadecimal(): bool + { + return $this->allowHexadecimal; } + /** + * @param bool $allowHexadecimal + * @return self + */ + public function setAllowHexadecimal(bool $allowHexadecimal) + { + $this->allowHexadecimal = $allowHexadecimal; + return $this; + } /** * @@ -98,7 +121,11 @@ public function getZplCode($_printerOptions = null) $zpl .= $this->fieldBlock->getZplCode($printerOptions); } - $zpl .= "^FH\\^FD"; //We allow hexadecimal and start element + if ($this->allowHexadecimal) { + $zpl .= "^FH\\"; + } + + $zpl .= "^FD"; //We allow hexadecimal and start element $zpl .= ZplUtils::convertAccentToZplAsciiHexa($this->text); $zpl .= ZplUtils::zplCommandSautLigne("FS"); diff --git a/tests/Weez/Zpl/Tests/Model/Element/ZebraTextTest.php b/tests/Weez/Zpl/Tests/Model/Element/ZebraTextTest.php new file mode 100644 index 0000000..812a0eb --- /dev/null +++ b/tests/Weez/Zpl/Tests/Model/Element/ZebraTextTest.php @@ -0,0 +1,34 @@ +getZplCode()); + } + + public function testGetZplCodeWithBlockTest(): void + { + $block = new ZebraFieldBlock(500, 2, 1, new ZebraAlignment(ZebraAlignment::RIGHT)); + $text = new ZebraText(20, 20, "Text", null, null, null, $block); + self::assertEquals("^FT20,20^FB500,2,1,R^FH\^FDText^FS\n", $text->getZplCode()); + } + + public function testGetZplCodeAllowDecimalTest(): void + { + $text = new ZebraText(20, 20, "Text\&Multilined"); + $text->setAllowHexadecimal(false); + + self::assertFalse($text->isAllowHexadecimal()); + self::assertEquals("^FT20,20^FDText\&Multilined^FS\n", $text->getZplCode()); + } +}