No idae what happened, but rotate in PIL instead of brother

This commit is contained in:
Christoffer Viken 2017-03-21 21:08:19 +00:00
parent 1b13dd9d32
commit 806c9c3516
2 changed files with 10 additions and 8 deletions

View File

@ -8,14 +8,14 @@ def px2mm(px, dpi=300):
class BrotherLabelWriter(ImageWriter): class BrotherLabelWriter(ImageWriter):
def __init__(self, typ='62', max_height=350, rot=0, text=None): def __init__(self, typ='62', max_height=350, rot=False, text=None):
super(BrotherLabelWriter, self).__init__() super(BrotherLabelWriter, self).__init__()
assert typ in label_type_specs assert typ in label_type_specs
if (rot//90) % 2 == 1: if self.rot:
self._h, self._w = label_type_specs[typ]['dots_printable'] self._h, self._w = label_type_specs[typ]['dots_printable']
if self._w == 0 or self._w > max_height: if self._w == 0 or self._w > max_height:
self._w = max_height self._w = max_height
if (rot//90) % 2 == 0: else:
self._w, self._h = label_type_specs[typ]['dots_printable'] self._w, self._h = label_type_specs[typ]['dots_printable']
if self._h == 0 or self._h > max_height: if self._h == 0 or self._h > max_height:
self._h = max_height self._h = max_height
@ -28,7 +28,7 @@ class BrotherLabelWriter(ImageWriter):
super(BrotherLabelWriter, self)._init(code) super(BrotherLabelWriter, self)._init(code)
def calculate_size(self, modules_per_line, number_of_lines, dpi=300): def calculate_size(self, modules_per_line, number_of_lines, dpi=300):
x, y = super(self).calculate_size(modules_per_line, number_of_lines, dpi) x, y = super(BrotherLabelWriter, self).calculate_size(modules_per_line, number_of_lines, dpi)
self._xo = (px2mm(self._w)-px2mm(x))/2 self._xo = (px2mm(self._w)-px2mm(x))/2
self._yo = (px2mm(self._h)-px2mm(y)) self._yo = (px2mm(self._h)-px2mm(y))
@ -44,6 +44,8 @@ class BrotherLabelWriter(ImageWriter):
super(BrotherLabelWriter, self)._paint_text(xpos+self._xo, ypos+self._yo) super(BrotherLabelWriter, self)._paint_text(xpos+self._xo, ypos+self._yo)
def _finish(self): def _finish(self):
if self.rot:
self._image.rotate(90)
if self._title: if self._title:
width = self._w+1 width = self._w+1
height = 0 height = 0

View File

@ -9,17 +9,17 @@ from barcode_helpers import BrotherLabelWriter
def print_bar_code(barcode_value, barcode_text, barcode_type="ean13", rotate=False, printer_type="QL-700", def print_bar_code(barcode_value, barcode_text, barcode_type="ean13", rotate=False, printer_type="QL-700",
label_type="62"): label_type="62"):
bar_coder = barcode.get_barcode_class(barcode_type) bar_coder = barcode.get_barcode_class(barcode_type)
wr = BrotherLabelWriter(typ=label_type, rot=rotate*90, text=barcode_text, max_height=1000) wr = BrotherLabelWriter(typ=label_type, rot=rotate, text=barcode_text, max_height=1000)
test = bar_coder(barcode_value, writer=wr) test = bar_coder(barcode_value, writer=wr)
fn = test.save(barcode_value) fn = test.save(barcode_value)
print_image(fn, printer_type, label_type, rotate*90) print_image(fn, printer_type, label_type)
def print_image(fn, printer_type="QL-700", label_type="62", rotate=0): def print_image(fn, printer_type="QL-700", label_type="62"):
qlr = BrotherQLRaster(printer_type) qlr = BrotherQLRaster(printer_type)
qlr.exception_on_warning = True qlr.exception_on_warning = True
create_label(qlr, fn, label_type, threshold=70, cut=True, rotate=rotate) create_label(qlr, fn, label_type, threshold=70, cut=True)
be = backend_factory("pyusb") be = backend_factory("pyusb")
list_available_devices = be['list_available_devices'] list_available_devices = be['list_available_devices']