From 0e61d182d0be2537e015c9f53e5865bc40ddcba0 Mon Sep 17 00:00:00 2001 From: Ronald Mak Date: Thu, 27 May 2021 17:17:54 +0800 Subject: [PATCH 1/2] Print Chinese(BIG5) text --- src/Mike42/Escpos/Printer.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Mike42/Escpos/Printer.php b/src/Mike42/Escpos/Printer.php index 05c8a6f0..e7aecf36 100644 --- a/src/Mike42/Escpos/Printer.php +++ b/src/Mike42/Escpos/Printer.php @@ -999,16 +999,17 @@ public function text(string $str) /** * Add Chinese text to the buffer. This is a specific workaround for Zijang printers- - * The printer will be switched to a two-byte mode and sent GBK-encoded text. + * The printer will be switched to a two-byte mode and sent GBK/BIG5-encoded text. * * Support for this will be merged into a print buffer. * * @param string $str Text to print, as UTF-8 + * @param string $encoding Encoding of Chinese text such as BIG-5, GB18030 */ - public function textChinese(string $str = "") + public function textChinese(string $str = "", string $encoding = "GBK") { $this -> connector -> write(self::FS . "&"); - $str = \UConverter::transcode($str, "GBK", "UTF-8"); + $str = \UConverter::transcode($str, $encoding, "UTF-8"); $this -> buffer -> writeTextRaw((string)$str); $this -> connector -> write(self::FS . "."); } From 50f44a32fe2cdcac895b32678621fa6c63127eb2 Mon Sep 17 00:00:00 2001 From: Ronald Mak Date: Wed, 8 Jul 2026 11:31:08 +0800 Subject: [PATCH 2/2] refactor: add ChineseEncoding enum and update textChinese method Create a strongly-typed enum for supported Chinese character encodings for ESC/POS printers. Update the Printer::textChinese method to use the enum instead of loose string parameters, improving type safety and code maintainability. Adjust the transcoding call to use the enum's string value. --- src/Mike42/Escpos/ChineseEncoding.php | 16 ++++++++++++++++ src/Mike42/Escpos/Printer.php | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/Mike42/Escpos/ChineseEncoding.php diff --git a/src/Mike42/Escpos/ChineseEncoding.php b/src/Mike42/Escpos/ChineseEncoding.php new file mode 100644 index 00000000..eea73e26 --- /dev/null +++ b/src/Mike42/Escpos/ChineseEncoding.php @@ -0,0 +1,16 @@ + connector -> write(self::FS . "&"); - $str = \UConverter::transcode($str, $encoding, "UTF-8"); + $str = \UConverter::transcode($str, $encoding -> value, "UTF-8"); $this -> buffer -> writeTextRaw((string)$str); $this -> connector -> write(self::FS . "."); }