diff --git a/report_aeroo/__openerp__.py b/report_aeroo/__openerp__.py index 0a01957b..70368244 100644 --- a/report_aeroo/__openerp__.py +++ b/report_aeroo/__openerp__.py @@ -130,4 +130,9 @@ 'active': False, 'application': True, 'auto_install': False, + 'external_dependencies': { + 'python': [ + 'elaphe' + ] + } } diff --git a/report_aeroo/barcode/EANBarCode.py b/report_aeroo/barcode/EANBarCode.py deleted file mode 100644 index ad9c399b..00000000 --- a/report_aeroo/barcode/EANBarCode.py +++ /dev/null @@ -1,159 +0,0 @@ -# Copyright (c) 2009-2011 Alistek Ltd (http://www.alistek.com) All Rights Reserved. -# General contacts - -from openerp.tools import config, ustr -fontsize = 12 - -""" -This class generate EAN bar code, it required PIL (python imaging library) -installed. - -If the code has not checksum (12 digits), it added automatically. - -Create bar code sample : - from EANBarCode import EanBarCode - bar = EanBarCode() - bar.getImage("9782212110708",50,"gif") - -""" - -class EanBarCode: - """ Compute the EAN bar code """ - def __init__(self): - A = {0 : "0001101", 1 : "0011001", 2 : "0010011", 3 : "0111101", 4 : "0100011", - 5 : "0110001", 6 : "0101111", 7 : "0111011", 8 : "0110111", 9 : "0001011"} - B = {0 : "0100111", 1 : "0110011", 2 : "0011011", 3 : "0100001", 4 : "0011101", - 5 : "0111001", 6 : "0000101", 7 : "0010001", 8 : "0001001", 9 : "0010111"} - C = {0 : "1110010", 1 : "1100110", 2 : "1101100", 3 : "1000010", 4 : "1011100", - 5 : "1001110", 6 : "1010000", 7 : "1000100", 8 : "1001000", 9 : "1110100"} - self.groupC = C - - self.family = {0 : (A,A,A,A,A,A), 1 : (A,A,B,A,B,B), 2 : (A,A,B,B,A,B), 3 : (A,A,B,B,B,A), 4 : (A,B,A,A,B,B), - 5 : (A,B,B,A,A,B), 6 : (A,B,B,B,A,A), 7 : (A,B,A,B,A,B), 8 : (A,B,A,B,B,A), 9 : (A,B,B,A,B,A)} - - - def makeCode(self, code): - """ Create the binary code - return a string which contains "0" for white bar, "1" for black bar, "L" for long bar """ - - # Convert code string in integer list - self.EAN13 = [] - for digit in code: - self.EAN13.append(int(digit)) - - # If the code has already a checksum - if len(self.EAN13) == 13: - # Verify checksum - self.verifyChecksum(self.EAN13) - # If the code has not yet checksum - elif len(self.EAN13) == 12: - # Add checksum value - self.EAN13.append(self.computeChecksum(self.EAN13)) - - # Get the left codage class - left = self.family[self.EAN13[0]] - - # Add start separator - strCode = 'L0L' - - # Compute the left part of bar code - for i in range(0,6): - strCode += left[i][self.EAN13[i+1]] - - # Add middle separator - strCode += '0L0L0' - - # Compute the right codage class - for i in range (7,13): - strCode += self.groupC[self.EAN13[i]] - - # Add stop separator - strCode += 'L0L' - - return strCode - - - def computeChecksum(self, arg): - """ Compute the checksum of bar code """ - # UPCA/EAN13 - weight=[1,3]*6 - magic=10 - sum = 0 - - for i in range(12): # checksum based on first 12 digits. - sum = sum + int(arg[i]) * weight[i] - z = ( magic - (sum % magic) ) % magic - if z < 0 or z >= magic: - return None - return z - - - def verifyChecksum(self, bits): - """ Verify the checksum """ - computedChecksum = self.computeChecksum(bits[:12]) - codeBarChecksum = bits[12] - - if codeBarChecksum != computedChecksum: - raise Exception ("Bad checksum is %s and should be %s"%(codeBarChecksum, computedChecksum)) - - - def getImage(self, value, height = 50, xw=1, rotate=None, extension = "PNG"): - """ Get an image with PIL library - value code barre value - height height in pixel of the bar code - extension image file extension""" - from PIL import Image, ImageFont, ImageDraw - import os - from string import lower, upper - - # Get the bar code list - bits = self.makeCode(value) - - # Get thee bar code with the checksum added - code = "" - for digit in self.EAN13: - code += "%d"%digit - - # Create a new image - position = 8 - im = Image.new("L",(len(bits)+position,height+2)) - - # Load font - ad = os.path.abspath(os.path.join(ustr(config['root_path']), u'addons')) - mod_path_list = map(lambda m: os.path.abspath(ustr(m.strip())), config['addons_path'].split(',')) - mod_path_list.append(ad) - - for mod_path in mod_path_list: - font_file = mod_path+os.path.sep+ \ - "report_aeroo"+os.path.sep+"barcode"+os.path.sep+"FreeMonoBold.ttf"#"courB08.pil" - if os.path.lexists(font_file): - font = ImageFont.truetype(font_file, fontsize) - #font = ImageFont.load(font_file) - - # Create drawer - draw = ImageDraw.Draw(im) - - # Erase image - draw.rectangle(((0,0),(im.size[0],im.size[1])),fill=256) - - # Draw first part of number - draw.text((0, height-9), code[0], font=font, fill=0) - - # Draw first part of number - draw.text((position+3, height-9), code[1:7], font=font, fill=0) - - # Draw second part of number - draw.text((len(bits)/2+2+position, height-9), code[7:], font=font, fill=0) - - # Draw the bar codes - for bit in range(len(bits)): - # Draw normal bar - if bits[bit] == '1': - draw.rectangle(((bit+position,0),(bit+position,height-10)),fill=0) - # Draw long bar - elif bits[bit] == 'L': - draw.rectangle(((bit+position,0),(bit+position,height-3)),fill=0) - - # Save the result image - return im - diff --git a/report_aeroo/barcode/FreeMonoBold.ttf b/report_aeroo/barcode/FreeMonoBold.ttf deleted file mode 100644 index 3bce6129..00000000 Binary files a/report_aeroo/barcode/FreeMonoBold.ttf and /dev/null differ diff --git a/report_aeroo/barcode/barcode.py b/report_aeroo/barcode/barcode.py index 5bde0288..5a396ec1 100644 --- a/report_aeroo/barcode/barcode.py +++ b/report_aeroo/barcode/barcode.py @@ -29,34 +29,26 @@ # ############################################################################## -from code128 import get_code -from code39 import create_c39 -from EANBarCode import EanBarCode +from elaphe import barcode try: from cStringIO import StringIO except ImportError: from StringIO import StringIO + def make_barcode(code, code_type='ean13', rotate=None, height=50, xw=1): if code: - if code_type.lower()=='ean13': - bar=EanBarCode() - im = bar.getImage(code,height) - elif code_type.lower()=='code128': - im = get_code(code, xw, height) - elif code_type.lower()=='code39': - im = create_c39(height, xw, code) + im = barcode(code_type, code, scale=height) else: return StringIO(), 'image/png' tf = StringIO() try: - if rotate!=None: - im=im.rotate(int(rotate)) + if rotate is not None: + im = im.rotate(int(rotate)) except Exception, e: pass im.save(tf, 'png') size_x = str(im.size[0]/96.0)+'in' size_y = str(im.size[1]/96.0)+'in' return tf, 'image/png', size_x, size_y - diff --git a/report_aeroo/barcode/code128.py b/report_aeroo/barcode/code128.py deleted file mode 100644 index a6efb3fb..00000000 --- a/report_aeroo/barcode/code128.py +++ /dev/null @@ -1,185 +0,0 @@ -# Copyright (c) 2009-2011 Alistek Ltd (http://www.alistek.com) All Rights Reserved. -# General contacts -# This list was cut'n'pasted verbatim from the "Code 128 Specification Page" -# at http://www.adams1.com/pub/russadam/128code.html - -codelist="""0 SP SP 00 2 1 2 2 2 2 -1 ! ! 01 2 2 2 1 2 2 -2 " " 02 2 2 2 2 2 1 -3 # # 03 1 2 1 2 2 3 -4 $ $ 04 1 2 1 3 2 2 -5 % % 05 1 3 1 2 2 2 -6 & & 06 1 2 2 2 1 3 -7 ' ' 07 1 2 2 3 1 2 -8 ( ( 08 1 3 2 2 1 2 -9 ) ) 09 2 2 1 2 1 3 -10 * * 10 2 2 1 3 1 2 -11 + + 11 2 3 1 2 1 2 -12 , , 12 1 1 2 2 3 2 -13 - - 13 1 2 2 1 3 2 -14 . . 14 1 2 2 2 3 1 -15 / / 15 1 1 3 2 2 2 -16 0 0 16 1 2 3 1 2 2 -17 1 1 17 1 2 3 2 2 1 -18 2 2 18 2 2 3 2 1 1 -19 3 3 19 2 2 1 1 3 2 -20 4 4 20 2 2 1 2 3 1 -21 5 5 21 2 1 3 2 1 2 -22 6 6 22 2 2 3 1 1 2 -23 7 7 23 3 1 2 1 3 1 -24 8 8 24 3 1 1 2 2 2 -25 9 9 25 3 2 1 1 2 2 -26 : : 26 3 2 1 2 2 1 -27 ; ; 27 3 1 2 2 1 2 -28 < < 28 3 2 2 1 1 2 -29 = = 29 3 2 2 2 1 1 -30 > > 30 2 1 2 1 2 3 -31 ? ? 31 2 1 2 3 2 1 -32 @ @ 32 2 3 2 1 2 1 -33 A A 33 1 1 1 3 2 3 -34 B B 34 1 3 1 1 2 3 -35 C C 35 1 3 1 3 2 1 -36 D D 36 1 1 2 3 1 3 -37 E E 37 1 3 2 1 1 3 -38 F F 38 1 3 2 3 1 1 -39 G G 39 2 1 1 3 1 3 -40 H H 40 2 3 1 1 1 3 -41 I I 41 2 3 1 3 1 1 -42 J J 42 1 1 2 1 3 3 -43 K K 43 1 1 2 3 3 1 -44 L L 44 1 3 2 1 3 1 -45 M M 45 1 1 3 1 2 3 -46 N N 46 1 1 3 3 2 1 -47 O O 47 1 3 3 1 2 1 -48 P P 48 3 1 3 1 2 1 -49 Q Q 49 2 1 1 3 3 1 -50 R R 50 2 3 1 1 3 1 -51 S S 51 2 1 3 1 1 3 -52 T T 52 2 1 3 3 1 1 -53 U U 53 2 1 3 1 3 1 -54 V V 54 3 1 1 1 2 3 -55 W W 55 3 1 1 3 2 1 -56 X X 56 3 3 1 1 2 1 -57 Y Y 57 3 1 2 1 1 3 -58 Z Z 58 3 1 2 3 1 1 -59 [ [ 59 3 3 2 1 1 1 -60 \\ \\ 60 3 1 4 1 1 1 -61 ] ] 61 2 2 1 4 1 1 -62 ^ ^ 62 4 3 1 1 1 1 -63 _ _ 63 1 1 1 2 2 4 -64 NUL ' 64 1 1 1 4 2 2 -65 SOH a 65 1 2 1 1 2 4 -66 STX b 66 1 2 1 4 2 1 -67 ETX c 67 1 4 1 1 2 2 -68 EOT d 68 1 4 1 2 2 1 -69 ENQ e 69 1 1 2 2 1 4 -70 ACK f 70 1 1 2 4 1 2 -71 BEL g 61 1 2 2 1 1 4 -72 BS h 72 1 2 2 4 1 1 -73 HT i 73 1 4 2 1 1 2 -74 LF j 74 1 4 2 2 1 1 -75 VT k 75 2 4 1 2 1 1 -76 FF l 76 2 2 1 1 1 4 -77 CR m 77 4 1 3 1 1 1 -78 SO n 78 2 4 1 1 1 2 -79 SI o 79 1 3 4 1 1 1 -80 DLE p 80 1 1 1 2 4 2 -81 DC1 q 81 1 2 1 1 4 2 -82 DC2 r 82 1 2 1 2 4 1 -83 DC3 s 83 1 1 4 2 1 2 -84 DC4 t 84 1 2 4 1 1 2 -85 NAK u 85 1 2 4 2 1 1 -86 SYN v 86 4 1 1 2 1 2 -87 ETB w 87 4 2 1 1 1 2 -88 CAN x 88 4 2 1 2 1 1 -89 EM y 89 2 1 2 1 4 1 -90 SUB z 90 2 1 4 1 2 1 -91 ESC { 91 4 1 2 1 2 1 -92 FS | 92 1 1 1 1 4 3 -93 GS } 93 1 1 1 3 4 1 -94 RS ~ 94 1 3 1 1 4 1 -95 (Hex 7F) US DEL 95 1 1 4 1 1 3 -96 (Hex 80) FNC 3 FNC 3 96 1 1 4 3 1 1 -97 (Hex 81) FNC 2 FNC 2 97 4 1 1 1 1 3 -98 (Hex 82) SHIFT SHIFT 98 4 1 1 3 1 1 -99 (Hex 83) CODE C CODE C 99 1 1 3 1 4 1 -100 (Hex 84) CODE B FNC 4 CODE B 1 1 4 1 3 1 -101 (Hex 85) FNC 4 CODE A CODE A 3 1 1 1 4 1 -102 (Hex 86) FNC 1 FNC 1 FNC 1 4 1 1 1 3 1""" - - - - -other="""103 (Hex 87) START (Code A) 2 1 1 4 1 2 -104 (Hex 88) START (Code B) 2 1 1 2 1 4 -105 (Hex 89) START (Code C) 2 1 1 2 3 2 -106 STOP 2 3 3 1 1 1 2""" - - -codes={} -values={} -for l in codelist.split('\n'): - l.strip() - num,a1,b1,c1,code=l.split('\t') - num=int(num.split(' ')[0]) - values[num]=[int(x) for x in code.split()] - codes[b1.strip()]=num - -codes[' ']=codes['SP'] - -for l in other.split('\n'): - l.strip() - num,name,code=l.split('\t') - num=int(num.split(' ')[0]) - values[num]=[int(x) for x in code.split()] - codes[name.strip()]=num - -def encode_message(msg): - startnum=codes['START (Code B)'] - message=values[startnum][:] - chksum=startnum - mult=1 - for c in msg: - if not codes.has_key(c): - raise "No code for "+c - chksum=chksum+mult*codes[c] - mult=mult+1 - message=message+values[codes[c]] - - chksum=chksum%103 - - message=message+values[chksum] - message=message+values[codes['STOP']] - - return message - - -import os -from PIL import Image -def get_code(message,xw=1,h=100,rotate=None): - """ message is message to code. - xw is horizontal multiplier (in pixels width of narrowest bar) - h is height in pixels. - - Returns a Python Imaging Library object.""" - - widths=[xw*20]+encode_message(message)+[xw*20] - - bits=[] - i=1 - for w in widths: - bits=bits+[i]*w*xw - i=1-i - - #print len(bits) - #print bits - - i=Image.new('1',(len(bits),h),1) - - for b in range(len(bits)): - for y in range(h): - i.putpixel((b,y),255*bits[b]) - - return i - - diff --git a/report_aeroo/barcode/code39.py b/report_aeroo/barcode/code39.py deleted file mode 100644 index eb9bbe9a..00000000 --- a/report_aeroo/barcode/code39.py +++ /dev/null @@ -1,162 +0,0 @@ -# Copyright (c) 2008 marscel.wordpress.com -# -# Copyright (c) 2011 Alistek Ltd (http://www.alistek.com) All Rights Reserved. -# General contacts - -# Code39.py v1 -# Requires Python and Python Imaging Library (PIL), -# has been tested with Python v2.6 and PIL v1.1.6 - -# Usage example: -# code39.py 100 2 "Hello World" barcode.png -# -# This creates a PNG image "barcode.png" containing a barcode of the height of 100px -# a min line width of 2px with "Hello World" encoded as "*HELLO WORLD*" in Code 39 - -from PIL import Image, ImageDraw, ImageFont -from openerp.tools import config, ustr -import os, sys - -marginx = 10 -marginy = 10 -fontsize = 15 - -charmap = { -'*':[0,3,0,1,2,1,2,1,0], -'-':[0,3,0,1,0,1,2,1,2], -'$':[0,3,0,3,0,3,0,1,0], -'%':[0,1,0,3,0,3,0,3,0], -' ':[0,3,2,1,0,1,2,1,0], -'.':[2,3,0,1,0,1,2,1,0], -'/':[0,3,0,3,0,1,0,3,0], -'+':[0,3,0,1,0,3,0,3,0], -'0':[0,1,0,3,2,1,2,1,0], -'1':[2,1,0,3,0,1,0,1,2], -'2':[0,1,2,3,0,1,0,1,2], -'3':[2,1,2,3,0,1,0,1,0], -'4':[0,1,0,3,2,1,0,1,2], -'5':[2,1,0,3,2,1,0,1,0], -'6':[0,1,2,3,2,1,0,1,0], -'7':[0,1,0,3,0,1,2,1,2], -'8':[2,1,0,3,0,1,2,1,0], -'9':[0,1,2,3,0,1,2,1,0], -'A':[2,1,0,1,0,3,0,1,2], -'B':[0,1,2,1,0,3,0,1,2], -'C':[2,1,2,1,0,3,0,1,0], -'D':[0,1,0,1,2,3,0,1,2], -'E':[2,1,0,1,2,3,0,1,0], -'F':[0,1,2,1,2,3,0,1,0], -'G':[0,1,0,1,0,3,2,1,2], -'H':[2,1,0,1,0,3,2,1,0], -'I':[0,1,2,1,0,3,2,1,0], -'J':[0,1,0,1,2,3,2,1,0], -'K':[2,1,0,1,0,1,0,3,2], -'L':[0,1,2,1,0,1,0,3,2], -'M':[2,1,2,1,0,1,0,3,0], -'N':[0,1,0,1,2,1,0,3,2], -'O':[2,1,0,1,2,1,0,3,0], -'P':[0,1,2,1,2,1,0,3,0], -'Q':[0,1,0,1,0,1,2,3,2], -'R':[2,1,0,1,0,1,2,3,0], -'S':[0,1,2,1,0,1,2,3,0], -'T':[0,1,0,1,2,1,2,3,0], -'U':[2,3,0,1,0,1,0,1,2], -'V':[0,3,2,1,0,1,0,1,2], -'W':[2,3,2,1,0,1,0,1,0], -'X':[0,3,0,1,2,1,0,1,2], -'Y':[2,3,0,1,2,1,0,1,0], -'Z':[0,3,2,1,2,1,0,1,0] -} - -def create_c39(height, smallest, text): - pixel_length = 0 - i = 0 - newtext = "" - machinetext = "*" + text + "*" - seglist = [] - while i < len(machinetext): - char = machinetext[i].capitalize() - i = i + 1 - try: - cmap = charmap[char] - if len(cmap) != 9: - continue - - j = 0 - while j < 9: - seg = int(cmap[j]) - - if seg == 0 or seg == 1: - pixel_length = pixel_length + smallest - seglist.append(seg) - elif seg == 2 or seg == 3: - pixel_length = pixel_length + smallest * 3 - seglist.append(seg) - - j = j + 1 - - newtext += char - except: - continue - - pixel_length = pixel_length + 2*marginx + len(newtext) * smallest - pixel_height = height + 2*marginy + fontsize - - barcode_img = Image.new('RGB', [pixel_length, pixel_height], "white") - - if len(seglist) == 0: - return barcode_img - - i = 0 - draw = ImageDraw.Draw(barcode_img) - current_x = marginx - - while i < len(seglist): - seg = seglist[i] - color = (255, 255, 255) - wdth = smallest - - if seg == 0 or seg == 2: - color = 0 - if seg == 0: - wdth = smallest - else: - wdth = smallest * 3 - elif seg == 1 or seg == 3: - color = (255, 255, 255) - if seg == 1: - wdth = smallest - else: - wdth = smallest * 3 - - j = 1 - - while j <= wdth: - draw.line((current_x, marginy, current_x, marginy+height), fill=color) - current_x = current_x + 1 - j = j + 1 - - if ((i+1) % 9) == 0: - j = 1 - while j <= smallest: - draw.line((current_x, marginy, current_x, marginy+height), fill=(255,255,255)) - current_x = current_x + 1 - j = j + 1 - i = i + 1 - - ad = os.path.abspath(os.path.join(ustr(config['root_path']), u'addons')) - mod_path_list = map(lambda m: os.path.abspath(ustr(m.strip())), config['addons_path'].split(',')) - mod_path_list.append(ad) - - for mod_path in mod_path_list: - font_file = mod_path+os.path.sep+ \ - "report_aeroo"+os.path.sep+"barcode"+os.path.sep+"FreeMonoBold.ttf" - if os.path.lexists(font_file): - font = ImageFont.truetype(font_file, fontsize) - - draw.text((pixel_length/2 - len(newtext)*(fontsize/2)/2-len(newtext), height+fontsize), newtext, font=font, fill=0) - - del draw - - return barcode_img - diff --git a/report_aeroo/barcode/courB08.pbm b/report_aeroo/barcode/courB08.pbm deleted file mode 100755 index aedce1a3..00000000 Binary files a/report_aeroo/barcode/courB08.pbm and /dev/null differ diff --git a/report_aeroo/barcode/courB08.pil b/report_aeroo/barcode/courB08.pil deleted file mode 100755 index 28982c0f..00000000 Binary files a/report_aeroo/barcode/courB08.pil and /dev/null differ