Rev 21413 | Rev 24665 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
18800 | fschmid | 1 | %!PS |
19685 | fschmid | 2 | |
22439 | craig | 3 | % Barcode Writer in Pure PostScript - Version 2018-02-04 |
4 | % https://bwipp.terryburton.co.uk |
||
4460 | subik | 5 | % |
22439 | craig | 6 | % Copyright (c) 2004-2018 Terry Burton |
4460 | subik | 7 | % |
8 | % Permission is hereby granted, free of charge, to any |
||
9 | % person obtaining a copy of this software and associated |
||
10 | % documentation files (the "Software"), to deal in the |
||
11 | % Software without restriction, including without |
||
12 | % limitation the rights to use, copy, modify, merge, |
||
13 | % publish, distribute, sublicense, and/or sell copies of |
||
14 | % the Software, and to permit persons to whom the Software |
||
15 | % is furnished to do so, subject to the following |
||
16 | % conditions: |
||
17 | % |
||
18 | % The above copyright notice and this permission notice |
||
19 | % shall be included in all copies or substantial portions |
||
20 | % of the Software. |
||
21 | % |
||
22 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY |
||
23 | % KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO |
||
24 | % THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
||
25 | % PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
26 | % THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
||
27 | % DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
||
28 | % CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||
29 | % CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
||
30 | % IN THE SOFTWARE. |
||
31 | |||
32 | % --BEGIN TEMPLATE-- |
||
33 | |||
18800 | fschmid | 34 | % --BEGIN RESOURCE preamble-- |
22439 | craig | 35 | %%BeginResource: Category uk.co.terryburton.bwipp 0.0 2018020400 29629 32838 |
18800 | fschmid | 36 | %%BeginData: 6 ASCII Lines |
16255 | fschmid | 37 | currentglobal |
38 | true setglobal |
||
18800 | fschmid | 39 | /Generic /Category findresource dup length 1 add dict copy dup |
40 | /InstanceType /setpacking where {pop /packedarraytype} {/arraytype} ifelse put |
||
16255 | fschmid | 41 | /uk.co.terryburton.bwipp exch /Category defineresource pop |
42 | setglobal |
||
18800 | fschmid | 43 | %%EndData |
44 | %%EndResource |
||
45 | % --END RESOURCE preamble-- |
||
16255 | fschmid | 46 | |
18800 | fschmid | 47 | % --BEGIN RESOURCE raiseerror-- |
48 | % --REQUIRES preamble-- |
||
22439 | craig | 49 | %%BeginResource: uk.co.terryburton.bwipp raiseerror 0.0 2018020400 153516 39847 |
18800 | fschmid | 50 | %%BeginData: 13 ASCII Lines |
51 | /setpacking where {pop currentpacking true setpacking} if |
||
52 | 1 dict |
||
53 | begin |
||
54 | /raiseerror { |
||
55 | $error exch /errorinfo exch put |
||
56 | $error exch /errorname exch put |
||
57 | $error /command null put |
||
22439 | craig | 58 | $error /newerror true put |
59 | stop |
||
18800 | fschmid | 60 | } bind def |
61 | /raiseerror dup load /uk.co.terryburton.bwipp defineresource pop |
||
62 | end |
||
63 | /setpacking where {pop setpacking} if |
||
64 | %%EndData |
||
65 | %%EndResource |
||
66 | % --END RESOURCE raiseerror-- |
||
67 | |||
13293 | subik | 68 | % --BEGIN RENDERER renlinear-- |
18800 | fschmid | 69 | % --REQUIRES preamble raiseerror-- |
22439 | craig | 70 | %%BeginResource: uk.co.terryburton.bwipp renlinear 0.0 2018020400 85663 81483 |
18800 | fschmid | 71 | %%BeginData: 237 ASCII Lines |
16255 | fschmid | 72 | /setpacking where {pop currentpacking true setpacking} if |
73 | 1 dict |
||
18800 | fschmid | 74 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 75 | begin |
13293 | subik | 76 | /renlinear { |
77 | |||
20313 | craig | 78 | 20 dict begin % Confine variables to local scope |
13293 | subik | 79 | |
20313 | craig | 80 | /args exch def % We are given some arguments |
13293 | subik | 81 | |
20313 | craig | 82 | % Default options |
83 | /sbs [] def |
||
84 | /bhs [] def |
||
85 | /bbs [] def |
||
86 | /txt [] def |
||
87 | /barcolor (unset) def |
||
88 | /includetext false def |
||
89 | /textcolor (unset) def |
||
90 | /textxalign (unset) def |
||
91 | /textyalign (unset) def |
||
92 | /textfont (Courier) def |
||
93 | /textsize 10 def |
||
94 | /textxoffset 0 def |
||
95 | /textyoffset 0 def |
||
96 | /textgaps 0 def |
||
97 | /alttext () def |
||
98 | /bordercolor (unset) def |
||
99 | /backgroundcolor (unset) def |
||
100 | /inkspread 0.15 def |
||
101 | /width 0 def |
||
102 | /barratio 1 def |
||
103 | /spaceratio 1 def |
||
104 | /showborder false def |
||
105 | /borderleft 10 def |
||
106 | /borderright 10 def |
||
107 | /bordertop 1 def |
||
108 | /borderbottom 1 def |
||
109 | /borderwidth 0.5 def |
||
110 | /guardwhitespace false def |
||
111 | /guardleftpos 0 def |
||
112 | /guardleftypos 0 def |
||
113 | /guardrightpos 0 def |
||
114 | /guardrightypos 0 def |
||
115 | /guardwidth 6 def |
||
116 | /guardheight 7 def |
||
117 | |||
118 | % Apply the renderer options and the user options |
||
119 | args {def} forall |
||
120 | opt {def} forall |
||
13293 | subik | 121 | |
20313 | craig | 122 | /barcolor barcolor cvlit def |
123 | /textcolor textcolor cvlit def |
||
124 | /textxalign textxalign cvlit def |
||
125 | /textyalign textyalign cvlit def |
||
126 | /textfont textfont cvlit def |
||
127 | /textsize textsize cvr def |
||
128 | /textxoffset textxoffset cvr def |
||
129 | /textyoffset textyoffset cvr def |
||
130 | /textgaps textgaps cvr def |
||
131 | /alttext alttext cvlit def |
||
132 | /bordercolor bordercolor cvlit def |
||
133 | /backgroundcolor backgroundcolor cvlit def |
||
134 | /inkspread inkspread cvr def |
||
135 | /width width cvr def |
||
136 | /barratio barratio cvr def |
||
137 | /spaceratio spaceratio cvr def |
||
138 | /borderleft borderleft cvr def |
||
139 | /borderright borderright cvr def |
||
140 | /bordertop bordertop cvr def |
||
141 | /borderbottom borderbottom cvr def |
||
142 | /borderwidth borderwidth cvr def |
||
143 | /guardleftpos guardleftpos cvr def |
||
144 | /guardleftypos guardleftypos cvr def |
||
145 | /guardrightpos guardrightpos cvr def |
||
146 | /guardrightypos guardrightypos cvr def |
||
147 | /guardwidth guardwidth cvr def |
||
148 | /guardheight guardheight cvr def |
||
149 | |||
150 | % Create bar elements and put them into the bars array |
||
151 | /bars sbs length 1 add 2 idiv array def |
||
152 | /x 0.00 def /maxh 0 def |
||
153 | |||
154 | /i exch def |
||
155 | i 2 mod 0 eq { % i is even |
||
156 | /d sbs i get barratio mul barratio sub 1 add def % d=digit*r-r+1 |
||
157 | sbs i get 0 ne { |
||
158 | /h bhs i 2 idiv get 72 mul def % Height from bhs |
||
159 | /c d 2 div x add def % Centre of the bar = x + d/2 |
||
160 | /y bbs i 2 idiv get 72 mul def % Baseline from bbs |
||
161 | /w d inkspread sub def % bar width = digit - inkspread |
||
162 | bars i 2 idiv [h c y w] put % Add the bar entry |
||
163 | h y add maxh gt {/maxh h y add def} if |
||
164 | } { |
||
165 | bars i 2 idiv -1 put % Dummy entry |
||
166 | } ifelse |
||
167 | } { |
||
168 | /d sbs i get spaceratio mul spaceratio sub 1 add def % d=digit*r-r+1 |
||
169 | } ifelse |
||
170 | /x x d add def % x+=d |
||
171 | } for |
||
13293 | subik | 172 | |
20313 | craig | 173 | gsave |
13293 | subik | 174 | |
20313 | craig | 175 | currentpoint translate |
13293 | subik | 176 | |
20313 | craig | 177 | % Force symbol to given width |
178 | width 0 ne { |
||
179 | width 72 mul x div 1 scale |
||
180 | } if |
||
13293 | subik | 181 | |
20313 | craig | 182 | % Set RGB or CMYK color depending on length of given hex string |
183 | /setanycolor { |
||
184 | /anycolor exch def |
||
185 | anycolor length 6 eq { |
||
186 | (< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor |
||
187 | } if |
||
188 | anycolor length 8 eq { |
||
189 | (< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor |
||
190 | } if |
||
191 | } bind def |
||
13293 | subik | 192 | |
20313 | craig | 193 | % Display the border and background |
194 | newpath |
||
195 | borderleft neg borderbottom neg moveto |
||
196 | x borderleft add borderright add 0 rlineto |
||
197 | |||
198 | x borderleft add borderright add neg 0 rlineto |
||
199 | |||
200 | closepath |
||
201 | backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if |
||
202 | showborder { |
||
203 | gsave |
||
204 | bordercolor (unset) ne { bordercolor setanycolor } if |
||
205 | borderwidth setlinewidth stroke |
||
206 | grestore |
||
207 | } if |
||
208 | |||
209 | % Display the bars for elements in the bars array |
||
210 | gsave |
||
211 | |||
212 | barcolor (unset) ne { barcolor setanycolor } if |
||
213 | bars { |
||
214 | dup -1 ne { |
||
215 | aload pop newpath setlinewidth moveto 0 exch rlineto stroke |
||
216 | } { |
||
217 | pop |
||
218 | } ifelse |
||
219 | } forall |
||
220 | grestore |
||
221 | |||
222 | % Display the text for elements in the text array |
||
223 | textcolor (unset) ne { textcolor setanycolor } if |
||
224 | includetext { |
||
225 | textxalign (unset) eq textyalign (unset) eq and alttext () eq and { |
||
226 | /s 0 def /fn () def |
||
227 | txt { |
||
228 | {} forall |
||
229 | 2 copy s ne exch fn ne or { |
||
22439 | craig | 230 | 2 copy /s exch def /fn exch def |
231 | selectfont |
||
20313 | craig | 232 | } { |
233 | pop pop |
||
234 | } ifelse |
||
235 | moveto show |
||
236 | } forall |
||
237 | } { |
||
22439 | craig | 238 | textfont textsize selectfont |
20313 | craig | 239 | alttext () eq { |
240 | /txt [ txt { 0 get {} forall } forall ] def |
||
241 | /tstr txt length string def |
||
242 | |||
243 | } { |
||
244 | /tstr alttext def |
||
245 | } ifelse |
||
16255 | fschmid | 246 | |
20313 | craig | 247 | % Find true ascent of font |
248 | tstr length 0 eq { |
||
249 | |||
250 | } { |
||
251 | gsave |
||
252 | newpath 0 0 moveto (0) false charpath pathbbox |
||
253 | 4 1 roll pop pop pop |
||
254 | grestore |
||
255 | currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse |
||
256 | currentfont /StrokeWidth known and { |
||
257 | currentfont /StrokeWidth get 2 div 0 exch |
||
258 | currentfont /FontMatrix get dtransform |
||
259 | dup mul exch dup mul add sqrt |
||
260 | add |
||
261 | } if |
||
262 | } ifelse |
||
263 | /textascent exch def |
||
264 | /textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def |
||
16255 | fschmid | 265 | |
20313 | craig | 266 | /textxpos textxoffset x textwidth sub 2 div add def |
267 | textxalign (left) eq { /textxpos textxoffset def } if |
||
268 | textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if |
||
269 | textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if |
||
270 | textxalign (offright) eq { /textxpos x textxoffset add def } if |
||
271 | textxalign (justify) eq textwidth x lt and { |
||
272 | /textxpos 0 def |
||
273 | /textgaps x textwidth sub tstr length 1 sub div def |
||
274 | } if |
||
275 | /textypos textyoffset textascent add 1 add neg def |
||
276 | textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if |
||
277 | textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if |
||
278 | textxpos textypos moveto textgaps 0 tstr ashow |
||
279 | } ifelse |
||
280 | } if |
||
13293 | subik | 281 | |
20313 | craig | 282 | % Display the guard elements |
283 | guardwhitespace { |
||
284 | 0.75 setlinewidth |
||
285 | guardleftpos 0 ne { |
||
286 | newpath |
||
287 | guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto |
||
288 | guardwidth neg guardheight -2 div rlineto |
||
289 | guardwidth guardheight -2 div rlineto |
||
290 | stroke |
||
291 | } if |
||
292 | guardrightpos 0 ne { |
||
293 | newpath |
||
294 | guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto |
||
295 | guardwidth guardheight -2 div rlineto |
||
296 | guardwidth neg guardheight -2 div rlineto |
||
297 | stroke |
||
298 | } if |
||
299 | } if |
||
300 | |||
301 | grestore |
||
302 | |||
303 | end |
||
13293 | subik | 304 | |
305 | } bind def |
||
16255 | fschmid | 306 | /renlinear dup load /uk.co.terryburton.bwipp defineresource pop |
307 | end |
||
308 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 309 | %%EndData |
310 | %%EndResource |
||
13293 | subik | 311 | % --END RENDERER renlinear-- |
312 | |||
313 | % --BEGIN RENDERER renmatrix-- |
||
18800 | fschmid | 314 | % --REQUIRES preamble raiseerror-- |
22439 | craig | 315 | %%BeginResource: uk.co.terryburton.bwipp renmatrix 0.0 2018020400 108321 107254 |
316 | %%BeginData: 333 ASCII Lines |
||
16255 | fschmid | 317 | /setpacking where {pop currentpacking true setpacking} if |
318 | 1 dict |
||
18800 | fschmid | 319 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 320 | begin |
13293 | subik | 321 | /renmatrix { |
322 | |||
20313 | craig | 323 | 20 dict begin |
13293 | subik | 324 | |
20313 | craig | 325 | /args exch def |
13293 | subik | 326 | |
20313 | craig | 327 | % Default options |
328 | /width 1 def |
||
329 | /height 1 def |
||
330 | /barcolor (unset) def |
||
331 | /backgroundcolor (unset) def |
||
22439 | craig | 332 | /colormap (unset) def |
21413 | craig | 333 | /inkspread 0 def |
334 | /inkspreadh 0 def |
||
335 | /inkspreadv 0 def |
||
22439 | craig | 336 | /includetext false def |
337 | /txt [] def |
||
338 | /textcolor (unset) def |
||
339 | /textxalign (unset) def |
||
340 | /textyalign (unset) def |
||
341 | /textfont (Courier) def |
||
342 | /textsize 10 def |
||
343 | /textxoffset 0 def |
||
344 | /textyoffset 0 def |
||
345 | /textgaps 0 def |
||
346 | /alttext () def |
||
13293 | subik | 347 | |
20313 | craig | 348 | % Apply the renderer options and the user options |
349 | args {def} forall |
||
350 | opt {def} forall |
||
13293 | subik | 351 | |
20313 | craig | 352 | /width width cvr def |
353 | /height height cvr def |
||
354 | /barcolor barcolor cvlit def |
||
355 | /backgroundcolor backgroundcolor cvlit def |
||
21413 | craig | 356 | /inkspread inkspread cvr def |
357 | /inkspreadh inkspreadh cvr def |
||
358 | /inkspreadv inkspreadv cvr def |
||
22439 | craig | 359 | /textcolor textcolor cvlit def |
360 | /textxalign textxalign cvlit def |
||
361 | /textyalign textyalign cvlit def |
||
362 | /textfont textfont cvlit def |
||
363 | /textsize textsize cvr def |
||
364 | /textxoffset textxoffset cvr def |
||
365 | /textyoffset textyoffset cvr def |
||
366 | /textgaps textgaps cvr def |
||
367 | /alttext alttext cvlit def |
||
13293 | subik | 368 | |
21413 | craig | 369 | inkspread 0 ne {/inkspreadh inkspread def} if |
370 | inkspread 0 ne {/inkspreadv inkspread def} if |
||
371 | |||
372 | /xyget { pixx mul add pixs exch get } bind def |
||
373 | /xyinvert { pixx mul add pixs exch 2 copy get 1 xor put } bind def |
||
374 | /mxyget { pixx mul add m exch get 2#001 and } bind def |
||
375 | /mxyset { pixx mul add m exch 3 -1 roll put } bind def |
||
376 | /msetborder { pixx mul add m exch 2 copy get 2#010 or put } bind def |
||
377 | /mborderoff { pixx mul add m exch 2 copy get 2#100 or put } bind def |
||
378 | /misborder { pixx mul add m exch get 2#110 and 2#010 eq } bind def |
||
379 | /mclear { pixx mul add m exch 2 copy get 2#001 and put } bind def |
||
380 | /mclear4 { |
||
381 | 2 copy mclear |
||
382 | 2 copy 1 add mclear |
||
383 | 2 copy exch 1 add exch mclear |
||
384 | 2 copy exch 1 add exch mclear |
||
385 | 1 add exch 1 add exch mclear |
||
386 | } bind def |
||
387 | |||
388 | /trace { |
||
389 | % Walk the outline of a region emitting edge coordinates of the path |
||
390 | /y exch def /x exch def |
||
391 | % dir 0:right 1:down 2:left 3:up |
||
392 | % hug 0:right 1:left |
||
393 | /dir x 1 add y 1 add mxyget def /hug dir def |
||
394 | /sx x def /sy y def /sdir dir def |
||
395 | mark [x y] { |
||
396 | x 1 add y |
||
397 | x 1 add y 1 add |
||
398 | x y 1 add |
||
399 | x y |
||
400 | 8 dir 2 mul neg roll |
||
401 | /Dy exch def /Dx exch def /D Dx Dy xyget def |
||
402 | /Cy exch def /Cx exch def /C Cx Cy xyget def |
||
403 | /By exch def /Bx exch def /B Bx By xyget def |
||
404 | /Ay exch def /Ax exch def /A Ax Ay xyget def |
||
405 | A B eq { |
||
406 | A C eq {/L} {/R} ifelse |
||
407 | } { |
||
408 | A C eq B D eq and { |
||
409 | A 0 eq hug 0 eq xor {/R} {/F} ifelse |
||
410 | } { |
||
411 | /F |
||
412 | } ifelse |
||
413 | } ifelse |
||
414 | dup /F eq { |
||
415 | pop |
||
416 | dir 0 eq {/x x 1 add def} if |
||
417 | dir 1 eq {/y y 1 add def} if |
||
418 | dir 2 eq {/x x 1 sub def} if |
||
419 | dir 3 eq {/y y 1 sub def} if |
||
420 | hug 0 eq { |
||
421 | Ax Ay msetborder |
||
422 | } { |
||
423 | Bx By msetborder |
||
424 | } ifelse |
||
425 | } { |
||
426 | /L eq { |
||
427 | /dir dir 3 add 4 mod def |
||
428 | hug 1 eq { |
||
429 | Bx By msetborder |
||
430 | Dx Dy mborderoff |
||
431 | } if |
||
432 | } { % R |
||
433 | /dir dir 1 add 4 mod def |
||
434 | hug 0 eq { |
||
435 | Ax Ay msetborder |
||
436 | Cx Cy mborderoff |
||
437 | } if |
||
438 | } ifelse |
||
439 | [x y] |
||
440 | } ifelse |
||
441 | x sx eq y sy eq and dir sdir eq and {exit} if |
||
442 | } loop |
||
443 | counttomark array astore exch pop |
||
444 | |||
445 | % Invert the interior of the path |
||
446 | /x x 1 add def /y y 1 add def |
||
447 | /t x y mxyget 1 xor def |
||
448 | mark x y { |
||
449 | counttomark 0 eq {exit} if |
||
450 | /y exch def /x exch def |
||
451 | x y mxyget t ne { |
||
452 | |||
453 | pixx 1 sub x 1 add 1 pixx 1 sub {dup y misborder {exch pop exit} if pop} for |
||
454 | 1 exch { % From left to right border |
||
455 | /i exch def |
||
456 | i y misborder not { |
||
457 | t i y mxyset |
||
458 | i y xyinvert |
||
459 | } if |
||
460 | i y 1 sub mxyget t ne i y 1 sub misborder not and {i y 1 sub} if |
||
461 | i y 1 add mxyget t ne i y 1 add misborder not and {i y 1 add} if |
||
462 | } for |
||
463 | } if |
||
464 | } loop |
||
465 | pop |
||
466 | |||
467 | % Walk the path to clear the border information |
||
468 | dup 0 get aload pop /y1 exch def /x1 exch def |
||
469 | dup dup length 1 sub 1 exch getinterval { |
||
470 | aload pop /y2 exch def /x2 exch def |
||
471 | x2 x1 gt { x1 2 x2 1 sub {y1 mclear4} for } if |
||
472 | y2 y1 gt { y1 2 y2 1 sub {x1 exch mclear4} for } if |
||
473 | x2 x1 lt { x1 -2 x2 1 add {y1 mclear4} for } if |
||
474 | y2 y1 lt { y1 -2 y2 1 add {x1 exch mclear4} for } if |
||
475 | /x1 x2 def /y1 y2 def |
||
476 | } forall |
||
477 | |||
478 | % Discard duplicate final point |
||
479 | dup length 1 sub 0 exch getinterval |
||
480 | |||
481 | } bind def |
||
482 | |||
20313 | craig | 483 | % Set RGB or CMYK color depending on length of given hex string |
484 | /setanycolor { |
||
485 | /anycolor exch def |
||
486 | anycolor length 6 eq { |
||
487 | (< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor |
||
488 | } if |
||
489 | anycolor length 8 eq { |
||
490 | (< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor |
||
491 | } if |
||
492 | } bind def |
||
13293 | subik | 493 | |
22439 | craig | 494 | % Plot a layer of single colour |
495 | /drawlayer { |
||
496 | |||
497 | /pixsorig pixs def |
||
498 | /pixs exch def |
||
499 | |||
500 | % Pad the bitmap on all sides |
||
501 | /pixs [ |
||
502 | pixx 2 add {0} repeat |
||
503 | |||
504 | |||
505 | pixs exch pixx getinterval aload pop |
||
506 | |||
507 | } for |
||
508 | pixx 2 add {0} repeat |
||
509 | ] def |
||
510 | /pixx pixx 2 add def |
||
511 | /pixy pixy 2 add def |
||
512 | |||
513 | % Track inverted regions and working space |
||
514 | /m [ pixs length {0} repeat ] def |
||
515 | |||
516 | % Construct paths by tracing and inverting each dark region |
||
517 | /paths [ |
||
518 | |||
519 | /j exch def |
||
520 | |||
521 | /i exch def |
||
522 | i j xyget 1 eq { |
||
523 | i 1 sub j 1 sub trace |
||
524 | } if |
||
525 | } for |
||
526 | } for |
||
527 | ] def |
||
528 | |||
529 | % Revert the bitmap size |
||
530 | /pixx pixx 2 sub def |
||
531 | /pixy pixy 2 sub def |
||
532 | |||
533 | % Draw the image |
||
534 | newpath |
||
535 | paths { |
||
536 | /p exch def |
||
537 | /len p length def |
||
538 | p len 1 sub get aload pop |
||
539 | p 0 get aload pop |
||
540 | |||
541 | /i exch def |
||
542 | p i 1 add len mod get aload pop 6 -2 roll % x3 y3 x1 y1 x2 y2 |
||
543 | 5 index inkspreadh |
||
544 | 4 index 4 -1 roll lt {add} {sub} ifelse % y3<y1 ? x2+i : x2-i |
||
545 | 4 1 roll |
||
546 | 4 index inkspreadv |
||
547 | 4 index 4 -1 roll gt {add} {sub} ifelse % x3>x1 ? y2+i : y2-i |
||
548 | 4 -1 roll exch pixy exch sub |
||
549 | i 0 eq {moveto} {lineto} ifelse |
||
550 | } for % x2 y2 x3 y3 |
||
551 | closepath |
||
552 | pop pop pop pop |
||
553 | } forall |
||
554 | fill |
||
555 | |||
556 | /pixs pixsorig def |
||
557 | |||
558 | } bind def |
||
559 | |||
560 | gsave |
||
561 | |||
20313 | craig | 562 | % Draw the image |
21413 | craig | 563 | /inkspreadh inkspreadh 2 div def |
564 | /inkspreadv inkspreadv 2 div def |
||
20313 | craig | 565 | currentpoint translate |
566 | width pixx div 72 mul height pixy div 72 mul scale |
||
567 | |||
21413 | craig | 568 | backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if |
22439 | craig | 569 | |
570 | colormap (unset) eq { |
||
571 | /colormap << 1 barcolor >> def |
||
572 | } if |
||
573 | |||
574 | colormap { |
||
575 | setanycolor |
||
576 | /key exch def |
||
577 | [ |
||
578 | pixs { key eq {1} {0} ifelse } forall |
||
579 | ] drawlayer |
||
21413 | craig | 580 | } forall |
22439 | craig | 581 | |
582 | % Display the text for elements in the text array |
||
583 | textcolor (unset) ne { textcolor setanycolor } if |
||
584 | includetext { |
||
585 | textxalign (unset) eq textyalign (unset) eq and alttext () eq and { |
||
586 | /s 0 def /fn () def |
||
587 | txt { |
||
588 | {} forall |
||
589 | 2 copy s ne exch fn ne or { |
||
590 | 2 copy /s exch def /fn exch def |
||
591 | selectfont |
||
592 | } { |
||
593 | pop pop |
||
594 | } ifelse |
||
595 | moveto show |
||
596 | } forall |
||
597 | } { |
||
598 | textfont textsize selectfont |
||
599 | alttext () eq { |
||
600 | /txt [ txt { 0 get {} forall } forall ] def |
||
601 | /tstr txt length string def |
||
602 | |||
603 | } { |
||
604 | /tstr alttext def |
||
605 | } ifelse |
||
606 | |||
607 | % Find true ascent of font |
||
608 | tstr length 0 eq { |
||
609 | |||
610 | } { |
||
611 | gsave |
||
612 | newpath 0 0 moveto (0) false charpath pathbbox |
||
613 | 4 1 roll pop pop pop |
||
614 | grestore |
||
615 | currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse |
||
616 | currentfont /StrokeWidth known and { |
||
617 | currentfont /StrokeWidth get 2 div 0 exch |
||
618 | currentfont /FontMatrix get dtransform |
||
619 | dup mul exch dup mul add sqrt |
||
620 | add |
||
621 | } if |
||
622 | } ifelse |
||
623 | /textascent exch def |
||
624 | /textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def |
||
625 | |||
626 | /textxpos textxoffset x textwidth sub 2 div add def |
||
627 | textxalign (left) eq { /textxpos textxoffset def } if |
||
628 | textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if |
||
629 | textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if |
||
630 | textxalign (offright) eq { /textxpos x textxoffset add def } if |
||
631 | textxalign (justify) eq textwidth x lt and { |
||
632 | /textxpos 0 def |
||
633 | /textgaps x textwidth sub tstr length 1 sub div def |
||
634 | } if |
||
635 | /textypos textyoffset textascent add 1 add neg def |
||
636 | textyalign (above) eq { /textypos textyoffset pixy add 1 add def } if |
||
637 | textyalign (center) eq { /textypos textyoffset pixy textascent sub 2 div add def } if |
||
638 | textxpos textypos moveto textgaps 0 tstr ashow |
||
639 | } ifelse |
||
640 | } if |
||
641 | |||
20313 | craig | 642 | grestore |
13293 | subik | 643 | |
20313 | craig | 644 | end |
13293 | subik | 645 | |
646 | } bind def |
||
16255 | fschmid | 647 | /renmatrix dup load /uk.co.terryburton.bwipp defineresource pop |
648 | end |
||
649 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 650 | %%EndData |
651 | %%EndResource |
||
13293 | subik | 652 | % --END RENDERER renmatrix-- |
653 | |||
654 | % --BEGIN RENDERER renmaximatrix-- |
||
18800 | fschmid | 655 | % --REQUIRES preamble raiseerror-- |
22439 | craig | 656 | %%BeginResource: uk.co.terryburton.bwipp renmaximatrix 0.0 2018020400 55677 52149 |
18800 | fschmid | 657 | %%BeginData: 79 ASCII Lines |
16255 | fschmid | 658 | /setpacking where {pop currentpacking true setpacking} if |
659 | 1 dict |
||
18800 | fschmid | 660 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 661 | begin |
13293 | subik | 662 | /renmaximatrix { |
663 | |||
20313 | craig | 664 | 20 dict begin |
13293 | subik | 665 | |
20313 | craig | 666 | /args exch def % We are given some arguments |
13293 | subik | 667 | |
20313 | craig | 668 | % Default options |
669 | /barcolor (unset) def |
||
670 | /backgroundcolor (unset) def |
||
18800 | fschmid | 671 | |
20313 | craig | 672 | % Apply the renderer options and the user options |
673 | args {def} forall |
||
674 | opt {def} forall |
||
18800 | fschmid | 675 | |
20313 | craig | 676 | /barcolor barcolor cvlit def |
677 | /backgroundcolor backgroundcolor cvlit def |
||
18800 | fschmid | 678 | |
20313 | craig | 679 | % Set RGB or CMYK color depending on length of given hex string |
680 | /setanycolor { |
||
681 | /anycolor exch def |
||
682 | anycolor length 6 eq { |
||
683 | (< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor |
||
684 | } if |
||
685 | anycolor length 8 eq { |
||
686 | (< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor |
||
687 | } if |
||
688 | } bind def |
||
18800 | fschmid | 689 | |
20313 | craig | 690 | gsave |
13293 | subik | 691 | |
20313 | craig | 692 | currentpoint translate |
13293 | subik | 693 | |
22439 | craig | 694 | 2.4945 dup scale % from 1pt to 0.88mm |
18800 | fschmid | 695 | |
20313 | craig | 696 | |
22439 | craig | 697 | backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if |
20313 | craig | 698 | barcolor (unset) ne { barcolor setanycolor } if |
18800 | fschmid | 699 | |
20313 | craig | 700 | 0.5 0.5774 translate |
13293 | subik | 701 | |
20313 | craig | 702 | newpath |
703 | pixs { |
||
22439 | craig | 704 | dup |
705 | /x exch 30 mod def |
||
20313 | craig | 706 | /y exch 30 idiv def |
707 | y 2 mod 0 eq {x} {x 0.5 add} ifelse |
||
708 | 32 y sub 0.8661 mul |
||
709 | moveto |
||
710 | |||
711 | -0.5 -0.2887 rlineto |
||
712 | |||
713 | 0.5 -0.2887 rlineto |
||
714 | 0.5 0.2887 rlineto |
||
715 | |||
716 | -0.5 0.2887 rlineto |
||
717 | closepath |
||
718 | } forall |
||
719 | fill |
||
13293 | subik | 720 | |
20313 | craig | 721 | % Plot the locator symbol |
722 | newpath 14 13.8576 0.5774 0 360 arc closepath |
||
723 | 14 13.8576 1.3359 360 0 arcn closepath fill |
||
724 | newpath 14 13.8576 2.1058 0 360 arc closepath |
||
725 | 14 13.8576 2.8644 360 0 arcn closepath fill |
||
726 | newpath 14 13.8576 3.6229 0 360 arc closepath |
||
727 | 14 13.8576 4.3814 360 0 arcn closepath fill |
||
13293 | subik | 728 | |
20313 | craig | 729 | grestore |
13293 | subik | 730 | |
20313 | craig | 731 | end |
13293 | subik | 732 | |
733 | } bind def |
||
16255 | fschmid | 734 | /renmaximatrix dup load /uk.co.terryburton.bwipp defineresource pop |
735 | end |
||
736 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 737 | %%EndData |
738 | %%EndResource |
||
13293 | subik | 739 | % --END RENDERER renmaximatrix-- |
740 | |||
741 | % --BEGIN ENCODER ean5-- |
||
18800 | fschmid | 742 | % --REQUIRES preamble raiseerror renlinear-- |
13293 | subik | 743 | % --DESC: EAN-5 (5 digit addon) |
744 | % --EXAM: 90200 |
||
745 | % --EXOP: includetext guardwhitespace |
||
746 | % --RNDR: renlinear |
||
22439 | craig | 747 | %%BeginResource: uk.co.terryburton.bwipp ean5 0.0 2018020400 65550 65357 |
18800 | fschmid | 748 | %%BeginData: 135 ASCII Lines |
16255 | fschmid | 749 | /setpacking where {pop currentpacking true setpacking} if |
750 | 1 dict |
||
18800 | fschmid | 751 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 752 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
753 | begin |
||
13293 | subik | 754 | /ean5 { |
755 | |||
20313 | craig | 756 | 20 dict begin |
13293 | subik | 757 | |
20313 | craig | 758 | /options exch def % We are given an option string |
759 | /barcode exch def % We are given a barcode string |
||
13293 | subik | 760 | |
20313 | craig | 761 | /dontdraw false def |
762 | /includetext false def % Enable/disable text |
||
763 | /textfont /Helvetica def |
||
764 | /textsize 12 def |
||
765 | /textxoffset 0 def |
||
766 | /textyoffset (unset) def |
||
767 | /height 0.7 def |
||
768 | |||
769 | % Parse the input options |
||
770 | options type /stringtype eq { |
||
771 | 1 dict begin |
||
772 | options { |
||
773 | token false eq {exit} if dup length string cvs (=) search |
||
774 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
775 | } loop |
||
776 | currentdict end /options exch def |
||
777 | } if |
||
778 | options {def} forall |
||
779 | |||
780 | /textfont textfont cvlit def |
||
781 | /textsize textsize cvr def |
||
782 | /height height cvr def |
||
783 | /textxoffset textxoffset cvr def |
||
784 | textyoffset (unset) eq { |
||
785 | /textyoffset height 72 mul 1 add def |
||
786 | } { |
||
787 | /textyoffset textyoffset cvr def |
||
788 | } ifelse |
||
18800 | fschmid | 789 | |
20313 | craig | 790 | % Validate input |
791 | barcode length 5 ne { |
||
792 | /bwipp.ean5badLength (EAN-5 add-on must be 5 digits) //raiseerror exec |
||
793 | } if |
||
794 | barcode { |
||
795 | dup 48 lt exch 57 gt or { |
||
796 | /bwipp.ean5badCharacter (EAN-5 add-on must contain only digits) //raiseerror exec |
||
797 | } if |
||
798 | } forall |
||
799 | |||
800 | % Create an array containing the character mappings |
||
801 | /encs |
||
802 | [ (3211) (2221) (2122) (1411) (1132) |
||
803 | (1231) (1114) (1312) (1213) (3112) |
||
804 | (112) (11) |
||
805 | ] def |
||
13293 | subik | 806 | |
20313 | craig | 807 | % Create a string of the available characters |
808 | /barchars (0123456789) def |
||
13293 | subik | 809 | |
20313 | craig | 810 | % Determine the mirror map based on mod 10 checksum |
811 | /mirrormaps |
||
812 | [ (11000) (10100) (10010) (10001) (01100) |
||
813 | (00110) (00011) (01010) (01001) (00101) |
||
814 | ] def |
||
815 | /checksum 0 def |
||
816 | |||
817 | /i exch def |
||
818 | /barchar barcode i get 48 sub def |
||
819 | i 2 mod 0 eq { |
||
820 | /checksum barchar 3 mul checksum add def |
||
821 | } { |
||
822 | /checksum barchar 9 mul checksum add def |
||
823 | } ifelse |
||
824 | } for |
||
825 | /checksum checksum 10 mod def |
||
826 | /mirrormap mirrormaps checksum get def |
||
13293 | subik | 827 | |
20313 | craig | 828 | /sbs 31 string def |
829 | /txt 5 array def |
||
830 | |||
831 | |||
832 | /i exch def |
||
13293 | subik | 833 | |
20313 | craig | 834 | % Prefix with either a start character or separator character |
835 | i 0 eq { |
||
836 | sbs 0 encs 10 get putinterval |
||
837 | } { |
||
838 | sbs i 1 sub 6 mul 7 add encs 11 get putinterval |
||
839 | } ifelse |
||
13293 | subik | 840 | |
20313 | craig | 841 | % Lookup the encoding for the barcode character |
842 | barcode i 1 getinterval barchars exch search |
||
843 | pop % Discard true leaving pre |
||
844 | length /indx exch def % indx is the length of pre |
||
845 | pop pop % Discard seek and post |
||
846 | /enc encs indx get def % Get the indxth encoding |
||
847 | mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap |
||
848 | /enclen enc length def |
||
849 | /revenc enclen string def |
||
850 | |||
851 | /j exch def |
||
852 | /char enc j get def |
||
853 | revenc enclen j sub 1 sub char put |
||
854 | } for |
||
855 | /enc revenc def |
||
856 | } if |
||
857 | sbs i 6 mul 3 add enc putinterval % Put encoded digit into sbs |
||
858 | txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textxoffset add textyoffset textfont textsize] put |
||
859 | } for |
||
13293 | subik | 860 | |
20313 | craig | 861 | % Return the arguments |
862 | << |
||
863 | /ren //renlinear |
||
864 | /sbs [sbs {48 sub} forall] |
||
865 | /bhs [16{height}repeat] |
||
866 | /bbs [16{0}repeat] |
||
867 | includetext { |
||
868 | /txt txt |
||
869 | } if |
||
870 | /opt options |
||
871 | /guardrightpos 10 |
||
872 | /guardrightypos textyoffset 4 add |
||
873 | /bordertop 10 |
||
874 | >> |
||
13293 | subik | 875 | |
20313 | craig | 876 | dontdraw not //renlinear if |
13293 | subik | 877 | |
20313 | craig | 878 | end |
13293 | subik | 879 | |
880 | } bind def |
||
16255 | fschmid | 881 | /ean5 dup load /uk.co.terryburton.bwipp defineresource pop |
882 | end |
||
883 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 884 | %%EndData |
885 | %%EndResource |
||
13293 | subik | 886 | % --END ENCODER ean5-- |
887 | |||
888 | % --BEGIN ENCODER ean2-- |
||
18800 | fschmid | 889 | % --REQUIRES preamble raiseerror renlinear-- |
13293 | subik | 890 | % --DESC: EAN-2 (2 digit addon) |
891 | % --EXAM: 05 |
||
892 | % --EXOP: includetext guardwhitespace |
||
893 | % --RNDR: renlinear |
||
22439 | craig | 894 | %%BeginResource: uk.co.terryburton.bwipp ean2 0.0 2018020400 63867 63619 |
18800 | fschmid | 895 | %%BeginData: 120 ASCII Lines |
16255 | fschmid | 896 | /setpacking where {pop currentpacking true setpacking} if |
897 | 1 dict |
||
18800 | fschmid | 898 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 899 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
900 | begin |
||
13293 | subik | 901 | /ean2 { |
902 | |||
20313 | craig | 903 | 20 dict begin |
13293 | subik | 904 | |
20313 | craig | 905 | /options exch def % We are given an options string |
906 | /barcode exch def % We are given a barcode string |
||
13293 | subik | 907 | |
20313 | craig | 908 | /dontdraw false def |
909 | /includetext false def % Enable/disable text |
||
910 | /textfont /Helvetica def |
||
911 | /textsize 12 def |
||
912 | /textxoffset 0 def |
||
913 | /textyoffset (unset) def |
||
914 | /height 0.7 def |
||
915 | |||
916 | % Parse the input options |
||
917 | options type /stringtype eq { |
||
918 | 1 dict begin |
||
919 | options { |
||
920 | token false eq {exit} if dup length string cvs (=) search |
||
921 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
922 | } loop |
||
923 | currentdict end /options exch def |
||
924 | } if |
||
925 | options {def} forall |
||
926 | |||
927 | /textfont textfont cvlit def |
||
928 | /textsize textsize cvr def |
||
929 | /height height cvr def |
||
930 | /textxoffset textxoffset cvr def |
||
931 | textyoffset (unset) eq { |
||
932 | /textyoffset height 72 mul 1 add def |
||
933 | } { |
||
934 | /textyoffset textyoffset cvr def |
||
935 | } ifelse |
||
18800 | fschmid | 936 | |
20313 | craig | 937 | % Validate input |
938 | barcode length 2 ne { |
||
939 | /bwipp.ean2badLength (EAN-2 add-on must be 2 digits) //raiseerror exec |
||
940 | } if |
||
941 | barcode { |
||
942 | dup 48 lt exch 57 gt or { |
||
943 | /bwipp.ean2badCharacter (EAN-2 add-on must contain only digits) //raiseerror exec |
||
944 | } if |
||
945 | } forall |
||
946 | |||
947 | % Create an array containing the character mappings |
||
948 | /encs |
||
949 | [ (3211) (2221) (2122) (1411) (1132) |
||
950 | (1231) (1114) (1312) (1213) (3112) |
||
951 | (112) (11) |
||
952 | ] def |
||
13293 | subik | 953 | |
20313 | craig | 954 | % Create a string of the available characters |
955 | /barchars (0123456789) def |
||
13293 | subik | 956 | |
20313 | craig | 957 | % Determine the mirror map based on mod 4 checksum |
958 | /mirrormap [(00) (01) (10) (11)] barcode 0 2 getinterval cvi 4 mod get def |
||
13293 | subik | 959 | |
20313 | craig | 960 | /sbs 13 string def |
961 | /txt 2 array def |
||
962 | |||
963 | |||
964 | /i exch def |
||
13293 | subik | 965 | |
20313 | craig | 966 | % Prefix with either a start character or separator character |
967 | i 0 eq { |
||
968 | sbs 0 encs 10 get putinterval |
||
969 | } { |
||
970 | sbs i 1 sub 6 mul 7 add encs 11 get putinterval |
||
971 | } ifelse |
||
13293 | subik | 972 | |
20313 | craig | 973 | % Lookup the encoding for the barcode character |
974 | barcode i 1 getinterval barchars exch search |
||
975 | pop % Discard true leaving pre |
||
976 | length /indx exch def % indx is the length of pre |
||
977 | pop pop % Discard seek and post |
||
978 | /enc encs indx get def % Get the indxth encoding |
||
979 | mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap |
||
980 | /enclen enc length def |
||
981 | /revenc enclen string def |
||
982 | |||
983 | /j exch def |
||
984 | /char enc j get def |
||
985 | revenc enclen j sub 1 sub char put |
||
986 | } for |
||
987 | /enc revenc def |
||
988 | } if |
||
989 | sbs i 6 mul 3 add enc putinterval % Put encoded digit into sbs |
||
990 | txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textxoffset add textyoffset textfont textsize] put |
||
991 | } for |
||
13293 | subik | 992 | |
20313 | craig | 993 | % Return the arguments |
994 | << |
||
995 | /ren //renlinear |
||
996 | /sbs [sbs {48 sub} forall] |
||
997 | /bhs [12{height}repeat] |
||
998 | /bbs [12{0}repeat] |
||
999 | includetext { |
||
1000 | /txt txt |
||
1001 | } if |
||
1002 | /opt options |
||
1003 | /guardrightpos 10 |
||
1004 | /guardrightypos textyoffset 4 add |
||
1005 | /bordertop 10 |
||
1006 | >> |
||
13293 | subik | 1007 | |
20313 | craig | 1008 | dontdraw not //renlinear if |
13293 | subik | 1009 | |
20313 | craig | 1010 | end |
13293 | subik | 1011 | |
1012 | } bind def |
||
16255 | fschmid | 1013 | /ean2 dup load /uk.co.terryburton.bwipp defineresource pop |
1014 | end |
||
1015 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 1016 | %%EndData |
1017 | %%EndResource |
||
13293 | subik | 1018 | % --END ENCODER ean2-- |
1019 | |||
4460 | subik | 1020 | % --BEGIN ENCODER ean13-- |
18800 | fschmid | 1021 | % --REQUIRES preamble raiseerror renlinear ean5 ean2-- |
7162 | subik | 1022 | % --DESC: EAN-13 |
18800 | fschmid | 1023 | % --EXAM: 2112345678900 |
11277 | subik | 1024 | % --EXOP: includetext guardwhitespace |
1025 | % --RNDR: renlinear |
||
22439 | craig | 1026 | %%BeginResource: uk.co.terryburton.bwipp ean13 0.0 2018020400 91601 94632 |
18800 | fschmid | 1027 | %%BeginData: 215 ASCII Lines |
16255 | fschmid | 1028 | /setpacking where {pop currentpacking true setpacking} if |
1029 | 1 dict |
||
18800 | fschmid | 1030 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 1031 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
1032 | dup /ean2 dup /uk.co.terryburton.bwipp findresource put |
||
1033 | dup /ean5 dup /uk.co.terryburton.bwipp findresource put |
||
1034 | begin |
||
4460 | subik | 1035 | /ean13 { |
1036 | |||
20313 | craig | 1037 | 20 dict begin |
4460 | subik | 1038 | |
20313 | craig | 1039 | /options exch def % We are given an option string |
1040 | /barcode exch def % We are given a barcode string |
||
4460 | subik | 1041 | |
20313 | craig | 1042 | /dontdraw false def |
1043 | /includetext false def % Enable/disable text |
||
1044 | /textfont /Helvetica def |
||
1045 | /textsize 12 def |
||
1046 | /textxoffset -10 def |
||
1047 | /textyoffset -4 def |
||
1048 | /height 1 def |
||
1049 | /addongap 12 def |
||
1050 | /addontextfont (unset) def |
||
1051 | /addontextsize (unset) def |
||
1052 | /addontextxoffset (unset) def |
||
1053 | /addontextyoffset (unset) def |
||
13293 | subik | 1054 | |
20313 | craig | 1055 | % Parse the input options, either a string or a dict |
1056 | options type /stringtype eq { |
||
1057 | 1 dict begin |
||
1058 | options { |
||
1059 | token false eq {exit} if dup length string cvs (=) search |
||
1060 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
1061 | } loop |
||
1062 | currentdict end /options exch def |
||
1063 | } if |
||
1064 | options {def} forall |
||
13293 | subik | 1065 | |
20313 | craig | 1066 | /textfont textfont cvlit def |
1067 | /textsize textsize cvr def |
||
1068 | /textxoffset textxoffset cvr def |
||
1069 | /textyoffset textyoffset cvr def |
||
1070 | /height height cvr def |
||
1071 | /addongap addongap cvr def |
||
1072 | addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if |
||
1073 | addontextsize (unset) ne {/addontextsize addontextsize cvr def} if |
||
1074 | addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if |
||
1075 | addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if |
||
4460 | subik | 1076 | |
20313 | craig | 1077 | % Split off the addon |
1078 | barcode ( ) search { |
||
1079 | /barcode exch def |
||
1080 | pop |
||
1081 | /addon exch def |
||
1082 | } { |
||
1083 | pop |
||
1084 | /addon () def |
||
1085 | } ifelse |
||
18800 | fschmid | 1086 | |
20313 | craig | 1087 | % Validate the input |
1088 | barcode length 12 ne barcode length 13 ne and { |
||
1089 | /bwipp.ean13badLength (EAN-13 must be 12 or 13 digits) //raiseerror exec |
||
1090 | } if |
||
1091 | barcode { |
||
1092 | dup 48 lt exch 57 gt or { |
||
1093 | /bwipp.ean13badCharacter (EAN-13 must contain only digits) //raiseerror exec |
||
1094 | } if |
||
1095 | } forall |
||
1096 | addon length 0 ne addon length 2 ne and addon length 5 ne and { |
||
1097 | /bwipp.ean13badAddOnLength (Add-on for EAN-13 must be 2 or 5 digits) //raiseerror exec |
||
1098 | } if |
||
18800 | fschmid | 1099 | |
20313 | craig | 1100 | % Add checksum digit |
1101 | /pad 13 string def |
||
1102 | /checksum 0 def |
||
1103 | |||
1104 | /i exch def |
||
1105 | /barchar barcode i get 48 sub def |
||
1106 | i 2 mod 0 eq { |
||
1107 | /checksum barchar checksum add def |
||
1108 | } { |
||
1109 | /checksum barchar 3 mul checksum add def |
||
1110 | } ifelse |
||
1111 | } for |
||
1112 | /checksum 10 checksum 10 mod sub 10 mod def |
||
1113 | barcode length 13 eq { |
||
1114 | barcode 12 get checksum 48 add ne { |
||
1115 | /bwipp.ean13badCheckDigit (Incorrect EAN-13 check digit provided) //raiseerror exec |
||
1116 | } if |
||
1117 | } if |
||
1118 | pad 0 barcode putinterval % Add barcode to the start of the pad |
||
1119 | pad 12 checksum 48 add put % Put ascii for checksum at end of pad |
||
1120 | /barcode pad def |
||
4460 | subik | 1121 | |
20313 | craig | 1122 | % Create an array containing the character mappings |
1123 | /encs |
||
1124 | [ (3211) (2221) (2122) (1411) (1132) |
||
1125 | (1231) (1114) (1312) (1213) (3112) |
||
1126 | (111) (11111) (111) |
||
1127 | ] def |
||
4460 | subik | 1128 | |
20313 | craig | 1129 | % Create a string of the available characters |
1130 | /barchars (0123456789) def |
||
4460 | subik | 1131 | |
20313 | craig | 1132 | % Digits to mirror on left side |
1133 | /mirrormaps |
||
1134 | [ (000000) (001011) (001101) (001110) (010011) |
||
1135 | (011001) (011100) (010101) (010110) (011010) |
||
1136 | ] def |
||
4460 | subik | 1137 | |
20313 | craig | 1138 | /sbs 59 string def |
1139 | /txt 13 array def |
||
1140 | |||
1141 | % Put the start character |
||
1142 | sbs 0 encs 10 get putinterval |
||
4460 | subik | 1143 | |
20313 | craig | 1144 | % First digit - determine mirrormap by this and show before guard bars |
1145 | /mirrormap mirrormaps barcode 0 get 48 sub get def |
||
1146 | txt 0 [barcode 0 1 getinterval textxoffset textyoffset textfont textsize] put |
||
4460 | subik | 1147 | |
20313 | craig | 1148 | % Left side - performs mirroring |
1149 | 1 1 6 { |
||
1150 | % Lookup the encoding for the each barcode character |
||
1151 | /i exch def |
||
1152 | barcode i 1 getinterval barchars exch search |
||
1153 | pop % Discard true leaving pre |
||
1154 | length /indx exch def % indx is the length of pre |
||
1155 | pop pop % Discard seek and post |
||
1156 | /enc encs indx get def % Get the indxth encoding |
||
1157 | mirrormap i 1 sub get 49 eq { % Reverse enc if 1 in this position in mirrormap |
||
1158 | /enclen enc length def |
||
1159 | /revenc enclen string def |
||
1160 | |||
1161 | /j exch def |
||
1162 | /char enc j get def |
||
1163 | revenc enclen j sub 1 sub char put |
||
1164 | } for |
||
1165 | /enc revenc def |
||
1166 | } if |
||
1167 | sbs i 1 sub 4 mul 3 add enc putinterval % Put encoded digit into sbs |
||
1168 | txt i [barcode i 1 getinterval i 1 sub 7 mul 14 add textxoffset add textyoffset textfont textsize] put |
||
1169 | } for |
||
4460 | subik | 1170 | |
20313 | craig | 1171 | % Put the middle character |
1172 | sbs 7 1 sub 4 mul 3 add encs 11 get putinterval |
||
4460 | subik | 1173 | |
20313 | craig | 1174 | % Right side |
1175 | 7 1 12 { |
||
1176 | % Lookup the encoding for the each barcode character |
||
1177 | /i exch def |
||
1178 | barcode i 1 getinterval barchars exch search |
||
1179 | pop % Discard true leaving pre |
||
1180 | length /indx exch def % indx is the length of pre |
||
1181 | pop pop % Discard seek and post |
||
1182 | /enc encs indx get def % Get the indxth encoding |
||
1183 | sbs i 1 sub 4 mul 8 add enc putinterval % Put encoded digit into sbs |
||
1184 | txt i [barcode i 1 getinterval i 1 sub 7 mul 18 add textxoffset add textyoffset textfont textsize] put |
||
1185 | } for |
||
4460 | subik | 1186 | |
20313 | craig | 1187 | % Put the end character |
1188 | sbs 56 encs 12 get putinterval |
||
13293 | subik | 1189 | |
20313 | craig | 1190 | /sbs [sbs {48 sub} forall] def |
1191 | includetext { |
||
1192 | /bhs [height height 12{height .075 sub}repeat height height 12{height .075 sub}repeat height height] def |
||
1193 | /bbs [0 0 12{.075}repeat 0 0 12{.075}repeat 0 0] def |
||
1194 | } { |
||
1195 | /bhs [30{height}repeat] def |
||
1196 | /bbs [30{0}repeat] def |
||
1197 | /txt [] def |
||
1198 | } ifelse |
||
1199 | /guardrightypos 0 def |
||
13293 | subik | 1200 | |
20313 | craig | 1201 | % Append the addon |
1202 | addon () ne { |
||
1203 | /addopts << |
||
1204 | /dontdraw true |
||
1205 | /includetext true |
||
1206 | /height height 0.15 sub |
||
1207 | /textxoffset addontextxoffset (unset) ne {addontextxoffset} {95 addongap add} ifelse |
||
1208 | addontextyoffset (unset) ne {/textyoffset addontextyoffset} if |
||
1209 | /textsize addontextsize (unset) ne {addontextsize} {textsize} ifelse |
||
1210 | /textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse |
||
1211 | >> def |
||
1212 | addon length 2 eq {addon addopts //ean2 exec} if |
||
1213 | addon length 5 eq {addon addopts //ean5 exec} if |
||
1214 | /addcode exch def |
||
1215 | /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def |
||
1216 | /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def |
||
1217 | /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def |
||
1218 | /txt [txt aload pop addcode (txt) get aload pop] def |
||
1219 | /guardrightypos height 72 mul 6 sub def |
||
1220 | } if |
||
1221 | |||
1222 | % Return the arguments |
||
1223 | << |
||
1224 | /ren //renlinear |
||
1225 | /sbs sbs |
||
1226 | /bhs bhs |
||
1227 | /bbs bbs |
||
1228 | /txt txt |
||
1229 | /opt options |
||
1230 | /guardrightpos 10 |
||
1231 | /guardrightypos guardrightypos |
||
1232 | /borderbottom 5 |
||
1233 | >> |
||
13293 | subik | 1234 | |
20313 | craig | 1235 | dontdraw not //renlinear if |
13293 | subik | 1236 | |
20313 | craig | 1237 | end |
4460 | subik | 1238 | |
1239 | } bind def |
||
16255 | fschmid | 1240 | /ean13 dup load /uk.co.terryburton.bwipp defineresource pop |
1241 | end |
||
1242 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 1243 | %%EndData |
1244 | %%EndResource |
||
4460 | subik | 1245 | % --END ENCODER ean13-- |
1246 | |||
1247 | % --BEGIN ENCODER ean8-- |
||
18800 | fschmid | 1248 | % --REQUIRES preamble raiseerror renlinear ean5 ean2-- |
7162 | subik | 1249 | % --DESC: EAN-8 |
18800 | fschmid | 1250 | % --EXAM: 02345673 |
1251 | % --EXOP: includetext guardwhitespace |
||
11277 | subik | 1252 | % --RNDR: renlinear |
22439 | craig | 1253 | %%BeginResource: uk.co.terryburton.bwipp ean8 0.0 2018020400 88151 91083 |
18800 | fschmid | 1254 | %%BeginData: 196 ASCII Lines |
16255 | fschmid | 1255 | /setpacking where {pop currentpacking true setpacking} if |
1256 | 1 dict |
||
18800 | fschmid | 1257 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 1258 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
1259 | dup /ean2 dup /uk.co.terryburton.bwipp findresource put |
||
1260 | dup /ean5 dup /uk.co.terryburton.bwipp findresource put |
||
1261 | begin |
||
4460 | subik | 1262 | /ean8 { |
1263 | |||
20313 | craig | 1264 | 20 dict begin |
4460 | subik | 1265 | |
20313 | craig | 1266 | /options exch def % We are given an option string |
1267 | /barcode exch def % We are given a barcode string |
||
4460 | subik | 1268 | |
20313 | craig | 1269 | /dontdraw false def |
1270 | /includetext false def % Enable/disable text |
||
1271 | /textfont /Helvetica def |
||
1272 | /textsize 12 def |
||
1273 | /textxoffset 4 def |
||
1274 | /textyoffset -4 def |
||
1275 | /height 1 def |
||
1276 | /addongap 12 def |
||
1277 | /addontextfont (unset) def |
||
1278 | /addontextsize (unset) def |
||
1279 | /addontextxoffset (unset) def |
||
1280 | /addontextyoffset (unset) def |
||
1281 | |||
1282 | % Parse the input options, either a string or a dict |
||
1283 | options type /stringtype eq { |
||
1284 | 1 dict begin |
||
1285 | options { |
||
1286 | token false eq {exit} if dup length string cvs (=) search |
||
1287 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
1288 | } loop |
||
1289 | currentdict end /options exch def |
||
1290 | } if |
||
1291 | options {def} forall |
||
1292 | |||
1293 | /textfont textfont cvlit def |
||
1294 | /textsize textsize cvr def |
||
1295 | /textxoffset textxoffset cvr def |
||
1296 | /textyoffset textyoffset cvr def |
||
1297 | /height height cvr def |
||
1298 | /addongap addongap cvr def |
||
1299 | addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if |
||
1300 | addontextsize (unset) ne {/addontextsize addontextsize cvr def} if |
||
1301 | addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if |
||
1302 | addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if |
||
13293 | subik | 1303 | |
20313 | craig | 1304 | % Split off the addon |
1305 | barcode ( ) search { |
||
1306 | /barcode exch def |
||
1307 | pop |
||
1308 | /addon exch def |
||
1309 | } { |
||
1310 | pop |
||
1311 | /addon () def |
||
1312 | } ifelse |
||
16255 | fschmid | 1313 | |
20313 | craig | 1314 | % Validate the input |
1315 | barcode length 7 ne barcode length 8 ne and { |
||
1316 | /bwipp.ean8badLength (EAN-8 must be 7 or 8 digits) //raiseerror exec |
||
1317 | } if |
||
1318 | barcode { |
||
1319 | dup 48 lt exch 57 gt or { |
||
1320 | /bwipp.ean8badCharacter (EAN-8 must contain only digits) //raiseerror exec |
||
1321 | } if |
||
1322 | } forall |
||
1323 | addon length 0 ne addon length 2 ne and addon length 5 ne and { |
||
1324 | /bwipp.ean8badAddOnLength (Add-on for EAN-8 must be 2 or 5 digits) //raiseerror exec |
||
1325 | } if |
||
18800 | fschmid | 1326 | |
20313 | craig | 1327 | % Add checksum digit |
1328 | /pad 8 string def |
||
1329 | /checksum 0 def |
||
1330 | |||
1331 | /i exch def |
||
1332 | /barchar barcode i get 48 sub def |
||
1333 | i 2 mod 0 ne { |
||
1334 | /checksum barchar checksum add def |
||
1335 | } { |
||
1336 | /checksum barchar 3 mul checksum add def |
||
1337 | } ifelse |
||
1338 | } for |
||
1339 | /checksum 10 checksum 10 mod sub 10 mod def |
||
1340 | barcode length 8 eq { |
||
1341 | barcode 7 get checksum 48 add ne { |
||
1342 | /bwipp.ean8badCheckDigit (Incorrect EAN-8 check digit provided) //raiseerror exec |
||
1343 | } if |
||
1344 | } if |
||
1345 | pad 0 barcode putinterval % Add barcode to the start of the pad |
||
1346 | pad 7 checksum 48 add put % Put ascii for checksum at end of pad |
||
1347 | /barcode pad def |
||
1348 | |||
1349 | % Create an array containing the character mappings |
||
1350 | /encs |
||
1351 | [ (3211) (2221) (2122) (1411) (1132) |
||
1352 | (1231) (1114) (1312) (1213) (3112) |
||
1353 | (111) (11111) (111) |
||
1354 | ] def |
||
4460 | subik | 1355 | |
20313 | craig | 1356 | % Create a string of the available characters |
1357 | /barchars (0123456789) def |
||
4460 | subik | 1358 | |
20313 | craig | 1359 | /sbs 43 string def |
1360 | /txt 8 array def |
||
1361 | |||
1362 | % Put the start character |
||
1363 | sbs 0 encs 10 get putinterval |
||
4460 | subik | 1364 | |
20313 | craig | 1365 | % Left side |
1366 | |||
1367 | % Lookup the encoding for the each barcode character |
||
1368 | /i exch def |
||
1369 | barcode i 1 getinterval barchars exch search |
||
1370 | pop % Discard true leaving pre |
||
1371 | length /indx exch def % indx is the length of pre |
||
1372 | pop pop % Discard seek and post |
||
1373 | /enc encs indx get def % Get the indxth encoding |
||
1374 | sbs i 4 mul 3 add enc putinterval % Put encoded digit into sbs |
||
1375 | txt i [barcode i 1 getinterval i 7 mul textxoffset add textyoffset textfont textsize] put |
||
1376 | } for |
||
4460 | subik | 1377 | |
20313 | craig | 1378 | % Put the middle character |
1379 | sbs 4 4 mul 3 add encs 11 get putinterval |
||
4460 | subik | 1380 | |
20313 | craig | 1381 | % Right side |
1382 | 4 1 7 { |
||
1383 | % Lookup the encoding for the each barcode character |
||
1384 | /i exch def |
||
1385 | barcode i 1 getinterval barchars exch search |
||
1386 | pop % Discard true leaving pre |
||
1387 | length /indx exch def % indx is the length of pre |
||
1388 | pop pop % Discard seek and post |
||
1389 | /enc encs indx get def % Get the indxth encoding |
||
1390 | sbs i 4 mul 8 add enc putinterval % Put encoded digit into sbs |
||
1391 | txt i [barcode i 1 getinterval i 7 mul textxoffset add 4 add textyoffset textfont textsize] put |
||
1392 | } for |
||
4460 | subik | 1393 | |
20313 | craig | 1394 | % Put the end character |
1395 | sbs 40 encs 12 get putinterval |
||
4460 | subik | 1396 | |
20313 | craig | 1397 | /sbs [sbs {48 sub} forall] def |
1398 | includetext { |
||
1399 | /bhs [height height 8{height .075 sub}repeat height height 8{height .075 sub}repeat height height] def |
||
1400 | /bbs [0 0 8{.075}repeat 0 0 8{.075}repeat 0 0] def |
||
1401 | } { |
||
1402 | /bhs [22{height}repeat] def |
||
1403 | /bbs [22{0}repeat] def |
||
1404 | /txt [] def |
||
1405 | } ifelse |
||
1406 | /guardrightypos 0 def |
||
4460 | subik | 1407 | |
20313 | craig | 1408 | % Append the addon |
1409 | addon () ne { |
||
1410 | /addopts << |
||
1411 | /dontdraw true |
||
1412 | /includetext true |
||
1413 | /height height 0.15 sub |
||
1414 | /textxoffset addontextxoffset (unset) ne {addontextxoffset} {67 addongap add} ifelse |
||
1415 | addontextyoffset (unset) ne {/textyoffset addontextyoffset} if |
||
1416 | /textsize addontextsize (unset) ne {addontextsize} {textsize} ifelse |
||
1417 | /textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse |
||
1418 | >> def |
||
1419 | addon length 2 eq {addon addopts //ean2 exec} if |
||
1420 | addon length 5 eq {addon addopts //ean5 exec} if |
||
1421 | /addcode exch def |
||
1422 | /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def |
||
1423 | /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def |
||
1424 | /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def |
||
1425 | /txt [txt aload pop addcode (txt) get aload pop] def |
||
1426 | /guardrightypos height 72 mul 6 sub def |
||
1427 | } if |
||
13293 | subik | 1428 | |
20313 | craig | 1429 | % Return the arguments |
1430 | << |
||
1431 | /ren //renlinear |
||
1432 | /sbs sbs |
||
1433 | /bhs bhs |
||
1434 | /bbs bbs |
||
1435 | /txt txt |
||
1436 | /opt options |
||
1437 | /guardleftpos 10 |
||
1438 | /guardrightpos 10 |
||
1439 | /guardrightypos guardrightypos |
||
1440 | /borderbottom 5 |
||
1441 | >> |
||
13293 | subik | 1442 | |
20313 | craig | 1443 | dontdraw not //renlinear if |
13293 | subik | 1444 | |
20313 | craig | 1445 | end |
4460 | subik | 1446 | |
1447 | } bind def |
||
16255 | fschmid | 1448 | /ean8 dup load /uk.co.terryburton.bwipp defineresource pop |
1449 | end |
||
1450 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 1451 | %%EndData |
1452 | %%EndResource |
||
4460 | subik | 1453 | % --END ENCODER ean8-- |
1454 | |||
1455 | % --BEGIN ENCODER upca-- |
||
18800 | fschmid | 1456 | % --REQUIRES preamble raiseerror renlinear ean5 ean2-- |
7162 | subik | 1457 | % --DESC: UPC-A |
18800 | fschmid | 1458 | % --EXAM: 416000336108 |
11277 | subik | 1459 | % --EXOP: includetext |
1460 | % --RNDR: renlinear |
||
22439 | craig | 1461 | %%BeginResource: uk.co.terryburton.bwipp upca 0.0 2018020400 97138 100087 |
19685 | fschmid | 1462 | %%BeginData: 248 ASCII Lines |
16255 | fschmid | 1463 | /setpacking where {pop currentpacking true setpacking} if |
1464 | 1 dict |
||
18800 | fschmid | 1465 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 1466 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
1467 | dup /ean2 dup /uk.co.terryburton.bwipp findresource put |
||
1468 | dup /ean5 dup /uk.co.terryburton.bwipp findresource put |
||
1469 | begin |
||
4460 | subik | 1470 | /upca { |
1471 | |||
20313 | craig | 1472 | 20 dict begin |
4460 | subik | 1473 | |
20313 | craig | 1474 | /options exch def |
1475 | /barcode exch def % We are given a barcode string |
||
4460 | subik | 1476 | |
20313 | craig | 1477 | /dontdraw false def |
1478 | /includetext false def % Enable/disable text |
||
1479 | /textfont /Helvetica def |
||
1480 | /textsize 12 def |
||
1481 | /textxoffset -7 def |
||
1482 | /textyoffset -4 def |
||
1483 | /height 1 def |
||
1484 | /addongap 12 def |
||
1485 | /addontextfont (unset) def |
||
1486 | /addontextsize (unset) def |
||
1487 | /addontextxoffset (unset) def |
||
1488 | /addontextyoffset (unset) def |
||
13293 | subik | 1489 | |
20313 | craig | 1490 | % Parse the input options |
1491 | options type /stringtype eq { |
||
1492 | 1 dict begin |
||
1493 | options { |
||
1494 | token false eq {exit} if dup length string cvs (=) search |
||
1495 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
1496 | } loop |
||
1497 | currentdict end /options exch def |
||
1498 | } if |
||
1499 | options {def} forall |
||
13293 | subik | 1500 | |
20313 | craig | 1501 | /textfont textfont cvlit def |
1502 | /textsize textsize cvr def |
||
1503 | /textxoffset textxoffset cvr def |
||
1504 | /textyoffset textyoffset cvr def |
||
1505 | /height height cvr def |
||
1506 | /addongap addongap cvr def |
||
1507 | addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if |
||
1508 | addontextsize (unset) ne {/addontextsize addontextsize cvr def} if |
||
1509 | addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if |
||
1510 | addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if |
||
18224 | jghali | 1511 | |
20313 | craig | 1512 | % Split off the addon |
1513 | barcode ( ) search { |
||
1514 | /barcode exch def |
||
1515 | pop |
||
1516 | /addon exch def |
||
1517 | } { |
||
1518 | pop |
||
1519 | /addon () def |
||
1520 | } ifelse |
||
18800 | fschmid | 1521 | |
20313 | craig | 1522 | % Expand a given UPC-E |
1523 | barcode length 7 eq barcode length 8 eq or { |
||
1524 | % Validate the input |
||
1525 | barcode { |
||
1526 | dup 48 lt exch 57 gt or { |
||
1527 | /bwipp.upcAupcEbadCharacter (UPC-E must contain only digits) //raiseerror exec |
||
1528 | } if |
||
1529 | } forall |
||
1530 | barcode 0 get dup 48 ne exch 49 ne and { |
||
1531 | /bwipp.upcAupcEbadNumberSystem (UPC-E must have number system 0 or 1) //raiseerror exec |
||
1532 | } if |
||
1533 | 1 { % Common exit |
||
1534 | /upcacode barcode length 8 eq {12} {11} ifelse string def |
||
1535 | barcode 6 get 48 sub 2 le { |
||
1536 | upcacode 0 barcode 0 3 getinterval putinterval |
||
1537 | upcacode 3 barcode 6 1 getinterval putinterval |
||
1538 | upcacode 4 (0000) putinterval |
||
1539 | upcacode 8 barcode 3 3 getinterval putinterval |
||
1540 | exit |
||
1541 | } if |
||
1542 | barcode 6 get 48 sub 3 eq { |
||
1543 | upcacode 0 barcode 0 4 getinterval putinterval |
||
1544 | upcacode 4 (00000) putinterval |
||
1545 | upcacode 9 barcode 4 2 getinterval putinterval |
||
1546 | exit |
||
1547 | } if |
||
1548 | barcode 6 get 48 sub 4 eq { |
||
1549 | upcacode 0 barcode 0 5 getinterval putinterval |
||
1550 | upcacode 5 (00000) putinterval |
||
1551 | upcacode 10 barcode 5 1 getinterval putinterval |
||
1552 | exit |
||
1553 | } if |
||
1554 | barcode 6 get 48 sub 5 ge { |
||
1555 | upcacode 0 barcode 0 6 getinterval putinterval |
||
1556 | upcacode 6 (0000) putinterval |
||
1557 | upcacode 10 barcode 6 1 getinterval putinterval |
||
1558 | exit |
||
1559 | } if |
||
1560 | } repeat |
||
1561 | barcode length 8 eq { |
||
1562 | upcacode 11 barcode 7 1 getinterval putinterval |
||
1563 | } if |
||
1564 | /barcode upcacode def |
||
1565 | } if |
||
19685 | fschmid | 1566 | |
20313 | craig | 1567 | % Validate the input |
1568 | barcode length 11 ne barcode length 12 ne and { |
||
1569 | /bwipp.upcAbadLength (UPC-A must be 11 or 12 digits) //raiseerror exec |
||
1570 | } if |
||
1571 | barcode { |
||
1572 | dup 48 lt exch 57 gt or { |
||
1573 | /bwipp.upcAbadCharacter (UPC-A must contain only digits) //raiseerror exec |
||
1574 | } if |
||
1575 | } forall |
||
1576 | addon length 0 ne addon length 2 ne and addon length 5 ne and { |
||
1577 | /bwipp.upcAbadAddOnLength (Add-on for UPC-A must be 2 or 5 digits) //raiseerror exec |
||
1578 | } if |
||
1579 | |||
1580 | % Add checksum digit to barcode |
||
1581 | /pad 12 string def % Create pad one bigger than barcode |
||
1582 | /checksum 0 def |
||
1583 | |||
1584 | /i exch def |
||
1585 | /barchar barcode i get 48 sub def |
||
1586 | i 2 mod 0 ne { |
||
1587 | /checksum checksum barchar add def |
||
1588 | } { |
||
1589 | /checksum checksum barchar 3 mul add def |
||
1590 | } ifelse |
||
1591 | } for |
||
1592 | /checksum 10 checksum 10 mod sub 10 mod def |
||
1593 | barcode length 12 eq { |
||
1594 | barcode 11 get checksum 48 add ne { |
||
1595 | /bwipp.upcAbadCheckDigit (Incorrect UPC check digit provided) //raiseerror exec |
||
1596 | } if |
||
1597 | } if |
||
1598 | pad 0 barcode putinterval % Add barcode to the start of the pad |
||
1599 | pad 11 checksum 48 add put % Put ascii for checksum at end of pad |
||
1600 | /barcode pad def |
||
4460 | subik | 1601 | |
20313 | craig | 1602 | % Create an array containing the character mappings |
1603 | /encs |
||
1604 | [ (3211) (2221) (2122) (1411) (1132) |
||
1605 | (1231) (1114) (1312) (1213) (3112) |
||
1606 | (111) (11111) (111) |
||
1607 | ] def |
||
4460 | subik | 1608 | |
20313 | craig | 1609 | % Create a string of the available characters |
1610 | /barchars (0123456789) def |
||
4460 | subik | 1611 | |
20313 | craig | 1612 | /sbs 59 string def |
1613 | /txt 12 array def |
||
4460 | subik | 1614 | |
20313 | craig | 1615 | % Put the start character |
1616 | sbs 0 encs 10 get putinterval |
||
4460 | subik | 1617 | |
20313 | craig | 1618 | % Left side |
1619 | |||
1620 | % Lookup the encoding for the each barcode character |
||
1621 | /i exch def |
||
1622 | barcode i 1 getinterval barchars exch search |
||
1623 | pop % Discard true leaving pre |
||
1624 | length /indx exch def % indx is the length of pre |
||
1625 | pop pop % Discard seek and post |
||
1626 | /enc encs indx get def % Get the indxth encoding |
||
1627 | sbs i 4 mul 3 add enc putinterval % Put encoded digit into sbs |
||
1628 | i 0 eq { % First digit is before the guard bars |
||
1629 | txt 0 [barcode 0 1 getinterval textxoffset textyoffset textfont textsize 2 sub] put |
||
1630 | } { |
||
1631 | txt i [barcode i 1 getinterval i 7 mul 11 add textxoffset add textyoffset textfont textsize] put |
||
1632 | } ifelse |
||
1633 | } for |
||
4460 | subik | 1634 | |
20313 | craig | 1635 | % Put the middle character |
1636 | sbs 6 4 mul 3 add encs 11 get putinterval |
||
4460 | subik | 1637 | |
20313 | craig | 1638 | % Right side |
1639 | 6 1 11 { |
||
1640 | % Lookup the encoding for the each barcode character |
||
1641 | /i exch def |
||
1642 | barcode i 1 getinterval barchars exch search |
||
1643 | pop % Discard true leaving pre |
||
1644 | length /indx exch def % indx is the length of pre |
||
1645 | pop pop % Discard seek and post |
||
1646 | /enc encs indx get def % Get the indxth encoding |
||
1647 | sbs i 4 mul 8 add enc putinterval % Put encoded digit into sbs |
||
1648 | i 11 eq { % Last digit is after guard bars |
||
1649 | txt 11 [barcode 11 1 getinterval textxoffset 103 add textyoffset textfont textsize 2 sub] put |
||
1650 | } { |
||
1651 | txt i [barcode i 1 getinterval i 7 mul textxoffset add 15 add textyoffset textfont textsize] put |
||
1652 | } ifelse |
||
1653 | } for |
||
4460 | subik | 1654 | |
20313 | craig | 1655 | % Put the end character |
1656 | sbs 56 encs 12 get putinterval |
||
4460 | subik | 1657 | |
20313 | craig | 1658 | /sbs [sbs {48 sub} forall] def |
1659 | includetext { |
||
1660 | /bhs [4{height}repeat 10{height .075 sub}repeat height height 10{height .075 sub}repeat 4{height}repeat] def |
||
1661 | /bbs [0 0 0 0 10{.075}repeat 0 0 10{.075}repeat 0 0 0 0] def |
||
1662 | } { |
||
1663 | /bhs [30{height}repeat] def |
||
1664 | /bbs [30{0}repeat] def |
||
1665 | /txt [] def |
||
1666 | } ifelse |
||
1667 | /guardrightypos 0 def |
||
4460 | subik | 1668 | |
20313 | craig | 1669 | % Append the addon |
1670 | addon () ne { |
||
1671 | /addopts << |
||
1672 | /dontdraw true |
||
1673 | /includetext true |
||
1674 | /height height 0.15 sub |
||
1675 | /textxoffset addontextxoffset (unset) ne {addontextxoffset} {95 addongap add} ifelse |
||
1676 | addontextyoffset (unset) ne {/textyoffset addontextyoffset} if |
||
1677 | /textsize addontextsize (unset) ne {addontextsize} {textsize} ifelse |
||
1678 | /textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse |
||
1679 | >> def |
||
1680 | addon length 2 eq {addon addopts //ean2 exec} if |
||
1681 | addon length 5 eq {addon addopts //ean5 exec} if |
||
1682 | /addcode exch def |
||
1683 | /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def |
||
1684 | /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def |
||
1685 | /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def |
||
1686 | /txt [txt aload pop addcode (txt) get aload pop] def |
||
1687 | /guardrightypos height 72 mul 6 sub def |
||
1688 | } if |
||
13293 | subik | 1689 | |
20313 | craig | 1690 | % Return the arguments |
1691 | << |
||
1692 | /ren //renlinear |
||
1693 | /sbs sbs |
||
1694 | /bhs bhs |
||
1695 | /bbs bbs |
||
1696 | /txt txt |
||
1697 | /opt options |
||
1698 | /guardrightpos 10 |
||
1699 | /guardrightypos guardrightypos |
||
1700 | /borderbottom 5 |
||
1701 | >> |
||
13293 | subik | 1702 | |
20313 | craig | 1703 | dontdraw not //renlinear if |
13293 | subik | 1704 | |
20313 | craig | 1705 | end |
4460 | subik | 1706 | |
1707 | } bind def |
||
16255 | fschmid | 1708 | /upca dup load /uk.co.terryburton.bwipp defineresource pop |
1709 | end |
||
1710 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 1711 | %%EndData |
1712 | %%EndResource |
||
4460 | subik | 1713 | % --END ENCODER upca-- |
1714 | |||
1715 | % --BEGIN ENCODER upce-- |
||
18800 | fschmid | 1716 | % --REQUIRES preamble raiseerror renlinear ean5 ean2-- |
7162 | subik | 1717 | % --DESC: UPC-E |
18224 | jghali | 1718 | % --EXAM: 00123457 |
18800 | fschmid | 1719 | % --EXOP: includetext |
11277 | subik | 1720 | % --RNDR: renlinear |
22439 | craig | 1721 | %%BeginResource: uk.co.terryburton.bwipp upce 0.0 2018020400 102967 109183 |
19685 | fschmid | 1722 | %%BeginData: 287 ASCII Lines |
16255 | fschmid | 1723 | /setpacking where {pop currentpacking true setpacking} if |
1724 | 1 dict |
||
18800 | fschmid | 1725 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 1726 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
1727 | dup /ean2 dup /uk.co.terryburton.bwipp findresource put |
||
1728 | dup /ean5 dup /uk.co.terryburton.bwipp findresource put |
||
1729 | begin |
||
4460 | subik | 1730 | /upce { |
1731 | |||
20313 | craig | 1732 | 20 dict begin |
4460 | subik | 1733 | |
20313 | craig | 1734 | /options exch def % We are given an option string |
1735 | /barcode exch def % We are given a barcode string |
||
4460 | subik | 1736 | |
20313 | craig | 1737 | /dontdraw false def |
1738 | /includetext false def % Enable/disable text |
||
1739 | /textfont /Helvetica def |
||
1740 | /textsize 12 def |
||
1741 | /textxoffset -7 def |
||
1742 | /textyoffset -4 def |
||
1743 | /height 1 def |
||
1744 | /addongap 12 def |
||
1745 | /addontextfont (unset) def |
||
1746 | /addontextsize (unset) def |
||
1747 | /addontextxoffset (unset) def |
||
1748 | /addontextyoffset (unset) def |
||
1749 | |||
1750 | % Parse the input options |
||
1751 | options type /stringtype eq { |
||
1752 | 1 dict begin |
||
1753 | options { |
||
1754 | token false eq {exit} if dup length string cvs (=) search |
||
1755 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
1756 | } loop |
||
1757 | currentdict end /options exch def |
||
1758 | } if |
||
1759 | options {def} forall |
||
1760 | |||
1761 | /textfont textfont cvlit def |
||
1762 | /textsize textsize cvr def |
||
1763 | /textxoffset textxoffset cvr def |
||
1764 | /textyoffset textyoffset cvr def |
||
1765 | /height height cvr def |
||
1766 | /addongap addongap cvr def |
||
1767 | addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if |
||
1768 | addontextsize (unset) ne {/addontextsize addontextsize cvr def} if |
||
1769 | addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if |
||
1770 | addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if |
||
4460 | subik | 1771 | |
20313 | craig | 1772 | % Split off the addon |
1773 | barcode ( ) search { |
||
1774 | /barcode exch def |
||
1775 | pop |
||
1776 | /addon exch def |
||
1777 | } { |
||
1778 | pop |
||
1779 | /addon () def |
||
1780 | } ifelse |
||
13293 | subik | 1781 | |
20313 | craig | 1782 | % Compress a given UPC-A |
1783 | barcode length 11 eq barcode length 12 eq or { |
||
1784 | % Validate the input |
||
1785 | barcode { |
||
1786 | dup 48 lt exch 57 gt or { |
||
1787 | /bwipp.upcEupcAbadCharacter (UPC-A must contain only digits) //raiseerror exec |
||
1788 | } if |
||
1789 | } forall |
||
1790 | 1 { % Common exit |
||
1791 | /upcecode barcode length 12 eq {8} {7} ifelse string def |
||
1792 | barcode 3 get 48 sub 2 le barcode 4 4 getinterval (0000) eq and { |
||
1793 | upcecode 0 barcode 0 3 getinterval putinterval |
||
1794 | upcecode 3 barcode 8 3 getinterval putinterval |
||
1795 | upcecode 6 barcode 3 1 getinterval putinterval |
||
1796 | exit |
||
1797 | } if |
||
1798 | barcode 4 5 getinterval (00000) eq { |
||
1799 | upcecode 0 barcode 0 4 getinterval putinterval |
||
1800 | upcecode 4 barcode 9 2 getinterval putinterval |
||
1801 | upcecode 6 (3) putinterval |
||
1802 | exit |
||
1803 | } if |
||
1804 | barcode 5 5 getinterval (00000) eq { |
||
1805 | upcecode 0 barcode 0 5 getinterval putinterval |
||
1806 | upcecode 5 barcode 10 1 getinterval putinterval |
||
1807 | upcecode 6 (4) putinterval |
||
1808 | exit |
||
1809 | } if |
||
1810 | barcode 10 get 48 sub 5 ge barcode 6 4 getinterval (0000) eq and { |
||
1811 | upcecode 0 barcode 0 6 getinterval putinterval |
||
1812 | upcecode 6 barcode 10 1 getinterval putinterval |
||
1813 | exit |
||
1814 | } if |
||
1815 | /bwipp.upcEupcAnotCompressible (UPC-A cannot be converted to a UPC-E) //raiseerror exec |
||
1816 | } repeat |
||
1817 | barcode length 12 eq { |
||
1818 | upcecode 7 barcode 11 1 getinterval putinterval |
||
1819 | } if |
||
1820 | /barcode upcecode def |
||
1821 | } if |
||
19685 | fschmid | 1822 | |
20313 | craig | 1823 | % Validate the input |
1824 | barcode length 7 ne barcode length 8 ne and { |
||
1825 | /bwipp.upcEbadLength (UPC-E must be 7 or 8 digits) //raiseerror exec |
||
1826 | } if |
||
1827 | barcode { |
||
1828 | dup 48 lt exch 57 gt or { |
||
1829 | /bwipp.upcEbadCharacter (UPC-E must contain only digits) //raiseerror exec |
||
1830 | } if |
||
1831 | } forall |
||
1832 | addon length 0 ne addon length 2 ne and addon length 5 ne and { |
||
1833 | /bwipp.upcEbadAddOnLength (Add-on for UPC-E must be 2 or 5 digits) //raiseerror exec |
||
1834 | } if |
||
18800 | fschmid | 1835 | |
20313 | craig | 1836 | % Ensure 0 or 1 number systems |
1837 | barcode 0 get dup 48 ne exch 49 ne and { |
||
1838 | /bwipp.upcEbadNumberSystem (UPC-E must have number system 0 or 1) //raiseerror exec |
||
1839 | } if |
||
18800 | fschmid | 1840 | |
20313 | craig | 1841 | % Create an array containing the character mappings |
1842 | /encs |
||
1843 | [ (3211) (2221) (2122) (1411) (1132) |
||
1844 | (1231) (1114) (1312) (1213) (3112) |
||
1845 | (111) (111111) |
||
1846 | ] def |
||
4460 | subik | 1847 | |
20313 | craig | 1848 | % Create a string of the available characters |
1849 | /barchars (0123456789) def |
||
4460 | subik | 1850 | |
20313 | craig | 1851 | /mirrormaps |
1852 | [ (000111) (001011) (001101) (001110) (010011) |
||
1853 | (011001) (011100) (010101) (010110) (011010) |
||
1854 | ] def |
||
4460 | subik | 1855 | |
20313 | craig | 1856 | % Derive the equivalent UPC-A for its checksum |
1857 | 1 { % Common exit |
||
1858 | /upcacode 11 string def |
||
1859 | barcode 6 get 48 sub 2 le { |
||
1860 | upcacode 0 barcode 0 3 getinterval putinterval |
||
1861 | upcacode 3 barcode 6 1 getinterval putinterval |
||
1862 | upcacode 4 (0000) putinterval |
||
1863 | upcacode 8 barcode 3 3 getinterval putinterval |
||
1864 | exit |
||
1865 | } if |
||
1866 | barcode 6 get 48 sub 3 eq { |
||
1867 | upcacode 0 barcode 0 4 getinterval putinterval |
||
1868 | upcacode 4 (00000) putinterval |
||
1869 | upcacode 9 barcode 4 2 getinterval putinterval |
||
1870 | exit |
||
1871 | } if |
||
1872 | barcode 6 get 48 sub 4 eq { |
||
1873 | upcacode 0 barcode 0 5 getinterval putinterval |
||
1874 | upcacode 5 (00000) putinterval |
||
1875 | upcacode 10 barcode 5 1 getinterval putinterval |
||
1876 | exit |
||
1877 | } if |
||
1878 | barcode 6 get 48 sub 5 ge { |
||
1879 | upcacode 0 barcode 0 6 getinterval putinterval |
||
1880 | upcacode 6 (0000) putinterval |
||
1881 | upcacode 10 barcode 6 1 getinterval putinterval |
||
1882 | exit |
||
1883 | } if |
||
1884 | } repeat |
||
1885 | /checksum 0 def |
||
1886 | |||
1887 | /i exch def |
||
1888 | /barchar upcacode i get 48 sub def |
||
1889 | i 2 mod 0 ne { |
||
1890 | /checksum checksum barchar add def |
||
1891 | } { |
||
1892 | /checksum checksum barchar 3 mul add def |
||
1893 | } ifelse |
||
1894 | } for |
||
1895 | /checksum 10 checksum 10 mod sub 10 mod def |
||
1896 | barcode length 8 eq { |
||
1897 | barcode 7 get checksum 48 add ne { |
||
1898 | /bwipp.upcEbadCheckDigit (Incorrect UPC check digit provided) //raiseerror exec |
||
1899 | } if |
||
1900 | } if |
||
1901 | /pad 8 string def |
||
1902 | pad 0 barcode putinterval % Add barcode to the start of the pad |
||
1903 | pad 7 checksum 48 add put % Put ascii for checksum at end of pad |
||
1904 | /barcode pad def |
||
1905 | /txt 8 array def |
||
1906 | txt 0 [barcode 0 1 getinterval textxoffset textyoffset textfont textsize 2 sub] put |
||
4460 | subik | 1907 | |
20313 | craig | 1908 | % Determine the mirror map based on checksum |
1909 | /mirrormap mirrormaps checksum get def |
||
4460 | subik | 1910 | |
20313 | craig | 1911 | % Invert the mirrormap if we are using a non-zero number system |
1912 | barcode 0 get 48 eq { |
||
1913 | /invt mirrormap length string def |
||
1914 | |||
1915 | /i exch def |
||
1916 | mirrormap i get 48 eq { |
||
1917 | invt i 49 put |
||
1918 | } { |
||
1919 | invt i 48 put |
||
1920 | } ifelse |
||
1921 | } for |
||
1922 | /mirrormap invt def |
||
1923 | } if |
||
4460 | subik | 1924 | |
20313 | craig | 1925 | /sbs 33 string def |
4460 | subik | 1926 | |
20313 | craig | 1927 | % Put the start character |
1928 | sbs 0 encs 10 get putinterval |
||
4460 | subik | 1929 | |
20313 | craig | 1930 | 1 1 6 { |
1931 | /i exch def |
||
1932 | % Lookup the encoding for the each barcode character |
||
1933 | barcode i 1 getinterval barchars exch search |
||
1934 | pop % Discard true leaving pre |
||
1935 | length /indx exch def % indx is the length of pre |
||
1936 | pop pop % Discard seek and post |
||
1937 | /enc encs indx get def % Get the indxth encoding |
||
1938 | mirrormap i 1 sub get 49 eq { % Reverse enc if 1 in this position in mirrormap |
||
1939 | /enclen enc length def |
||
1940 | /revenc enclen string def |
||
1941 | |||
1942 | /j exch def |
||
1943 | /char enc j get def |
||
1944 | revenc enclen j sub 1 sub char put |
||
1945 | } for |
||
1946 | /enc revenc def |
||
1947 | } if |
||
1948 | sbs i 1 sub 4 mul 3 add enc putinterval % Put encoded digit into sbs |
||
1949 | txt i [barcode i 1 getinterval i 1 sub 7 mul 11 add textxoffset add textyoffset textfont textsize] put |
||
1950 | } for |
||
4460 | subik | 1951 | |
20313 | craig | 1952 | txt 7 [barcode 7 1 getinterval 6 7 mul 18 add textxoffset add textyoffset textfont textsize 2 sub] put |
4460 | subik | 1953 | |
20313 | craig | 1954 | % Put the end character |
1955 | sbs 27 encs 11 get putinterval |
||
4460 | subik | 1956 | |
20313 | craig | 1957 | /sbs [sbs {48 sub} forall] def |
1958 | includetext { |
||
1959 | /bhs [height height 12{height .075 sub}repeat height height height] def |
||
1960 | /bbs [0 0 12{.075}repeat 0 0 0] def |
||
1961 | } { |
||
1962 | /bhs [17{height}repeat] def |
||
1963 | /bbs [17{0}repeat] def |
||
1964 | /txt [] def |
||
1965 | } ifelse |
||
1966 | /guardrightypos 0 def |
||
4460 | subik | 1967 | |
20313 | craig | 1968 | % Append the addon |
1969 | addon () ne { |
||
1970 | /addopts << |
||
1971 | /dontdraw true |
||
1972 | /includetext true |
||
1973 | /height height 0.15 sub |
||
1974 | /textxoffset addontextxoffset (unset) ne {addontextxoffset} {51 addongap add} ifelse |
||
1975 | addontextyoffset (unset) ne {/textyoffset addontextyoffset} if |
||
1976 | /textsize addontextsize (unset) ne {addontextsize} {textsize} ifelse |
||
1977 | /textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse |
||
1978 | >> def |
||
1979 | addon length 2 eq {addon addopts //ean2 exec} if |
||
1980 | addon length 5 eq {addon addopts //ean5 exec} if |
||
1981 | /addcode exch def |
||
1982 | /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def |
||
1983 | /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def |
||
1984 | /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def |
||
1985 | /txt [txt aload pop addcode (txt) get aload pop] def |
||
1986 | /guardrightypos height 72 mul 6 sub def |
||
1987 | } if |
||
4460 | subik | 1988 | |
20313 | craig | 1989 | % Return the arguments |
1990 | << |
||
1991 | /ren //renlinear |
||
1992 | /sbs sbs |
||
1993 | /bhs bhs |
||
1994 | /bbs bbs |
||
1995 | /txt txt |
||
1996 | /opt options |
||
1997 | /guardrightpos 10 |
||
1998 | /guardrightypos guardrightypos |
||
1999 | /borderbottom 5 |
||
2000 | >> |
||
4460 | subik | 2001 | |
20313 | craig | 2002 | dontdraw not //renlinear if |
4460 | subik | 2003 | |
20313 | craig | 2004 | end |
4460 | subik | 2005 | |
2006 | } bind def |
||
16255 | fschmid | 2007 | /upce dup load /uk.co.terryburton.bwipp defineresource pop |
2008 | end |
||
2009 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 2010 | %%EndData |
2011 | %%EndResource |
||
13293 | subik | 2012 | % --END ENCODER upce-- |
4460 | subik | 2013 | |
2014 | % --BEGIN ENCODER isbn-- |
||
18800 | fschmid | 2015 | % --REQUIRES preamble raiseerror renlinear ean5 ean2 ean13-- |
7162 | subik | 2016 | % --DESC: ISBN |
18800 | fschmid | 2017 | % --EXAM: 978-1-56581-231-4 52250 |
11277 | subik | 2018 | % --EXOP: includetext guardwhitespace |
2019 | % --RNDR: renlinear |
||
22439 | craig | 2020 | %%BeginResource: uk.co.terryburton.bwipp isbn 0.0 2018020400 104089 106810 |
19685 | fschmid | 2021 | %%BeginData: 252 ASCII Lines |
16255 | fschmid | 2022 | /setpacking where {pop currentpacking true setpacking} if |
2023 | 1 dict |
||
18800 | fschmid | 2024 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 2025 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
2026 | dup /ean13 dup /uk.co.terryburton.bwipp findresource put |
||
2027 | begin |
||
4460 | subik | 2028 | /isbn { |
2029 | |||
20313 | craig | 2030 | 20 dict begin |
4460 | subik | 2031 | |
20313 | craig | 2032 | /options exch def % We are given an options string |
2033 | /barcode exch def % We are given the isbn text with dashes |
||
4460 | subik | 2034 | |
20313 | craig | 2035 | /dontdraw false def |
2036 | /includetext false def % Enable/disable ISBN text |
||
2037 | /isbntextfont /Courier def |
||
2038 | /isbntextsize 9 def |
||
2039 | /isbntextxoffset (unset) def |
||
2040 | /isbntextyoffset (unset) def |
||
2041 | /height 1 def |
||
2042 | /addongap 12 def |
||
2043 | /legacy false def |
||
2044 | |||
2045 | % Parse the input options |
||
2046 | options type /stringtype eq { |
||
2047 | 1 dict begin |
||
2048 | options { |
||
2049 | token false eq {exit} if dup length string cvs (=) search |
||
2050 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
2051 | } loop |
||
2052 | currentdict end /options exch def |
||
2053 | } if |
||
2054 | options {def} forall |
||
2055 | |||
2056 | /isbntextfont isbntextfont cvlit def |
||
2057 | /isbntextsize isbntextsize cvr def |
||
2058 | isbntextxoffset (unset) ne {/isbntextxoffset isbntextxoffset cvr def} if |
||
2059 | isbntextyoffset (unset) ne {/isbntextyoffset isbntextyoffset cvr def} if |
||
2060 | /height height cvr def |
||
2061 | /addongap addongap cvr def |
||
16255 | fschmid | 2062 | |
20313 | craig | 2063 | % Split off the addon |
2064 | barcode ( ) search { |
||
2065 | /barcode exch def |
||
2066 | pop |
||
2067 | /addon exch def |
||
2068 | } { |
||
2069 | pop |
||
2070 | /addon () def |
||
2071 | } ifelse |
||
18800 | fschmid | 2072 | |
20313 | craig | 2073 | % Validate the input |
2074 | barcode length 15 ne barcode length 17 ne and |
||
2075 | barcode length 11 ne barcode length 13 ne and and { |
||
2076 | /bwipp.isbnBadLength (ISBN-13 must be 15 or 17 characters including dashes. ISBN-10 must be 11 or 13 characters including dashes) //raiseerror exec |
||
2077 | } if |
||
2078 | addon length 0 ne addon length 2 ne and addon length 5 ne and { |
||
2079 | /bwipp.isbnBadAddOnLength (Add-on for ISBN must be 2 or 5 digits) //raiseerror exec |
||
2080 | } if |
||
2081 | barcode length 15 ge { % ISBN-13 |
||
2082 | barcode 0 4 getinterval dup (978-) ne exch (979-) ne and { |
||
2083 | /bwipp.isbn13badPrefix (ISBN-13 prefix must be 978- or 979-) //raiseerror exec |
||
2084 | } if |
||
2085 | /wasdash false def /numdash 0 def /numdigit 0 def |
||
2086 | barcode 5 9 getinterval { |
||
2087 | dup |
||
2088 | 45 eq { |
||
2089 | wasdash { |
||
2090 | /bwipp.isbn13adjacentDashes (ISBN-13 does not permit adjacent dashes) //raiseerror exec |
||
2091 | } if |
||
2092 | /wasdash true def |
||
2093 | /numdash numdash 1 add def |
||
2094 | } if |
||
2095 | dup 48 ge exch 57 le and { |
||
2096 | /wasdash false def |
||
2097 | /numdigit numdigit 1 add def |
||
2098 | } if |
||
2099 | } forall |
||
2100 | numdash 2 ne numdigit 7 ne or { |
||
2101 | /bwipp.isbn13numDashesDigits (Incorrect number of dashes and digits for ISBN-13) //raiseerror exec |
||
2102 | } if |
||
2103 | barcode 14 get dup 48 lt exch 57 gt or { |
||
2104 | /bwipp.isbn13character15 (ISBN-13 character 15 must be a digit) //raiseerror exec |
||
2105 | } if |
||
2106 | barcode length 17 eq { |
||
2107 | barcode 15 1 getinterval (-) ne { |
||
2108 | /bwipp.isbn13character16 (ISBN-13 penultimate character must be a dash) //raiseerror exec |
||
2109 | } if |
||
2110 | barcode 16 get dup 48 lt exch 57 gt or { |
||
2111 | /bwipp.isbn13character17 (ISBN-13 final character must be a digit) //raiseerror exec |
||
2112 | } if |
||
2113 | } if |
||
2114 | } { % ISBN-10 |
||
2115 | barcode 0 get dup 48 lt exch 57 gt or { |
||
2116 | /bwipp.isbn10FirstDigit (ISBN-10 first character must be a digit) //raiseerror exec |
||
2117 | } if |
||
2118 | /wasdash false def /numdash 0 def /numdigit 0 def |
||
2119 | barcode 1 9 getinterval { |
||
2120 | dup |
||
2121 | 45 eq { |
||
2122 | wasdash { |
||
2123 | /bwipp.isbn10adjacentDashes (ISBN-10 does not permit adjacent dashes) //raiseerror exec |
||
2124 | } if |
||
2125 | /wasdash true def |
||
2126 | /numdash numdash 1 add def |
||
2127 | } if |
||
2128 | dup 48 ge exch 57 le and { |
||
2129 | /wasdash false def |
||
2130 | /numdigit numdigit 1 add def |
||
2131 | } if |
||
2132 | } forall |
||
2133 | numdash 2 ne numdigit 7 ne or { |
||
2134 | /bwipp.isbn10numDashesDigits (Incorrect number of dashes and digits for ISBN-10) //raiseerror exec |
||
2135 | } if |
||
2136 | barcode 10 get dup 48 lt exch 57 gt or { |
||
2137 | /bwipp.isbn10character11 (ISBN-10 character 11 must be a digit) //raiseerror exec |
||
2138 | } if |
||
2139 | barcode length 13 eq { |
||
2140 | barcode 11 1 getinterval (-) ne { |
||
2141 | /bwipp.isbn10character12 (ISBN-10 penultimate character must be a dash) //raiseerror exec |
||
2142 | } if |
||
2143 | barcode 12 get dup dup 48 lt exch 57 gt or exch 88 ne and { |
||
2144 | /bwipp.isbn10character13 (ISBN-10 final character must be a digit or X) //raiseerror exec |
||
2145 | } if |
||
2146 | } if |
||
2147 | } ifelse |
||
16255 | fschmid | 2148 | |
20313 | craig | 2149 | /isbntxt barcode def |
19685 | fschmid | 2150 | |
20313 | craig | 2151 | % Read the digits from isbntxt and validate checksum for ISBN-10 |
2152 | isbntxt length 13 le { |
||
2153 | /isbn 10 string def |
||
2154 | /checksum 0 def |
||
2155 | /i 0 def /n 0 def |
||
2156 | { % loop |
||
2157 | /isbnchar isbntxt i get 48 sub def |
||
2158 | isbnchar -3 ne { % Ignore dashes |
||
2159 | isbn n isbnchar 48 add put |
||
2160 | n 9 lt { |
||
2161 | /checksum checksum 10 n sub isbnchar mul add def |
||
2162 | } if |
||
2163 | /n n 1 add def |
||
2164 | } if |
||
2165 | /i i 1 add def |
||
2166 | i isbntxt length eq {exit} if |
||
2167 | } loop |
||
2168 | /checksum 11 checksum 11 mod sub 11 mod dup 10 eq {pop 40} if 48 add def |
||
2169 | /isbn isbn 0 9 getinterval def |
||
2170 | isbntxt length 13 eq { |
||
2171 | isbntxt 12 get checksum ne { |
||
2172 | /bwipp.isbn10badCheckDigit (Incorrect ISBN-10 check digit provided) //raiseerror exec |
||
2173 | } if |
||
2174 | } if |
||
2175 | } if |
||
4460 | subik | 2176 | |
20313 | craig | 2177 | legacy not isbntxt length 15 ge or { |
19685 | fschmid | 2178 | |
20313 | craig | 2179 | % Convert ISBN-10 to ISBN-13 |
2180 | isbntxt length 13 le { |
||
2181 | /pad 15 string def |
||
2182 | pad 0 (978-) putinterval |
||
2183 | pad 4 isbntxt 0 11 getinterval putinterval |
||
2184 | /isbntxt pad def |
||
2185 | } if |
||
19685 | fschmid | 2186 | |
20313 | craig | 2187 | % Read the digits from isbntxt and validate checksum for ISBN-13 |
2188 | /isbn 13 string def |
||
2189 | /checksum 0 def |
||
2190 | /i 0 def /n 0 def |
||
2191 | { % loop |
||
2192 | /isbnchar isbntxt i get 48 sub def |
||
2193 | isbnchar -3 ne { % Ignore dashes |
||
2194 | isbn n isbnchar 48 add put |
||
2195 | n 12 lt { |
||
2196 | /checksum isbnchar n 2 mod 0 ne {3 mul} if checksum add def |
||
2197 | } if |
||
2198 | /n n 1 add def |
||
2199 | } if |
||
2200 | /i i 1 add def |
||
2201 | i isbntxt length eq {exit} if |
||
2202 | } loop |
||
2203 | /checksum 10 checksum 10 mod sub 10 mod 48 add def |
||
2204 | /isbn isbn 0 12 getinterval def |
||
2205 | isbntxt length 17 eq { |
||
2206 | isbntxt 16 get checksum ne { |
||
2207 | /bwipp.isbn13badCheckDigit (Incorrect ISBN-13 check digit provided) //raiseerror exec |
||
2208 | } if |
||
2209 | } if |
||
19685 | fschmid | 2210 | |
20313 | craig | 2211 | } if |
19685 | fschmid | 2212 | |
20313 | craig | 2213 | % Add the ISBN header to the isbntxt |
2214 | /pad isbn length 12 eq {22} {18} ifelse string def |
||
2215 | pad 0 (ISBN ) putinterval |
||
2216 | pad 5 isbntxt putinterval |
||
2217 | pad pad length 2 sub 45 put |
||
2218 | pad pad length 1 sub checksum put |
||
2219 | /isbntxt pad def |
||
4460 | subik | 2220 | |
20313 | craig | 2221 | % Convert ISBN digits to EAN-13 |
2222 | /barcode 12 string def |
||
2223 | isbn length 9 eq { |
||
2224 | barcode 0 (978) putinterval |
||
2225 | barcode 3 isbn putinterval |
||
2226 | } { |
||
2227 | barcode 0 isbn putinterval |
||
2228 | } ifelse |
||
4460 | subik | 2229 | |
20313 | craig | 2230 | % Append the addon |
2231 | addon () ne { |
||
2232 | 12 addon length add 1 add string |
||
2233 | dup 0 barcode putinterval |
||
2234 | dup 12 ( ) putinterval |
||
2235 | dup 13 addon putinterval |
||
2236 | /barcode exch def |
||
2237 | } if |
||
4460 | subik | 2238 | |
20313 | craig | 2239 | % Get the result of encoding with ean13 |
2240 | options (dontdraw) true put |
||
2241 | options (addongap) addongap put |
||
2242 | /args barcode options //ean13 exec def |
||
13293 | subik | 2243 | |
20313 | craig | 2244 | % Add the ISBN text |
2245 | includetext { |
||
2246 | isbntextxoffset (unset) eq { |
||
2247 | /isbntextxoffset isbn length 9 eq {-1} {-12} ifelse def |
||
2248 | } if |
||
2249 | isbntextyoffset (unset) eq { |
||
2250 | /isbntextyoffset height 72 mul 3 add def |
||
2251 | } if |
||
2252 | args (txt) known { |
||
2253 | /txt args (txt) get def |
||
2254 | /newtxt txt length 1 add array def |
||
2255 | newtxt 0 txt putinterval |
||
2256 | newtxt newtxt length 1 sub [isbntxt isbntextxoffset isbntextyoffset isbntextfont isbntextsize] put |
||
2257 | args (txt) newtxt put |
||
2258 | } { |
||
2259 | args (txt) [ [isbntxt isbntextxoffset isbntextyoffset isbntextfont isbntextsize] ] put |
||
2260 | } ifelse |
||
2261 | } if |
||
4460 | subik | 2262 | |
20313 | craig | 2263 | args (opt) options put |
2264 | args |
||
4460 | subik | 2265 | |
20313 | craig | 2266 | dontdraw not //renlinear if |
13293 | subik | 2267 | |
20313 | craig | 2268 | end |
2269 | |||
4460 | subik | 2270 | } bind def |
16255 | fschmid | 2271 | /isbn dup load /uk.co.terryburton.bwipp defineresource pop |
2272 | end |
||
2273 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 2274 | %%EndData |
2275 | %%EndResource |
||
4460 | subik | 2276 | % --END ENCODER isbn-- |
2277 | |||
16255 | fschmid | 2278 | % --BEGIN ENCODER ismn-- |
18800 | fschmid | 2279 | % --REQUIRES preamble raiseerror renlinear ean5 ean2 ean13-- |
16255 | fschmid | 2280 | % --DESC: ISMN |
18800 | fschmid | 2281 | % --EXAM: 979-0-2605-3211-3 |
16255 | fschmid | 2282 | % --EXOP: includetext guardwhitespace |
2283 | % --RNDR: renlinear |
||
22439 | craig | 2284 | %%BeginResource: uk.co.terryburton.bwipp ismn 0.0 2018020400 99933 102747 |
19685 | fschmid | 2285 | %%BeginData: 231 ASCII Lines |
16255 | fschmid | 2286 | /setpacking where {pop currentpacking true setpacking} if |
2287 | 1 dict |
||
18800 | fschmid | 2288 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 2289 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
2290 | dup /ean13 dup /uk.co.terryburton.bwipp findresource put |
||
2291 | begin |
||
2292 | /ismn { |
||
2293 | |||
20313 | craig | 2294 | 20 dict begin |
16255 | fschmid | 2295 | |
20313 | craig | 2296 | /options exch def % We are given an options string |
2297 | /barcode exch def % We are given the ismn text with dashes |
||
16255 | fschmid | 2298 | |
20313 | craig | 2299 | /dontdraw false def |
2300 | /includetext false def % Enable/disable ISMN text |
||
2301 | /ismntextfont /Courier def |
||
2302 | /ismntextsize 9 def |
||
2303 | /ismntextxoffset (unset) def |
||
2304 | /ismntextyoffset (unset) def |
||
2305 | /height 1 def |
||
2306 | /addongap 12 def |
||
2307 | /legacy false def |
||
16255 | fschmid | 2308 | |
20313 | craig | 2309 | % Parse the input options |
2310 | options type /stringtype eq { |
||
2311 | 1 dict begin |
||
2312 | options { |
||
2313 | token false eq {exit} if dup length string cvs (=) search |
||
2314 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
2315 | } loop |
||
2316 | currentdict end /options exch def |
||
2317 | } if |
||
2318 | options {def} forall |
||
2319 | |||
2320 | /ismntextfont ismntextfont cvlit def |
||
2321 | /ismntextsize ismntextsize cvr def |
||
2322 | ismntextxoffset (unset) ne {/ismntextxoffset ismntextxoffset cvr def} if |
||
2323 | ismntextyoffset (unset) ne {/ismntextyoffset ismntextyoffset cvr def} if |
||
2324 | /height height cvr def |
||
2325 | /addongap addongap cvr def |
||
2326 | |||
2327 | % Split off the addon |
||
2328 | barcode ( ) search { |
||
2329 | /barcode exch def |
||
2330 | pop |
||
2331 | /addon exch def |
||
2332 | } { |
||
2333 | pop |
||
2334 | /addon () def |
||
2335 | } ifelse |
||
16255 | fschmid | 2336 | |
20313 | craig | 2337 | % Validate the input |
2338 | barcode length 15 ne barcode length 17 ne and |
||
2339 | barcode length 11 ne barcode length 13 ne and and { |
||
2340 | /bwipp.ismnBadLength (ISMN-13 must be 15 or 17 characters including dashes. ISMN-10 must be 11 or 13 characters including dashes) //raiseerror exec |
||
2341 | } if |
||
2342 | addon length 0 ne addon length 2 ne and addon length 5 ne and { |
||
2343 | /bwipp.ismnBadAddOnLength (Add-on for ISMN must be 2 or 5 digits) //raiseerror exec |
||
2344 | } if |
||
2345 | barcode length 15 ge { % ISMN-13 |
||
2346 | barcode 0 4 getinterval (979-) ne { |
||
2347 | /bwipp.ismn13badPrefix (ISMN-13 prefix must be 979-) //raiseerror exec |
||
2348 | } if |
||
2349 | /wasdash false def /numdash 0 def /numdigit 0 def |
||
2350 | barcode 5 9 getinterval { |
||
2351 | dup |
||
2352 | 45 eq { |
||
2353 | wasdash { |
||
2354 | /bwipp.ismn13adjacentDashes (ISMN-13 does not permit adjacent dashes) //raiseerror exec |
||
2355 | } if |
||
2356 | /wasdash true def |
||
2357 | /numdash numdash 1 add def |
||
2358 | } if |
||
2359 | dup 48 ge exch 57 le and { |
||
2360 | /wasdash false def |
||
2361 | /numdigit numdigit 1 add def |
||
2362 | } if |
||
2363 | } forall |
||
2364 | numdash 2 ne numdigit 7 ne or { |
||
2365 | /bwipp.ismn13numDashesDigits (Incorrect number of dashes and digits for ISMN-13) //raiseerror exec |
||
2366 | } if |
||
2367 | barcode 14 get dup 48 lt exch 57 gt or { |
||
2368 | /bwipp.ismn13character15 (ISMN-13 character 15 must be a digit) //raiseerror exec |
||
2369 | } if |
||
2370 | barcode length 17 eq { |
||
2371 | barcode 15 1 getinterval (-) ne { |
||
2372 | /bwipp.ismn13character16 (ISMN-13 penultimate character must be a dash) //raiseerror exec |
||
2373 | } if |
||
2374 | barcode 16 get dup 48 lt exch 57 gt or { |
||
2375 | /bwipp.ismn13character17 (ISMN-13 final character must be a digit) //raiseerror exec |
||
2376 | } if |
||
2377 | } if |
||
2378 | } { % ISMN-10 |
||
2379 | barcode 0 2 getinterval (M-) ne { |
||
2380 | /bwipp.ismn10badPrefix (ISMN-10 prefix must be M-) //raiseerror exec |
||
2381 | } if |
||
2382 | barcode 2 get dup 48 lt exch 57 gt or { |
||
2383 | /bwipp.ismn10character3 (ISMN-10 character 3 must be a digit) //raiseerror exec |
||
2384 | } if |
||
2385 | /wasdash false def /numdash 0 def /numdigit 0 def |
||
2386 | barcode 3 7 getinterval { |
||
2387 | dup |
||
2388 | 45 eq { |
||
2389 | wasdash { |
||
2390 | /bwipp.ismn10adjacentDashes (ISMN-10 does not permit adjacent dashes) //raiseerror exec |
||
2391 | } if |
||
2392 | /wasdash true def |
||
2393 | /numdash numdash 1 add def |
||
2394 | } if |
||
2395 | dup 48 ge exch 57 le and { |
||
2396 | /wasdash false def |
||
2397 | /numdigit numdigit 1 add def |
||
2398 | } if |
||
2399 | } forall |
||
2400 | numdash 1 ne numdigit 6 ne or { |
||
2401 | /bwipp.ismn10numDashesDigits (Incorrect number of dashes and digits for ISMN-10) //raiseerror exec |
||
2402 | } if |
||
2403 | barcode 10 get dup 48 lt exch 57 gt or { |
||
2404 | /bwipp.ismn10character11 (ISMN-10 character 11 must be a digit) //raiseerror exec |
||
2405 | } if |
||
2406 | barcode length 13 eq { |
||
2407 | barcode 11 1 getinterval (-) ne { |
||
2408 | /bwipp.ismn10character12 (ISMN-10 penultimate character must be a dash) //raiseerror exec |
||
2409 | } if |
||
2410 | barcode 12 get dup dup 48 lt exch 57 gt or exch 88 ne and { |
||
2411 | /bwipp.ismn10character13 (ISMN-10 final character must be a digit or X) //raiseerror exec |
||
2412 | } if |
||
2413 | } if |
||
2414 | } ifelse |
||
19685 | fschmid | 2415 | |
20313 | craig | 2416 | /ismntxt barcode def |
19685 | fschmid | 2417 | |
20313 | craig | 2418 | % Convert old ISMN to ISMN-13 |
2419 | /legacytxt () def |
||
2420 | ismntxt length 13 le { |
||
2421 | /legacytxt ismntxt def |
||
2422 | /pad ismntxt length 4 add string def |
||
2423 | pad 0 (979-0-) putinterval |
||
2424 | pad 6 ismntxt 2 ismntxt length 2 sub getinterval putinterval |
||
2425 | /ismntxt pad def |
||
2426 | } if |
||
16255 | fschmid | 2427 | |
20313 | craig | 2428 | % Read the digits from ismntxt and calculate checksums |
2429 | /ismn 13 string def |
||
2430 | /checksum 0 def |
||
2431 | /i 0 def /n 0 def |
||
2432 | { % loop |
||
2433 | /ismnchar ismntxt i get 48 sub def |
||
2434 | ismnchar -3 ne { % Ignore dashes |
||
2435 | ismn n ismnchar 48 add put |
||
2436 | n 12 lt { |
||
2437 | n 2 mod 0 eq { |
||
2438 | /checksum ismnchar checksum add def |
||
2439 | } { |
||
2440 | /checksum ismnchar 3 mul checksum add def |
||
2441 | } ifelse |
||
2442 | } if |
||
2443 | /n n 1 add def |
||
2444 | } if |
||
2445 | /i i 1 add def |
||
2446 | i ismntxt length eq {exit} if |
||
2447 | } loop |
||
2448 | /checksum 10 checksum 10 mod sub 10 mod 48 add def |
||
16255 | fschmid | 2449 | |
20313 | craig | 2450 | % Validate the checksum |
2451 | barcode length 13 eq barcode length 17 eq or { |
||
2452 | barcode dup length 1 sub get checksum ne { |
||
2453 | /bwipp.ismnBadCheckDigit (Incorrect ISMN check digit provided) //raiseerror exec |
||
2454 | } if |
||
2455 | } if |
||
19685 | fschmid | 2456 | |
20313 | craig | 2457 | % Add the ISMN header and checksum to the ismntxt |
2458 | legacy legacytxt () ne and { |
||
2459 | /ismntxt legacytxt def |
||
2460 | /pad 18 string def |
||
2461 | } { |
||
2462 | /pad 22 string def |
||
2463 | } ifelse |
||
2464 | pad 0 (ISMN ) putinterval |
||
2465 | pad 5 ismntxt putinterval |
||
2466 | pad pad length 2 sub 45 put |
||
2467 | pad pad length 1 sub checksum put |
||
2468 | /ismntxt pad def |
||
16255 | fschmid | 2469 | |
20313 | craig | 2470 | % Convert ISMN digits to EAN-13 |
2471 | /barcode ismn 0 12 getinterval def |
||
16255 | fschmid | 2472 | |
20313 | craig | 2473 | % Append the addon |
2474 | addon () ne { |
||
2475 | 12 addon length add 1 add string |
||
2476 | dup 0 barcode putinterval |
||
2477 | dup 12 ( ) putinterval |
||
2478 | dup 13 addon putinterval |
||
2479 | /barcode exch def |
||
2480 | } if |
||
16255 | fschmid | 2481 | |
20313 | craig | 2482 | % Get the result of encoding with ean13 |
2483 | options (dontdraw) true put |
||
2484 | options (addongap) addongap put |
||
2485 | /args barcode options //ean13 exec def |
||
16255 | fschmid | 2486 | |
20313 | craig | 2487 | % Add the ISMN text |
2488 | includetext { |
||
2489 | ismntextxoffset (unset) eq { |
||
2490 | /ismntextxoffset ismntxt length 18 eq {-1} {-12} ifelse def |
||
2491 | } if |
||
2492 | ismntextyoffset (unset) eq { |
||
2493 | /ismntextyoffset height 72 mul 3 add def |
||
2494 | } if |
||
2495 | args (txt) known { |
||
2496 | /txt args (txt) get def |
||
2497 | /newtxt txt length 1 add array def |
||
2498 | newtxt 0 txt putinterval |
||
2499 | newtxt newtxt length 1 sub [ismntxt ismntextxoffset ismntextyoffset ismntextfont ismntextsize] put |
||
2500 | args (txt) newtxt put |
||
2501 | } { |
||
2502 | args (txt) [ [ismntxt ismntextxoffset ismntextyoffset ismntextfont ismntextsize] ] put |
||
2503 | } ifelse |
||
2504 | } if |
||
16255 | fschmid | 2505 | |
20313 | craig | 2506 | args (opt) options put |
2507 | args |
||
16255 | fschmid | 2508 | |
20313 | craig | 2509 | dontdraw not //renlinear if |
16255 | fschmid | 2510 | |
20313 | craig | 2511 | end |
2512 | |||
16255 | fschmid | 2513 | } bind def |
2514 | /ismn dup load /uk.co.terryburton.bwipp defineresource pop |
||
2515 | end |
||
2516 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 2517 | %%EndData |
2518 | %%EndResource |
||
16255 | fschmid | 2519 | % --END ENCODER ismn-- |
2520 | |||
2521 | % --BEGIN ENCODER issn-- |
||
18800 | fschmid | 2522 | % --REQUIRES preamble raiseerror renlinear ean2 ean5 ean13-- |
16255 | fschmid | 2523 | % --DESC: ISSN |
19685 | fschmid | 2524 | % --EXAM: 0311-175X 00 17 |
16255 | fschmid | 2525 | % --EXOP: includetext guardwhitespace |
2526 | % --RNDR: renlinear |
||
22439 | craig | 2527 | %%BeginResource: uk.co.terryburton.bwipp issn 0.0 2018020400 89245 88647 |
2528 | %%BeginData: 176 ASCII Lines |
||
16255 | fschmid | 2529 | /setpacking where {pop currentpacking true setpacking} if |
2530 | 1 dict |
||
18800 | fschmid | 2531 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 2532 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
2533 | dup /ean13 dup /uk.co.terryburton.bwipp findresource put |
||
2534 | begin |
||
2535 | /issn { |
||
2536 | |||
20313 | craig | 2537 | 20 dict begin |
16255 | fschmid | 2538 | |
20313 | craig | 2539 | /options exch def % We are given an options string |
2540 | /issntxt exch def % We are given the issn text with dashes |
||
16255 | fschmid | 2541 | |
20313 | craig | 2542 | /dontdraw false def |
2543 | /includetext false def % Enable/disable ISSN text |
||
2544 | /issntextfont /Courier def |
||
2545 | /issntextsize 9 def |
||
2546 | /issntextxoffset (unset) def |
||
2547 | /issntextyoffset (unset) def |
||
2548 | /height 1 def |
||
2549 | /addongap 12 def |
||
16255 | fschmid | 2550 | |
20313 | craig | 2551 | % Parse the input options |
2552 | options type /stringtype eq { |
||
2553 | 1 dict begin |
||
2554 | options { |
||
2555 | token false eq {exit} if dup length string cvs (=) search |
||
2556 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
2557 | } loop |
||
2558 | currentdict end /options exch def |
||
2559 | } if |
||
2560 | options {def} forall |
||
2561 | |||
2562 | /issntextfont issntextfont cvlit def |
||
2563 | /issntextsize issntextsize cvr def |
||
2564 | issntextxoffset (unset) ne {/issntextxoffset issntextxoffset cvr def} if |
||
2565 | issntextyoffset (unset) ne {/issntextyoffset issntextyoffset cvr def} if |
||
2566 | /height height cvr def |
||
2567 | /addongap addongap cvr def |
||
22439 | craig | 2568 | |
20313 | craig | 2569 | % Split off the ISSN |
2570 | issntxt ( ) search { |
||
2571 | /issntxt exch def |
||
2572 | pop |
||
2573 | /seqvar exch def |
||
22439 | craig | 2574 | } { |
20313 | craig | 2575 | pop |
22439 | craig | 2576 | /seqvar (00) def |
20313 | craig | 2577 | } ifelse |
16255 | fschmid | 2578 | |
20313 | craig | 2579 | % Split off the sequence variant and addon |
2580 | seqvar ( ) search { |
||
2581 | /seqvar exch def |
||
2582 | pop |
||
2583 | /addon exch def |
||
2584 | } { |
||
2585 | pop |
||
22439 | craig | 2586 | /addon () def |
20313 | craig | 2587 | } ifelse |
16255 | fschmid | 2588 | |
20313 | craig | 2589 | % Validate the input |
2590 | issntxt length 8 ne issntxt length 9 ne and { |
||
22439 | craig | 2591 | /bwipp.issnBadLength (ISSN must be 8 or 9 characters including dash, in the format XXXX-XXXX) //raiseerror exec |
20313 | craig | 2592 | } if |
2593 | issntxt 0 4 getinterval { |
||
2594 | dup 48 lt exch 57 gt or { |
||
22439 | craig | 2595 | /bwipp.issnFirstThroughFourthNotNumeric (ISSN first four characters must be numeral characters) //raiseerror exec |
20313 | craig | 2596 | } if |
2597 | } forall |
||
2598 | issntxt 4 1 getinterval (-) ne { |
||
22439 | craig | 2599 | /bwipp.issnNeedsDash (ISSN fifth character must be a dash) //raiseerror exec |
20313 | craig | 2600 | } if |
2601 | issntxt 5 3 getinterval { |
||
2602 | dup 48 lt exch 57 gt or { |
||
22439 | craig | 2603 | /bwipp.issnSixthThroughEighthNotNumeric (ISSN sixth through eighth characters must be numerals) //raiseerror exec |
20313 | craig | 2604 | } if |
2605 | } forall |
||
2606 | issntxt length 9 eq { |
||
2607 | issntxt 8 get dup dup 48 lt exch 57 gt or exch 88 ne and { % Digits or X |
||
22439 | craig | 2608 | /bwipp.issnNinthCharacterBadFormat (ISSN ninth character must be a number or the character X) //raiseerror exec |
20313 | craig | 2609 | } if |
2610 | } if |
||
2611 | seqvar length 2 ne { |
||
2612 | /bwipp.issnBadSequenceVariantLength (Sequence variant for ISSN must be 2 digits) //raiseerror exec |
||
2613 | } if |
||
2614 | seqvar { |
||
2615 | dup 48 lt exch 57 gt or { |
||
2616 | /bwipp.issnSequenceVariantBadCharacter (Sequence variant for ISSN must contain only digits) //raiseerror exec |
||
2617 | } if |
||
2618 | } forall |
||
2619 | addon length 0 ne addon length 2 ne and addon length 5 ne and { |
||
2620 | /bwipp.issnBadAddOnLength (Add-on for ISSN must be 2 or 5 digits) //raiseerror exec |
||
2621 | } if |
||
19685 | fschmid | 2622 | |
20313 | craig | 2623 | % Read the digits from issntxt and calculate checksums |
2624 | /issn 8 string def |
||
2625 | /checksum 0 def |
||
2626 | /i 0 def /n 0 def |
||
2627 | { % loop |
||
2628 | /issnchar issntxt i get 48 sub def |
||
2629 | issnchar -3 ne { % Ignore dashes |
||
2630 | issn n issnchar 48 add put |
||
2631 | n 7 lt { |
||
2632 | /checksum checksum issnchar 8 n sub mul add def |
||
2633 | } if |
||
2634 | /n n 1 add def |
||
2635 | } if |
||
2636 | /i i 1 add def |
||
2637 | i issntxt length eq {exit} if |
||
2638 | } loop |
||
2639 | /checksum 11 checksum 11 mod sub 11 mod def |
||
2640 | /checksum checksum 48 add dup 58 eq {pop 88} if def |
||
2641 | issntxt length 9 eq { |
||
2642 | issntxt 8 get checksum ne { |
||
2643 | /bwipp.issnBadCheckDigit (Incorrect ISSN check digit provided) //raiseerror exec |
||
2644 | } if |
||
2645 | } if |
||
16255 | fschmid | 2646 | |
20313 | craig | 2647 | % Add the ISSN header and checksum to the issntxt |
2648 | /pad 14 string def |
||
2649 | pad 0 (ISSN ) putinterval |
||
2650 | pad 5 issntxt putinterval % Add issntxt to the pad |
||
2651 | pad 13 checksum put |
||
2652 | /issntxt pad def |
||
16255 | fschmid | 2653 | |
20313 | craig | 2654 | % Convert ISSN digits to EAN-13 |
2655 | /barcode issn 0 7 getinterval def |
||
16255 | fschmid | 2656 | |
20313 | craig | 2657 | % Append the sequence variant |
2658 | /barcode 12 string def |
||
2659 | barcode 0 (977) putinterval |
||
2660 | barcode 3 issn putinterval |
||
2661 | barcode 10 seqvar putinterval |
||
16255 | fschmid | 2662 | |
20313 | craig | 2663 | % Append the addon |
2664 | addon () ne { |
||
2665 | 12 addon length add 1 add string |
||
2666 | dup 0 barcode putinterval |
||
2667 | dup 12 ( ) putinterval |
||
2668 | dup 13 addon putinterval |
||
2669 | /barcode exch def |
||
2670 | } if |
||
16255 | fschmid | 2671 | |
20313 | craig | 2672 | % Get the result of encoding with ean13 |
2673 | options (dontdraw) true put |
||
2674 | options (addongap) addongap put |
||
2675 | /args barcode options //ean13 exec def |
||
16255 | fschmid | 2676 | |
20313 | craig | 2677 | % Add the ISSN text |
2678 | includetext { |
||
2679 | issntextxoffset (unset) eq {/issntextxoffset 10 def} if |
||
2680 | issntextyoffset (unset) eq { |
||
2681 | /issntextyoffset height 72 mul 3 add def |
||
2682 | } if |
||
2683 | args (txt) known { |
||
2684 | /txt args (txt) get def |
||
2685 | /newtxt txt length 1 add array def |
||
2686 | newtxt 0 txt putinterval |
||
2687 | newtxt newtxt length 1 sub [issntxt issntextxoffset issntextyoffset issntextfont issntextsize] put |
||
2688 | args (txt) newtxt put |
||
2689 | } { |
||
2690 | args (txt) [ [issntxt issntextxoffset issntextyoffset issntextfont issntextsize] ] put |
||
2691 | } ifelse |
||
2692 | } if |
||
16255 | fschmid | 2693 | |
20313 | craig | 2694 | args (opt) options put |
2695 | args |
||
16255 | fschmid | 2696 | |
20313 | craig | 2697 | dontdraw not //renlinear if |
16255 | fschmid | 2698 | |
20313 | craig | 2699 | end |
22439 | craig | 2700 | |
16255 | fschmid | 2701 | } bind def |
2702 | /issn dup load /uk.co.terryburton.bwipp defineresource pop |
||
2703 | end |
||
2704 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 2705 | %%EndData |
2706 | %%EndResource |
||
16255 | fschmid | 2707 | % --END ENCODER issn-- |
2708 | |||
4460 | subik | 2709 | % --BEGIN ENCODER code128-- |
18800 | fschmid | 2710 | % --REQUIRES preamble raiseerror renlinear-- |
7162 | subik | 2711 | % --DESC: Code 128 |
20271 | craig | 2712 | % --EXAM: Count01234567! |
2713 | % --EXOP: includetext |
||
11277 | subik | 2714 | % --RNDR: renlinear |
22439 | craig | 2715 | %%BeginResource: uk.co.terryburton.bwipp code128 0.0 2018020400 139931 142645 |
20271 | craig | 2716 | %%BeginData: 455 ASCII Lines |
16255 | fschmid | 2717 | /setpacking where {pop currentpacking true setpacking} if |
2718 | 1 dict |
||
18800 | fschmid | 2719 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 2720 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
2721 | begin |
||
4460 | subik | 2722 | /code128 { |
2723 | |||
20313 | craig | 2724 | 20 dict begin % Confine variables to local scope |
4460 | subik | 2725 | |
20313 | craig | 2726 | /options exch def % We are given an option string |
2727 | /barcode exch def % We are given a barcode string |
||
4460 | subik | 2728 | |
20313 | craig | 2729 | /dontdraw false def |
2730 | /includetext false def % Enable/disable text |
||
2731 | /textfont /Courier def |
||
2732 | /textsize 10 def |
||
2733 | /textxoffset 0 def |
||
2734 | /textyoffset -7 def |
||
2735 | /height 1 def |
||
2736 | /encoding (auto) def |
||
2737 | /raw false def |
||
2738 | /parse false def |
||
2739 | /parsefnc false def |
||
16255 | fschmid | 2740 | |
20313 | craig | 2741 | % Parse the input options |
2742 | options type /stringtype eq { |
||
2743 | 1 dict begin |
||
2744 | options { |
||
2745 | token false eq {exit} if dup length string cvs (=) search |
||
2746 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
2747 | } loop |
||
2748 | currentdict end /options exch def |
||
2749 | } if |
||
2750 | options {def} forall |
||
16255 | fschmid | 2751 | |
20313 | craig | 2752 | /textfont textfont cvlit def |
2753 | /textsize textsize cvr def |
||
2754 | /textxoffset textxoffset cvr def |
||
2755 | /textyoffset textyoffset cvr def |
||
2756 | /height height cvr def |
||
16255 | fschmid | 2757 | |
20313 | craig | 2758 | % Parse ordinals of the form ^NNN to ASCII |
2759 | parse { |
||
2760 | /msg barcode length string def |
||
2761 | /j 0 def |
||
2762 | barcode |
||
2763 | { % loop |
||
2764 | (^) search { |
||
2765 | dup msg exch j exch putinterval |
||
2766 | length j add 1 add /j exch def |
||
2767 | pop |
||
2768 | dup 0 3 getinterval cvi msg exch j 1 sub exch put |
||
2769 | dup length 3 sub 3 exch getinterval |
||
2770 | } { |
||
2771 | dup msg exch j exch putinterval |
||
2772 | length j add /j exch def |
||
2773 | /barcode msg 0 j getinterval def |
||
2774 | exit |
||
2775 | } ifelse |
||
2776 | } loop |
||
2777 | } if |
||
16255 | fschmid | 2778 | |
20313 | craig | 2779 | /barlen barcode length def |
16255 | fschmid | 2780 | |
20313 | craig | 2781 | % Special function characters |
2782 | /sta -1 def /stb -2 def /stc -3 def |
||
2783 | /swa -4 def /swb -5 def /swc -6 def |
||
2784 | /fn1 -7 def /fn2 -8 def /fn3 -9 def |
||
2785 | /fn4 -10 def /sft -11 def /stp -12 def |
||
2786 | /lka -13 def /lkc -14 def % CC-A/B and CC-C linkage |
||
16255 | fschmid | 2787 | |
20313 | craig | 2788 | % Character maps for each state |
2789 | /charmaps [ |
||
2790 | % A B C A B C A B C |
||
2791 | [ 32 32 (00) ] [ (!) (!) (01) ] [ (") (") (02) ] % 0-2 |
||
2792 | [ (#) (#) (03) ] [ ($) ($) (04) ] [ (%) (%) (05) ] % 3-5 |
||
2793 | [ (&) (&) (06) ] [ (') (') (07) ] [ 40 40 (08) ] % 6-8 |
||
2794 | [ 41 41 (09) ] [ (*) (*) (10) ] [ (+) (+) (11) ] % 9-11 |
||
2795 | [ (,) (,) (12) ] [ (-) (-) (13) ] [ (.) (.) (14) ] % 12-14 |
||
2796 | [ (/) (/) (15) ] [ (0) (0) (16) ] [ (1) (1) (17) ] % 15-17 |
||
2797 | [ (2) (2) (18) ] [ (3) (3) (19) ] [ (4) (4) (20) ] % 18-20 |
||
2798 | [ (5) (5) (21) ] [ (6) (6) (22) ] [ (7) (7) (23) ] % 21-23 |
||
2799 | [ (8) (8) (24) ] [ (9) (9) (25) ] [ (:) (:) (26) ] % 24-26 |
||
2800 | [ (;) (;) (27) ] [ (<) (<) (28) ] [ (=) (=) (29) ] % 27-29 |
||
2801 | [ (>) (>) (30) ] [ (?) (?) (31) ] [ (@) (@) (32) ] % 30-32 |
||
2802 | [ (A) (A) (33) ] [ (B) (B) (34) ] [ (C) (C) (35) ] % 33-35 |
||
2803 | [ (D) (D) (36) ] [ (E) (E) (37) ] [ (F) (F) (38) ] % 36-38 |
||
2804 | [ (G) (G) (39) ] [ (H) (H) (40) ] [ (I) (I) (41) ] % 39-41 |
||
2805 | [ (J) (J) (42) ] [ (K) (K) (43) ] [ (L) (L) (44) ] % 42-44 |
||
2806 | [ (M) (M) (45) ] [ (N) (N) (46) ] [ (O) (O) (47) ] % 45-47 |
||
2807 | [ (P) (P) (48) ] [ (Q) (Q) (49) ] [ (R) (R) (50) ] % 48-50 |
||
2808 | [ (S) (S) (51) ] [ (T) (T) (52) ] [ (U) (U) (53) ] % 51-53 |
||
2809 | [ (V) (V) (54) ] [ (W) (W) (55) ] [ (X) (X) (56) ] % 54-56 |
||
2810 | [ (Y) (Y) (57) ] [ (Z) (Z) (58) ] [ ([) ([) (59) ] % 57-59 |
||
2811 | [ 92 92 (60) ] [ (]) (]) (61) ] [ (^) (^) (62) ] % 60-62 |
||
2812 | [ (_) (_) (63) ] [ 0 (`) (64) ] [ 1 (a) (65) ] % 63-65 |
||
2813 | [ 2 (b) (66) ] [ 3 (c) (67) ] [ 4 (d) (68) ] % 66-68 |
||
2814 | [ 5 (e) (69) ] [ 6 (f) (70) ] [ 7 (g) (71) ] % 69-71 |
||
2815 | [ 8 (h) (72) ] [ 9 (i) (73) ] [ 10 (j) (74) ] % 72-74 |
||
2816 | [ 11 (k) (75) ] [ 12 (l) (76) ] [ 13 (m) (77) ] % 75-77 |
||
2817 | [ 14 (n) (78) ] [ 15 (o) (79) ] [ 16 (p) (80) ] % 78-80 |
||
2818 | [ 17 (q) (81) ] [ 18 (r) (82) ] [ 19 (s) (83) ] % 81-83 |
||
2819 | [ 20 (t) (84) ] [ 21 (u) (85) ] [ 22 (v) (86) ] % 84-86 |
||
2820 | [ 23 (w) (87) ] [ 24 (x) (88) ] [ 25 (y) (89) ] % 87-89 |
||
2821 | [ 26 (z) (90) ] [ 27 ({) (91) ] [ 28 (|) (92) ] % 90-92 |
||
2822 | [ 29 (}) (93) ] [ 30 (~) (94) ] [ 31 127 (95) ] % 93-95 |
||
2823 | [ fn3 fn3 (96) ] [ fn2 fn2 (97) ] [ sft sft (98) ] % 96-98 |
||
2824 | [ swc swc (99) ] [ swb fn4 swb ] [ fn4 swa swa ] % 99-101 |
||
2825 | [ fn1 fn1 fn1 ] [ sta sta sta ] [ stb stb stb ] % 102-104 |
||
2826 | [ stc stc stc ] [ stp stp stp ] % 105-106 |
||
2827 | ] def |
||
2828 | |||
2829 | % Invert charmaps to give character to value maps for each state |
||
2830 | /charvals [ 109 dict 109 dict 109 dict ] def |
||
2831 | |||
2832 | /i exch def |
||
2833 | /encs charmaps i get def |
||
2834 | |||
2835 | /j exch def |
||
2836 | encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required |
||
2837 | charvals j get exch i put |
||
2838 | } for |
||
2839 | } for |
||
2840 | /seta charvals 0 get def |
||
2841 | /setb charvals 1 get def |
||
2842 | /setc charvals 2 get def |
||
16255 | fschmid | 2843 | |
20313 | craig | 2844 | % Include pseudo characters for GS1-128 Composite linkage identifiers |
2845 | seta lka seta swb get put seta lkc seta swc get put |
||
2846 | setb lka setb swc get put setb lkc setb swa get put |
||
2847 | setc lka setc swa get put setc lkc setc swb get put |
||
16255 | fschmid | 2848 | |
20313 | craig | 2849 | raw {/encoding (raw) def} if |
16255 | fschmid | 2850 | |
20313 | craig | 2851 | encoding (raw) eq { |
2852 | /cws barlen array def |
||
2853 | /i 0 def /j 0 def |
||
2854 | { % loop |
||
2855 | i barlen eq {exit} if |
||
2856 | /cw barcode i 1 add 3 getinterval cvi def |
||
2857 | cws j cw put |
||
2858 | /i i 4 add def |
||
2859 | /j j 1 add def |
||
2860 | } loop |
||
2861 | /cws cws 0 j getinterval def |
||
2862 | /text () def |
||
2863 | } if |
||
16255 | fschmid | 2864 | |
20313 | craig | 2865 | encoding (auto) eq { |
16255 | fschmid | 2866 | |
20313 | craig | 2867 | /fncvals << |
2868 | (FNC1) fn1 |
||
2869 | (FNC2) fn2 |
||
2870 | (FNC3) fn3 |
||
20271 | craig | 2871 | % (FNC4) fn4 Not user accessible as encoded automatically |
20313 | craig | 2872 | (LNKA) lka |
2873 | (LNKC) lkc |
||
2874 | >> def |
||
16255 | fschmid | 2875 | |
20313 | craig | 2876 | % Convert input into bytes accounting for FNC and LNK characters |
2877 | /msg barlen array def |
||
2878 | /text barlen string def |
||
2879 | /i 0 def /j 0 def { |
||
2880 | i barlen eq {exit} if |
||
2881 | /char barcode i get def |
||
2882 | text j char put |
||
2883 | parsefnc char 94 eq and i barlen 4 sub lt and { |
||
2884 | barcode i 1 add get 94 ne { |
||
2885 | /char fncvals barcode i 1 add 4 getinterval get def |
||
2886 | text j ( ) putinterval |
||
2887 | /i i 4 add def |
||
2888 | } { |
||
2889 | /i i 1 add def |
||
2890 | } ifelse |
||
2891 | } if |
||
2892 | msg j char put |
||
2893 | /i i 1 add def |
||
2894 | /j j 1 add def |
||
2895 | } loop |
||
2896 | /msg msg 0 j getinterval def |
||
2897 | /msglen msg length def |
||
2898 | /text text 0 j getinterval def |
||
16255 | fschmid | 2899 | |
20313 | craig | 2900 | % Standard and extended ASCII runlength at position |
2901 | /numSA [ msglen {0} repeat 0 ] def |
||
2902 | /numEA [ msglen {0} repeat 0 ] def |
||
2903 | msglen 1 sub -1 0 { |
||
2904 | /i exch def |
||
2905 | msg i get 0 ge { |
||
2906 | msg i get 128 ge { |
||
2907 | numEA i numEA i 1 add get 1 add put |
||
2908 | } { |
||
2909 | numSA i numSA i 1 add get 1 add put |
||
2910 | } ifelse |
||
2911 | } if |
||
2912 | } for |
||
20271 | craig | 2913 | |
20313 | craig | 2914 | % FNC4 codeword insertion for extended ASCII |
2915 | /ea false def /msgtmp [] def |
||
2916 | |||
2917 | /i exch def |
||
2918 | /c msg i get def |
||
2919 | ea c 128 lt xor not c 0 ge and { % Other mode required |
||
2920 | ea {numSA} {numEA} ifelse i get dup % Runlength of other mode |
||
2921 | i add msglen eq {3} {5} ifelse % Does run terminate symbol |
||
2922 | lt { % Shift |
||
2923 | /msgtmp [ msgtmp aload pop fn4 ] def |
||
2924 | } { % Latch |
||
2925 | /msgtmp [ msgtmp aload pop fn4 fn4 ] def |
||
2926 | /ea ea not def |
||
2927 | } ifelse |
||
2928 | } if |
||
2929 | /msgtmp [ msgtmp aload pop c 0 ge {c 127 and} {c} ifelse ] def |
||
2930 | } for |
||
2931 | /msg msgtmp def |
||
2932 | /msglen msg length def |
||
20271 | craig | 2933 | |
20313 | craig | 2934 | % Determine digit runlength and characters from given position |
2935 | /numsscr { |
||
2936 | /n 0 def /s 0 def |
||
2937 | /p exch def { |
||
2938 | p msglen ge {exit} if |
||
2939 | msg p get |
||
2940 | dup setc exch known not {pop exit} if |
||
2941 | fn1 eq { |
||
2942 | % FNC1 in odd position of run like two digits |
||
2943 | s 2 mod 0 eq {/s s 1 add def} {exit} ifelse |
||
2944 | } if |
||
2945 | /n n 1 add def |
||
2946 | /s s 1 add def |
||
2947 | /p p 1 add def |
||
2948 | } loop |
||
2949 | n s |
||
2950 | } bind def |
||
16255 | fschmid | 2951 | |
20313 | craig | 2952 | % Encoding for each alphabet |
2953 | /enca { |
||
2954 | seta exch get cws exch j exch put |
||
2955 | /j j 1 add def |
||
2956 | } bind def |
||
2957 | /encb { |
||
2958 | setb exch get cws exch j exch put |
||
2959 | /j j 1 add def |
||
2960 | } bind def |
||
2961 | /encc { |
||
2962 | dup type /arraytype ne { |
||
2963 | setc exch get |
||
2964 | } { |
||
2965 | aload pop 48 sub exch 48 sub 10 mul add |
||
2966 | } ifelse |
||
2967 | cws exch j exch put |
||
2968 | /j j 1 add def |
||
2969 | } bind def |
||
16255 | fschmid | 2970 | |
20313 | craig | 2971 | % Character exclusively in either alphabet A or B |
2972 | /anotb {dup seta exch known exch setb exch known not and} bind def |
||
2973 | /bnota {dup setb exch known exch seta exch known not and} bind def |
||
18224 | jghali | 2974 | |
20313 | craig | 2975 | % Pre-compute relative position of next anotb and next bnota characters |
2976 | /nextanotb [ msg length {0} repeat 9999 ] def |
||
2977 | /nextbnota [ msg length {0} repeat 9999 ] def |
||
2978 | msg length 1 sub -1 0 { |
||
2979 | /i exch def |
||
2980 | msg i get anotb { |
||
2981 | nextanotb i 0 put |
||
2982 | } { |
||
2983 | nextanotb i nextanotb i 1 add get 1 add put |
||
2984 | } ifelse |
||
2985 | msg i get bnota { |
||
2986 | nextbnota i 0 put |
||
2987 | } { |
||
2988 | nextbnota i nextbnota i 1 add get 1 add put |
||
2989 | } ifelse |
||
2990 | } for |
||
18224 | jghali | 2991 | |
20313 | craig | 2992 | % Does a-only come before b-only after given position and vice versa |
2993 | /abeforeb {dup nextanotb exch get exch nextbnota exch get lt} bind def |
||
2994 | /bbeforea {dup nextbnota exch get exch nextanotb exch get lt} bind def |
||
2995 | |||
2996 | /cws barcode length 2 mul 3 add array def |
||
18224 | jghali | 2997 | |
20313 | craig | 2998 | % Select start character |
2999 | /j 0 def |
||
3000 | msglen 0 gt {0 numsscr} {-1 -1} ifelse /nums exch def /nchars exch def |
||
3001 | { % common exit |
||
3002 | msglen 0 eq { |
||
3003 | stb enca |
||
3004 | /cset (setb) def |
||
3005 | exit |
||
3006 | } if |
||
3007 | msglen 2 eq nums 2 eq and { |
||
3008 | stc enca |
||
3009 | /cset (setc) def |
||
3010 | exit |
||
3011 | } if |
||
3012 | nums 4 ge { |
||
3013 | stc enca |
||
3014 | /cset (setc) def |
||
3015 | exit |
||
3016 | } if |
||
3017 | |||
3018 | sta enca |
||
3019 | /cset (seta) def |
||
3020 | exit |
||
3021 | } if |
||
3022 | stb enca |
||
3023 | /cset (setb) def |
||
3024 | exit |
||
3025 | } loop |
||
18224 | jghali | 3026 | |
20313 | craig | 3027 | % Main encoding loop |
3028 | /i 0 def { |
||
3029 | i msglen eq {exit} if |
||
3030 | |||
3031 | i numsscr /nums exch def /nchars exch def |
||
3032 | |||
3033 | % Determine switches and shifts |
||
3034 | { % common exit |
||
3035 | cset (seta) eq cset (setb) eq or nums 4 ge and |
||
3036 | msg i get fn1 ne and { |
||
3037 | nums 2 mod 0 eq { |
||
3038 | swc cset (seta) eq {enca} {encb} ifelse |
||
3039 | /cset (setc) def |
||
3040 | exit |
||
3041 | } { |
||
3042 | msg i get cset (seta) eq {enca} {encb} ifelse |
||
3043 | /i i 1 add def |
||
3044 | swc cset (seta) eq {enca} {encb} ifelse |
||
3045 | /cset (setc) def |
||
3046 | exit |
||
3047 | } ifelse |
||
3048 | } if |
||
3049 | cset (setb) eq msg i get anotb and { |
||
3050 | i msglen 1 sub lt { |
||
3051 | i 1 add bbeforea { |
||
3052 | sft encb |
||
3053 | msg i get enca |
||
3054 | /i i 1 add def |
||
3055 | exit |
||
3056 | } if |
||
3057 | } if |
||
3058 | swa encb |
||
3059 | /cset (seta) def |
||
3060 | exit |
||
3061 | } if |
||
3062 | cset (seta) eq msg i get bnota and { |
||
3063 | i msglen 1 sub lt { |
||
3064 | i 1 add abeforeb { |
||
3065 | sft enca |
||
3066 | msg i get encb |
||
3067 | /i i 1 add def |
||
3068 | exit |
||
3069 | } if |
||
3070 | } if |
||
3071 | swb enca |
||
3072 | /cset (setb) def |
||
3073 | exit |
||
3074 | } if |
||
3075 | cset (setc) eq nums 2 lt and { |
||
3076 | i abeforeb { |
||
3077 | swa encc |
||
3078 | /cset (seta) def |
||
3079 | exit |
||
3080 | } if |
||
3081 | swb encc |
||
3082 | /cset (setb) def |
||
3083 | exit |
||
3084 | } if |
||
3085 | |||
3086 | % No switches or latches so encode |
||
3087 | cset (seta) eq { |
||
3088 | msg i get enca |
||
3089 | /i i 1 add def |
||
3090 | exit |
||
3091 | } if |
||
3092 | cset (setb) eq { |
||
3093 | msg i get encb |
||
3094 | /i i 1 add def |
||
3095 | exit |
||
3096 | } if |
||
3097 | cset (setc) eq { |
||
3098 | msg i get fn1 eq { |
||
3099 | fn1 encc |
||
3100 | /i i 1 add def |
||
3101 | } { |
||
3102 | msg i 2 getinterval encc |
||
3103 | /i i 2 add def |
||
3104 | } ifelse |
||
3105 | exit |
||
3106 | } if |
||
3107 | |||
3108 | exit |
||
3109 | } loop |
||
3110 | |||
3111 | } loop |
||
3112 | /cws cws 0 j getinterval def |
||
3113 | } if % auto encoding |
||
18224 | jghali | 3114 | |
20313 | craig | 3115 | % Derive checksum and place stop character |
3116 | /cws j 2 add array dup 0 cws putinterval def |
||
3117 | /csum cws 0 get def |
||
3118 | 1 1 j 1 sub { |
||
3119 | /i exch def |
||
3120 | /csum csum cws i get i mul add def |
||
3121 | } for |
||
3122 | /csum csum 103 mod def |
||
3123 | cws j csum put |
||
3124 | cws j 1 add seta stp get put |
||
16255 | fschmid | 3125 | |
20313 | craig | 3126 | % Create an array containing the character mappings |
3127 | /encs |
||
3128 | [ (212222) (222122) (222221) (121223) (121322) (131222) (122213) |
||
3129 | (122312) (132212) (221213) (221312) (231212) (112232) (122132) |
||
3130 | (122231) (113222) (123122) (123221) (223211) (221132) (221231) |
||
3131 | (213212) (223112) (312131) (311222) (321122) (321221) (312212) |
||
3132 | (322112) (322211) (212123) (212321) (232121) (111323) (131123) |
||
3133 | (131321) (112313) (132113) (132311) (211313) (231113) (231311) |
||
3134 | (112133) (112331) (132131) (113123) (113321) (133121) (313121) |
||
3135 | (211331) (231131) (213113) (213311) (213131) (311123) (311321) |
||
3136 | (331121) (312113) (312311) (332111) (314111) (221411) (431111) |
||
3137 | (111224) (111422) (121124) (121421) (141122) (141221) (112214) |
||
3138 | (112412) (122114) (122411) (142112) (142211) (241211) (221114) |
||
3139 | (413111) (241112) (134111) (111242) (121142) (121241) (114212) |
||
3140 | (124112) (124211) (411212) (421112) (421211) (212141) (214121) |
||
3141 | (412121) (111143) (111341) (131141) (114113) (114311) (411113) |
||
3142 | (411311) (113141) (114131) (311141) (411131) (211412) (211214) |
||
3143 | (211232) (2331112) |
||
3144 | ] def |
||
4460 | subik | 3145 | |
20313 | craig | 3146 | % Derive space bar succession |
3147 | /sbs cws length 6 mul 1 add string def |
||
3148 | |||
3149 | /i exch def |
||
3150 | sbs i 6 mul encs cws i get get putinterval |
||
3151 | } for |
||
4460 | subik | 3152 | |
20313 | craig | 3153 | % Return the arguments |
3154 | << |
||
3155 | /ren //renlinear |
||
3156 | /sbs [sbs {48 sub} forall] |
||
3157 | /bhs [sbs length 1 add 2 idiv {height} repeat] |
||
3158 | /bbs [sbs length 1 add 2 idiv {0} repeat] |
||
3159 | /txt [ [text textxoffset textyoffset textfont textsize] ] |
||
3160 | /textxalign (center) |
||
3161 | /opt options |
||
3162 | >> |
||
4460 | subik | 3163 | |
20313 | craig | 3164 | dontdraw not //renlinear if |
16255 | fschmid | 3165 | |
20313 | craig | 3166 | end |
16255 | fschmid | 3167 | |
3168 | } bind def |
||
3169 | /code128 dup load /uk.co.terryburton.bwipp defineresource pop |
||
3170 | end |
||
3171 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 3172 | %%EndData |
3173 | %%EndResource |
||
16255 | fschmid | 3174 | % --END ENCODER code128-- |
3175 | |||
3176 | % --BEGIN ENCODER gs1-128-- |
||
18800 | fschmid | 3177 | % --REQUIRES preamble raiseerror renlinear code128-- |
16255 | fschmid | 3178 | % --DESC: GS1-128 |
3179 | % --EXAM: (01)95012345678903(3103)000123 |
||
3180 | % --EXOP: includetext |
||
3181 | % --RNDR: renlinear |
||
22439 | craig | 3182 | %%BeginResource: uk.co.terryburton.bwipp gs1-128 0.0 2018020400 80021 79624 |
3183 | %%BeginData: 158 ASCII Lines |
||
16255 | fschmid | 3184 | /setpacking where {pop currentpacking true setpacking} if |
3185 | 1 dict |
||
18800 | fschmid | 3186 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 3187 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
3188 | dup /code128 dup /uk.co.terryburton.bwipp findresource put |
||
3189 | begin |
||
3190 | /gs1-128 { |
||
3191 | |||
20313 | craig | 3192 | 20 dict begin % Confine variables to local scope |
16255 | fschmid | 3193 | |
20313 | craig | 3194 | /options exch def % We are given an option string |
3195 | /barcode exch def % We are given a barcode string |
||
16255 | fschmid | 3196 | |
20313 | craig | 3197 | /dontdraw false def |
3198 | /includetext false def % Enable/disable text |
||
3199 | /textfont /Courier def |
||
3200 | /textsize 10 def |
||
3201 | /textxoffset 0 def |
||
3202 | /textyoffset -7 def |
||
3203 | /height 0.5 def |
||
3204 | /linkagea false def |
||
3205 | /linkagec false def |
||
3206 | |||
3207 | % Parse the input options |
||
3208 | options type /stringtype eq { |
||
3209 | 1 dict begin |
||
3210 | options { |
||
3211 | token false eq {exit} if dup length string cvs (=) search |
||
3212 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
3213 | } loop |
||
3214 | currentdict end /options exch def |
||
3215 | } if |
||
3216 | options {def} forall |
||
16255 | fschmid | 3217 | |
20313 | craig | 3218 | /textfont textfont cvlit def |
3219 | /textsize textsize cvr def |
||
3220 | /textxoffset textxoffset cvr def |
||
3221 | /textyoffset textyoffset cvr def |
||
3222 | /height height cvr def |
||
3223 | |||
3224 | /text barcode def |
||
22439 | craig | 3225 | |
20313 | craig | 3226 | % Expand ordinals of the form ^NNN to ASCII |
3227 | /expand { |
||
3228 | /in exch def |
||
3229 | /out in length string def |
||
3230 | /j 0 def |
||
3231 | in |
||
3232 | { % loop |
||
3233 | (^) search { |
||
3234 | dup out exch j exch putinterval |
||
3235 | length j add 1 add /j exch def |
||
3236 | pop |
||
3237 | dup 0 3 getinterval cvi out exch j 1 sub exch put |
||
3238 | dup length 3 sub 3 exch getinterval |
||
3239 | } { |
||
3240 | dup out exch j exch putinterval |
||
3241 | length j add /j exch def |
||
3242 | out 0 j getinterval exit |
||
22439 | craig | 3243 | } ifelse |
20313 | craig | 3244 | } loop |
3245 | } bind def |
||
22439 | craig | 3246 | |
20313 | craig | 3247 | % Parse out AIs |
22439 | craig | 3248 | /ais [] def |
3249 | /vals [] def |
||
20313 | craig | 3250 | barcode dup length 1 sub 1 exch getinterval |
3251 | { % loop |
||
3252 | dup () eq {exit} if |
||
3253 | (\)) search pop |
||
3254 | exch pop |
||
3255 | exch (\() search { |
||
22439 | craig | 3256 | exch pop exch 3 1 roll |
3257 | } { |
||
20313 | craig | 3258 | () 3 1 roll |
3259 | } ifelse |
||
22439 | craig | 3260 | [ ais aload pop counttomark 2 add index ] /ais exch def |
3261 | [ vals aload pop counttomark 1 add index expand ] /vals exch def |
||
3262 | pop pop |
||
20313 | craig | 3263 | } loop |
3264 | pop |
||
4460 | subik | 3265 | |
20313 | craig | 3266 | % Pre-defined fixed length data field AIs |
3267 | % any AI whose prefix is not included in this table must be |
||
3268 | % terminated with "FNC1", even if it's fixed length |
||
3269 | /aifixed 23 dict def |
||
3270 | [ |
||
3271 | |||
3272 | ] { |
||
3273 | (00) 2 string copy dup dup 1 5 -1 roll 48 add put aifixed 3 1 roll put |
||
3274 | } forall |
||
3275 | [ |
||
3276 | 11 1 20 {} for |
||
3277 | 23 |
||
3278 | 31 1 36 {} for |
||
3279 | 41 |
||
3280 | ] { |
||
3281 | 10 2 string cvrs dup aifixed 3 1 roll put |
||
3282 | } forall |
||
4460 | subik | 3283 | |
20313 | craig | 3284 | % Create the code128 data |
3285 | /fnc1 -1 def |
||
3286 | /c128 [ fnc1 ] def |
||
3287 | |||
3288 | /i exch def |
||
3289 | /ai ais i get def |
||
22439 | craig | 3290 | /val vals i get def |
20313 | craig | 3291 | c128 length ai length add val length add array |
3292 | dup 0 c128 putinterval |
||
3293 | dup c128 length ai [ exch {} forall ] putinterval |
||
3294 | dup c128 length ai length add val [ exch {} forall ] putinterval |
||
3295 | /c128 exch def |
||
3296 | i ais length 1 sub ne aifixed ai 0 2 getinterval known not and { % Append FNC1 |
||
3297 | c128 length 1 add array |
||
3298 | dup 0 c128 putinterval |
||
3299 | dup c128 length fnc1 put |
||
3300 | /c128 exch def |
||
3301 | } if |
||
3302 | } for |
||
16255 | fschmid | 3303 | |
20313 | craig | 3304 | % Compose input to code128 |
3305 | /barcode c128 length 1 add 5 mul string def |
||
3306 | /i 0 def /j 0 def { |
||
3307 | i c128 length eq {exit} if |
||
3308 | c128 i get dup fnc1 eq { |
||
3309 | pop barcode j (^FNC1) putinterval |
||
3310 | /j j 4 add def |
||
3311 | } { |
||
3312 | barcode exch j exch put |
||
3313 | } ifelse |
||
3314 | /i i 1 add def |
||
3315 | /j j 1 add def |
||
3316 | } loop |
||
3317 | linkagea linkagec or { |
||
3318 | barcode j linkagea {(^LNKA)} {(^LNKC)} ifelse putinterval |
||
3319 | /j j 5 add def |
||
3320 | } if |
||
3321 | /barcode barcode 0 j getinterval def |
||
4460 | subik | 3322 | |
20313 | craig | 3323 | % Get the result of encoding with code128 |
3324 | options (height) height put |
||
3325 | options (dontdraw) true put |
||
3326 | options (parsefnc) true put |
||
3327 | /args barcode options //code128 exec def |
||
4460 | subik | 3328 | |
20313 | craig | 3329 | args (txt) [ [text textxoffset textyoffset textfont textsize] ] put |
3330 | args (textxalign) (center) put |
||
3331 | args (opt) options put |
||
3332 | args |
||
3333 | |||
3334 | dontdraw not //renlinear if |
||
3335 | |||
3336 | end |
||
4460 | subik | 3337 | |
16255 | fschmid | 3338 | } bind def |
3339 | /gs1-128 dup load /uk.co.terryburton.bwipp defineresource pop |
||
3340 | end |
||
3341 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 3342 | %%EndData |
3343 | %%EndResource |
||
16255 | fschmid | 3344 | % --END ENCODER gs1-128-- |
4460 | subik | 3345 | |
16255 | fschmid | 3346 | % --BEGIN ENCODER ean14-- |
18800 | fschmid | 3347 | % --REQUIRES preamble raiseerror renlinear code128-- |
16255 | fschmid | 3348 | % --DESC: GS1-14 |
20271 | craig | 3349 | % --EXAM: (01) 0 46 01234 56789 3 |
16255 | fschmid | 3350 | % --EXOP: includetext |
3351 | % --RNDR: renlinear |
||
22439 | craig | 3352 | %%BeginResource: uk.co.terryburton.bwipp ean14 0.0 2018020400 71196 70896 |
20271 | craig | 3353 | %%BeginData: 105 ASCII Lines |
16255 | fschmid | 3354 | /setpacking where {pop currentpacking true setpacking} if |
3355 | 1 dict |
||
18800 | fschmid | 3356 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 3357 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
3358 | dup /code128 dup /uk.co.terryburton.bwipp findresource put |
||
3359 | begin |
||
3360 | /ean14 { |
||
3361 | |||
20313 | craig | 3362 | 20 dict begin % Confine variables to local scope |
16255 | fschmid | 3363 | |
20313 | craig | 3364 | /options exch def % We are given an option string |
3365 | /barcode exch def % We are given a barcode string |
||
16255 | fschmid | 3366 | |
20313 | craig | 3367 | /dontdraw false def |
3368 | /includetext false def % Enable/disable text |
||
3369 | /textfont /Courier def |
||
3370 | /textsize 10 def |
||
3371 | /textxoffset 0 def |
||
3372 | /textyoffset -7 def |
||
3373 | /height 1 def |
||
20271 | craig | 3374 | |
20313 | craig | 3375 | % Parse the input options |
3376 | options type /stringtype eq { |
||
3377 | 1 dict begin |
||
3378 | options { |
||
3379 | token false eq {exit} if dup length string cvs (=) search |
||
3380 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
3381 | } loop |
||
3382 | currentdict end /options exch def |
||
3383 | } if |
||
3384 | options {def} forall |
||
4460 | subik | 3385 | |
20313 | craig | 3386 | /textfont textfont cvlit def |
3387 | /textsize textsize cvr def |
||
3388 | /textxoffset textxoffset cvr def |
||
3389 | /textyoffset textyoffset cvr def |
||
3390 | /height height cvr def |
||
13293 | subik | 3391 | |
20313 | craig | 3392 | % Strip spaces from the given data |
3393 | /text barcode def |
||
3394 | barcode dup length string exch 0 exch |
||
3395 | {dup 32 ne {3 copy put pop 1 add} {pop} ifelse} forall |
||
3396 | |||
3397 | /hasspace text length barcode length ne def |
||
3398 | |||
3399 | % Validate the input |
||
3400 | barcode 0 4 getinterval (\(01\)) ne { |
||
3401 | /bwipp.ean14badAI (GS1-14 must begin with (01) application identifier) //raiseerror exec |
||
3402 | } if |
||
3403 | barcode length 17 ne barcode length 18 ne and { |
||
3404 | /bwipp.ean14badLength (GS1-14 must be 13 or 14 digits) //raiseerror exec |
||
3405 | } if |
||
3406 | barcode 4 barcode length 4 sub getinterval { |
||
3407 | dup 48 lt exch 57 gt or { |
||
3408 | /bwipp.ean14badCharacter (GS1-14 must contain only digits) //raiseerror exec |
||
3409 | } if |
||
3410 | } forall |
||
16255 | fschmid | 3411 | |
20313 | craig | 3412 | % Calculate checksum and add to end of barcode |
3413 | /checksum 0 def |
||
3414 | |||
3415 | /i exch def |
||
3416 | /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def |
||
3417 | } for |
||
3418 | /checksum 10 checksum 10 mod sub 10 mod def |
||
3419 | barcode length 18 eq { |
||
3420 | barcode 17 get checksum 48 add ne { |
||
3421 | /bwipp.ean14badCheckDigit (Incorrect GS1-14 check digit provided) //raiseerror exec |
||
3422 | } if |
||
3423 | } { |
||
3424 | 18 string |
||
3425 | dup 0 barcode putinterval |
||
3426 | dup 17 checksum 48 add put |
||
3427 | /barcode exch def |
||
3428 | text length hasspace {2} {1} ifelse add string |
||
3429 | dup dup length 2 sub ( ) putinterval |
||
3430 | dup dup length 1 sub checksum 48 add put |
||
3431 | dup 0 text putinterval |
||
3432 | /text exch def |
||
3433 | } ifelse |
||
3434 | /gtin barcode 4 14 getinterval def |
||
18800 | fschmid | 3435 | |
20313 | craig | 3436 | % Compose input to code128 |
3437 | /barcode 21 string def |
||
3438 | barcode 0 (^FNC101) putinterval |
||
3439 | barcode 7 gtin putinterval |
||
16255 | fschmid | 3440 | |
20313 | craig | 3441 | % Get the result of encoding with code128 |
3442 | options (dontdraw) true put |
||
3443 | options (parsefnc) true put |
||
3444 | /args barcode options //code128 exec def |
||
16255 | fschmid | 3445 | |
20313 | craig | 3446 | args (txt) [ [text textxoffset textyoffset textfont textsize] ] put |
3447 | args (textxalign) (center) put |
||
3448 | args (opt) options put |
||
3449 | args |
||
3450 | |||
3451 | dontdraw not //renlinear if |
||
3452 | |||
3453 | end |
||
4460 | subik | 3454 | |
3455 | } bind def |
||
16255 | fschmid | 3456 | /ean14 dup load /uk.co.terryburton.bwipp defineresource pop |
3457 | end |
||
3458 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 3459 | %%EndData |
3460 | %%EndResource |
||
16255 | fschmid | 3461 | % --END ENCODER ean14-- |
4460 | subik | 3462 | |
16255 | fschmid | 3463 | % --BEGIN ENCODER sscc18-- |
18800 | fschmid | 3464 | % --REQUIRES preamble raiseerror renlinear code128-- |
16255 | fschmid | 3465 | % --DESC: SSCC-18 |
20271 | craig | 3466 | % --EXAM: (00) 0 0614141 123456789 0 |
16255 | fschmid | 3467 | % --EXOP: includetext |
3468 | % --RNDR: renlinear |
||
22439 | craig | 3469 | %%BeginResource: uk.co.terryburton.bwipp sscc18 0.0 2018020400 71208 70903 |
20271 | craig | 3470 | %%BeginData: 105 ASCII Lines |
16255 | fschmid | 3471 | /setpacking where {pop currentpacking true setpacking} if |
3472 | 1 dict |
||
18800 | fschmid | 3473 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 3474 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
3475 | dup /code128 dup /uk.co.terryburton.bwipp findresource put |
||
3476 | begin |
||
3477 | /sscc18 { |
||
3478 | |||
20313 | craig | 3479 | 20 dict begin % Confine variables to local scope |
16255 | fschmid | 3480 | |
20313 | craig | 3481 | /options exch def % We are given an option string |
3482 | /barcode exch def % We are given a barcode string |
||
16255 | fschmid | 3483 | |
20313 | craig | 3484 | /dontdraw false def |
3485 | /includetext false def % Enable/disable text |
||
3486 | /textfont /Courier def |
||
3487 | /textsize 10 def |
||
3488 | /textxoffset 0 def |
||
3489 | /textyoffset -7 def |
||
3490 | /height 1 def |
||
3491 | |||
3492 | % Parse the input options |
||
3493 | options type /stringtype eq { |
||
3494 | 1 dict begin |
||
3495 | options { |
||
3496 | token false eq {exit} if dup length string cvs (=) search |
||
3497 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
3498 | } loop |
||
3499 | currentdict end /options exch def |
||
3500 | } if |
||
3501 | options {def} forall |
||
16255 | fschmid | 3502 | |
20313 | craig | 3503 | /textfont textfont cvlit def |
3504 | /textsize textsize cvr def |
||
3505 | /textxoffset textxoffset cvr def |
||
3506 | /textyoffset textyoffset cvr def |
||
3507 | /height height cvr def |
||
16255 | fschmid | 3508 | |
20313 | craig | 3509 | % Strip spaces from the given data |
3510 | /text barcode def |
||
3511 | barcode dup length string exch 0 exch |
||
3512 | {dup 32 ne {3 copy put pop 1 add} {pop} ifelse} forall |
||
3513 | |||
3514 | /hasspace text length barcode length ne def |
||
20271 | craig | 3515 | |
20313 | craig | 3516 | % Validate the input |
3517 | barcode 0 4 getinterval (\(00\)) ne { |
||
3518 | /bwipp.sscc18badAI (SSCC-18 must begin with (00) application identifier) //raiseerror exec |
||
3519 | } if |
||
3520 | barcode length 21 ne barcode length 22 ne and { |
||
3521 | /bwipp.sscc18badLength (SSCC-18 must be 17 or 18 digits) //raiseerror exec |
||
3522 | } if |
||
3523 | barcode 4 barcode length 4 sub getinterval { |
||
3524 | dup 48 lt exch 57 gt or { |
||
3525 | /bwipp.sscc18badCharacter (SSCC-18 must contain only digits) //raiseerror exec |
||
3526 | } if |
||
3527 | } forall |
||
16255 | fschmid | 3528 | |
20313 | craig | 3529 | % Calculate checksum and add to end of barcode |
3530 | /checksum 0 def |
||
3531 | |||
3532 | /i exch def |
||
3533 | /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def |
||
3534 | } for |
||
3535 | /checksum 10 checksum 10 mod sub 10 mod def |
||
3536 | barcode length 22 eq { |
||
3537 | barcode 21 get checksum 48 add ne { |
||
3538 | /bwipp.sscc18badCheckDigit (Incorrect SSCC-18 check digit provided) //raiseerror exec |
||
3539 | } if |
||
3540 | } { |
||
3541 | 22 string |
||
3542 | dup 0 barcode putinterval |
||
3543 | dup 21 checksum 48 add put |
||
3544 | /barcode exch def |
||
3545 | text length hasspace {2} {1} ifelse add string |
||
3546 | dup dup length 2 sub ( ) putinterval |
||
3547 | dup dup length 1 sub checksum 48 add put |
||
3548 | dup 0 text putinterval |
||
3549 | /text exch def |
||
3550 | } ifelse |
||
3551 | /sscc barcode 4 18 getinterval def |
||
18800 | fschmid | 3552 | |
20313 | craig | 3553 | % Compose input to code128 |
3554 | /barcode 25 string def |
||
3555 | barcode 0 (^FNC100) putinterval |
||
3556 | barcode 7 sscc putinterval |
||
16255 | fschmid | 3557 | |
20313 | craig | 3558 | % Get the result of encoding with code128 |
3559 | options (dontdraw) true put |
||
3560 | options (parsefnc) true put |
||
3561 | /args barcode options //code128 exec def |
||
16255 | fschmid | 3562 | |
20313 | craig | 3563 | args (txt) [ [text textxoffset textyoffset textfont textsize] ] put |
3564 | args (textxalign) (center) put |
||
3565 | args (opt) options put |
||
3566 | args |
||
3567 | |||
3568 | dontdraw not //renlinear if |
||
3569 | |||
3570 | end |
||
16255 | fschmid | 3571 | |
3572 | } bind def |
||
3573 | /sscc18 dup load /uk.co.terryburton.bwipp defineresource pop |
||
3574 | end |
||
3575 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 3576 | %%EndData |
3577 | %%EndResource |
||
16255 | fschmid | 3578 | % --END ENCODER sscc18-- |
3579 | |||
4460 | subik | 3580 | % --BEGIN ENCODER code39-- |
18800 | fschmid | 3581 | % --REQUIRES preamble raiseerror renlinear-- |
7162 | subik | 3582 | % --DESC: Code 39 |
3583 | % --EXAM: THIS IS CODE 39 |
||
11277 | subik | 3584 | % --EXOP: includetext includecheck includecheckintext |
3585 | % --RNDR: renlinear |
||
22439 | craig | 3586 | %%BeginResource: uk.co.terryburton.bwipp code39 0.0 2018020400 71882 71562 |
18800 | fschmid | 3587 | %%BeginData: 141 ASCII Lines |
16255 | fschmid | 3588 | /setpacking where {pop currentpacking true setpacking} if |
3589 | 1 dict |
||
18800 | fschmid | 3590 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 3591 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
3592 | begin |
||
4460 | subik | 3593 | /code39 { |
3594 | |||
20313 | craig | 3595 | 20 dict begin % Confine variables to local scope |
4460 | subik | 3596 | |
20313 | craig | 3597 | /options exch def % We are given an option string |
3598 | /barcode exch def % We are given a barcode string |
||
4460 | subik | 3599 | |
20313 | craig | 3600 | /dontdraw false def |
3601 | /includecheck false def |
||
3602 | /validatecheck false def |
||
3603 | /includetext false def |
||
3604 | /includecheckintext false def |
||
3605 | /hidestars false def |
||
3606 | /textfont /Courier def |
||
3607 | /textsize 10 def |
||
3608 | /textyoffset -7 def |
||
3609 | /height 1 def |
||
3610 | |||
3611 | % Parse the input options |
||
3612 | options type /stringtype eq { |
||
3613 | 1 dict begin |
||
3614 | options { |
||
3615 | token false eq {exit} if dup length string cvs (=) search |
||
3616 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
3617 | } loop |
||
3618 | currentdict end /options exch def |
||
3619 | } if |
||
3620 | options {def} forall |
||
3621 | |||
3622 | /textfont textfont cvlit def |
||
3623 | /textsize textsize cvr def |
||
3624 | /textyoffset textyoffset cvr def |
||
3625 | /height height cvr def |
||
18800 | fschmid | 3626 | |
20313 | craig | 3627 | % Create a string of the available characters |
3628 | /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def |
||
3629 | /charvals 43 dict def |
||
3630 | |||
18800 | fschmid | 3631 | |
20313 | craig | 3632 | % Validate the input |
3633 | |||
3634 | barcode exch 1 getinterval charvals exch known not { |
||
3635 | /bwipp.code39badCharacter (Code 39 must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec |
||
3636 | } if |
||
3637 | } for |
||
18800 | fschmid | 3638 | |
20313 | craig | 3639 | /barlen barcode length validatecheck {1 sub} if def |
18800 | fschmid | 3640 | |
20313 | craig | 3641 | /checksum 0 def |
3642 | |||
3643 | barcode exch 1 getinterval charvals exch get |
||
3644 | checksum add /checksum exch def |
||
3645 | } for |
||
3646 | /checksum checksum 43 mod def |
||
3647 | validatecheck { |
||
3648 | barcode barlen get barchars checksum get ne { |
||
3649 | /bwipp.code39badCheckDigit (Incorrect Code 39 check digit provided) //raiseerror exec |
||
3650 | } if |
||
3651 | /barcode barcode 0 barlen getinterval def |
||
3652 | /includecheck true def |
||
3653 | } if |
||
18800 | fschmid | 3654 | |
20313 | craig | 3655 | % Create an array containing the character mappings |
3656 | /encs |
||
3657 | [ (1113313111) (3113111131) (1133111131) (3133111111) (1113311131) |
||
3658 | (3113311111) (1133311111) (1113113131) (3113113111) (1133113111) |
||
3659 | (3111131131) (1131131131) (3131131111) (1111331131) (3111331111) |
||
3660 | (1131331111) (1111133131) (3111133111) (1131133111) (1111333111) |
||
3661 | (3111111331) (1131111331) (3131111311) (1111311331) (3111311311) |
||
3662 | (1131311311) (1111113331) (3111113311) (1131113311) (1111313311) |
||
3663 | (3311111131) (1331111131) (3331111111) (1311311131) (3311311111) |
||
3664 | (1331311111) (1311113131) (3311113111) (1331113111) (1313131111) |
||
3665 | (1313111311) (1311131311) (1113131311) (1311313111) |
||
3666 | ] def |
||
4460 | subik | 3667 | |
20313 | craig | 3668 | /sbs barlen includecheck {3} {2} ifelse add 10 mul string def |
3669 | /txt barlen includecheck {3} {2} ifelse add array def |
||
4460 | subik | 3670 | |
20313 | craig | 3671 | % Put the start character |
3672 | sbs 0 encs 43 get putinterval |
||
3673 | hidestars not { |
||
3674 | txt 0 [(*) 0 textyoffset textfont textsize] put |
||
3675 | } { |
||
3676 | txt 0 [() 0 textyoffset textfont textsize] put |
||
3677 | } ifelse |
||
4460 | subik | 3678 | |
20313 | craig | 3679 | |
3680 | /i exch def |
||
3681 | /indx charvals barcode i 1 getinterval get def |
||
3682 | sbs i 10 mul 10 add encs indx get putinterval |
||
3683 | txt i 1 add [barcode i 1 getinterval i 1 add 16 mul textyoffset textfont textsize] put |
||
3684 | } for |
||
4460 | subik | 3685 | |
20313 | craig | 3686 | % Put the checksum and end characters |
3687 | includecheck { |
||
3688 | sbs barlen 10 mul 10 add encs checksum get putinterval |
||
3689 | includecheckintext { |
||
3690 | txt barlen 1 add [barchars checksum 1 getinterval barlen 1 add 16 mul textyoffset textfont textsize] put |
||
3691 | } { |
||
3692 | txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put |
||
3693 | } ifelse |
||
3694 | sbs barlen 10 mul 20 add encs 43 get putinterval |
||
3695 | hidestars not { |
||
3696 | txt barlen 2 add [(*) barlen 2 add 16 mul textyoffset textfont textsize] put |
||
3697 | } { |
||
3698 | txt barlen 2 add [() barlen 2 add 16 mul textyoffset textfont textsize] put |
||
3699 | } ifelse |
||
3700 | } { |
||
3701 | sbs barlen 10 mul 10 add encs 43 get putinterval |
||
3702 | hidestars not { |
||
3703 | txt barlen 1 add [(*) barlen 1 add 16 mul textyoffset textfont textsize] put |
||
3704 | } { |
||
3705 | txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put |
||
3706 | } ifelse |
||
3707 | } ifelse |
||
3708 | |||
3709 | % Return the arguments |
||
3710 | << |
||
3711 | /ren //renlinear |
||
3712 | /sbs [sbs {48 sub} forall] |
||
3713 | /bhs [sbs length 1 add 2 idiv {height} repeat] |
||
3714 | /bbs [sbs length 1 add 2 idiv {0} repeat] |
||
3715 | includetext { |
||
3716 | /txt txt |
||
3717 | } if |
||
3718 | /opt options |
||
3719 | >> |
||
4460 | subik | 3720 | |
20313 | craig | 3721 | dontdraw not //renlinear if |
13293 | subik | 3722 | |
20313 | craig | 3723 | end |
4460 | subik | 3724 | |
3725 | } bind def |
||
16255 | fschmid | 3726 | /code39 dup load /uk.co.terryburton.bwipp defineresource pop |
3727 | end |
||
3728 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 3729 | %%EndData |
3730 | %%EndResource |
||
4460 | subik | 3731 | % --END ENCODER code39-- |
3732 | |||
16255 | fschmid | 3733 | % --BEGIN ENCODER code39ext-- |
18800 | fschmid | 3734 | % --REQUIRES preamble raiseerror renlinear code39-- |
16255 | fschmid | 3735 | % --DESC: Code 39 Extended |
3736 | % --EXAM: Code39 Ext! |
||
3737 | % --EXOP: includetext includecheck includecheckintext |
||
3738 | % --RNDR: renlinear |
||
22439 | craig | 3739 | %%BeginResource: uk.co.terryburton.bwipp code39ext 0.0 2018020400 67995 71251 |
18800 | fschmid | 3740 | %%BeginData: 110 ASCII Lines |
16255 | fschmid | 3741 | /setpacking where {pop currentpacking true setpacking} if |
3742 | 1 dict |
||
18800 | fschmid | 3743 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 3744 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
3745 | dup /code39 dup /uk.co.terryburton.bwipp findresource put |
||
3746 | begin |
||
3747 | /code39ext { |
||
3748 | |||
20313 | craig | 3749 | 20 dict begin |
16255 | fschmid | 3750 | |
20313 | craig | 3751 | /options exch def % We are given an options string |
3752 | /barcode exch def % We are given the code39extended text |
||
16255 | fschmid | 3753 | |
20313 | craig | 3754 | /dontdraw false def |
3755 | /includetext false def |
||
3756 | /parse false def |
||
16255 | fschmid | 3757 | |
20313 | craig | 3758 | % Parse the input options |
3759 | options type /stringtype eq { |
||
3760 | 1 dict begin |
||
3761 | options { |
||
3762 | token false eq {exit} if dup length string cvs (=) search |
||
3763 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
3764 | } loop |
||
3765 | currentdict end /options exch def |
||
3766 | } if |
||
3767 | options {def} forall |
||
16255 | fschmid | 3768 | |
20313 | craig | 3769 | % Parse ordinals of the form ^NNN to ASCII |
3770 | parse { |
||
3771 | /msg barcode length string def |
||
3772 | /j 0 def |
||
3773 | barcode |
||
3774 | { % loop |
||
3775 | (^) search { |
||
3776 | dup msg exch j exch putinterval |
||
3777 | length j add 1 add /j exch def |
||
3778 | pop |
||
3779 | dup 0 3 getinterval cvi msg exch j 1 sub exch put |
||
3780 | dup length 3 sub 3 exch getinterval |
||
3781 | } { |
||
3782 | dup msg exch j exch putinterval |
||
3783 | length j add /j exch def |
||
3784 | /barcode msg 0 j getinterval def |
||
3785 | exit |
||
3786 | } ifelse |
||
3787 | } loop |
||
3788 | } if |
||
16255 | fschmid | 3789 | |
20313 | craig | 3790 | % Validate the input |
3791 | barcode { |
||
3792 | 128 ge { |
||
3793 | /bwipp.code39extBadCharacter (Code 39 Extended must contain only ASCII characters) //raiseerror exec |
||
3794 | } if |
||
3795 | } forall |
||
18800 | fschmid | 3796 | |
20313 | craig | 3797 | /barlen barcode length def |
16255 | fschmid | 3798 | |
20313 | craig | 3799 | % Extended alphabet to non-extended alphabet |
3800 | /extencs |
||
3801 | [ (%U) ($A) ($B) ($C) ($D) ($E) ($F) ($G) ($H) ($I) ($J) ($K) ($L) ($M) ($N) ($O) |
||
3802 | ($P) ($Q) ($R) ($S) ($T) ($U) ($V) ($W) ($X) ($Y) ($Z) (%A) (%B) (%C) (%D) (%E) |
||
3803 | ( ) (/A) (/B) (/C) (/D) (/E) (/F) (/G) (/H) (/I) (/J) (/K) (/L) (-) (.) (/O) |
||
3804 | (0) (1) (2) (3) (4) (5) (6) (7) (8) (9) (/Z) (%F) (%G) (%H) (%I) (%J) |
||
3805 | (%V) (A) (B) (C) (D) (E) (F) (G) (H) (I) (J) (K) (L) (M) (N) (O) |
||
3806 | (P) (Q) (R) (S) (T) (U) (V) (W) (X) (Y) (Z) (%K) (%L) (%M) (%N) (%O) |
||
3807 | (%W) (+A) (+B) (+C) (+D) (+E) (+F) (+G) (+H) (+I) (+J) (+K) (+L) (+M) (+N) (+O) |
||
3808 | (+P) (+Q) (+R) (+S) (+T) (+U) (+V) (+W) (+X) (+Y) (+Z) (%P) (%Q) (%R) (%S) (%T) |
||
3809 | ] def |
||
16255 | fschmid | 3810 | |
20313 | craig | 3811 | /newcode barlen 2 mul string def |
3812 | /newtext barlen 2 mul string def |
||
3813 | /j 0 def |
||
3814 | |||
3815 | /i exch def |
||
3816 | /extchar extencs barcode i get get def |
||
3817 | newcode j extchar putinterval |
||
3818 | newtext j barcode i get put |
||
3819 | extchar length 1 ne {newtext j 1 add ( ) putinterval} if |
||
3820 | /j j extchar length add def |
||
3821 | } for |
||
3822 | /newcode newcode 0 j getinterval def |
||
3823 | /newtext newtext 0 j getinterval def |
||
16255 | fschmid | 3824 | |
20313 | craig | 3825 | % Get the result of encoding with code39 |
3826 | options (dontdraw) true put |
||
3827 | /args newcode options //code39 exec def |
||
16255 | fschmid | 3828 | |
20313 | craig | 3829 | % Replace chars in /txt with chars in newtext |
3830 | includetext { |
||
3831 | /txt args (txt) get def |
||
3832 | |||
3833 | /i exch def |
||
3834 | /txtentry txt i 1 add get def |
||
3835 | txtentry 0 newtext i 1 getinterval put |
||
3836 | txt i 1 add txtentry put |
||
3837 | } for |
||
3838 | args (txt) txt put |
||
3839 | } if |
||
3840 | args (opt) options put |
||
3841 | args |
||
16255 | fschmid | 3842 | |
20313 | craig | 3843 | dontdraw not //renlinear if |
16255 | fschmid | 3844 | |
20313 | craig | 3845 | end |
16255 | fschmid | 3846 | |
3847 | } bind def |
||
3848 | /code39ext dup load /uk.co.terryburton.bwipp defineresource pop |
||
3849 | end |
||
3850 | /setpacking where {pop setpacking} if |
||
18800 | fschmid | 3851 | %%EndData |
3852 | %%EndResource |
||
16255 | fschmid | 3853 | % --END ENCODER code39ext-- |
3854 | |||
3855 | % --BEGIN ENCODER code32-- |
||
18800 | fschmid | 3856 | % --REQUIRES preamble raiseerror renlinear code39-- |
3857 | % --DESC: Italian Pharmacode |
||
16255 | fschmid | 3858 | % --EXAM: 01234567 |
3859 | % --EXOP: includetext |
||
3860 | % --RNDR: renlinear |
||
22439 | craig | 3861 | %%BeginResource: uk.co.terryburton.bwipp code32 0.0 2018020400 65276 68553 |
18800 | fschmid | 3862 | %%BeginData: 99 ASCII Lines |
16255 | fschmid | 3863 | /setpacking where {pop currentpacking true setpacking} if |
3864 | 1 dict |
||
18800 | fschmid | 3865 | dup /raiseerror dup /uk.co.terryburton.bwipp findresource put |
16255 | fschmid | 3866 | dup /renlinear dup /uk.co.terryburton.bwipp findresource put |
3867 | dup /code39 dup /uk.co.terryburton.bwipp findresource put |
||
3868 | begin |
||
3869 | /code32 { |
||
3870 | |||
20313 | craig | 3871 | 20 dict begin |
16255 | fschmid | 3872 | |
20313 | craig | 3873 | /options exch def % We are given an options string |
3874 | /barcode exch def % We are given a barcode string |
||
16255 | fschmid | 3875 | |
20313 | craig | 3876 | /dontdraw false def |
3877 | /includetext false def % Enable/disable code32 text |
||
3878 | /textfont /Courier def |
||
3879 | /textsize 10 def |
||
3880 | /textyoffset -7 def |
||
3881 | /textxoffset 0 def |
||
3882 | /height 1 def |
||
16255 | fschmid | 3883 | |
20313 | craig | 3884 | % Parse the input options |
3885 | options type /stringtype eq { |
||
3886 | 1 dict begin |
||
3887 | options { |
||
3888 | token false eq {exit} if dup length string cvs (=) search |
||
3889 | true eq {cvlit exch pop exch def} {cvlit true def} ifelse |
||
3890 | } loop |
||
3891 | currentdict end /options exch def |
||
3892 | } if |
||
3893 | options {def} forall |
||
16255 | fschmid | 3894 | |
20313 | craig | 3895 | /textfont textfont cvlit def |
3896 | /textsize textsize cvr def |
||
3897 | /textyoffset textyoffset cvr def |
||
3898 | /height height cvr def |
||
16255 | fschmid | 3899 | |
20313 | craig | 3900 | % Validate the input |
3901 | barcode length 8 ne barcode length 9 ne and { |
||
3902 | /bwipp.code32badLength (Italian Pharmacode must be 8 or 9 digits) //raiseerror exec |
||
3903 | } if |
||
3904 | barcode { |
||
3905 | dup 48 lt exch 57 gt or { |
||
3906 | /bwipp.code32badCharacter (Italian Pharmacode must contain only digits) //raiseerror exec |
||
3907 | } if |
||
3908 | } forall |
||
16255 | fschmid | 3909 | |
20313 | craig | 3910 | % Calculate check digit |
3911 | /checksum 0 def |
||
3912 | |||
3913 | /i exch def |
||
3914 | barcode i get 48 sub i 2 mod 0 ne {2 mul} if dup 9 gt {9 sub} if |
||
3915 | checksum add /checksum exch def |
||
3916 | } for |
||
3917 | /checksum checksum 10 mod def |
||
3918 | barcode length 9 eq { |
||
3919 | barcode 8 get checksum 48 add ne { |
||
3920 | /bwipp.code32badCheckDigit (Incorrect Italian Pharmacode check digit provided) //raiseerror exec |
||
3921 | } if |
||
3922 | } if |
||
3923 | 10 string |
||
3924 | dup 0 barcode putinterval |
||
3925 | dup 8 checksum 48 add put |
||
3926 | /text exch def |
||
16255 | fschmid | 3927 | |
20313 | craig | 3928 | % convert number from base10 to base32 |
3929 | /val text cvi 32 barcode cvrs def |
||
3930 | /barcode 6 string def |
||
3931 | |||
3932 | barcode 6 val length sub val putinterval |
||
16255 | fschmid | 3933 | |
20313 | craig | 3934 | % convert base32 number to specified character set |
3935 | |||
3936 | dup barcode exch get |
||
3937 | dup (AEIO) {ge {1 add} if dup} forall pop |
||
3938 | barcode 3 1 roll put |
||
3939 | } for |
||
16255 | fschmid | 3940 | |
20313 | craig | 3941 | % format HRI |
3942 | text 1 text 0 9 getinterval putinterval |
||
3943 | text 0 65 put |
||
16255 | fschmid | 3944 | |