1ef3c8b1b935901dd133c337031a7300334db424JazzyNico#
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# Copyright (C) 2007 Martin Owens
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico#
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# This program is free software; you can redistribute it and/or modify
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# it under the terms of the GNU General Public License as published by
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# the Free Software Foundation; either version 2 of the License, or
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# (at your option) any later version.
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico#
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# This program is distributed in the hope that it will be useful,
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# but WITHOUT ANY WARRANTY; without even the implied warranty of
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# GNU General Public License for more details.
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico#
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# You should have received a copy of the GNU General Public License
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico# along with this program; if not, write to the Free Software
107e00c8104649437b9520d0ba298dba659e7cd7JazzyNico# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico#
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico"""
1ef3c8b1b935901dd133c337031a7300334db424JazzyNicoPython barcode renderer for Code39 Extended barcodes. Designed for Inkscape.
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico"""
040e298be5b23e77e33309d65449072183c82d5cacspike
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owensfrom Code39 import Code39
040e298be5b23e77e33309d65449072183c82d5cacspike
040e298be5b23e77e33309d65449072183c82d5cacspikeencode = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
040e298be5b23e77e33309d65449072183c82d5cacspike
040e298be5b23e77e33309d65449072183c82d5cacspikemap = {}
040e298be5b23e77e33309d65449072183c82d5cacspike
040e298be5b23e77e33309d65449072183c82d5cacspikei = 0
040e298be5b23e77e33309d65449072183c82d5cacspikefor char in encode:
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico map[char] = i
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico i = i + 1
040e298be5b23e77e33309d65449072183c82d5cacspike
040e298be5b23e77e33309d65449072183c82d5cacspike# Extended encoding maps for full ASCII Code93
040e298be5b23e77e33309d65449072183c82d5cacspikedef getMap(array):
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico result = {}
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico y = 0
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico for x in array:
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico result[chr(x)] = encode[y]
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico y = y + 1
040e298be5b23e77e33309d65449072183c82d5cacspike
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico return result;
040e298be5b23e77e33309d65449072183c82d5cacspike
040e298be5b23e77e33309d65449072183c82d5cacspike# MapA is eclectic, but B, C, D are all ASCII ranges
040e298be5b23e77e33309d65449072183c82d5cacspikemapA = 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]) # %
040e298be5b23e77e33309d65449072183c82d5cacspikemapB = getMap(range(1, 26)) # $
040e298be5b23e77e33309d65449072183c82d5cacspikemapC = getMap(range(33, 58)) # /
040e298be5b23e77e33309d65449072183c82d5cacspikemapD = getMap(range(97, 122)) # +
040e298be5b23e77e33309d65449072183c82d5cacspike
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owensclass Code39Ext(Code39):
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico def encode(self, text):
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico # We are only going to extend the Code39 barcodes
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico result = ''
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico for char in text:
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico if mapA.has_key(char):
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico char = '%' + mapA[char]
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico elif mapB.has_key(char):
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico char = '$' + mapB[char]
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico elif mapC.has_key(char):
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico char = '/' + mapC[char]
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico elif mapD.has_key(char):
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico char = '+' + mapD[char]
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico result = result + char
1ef3c8b1b935901dd133c337031a7300334db424JazzyNico
12a239f8730c2bb6e3738d5e75b3237877594d07Martin Owens return Code39.encode(self, result);
040e298be5b23e77e33309d65449072183c82d5cacspike