-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathdatabarlimited.ps.src
323 lines (293 loc) · 9.13 KB
/
databarlimited.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
% 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 databarlimited--
% --REQUIRES preamble loadctx unloadctx raiseerror processoptions renlinear--
% --DESC: GS1 DataBar Limited
% --EXAM: (01)09521234543213
% --EXOP:
% --RNDR: renlinear
/setpacking where {pop currentpacking true setpacking} if
20 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
/databarlimited {
20 dict begin % Confine variables to local scope
/ctx null def
/dontdraw false def
/height 10.0 72 div def
/linkage false def
//processoptions exec /options exch def
/barcode exch def
/databarlimited //loadctx exec
% Validate the input
barcode length 17 ne barcode length 18 ne and {
/bwipp.databarlimitedBadLength (GS1 DataBar Limited must be 13 or 14 digits) //raiseerror exec
} if
barcode 0 4 getinterval (\(01\)) ne {
/bwipp.databarlimitedBadAI (GS1 DataBar Limited must begin with (01) application identifier) //raiseerror exec
} if
barcode 4 get dup 48 lt exch 49 gt or {
/bwipp.databarlimitedBadStartDigit (GS1 DataBar Limited must begin with 0 or 1) //raiseerror exec
} if
barcode 5 barcode length 5 sub getinterval {
dup 48 lt exch 57 gt or {
/bwipp.databarlimitedBadCharacter (GS1 DataBar Limited must contain only digits) //raiseerror exec
} if
} forall
% Calculate checksum and add to end of barcode
/checksum 0 def
0 1 12 {
/i exch def
/checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def
} for
/checksum 10 checksum 10 mod sub 10 mod def
barcode length 18 eq {
barcode 17 get checksum 48 add ne {
/bwipp.databarlimitedBadCheckDigit (Incorrect GS1 DataBar Limited check digit provided) //raiseerror exec
} if
} if
18 string
dup 0 barcode putinterval
dup 17 checksum 48 add put
/barcode exch def
% Strip the AI and optional check digit
{
/linkval [ 2 0 1 5 1 3 3 5 3 1 0 9 6 ] def
} ctxdef
/binval [
barcode 4 13 getinterval {48 sub} forall
] def
linkage {
0 1 binval length 1 sub {
/i exch def
binval i binval i get linkval i get add put
} for
} if
% Create the human readable text
/txt barcode length array def
0 1 barcode length 1 sub {
/i exch def
txt i [barcode i 1 getinterval 0 0 () 0] put
} for
/ncr { % n r
2 copy sub 2 copy lt {exch} if % n r maxd mind
1 1 5 3 roll % mind j=1 v=1 n maxd
1 add -1 exch { % mind j v n -1 maxd+1
mul % mind j v*i
1 index 3 index le {
1 index idiv exch 1 add exch
} if
} for
{ % mind j v
1 index 3 index gt {exit} if
1 index idiv exch 1 add exch
} loop
exch pop exch pop
} def
/getRSSwidths {
/oe exch def
/el exch def
/mw exch def
/nm exch def
/val exch def
/out el array def
/mask 0 def
0 1 el 2 sub {
/bar exch def
/ew 1 def
/mask mask 1 bar bitshift or def {
/sval nm ew sub 1 sub el bar sub 2 sub ncr def
oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and {
/sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def
} if
el bar sub 2 gt {
/lval 0 def
nm ew sub el sub bar add 2 add -1 mw 1 add {
nm exch sub ew sub 1 sub el bar sub 3 sub ncr
/lval exch lval add def
} for
/sval sval lval el bar sub 1 sub mul sub def
} {
nm ew sub mw gt {/sval sval 1 sub def} if
} ifelse
/val val sval sub def
val 0 lt {exit} if
/ew ew 1 add def
/mask mask 1 bar bitshift not and def
} loop
/val val sval add def
/nm nm ew sub def
out bar ew put
} for
out el 1 sub nm put
out
} def
0 1 11 {
/i exch def
binval i 1 add 2 copy get binval i get 2013571 mod 10 mul add put
binval i binval i get 2013571 idiv put
} for
/d2 binval 12 get 2013571 mod def
binval 12 2 copy get 2013571 idiv put
/d1 0 def
/i true def
0 1 12 {
/j exch def
binval j get
dup 0 eq i and {
pop
} {
/i false def
/d1 d1 3 -1 roll 10 12 j sub exp cvi mul add def
} ifelse
} for
{
/tab267 [
183063 0 17 9 6 3 6538 28
820063 183064 13 13 5 4 875 728
1000775 820064 9 17 3 6 28 6454
1491020 1000776 15 11 5 4 2415 203
1979844 1491021 11 15 4 5 203 2408
1996938 1979845 19 7 8 1 17094 1
2013570 1996939 7 19 1 8 1 16632
] def
} ctxdef
/i 0 def {
d1 tab267 i get le {
tab267 i 1 add 7 getinterval aload pop
/d1te exch def /d1to exch def
/d1mwe exch def /d1mwo exch def
/d1ele exch def /d1elo exch def
/d1gs exch def
exit
} if
/i i 8 add def
} loop
/i 0 def {
d2 tab267 i get le {
tab267 i 1 add 7 getinterval aload pop
/d2te exch def /d2to exch def
/d2mwe exch def /d2mwo exch def
/d2ele exch def /d2elo exch def
/d2gs exch def
exit
} if
/i i 8 add def
} loop
/d1wo d1 d1gs sub d1te idiv d1elo d1mwo 7 false getRSSwidths def
/d1we d1 d1gs sub d1te mod d1ele d1mwe 7 true getRSSwidths def
/d2wo d2 d2gs sub d2te idiv d2elo d2mwo 7 false getRSSwidths def
/d2we d2 d2gs sub d2te mod d2ele d2mwe 7 true getRSSwidths def
/d1w 14 array def
0 1 6 {
/i exch def
d1w i 2 mul d1wo i get put
d1w i 2 mul 1 add d1we i get put
} for
/d2w 14 array def
0 1 6 {
/i exch def
d2w i 2 mul d2wo i get put
d2w i 2 mul 1 add d2we i get put
} for
/widths [
d1w aload pop
d2w aload pop
] def
{
/checkweights [
1 3 9 27 81 65 17 51 64 14 42 37 22 66
20 60 2 6 18 54 73 41 34 13 39 28 84 74
] def
/checkseq [
0 1 43 {} for
45 52 57
63 1 66 {} for
73 1 79 {} for
82
126 1 130 {} for
132
141 1 146 {} for
210 1 217 {} for
220
316 1 320 {} for
322 323
326 337
] def
} ctxdef
/checksum 0 def
0 1 27 {
/i exch def
/checksum checksum widths i get checkweights i get mul add def
} for
/checksum checksum 89 mod def
/seq checkseq checksum get def
/swidths seq 21 idiv 8 3 6 false getRSSwidths def
/bwidths seq 21 mod 8 3 6 false getRSSwidths def
/checkwidths [0 0 0 0 0 0 0 0 0 0 0 0 1 1] def
0 1 5 {
/i exch def
checkwidths i 2 mul swidths i get put
checkwidths i 2 mul 1 add bwidths i get put
} for
/sbs [
1
d1w aload pop
checkwidths aload pop
d2w aload pop
1 1 5
] def
% Return the arguments
<<
/ren /renlinear
/sbs sbs
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
/txt txt
/textxalign (center)
/borderleft 0.0
/borderright 0.0
/opt options
>>
dontdraw not //renlinear if
//unloadctx exec
end
}
[/barcode] {null def} forall
bind def
/databarlimited dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --END ENCODER databarlimited--