From 1db55caba8f6364a86096d1bbf7fa8cfc6e3238b Mon Sep 17 00:00:00 2001 From: WeijiangChen Date: Wed, 7 Aug 2019 19:53:16 +0800 Subject: [PATCH] Add Chinese support --- src/escpos/magicencode.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/escpos/magicencode.py b/src/escpos/magicencode.py index c87b20c..b2454ca 100644 --- a/src/escpos/magicencode.py +++ b/src/escpos/magicencode.py @@ -22,6 +22,7 @@ from .constants import CODEPAGE_CHANGE from .exceptions import Error from .codepages import CodePages import six +import re class Encoder(object): @@ -252,6 +253,9 @@ class MagicEncode(object): self.write_with_encoding(self.encoding, text) return + if re.findall(r'[\u4e00-\u9fa5]', text): + text = text.encode('GB18030') + # See how far we can go into the text with the current encoding to_write, text = split_writable_text(self.encoder, text, self.encoding) if to_write: