From 5137e7a20e969445795a32f14a42bed5d480cd4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bouc=CC=8Cek?= Date: Tue, 12 May 2020 07:15:18 +0200 Subject: [PATCH] Add line styles, italic mode and underline mode --- src/Receipt.php | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Receipt.php b/src/Receipt.php index 78fb139..dbea1e0 100644 --- a/src/Receipt.php +++ b/src/Receipt.php @@ -132,11 +132,16 @@ public function code128(string $data, int $width = 3, int $height = 42, int $tex return $this; } - public function line(): self + public function line(int $type = 0): self { - // \xc4 = Em dash + $chars = [ + // \xc4 = Em dash + 0 => "\xc4", + 1 => "-", + 2 => "- ", + ]; // 48 = chars to receipt width - return $this->writeLf(str_repeat("\xc4", 48), true); + return $this->writeLf(str_repeat($chars[$type], $type == 2 ? (48 / 2) : 48), true); } public function left(): self @@ -169,6 +174,30 @@ public function unbold(): self return $this; } + public function italic(): self + { + $this->buff(self::C_ESC . "\x34\x01"); + return $this; + } + + public function unitalic(): self + { + $this->buff(self::C_ESC . "\x34\x00"); + return $this; + } + + public function underline(): self + { + $this->buff(self::C_ESC . "\x2d\x01"); + return $this; + } + + public function ununderline(): self + { + $this->buff(self::C_ESC . "\x2d\x00"); + return $this; + } + public function fontA(): self { $this->buff(self::C_ESC . "\x4d\x00");