From 58c7c33fe946bd3b5a25eba0866b0e8947e7e121 Mon Sep 17 00:00:00 2001 From: Dean Rispin Date: Mon, 29 Feb 2016 10:04:00 -0800 Subject: [PATCH] Add inverted printing to set method --- doc/user/methods.rst | 5 +++-- escpos/constants.py | 2 ++ escpos/escpos.py | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/doc/user/methods.rst b/doc/user/methods.rst index 976bde6..10f4fb8 100644 --- a/doc/user/methods.rst +++ b/doc/user/methods.rst @@ -65,8 +65,8 @@ text("text") Prints raw text. Raises ``TextError`` exception. -set("align", "font", "type", width, height) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +set("align", "font", "type", width, height, invert) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Set text properties. * ``align`` set horizontal position for text, the possible values are: @@ -79,6 +79,7 @@ Set text properties. * ``type`` type could be ``B`` (Bold), ``U`` (Underline) or ``normal``. *Default:* normal * ``width`` is a numeric value, 1 is for regular size, and 2 is twice the standard size. *Default*: 1 * ``height`` is a numeric value, 1 is for regular size and 2 is twice the standard size. *Default*: 1 +* ``invert`` is a boolean value, True enables white on black printing. *Default*: False cut("mode") ^^^^^^^^^^^ diff --git a/escpos/constants.py b/escpos/constants.py index c7e5309..59a8853 100644 --- a/escpos/constants.py +++ b/escpos/constants.py @@ -64,6 +64,8 @@ TXT_FONT_B = ESC + '\x4d\x01' # Font type B TXT_ALIGN_LT = ESC + '\x61\x00' # Left justification TXT_ALIGN_CT = ESC + '\x61\x01' # Centering TXT_ALIGN_RT = ESC + '\x61\x02' # Right justification +TXT_INVERT_ON = GS + '\x42\x01' # Inverse Printing ON +TXT_INVERT_OFF = GS + '\x42\x00' # Inverse Printing OFF # Char code table CHARCODE_PC437 = ESC + '\x74\x00' # USA: Standard Europe diff --git a/escpos/escpos.py b/escpos/escpos.py index b8b8342..f082b4b 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -451,7 +451,7 @@ class Escpos(object): colCount = self.columns if columns is None else columns self.text(textwrap.fill(txt, colCount)) - def set(self, align='left', font='a', text_type='normal', width=1, height=1, density=9): + def set(self, align='left', font='a', text_type='normal', width=1, height=1, density=9, invert=False): """ Set text properties by sending them to the printer :param align: horizontal position for text, possible values are: @@ -541,6 +541,11 @@ class Escpos(object): self._raw(PD_P50) else: # DEFAULT: DOES NOTHING pass + # Invert Printing + if invert == True: + self._raw(TXT_INVERT_ON) + else: + self._raw(TXT_INVERT_OFF) def cut(self, mode=''): """ Cut paper.