Improve ticket legibility: larger fonts, spacing, indentation and thermal emphasized mode
Some checks failed
CI / lint-and-test (3.11) (push) Has been cancelled
CI / lint-and-test (3.13) (push) Has been cancelled

This commit is contained in:
2026-07-18 16:22:26 +00:00
parent 8e6c1f2887
commit 95a01c8958
3 changed files with 31 additions and 15 deletions

View File

@@ -16,9 +16,13 @@ ALIGN_CENTER = ESC + b'a' + b'\x01'
ALIGN_RIGHT = ESC + b'a' + b'\x02'
BOLD_ON = ESC + b'E' + b'\x01'
BOLD_OFF = ESC + b'E' + b'\x00'
EMPH_ON = ESC + b'G' + b'\x01' # Double-strike / emphasized
EMPH_OFF = ESC + b'G' + b'\x00'
DOUBLE_HEIGHT = ESC + b'!' + b'\x10'
NORMAL_SIZE = ESC + b'!' + b'\x00'
LARGE_SIZE = ESC + b'!' + b'\x30' # Double width + double height
LINE_SPACING_140 = ESC + b'3' + b'\x28' # ~1.4x line spacing
LINE_SPACING_DEFAULT = ESC + b'2'
def generate_ticket(sale_data, business_info, width=80):
@@ -34,6 +38,8 @@ def generate_ticket(sale_data, business_info, width=80):
chars = 32 if width == 58 else 48 # characters per line
buf = bytearray()
buf += INIT
buf += EMPH_ON
buf += LINE_SPACING_140
# Header: business name (centered, bold, large)
buf += ALIGN_CENTER
@@ -100,6 +106,8 @@ def generate_ticket(sale_data, business_info, width=80):
buf += 'Gracias por su compra!\n'.encode('cp437', errors='replace')
buf += 'Nexus Autoparts POS\n'.encode('cp437', errors='replace')
buf += b'\n\n\n'
buf += LINE_SPACING_DEFAULT
buf += EMPH_OFF
buf += FEED + b'\x05' # Feed 5 lines before cutting
buf += CUT # Full cut
@@ -120,6 +128,8 @@ def generate_quotation_ticket(quote_data, business_info, width=80):
chars = 32 if width == 58 else 48
buf = bytearray()
buf += INIT
buf += EMPH_ON
buf += LINE_SPACING_140
# Header
buf += ALIGN_CENTER
@@ -188,6 +198,8 @@ def generate_quotation_ticket(quote_data, business_info, width=80):
buf += 'Precios sujetos a disponibilidad\n'.encode('cp437', errors='replace')
buf += 'Nexus Autoparts POS\n'.encode('cp437', errors='replace')
buf += b'\n\n\n'
buf += LINE_SPACING_DEFAULT
buf += EMPH_OFF
buf += FEED + b'\x05'
buf += CUT
@@ -226,6 +238,8 @@ def generate_service_order_ticket(so_data, business_info, width=80):
chars = 32 if width == 58 else 48
buf = bytearray()
buf += INIT
buf += EMPH_ON
buf += LINE_SPACING_140
# Header
buf += ALIGN_CENTER
@@ -340,6 +354,8 @@ def generate_service_order_ticket(so_data, business_info, width=80):
buf += "No es comprobante fiscal\n".encode("cp437", errors="replace")
buf += "Nexus Autoparts POS\n".encode("cp437", errors="replace")
buf += b"\n\n\n"
buf += LINE_SPACING_DEFAULT
buf += EMPH_OFF
buf += FEED + b'\x05'
buf += CUT