~ubuntu-branches/debian/experimental/inkscape/experimental

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'''
 
2
Copyright (C) 2007 Martin Owens
 
3
 
 
4
Thanks to Lineaire Chez of Inkbar ( www.inkbar.lineaire.net )
 
5
 
 
6
This program is free software; you can redistribute it and/or modify
 
7
it under the terms of the GNU General Public License as published by
 
8
the Free Software Foundation; either version 2 of the License, or
 
9
(at your option) any later version.
 
10
 
 
11
This program is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with this program; if not, write to the Free Software
 
18
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
'''
 
20
 
 
21
import EAN13
 
22
from EAN13 import mapLeftFaimly, guardBar, centerBar, mapRight
 
23
import sys
 
24
 
 
25
class Object(EAN13.Object):
 
26
        def encode(self, number):
 
27
                result = ''
 
28
 
 
29
                if len(number) < 11 or len(number) > 12 or not number.isdigit():
 
30
                        sys.stderr.write("Can not encode '" + number + "' into UPC-A Barcode, Size must be 11 numbers only, and 1 check digit (optional).\n")
 
31
                        return
 
32
 
 
33
                if len(number) == 11:
 
34
                        number = number + self.getChecksum(number)
 
35
                else:
 
36
                        if not self.varifyChecksum(number):
 
37
                                sys.stderr.write("EAN13 Checksum not correct for this barcode, omit last charicter to generate new checksum.\n")
 
38
                                return
 
39
 
 
40
                result = result + guardBar
 
41
 
 
42
                i = 0
 
43
                for i in range(0,6):
 
44
                        result += mapLeftFaimly[0][int(number[i])]
 
45
 
 
46
                result += centerBar
 
47
 
 
48
                for i in range (6,12):
 
49
                        result += mapRight[int(number[i])]
 
50
 
 
51
                result = result + guardBar;
 
52
 
 
53
                self.label    = number[0] + '   ' + number[1:6] + '    ' + number[6:11] + '   ' + number[11]
 
54
                self.inclabel = self.label
 
55
                return result;
 
56
 
 
57
        def fontSize(self):
 
58
                return '10'