Repository navigation
Expand file tree
/
Copy pathcode11.ps.src
More file actions
282 lines (242 loc) · 8.77 KB
/
Copy pathcode11.ps.src
File metadata and controls
282 lines (242 loc) · 8.77 KB
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
% Barcode Writer in Pure PostScript
% https://bwipp.terryburton.co.uk
%
% vim: set sw=4 sts=4 et:
%
% Copyright (c) 2004-2026 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 code11--
% --REQUIRES preamble raiseerror setuphooks processoptions setanycolor render renlinear--
% --DESC: Code 11
% --EXAM: 0123456789
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
% --FMLY: Less-used Symbols
currentglobal
true setglobal
/setpacking where {pop currentpacking true setpacking} if
9 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /processoptions dup /uk.co.terryburton.bwipp findresource put
dup /render dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code11.encs [
(111131) (311131) (131131) (331111) (113131)
(313111) (133111) (111331) (311311) (311111)
(113111) (113311)
] readonly def
/code11.barchars (0123456789-) readonly def
/code11.latevars dup 2 dict def load /init {
currentglobal
true setglobal
//code11.latevars begin
/charvals 11 dict def
0 1 10 {
charvals exch dup //code11.barchars exch 1 getinterval exch put
} for
/charvals charvals readonly def
/init { //code11.latevars {def} forall } def
end
//code11.latevars /init get exec
setglobal
} bind put
/uk.co.terryburton.bwipp.global_ctx dup where {
exch get /preload known {//code11.latevars /init get exec} if
} {pop} ifelse
/code11 {
37 dict begin
{
/dontdraw false def
/includecheck false def
/validatecheck false def
/numcheckdigits 2 def
/includetext false def
/includecheckintext false def
/text1font /Courier def
/text1size 10.0 def
/text1yoffset -7.0 def
/height -1.0 def
/width 0 def
/propspec false def
/loosespec false def
/strictspec false def
/mag 1.0 def
/xdim -1.0 def
/hdim -1.0 def
/ast (default) def
/xmin -1.0 def /xnom -1.0 def /xmax -1.0 def
/hnom -1.0 def
/modunit 1 def
{null /apply //processoptions exec} stopped {pop stop} if
/options exch def
/global_encoder_defaults //render exec
/barcode exch def
/_render
dontdraw /uk.co.terryburton.bwipp.global_ctx dup where {exch get /enabledontdraw known} {pop false} ifelse and
/uk.co.terryburton.bwipp._dontdraw dup where {exch get} {pop false} ifelse or not
def
//code11.latevars /init get exec
barcode () eq {
/bwipp.code11emptyData (The data must not be empty) //raiseerror exec
} if
barcode length 500 gt {
/bwipp.code11inputTooLong (The input data is too long) //raiseerror exec
} if
%
% Validate the input
%
0 1 barcode length 1 sub {
barcode exch 1 getinterval charvals exch known not {
/bwipp.code11badCharacter (Code 11 must contain only digits and dashes) //raiseerror exec
} if
} for
%
% Apply AST spec overrides and resolve physical specification
%
/code11 ast /apply_ast //render exec not { //raiseerror exec } if
/resolve_strictspec //render exec
numcheckdigits 1 ne numcheckdigits 2 ne and {
/bwipp.code11badNumCheckDigits (The number of check digits must be 1 or 2) //raiseerror exec
} if
/barlen barcode length def
validatecheck {
barlen numcheckdigits lt {
/bwipp.code11badLength (The data is shorter than its check digits) //raiseerror exec
} if
/barlen barlen numcheckdigits sub def
} if
% Code 11 is designed to use two check digits; some scanners accept one for up to 10 characters
includecheck validatecheck or numcheckdigits 1 eq and barlen 10 gt and {
/bwipp.code11oneCheckDigitTooLong (One check digit is only for data of up to 10 characters) //raiseerror exec
} if
/numchecks includecheck validatecheck or {numcheckdigits} {0} ifelse def
/checksum1 0 def /checksum2 0 def
0 1 barlen 1 sub {
/i exch def
/indx charvals barcode i 1 getinterval get def
/checksum1 checksum1 barlen i sub 1 sub 10 mod 1 add indx mul add def
/checksum2 checksum2 barlen i sub 9 mod 1 add indx mul add def
} for
/checksum1 checksum1 11 mod def
/checksum2 checksum2 checksum1 add 11 mod def
validatecheck {
numchecks 1 eq {
barcode barlen get //code11.barchars checksum1 get ne {
/bwipp.code11badCheckDigit
[ (Incorrect Code 11 check digit provided: expected ) //code11.barchars checksum1 1 getinterval (, not ) barcode barlen 1 getinterval ]
dup 0 exch {length add} forall string
exch 0 exch { dup length 2 index add 3 index 4 2 roll putinterval } forall pop
//raiseerror exec
} if
} {
barcode barlen get //code11.barchars checksum1 get ne
barcode barlen 1 add get //code11.barchars checksum2 get ne or {
/bwipp.code11badCheckDigits
[ (Incorrect Code 11 check digits provided: expected ) //code11.barchars checksum1 1 getinterval //code11.barchars checksum2 1 getinterval (, not ) barcode barlen 2 getinterval ]
dup 0 exch {length add} forall string
exch 0 exch { dup length 2 index add 3 index 4 2 roll putinterval } forall pop
//raiseerror exec
} if
} ifelse
/barcode barcode 0 barlen getinterval def
/includecheck true def
} {
includecheck {
/checkdigit numchecks string
dup 0 //code11.barchars checksum1 get put
numchecks 2 eq { dup 1 //code11.barchars checksum2 get put } if
/report //render exec
} if
} ifelse
/sbs barlen numchecks add 6 mul 12 add string def
%
% Put the start character
%
sbs 0 //code11.encs 11 get putinterval
0 1 barlen 1 sub {
/i exch def
/indx charvals barcode i 1 getinterval get def
/enc //code11.encs indx get def
sbs i 6 mul 6 add enc putinterval
} for
%
% Put the checksum and end characters
%
includecheck {
numchecks 2 eq {
sbs barlen 6 mul 6 add //code11.encs checksum1 get putinterval
sbs barlen 6 mul 12 add //code11.encs checksum2 get putinterval
sbs barlen 6 mul 18 add //code11.encs 11 get putinterval
} {
sbs barlen 6 mul 6 add //code11.encs checksum1 get putinterval
sbs barlen 6 mul 12 add //code11.encs 11 get putinterval
} ifelse
} {
sbs barlen 6 mul 6 add //code11.encs 11 get putinterval
} ifelse
/text includecheck includecheckintext and {
numchecks 2 eq {
barlen 2 add string dup 0 barcode putinterval
dup barlen //code11.barchars checksum1 1 getinterval putinterval
dup barlen 1 add //code11.barchars checksum2 1 getinterval putinterval
} {
barlen 1 add string dup 0 barcode putinterval
dup barlen //code11.barchars checksum1 1 getinterval putinterval
} ifelse
} { barcode } ifelse def
/sbs [sbs {48 sub} forall] def
/resolve_height //render exec dup -1 eq { pop 1.0 } if /height exch def
<<
/ren /renlinear
/sbs sbs
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
includetext {
/txt [ [text 0 0 text1font text1size] ]
/text1xalign (center)
} if
/strictspec strictspec
/loosespec loosespec
/xdim xdim
/xmin xmin
/xmax xmax
/modunit modunit
/opt options
>>
_render //renlinear if
} stopped {end stop} if
end
}
[/barcode] {null def} forall
bind def
/code11 dup load executeonly /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
setglobal
% --END ENCODER code11--