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 code93--
35
% --REQUIRES preamble raiseerror renlinear--
37
% --EXAM: THIS IS CODE 93
38
% --EXOP: includetext includecheck
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 % Enable/disable checkdigit
54
/includetext false def % Enable/disable text
55
/textfont /Courier def
61
% Parse the input options
62
options type /stringtype eq {
65
token false eq {exit} if dup length string cvs (=) search
66
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
68
currentdict end /options exch def
72
/textfont textfont cvlit def
73
/textsize textsize cvr def
74
/textyoffset textyoffset cvr def
75
/height height cvr def
78
[ (131112) (111213) (111312) (111411) (121113)
79
(121212) (121311) (111114) (131211) (141111)
80
(211113) (211212) (211311) (221112) (221211)
81
(231111) (112113) (112212) (112311) (122112)
82
(132111) (111123) (111222) (111321) (121122)
83
(131121) (212112) (212211) (211122) (211221)
84
(221121) (222111) (112122) (112221) (122121)
85
(123111) (121131) (311112) (311211) (321111)
86
(112131) (113121) (211131) (121221) (312111)
87
(311121) (122211) (111141) (1111411)
90
% Create a string of the available characters
91
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
93
/barlen barcode length def
95
% Special function characters
96
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
104
% Convert input into bytes accounting for shift characters
105
/msg barlen array def
107
i barlen eq {exit} if
108
/char barcode i get def
109
parsefnc char 94 eq and i barlen 4 sub lt and {
110
barcode i 1 add get 94 ne {
111
/char fncvals barcode i 1 add 4 getinterval get def
121
/msg msg 0 j getinterval def
122
/msglen msg length def
125
/sbs msglen 6 mul 25 add string def
127
/sbs msglen 6 mul 13 add string def
129
/txt msglen array def
131
% Put the start character
132
sbs 0 encs 47 get putinterval
134
/checksum1 0 def /checksum2 0 def
137
% Lookup the encoding for the each barcode character
139
42 exch sub /indx exch def
142
1 string dup 0 4 -1 roll put /char exch def
144
pop % Discard true leaving pre
145
length /indx exch def % indx is the length of pre
146
pop pop % Discard seek and post
148
/enc encs indx get def % Get the indxth encoding
149
sbs i 6 mul 6 add enc putinterval % Put encoded digit into sbs
150
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
151
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
152
/checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
156
% Put the first checksum character
157
/checksum1 checksum1 47 mod def
158
/checksum2 checksum2 checksum1 add 47 mod def
159
sbs msglen 6 mul 6 add encs checksum1 get putinterval
160
sbs msglen 6 mul 12 add encs checksum2 get putinterval
161
% Put the end character
162
sbs msglen 6 mul 18 add encs 48 get putinterval
164
% Put the end character
165
sbs msglen 6 mul 6 add encs 48 get putinterval
168
% Return the arguments
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
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
187
/setpacking where {pop setpacking} if
188
% --END ENCODER code93--