Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Print Inverted" Feature #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions zpl/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@
class Label:
'''
Used to build a ZPL2 label.

all dimensions are given in millimeters and automatically converted to
printer dot units.
'''

def __init__(self, height, width=110.0, dpmm=12.0):
def __init__(self, height, width=110.0, dpmm=12.0, print_inverted=False):
"""
Creates one (or more) ZPL2 labels.

*height* and *width* are given in millimeters
*dpmm* refers to dots per millimeter (e.g. 12 for 300dpi)
*print_inverted* rotates the label format by 180 degrees such that the label appears to be printed upside down
"""
self.height = height
self.width = width
self.dpmm = dpmm

self.code = "^XA"
if print_inverted:
self.code += "^POI"

def labelhome(self, x, y, justification=None):
"""
Expand Down Expand Up @@ -74,7 +76,6 @@ def set_darkness(self, value):
def textblock(self, width, justification='C', lines=1):
"""
new text block

width of textblock in millimeters
"""
assert justification in ['L','R','C','J']
Expand All @@ -101,7 +102,6 @@ def write_text(self, text, char_height=None, char_width=None, font='0', orientat
def set_default_font(self, height, width, font='0'):
"""
sets default font from here onward

height and width are given in milimeters
"""
assert re.match(r'[A-Z0-9]', font), "invalid font"
Expand All @@ -111,7 +111,6 @@ def change_international_font(self, character_set=28, remaps=[]):
"""
change the international font/encoding, that enables you to call
up the international character set you want to use for printing

"remaps" arg is a list of tuples with the number of the source
character and the substitute character destination.
"""
Expand All @@ -131,9 +130,7 @@ def change_international_font(self, character_set=28, remaps=[]):
def _convert_image(self, image, width, height, compression_type='A'):
'''
converts *image* (of type PIL.Image) to a ZPL2 format

compression_type can be one of ['A', 'B', 'C']

returns data
'''
image = image.resize((int(width*self.dpmm), int(height*self.dpmm)))
Expand Down Expand Up @@ -170,7 +167,6 @@ def upload_graphic(self, name, image, width, height=0):
def write_graphic(self, image, width, height=0, compression_type="A"):
"""
embeddes image with given width

image has to be of type PIL.Image
if height is not given, it will be chosen proportionally
"""
Expand Down Expand Up @@ -301,7 +297,6 @@ def saveFormat(self, name):
def preview(self, index=0):
'''
Opens rendered preview using Labelary API.

Not all commands are supported, see http://labelary.com for more information.
'''
try:
Expand Down Expand Up @@ -352,3 +347,4 @@ def __main__():

if __name__ == "__main__":
__main__()