diff --git a/setup.cfg b/setup.cfg index bd6d35f..deb2094 100644 --- a/setup.cfg +++ b/setup.cfg @@ -48,7 +48,7 @@ install_requires = setup_requires = setuptools_scm tests_require = jaconv - tox + tox>=4.11 pytest>=7.4 pytest-cov pytest-mock diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index be2f815..d0c7293 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -872,6 +872,7 @@ class Escpos(object): invert: Optional[bool] = None, smooth: Optional[bool] = None, flip: Optional[bool] = None, + normal_textsize: Optional[bool] = None, double_width: Optional[bool] = None, double_height: Optional[bool] = None, custom_size: Optional[bool] = None, @@ -891,6 +892,7 @@ class Escpos(object): special values 'a' or 'b', referring to fonts 0 and 1. :param bold: text in bold :param underline: underline mode for text, decimal range 0-2 + :param normal_textsize: switch to normal textsize if True :param double_height: doubles the height of the text :param double_width: doubles the width of the text :param custom_size: uses custom size specified by width and height @@ -902,7 +904,7 @@ class Escpos(object): :param smooth: True enables text smoothing. Effective on 4x4 size text and larger :param flip: True enables upside-down printing """ - if custom_size is not None and custom_size: + if custom_size: if ( isinstance(width, int) and isinstance(height, int) @@ -913,7 +915,7 @@ class Escpos(object): self._raw(TXT_SIZE + six.int2byte(size_byte)) else: raise SetVariableError() - elif custom_size is not None: + elif normal_textsize or double_height or double_width: self._raw(TXT_NORMAL) if double_width and double_height: self._raw(TXT_STYLE["size"]["2x"]) @@ -924,6 +926,7 @@ class Escpos(object): else: self._raw(TXT_STYLE["size"]["normal"]) else: + # no text size handling requested pass if flip is not None: @@ -993,6 +996,7 @@ class Escpos(object): :param smooth: True enables text smoothing. Effective on 4x4 size text and larger, *default*: False :param flip: True enables upside-down printing, *default*: False """ + normal_textsize = not custom_size and not double_width and not double_height self.set( align=align, font=font, @@ -1004,6 +1008,7 @@ class Escpos(object): invert=invert, smooth=smooth, flip=flip, + normal_textsize=normal_textsize, double_width=double_width, double_height=double_height, custom_size=custom_size, diff --git a/test/test_function_set.py b/test/test_function_set.py index 8545a82..8f9763b 100644 --- a/test/test_function_set.py +++ b/test/test_function_set.py @@ -1,4 +1,5 @@ import six +import pytest import escpos.printer as printer from escpos.constants import SET_FONT, TXT_NORMAL, TXT_SIZE, TXT_STYLE @@ -54,6 +55,18 @@ def test_set_size_2h(): assert instance.output == b"".join(expected_sequence) +def test_set_size_2h_no_default(): + instance = printer.Dummy() + instance.set(double_height=True) + + expected_sequence = ( + TXT_NORMAL, + TXT_STYLE["size"]["2h"], # Double height text size + ) + + assert instance.output == b"".join(expected_sequence) + + def test_set_size_2w(): instance = printer.Dummy() instance.set_with_default(double_width=True) @@ -73,6 +86,18 @@ def test_set_size_2w(): assert instance.output == b"".join(expected_sequence) +def test_set_size_2w_no_default(): + instance = printer.Dummy() + instance.set(double_width=True) + + expected_sequence = ( + TXT_NORMAL, + TXT_STYLE["size"]["2w"], # Double width text size + ) + + assert instance.output == b"".join(expected_sequence) + + def test_set_size_2x(): instance = printer.Dummy() instance.set_with_default(double_height=True, double_width=True) @@ -92,6 +117,18 @@ def test_set_size_2x(): assert instance.output == b"".join(expected_sequence) +def test_set_size_2x_no_default(): + instance = printer.Dummy() + instance.set(double_width=True, double_height=True) + + expected_sequence = ( + TXT_NORMAL, + TXT_STYLE["size"]["2x"], # Quad area text size + ) + + assert instance.output == b"".join(expected_sequence) + + def test_set_size_custom(): instance = printer.Dummy() instance.set_with_default(custom_size=True, width=8, height=7) @@ -111,6 +148,20 @@ def test_set_size_custom(): assert instance.output == b"".join(expected_sequence) +@pytest.mark.parametrize("width", [1, 8]) +@pytest.mark.parametrize("height", [1, 8]) +def test_set_size_custom_no_default(width, height): + instance = printer.Dummy() + instance.set(custom_size=True, width=width, height=height) + + expected_sequence = ( + TXT_SIZE, # Custom text size, no normal reset + six.int2byte(TXT_STYLE["width"][width] + TXT_STYLE["height"][height]), + ) + + assert instance.output == b"".join(expected_sequence) + + # Flip