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 bc412--
35
% --REQUIRES preamble raiseerror renlinear--
38
% --EXOP: semi includetext 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
57
/includestartstop false def
59
/textfont /Courier def
64
% Parse the input options
65
options type /stringtype eq {
68
token false eq {exit} if dup length string cvs (=) search
69
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
71
currentdict end /options exch def
75
/textfont textfont cvlit def
76
/textsize textsize cvr def
77
/textyoffset textyoffset cvr def
78
/height height cvr def
81
/includecheck true def
82
/includestartstop true def
85
% Create a string of the available characters
86
/barchars (0R9GLVHA8EZ4NTS1J2Q6C7DYKBUIX3FWP5M) def
88
0 1 34 {charvals exch dup barchars exch 1 getinterval exch put} for
91
0 1 barcode length 1 sub {
92
barcode exch 1 getinterval charvals exch known not {
93
/bwipp.bc412badCharacter (BC412 must contain only digits and capital letters except O) //raiseerror exec
97
/barlen barcode length validatecheck {1 sub} if def
101
barcode exch 1 getinterval charvals exch get
102
checksum add /checksum exch def
104
/checksum checksum 35 mod def
106
barcode barlen get barchars checksum get ne {
107
/bwipp.bc412badCheckDigit (Incorrect BC412 check digit provided) //raiseerror exec
109
/barcode barcode 0 barlen getinterval def
110
/includecheck true def
113
% Create an array containing the character mappings
115
[ (11111115) (13111212) (11131113) (12111213) (12121311)
116
(13131111) (12111312) (11131212) (11121411) (11151111)
117
(15111111) (11111511) (12131211) (13121112) (13111212)
118
(11111214) (12121113) (11111313) (13111113) (11121213)
119
(11141112) (11121312) (11141211) (14121111) (12121212)
120
(11131311) (13121211) (12111411) (14111211) (11111412)
121
(12111114) (14111112) (12141111) (11121114) (12131112)
125
/sbs barlen 1 add 8 mul 5 add string def
127
/txt barlen 1 add array def
129
/txt barlen array def
132
% Put the start character
134
sbs 0 encs 35 get putinterval
144
/indx charvals barcode i 1 getinterval get def
145
sbs pos encs indx get putinterval
146
txt i [barcode i 1 getinterval i 12 mul txtpos add textyoffset textfont textsize] put
152
sbs pos encs checksum get putinterval
154
txt barlen [barchars checksum 1 getinterval barlen 12 mul txtpos add textyoffset textfont textsize] put
156
txt barlen [() barlen 12 mul txtpos add textyoffset textfont textsize] put
161
% Put the stop character
163
sbs pos encs 36 get putinterval
167
% Return the arguments
168
/sbs sbs 0 pos getinterval def
171
/sbs [sbs {48 sub} forall]
172
/bhs [sbs length 1 add 2 idiv {height} repeat]
173
/bbs [sbs length 1 add 2 idiv {0} repeat]
180
dontdraw not //renlinear if
185
/bc412 dup load /uk.co.terryburton.bwipp defineresource pop
187
/setpacking where {pop setpacking} if
188
% --END ENCODER bc412--