[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r5972 - trunk/gnue-common/src/printing/barcodes
From: |
jcater |
Subject: |
r5972 - trunk/gnue-common/src/printing/barcodes |
Date: |
Mon, 12 Jul 2004 14:11:07 -0500 (CDT) |
Author: jcater
Date: 2004-07-12 14:11:06 -0500 (Mon, 12 Jul 2004)
New Revision: 5972
Modified:
trunk/gnue-common/src/printing/barcodes/Base.py
trunk/gnue-common/src/printing/barcodes/codabar.py
trunk/gnue-common/src/printing/barcodes/code39.py
trunk/gnue-common/src/printing/barcodes/interleaved2of5.py
trunk/gnue-common/src/printing/barcodes/postnet.py
trunk/gnue-common/src/printing/barcodes/standard2of5.py
Log:
* Added support for text below the barcode
* Only supports EPS at this time
* Made the EPS generation more efficient
* Add support/emulation for setstrokeadjust to make sure all lines are same
width
* I have tested Code 39 (I don't have a scanner capable of reading the
others...)
Modified: trunk/gnue-common/src/printing/barcodes/Base.py
===================================================================
--- trunk/gnue-common/src/printing/barcodes/Base.py 2004-07-12 13:41:25 UTC
(rev 5971)
+++ trunk/gnue-common/src/printing/barcodes/Base.py 2004-07-12 19:11:06 UTC
(rev 5972)
@@ -25,12 +25,13 @@
"""
"""
#
-import sys, os
+import sys, os, string
import Image, ImageDraw
class InvalidBarcode(StandardError):
pass
+
class Barcode:
mapping = {}
chars = []
@@ -40,15 +41,22 @@
spacing = ''
start = ''
stop = ''
+ defaultIncludeText = True
+ encodingMap = {
+ # Stroke?, X Multiplier, Y Multiplier
+ '0': (False, 1, 1),
+ '1': (True, 1, 1),
+ }
+
def checkdigit(self, value):
"""
Returns the checkdigit encoding for the given value
"""
return ''
- def calculateLineHeight(self, value, code):
+ def calculateLineHeight(self, width):
return self.lineHeight
def _buildBinary(self, value):
@@ -59,7 +67,7 @@
"""
if self.validLengths and len(value) not in self.validLengths:
- raise InvalidBarcode
+ raise InvalidBarcode, 'Barcode is not a valid length: Should be one of
%s' % self.validLengths
value = str(value)
rv = self.start + self.spacing
@@ -73,7 +81,7 @@
try:
rv += self.mapping[ch]
except KeyError:
- raise InvalidBarcode
+ raise InvalidBarcode, 'Barcode cannot contain "%s" character.' % ch
return rv + self.spacing + self.stop
@@ -82,76 +90,214 @@
###
###
def generate(self, value, stream=sys.stdout,
- format='postscript', dpi=300):
+ format='eps', includeText=None, textSize=7, dpi=300):
+ if includeText is None:
+ includeText = self.defaultIncludeText
code = self._buildBinary(value)
lineWidth = self.lineWidth
- lineHeight = self.calculateLineHeight(value, code)
+ try:
+ spaceWidth = self.spaceWidth
+ except:
+ spaceWidth = lineWidth
+ width = 0
+ for ch in code:
+ stroke, xmul, ymul = self.encodingMap[ch]
+ if stroke:
+ width += lineWidth*xmul
+ else:
+ width += spaceWidth*xmul
+
+ lineHeight = self.calculateLineHeight(width)
+
##
## Vector-based PS/EPS output
##
- if format in ("postscript",'eps'):
- # Special case for PostNet
- lineHeight2 = self.lineHeight*.4
+ if format in ('eps'):
# Write minimal EPS header
- if format == 'eps':
- stream.write('%!PS-Adobe-3.0 EPSF-3.0\n')
- stream.write('%%%%BoundingBox: 0 0 %s %s\n'% (
- int(lineWidth*(len(code)+1)+.5),int(lineHeight+.5)))
+ stream.write('%!PS-Adobe-3.0 EPSF-3.0\n')
+ stream.write('%%%%BoundingBox: 0 0 %s %s\n' % (width+1,
+ lineHeight+(includeText and ( textSize+2 ) or 1 )))
+ stream.write(psHeader)
# Initialize the graphics
- stream.write('gsave\n0 setgray\n%s setlinewidth\nnewpath\n0 0 moveto\n'
% lineWidth)
+ stream.write('gsave 0 setgray\n')
+ if includeText:
+ y = textSize + 1
+ else:
+ y = 0
+
+ strokes = {}
+
# Draw each bar
+ x = 0
for ch in code:
- if ch == '1':
- stream.write('0 %s rlineto %s -%s rmoveto\n' % (
- lineHeight, lineWidth, lineHeight))
+ stroke, xmul, ymul = self.encodingMap[ch]
+ dx = lineWidth*xmul
+ dy = lineHeight*ymul
+ if stroke:
- # Special case for PostNet as it is
- # height-sensitive, not width-sensitive
- elif ch == '2':
- stream.write('0 %s rlineto %s -%s rmoveto\n' % (
- lineHeight2, lineWidth, lineHeight2))
+ # So we won't cut off half the first bar...
+ if not x:
+ x = dx/2
+ # Store the strokes by their width, so we can
+ # more efficiently draw all the same-width lines
+ # at the same time.
+ try:
+ strks = strokes[dx]
+ except KeyError:
+ strks = strokes[dx] = []
+
+ # Draw the line
+ strks += ['%s %s Mt %s %s Lt' % (
+ x+dx/2, y, x+dx/2, y+dy)]
+ x += dx
else:
- stream.write('%s 0 rmoveto\n' % (
- lineWidth))
+ x += spaceWidth*xmul
- # Do the actual drawing, and cleanup
- stream.write('stroke\ngrestore\n')
+ # For each stroke, draw:
+ for stroke, set in strokes.items():
+ stream.write('%s setlinewidth newpath\n' % stroke)
+ stream.write(string.join(set,'\n'))
+ stream.write('\nstroke\n')
+ # Draw the text
+ if includeText:
+ stream.write('/Courier findfont %s scalefont setfont\n' % textSize)
+ stream.write('%s 0 moveto ' % (x/2))
+ stream.write('(%s) dup stringwidth pop 2 div neg 0 rmoveto show\n' %
value)
+ stream.write("grestore\n%%Trailer\n%%EOF\n")
+
+
##
## Raster-based output using PIL
##
- elif format in ('png','tiff','ppm','xbm'):
- lineWidth = int(lineWidth * dpi/72+.5) # 300dpi
- lineHeight = int(lineHeight * dpi/72+.5) # 300dpi
- # Special case for PostNet
- lineHeight2 = int(lineHeight * .4+.5)
+# elif format in ('png','tiff','ppm','xbm'):
+# lineWidth = int(lineWidth * dpi/72+.5) # 300dpi
+# lineHeight = int(lineHeight * dpi/72+.5) # 300dpi
+# # Special case for PostNet
+# lineHeight2 = int(lineHeight * .45+.5)
+#
+# # Create a new monochrome image with a white backgint
+# image = Image.new('1',(int(len(code)*lineWidth+.5),
+# int(lineHeight+.5)), 1)
+# draw = ImageDraw.Draw(image)
+# offs = 0
+# for ch in code:
+# if ch == '1':
+# draw.rectangle((offs,0,offs+lineWidth-1,lineHeight),
+# outline=0, fill=0)
+# # Special case for PostNet
+# elif ch == '2':
+# draw.rectangle((offs,0,offs+lineWidth-1,lineHeight2),
+# outline=0, fill=0)
+# offs += lineWidth
+#
+# image.save(stream, format)
- # Create a new monochrome image with a white backgint
- image = Image.new('1',(int(len(code)*lineWidth+.5),
- int(lineHeight+.5)), 1)
- draw = ImageDraw.Draw(image)
- offs = 0
- for ch in code:
- if ch == '1':
- draw.rectangle((offs,0,offs+lineWidth-1,lineHeight),
- outline=0, fill=0)
- # Special case for PostNet
- elif ch == '2':
- draw.rectangle((offs,0,offs+lineWidth-1,lineHeight2),
- outline=0, fill=0)
- offs += lineWidth
- image.save(stream, format)
+ # Line height is .15 * barcode width, but at least .25"
+ # This is used by Code39, Interleaved 2 of 5, etc
+ def _calculate15(self, width):
+ return max(18, .15 * width)
- # Line height is .15 * barcode width, but at least .25"
- # This is used by Code39, Interleaved 2 of 5, etc
- def _calculate15(self, value, code):
- return max(18, .15 * len(code) * self.lineWidth)
+
+##
+## This fun stuff emulates setstrokeadjust if not present.
+## This mode forces all lines of the same width to actually
+## print at the same width, at the expense of whitespace.
+## If printing at 600dpi or more, this likely won't make a different.
+## It could at 300dpi or less, though.
+##
+psHeader = """\
+%%EndComments
+%%BeginProlog
+% automatic stroke adjustment already available?
+/Level2|DPS /setstrokeadjust where {pop true} {false} ifelse def
+Level2|DPS not { save } if % remove procset if not needed
+Level2|DPS % def interface for Level 2
+{
+%%BeginResource: procset Adobe_SpecialGraphics_L2DPS 1.0 0
+/GRinit {} def
+/Mt /moveto load def
+/Lt /lineto load def
+/Ct /curveto load def
+/Rt /rectstroke load def
+/SA /setstrokeadjust load def
+%%EndResource
+} if
+Level2|DPS not { restore } if
+Level2|DPS { save }if % remove procset from VM if not
+% needed
+Level2|DPS not { % emulations are needed
+%%BeginResource: procset Adobe_SpecialGraphics_L1 1.0 0
+/GRdict 5 dict def
+GRdict begin
+/Mt /moveto load def
+/Lt /lineto load def
+/Ct /curveto load def
+/Rt { % x y w h Rt - basic rectangle
+4 -2 roll moveto % bottom left hand corner
+dup 0 exch rlineto % to upper left
+exch 0 rlineto % to upper right
+neg 0 exch rlineto % to lower right
+closepath
+} bind def
+/SA { % true,false SA - enable/disable stroke adjustment
+{ mark countdictstack 2 sub
+{currentdict GRdict eq {SAdict begin exit}
+{currentdict end} ifelse} repeat
+counttomark {begin} repeat pop}
+{ mark countdictstack 2 sub
+{currentdict SAdict eq {end exit} {currentdict end} ifelse
+}
+repeat counttomark {begin} repeat pop
+} ifelse
+} bind def
+end % GRdict
+/GRinit { % put GRdict on stack under userdict
+countdictstack array dictstack cleardictstack
+dup 0 GRdict put { begin} forall
+} bind def
+/SAdict 10 dict def
+SAdict begin
+% snap user space location to device space pixel
+/snaptopixel { % x y snaptopixel sx sy
+transform
+.25 sub round .25 add exch
+.25 sub round .25 add exch
+itransform
+} bind def
+/Mt { % x y Mt - moveto
+snaptopixel moveto
+} bind def
+/Lt { % x y Lt - lineto
+snaptopixel lineto
+} bind def
+/Ct { % x1 y1 x2 y2 x3 y3 Ct - curveto
+snaptopixel curveto
+} bind def % note control points are not snapped
+/Rt { % x y w h Rt - basic rectangle
+4 -2 roll Mt % bottom left hand corner
+dtransform round exch round exch idtransform
+dup 0 exch rlineto % to upper left
+exch 0 rlineto % to upper right
+neg 0 exch rlineto % to lower right
+closepath
+} bind def
+end % SAdict
+%%EndResource
+} if
+Level2|DPS { restore }if
+%%EndProlog
+%%BeginSetup
+GRinit
+true SA
+%%EndSetup
+"""
Modified: trunk/gnue-common/src/printing/barcodes/codabar.py
===================================================================
--- trunk/gnue-common/src/printing/barcodes/codabar.py 2004-07-12 13:41:25 UTC
(rev 5971)
+++ trunk/gnue-common/src/printing/barcodes/codabar.py 2004-07-12 19:11:06 UTC
(rev 5972)
@@ -31,29 +31,38 @@
class Codabar(Barcode):
chars = '0123456789-$:/.+'
mapping = {
- '0': '10101001100',
- '1': '10101100100',
- '2': '10100101100',
- '3': '11001010100',
- '4': '10110100100',
- '5': '11010100100',
- '6': '10010101100',
- '7': '10010110100',
- '8': '10011010100',
- '9': '11010010100',
- '-': '10100110100',
- '$': '10110010100',
- ':': '110101101100',
- '/': '110110101100',
- '.': '110110110100',
- '+': '10110011001100'
+ '0': 'NnNnNwWn',
+ '1': 'NnNnWwNn',
+ '2': 'NnNwNnWn',
+ '3': 'WwNnNnNn',
+ '4': 'NnWnNwNn',
+ '5': 'WnNnNwNn',
+ '6': 'NwNnNnWn',
+ '7': 'NwNnWnNn',
+ '8': 'NwWnNnNn',
+ '9': 'WnNwNnNn',
+ '-': 'NnNwWnNn',
+ '$': 'NnWwNnNn',
+ ':': 'WnNnWnWn',
+ '/': 'WnWnNnWn',
+ '.': 'WnWnWnNn',
+ '+': 'NnWwWwWn'
}
- start = '100100101100'
- stop = '1010011001'
+ start = 'NwNwNnWn'
+ stop = 'nnNwWwN'
- calculateLineHeight = Barcode._calculate15
+ lineWidth = .72 # points (1.0mil)
+ lineHeight = 18 # 1/4"
+ encodingMap = {
+ # Stroke?, X Multiplier, Y Multiplier
+ 'n': (False, 1, 1), # Narrow Spaces
+ 'w': (False, 2.5, 1), # Wide Spaces
+ 'N': (True, 1, 1), # Narrow bars
+ 'W': (True, 2.5, 1) # Wide bars
+ }
+
if __name__ == '__main__':
codabar = Codabar()
@@ -63,7 +72,6 @@
codabar.generate(value,f, format)
f.close()
- test('0123456789-$:/.+','png','test1.png')
- test('+./:$-9876543210','tiff','test1.tif')
- test('+./:$-9876543210','postscript','test1.ps')
- test('0123456789-$:/.+','eps','test1.eps')
+# test('0123456789-$:/.+','png','test1.png')
+# test('+./:$-9876543210','tiff','test1.tif')
+ test('0123456789-$:/.+','eps','codabar-1.eps')
Modified: trunk/gnue-common/src/printing/barcodes/code39.py
===================================================================
--- trunk/gnue-common/src/printing/barcodes/code39.py 2004-07-12 13:41:25 UTC
(rev 5971)
+++ trunk/gnue-common/src/printing/barcodes/code39.py 2004-07-12 19:11:06 UTC
(rev 5972)
@@ -14,9 +14,9 @@
# You should have received a copy of the GNU General Public
# License along with program; see the file COPYING. If not,
# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
+# - Suite 330, Boston, MA 02W1-1307, USA.
#
-# Copyright 2004 Free Software Foundation
+# Copyright 2w4 Free Software Foundation
#
# FILE:
# barcodes/code39.py
@@ -35,57 +35,65 @@
"""
chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'
mapping = {
- '0': '1010011011010',
- '1': '1101001010110',
- '2': '1011001010110',
- '3': '1101100101010',
- '4': '1010011010110',
- '5': '1101001101010',
- '6': '1011001101010',
- '7': '1010010110110',
- '8': '1101001011010',
- '9': '1011001011010',
- 'A': '1101010010110',
- 'B': '1011010010110',
- 'C': '1101101001010',
- 'D': '1010110010110',
- 'E': '1101011001010',
- 'F': '1011011001010',
- 'G': '1010100110110',
- 'H': '1101010011010',
- 'I': '1011010011010',
- 'J': '1010110011010',
- 'K': '1101010100110',
- 'L': '1011010100110',
- 'M': '1101101010010',
- 'N': '1010110100110',
- 'O': '1101011010010',
- 'P': '1011011010010',
- 'Q': '1010101100110',
- 'R': '1101010110010',
- 'S': '1011010110010',
- 'T': '1010110110010',
- 'U': '1100101010110',
- 'V': '1001101010110',
- 'W': '1100110101010',
- 'X': '1001011010110',
- 'Y': '1100101101010',
- 'Z': '1001101101010',
- '-': '1001010110110',
- '.': '1100101011010',
- ' ': '1001101011010',
- '$': '1001001010010',
- '/': '1001001010010',
- '+': '1001010010010',
- '%': '1010010010010',
+ '0': 'NnNwWnWnNn',
+ '1': 'WnNwNnNnWn',
+ '2': 'NnWwNnNnWn',
+ '3': 'WnWwNnNnNn',
+ '4': 'NnNwWnNnWn',
+ '5': 'WnNwWnNnNn',
+ '6': 'NnWwWnNnNn',
+ '7': 'NnNwNnWnWn',
+ '8': 'WnNwNnWnNn',
+ '9': 'NnWwNnWnNn',
+ 'A': 'WnNnNwNnWn',
+ 'B': 'NnWnNwNnWn',
+ 'C': 'WnWnNwNnNn',
+ 'D': 'NnNnWwNnWn',
+ 'E': 'WnNnWwNnNn',
+ 'F': 'NnWnWwNnNn',
+ 'G': 'NnNnNwWnWn',
+ 'H': 'WnNnNwWnNn',
+ 'I': 'NnWnNwWnNn',
+ 'J': 'NnNnWwWnNn',
+ 'K': 'WnNnNnNwWn',
+ 'L': 'NnWnNnNwWn',
+ 'M': 'WnWnNnNwNn',
+ 'N': 'NnNnWnNwWn',
+ 'O': 'WnNnWnNwNn',
+ 'P': 'NnWnWnNwNn',
+ 'Q': 'NnNnNnWwWn',
+ 'R': 'WnNnNnWwNn',
+ 'S': 'NnWnNnWwNn',
+ 'T': 'NnNnWnWwNn',
+ 'U': 'WwNnNnNnWn',
+ 'V': 'NwWnNnNnWn',
+ 'W': 'WwWnNnNnNn',
+ 'X': 'NwNnWnNnWn',
+ 'Y': 'WwNnWnNnNn',
+ 'Z': 'NwWnWnNnNn',
+ '-': 'NwNnNnWnWn',
+ '.': 'WwNnNnWnNn',
+ ' ': 'NwWnNnWnNn',
+ '$': 'NwNwNnNwNn',
+ '/': 'NwNwNnNwNn',
+ '+': 'NwNnNwNwNn',
+ '%': 'NnNwNwNwNn',
}
- start= '1001011011010'
- stop = '100101101101'
+ start= 'NwNnWnWnNn'
+ stop = 'NwNnWnWnN'
- lineWidth = .72 # points (1.0mil)
+ lineWidth = .6 # points (1.0mil)
lineHeight = 18 # Actually dependent on the width
+ encodingMap = {
+ # Stroke?, X Multiplier, Y Multiplier
+ 'n': (False, 1, 1), # Narrow Spaces
+ 'w': (False, 2.1, 1), # Wide Spaces
+ 'N': (True, 1, 1), # Narrow bars
+ 'W': (True, 2.1, 1) # Wide bars
+ }
+
calculateLineHeight = Barcode._calculate15
@@ -102,7 +110,7 @@
v = 0
for ch in value:
v += self.chars.index(ch)
- return self.mapping[self.chars[divmod(chv,43)[1]]]
+ return self.chars[divmod(chv,43)[1]]
if __name__ == '__main__':
@@ -114,7 +122,9 @@
code39.generate(value,f, format)
f.close()
- test('0123456789ABCDEF','png','test1.png')
- test('0123456789ABCDEF','tiff','test1.tif')
- test('0123456789','postscript','test1.ps')
- test('0123456789ABCDEF','eps','test1.eps')
+# test('0123456789ABCDEF','png','test1.png')
+# test('0123456789ABCDEF','tiff','test1.tif')
+ test('0123456789ABCDEF','eps','code39-1.eps')
+ test('GHIJKLMNOPQRSTUV','eps','code39-2.eps')
+ test('WXYZ-. $/+%','eps','code39-3.eps')
+ test('FI123456789','eps','code39-4.eps')
Modified: trunk/gnue-common/src/printing/barcodes/interleaved2of5.py
===================================================================
--- trunk/gnue-common/src/printing/barcodes/interleaved2of5.py 2004-07-12
13:41:25 UTC (rev 5971)
+++ trunk/gnue-common/src/printing/barcodes/interleaved2of5.py 2004-07-12
19:11:06 UTC (rev 5972)
@@ -46,12 +46,20 @@
'9': 'NWNWN'
}
- lineWidth = .54 # points (7.5mil)
+ lineWidth = .6 # points (7.5mil)
lineHeight = 18 # Actually dependent on the width
- start = '1010'
- stop = '1101'
+ start = 'NnNn'
+ stop = 'WnN'
+ encodingMap = {
+ # Stroke?, X Multiplier, Y Multiplier
+ 'n': (False, 1, 1), # Narrow Spaces
+ 'w': (False, 2.5, 1), # Wide Spaces
+ 'N': (True, 1, 1), # Narrow bars
+ 'W': (True, 2.5, 1) # Wide bars
+ }
+
calculateLineHeight = Barcode._calculate15
# Since this is interleaved, we do
@@ -74,19 +82,13 @@
for i in range(len(value)/2):
try:
bar = self.mapping[value[i]]
- space = self.mapping[value[i+1]]
+ space = self.mapping[value[i+1]].lower()
except KeyError:
raise InvalidBarcode
for j in xrange(5):
- if bar[j] == 'W':
- rv += '11'
- else:
- rv += '1'
- if space[j] == 'W':
- rv += '00'
- else:
- rv += '0'
+ rv += bar[j]
+ rv += space[j]
return rv + self.stop
@@ -100,7 +102,7 @@
testbar.generate(value,f, format)
f.close()
- test('0123456789','png','test1.png')
- test('9876543210','tiff','test1.tif')
- test('9876543210','postscript','test1.ps')
- test('0123456789','eps','test1.eps')
+# test('0123456789','png','test1.png')
+# test('9876543210','tiff','test1.tif')
+ test('0123456789','eps','i2of5-1.eps')
+ test('9876543210','eps','i2of5-1.eps')
Modified: trunk/gnue-common/src/printing/barcodes/postnet.py
===================================================================
--- trunk/gnue-common/src/printing/barcodes/postnet.py 2004-07-12 13:41:25 UTC
(rev 5971)
+++ trunk/gnue-common/src/printing/barcodes/postnet.py 2004-07-12 19:11:06 UTC
(rev 5972)
@@ -36,6 +36,7 @@
validLengths = [5,9,11]
chars = '0123456789'
mapping = {
+ # 1 = tall bar, 2=short bar, 0=space
'0': '1010202020',
'1': '2020201010',
'2': '2020102010',
@@ -51,9 +52,21 @@
start = '10'
stop = '1'
- lineWidth = 1.44 # points (.02")
- lineHeight = 9 # (.125")
+ lineWidth = 1.44 # points
+ lineHeight = 8.5 # (.125")
+ spaceWidth = 1.66
+ encodingMap = {
+ # Stroke?, X Multiplier, Y Multiplier
+ '0': (False, 1, 1), # Spaces
+ '1': (True, 1, 1), # Tall bars
+ '2': (True, 1, .45) # Short bars
+ }
+
+
+
+ defaultIncludeText = False
+
# Calculate a Mod-10 check digit
def checkdigit(self, value):
v = 0
@@ -62,7 +75,7 @@
v += int(ch)
except ValueError:
raise InvalidBarcode
- return self.mapping[self.chars[divmod(v,10)[1]]]
+ return self.chars[divmod(v,10)[1]]
if __name__ == '__main__':
@@ -74,7 +87,8 @@
postnet.generate(value,f, format)
f.close()
- test('381072456','png','test1.png')
- test('381172459','tiff','test1.tif')
- test('381072456','postscript','test1.ps')
- test('381072456','eps','test1.eps')
+# test('381072456','png','test1.png')
+# test('381172459','tiff','test1.tif')
+ test('123456789','eps','postnet-1.eps')
+ test('12345','eps','postnet-2.eps')
+ test('12345678901','eps','postnet-3.eps')
Modified: trunk/gnue-common/src/printing/barcodes/standard2of5.py
===================================================================
--- trunk/gnue-common/src/printing/barcodes/standard2of5.py 2004-07-12
13:41:25 UTC (rev 5971)
+++ trunk/gnue-common/src/printing/barcodes/standard2of5.py 2004-07-12
19:11:06 UTC (rev 5972)
@@ -32,24 +32,34 @@
class Standard2of5(Barcode):
chars = '0123456789'
mapping = {
- '0': '10101110111010',
- '1': '11101010101110',
- '2': '10111010101110',
- '3': '11101110101010',
- '4': '10101110101110',
- '5': '11101011101010',
- '6': '10111011101010',
- '7': '10101011101110',
- '8': '11101010111010',
- '9': '10111010111010'
+ '0': 'N0N0W0W0N0',
+ '1': 'W0N0N0N0W0',
+ '2': 'N0W0N0N0W0',
+ '3': 'W0W0N0N0N0',
+ '4': 'N0N0W0N0W0',
+ '5': 'W0N0W0N0N0',
+ '6': 'N0W0W0N0N0',
+ '7': 'N0N0N0W0W0',
+ '8': 'W0N0N0W0N0',
+ '9': 'N0W0N0W0N0'
}
- start = '11011010'
- stop = '1101011'
+ start = '0M0N0'
+ stop = 'M0N0M'
- calculateLineHeight = Barcode._calculate15
+ encodingMap = {
+ # Stroke?, X Multiplier, Y Multiplier
+ '0': (False, 1, 1), # Narrow Spaces
+ 'N': (True, 1, 1), # Narrow bars
+ 'M': (True, 2, 1), # Medium bars
+ 'W': (True, 3, 1) # Wide bars
+ }
+ # calculateLineHeight = Barcode._calculate15 # Unsure of this
+ lineWidth = 1 # points -- Unsure of this
+ lineHeight = 18 # Actually dependent on the width
+
if __name__ == '__main__':
testbar = Standard2of5()
@@ -59,7 +69,6 @@
testbar.generate(value,f, format)
f.close()
- test('0123456789','png','test1.png')
- test('9876543210','tiff','test1.tif')
- test('9876543210','postscript','test1.ps')
- test('0123456789','eps','test1.eps')
+# test('0123456789','png','test1.png')
+# test('9876543210','tiff','test1.tif')
+ test('0123456789','eps','s2of5-1.eps')
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r5972 - trunk/gnue-common/src/printing/barcodes,
jcater <=