2
Copyright (C) 2007 Martin Owens
3
Copyright (C) 2009 Aaron C Spike
5
Thanks to Lineaire Chez of Inkbar ( www.inkbar.lineaire.net )
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
from Base import Barcode
26
[ "0001101","0011001","0010011","0111101","0100011","0110001","0101111","0111011","0110111","0001011" ], #L
27
[ "0100111","0110011","0011011","0100001","0011101","0111001","0000101","0010001","0001001","0010111" ], #G
29
mapFamily = [ '11000','10100','10010','10001','01100','00110','00011','01010','01001','00101' ]
34
class Object(Barcode):
35
def encode(self, number):
37
self.x += 110.0 # horizontal offset so it does not overlap EAN13
38
self.y -= self.height + 5 # move the text to the top
39
if len(number) != 5 or not number.isdigit():
40
sys.stderr.write("Can not encode '" + number + "' into EAN5 Barcode, Size must be 5 numbers only\n")
43
check = self.getChecksum(number)
44
family = mapFamily[check]
47
mapLeft = mapLeftFamily[int(family[i])]
48
result.append(mapLeft[int(number[i])])
50
self.label = number[0]
52
self.label += ' ' + number[i]
53
self.inclabel = self.label
54
return startBar + '01'.join(result)
56
def getChecksum(self, number):
57
return sum([int(n)*int(m) for n,m in zip(number, '39393')]) % 10
59
def getStyle(self, index):
60
result = { 'width' : '1', 'top' : int(self.y) + self.height + 5 + int(self.fontSize()), 'write' : True }
61
if index==0: # White Space
62
result['write'] = False
63
elif index==1: # Black Bar
64
result['height'] = int(self.height)
65
elif index==2: # Guide Bar
66
result['height'] = int(self.height) + 5