Merge pull request #222 from MicroJoe/software-barcode
First implementation of software barcode
This commit is contained in:
commit
83b426f5fd
|
@ -0,0 +1,9 @@
|
||||||
|
from escpos.printer import Usb
|
||||||
|
|
||||||
|
|
||||||
|
# Adapt to your needs
|
||||||
|
p = Usb(0x0416, 0x5011, profile="POS-5890")
|
||||||
|
|
||||||
|
# Some software barcodes
|
||||||
|
p.soft_barcode('code128', 'Hello')
|
||||||
|
p.soft_barcode('code39', '123456')
|
3
setup.py
3
setup.py
|
@ -117,7 +117,8 @@ setup(
|
||||||
'pyyaml',
|
'pyyaml',
|
||||||
'argparse',
|
'argparse',
|
||||||
'argcomplete',
|
'argcomplete',
|
||||||
'future'
|
'future',
|
||||||
|
'viivakoodi>=0.8'
|
||||||
],
|
],
|
||||||
setup_requires=[
|
setup_requires=[
|
||||||
'setuptools_scm',
|
'setuptools_scm',
|
||||||
|
|
|
@ -19,6 +19,9 @@ import qrcode
|
||||||
import textwrap
|
import textwrap
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
import barcode
|
||||||
|
from barcode.writer import ImageWriter
|
||||||
|
|
||||||
from .constants import ESC, GS, NUL, QR_ECLEVEL_L, QR_ECLEVEL_M, QR_ECLEVEL_H, QR_ECLEVEL_Q
|
from .constants import ESC, GS, NUL, QR_ECLEVEL_L, QR_ECLEVEL_M, QR_ECLEVEL_H, QR_ECLEVEL_Q
|
||||||
from .constants import QR_MODEL_1, QR_MODEL_2, QR_MICRO, BARCODE_TYPES, BARCODE_HEIGHT, BARCODE_WIDTH
|
from .constants import QR_MODEL_1, QR_MODEL_2, QR_MICRO, BARCODE_TYPES, BARCODE_HEIGHT, BARCODE_WIDTH
|
||||||
from .constants import BARCODE_FONT_A, BARCODE_FONT_B
|
from .constants import BARCODE_FONT_A, BARCODE_FONT_B
|
||||||
|
@ -408,6 +411,31 @@ class Escpos(object):
|
||||||
if function_type.upper() == "A":
|
if function_type.upper() == "A":
|
||||||
self._raw(NUL)
|
self._raw(NUL)
|
||||||
|
|
||||||
|
def soft_barcode(self, barcode_type, data, impl='bitImageColumn',
|
||||||
|
module_height=5, module_width=0.2, text_distance=1):
|
||||||
|
|
||||||
|
image_writer = ImageWriter()
|
||||||
|
|
||||||
|
# Check if barcode type exists
|
||||||
|
if barcode_type not in barcode.PROVIDED_BARCODES:
|
||||||
|
raise BarcodeTypeError(
|
||||||
|
'Barcode type {} not supported by software barcode renderer'
|
||||||
|
.format(barcode_type))
|
||||||
|
|
||||||
|
# Render the barcode to a fake file
|
||||||
|
barcode_class = barcode.get_barcode_class(barcode_type)
|
||||||
|
my_code = barcode_class(data, writer=image_writer)
|
||||||
|
|
||||||
|
my_code.write("/dev/null", {
|
||||||
|
'module_height': module_height,
|
||||||
|
'module_width': module_width,
|
||||||
|
'text_distance': text_distance
|
||||||
|
})
|
||||||
|
|
||||||
|
# Retrieve the Pillow image and print it
|
||||||
|
image = my_code.writer._image
|
||||||
|
self.image(image, impl=impl)
|
||||||
|
|
||||||
def text(self, txt):
|
def text(self, txt):
|
||||||
""" Print alpha-numeric text
|
""" Print alpha-numeric text
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue