~ubuntu-branches/ubuntu/precise/inkscape/precise-updates

« back to all changes in this revision

Viewing changes to share/extensions/Barcode/EAN5.py

  • Committer: Bazaar Package Importer
  • Author(s): Alex Valavanis
  • Date: 2010-09-12 19:44:58 UTC
  • mfrom: (1.1.12 upstream) (45.1.3 maverick)
  • Revision ID: james.westby@ubuntu.com-20100912194458-4sjwmbl7dlsrk5dc
Tags: 0.48.0-1ubuntu1
* Merge with Debian unstable (LP: #628048, LP: #401567, LP: #456248, 
  LP: #463602, LP: #591986)
* debian/control: 
  - Ubuntu maintainers
  - Promote python-lxml, python-numpy, python-uniconvertor to Recommends.
  - Demote pstoedit to Suggests (universe package).
  - Suggests ttf-dejavu instead of ttf-bitstream-vera (LP: #513319)
* debian/rules:
  - Run intltool-update on build (Ubuntu-specific).
  - Add translation domain to .desktop files (Ubuntu-specific).
* debian/dirs:
  - Add usr/share/pixmaps.  Allow inkscape.xpm installation
* drop 50-poppler-API.dpatch (now upstream)
* drop 51-paste-in-unwritable-directory.dpatch (now upstream) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
''' 
 
2
Copyright (C) 2007 Martin Owens 
 
3
Copyright (C) 2009 Aaron C Spike 
 
4
 
 
5
Thanks to Lineaire Chez of Inkbar ( www.inkbar.lineaire.net ) 
 
6
 
 
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. 
 
11
 
 
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. 
 
16
 
 
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
'''
 
21
 
 
22
from Base import Barcode
 
23
import sys
 
24
 
 
25
mapLeftFamily = [
 
26
    [ "0001101","0011001","0010011","0111101","0100011","0110001","0101111","0111011","0110111","0001011" ], #L
 
27
    [ "0100111","0110011","0011011","0100001","0011101","0111001","0000101","0010001","0001001","0010111" ], #G
 
28
]
 
29
mapFamily  = [ '11000','10100','10010','10001','01100','00110','00011','01010','01001','00101' ]
 
30
 
 
31
startBar = '01011';
 
32
sepBar = '01';
 
33
 
 
34
class Object(Barcode):
 
35
    def encode(self, number):
 
36
        result = []
 
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")
 
41
            return
 
42
 
 
43
        check = self.getChecksum(number)
 
44
        family = mapFamily[check]
 
45
 
 
46
        for i in range(5):
 
47
            mapLeft = mapLeftFamily[int(family[i])]
 
48
            result.append(mapLeft[int(number[i])])
 
49
 
 
50
        self.label = number[0]
 
51
        for i in range(1,5):
 
52
            self.label += ' ' + number[i]
 
53
        self.inclabel = self.label
 
54
        return startBar + '01'.join(result)
 
55
 
 
56
    def getChecksum(self, number):
 
57
        return sum([int(n)*int(m) for n,m in zip(number, '39393')]) % 10
 
58
 
 
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
 
67
        return result