eymlo / python-escpos

Automatically exported from code.google.com/p/python-escpos
GNU General Public License v3.0
1 stars 0 forks source link

Corrections for direct printer firmware typeface flags #18

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Epson.set('center','A','NORMAL',2,2)

   ( The typeface is tall and not wide;
     double width and height is a single 0x30 flag,
     not 0x10 and 0x20 in sequence;
     0x20 ends up cancelling 0x10. )

2. Epson.set('center','U2','NORMAL',2,2)

   ( a stale constant for turning off Italic remains;
     this is not defined in constants.py; therefore,
     delete this line )

What is the expected output? What do you see instead?

1. For text that should be quad area, I see
   Text that is tall, and not wide

2. For normal weight with strong underline,
   I see A NameError:

>>> Epson.set('center','A','U2',2,2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/escpos/escpos.py", line 206, in set
    self._raw(TXT_ITALIC_OFF)
NameError: global name 'TXT_ITALIC_OFF' is not defined

What version of the product are you using? On what operating system?

$ hg summary
parent: 12:849dabb63ce0 tip
 Added syntax to have print working on windows
branch: default
commit: 2 modified, 5 unknown
update: (current)

$ uname -imrs 
FreeBSD 9.2-RELEASE i386 GENERIC

Please provide any additional information below.

  diff attached in hg-diff-escpos.txt;

  constants.py:
    1. I have introduced a suggested fix for quad area characters,
    in the form of a new constant, "TXT_4SQUARE".

  escpos.py:
    1. For quad-area characters, reset to normal first,
    then send only one flag to activate double width and height.

    2. The deprecated constant, "TXT_ITALIC_OFF", is removed.

This was verified on an Epson TM-H6000, IEE-1284 (parallel)
  Epson = printer.File("/dev/lpt0")

Thank you for this library. I look forward to extending it
if I am able to.

Thanks as well to the developers of Mercurial;
an R.C.S that works, just as the developers intended.

Original issue reported on code.google.com by syncma...@gmail.com on 10 Dec 2013 at 4:03

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you syncman1x.
Hopefully your changes will be added to the new release this weekend.

Once again, thank you for your contribution.

Original comment by manpaz on 2 Jan 2014 at 8:17

GoogleCodeExporter commented 9 years ago
Your welcome.

----

This comment is not directly related to Issue #18:

I am describing a possible extension, which I intend to resubmit later as a new 
issue.

Here is an experiment, for people who have a combination thermal & slip 
printer. The paper type can be selected:

HW_PRINT_ROLL = '\x1B\x63\x30\x03' # 80mm roll, thermal
HW_PRINT_SLIP = '\x1B\x63\x30\x04' # Slip / Cheque, dot matrix

Common settings, like the type face and character geometry, can be set on the 
dot matrix slip printer, the same way as done for the thermal engine.

E.paper('slip')

E.set('left','A','B',1,2)

If anyone tests this, please be mindful of both the logical and physical length 
of your slip. My printer seems not to sense the end of a narrow slip. It is 
okay with an A4 sheet.

PAPER_SLIP_OUT  = '\x1B\x4B\xC0' # Eject slip or cheque

The method I use to eject is a slip-reverse command. It reverses the feed 
direction on a flat paper path TM-H5000II, and feeds a slip out forward on the 
TM-H6000.

E.cut('slip')

Always return to the roll paper type when finished.

E.paper('roll')

% hg diff

diff -r 849dabb63ce0 escpos/constants.py
--- a/escpos/constants.py   Thu May 30 08:56:33 2013 -0700
+++ b/escpos/constants.py   Sat Jan 18 15:14:30 2014 +1100
@@ -10,16 +10,21 @@
 HW_INIT   = '\x1b\x40'         # Clear data in buffer and reset modes
 HW_SELECT = '\x1b\x3d\x01'     # Printer select
 HW_RESET  = '\x1b\x3f\x0a\x00' # Reset printer hardware
+# Printer paper
+HW_PRINT_ROLL = '\x1B\x63\x30\x03' # 80mm roll, thermal
+HW_PRINT_SLIP = '\x1B\x63\x30\x04' # Slip / Cheque, dot matrix
 # Cash Drawer
 CD_KICK_2 = '\x1b\x70\x00'     # Sends a pulse to pin 2 [] 
 CD_KICK_5 = '\x1b\x70\x01'     # Sends a pulse to pin 5 [] 
 # Paper
 PAPER_FULL_CUT  = '\x1d\x56\x00' # Full cut paper
 PAPER_PART_CUT  = '\x1d\x56\x01' # Partial cut paper
+PAPER_SLIP_OUT  = '\x1B\x4B\xC0' # Eject slip or cheque
 # Text format   
 TXT_NORMAL      = '\x1b\x21\x00' # Normal text
 TXT_2HEIGHT     = '\x1b\x21\x10' # Double height text
 TXT_2WIDTH      = '\x1b\x21\x20' # Double width text
+TXT_4SQUARE     = '\x1b\x21\x30' # Quad area text
 TXT_UNDERL_OFF  = '\x1b\x2d\x00' # Underline font OFF
 TXT_UNDERL_ON   = '\x1b\x2d\x01' # Underline font 1-dot ON
 TXT_UNDERL2_ON  = '\x1b\x2d\x02' # Underline font 2-dot ON
diff -r 849dabb63ce0 escpos/escpos.py
--- a/escpos/escpos.py  Thu May 30 08:56:33 2013 -0700
+++ b/escpos/escpos.py  Sat Jan 18 15:14:30 2014 +1100
@@ -189,8 +189,8 @@
             self._raw(TXT_NORMAL)
             self._raw(TXT_2HEIGHT)
         elif height == 2 and width == 2:
-            self._raw(TXT_2WIDTH)
-            self._raw(TXT_2HEIGHT)
+            self._raw(TXT_NORMAL)
+            self._raw(TXT_4SQUARE)
         else: # DEFAULT SIZE: NORMAL
             self._raw(TXT_NORMAL)
         # Type
@@ -203,7 +203,6 @@
         elif type.upper() == "U2":
             self._raw(TXT_BOLD_OFF)
             self._raw(TXT_UNDERL2_ON)
-            self._raw(TXT_ITALIC_OFF)
         elif type.upper() == "BU":
             self._raw(TXT_BOLD_ON)
             self._raw(TXT_UNDERL_ON)
@@ -227,6 +226,15 @@
             self._raw(TXT_ALIGN_LT)

+    def paper(self, type='ROLL'):
+        if type.upper() == '':
+            self._raw(HW_PRINT_ROLL)
+        elif type.upper() == 'ROLL':
+            self._raw(HW_PRINT_ROLL)
+        elif type.upper() == 'SLIP':
+            self._raw(HW_PRINT_SLIP)
+
+
     def cut(self, mode=''):
         """ Cut paper """
         # Fix the size between last line and cut
@@ -234,6 +242,10 @@
         self._raw("\n\n\n\n\n\n")
         if mode.upper() == "PART":
             self._raw(PAPER_PART_CUT)
+        if mode.upper() == "FULL":
+            self._raw(PAPER_FULL_CUT)
+        if mode.upper() == "PART":
+            self._raw(PAPER_SLIP_OUT)
         else: # DEFAULT MODE: FULL CUT
             self._raw(PAPER_FULL_CUT)

Original comment by syncma...@gmail.com on 18 Jan 2014 at 4:54