1 #
2 # Copyright (C) 2009 Aaron C Spike
3 # 2010 Martin Owens
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #
19 """
20 Python barcode renderer for EAN5 barcodes. Designed for use with Inkscape.
21 """
23 from BaseEan import EanBarcode
25 FAMS = [ '11000','10100','10010','10001','01100','00110','00011','01010','01001','00101' ]
26 START = '01011'
28 class Object(EanBarcode):
29 """Provide an Ean5 barcode generator"""
30 name = 'ean5'
31 length = 5
33 def _encode(self, number):
34 self.x += 110.0 # horiz offset so it does not overlap EAN13
35 self.y -= self.height + 5 # move the text to the top
36 self.label = ' '.join(self.space(number))
37 family = sum([int(n)*int(m) for n,m in zip(number, '39393')]) % 10
38 return START + '01'.join(self.encode_interleaved(family, number, FAMS))