3
% Barcode Writer in Pure PostScript
4
% http://www.terryburton.co.uk/barcodewriter/
6
% Copyright (c) 2004-2014 Terry Burton
10
% Permission is hereby granted, free of charge, to any
11
% person obtaining a copy of this software and associated
12
% documentation files (the "Software"), to deal in the
13
% Software without restriction, including without
14
% limitation the rights to use, copy, modify, merge,
15
% publish, distribute, sublicense, and/or sell copies of
16
% the Software, and to permit persons to whom the Software
17
% is furnished to do so, subject to the following
20
% The above copyright notice and this permission notice
21
% shall be included in all copies or substantial portions
24
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
25
% KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
26
% THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
27
% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28
% THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
29
% DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
30
% CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31
% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
34
% --BEGIN ENCODER code39--
35
% --REQUIRES preamble raiseerror renlinear--
37
% --EXAM: THIS IS CODE 39
38
% --EXOP: includetext includecheck includecheckintext
40
/setpacking where {pop currentpacking true setpacking} if
42
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
43
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
47
20 dict begin % Confine variables to local scope
49
/options exch def % We are given an option string
50
/barcode exch def % We are given a barcode string
53
/includecheck false def
54
/validatecheck false def
55
/includetext false def
56
/includecheckintext false def
58
/textfont /Courier def
63
% Parse the input options
64
options type /stringtype eq {
67
token false eq {exit} if dup length string cvs (=) search
68
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
70
currentdict end /options exch def
74
/textfont textfont cvlit def
75
/textsize textsize cvr def
76
/textyoffset textyoffset cvr def
77
/height height cvr def
79
% Create a string of the available characters
80
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
82
0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
85
0 1 barcode length 1 sub {
86
barcode exch 1 getinterval charvals exch known not {
87
/bwipp.code39badCharacter (Code 39 must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
91
/barlen barcode length validatecheck {1 sub} if def
95
barcode exch 1 getinterval charvals exch get
96
checksum add /checksum exch def
98
/checksum checksum 43 mod def
100
barcode barlen get barchars checksum get ne {
101
/bwipp.code39badCheckDigit (Incorrect Code 39 check digit provided) //raiseerror exec
103
/barcode barcode 0 barlen getinterval def
104
/includecheck true def
107
% Create an array containing the character mappings
109
[ (1113313111) (3113111131) (1133111131) (3133111111) (1113311131)
110
(3113311111) (1133311111) (1113113131) (3113113111) (1133113111)
111
(3111131131) (1131131131) (3131131111) (1111331131) (3111331111)
112
(1131331111) (1111133131) (3111133111) (1131133111) (1111333111)
113
(3111111331) (1131111331) (3131111311) (1111311331) (3111311311)
114
(1131311311) (1111113331) (3111113311) (1131113311) (1111313311)
115
(3311111131) (1331111131) (3331111111) (1311311131) (3311311111)
116
(1331311111) (1311113131) (3311113111) (1331113111) (1313131111)
117
(1313111311) (1311131311) (1113131311) (1311313111)
120
/sbs barlen includecheck {3} {2} ifelse add 10 mul string def
121
/txt barlen includecheck {3} {2} ifelse add array def
123
% Put the start character
124
sbs 0 encs 43 get putinterval
126
txt 0 [(*) 0 textyoffset textfont textsize] put
128
txt 0 [() 0 textyoffset textfont textsize] put
133
/indx charvals barcode i 1 getinterval get def
134
sbs i 10 mul 10 add encs indx get putinterval
135
txt i 1 add [barcode i 1 getinterval i 1 add 16 mul textyoffset textfont textsize] put
138
% Put the checksum and end characters
140
sbs barlen 10 mul 10 add encs checksum get putinterval
142
txt barlen 1 add [barchars checksum 1 getinterval barlen 1 add 16 mul textyoffset textfont textsize] put
144
txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put
146
sbs barlen 10 mul 20 add encs 43 get putinterval
148
txt barlen 2 add [(*) barlen 2 add 16 mul textyoffset textfont textsize] put
150
txt barlen 2 add [() barlen 2 add 16 mul textyoffset textfont textsize] put
153
sbs barlen 10 mul 10 add encs 43 get putinterval
155
txt barlen 1 add [(*) barlen 1 add 16 mul textyoffset textfont textsize] put
157
txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put
161
% Return the arguments
164
/sbs [sbs {48 sub} forall]
165
/bhs [sbs length 1 add 2 idiv {height} repeat]
166
/bbs [sbs length 1 add 2 idiv {0} repeat]
173
dontdraw not //renlinear if
178
/code39 dup load /uk.co.terryburton.bwipp defineresource pop
180
/setpacking where {pop setpacking} if
181
% --END ENCODER code39--