-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathbc412.ps.src
230 lines (207 loc) · 7.27 KB
/
bc412.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
% 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 bc412--
% --REQUIRES preamble loadctx unloadctx raiseerror processoptions renlinear--
% --DESC: BC412
% --EXAM: BC412SEMI
% --EXOP: semi includetext includecheckintext
% --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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/bc412 {
20 dict begin % Confine variables to local scope
/ctx null def
/dontdraw false def
/includecheck false def
/validatecheck false def
/includetext false def
/includecheckintext false def
/includestartstop false def
/semi false def
/textfont /Courier def
/textsize 10.0 def
/textyoffset -7.0 def
/height 1.0 def
//processoptions exec /options exch def
/barcode exch def
barcode () eq {
/bwipp.bc412emptyData (The data must not be empty) //raiseerror exec
} if
semi {
% Implies includecheck and includecheckintext also
/includestartstop true def
} if
/bc412 //loadctx exec
% Create a string of the available characters
{
/barchars (0R9GLVHA8EZ4NTS1J2Q6C7DYKBUIX3FWP5M) def
/charvals 35 dict def
0 1 34 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef
% Validate the input
0 1 barcode length 1 sub {
barcode exch 1 getinterval charvals exch known not {
/bwipp.bc412badCharacter (BC412 must contain only digits and capital letters except O) //raiseerror exec
} if
} for
semi {
% Validate length
validatecheck {
barcode length 8 lt barcode length 19 gt or {
/bwipp.bc412semivalidateBadLength (BC412 semi with check digit must be 8 to 19 characters long) //raiseerror exec
} if
} {
barcode length 7 lt barcode length 18 gt or {
/bwipp.bc412semiBadLength (BC412 semi must be 7 to 18 characters long) //raiseerror exec
} if
} ifelse
/barlen barcode length def
validatecheck not { % Place dummy (0) in checksum position (1-based 2nd)
/barlen barlen 1 add def
/sbarcode barlen string def
sbarcode 0 barcode 0 get put
sbarcode 1 48 put % (0)
sbarcode 2 barcode 1 barlen 2 sub getinterval putinterval
/barcode sbarcode def
} if
/sumodd 0 def /sumeven 0 def
0 1 barlen 1 sub {
/i exch def
barcode i 1 getinterval charvals exch get
i 2 mod 0 eq { % 1-based odd
sumodd add /sumodd exch def
} {
sumeven add /sumeven exch def
} ifelse
} for
/checksum sumodd 35 mod sumeven 35 mod 2 mul add 35 mod def % F = Mod35( Mod35( Fodd ) + 2 * Mod35( Feven ) )
validatecheck {
checksum 0 ne {
/bwipp.bc412semiBadCheckDigit (Incorrect BC412 semi check digit provided) //raiseerror exec
} if
} {
/checksum checksum 17 mul 35 mod def % CD = Mod35( 17 * F )
barcode 1 barchars checksum get put
} ifelse
} {
/barlen barcode length validatecheck {1 sub} if def
/checksum 0 def
0 1 barlen 1 sub {
barcode exch 1 getinterval charvals exch get
checksum add /checksum exch def
} for
/checksum checksum 35 mod def
validatecheck {
barcode barlen get barchars checksum get ne {
/bwipp.bc412badCheckDigit (Incorrect BC412 check digit provided) //raiseerror exec
} if
/barcode barcode 0 barlen getinterval def
/includecheck true def
} if
} ifelse
% Create an array containing the character mappings
{
/encs
[ (11111115) (13111212) (11131113) (12111213) (12121311) % 0R9GL
(13131111) (12111312) (11131212) (11121411) (11151111) % VHA8E
(15111111) (11111511) (12131211) (13121112) (13111311) % Z4NTS
(11111214) (12121113) (11111313) (13111113) (11121213) % 1J2Q6
(11141112) (11121312) (11141211) (14121111) (12121212) % C7DYK
(11131311) (13121211) (12111411) (14111211) (11111412) % BUIX3
(12111114) (14111112) (12141111) (11121114) (12131112) % FWP5M
(12) (111) % Start Stop
] def
} ctxdef
/sbs barlen 1 add 8 mul 5 add string def
includecheck {
/txt barlen 1 add array def
} {
/txt barlen array def
} ifelse
% Put the start character
includestartstop {
sbs 0 encs 35 get putinterval
/pos 2 def
/txtpos 3.0 def
} {
/pos 0 def
/txtpos 0.0 def
} ifelse
0 1 barlen 1 sub {
/i exch def
/indx charvals barcode i 1 getinterval get def
sbs pos encs indx get putinterval
txt i [barcode i 1 getinterval i 12 mul txtpos add textyoffset textfont textsize] put
/pos pos 8 add def
} for
% Put the checksum
includecheck {
sbs pos encs checksum get putinterval
includecheckintext {
txt barlen [barchars checksum 1 getinterval barlen 12 mul txtpos add textyoffset textfont textsize] put
} {
txt barlen [() barlen 12 mul txtpos add textyoffset textfont textsize] put
} ifelse
/pos pos 8 add def
} if
% Put the stop character
includestartstop {
sbs pos encs 36 get putinterval
/pos pos 3 add def
} if
% Return the arguments
/sbs sbs 0 pos getinterval def
<<
/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
/bc412 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --END ENCODER bc412--