-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathcode93.ps.src
172 lines (151 loc) · 5.41 KB
/
code93.ps.src
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
% Barcode Writer in Pure PostScript
% https://bwipp.terryburton.co.uk
%
% Copyright (c) 2004-2024 Terry Burton
%
% $Id$
%
% Permission is hereby granted, free of charge, to any
% person obtaining a copy of this software and associated
% documentation files (the "Software"), to deal in the
% Software without restriction, including without
% limitation the rights to use, copy, modify, merge,
% publish, distribute, sublicense, and/or sell copies of
% the Software, and to permit persons to whom the Software
% is furnished to do so, subject to the following
% conditions:
%
% The above copyright notice and this permission notice
% shall be included in all copies or substantial portions
% of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
% KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
% THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
% THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
% DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
% CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
% IN THE SOFTWARE.
% --BEGIN ENCODER code93--
% --REQUIRES preamble loadctx unloadctx raiseerror processoptions parseinput renlinear--
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /loadctx dup /uk.co.terryburton.bwipp findresource put
dup /unloadctx dup /uk.co.terryburton.bwipp findresource put
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /processoptions dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {
20 dict begin % Confine variables to local scope
/ctx null def
/dontdraw false def
/includecheck false def % Enable/disable checkdigit
/includetext false def % Enable/disable text
/textfont /Courier def
/textsize 10.0 def
/textyoffset -7.0 def
/height 1.0 def
/parse false def
/parsefnc false def
//processoptions exec /options exch def
/barcode exch def
/code93 //loadctx exec
{
/encs
[ (131112) (111213) (111312) (111411) (121113) % 0-4
(121212) (121311) (111114) (131211) (141111) % 5-9
(211113) (211212) (211311) (221112) (221211) % A-E
(231111) (112113) (112212) (112311) (122112) % F-J
(132111) (111123) (111222) (111321) (121122) % K-O
(131121) (212112) (212211) (211122) (211221) % P-T
(221121) (222111) (112122) (112221) (122121) % U-Y
(123111) (121131) (311112) (311211) (321111) % "Z" "-" "." " " "$"
(112131) (113121) (211131) (121221) (312111) % "/" "+" "%" ($) (%)
(311121) (122211) (111141) (1111411) % (/) (+) STA END
] def
% Create a string of the available characters
/barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
/charvals 47 dict def
0 1 42 {charvals exch dup barchars exch get exch put} for
/sft1 -1 def /sft2 -2 def /sft3 -3 def /sft4 -4 def
charvals sft1 43 put
charvals sft2 44 put
charvals sft3 45 put
charvals sft4 46 put
} ctxdef
% Special function characters
/fncvals <<
/parse parse
/parsefnc parsefnc
(SFT$) sft1
(SFT%) sft2
(SFT/) sft3
(SFT+) sft4
>> def
/msg barcode fncvals //parseinput exec def
/msglen msg length def
% Validate the input
msg {
charvals exch known not {
/bwipp.code93BadCharacter (Code 93 must only contain digits, capital letters, spaces, the symbols -.$/+ and shift non-data characters) //raiseerror exec
} if
} forall
includecheck {
/sbs msglen 6 mul 25 add string def
} {
/sbs msglen 6 mul 13 add string def
} ifelse
/txt msglen array def
% Put the start character
sbs 0 encs 47 get putinterval
/checksum1 0 def /checksum2 0 def
0 1 msglen 1 sub {
/i exch def
/indx charvals msg i get get def
sbs i 6 mul 6 add encs indx get putinterval
/char msg i get dup 0 lt { pop ( ) } { 1 string dup 0 4 -1 roll put } ifelse def
txt i [char i 9 mul 9 add textyoffset textfont textsize] put
/checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
/checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
} for
includecheck {
% Put the first checksum character
/checksum1 checksum1 47 mod def
/checksum2 checksum2 checksum1 add 47 mod def
sbs msglen 6 mul 6 add encs checksum1 get putinterval
sbs msglen 6 mul 12 add encs checksum2 get putinterval
% Put the end character
sbs msglen 6 mul 18 add encs 48 get putinterval
} {
% Put the end character
sbs msglen 6 mul 6 add encs 48 get putinterval
} ifelse
% Return the arguments
<<
/ren /renlinear
/sbs [sbs {48 sub} forall]
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
includetext {
/txt txt
} if
/opt options
>>
dontdraw not //renlinear if
//unloadctx exec
end
}
[/barcode] {null def} forall
bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --END ENCODER code93--