~ubuntu-branches/ubuntu/utopic/inkscape/utopic-proposed

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/share/extensions/Barcode/Code39Ext.py

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'''
 
2
Copyright (C) 2007 Martin Owens
 
3
 
 
4
This program is free software; you can redistribute it and/or modify
 
5
it under the terms of the GNU General Public License as published by
 
6
the Free Software Foundation; either version 2 of the License, or
 
7
(at your option) any later version.
 
8
 
 
9
This program is distributed in the hope that it will be useful,
 
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
GNU General Public License for more details.
 
13
 
 
14
You should have received a copy of the GNU General Public License
 
15
along with this program; if not, write to the Free Software
 
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
'''
 
18
 
 
19
import Code39
 
20
 
 
21
encode = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
 
22
 
 
23
map = {}
 
24
 
 
25
i = 0
 
26
for char in encode:
 
27
        map[char] = i
 
28
        i = i + 1
 
29
 
 
30
# Extended encoding maps for full ASCII Code93
 
31
def getMap(array):
 
32
        result = {}
 
33
        y = 0
 
34
        for x in array:
 
35
                result[chr(x)] = encode[y]
 
36
                y = y + 1
 
37
 
 
38
        return result;
 
39
 
 
40
# MapA is eclectic, but B, C, D are all ASCII ranges
 
41
mapA = getMap([27,28,29,30,31,59,60,61,62,63,91,92,93,94,95,123,124,125,126,127,0,64,96,127,127,127]) # %
 
42
mapB = getMap(range(1, 26)) # $
 
43
mapC = getMap(range(33, 58)) # /
 
44
mapD = getMap(range(97, 122)) # +
 
45
 
 
46
class Object(Code39.Object):
 
47
        def encode(self, text):
 
48
                # We are only going to extend the Code39 barcodes
 
49
                result = ''
 
50
                for char in text:
 
51
                        if mapA.has_key(char):
 
52
                                char = '%' + mapA[char]
 
53
                        elif mapB.has_key(char):
 
54
                                char = '$' + mapB[char]
 
55
                        elif mapC.has_key(char):
 
56
                                char = '/' + mapC[char]
 
57
                        elif mapD.has_key(char):
 
58
                                char = '+' + mapD[char]
 
59
                        result = result + char
 
60
 
 
61
                return Code39.Object.encode(self, result);
 
62