Add inverted printing to set method

This commit is contained in:
Dean Rispin 2016-02-29 10:04:00 -08:00
parent b7c6edc9e1
commit 58c7c33fe9
3 changed files with 11 additions and 3 deletions

View File

@ -65,8 +65,8 @@ text("text")
Prints raw text. Raises ``TextError`` exception. Prints raw text. Raises ``TextError`` exception.
set("align", "font", "type", width, height) set("align", "font", "type", width, height, invert)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Set text properties. Set text properties.
* ``align`` set horizontal position for text, the possible values are: * ``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 * ``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 * ``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 * ``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") cut("mode")
^^^^^^^^^^^ ^^^^^^^^^^^

View File

@ -64,6 +64,8 @@ TXT_FONT_B = ESC + '\x4d\x01' # Font type B
TXT_ALIGN_LT = ESC + '\x61\x00' # Left justification TXT_ALIGN_LT = ESC + '\x61\x00' # Left justification
TXT_ALIGN_CT = ESC + '\x61\x01' # Centering TXT_ALIGN_CT = ESC + '\x61\x01' # Centering
TXT_ALIGN_RT = ESC + '\x61\x02' # Right justification 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 # Char code table
CHARCODE_PC437 = ESC + '\x74\x00' # USA: Standard Europe CHARCODE_PC437 = ESC + '\x74\x00' # USA: Standard Europe

View File

@ -451,7 +451,7 @@ class Escpos(object):
colCount = self.columns if columns is None else columns colCount = self.columns if columns is None else columns
self.text(textwrap.fill(txt, colCount)) 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 """ Set text properties by sending them to the printer
:param align: horizontal position for text, possible values are: :param align: horizontal position for text, possible values are:
@ -541,6 +541,11 @@ class Escpos(object):
self._raw(PD_P50) self._raw(PD_P50)
else: # DEFAULT: DOES NOTHING else: # DEFAULT: DOES NOTHING
pass pass
# Invert Printing
if invert == True:
self._raw(TXT_INVERT_ON)
else:
self._raw(TXT_INVERT_OFF)
def cut(self, mode=''): def cut(self, mode=''):
""" Cut paper. """ Cut paper.