15d189daaab0518f5405baf3e16d7c10852c1ef3
1 #!/usr/bin/env python
2 '''
3 Copyright (C) 2007 Martin Owens
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
20 '''
22 import EAN13
23 from EAN13 import mapLeftFaimly, guardBar, centerBar, mapRight
24 import sys
26 class Object(EAN13.Object):
27 def encode(self, number):
28 result = ''
30 if len(number) < 11 or len(number) > 12 or not number.isdigit():
31 sys.stderr.write("Can not encode '" + number + "' into UPC-A Barcode, Size must be 11 numbers only, and 1 check digit (optional).\n")
32 return
34 if len(number) == 11:
35 number = number + self.getChecksum(number)
36 else:
37 if not self.verifyChecksum(number):
38 sys.stderr.write("UPC-A Checksum not correct for this barcode, omit last character to generate new checksum.\n")
39 return
41 result = result + guardBar
43 i = 0
44 for i in range(0,6):
45 result += mapLeftFaimly[0][int(number[i])]
47 result += centerBar
49 for i in range (6,12):
50 result += mapRight[int(number[i])]
52 result = result + guardBar;
54 self.label = number[0] + ' ' + number[1:6] + ' ' + number[6:11] + ' ' + number[11]
55 self.inclabel = self.label
56 return result;
58 def fontSize(self):
59 return '10'