Subversion Repositories Scribus

Rev

Rev 25039 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18800 fschmid 1
%!PS
19685 fschmid 2
 
25039 craig 3
% Barcode Writer in Pure PostScript - Version 2021-09-28
22439 craig 4
% https://bwipp.terryburton.co.uk
4460 subik 5
%
25039 craig 6
% Copyright (c) 2004-2022 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--
25039 craig 35
%%BeginResource: Category uk.co.terryburton.bwipp 0.0 2021092800 29733 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--
25039 craig 49
%%BeginResource: uk.co.terryburton.bwipp raiseerror 0.0 2021092800 39041 38872
50
%%BeginData:         15 ASCII Lines
18800 fschmid 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
25039 craig 60
}
61
[/barcode] {null def} forall
62
bind def
18800 fschmid 63
/raiseerror dup load /uk.co.terryburton.bwipp defineresource pop
64
end
65
/setpacking where {pop setpacking} if
66
%%EndData
67
%%EndResource
68
% --END RESOURCE raiseerror--
69
 
25039 craig 70
% --BEGIN RESOURCE parseinput--
71
% --REQUIRES preamble raiseerror--
72
%%BeginResource: uk.co.terryburton.bwipp parseinput 0.0 2021092800 58513 58076
73
%%BeginData:        129 ASCII Lines
74
/setpacking where {pop currentpacking true setpacking} if
75
4 dict
76
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
77
begin
78
/parseinput {
79
 
80
    6 dict begin
81
 
82
    /fncvals exch def
83
    /barcode exch def
84
 
85
    /parse     dup dup fncvals exch get def fncvals exch undef
86
    /parsefnc  dup dup fncvals exch get def fncvals exch undef
87
    /parseonly dup dup fncvals exch known def fncvals exch undef
88
    /eci       dup dup fncvals exch known def fncvals exch undef
89
 
90
    /msg barcode length array def
91
    /j 0 def
92
    barcode {  % loop
93
        (^) search exch
94
        % Copy characters up to a "^"
95
        dup length exch
96
        msg exch j exch [ exch {} forall ] putinterval
97
        j add /j exch def
98
        {  % Found a "^" escape character
99
            pop
100
            1 {  % common exit
101
 
102
                parse not parsefnc not and {  % "^" as is
103
                    msg j 94 put
104
                    /j j 1 add def
105
                    exit
106
                } if
107
 
108
                % Encode "^" to start with
109
                msg j 94 put
110
                /j j 1 add def
111
 
112
                % parse
113
                parse {
114
                    dup length 3 ge {
115
                        dup 0 3 getinterval true exch {
116
                            dup 48 lt exch 57 gt or { pop false } if
117
                        } forall
118
                        {  % "^NNN" to byte
119
                            dup 0 3 getinterval cvi dup 255 gt {
120
                                pop pop
121
                                /bwipp.invalidOrdinal (Ordinal must be 000 to 255) //raiseerror exec
122
                            } if
123
                            /j j 1 sub def  % Replace "^" with ordinal
124
                            msg exch j exch put
125
                            /j j 1 add def
126
                            dup length 3 sub 3 exch getinterval
127
                        } if
128
                    } if
129
                } if
130
 
131
                parseonly
132
                parsefnc not or
133
                msg j 1 sub get 94 ne  % Carat was substituted away
134
                or {exit} if
135
 
136
                % parsefnc
137
                /j j 1 sub def
138
                dup length 3 lt {
139
                    pop
140
                    /bwipp.truncatedFNC (Function character truncated) //raiseerror exec
141
                } if
142
                dup 0 get 94 eq {  % "^^" -> "^"
143
                    msg j 94 put
144
                    /j j 1 add def
145
                    dup length 1 sub 1 exch getinterval
146
                    exit
147
                } if
148
                dup 0 3 getinterval (ECI) eq eci and {  % "^ECInnnnnn" -> -1nnnnnn
149
                    dup length 9 lt {
150
                        pop
151
                        /bwipp.truncatedECI (ECI truncated) //raiseerror exec
152
                    } if
153
                    dup 3 6 getinterval
154
                    dup {
155
                        dup 48 lt exch 57 gt or {
156
                            pop pop
157
                            /bwipp.invalidECI (ECI must be 000000 to 999999) //raiseerror exec
158
                        } if
159
                    } forall
160
 
161
                    msg exch j exch put
162
                    /j j 1 add def
163
                    dup length 9 sub 9 exch getinterval
164
                    exit
165
                } if
166
                dup length 4 lt {  % "^FNCx" -> fncvals{FNCx}
167
                    pop
168
                    /bwipp.truncatedFNC (Function character truncated) //raiseerror exec
169
                } if
170
                dup 0 4 getinterval dup fncvals exch known not {
171
                    dup length 28 add string dup 28 4 -1 roll putinterval
172
                    dup 0 (Unknown function character: ) putinterval
173
                    exch pop
174
                    /bwipp.unknownFNC exch //raiseerror exec
175
                } if
176
                fncvals exch get
177
                msg exch j exch put
178
                /j j 1 add def
179
                dup length 4 sub 4 exch getinterval
180
                exit
181
 
182
            } repeat
183
        } {  % No more "^" characters
184
            exit
185
        }  ifelse
186
    } loop
187
 
188
    parseonly not {
189
        msg 0 j getinterval
190
    } {
191
        j string
192
 
193
    } ifelse
194
 
195
    end
196
 
197
}
198
[/barcode] {null def} forall
199
bind def
200
/parseinput dup load /uk.co.terryburton.bwipp defineresource pop
201
end
202
/setpacking where {pop setpacking} if
203
%%EndData
204
%%EndResource
205
% --END RESOURCE parseinput--
206
 
207
% --BEGIN RESOURCE gs1lint--
208
% --REQUIRES preamble raiseerror--
209
%%BeginResource: uk.co.terryburton.bwipp gs1lint 0.0 2021092800 346062 386888
210
%%BeginData:       1674 ASCII Lines
211
/setpacking where {pop currentpacking true setpacking} if
212
2 dict
213
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
214
begin
215
/gs1lint {
216
 
217
    20 dict begin
218
 
219
    /vals exch def
220
    /ais exch def
221
 
222
    /lintnumeric {
223
        true exch {
224
            dup 48 lt exch 57 gt or { pop false exit } if
225
        } forall
226
        not { pop /bwipp.GS1notNumeric (Not numeric) false exit } if
227
    } bind def
228
 
229
    /lintcset82 {
230
        true exch {
231
            1 string dup 0 4 -1 roll put
232
            (!"%&'()*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz)
233
            exch search not { pop pop false exit } if
234
            pop pop pop
235
        } forall
236
        not { pop /bwipp.GS1badCSET82character (Invalid CSET 82 character) false exit } if
237
    } bind def
238
 
239
    /lintcset39 {
240
        true exch {
241
            1 string dup 0 4 -1 roll put
242
            (#-/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ)
243
            exch search not { pop pop false exit } if
244
            pop pop pop
245
        } forall
246
        not { pop /bwipp.GS1badCSET39character  (Invalid CSET 39 character) false exit } if
247
    } bind def
248
 
249
    /lintkey {
250
        dup length 2 lt { pop pop /bwipp.GS1keyTooShort (Key is too short) false exit } if
251
        dup 0 get dup 48 lt exch 57 gt or exch
252
        1 get dup 48 lt exch 57 gt or or {
253
            pop /bwipp.GS1badGCP (Non-numeric company prefix) false exit
254
        } if
255
    } bind def
256
 
257
    /lintimporteridx {
258
        (-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz)
259
        exch search not {pop pop /bwipp.GS1badImporterIndex (Invalid importer index) false exit} if
260
        pop pop pop
261
    } bind def
262
 
263
    /lintcsum {
264
        mark exch
265
        dup length 2 mod 0 eq {3} {1} ifelse
266
        exch { 48 sub 1 index mul exch 4 exch sub } forall pop
267
 
268
        10 mod 0 ne { pop /bwipp.GS1badChecksum (Bad checksum) false exit } if
269
    } bind def
270
 
271
    /cset82 <<
272
 
273
        { exch dup 1 add } forall pop
274
    >> def
275
 
276
    /cset32 <<
277
 
278
        { exch dup 1 add } forall pop
279
    >> def
280
 
281
    /lintcsumalpha {
282
        dup length 2 lt { pop pop /bwipp.GS1alphaTooShort (Alphanumeric string is too short to check) false exit} if
283
        dup length 2 sub
284
        2 copy
285
 
286
            dup cset82 exch known { cset82 exch get } { -1 exit } ifelse
287
        } forall
288
        dup -1 eq { cleartomark pop pop pop /bwipp.GS1UnknownCSET82Character (Unknown CSET 82 character) false exit} if
289
        counttomark array astore exch pop
290
        3 1 roll
291
        2 getinterval mark exch {
292
            dup cset32 exch known { cset32 exch get } { -1 exit } ifelse
293
        } forall
294
        dup -1 eq { cleartomark pop pop /bwipp.GS1UnknownCSET32Character (Unknown CSET 32 character) false exit} if
295
        counttomark array astore exch pop
296
        dup 0 get 5 bitshift exch 1 get add exch
297
        [ 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 ]
298
        1 index length
299
        dup 2 index length gt { pop pop pop pop pop /bwipp.GS1alphaTooLong (Alphanumeric string is too long to check) false exit} if
300
 
301
 
302
        ne { pop /bwipp.GS1badAlphaCheckCharacters (Bad alphanumeric check characters) false exit} if
303
    } bind def
304
 
305
    /iso3166 << [
306
        /004 /008 /010 /012 /016 /020 /024 /028 /031 /032 /036 /040 /044 /048
307
        /050 /051 /052 /056 /060 /064 /068 /070 /072 /074 /076 /084 /086 /090 /092 /096
308
        /100 /104 /108 /112 /116 /120 /124 /132 /136 /140 /144 /148
309
        /152 /156 /158 /162 /166 /170 /174 /175 /178 /180 /184 /188 /191 /192 /196
310
        /203 /204 /208 /212 /214 /218 /222 /226 /231 /232 /233 /234 /238 /239 /242 /246 /248
311
        /250 /254 /258 /260 /262 /266 /268 /270 /275 /276 /288 /292 /296
312
        /300 /304 /308 /312 /316 /320 /324 /328 /332 /334 /336 /340 /344 /348
313
        /352 /356 /360 /364 /368 /372 /376 /380 /384 /388 /392 /398
314
        /400 /404 /408 /410 /414 /417 /418 /422 /426 /428 /430 /434 /438 /440 /442 /446
315
        /450 /454 /458 /462 /466 /470 /474 /478 /480 /484 /492 /496 /498 /499
316
        /500 /504 /508 /512 /516 /520 /524 /528 /531 /533 /534 /535 /540 /548
317
        /554 /558 /562 /566 /570 /574 /578 /580 /581 /583 /584 /585 /586 /591 /598
318
        /600 /604 /608 /612 /616 /620 /624 /626 /630 /634 /638 /642 /643 /646
319
        /652 /654 /659 /660 /662 /663 /666 /670 /674 /678 /682 /686 /688 /690 /694
320
        /702 /703 /704 /705 /706 /710 /716 /724 /728 /729 /732 /740 /744 /748
321
        /752 /756 /760 /762 /764 /768 /772 /776 /780 /784 /788 /792 /795 /796 /798
322
        /800 /804 /807 /818 /826 /831 /832 /833 /834 /840
323
        /850 /854 /858 /860 /862 /876 /882 /887 /894
324
    ] {dup} forall >> def
325
 
326
    /lintiso3166 {
327
        iso3166 exch known not { pop /bwipp.GS1UnknownCountry (Unknown country code) false exit } if
328
    } bind def
329
 
330
    /lintiso3166999 {
331
        dup /999 ne {
332
            iso3166 exch known not { pop /bwipp.GS1UnknownCountryOr999 (Unknown country code or not 999) false exit } if
333
        } {
334
            pop
335
        } ifelse
336
    } bind def
337
 
338
    /lintiso3166list {
339
        dup length 3 mod 0 ne {
340
            pop pop /bwipp.GS1BadCountryListLength (Not a group of three-digit country codes) false exit
341
        } if
342
        true
343
 
344
            2 index exch 3 getinterval
345
            iso3166 exch known not { pop pop false exit } if
346
        } for
347
        not { pop /bwipp.GS1UnknownCountry (Unknown country code) false exit } if
348
        pop
349
    } bind def
350
 
351
    /iso3166alpha2 << [
352
        /AD /AE /AF /AG /AI /AL /AM /AO /AQ /AR /AS /AT /AU /AW /AX /AZ
353
        /BA /BB /BD /BE /BF /BG /BH /BI /BJ /BL /BM /BN /BO /BQ /BR /BS /BT /BV /BW /BY /BZ
354
        /CA /CC /CD /CF /CG /CH /CI /CK /CL /CM /CN /CO /CR /CU /CV /CW /CX /CY /CZ
355
        /DE /DJ /DK /DM /DO /DZ
356
        /EC /EE /EG /EH /ER /ES /ET
357
        /FI /FJ /FK /FM /FO /FR
358
        /GA /GB /GD /GE /GF /GG /GH /GI /GL /GM /GN /GP /GQ /GR /GS /GT /GU /GW /GY
359
        /HK /HM /HN /HR /HT /HU
360
        /ID /IE /IL /IM /IN /IO /IQ /IR /IS /IT /JE /JM /JO /JP
361
        /KE /KG /KH /KI /KM /KN /KP /KR /KW /KY /KZ
362
        /LA /LB /LC /LI /LK /LR /LS /LT /LU /LV /LY
363
        /MA /MC /MD /ME /MF /MG /MH /MK /ML /MM /MN /MO /MP /MQ /MR /MS /MT /MU /MV /MW /MX /MY /MZ
364
        /NA /NC /NE /NF /NG /NI /NL /NO /NP /NR /NU /NZ
365
        /OM
366
        /PA /PE /PF /PG /PH /PK /PL /PM /PN /PR /PS /PT /PW /PY
367
        /QA
368
        /RE /RO /RS /RU /RW
369
        /SA /SB /SC /SD /SE /SG /SH /SI /SJ /SK /SL /SM /SN /SO /SR /SS /ST /SV /SX /SY /SZ
370
        /TC /TD /TF /TG /TH /TJ /TK /TL /TM /TN /TO /TR /TT /TV /TW /TZ
371
        /UA /UG /UM /US /UY /UZ
372
        /VA /VC /VE /VG /VI /VN /VU
373
        /WF /WS
374
        /YE /YT
375
        /ZA /ZM /ZW
376
    ] {dup} forall >> def
377
 
378
    /lintiso3166alpha2 {
379
        iso3166alpha2 exch known not { pop /bwipp.GS1UnknownCountryAlpha (Unknown country alpha code) false exit } if
380
    } bind def
381
 
382
    /iso4217 << [
383
        /008 /012 /032 /036 /044 /048
384
        /050 /051 /052 /060 /064 /068 /072 /084 /090 /096
385
        /104 /108 /116 /124 /132 /136 /144
386
        /152 /156 /170 /174 /188 /191 /192
387
        /203 /208 /214 /222 /230 /232 /238 /242 /262 /270 /292
388
        /320 /324 /328 /332 /340 /344 /348
389
        /352 /356 /360 /364 /368 /376 /388 /392 /398
390
        /400 /404 /408 /410 /414 /417 /418
391
        /422 /426 /430 /434 /446
392
        /454 /458 /462 /480 /484 /496 /498
393
        /504 /512 /516 /524 /532 /533 /548
394
        /554 /558 /566 /578 /586 /590 /598
395
        /600 /604 /608 /634 /643 /646 /654 /682 /690 /694
396
        /702 /704 /706 /710 /728 /748
397
        /752 /756 /760 /764 /776 /780 /784 /788
398
        /800 /807 /818 /826 /834 /840 /858 /860 /882 /886
399
        /901 /927 /928 /929 /930 /931 /932 /933 /934 /936 /938
400
        /940 /941 /943 /944 /946 /947 /948 /949
401
        /950 /951 /952 /953 /955 /956 /957 /958 /959
402
        /960 /961 /962 /963 /964 /965 /967 /968 /969
403
        /970 /971 /972 /973 /975 /976 /977 /978 /979
404
        /980 /981 /984 /985 /986 /990 /994 /997 /999
405
    ] {dup} forall >> def
406
 
407
    /lintiso4217 {
408
        iso4217 exch known not { pop /bwipp.GS1UnknownCurrency (Unknown currency code) false exit } if
409
    } bind def
410
 
411
    /lintiban {
412
        dup length 4 le { pop pop /bwipp.GS1tooShort (IBAN too short) false exit } if
413
        dup true exch {
414
            1 string dup 0 4 -1 roll put
415
            (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ)
416
            exch search not { pop pop false exit } if
417
            pop pop pop
418
        } forall
419
        not { pop /bwipp.GS1badIBANcharacter (Invalid IBAN character) false exit } if
420
        dup mark exch mark exch {} forall counttomark -4 roll counttomark array astore exch pop {
421
            48 sub dup 9 gt {7 sub dup 10 idiv exch 10 mod} if
422
        } forall counttomark array astore exch pop
423
 
424
        1 ne { pop pop /bwipp.GS1badIBANchecksum (IBAN checksum incorrect) false exit } if
425
 
426
    } bind def
427
 
428
    /lintzero {
429
        (0) ne { pop /bwipp.GS1zeroRequired (Zero is required) false exit } if
430
    } bind def
431
 
432
    /lintnonzero {
433
        false exch { 48 ne {pop true} if } forall
434
        not { pop /bwipp.GS1zeroNotPermitted (Zero not permitted) false exit } if
435
    } bind def
436
 
437
    /lintnozeroprefix {
438
        dup length 1 gt exch 0 get 48 eq and {
439
            pop /bwipp.GS1badZeroPrefix (Zero prefix is not permitted) false exit
440
        } if
441
    } bind def
442
 
443
    /lintyymmd0 {
444
        dup 2 2 getinterval cvi dup 1 lt exch 12 gt or { pop /bwipp.GS1badMonth (Invalid month) false exit } if
445
        dup 0 2 getinterval cvi dup  21  sub  % Update 20YY periodically for century calculation
446
        dup 51 ge {pop 1900 add} { -50 le {2100 add} {2000 add} ifelse} ifelse  % YYYY
447
        dup 400 mod 0 eq exch dup 4 mod 0 eq exch 100 mod 0 ne and or           % Leap year?
448
        [ 31  3 -1 roll {29} {28} ifelse  31 30 31 30 31 31 30 31 30 31 ]
449
        1 index 2 2 getinterval cvi 1 sub get
450
        exch 4 2 getinterval cvi lt { pop /bwipp.GS1badDay (Invalid day of month) false exit } if
451
    } bind def
452
 
453
    /lintyymmdd {
454
        dup length 6 ne { pop /bwipp.GS1badDateLength (Invalid length for date) false exit } if
455
        dup 4 2 getinterval cvi 1 lt { pop /bwipp.GS1badDay (Invalid day of month) false exit } if
456
        lintyymmd0
457
    } bind def
458
 
459
    /lintyymmddhh {
460
        dup length 8 ne { pop /bwipp.GS1badYYMMDDHHLength (Invalid length for date with hour) false exit } if
461
        dup 6 2 getinterval cvi 23 gt { pop pop /bwipp.GS1badHour (Invalid hour of day) false exit } if
462
 
463
    } bind def
464
 
465
    /linthhmm {
466
        dup 0 2 getinterval cvi 23 gt { pop pop /bwipp.GS1badHour (Invalid hour of day) false exit } if
467
        2 2 getinterval cvi 59 gt { pop /bwipp.GS1badMinute (Invalid minute in the hour) false exit } if
468
    } bind def
469
 
470
    /lintmmoptss {
471
        dup length dup 2 ne exch 4 ne and {
472
            pop /bwipp.GS1badTimeLength (Invalid length for optional minutes and seconds) false exit
473
        } if
474
        dup 0 2 getinterval cvi 59 gt { pop pop /bwipp.GS1badMinute (Invalid minute in the hour) false exit } if
475
        dup length 4 ge {
476
            dup 2 2 getinterval cvi 59 gt { pop pop /bwipp.GS1badSecond (Invalid second in the minute) false exit } if
477
        } if
478
        pop
479
    } bind def
480
 
481
    /lintyesno {
482
        dup (0) ne exch (1) ne and {
483
            pop /bwipp.GS1badBoolean (Neither 0 nor 1 for yes or no) false exit
484
        } if
485
    } bind def
486
 
487
    /lintwinding {
488
        dup (0) ne exch dup (1) ne exch (9) ne and and {
489
            pop /bwipp.GS1badWinding (Invalid winding direction) false exit
490
        } if
491
    } bind def
492
 
493
    /lintpieceoftotal {
494
        dup length 2 mod 0 ne { pop pop /bwipp.GS1badPieceTotalLength (Invalid piece/total length) false exit } if
495
        dup dup length 2 idiv 0 exch getinterval cvi
496
        dup 0 eq { pop pop pop /bwipp.GS1badPieceNumber (Invalid piece number) false exit } if
497
        exch dup length 2 idiv dup getinterval cvi
498
        dup 0 eq { pop pop pop /bwipp.GS1badPieceTotal (Invalid total number) false exit } if
499
        gt { pop /bwipp.GS1pieceExceedsTotal (Piece number exceeds total) false exit } if
500
    } bind def
501
 
502
    /lintpcenc {
503
        {
504
            (%) search not {pop exit} if
505
            pop pop dup length 2 lt { pop pop /bwipp.GS1badPercentEscape (Invalid % escape) false exit } if
506
            dup 0 2 getinterval true exch {
507
                1 string dup 0 4 -1 roll put
508
                (0123456789ABCDEFabcdef)
509
                exch search not { pop pop false exit } if
510
                pop pop pop
511
            } forall
512
            not { pop pop /bwipp.GS1badPercentChars (Invalid characters for percent encoding) false exit } if
513
        } loop
514
    } bind def
515
 
516
    /lintcouponcode {
517
        dup true exch {
518
            dup 48 lt exch 57 gt or { pop false exit } if
519
        } forall
520
        not { pop pop /bwipp.GS1couponNotNumeric (Coupon not numeric) false exit } if
521
 
522
        % GCP VLI and value
523
        dup length 1 lt {
524
            pop pop /bwipp.GS1couponTooShortGCPVLI (Coupon too short: Missing GCP VLI) false exit
525
        } if
526
        dup 0 1 getinterval cvi dup 6 gt {
527
            pop pop /bwipp.GS1couponBadGCPVLI (Coupon GCP length indicator must be 0-6) false exit
528
        } if
529
        6 add 1 add
530
        2 copy exch length gt {
531
            pop pop pop /bwipp.GS1couponTooShortGCP (Coupon too short: GCP truncated) false exit
532
        } if
533
        dup 2 index length exch sub getinterval
534
 
535
        % Offer Code
536
        dup length 6 lt {
537
            pop pop /bwipp.GS1couponTooShortOfferCode (Coupon too short: Offer Code truncated) false exit
538
        } if
539
        dup length 6 sub 6 exch getinterval
540
 
541
        % Save Value VLI and value
542
        dup length 1 lt {
543
            pop pop /bwipp.GS1couponTooShortSaveValueVLI (Coupon too short: Missing Save Value VLI) false exit
544
        } if
545
        dup 0 1 getinterval cvi dup dup 1 lt exch 5 gt or {
546
            pop pop /bwipp.GS1couponBadSaveValueVLI (Coupon Save Value length indicator must be 1-5) false exit
547
        } if
548
        1 add
549
        2 copy exch length gt {
550
            pop pop pop /bwipp.GS1couponTooShortSaveValue (Coupon too short: Save Value truncated) false exit
551
        } if
552
        dup 2 index length exch sub getinterval
553
 
554
        % 1st Purchase Requirement VLI and value
555
        dup length 1 lt {
556
            pop pop /bwipp.GS1couponTooShort1stPurchaseRequirementVLI (Coupon too short: Missing 1st Purchase Requirement VLI) false exit
557
        } if
558
        dup 0 1 getinterval cvi dup dup 1 lt exch 5 gt or {
559
            pop pop /bwipp.GS1couponBad1stPurchaseRequirementVLI (Coupon 1st Purchase Requirement length indicator must be 1-5) false exit
560
        } if
561
        1 add
562
        2 copy exch length gt {
563
            pop pop pop /bwipp.GS1couponTooShort1stPurchaseRequirement (Coupon too short: 1st Purchase Requirement truncated) false exit
564
        } if
565
        dup 2 index length exch sub getinterval
566
 
567
        % 1st Purchase Requirement Code
568
        dup length 1 lt {
569
            pop pop /bwipp.GS1couponTooShort1stPurchaseRequirementCode (Coupon too short: Missing 1st Purchase Requirement Code) false exit
570
        } if
571
        dup 0 1 getinterval cvi dup 4 gt exch 9 ne and {
572
            pop pop /bwipp.GS1couponBad1stPurchaseRequirementCode (Coupon 1st Purchase Requirement Code must be 0-4 or 9) false exit
573
        } if
574
        dup length 1 sub 1 exch getinterval
575
 
576
        % 1st Purchase Family Code
577
        dup length 3 lt {
578
            pop pop /bwipp.GS1couponTooShort1stPurchaseFamilyCode (Coupon too short: 1st Purchase Family Code truncated) false exit
579
        } if
580
        dup length 3 sub 3 exch getinterval
581
 
582
        % Optional field 1
583
        dup length 1 ge { dup 0 1 getinterval cvi 1 eq {
584
            1 dup 2 index length exch sub getinterval
585
 
586
            % Additional Purchase Rules Code
587
            dup length 1 lt {
588
                pop pop /bwipp.GS1couponTooShortAdditionalPurchaseRulesCode (Coupon too short: Missing Additional Purchase Rules Code) false exit
589
            } if
590
            dup 0 1 getinterval cvi 3 gt {
591
                pop pop /bwipp.GS1couponBadAdditionalPurchaseRulesCode (Coupon Additional Purchase Rules Code must be 0-3) false exit
592
            } if
593
            dup length 1 sub 1 exch getinterval
594
 
595
            % 2nd Purchase RequirementVLI and value
596
            dup length 1 lt {
597
                pop pop /bwipp.GS1couponTooShort2ndPurchaseRequirementVLI (Coupon too short: Missing 2nd Purchase Requirement VLI) false exit
598
            } if
599
            dup 0 1 getinterval cvi dup dup 1 lt exch 5 gt or {
600
                pop pop /bwipp.GS1couponBad2ndPurchaseRequirementVLI (Coupon 2nd Purchase Requirement length indicator must be 1-5) false exit
601
            } if
602
            1 add
603
            2 copy exch length gt {
604
                pop pop pop /bwipp.GS1couponTooShort2ndPurchaseRequirement (Coupon too short: 2nd Purchase Requirement truncated) false exit
605
            } if
606
            dup 2 index length exch sub getinterval
607
 
608
            % 2nd Purchase Requirement Code
609
            dup length 1 lt {
610
                pop pop /bwipp.GS1couponTooShort2ndPurchaseRequirementCode (Coupon too short: Missing 2nd Purchase Requirement Code) false exit
611
            } if
612
            dup 0 1 getinterval cvi dup 4 gt exch 9 ne and {
613
                pop pop /bwipp.GS1couponBad2ndPurchaseRequirementCode (Coupon 2nd Purchase Requirement Code must be 0-4 or 9) false exit
614
            } if
615
            dup length 1 sub 1 exch getinterval
616
 
617
            % 2nd Purchase Family Code
618
            dup length 3 lt {
619
                pop pop /bwipp.GS1couponTooShort2ndPurchaseFamilyCode (Coupon too short: 2nd Purchase Family Code truncated) false exit
620
            } if
621
            dup length 3 sub 3 exch getinterval
622
 
623
            % 2nd Purchase GCP VLI and value
624
            dup length 1 lt {
625
                pop pop /bwipp.GS1couponTooShort2ndPurchaseGCPVLI (Coupon too short: Missing 2nd Purchase GCP VLI) false exit
626
            } if
627
            dup 0 1 getinterval cvi dup dup 6 gt exch 9 ne and {
628
                pop pop /bwipp.GS1couponBad2ndPurchaseGCPVLI (Coupon 2nd Purchase GCP length indicator must be 0-6 or 9) false exit
629
            } if
630
            dup 9 ne {6 add} {pop 0} ifelse 1 add
631
            2 copy exch length gt {
632
                pop pop pop /bwipp.GS1couponTooShort2ndPurchaseGCP (Coupon too short: 2nd Purchase GCP truncated) false exit
633
            } if
634
            dup 2 index length exch sub getinterval
635
 
636
        } if } if
637
 
638
        % Optional field 2
639
        dup length 1 ge { dup 0 1 getinterval cvi 2 eq {
640
            1 dup 2 index length exch sub getinterval
641
 
642
            % 3rd Purchase RequirementVLI and value
643
            dup length 1 lt {
644
                pop pop /bwipp.GS1couponTooShort3rdPurchaseRequirementVLI (Coupon too short: Missing 3rd Purchase Requirement VLI) false exit
645
            } if
646
            dup 0 1 getinterval cvi dup dup 1 lt exch 5 gt or {
647
                pop pop /bwipp.GS1couponBad3rdPurchaseRequirementVLI (Coupon 3rd Purchase Requirement length indicator must be 1-5) false exit
648
            } if
649
            1 add
650
            2 copy exch length gt {
651
                pop pop pop /bwipp.GS1couponTooShort3rdPurchaseRequirement (Coupon too short: 3rd Purchase Requirement truncated) false exit
652
            } if
653
            dup 2 index length exch sub getinterval
654
 
655
            % 3rd Purchase Requirement Code
656
            dup length 1 lt {
657
                pop pop /bwipp.GS1couponTooShort3rdPurchaseRequirementCode (Coupon too short: Missing 3rd Purchase Requirement Code) false exit
658
            } if
659
            dup 0 1 getinterval cvi dup 4 gt exch 9 ne and {
660
                pop pop /bwipp.GS1couponBad3rdPurchaseRequirementCode (Coupon 3rd Purchase Requirement Code must be 0-4 or 9) false exit
661
            } if
662
            dup length 1 sub 1 exch getinterval
663
 
664
            % 3rd Purchase Family Code
665
            dup length 3 lt {
666
                pop pop /bwipp.GS1couponTooShort3rdPurchaseFamilyCode (Coupon too short: 3rd Purchase Family Code truncated) false exit
667
            } if
668
            dup length 3 sub 3 exch getinterval
669
 
670
            % 3rd Purchase GCP VLI and value
671
            dup length 1 lt {
672
                pop pop /bwipp.GS1couponTooShort3rdPurchaseGCPVLI (Coupon too short: Missing 3rd Purchase GCP VLI) false exit
673
            } if
674
            dup 0 1 getinterval cvi dup dup 6 gt exch 9 ne and {
675
                pop pop /bwipp.GS1couponBad3rdPurchaseGCPVLI (Coupon 3rd Purchase GCP length indicator must be 0-6 or 9) false exit
676
            } if
677
            dup 9 ne {6 add} {pop 0} ifelse 1 add
678
            2 copy exch length gt {
679
                pop pop pop /bwipp.GS1couponTooShort3rdPurchaseGCP (Coupon too short: 3rd Purchase GCP truncated) false exit
680
            } if
681
            dup 2 index length exch sub getinterval
682
 
683
        } if } if
684
 
685
        % Optional field 3
686
        /couponexpire -1 def
687
        dup length 1 ge { dup 0 1 getinterval cvi 3 eq {
688
            1 dup 2 index length exch sub getinterval
689
 
690
            % Expiration date
691
            dup length 6 lt {
692
                pop pop /bwipp.GS1couponTooShortExpirationDate (Coupon too short: Expiration date) false exit
693
            } if
694
            dup 2 2 getinterval cvi dup 1 lt exch 12 gt or { pop pop /bwipp.GS1couponExpirationDateBadMonth (Invalid month in expiration date) false exit } if
695
            dup 0 2 getinterval cvi dup 21 sub  % Update 20YY periodically for century calculation
696
            dup 51 ge {pop 1900 add} { -50 le {2100 add} {2000 add} ifelse} ifelse  % YYYY
697
            dup 400 mod 0 eq exch dup 4 mod 0 eq exch 100 mod 0 ne and or           % Leap year?
698
            [ 31  3 -1 roll {29} {28} ifelse  31 30 31 30 31 31 30 31 30 31 ]
699
            1 index 2 2 getinterval cvi 1 sub get
700
            1 index 4 2 getinterval cvi dup 3 1 roll lt
701
            exch 1 lt or { pop pop /bwipp.GS1couponExpirationDateBadDay (Invalid day of month in expiration date) false exit } if
702
            dup 0 6 getinterval cvi /couponexpire exch def
703
            dup length 6 sub 6 exch getinterval
704
 
705
        } if } if
706
 
707
        % Optional field 4
708
        dup length 1 ge { dup 0 1 getinterval cvi 4 eq {
709
            1 dup 2 index length exch sub getinterval
710
 
711
            % Start date
712
            dup length 6 lt {
713
                pop pop /bwipp.GS1couponTooShortStartDate (Coupon too short: Start date) false exit
714
            } if
715
            dup 2 2 getinterval cvi dup 1 lt exch 12 gt or { pop pop /bwipp.GS1couponStartDateBadMonth (Invalid month in start date) false exit } if
716
            dup 0 2 getinterval cvi dup 21 sub  % Update 20YY periodically for century calculation
717
            dup 51 ge {pop 1900 add} { -50 le {2100 add} {2000 add} ifelse} ifelse  % YYYY
718
            dup 400 mod 0 eq exch dup 4 mod 0 eq exch 100 mod 0 ne and or           % Leap year?
719
            [ 31  3 -1 roll {29} {28} ifelse  31 30 31 30 31 31 30 31 30 31 ]
720
            1 index 2 2 getinterval cvi 1 sub get
721
            1 index 4 2 getinterval cvi dup 3 1 roll lt
722
            exch 1 lt or { pop pop /bwipp.GS1couponStartDateBadDay (Invalid day of month in start date) false exit } if
723
            dup 0 6 getinterval cvi /couponstart exch def
724
            couponexpire -1 ne couponexpire couponstart lt and {
725
                pop pop /bwipp.GS1couponExpireDateBeforeStartDate (Coupon expires before it starts) false exit
726
            } if
727
            dup length 6 sub 6 exch getinterval
728
 
729
        } if } if
730
 
731
        % Optional field 5
732
        dup length 1 ge { dup 0 1 getinterval cvi 5 eq {
733
            1 dup 2 index length exch sub getinterval
734
 
735
            % Serial Number VLI and value
736
            dup length 1 lt {
737
                pop pop /bwipp.GS1couponTooShortSerialNumberVLI (Coupon too short: Missing Serial Number VLI) false exit
738
            } if
739
            dup 0 1 getinterval cvi 6 add 1 add
740
            2 copy exch length gt {
741
                pop pop pop /bwipp.GS1couponTooShortSerialNumber (Coupon too short: Serial Number truncated) false exit
742
            } if
743
            dup 2 index length exch sub getinterval
744
 
745
        } if } if
746
 
747
        % Optional field 6
748
        dup length 1 ge { dup 0 1 getinterval cvi 6 eq {
749
            1 dup 2 index length exch sub getinterval
750
 
751
            % Retailer GCP/GLN VLI and value
752
            dup length 1 lt {
753
                pop pop /bwipp.GS1couponTooShortRetailerGCPGLNVLI (Coupon too short: Missing Retailer GCP/GLN VLI) false exit
754
            } if
755
            dup 0 1 getinterval cvi dup dup 1 lt exch 7 gt or {
756
                pop pop /bwipp.GS1couponBadRetailerGCPGLNVLI (Coupon Retailer GCP/GLN length indicator must be 1-7) false exit
757
            } if
758
            6 add 1 add
759
            2 copy exch length gt {
760
                pop pop pop /bwipp.GS1couponTooShortRetailerGCPGLN (Coupon too short: Retailer GCP/GLN truncated) false exit
761
            } if
762
            dup 2 index length exch sub getinterval
763
 
764
        } if } if
765
 
766
        % Optional field 9
767
        dup length 1 ge { dup 0 1 getinterval cvi 9 eq {
768
            1 dup 2 index length exch sub getinterval
769
 
770
            % Save Value Code
771
            dup length 1 lt {
772
                pop pop /bwipp.GS1couponTooShortSaveValueCode (Coupon too short: Missing Save Value Code) false exit
773
            } if
774
            dup 0 1 getinterval cvi dup 6 gt exch dup 3 eq exch 4 eq or or {
775
                pop pop /bwipp.GS1couponBadSaveValueCode (Coupon Save Value Code must be 0,1,2,5 or 6) false exit
776
            } if
777
            dup length 1 sub 1 exch getinterval
778
 
779
            % Save Value Applies to Item
780
            dup length 1 lt {
781
                pop pop /bwipp.GS1couponTooShortSaveValueAppliesToItem (Coupon too short: Missing Save Value Applies to Item) false exit
782
            } if
783
            dup 0 1 getinterval cvi 2 gt {
784
                pop pop /bwipp.GS1couponBadSaveValueAppliesToItem (Coupon Save Value Applies to Item must be 0-2) false exit
785
            } if
786
            dup length 1 sub 1 exch getinterval
787
 
788
            % Store Coupon Flag
789
            dup length 1 lt {
790
                pop pop /bwipp.GS1couponTooShortStoreCouponFlag (Coupon too short: Missing Store Coupon Flag) false exit
791
            } if
792
            dup length 1 sub 1 exch getinterval
793
 
794
            % Don't Multiply Flag
795
            dup length 1 lt {
796
                pop pop /bwipp.GS1couponTooShortDontMultiplyFlag (Coupon too short: Missing Don't Multiply Flag) false exit
797
            } if
798
            dup 0 1 getinterval cvi 1 gt {
799
                pop pop /bwipp.GS1couponBadDontMultiplyFlag (Don't Multiply Flag must be 0 or 1) false exit
800
            } if
801
            dup length 1 sub 1 exch getinterval
802
 
803
        } if } if
804
 
805
        dup length 0 ne {
806
            pop pop /bwipp.GS1couponUnrecognisedOptionalField (Coupon fields must be 1,2,3,4,5,6 or 9, increasing order) false exit
807
        } if
808
        pop
809
    } bind def
810
 
811
    /lintcouponposoffer {
812
        dup true exch {
813
            dup 48 lt exch 57 gt or { pop false exit } if
814
        } forall
815
        not { pop pop /bwipp.GS1couponNotNumeric (Coupon not numeric) false exit } if
816
        % Format Code
817
        dup length 1 lt {
818
            pop pop /bwipp.GS1couponTooShortFormatCode (Coupon too short: Missing Format Code) false exit
819
        } if
820
        dup 0 1 getinterval dup (0) ne exch (1) ne and {
821
            pop pop /bwipp.GS1couponBadFormatCode (Coupon format must be 0 or 1) false exit
822
        } if
823
        dup length 1 sub 1 exch getinterval
824
        % Funder ID VLI and Funder ID
825
        dup length 1 lt {
826
            pop pop /bwipp.GS1couponTooShortFunderVLI (Coupon too short: Missing Funder VLI) false exit
827
        } if
828
        dup 0 1 getinterval cvi dup 6 gt {
829
            pop pop pop /bwipp.GS1couponBadFunderVLI (Coupon Funder length indicator must be 0-6) false exit
830
        } if
831
        6 add 1 add
832
        2 copy exch length gt {
833
            pop pop pop /bwipp.GS1couponTooShortFunder (Coupon too short: Truncated Funder ID) false exit
834
        } if
835
        dup 2 index length exch sub getinterval
836
        % Offer Code
837
        dup length 6 lt {
838
            pop pop /bwipp.GS1couponTooShortOfferCode (Coupon too short: Truncated Offer Code) false exit
839
        } if
840
        dup length 6 sub 6 exch getinterval
841
        % Serial Number VLI and Serial Number
842
        dup length 1 lt {
843
            pop pop /bwipp.GS1couponTooShortSnVLI (Coupon too short: Missing SN VLI) false exit
844
        } if
845
        dup 0 1 getinterval cvi
846
        6 add 1 add
847
        2 copy exch length gt {
848
            pop pop pop /bwipp.GS1couponTooShortSn (Coupon too short: Truncated SN) false exit
849
        } if
850
        dup 2 index length exch sub getinterval
851
        dup length 0 ne {
852
            pop pop /bwipp.GS1couponTooLong (Coupon too long) false exit
853
        } if
854
        pop
855
    } bind def
856
 
857
    /gs1syntax <<
858
 
859
        [
860
        << /cset /N  /min 18  /max 18  /check [ /lintcsum /lintkey ] >>
861
        ]
862
        (00) exch dup
863
        pop
864
 
865
        [
866
        << /cset /N  /min 14  /max 14  /check [ /lintcsum /lintkey ] >>
867
        ]
868
        (01) exch dup
869
        (02) exch dup
870
        pop
871
 
872
        [
873
        << /cset /X  /min  1  /max 20  /check [] >>
874
        ]
875
        (10) exch dup
876
        pop
877
 
878
        [
879
        << /cset /N  /min  6  /max  6  /check [ /lintyymmd0 ] >>
880
        ]
881
        (11) exch dup
882
        (12) exch dup
883
        (13) exch dup
884
        (15) exch dup
885
        (16) exch dup
886
        (17) exch dup
887
        pop
888
 
889
        [
890
        << /cset /N  /min  2  /max  2  /check [] >>
891
        ]
892
        (20) exch dup
893
        pop
894
 
895
        [
896
        << /cset /X  /min  1  /max 20  /check [] >>
897
        ]
898
        (21) exch dup
899
        (22) exch dup
900
        pop
901
 
902
        [
903
        << /cset /X  /min  1  /max 28  /check [] >>
904
        ]
905
        (235) exch dup
906
        pop
907
 
908
        [
909
        << /cset /X  /min  1  /max 30  /check [] >>
910
        ]
911
        (240) exch dup
912
        (241) exch dup
913
        pop
914
 
915
        [
916
        << /cset /N  /min  1  /max  6  /check [] >>
917
        ]
918
        (242) exch dup
919
        pop
920
 
921
        [
922
        << /cset /X  /min  1  /max 20  /check [] >>
923
        ]
924
        (243) exch dup
925
        pop
926
 
927
        [
928
        << /cset /X  /min  1  /max 30  /check [] >>
929
        ]
930
        (250) exch dup
931
        (251) exch dup
932
        pop
933
 
934
        [
935
        << /cset /N  /min 13  /max 13  /check [ /lintcsum /lintkey ] >>
936
        << /cset /X  /min  0  /max 17  /check [] >>
937
        ]
938
        (253) exch dup
939
        pop
940
 
941
        [
942
        << /cset /X  /min  1  /max 20  /check [] >>
943
        ]
944
        (254) exch dup
945
        pop
946
 
947
        [
948
        << /cset /N  /min 13  /max 13  /check [ /lintcsum /lintkey ] >>
949
        << /cset /N  /min  0  /max 12  /check [] >>
950
        ]
951
        (255) exch dup
952
        pop
953
 
954
        [
955
        << /cset /N  /min  1  /max  8  /check [] >>
956
        ]
957
        (30) exch dup
958
        pop
959
 
960
        [
961
        << /cset /N  /min  6  /max  6  /check [] >>
962
        ]
963
        (3100) exch dup
964
        (3101) exch dup
965
        (3102) exch dup
966
        (3103) exch dup
967
        (3104) exch dup
968
        (3105) exch dup
969
        (3110) exch dup
970
        (3111) exch dup
971
        (3112) exch dup
972
        (3113) exch dup
973
        (3114) exch dup
974
        (3115) exch dup
975
        (3120) exch dup
976
        (3121) exch dup
977
        (3122) exch dup
978
        (3123) exch dup
979
        (3124) exch dup
980
        (3125) exch dup
981
        (3130) exch dup
982
        (3131) exch dup
983
        (3132) exch dup
984
        (3133) exch dup
985
        (3134) exch dup
986
        (3135) exch dup
987
        (3140) exch dup
988
        (3141) exch dup
989
        (3142) exch dup
990
        (3143) exch dup
991
        (3144) exch dup
992
        (3145) exch dup
993
        (3150) exch dup
994
        (3151) exch dup
995
        (3152) exch dup
996
        (3153) exch dup
997
        (3154) exch dup
998
        (3155) exch dup
999
        (3160) exch dup
1000
        (3161) exch dup
1001
        (3162) exch dup
1002
        (3163) exch dup
1003
        (3164) exch dup
1004
        (3165) exch dup
1005
        (3200) exch dup
1006
        (3201) exch dup
1007
        (3202) exch dup
1008
        (3203) exch dup
1009
        (3204) exch dup
1010
        (3205) exch dup
1011
        (3210) exch dup
1012
        (3211) exch dup
1013
        (3212) exch dup
1014
        (3213) exch dup
1015
        (3214) exch dup
1016
        (3215) exch dup
1017
        (3220) exch dup
1018
        (3221) exch dup
1019
        (3222) exch dup
1020
        (3223) exch dup
1021
        (3224) exch dup
1022
        (3225) exch dup
1023
        (3230) exch dup
1024
        (3231) exch dup
1025
        (3232) exch dup
1026
        (3233) exch dup
1027
        (3234) exch dup
1028
        (3235) exch dup
1029
        (3240) exch dup
1030
        (3241) exch dup
1031
        (3242) exch dup
1032
        (3243) exch dup
1033
        (3244) exch dup
1034
        (3245) exch dup
1035
        (3250) exch dup
1036
        (3251) exch dup
1037
        (3252) exch dup
1038
        (3253) exch dup
1039
        (3254) exch dup
1040
        (3255) exch dup
1041
        (3260) exch dup
1042
        (3261) exch dup
1043
        (3262) exch dup
1044
        (3263) exch dup
1045
        (3264) exch dup
1046
        (3265) exch dup
1047
        (3270) exch dup
1048
        (3271) exch dup
1049
        (3272) exch dup
1050
        (3273) exch dup
1051
        (3274) exch dup
1052
        (3275) exch dup
1053
        (3280) exch dup
1054
        (3281) exch dup
1055
        (3282) exch dup
1056
        (3283) exch dup
1057
        (3284) exch dup
1058
        (3285) exch dup
1059
        (3290) exch dup
1060
        (3291) exch dup
1061
        (3292) exch dup
1062
        (3293) exch dup
1063
        (3294) exch dup
1064
        (3295) exch dup
1065
        (3300) exch dup
1066
        (3301) exch dup
1067
        (3302) exch dup
1068
        (3303) exch dup
1069
        (3304) exch dup
1070
        (3305) exch dup
1071
        (3310) exch dup
1072
        (3311) exch dup
1073
        (3312) exch dup
1074
        (3313) exch dup
1075
        (3314) exch dup
1076
        (3315) exch dup
1077
        (3320) exch dup
1078
        (3321) exch dup
1079
        (3322) exch dup
1080
        (3323) exch dup
1081
        (3324) exch dup
1082
        (3325) exch dup
1083
        (3330) exch dup
1084
        (3331) exch dup
1085
        (3332) exch dup
1086
        (3333) exch dup
1087
        (3334) exch dup
1088
        (3335) exch dup
1089
        (3340) exch dup
1090
        (3341) exch dup
1091
        (3342) exch dup
1092
        (3343) exch dup
1093
        (3344) exch dup
1094
        (3345) exch dup
1095
        (3350) exch dup
1096
        (3351) exch dup
1097
        (3352) exch dup
1098
        (3353) exch dup
1099
        (3354) exch dup
1100
        (3355) exch dup
1101
        (3360) exch dup
1102
        (3361) exch dup
1103
        (3362) exch dup
1104
        (3363) exch dup
1105
        (3364) exch dup
1106
        (3365) exch dup
1107
        (3370) exch dup
1108
        (3371) exch dup
1109
        (3372) exch dup
1110
        (3373) exch dup
1111
        (3374) exch dup
1112
        (3375) exch dup
1113
        (3400) exch dup
1114
        (3401) exch dup
1115
        (3402) exch dup
1116
        (3403) exch dup
1117
        (3404) exch dup
1118
        (3405) exch dup
1119
        (3410) exch dup
1120
        (3411) exch dup
1121
        (3412) exch dup
1122
        (3413) exch dup
1123
        (3414) exch dup
1124
        (3415) exch dup
1125
        (3420) exch dup
1126
        (3421) exch dup
1127
        (3422) exch dup
1128
        (3423) exch dup
1129
        (3424) exch dup
1130
        (3425) exch dup
1131
        (3430) exch dup
1132
        (3431) exch dup
1133
        (3432) exch dup
1134
        (3433) exch dup
1135
        (3434) exch dup
1136
        (3435) exch dup
1137
        (3440) exch dup
1138
        (3441) exch dup
1139
        (3442) exch dup
1140
        (3443) exch dup
1141
        (3444) exch dup
1142
        (3445) exch dup
1143
        (3450) exch dup
1144
        (3451) exch dup
1145
        (3452) exch dup
1146
        (3453) exch dup
1147
        (3454) exch dup
1148
        (3455) exch dup
1149
        (3460) exch dup
1150
        (3461) exch dup
1151
        (3462) exch dup
1152
        (3463) exch dup
1153
        (3464) exch dup
1154
        (3465) exch dup
1155
        (3470) exch dup
1156
        (3471) exch dup
1157
        (3472) exch dup
1158
        (3473) exch dup
1159
        (3474) exch dup
1160
        (3475) exch dup
1161
        (3480) exch dup
1162
        (3481) exch dup
1163
        (3482) exch dup
1164
        (3483) exch dup
1165
        (3484) exch dup
1166
        (3485) exch dup
1167
        (3490) exch dup
1168
        (3491) exch dup
1169
        (3492) exch dup
1170
        (3493) exch dup
1171
        (3494) exch dup
1172
        (3495) exch dup
1173
        (3500) exch dup
1174
        (3501) exch dup
1175
        (3502) exch dup
1176
        (3503) exch dup
1177
        (3504) exch dup
1178
        (3505) exch dup
1179
        (3510) exch dup
1180
        (3511) exch dup
1181
        (3512) exch dup
1182
        (3513) exch dup
1183
        (3514) exch dup
1184
        (3515) exch dup
1185
        (3520) exch dup
1186
        (3521) exch dup
1187
        (3522) exch dup
1188
        (3523) exch dup
1189
        (3524) exch dup
1190
        (3525) exch dup
1191
        (3530) exch dup
1192
        (3531) exch dup
1193
        (3532) exch dup
1194
        (3533) exch dup
1195
        (3534) exch dup
1196
        (3535) exch dup
1197
        (3540) exch dup
1198
        (3541) exch dup
1199
        (3542) exch dup
1200
        (3543) exch dup
1201
        (3544) exch dup
1202
        (3545) exch dup
1203
        (3550) exch dup
1204
        (3551) exch dup
1205
        (3552) exch dup
1206
        (3553) exch dup
1207
        (3554) exch dup
1208
        (3555) exch dup
1209
        (3560) exch dup
1210
        (3561) exch dup
1211
        (3562) exch dup
1212
        (3563) exch dup
1213
        (3564) exch dup
1214
        (3565) exch dup
1215
        (3570) exch dup
1216
        (3571) exch dup
1217
        (3572) exch dup
1218
        (3573) exch dup
1219
        (3574) exch dup
1220
        (3575) exch dup
1221
        (3600) exch dup
1222
        (3601) exch dup
1223
        (3602) exch dup
1224
        (3603) exch dup
1225
        (3604) exch dup
1226
        (3605) exch dup
1227
        (3610) exch dup
1228
        (3611) exch dup
1229
        (3612) exch dup
1230
        (3613) exch dup
1231
        (3614) exch dup
1232
        (3615) exch dup
1233
        (3620) exch dup
1234
        (3621) exch dup
1235
        (3622) exch dup
1236
        (3623) exch dup
1237
        (3624) exch dup
1238
        (3625) exch dup
1239
        (3630) exch dup
1240
        (3631) exch dup
1241
        (3632) exch dup
1242
        (3633) exch dup
1243
        (3634) exch dup
1244
        (3635) exch dup
1245
        (3640) exch dup
1246
        (3641) exch dup
1247
        (3642) exch dup
1248
        (3643) exch dup
1249
        (3644) exch dup
1250
        (3645) exch dup
1251
        (3650) exch dup
1252
        (3651) exch dup
1253
        (3652) exch dup
1254
        (3653) exch dup
1255
        (3654) exch dup
1256
        (3655) exch dup
1257
        (3660) exch dup
1258
        (3661) exch dup
1259
        (3662) exch dup
1260
        (3663) exch dup
1261
        (3664) exch dup
1262
        (3665) exch dup
1263
        (3670) exch dup
1264
        (3671) exch dup
1265
        (3672) exch dup
1266
        (3673) exch dup
1267
        (3674) exch dup
1268
        (3675) exch dup
1269
        (3680) exch dup
1270
        (3681) exch dup
1271
        (3682) exch dup
1272
        (3683) exch dup
1273
        (3684) exch dup
1274
        (3685) exch dup
1275
        (3690) exch dup
1276
        (3691) exch dup
1277
        (3692) exch dup
1278
        (3693) exch dup
1279
        (3694) exch dup
1280
        (3695) exch dup
1281
        pop
1282
 
1283
        [
1284
        << /cset /N  /min  1  /max  8  /check [] >>
1285
        ]
1286
        (37) exch dup
1287
        pop
1288
 
1289
        [
1290
        << /cset /N  /min  1  /max 15  /check [] >>
1291
        ]
1292
        (3900) exch dup
1293
        (3901) exch dup
1294
        (3902) exch dup
1295
        (3903) exch dup
1296
        (3904) exch dup
1297
        (3905) exch dup
1298
        (3906) exch dup
1299
        (3907) exch dup
1300
        (3908) exch dup
1301
        (3909) exch dup
1302
        pop
1303
 
1304
        [
1305
        << /cset /N  /min  3  /max  3  /check [ /lintiso4217 ] >>
1306
        << /cset /N  /min  1  /max 15  /check [] >>
1307
        ]
1308
        (3910) exch dup
1309
        (3911) exch dup
1310
        (3912) exch dup
1311
        (3913) exch dup
1312
        (3914) exch dup
1313
        (3915) exch dup
1314
        (3916) exch dup
1315
        (3917) exch dup
1316
        (3918) exch dup
1317
        (3919) exch dup
1318
        pop
1319
 
1320
        [
1321
        << /cset /N  /min  1  /max 15  /check [] >>
1322
        ]
1323
        (3920) exch dup
1324
        (3921) exch dup
1325
        (3922) exch dup
1326
        (3923) exch dup
1327
        (3924) exch dup
1328
        (3925) exch dup
1329
        (3926) exch dup
1330
        (3927) exch dup
1331
        (3928) exch dup
1332
        (3929) exch dup
1333
        pop
1334
 
1335
        [
1336
        << /cset /N  /min  3  /max  3  /check [ /lintiso4217 ] >>
1337
        << /cset /N  /min  1  /max 15  /check [] >>
1338
        ]
1339
        (3930) exch dup
1340
        (3931) exch dup
1341
        (3932) exch dup
1342
        (3933) exch dup
1343
        (3934) exch dup
1344
        (3935) exch dup
1345
        (3936) exch dup
1346
        (3937) exch dup
1347
        (3938) exch dup
1348
        (3939) exch dup
1349
        pop
1350
 
1351
        [
1352
        << /cset /N  /min  4  /max  4  /check [] >>
1353
        ]
1354
        (3940) exch dup
1355
        (3941) exch dup
1356
        (3942) exch dup
1357
        (3943) exch dup
1358
        pop
1359
 
1360
        [
1361
        << /cset /N  /min  6  /max  6  /check [] >>
1362
        ]
1363
        (3950) exch dup
1364
        (3951) exch dup
1365
        (3952) exch dup
1366
        (3953) exch dup
1367
        (3954) exch dup
1368
        (3955) exch dup
1369
        pop
1370
 
1371
        [
1372
        << /cset /X  /min  1  /max 30  /check [] >>
1373
        ]
1374
        (400) exch dup
1375
        pop
1376
 
1377
        [
1378
        << /cset /X  /min  1  /max 30  /check [ /lintkey ] >>
1379
        ]
1380
        (401) exch dup
1381
        pop
1382
 
1383
        [
1384
        << /cset /N  /min 17  /max 17  /check [ /lintcsum /lintkey ] >>
1385
        ]
1386
        (402) exch dup
1387
        pop
1388
 
1389
        [
1390
        << /cset /X  /min  1  /max 30  /check [] >>
1391
        ]
1392
        (403) exch dup
1393
        pop
1394
 
1395
        [
1396
        << /cset /N  /min 13  /max 13  /check [ /lintcsum /lintkey ] >>
1397
        ]
1398
        (410) exch dup
1399
        (411) exch dup
1400
        (412) exch dup
1401
        (413) exch dup
1402
        (414) exch dup
1403
        (415) exch dup
1404
        (416) exch dup
1405
        (417) exch dup
1406
        pop
1407
 
1408
        [
1409
        << /cset /X  /min  1  /max 20  /check [] >>
1410
        ]
1411
        (420) exch dup
1412
        pop
1413
 
1414
        [
1415
        << /cset /N  /min  3  /max  3  /check [ /lintiso3166 ] >>
1416
        << /cset /X  /min  1  /max  9  /check [] >>
1417
        ]
1418
        (421) exch dup
1419
        pop
1420
 
1421
        [
1422
        << /cset /N  /min  3  /max  3  /check [ /lintiso3166 ] >>
1423
        ]
1424
        (422) exch dup
1425
        pop
1426
 
1427
        [
1428
        << /cset /N  /min  3  /max 15  /check [ /lintiso3166list ] >>
1429
        ]
1430
        (423) exch dup
1431
        pop
1432
 
1433
        [
1434
        << /cset /N  /min  3  /max  3  /check [ /lintiso3166 ] >>
1435
        ]
1436
        (424) exch dup
1437
        pop
1438
 
1439
        [
1440
        << /cset /N  /min  3  /max 15  /check [ /lintiso3166list ] >>
1441
        ]
1442
        (425) exch dup
1443
        pop
1444
 
1445
        [
1446
        << /cset /N  /min  3  /max  3  /check [ /lintiso3166 ] >>
1447
        ]
1448
        (426) exch dup
1449
        pop
1450
 
1451
        [
1452
        << /cset /X  /min  1  /max  3  /check [] >>
1453
        ]
1454
        (427) exch dup
1455
        pop
1456
 
1457
        [
1458
        << /cset /X  /min  1  /max 35  /check [ /lintpcenc ] >>
1459
        ]
1460
        (4300) exch dup
1461
        (4301) exch dup
1462
        pop
1463
 
1464
        [
1465
        << /cset /X  /min  1  /max 70  /check [ /lintpcenc ] >>
1466
        ]
1467
        (4302) exch dup
1468
        (4303) exch dup
1469
        (4304) exch dup
1470
        (4305) exch dup
1471
        (4306) exch dup
1472
        pop
1473
 
1474
        [
1475
        << /cset /X  /min  2  /max  2  /check [ /lintiso3166alpha2 ] >>
1476
        ]
1477
        (4307) exch dup
1478
        pop
1479
 
1480
        [
1481
        << /cset /X  /min  1  /max 30  /check [] >>
1482
        ]
1483
        (4308) exch dup
1484
        pop
1485
 
1486
        [
1487
        << /cset /X  /min  1  /max 35  /check [ /lintpcenc ] >>
1488
        ]
1489
        (4310) exch dup
1490
        (4311) exch dup
1491
        pop
1492
 
1493
        [
1494
        << /cset /X  /min  1  /max 70  /check [ /lintpcenc ] >>
1495
        ]
1496
        (4312) exch dup
1497
        (4313) exch dup
1498
        (4314) exch dup
1499
        (4315) exch dup
1500
        (4316) exch dup
1501
        pop
1502
 
1503
        [
1504
        << /cset /X  /min  2  /max  2  /check [ /lintiso3166alpha2 ] >>
1505
        ]
1506
        (4317) exch dup
1507
        pop
1508
 
1509
        [
1510
        << /cset /X  /min  1  /max 20  /check [] >>
1511
        ]
1512
        (4318) exch dup
1513
        pop
1514
 
1515
        [
1516
        << /cset /X  /min  1  /max 30  /check [] >>
1517
        ]
1518
        (4319) exch dup
1519
        pop
1520
 
1521
        [
1522
        << /cset /X  /min  1  /max 35  /check [ /lintpcenc ] >>
1523
        ]
1524
        (4320) exch dup
1525
        pop
1526
 
1527
        [
1528
        << /cset /N  /min  1  /max  1  /check [ /lintyesno ] >>
1529
        ]
1530
        (4321) exch dup
1531
        (4322) exch dup
1532
        (4323) exch dup
1533
        pop
1534
 
1535
        [
1536
        << /cset /N  /min  6  /max  6  /check [ /lintyymmd0 ] >>
1537
        << /cset /N  /min  4  /max  4  /check [ /linthhmm ] >>
1538
        ]
1539
        (4324) exch dup
1540
        (4325) exch dup
1541
        pop
1542
 
1543
        [
1544
        << /cset /N  /min  6  /max  6  /check [ /lintyymmdd ] >>
1545
        ]
1546
        (4326) exch dup
1547
        pop
1548
 
1549
        [
1550
        << /cset /N  /min 13  /max 13  /check [] >>
1551
        ]
1552
        (7001) exch dup
1553
        pop
1554
 
1555
        [
1556
        << /cset /X  /min  1  /max 30  /check [] >>
1557
        ]
1558
        (7002) exch dup
1559
        pop
1560
 
1561
        [
1562
        << /cset /N  /min  6  /max  6  /check [ /lintyymmdd ] >>
1563
        << /cset /N  /min  4  /max  4  /check [ /linthhmm ] >>
1564
        ]
1565
        (7003) exch dup
1566
        pop
1567
 
1568
        [
1569
        << /cset /N  /min  1  /max  4  /check [] >>
1570
        ]
1571
        (7004) exch dup
1572
        pop
1573
 
1574
        [
1575
        << /cset /X  /min  1  /max 12  /check [] >>
1576
        ]
1577
        (7005) exch dup
1578
        pop
1579
 
1580
        [
1581
        << /cset /N  /min  6  /max  6  /check [ /lintyymmdd ] >>
1582
        ]
1583
        (7006) exch dup
1584
        pop
1585
 
1586
        [
1587
        << /cset /N  /min  6  /max  6  /check [ /lintyymmdd ] >>
1588
        << /cset /N  /min  0  /max  6  /check [ /lintyymmdd ] >>
1589
        ]
1590
        (7007) exch dup
1591
        pop
1592
 
1593
        [
1594
        << /cset /X  /min  1  /max  3  /check [] >>
1595
        ]
1596
        (7008) exch dup
1597
        pop
1598
 
1599
        [
1600
        << /cset /X  /min  1  /max 10  /check [] >>
1601
        ]
1602
        (7009) exch dup
1603
        pop
1604
 
1605
        [
1606
        << /cset /X  /min  1  /max  2  /check [] >>
1607
        ]
1608
        (7010) exch dup
1609
        pop
1610
 
1611
        [
1612
        << /cset /X  /min  1  /max 20  /check [] >>
1613
        ]
1614
        (7020) exch dup
1615
        (7021) exch dup
1616
        (7022) exch dup
1617
        pop
1618
 
1619
        [
1620
        << /cset /X  /min  1  /max 30  /check [ /lintkey ] >>
1621
        ]
1622
        (7023) exch dup
1623
        pop
1624
 
1625
        [
1626
        << /cset /N  /min  3  /max  3  /check [ /lintiso3166999 ] >>
1627
        << /cset /X  /min  1  /max 27  /check [] >>
1628
        ]
1629
        (7030) exch dup
1630
        (7031) exch dup
1631
        (7032) exch dup
1632
        (7033) exch dup
1633
        (7034) exch dup
1634
        (7035) exch dup
1635
        (7036) exch dup
1636
        (7037) exch dup
1637
        (7038) exch dup
1638
        (7039) exch dup
1639
        pop
1640
 
1641
        [
1642
        << /cset /N  /min  1  /max  1  /check [] >>
1643
        << /cset /X  /min  1  /max  1  /check [] >>
1644
        << /cset /X  /min  1  /max  1  /check [] >>
1645
        << /cset /X  /min  1  /max  1  /check [ /lintimporteridx ] >>
1646
        ]
1647
        (7040) exch dup
1648
        pop
1649
 
1650
        [
1651
        << /cset /X  /min  1  /max 20  /check [] >>
1652
        ]
1653
        (710) exch dup
1654
        (711) exch dup
1655
        (712) exch dup
1656
        (713) exch dup
1657
        (714) exch dup
1658
        (715) exch dup
1659
        pop
1660
 
1661
        [
1662
        << /cset /X  /min  2  /max  2  /check [] >>
1663
        << /cset /X  /min  1  /max 28  /check [] >>
1664
        ]
1665
        (7230) exch dup
1666
        (7231) exch dup
1667
        (7232) exch dup
1668
        (7233) exch dup
1669
        (7234) exch dup
1670
        (7235) exch dup
1671
        (7236) exch dup
1672
        (7237) exch dup
1673
        (7238) exch dup
1674
        (7239) exch dup
1675
        pop
1676
 
1677
        [
1678
        << /cset /X  /min  1  /max 20  /check [] >>
1679
        ]
1680
        (7240) exch dup
1681
        pop
1682
 
1683
        [
1684
        << /cset /N  /min  4  /max  4  /check [ /lintnonzero ] >>
1685
        << /cset /N  /min  5  /max  5  /check [ /lintnonzero ] >>
1686
        << /cset /N  /min  3  /max  3  /check [ /lintnonzero ] >>
1687
        << /cset /N  /min  1  /max  1  /check [ /lintwinding ] >>
1688
        << /cset /N  /min  1  /max  1  /check [] >>
1689
        ]
1690
        (8001) exch dup
1691
        pop
1692
 
1693
        [
1694
        << /cset /X  /min  1  /max 20  /check [] >>
1695
        ]
1696
        (8002) exch dup
1697
        pop
1698
 
1699
        [
1700
        << /cset /N  /min  1  /max  1  /check [ /lintzero ] >>
1701
        << /cset /N  /min 13  /max 13  /check [ /lintcsum /lintkey ] >>
1702
        << /cset /X  /min  0  /max 16  /check [] >>
1703
        ]
1704
        (8003) exch dup
1705
        pop
1706
 
1707
        [
1708
        << /cset /X  /min  1  /max 30  /check [ /lintkey ] >>
1709
        ]
1710
        (8004) exch dup
1711
        pop
1712
 
1713
        [
1714
        << /cset /N  /min  6  /max  6  /check [] >>
1715
        ]
1716
        (8005) exch dup
1717
        pop
1718
 
1719
        [
1720
        << /cset /N  /min 14  /max 14  /check [ /lintcsum ] >>
1721
        << /cset /N  /min  4  /max  4  /check [ /lintpieceoftotal ] >>
1722
        ]
1723
        (8006) exch dup
1724
        pop
1725
 
1726
        [
1727
        << /cset /X  /min  1  /max 34  /check [ /lintiban ] >>
1728
        ]
1729
        (8007) exch dup
1730
        pop
1731
 
1732
        [
1733
        << /cset /N  /min  8  /max  8  /check [ /lintyymmddhh ] >>
1734
        << /cset /N  /min  0  /max  4  /check [ /lintmmoptss ] >>
1735
        ]
1736
        (8008) exch dup
1737
        pop
1738
 
1739
        [
1740
        << /cset /X  /min  1  /max 50  /check [] >>
1741
        ]
1742
        (8009) exch dup
1743
        pop
1744
 
1745
        [
1746
        << /cset /C  /min  1  /max 30  /check [ /lintkey ] >>
1747
        ]
1748
        (8010) exch dup
1749
        pop
1750
 
1751
        [
1752
        << /cset /N  /min  1  /max 12  /check [ /lintnozeroprefix ] >>
1753
        ]
1754
        (8011) exch dup
1755
        pop
1756
 
1757
        [
1758
        << /cset /X  /min  1  /max 20  /check [] >>
1759
        ]
1760
        (8012) exch dup
1761
        pop
1762
 
1763
        [
1764
        << /cset /X  /min  1  /max 25  /check [ /lintcsumalpha /lintkey ] >>
1765
        ]
1766
        (8013) exch dup
1767
        pop
1768
 
1769
        [
1770
        << /cset /N  /min 18  /max 18  /check [ /lintcsum ] >>
1771
        ]
1772
        (8017) exch dup
1773
        (8018) exch dup
1774
        pop
1775
 
1776
        [
1777
        << /cset /N  /min  1  /max 10  /check [] >>
1778
        ]
1779
        (8019) exch dup
1780
        pop
1781
 
1782
        [
1783
        << /cset /X  /min  1  /max 25  /check [] >>
1784
        ]
1785
        (8020) exch dup
1786
        pop
1787
 
1788
        [
1789
        << /cset /N  /min 14  /max 14  /check [ /lintcsum ] >>
1790
        << /cset /N  /min  4  /max  4  /check [ /lintpieceoftotal ] >>
1791
        ]
1792
        (8026) exch dup
1793
        pop
1794
 
1795
        [
1796
        << /cset /X  /min  1  /max 70  /check [ /lintcouponcode ] >>
1797
        ]
1798
        (8110) exch dup
1799
        pop
1800
 
1801
        [
1802
        << /cset /N  /min  4  /max  4  /check [] >>
1803
        ]
1804
        (8111) exch dup
1805
        pop
1806
 
1807
        [
1808
        << /cset /X  /min  1  /max 70  /check [ /lintcouponposoffer ] >>
1809
        ]
1810
        (8112) exch dup
1811
        pop
1812
 
1813
        [
1814
        << /cset /X  /min  1  /max 70  /check [] >>
1815
        ]
1816
        (8200) exch dup
1817
        pop
1818
 
1819
        [
1820
        << /cset /X  /min  1  /max 30  /check [] >>
1821
        ]
1822
        (90) exch dup
1823
        pop
1824
 
1825
        [
1826
        << /cset /X  /min  1  /max 90  /check [] >>
1827
        ]
1828
        (91) exch dup
1829
        (92) exch dup
1830
        (93) exch dup
1831
        (94) exch dup
1832
        (95) exch dup
1833
        (96) exch dup
1834
        (97) exch dup
1835
        (98) exch dup
1836
        (99) exch dup
1837
        pop
1838
 
1839
    >> def
1840
 
1841
    true
1842
 
1843
        dup ais exch get /ai exch def
1844
        vals exch get /val exch def
1845
        gs1syntax ai known {
1846
            gs1syntax ai get {  % For each element of the AI
1847
                /props exch def
1848
                props /max get val length 2 copy gt {exch} if pop
1849
                val exch 0 exch getinterval /eval exch def
1850
                /val val eval length dup val length exch sub getinterval def
1851
                eval length props /min get lt {
1852
                    pop /bwipp.GS1valueTooShort (Too short) false exit
1853
                } if
1854
                << /N /lintnumeric  /X /lintcset82  /C /lintcset39 >> props /cset get get eval exch load exec
1855
                eval length 0 gt {
1856
                    props /check get { eval exch load exec } forall
1857
                } if
1858
            } forall
1859
            dup not {exit} if
1860
            val length 0 ne {
1861
                pop /bwipp.GS1valueTooLong (Too long) false exit
1862
            } if
1863
        } {
1864
            pop /bwipp.GS1unknownAI (Unrecognised AI) false exit
1865
        } ifelse
1866
    } for
1867
    not {
1868
        dup length ai length add 5 add string
1869
        dup 0 (AI ) putinterval
1870
        dup 3 ai putinterval
1871
        dup 3 ai length add (: ) putinterval
1872
        dup 5 ai length add 4 -1 roll putinterval
1873
        //raiseerror exec
1874
    } if
1875
    true
1876
 
1877
    end
1878
 
1879
}
1880
[/barcode] {null def} forall
1881
bind def
1882
/gs1lint dup load /uk.co.terryburton.bwipp defineresource pop
1883
end
1884
/setpacking where {pop setpacking} if
1885
%%EndData
1886
%%EndResource
1887
% --END RESOURCE gs1lint--
1888
 
13293 subik 1889
% --BEGIN RENDERER renlinear--
18800 fschmid 1890
% --REQUIRES preamble raiseerror--
25039 craig 1891
%%BeginResource: uk.co.terryburton.bwipp renlinear 0.0 2021092800 74624 73842
1892
%%BeginData:        239 ASCII Lines
16255 fschmid 1893
/setpacking where {pop currentpacking true setpacking} if
1894
1 dict
18800 fschmid 1895
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16255 fschmid 1896
begin
13293 subik 1897
/renlinear {
1898
 
20313 craig 1899
    20 dict begin          % Confine variables to local scope
13293 subik 1900
 
20313 craig 1901
    /args exch def   % We are given some arguments
13293 subik 1902
 
20313 craig 1903
    % Default options
1904
    /sbs [] def
1905
    /bhs [] def
1906
    /bbs [] def
1907
    /txt [] def
1908
    /barcolor (unset) def
1909
    /includetext false def
1910
    /textcolor (unset) def
1911
    /textxalign (unset) def
1912
    /textyalign (unset) def
1913
    /textfont (Courier) def
1914
    /textsize 10 def
1915
    /textxoffset 0 def
1916
    /textyoffset 0 def
1917
    /textgaps 0 def
1918
    /alttext () def
1919
    /bordercolor (unset) def
1920
    /backgroundcolor (unset) def
1921
    /inkspread 0.15 def
1922
    /width 0 def
1923
    /barratio 1 def
1924
    /spaceratio 1 def
1925
    /showborder false def
1926
    /borderleft 10 def
1927
    /borderright 10 def
1928
    /bordertop 1 def
1929
    /borderbottom 1 def
1930
    /borderwidth 0.5 def
1931
    /guardwhitespace false def
1932
    /guardleftpos 0 def
1933
    /guardleftypos 0 def
1934
    /guardrightpos 0 def
1935
    /guardrightypos 0 def
1936
    /guardwidth 6 def
1937
    /guardheight 7 def
25039 craig 1938
 
20313 craig 1939
    % Apply the renderer options and the user options
1940
    args {def} forall
25039 craig 1941
    opt {def} forall
13293 subik 1942
 
20313 craig 1943
    /barcolor barcolor cvlit def
1944
    /textcolor textcolor cvlit def
1945
    /textxalign textxalign cvlit def
1946
    /textyalign textyalign cvlit def
1947
    /textfont textfont cvlit def
1948
    /textsize textsize cvr def
1949
    /textxoffset textxoffset cvr def
1950
    /textyoffset textyoffset cvr def
1951
    /textgaps textgaps cvr def
1952
    /alttext alttext cvlit def
1953
    /bordercolor bordercolor cvlit def
1954
    /backgroundcolor backgroundcolor cvlit def
1955
    /inkspread inkspread cvr def
1956
    /width width cvr def
1957
    /barratio barratio cvr def
1958
    /spaceratio spaceratio cvr def
1959
    /borderleft borderleft cvr def
1960
    /borderright borderright cvr def
1961
    /bordertop bordertop cvr def
1962
    /borderbottom borderbottom cvr def
1963
    /borderwidth borderwidth cvr def
1964
    /guardleftpos guardleftpos cvr def
1965
    /guardleftypos guardleftypos cvr def
1966
    /guardrightpos guardrightpos cvr def
1967
    /guardrightypos guardrightypos cvr def
1968
    /guardwidth guardwidth cvr def
1969
    /guardheight guardheight cvr def
25039 craig 1970
 
20313 craig 1971
    % Create bar elements and put them into the bars array
1972
    /bars sbs length 1 add 2 idiv array def
1973
    /x 0.00 def /maxh 0 def
1974
 
1975
        /i exch def
1976
        i 2 mod 0 eq {           % i is even
1977
            /d sbs i get barratio mul barratio sub 1 add def  % d=digit*r-r+1
1978
            sbs i get 0 ne {
1979
                /h bhs i 2 idiv get 72 mul def  % Height from bhs
1980
                /c d 2 div x add def            % Centre of the bar = x + d/2
1981
                /y bbs i 2 idiv get 72 mul def  % Baseline from bbs
1982
                /w d inkspread sub def          % bar width = digit - inkspread
1983
                bars i 2 idiv [h c y w] put     % Add the bar entry
1984
                h y add maxh gt {/maxh h y add def} if
1985
            } {
1986
                bars i 2 idiv -1 put            % Dummy entry
1987
            } ifelse
1988
        } {
25039 craig 1989
            /d sbs i get spaceratio mul spaceratio sub 1 add def  % d=digit*r-r+1
20313 craig 1990
        } ifelse
1991
        /x x d add def  % x+=d
1992
    } for
13293 subik 1993
 
20313 craig 1994
    gsave
13293 subik 1995
 
20313 craig 1996
    currentpoint translate
13293 subik 1997
 
20313 craig 1998
    % Force symbol to given width
1999
    width 0 ne {
2000
        width 72 mul x div 1 scale
2001
    } if
13293 subik 2002
 
20313 craig 2003
    % Set RGB or CMYK color depending on length of given hex string
2004
    /setanycolor {
2005
        /anycolor exch def
2006
        anycolor length 6 eq {
2007
            (<      >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
2008
        } if
2009
        anycolor length 8 eq {
2010
            (<        >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
2011
        } if
2012
    } bind def
13293 subik 2013
 
20313 craig 2014
    % Display the border and background
2015
    newpath
2016
    borderleft neg borderbottom neg moveto
2017
    x borderleft add borderright add 0 rlineto
2018
 
2019
    x borderleft add borderright add neg 0 rlineto
25039 craig 2020
 
20313 craig 2021
    closepath
25039 craig 2022
    backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
20313 craig 2023
    showborder {
2024
        gsave
2025
        bordercolor (unset) ne { bordercolor setanycolor } if
2026
        borderwidth setlinewidth stroke
2027
        grestore
25039 craig 2028
    } if
2029
 
20313 craig 2030
    % Display the bars for elements in the bars array
2031
    gsave
2032
 
2033
    barcolor (unset) ne { barcolor setanycolor } if
2034
    bars {
2035
        dup -1 ne {
2036
            aload pop newpath setlinewidth moveto 0 exch rlineto stroke
2037
        } {
2038
            pop
2039
        } ifelse
2040
    } forall
2041
    grestore
25039 craig 2042
 
20313 craig 2043
    % Display the text for elements in the text array
2044
    textcolor (unset) ne { textcolor setanycolor } if
2045
    includetext {
2046
        textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
2047
            /s 0 def /fn () def
2048
            txt {
2049
                {} forall
2050
                2 copy s ne exch fn ne or {
22439 craig 2051
                    2 copy /s exch def /fn exch def
2052
                    selectfont
20313 craig 2053
                } {
2054
                    pop pop
2055
                } ifelse
2056
                moveto show
2057
            } forall
2058
        } {
22439 craig 2059
            textfont textsize selectfont
20313 craig 2060
            alttext () eq {
2061
                /txt [ txt { 0 get {} forall } forall ] def
2062
                /tstr txt length string def
2063
 
2064
            } {
2065
                /tstr alttext def
2066
            } ifelse
16255 fschmid 2067
 
20313 craig 2068
            % Find true ascent of font
2069
            tstr length 0 eq {
2070
 
2071
            } {
2072
                gsave
2073
                newpath 0 0 moveto (0) false charpath pathbbox
2074
                4 1 roll pop pop pop
2075
                grestore
2076
                currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
2077
                currentfont /StrokeWidth known and {
2078
                    currentfont /StrokeWidth get 2 div 0 exch
2079
                    currentfont /FontMatrix get dtransform
2080
                    dup mul exch dup mul add sqrt
2081
                    add
2082
                } if
2083
            } ifelse
2084
            /textascent exch def
2085
            /textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
16255 fschmid 2086
 
20313 craig 2087
            /textxpos textxoffset x textwidth sub 2 div add def
2088
            textxalign (left) eq { /textxpos textxoffset def } if
2089
            textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
2090
            textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
2091
            textxalign (offright) eq { /textxpos x textxoffset add def } if
2092
            textxalign (justify) eq textwidth x lt and {
2093
                /textxpos 0 def
2094
                /textgaps x textwidth sub tstr length 1 sub div def
2095
            } if
2096
            /textypos textyoffset textascent add 1 add neg def
2097
            textyalign (above) eq { /textypos textyoffset maxh add 1 add def } if
2098
            textyalign (center) eq { /textypos textyoffset maxh textascent sub 2 div add def } if
2099
            textxpos textypos moveto textgaps 0 tstr ashow
2100
        } ifelse
25039 craig 2101
    } if
13293 subik 2102
 
20313 craig 2103
    % Display the guard elements
2104
    guardwhitespace {
2105
        0.75 setlinewidth
2106
        guardleftpos 0 ne {
2107
            newpath
2108
            guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
2109
            guardwidth neg guardheight -2 div rlineto
2110
            guardwidth guardheight -2 div rlineto
25039 craig 2111
            stroke
20313 craig 2112
        } if
2113
        guardrightpos 0 ne {
2114
            newpath
2115
            guardrightpos x add guardwidth sub guardrightypos guardheight 2 div add moveto
2116
            guardwidth guardheight -2 div rlineto
2117
            guardwidth neg guardheight -2 div rlineto
25039 craig 2118
            stroke
20313 craig 2119
        } if
2120
    } if
25039 craig 2121
 
20313 craig 2122
    grestore
25039 craig 2123
 
20313 craig 2124
    end
13293 subik 2125
 
25039 craig 2126
}
2127
[/barcode] {null def} forall
2128
bind def
16255 fschmid 2129
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
2130
end
2131
/setpacking where {pop setpacking} if
18800 fschmid 2132
%%EndData
2133
%%EndResource
13293 subik 2134
% --END RENDERER renlinear--
2135
 
2136
% --BEGIN RENDERER renmatrix--
18800 fschmid 2137
% --REQUIRES preamble raiseerror--
25039 craig 2138
%%BeginResource: uk.co.terryburton.bwipp renmatrix 0.0 2021092800 90671 89573
2139
%%BeginData:        306 ASCII Lines
16255 fschmid 2140
/setpacking where {pop currentpacking true setpacking} if
2141
1 dict
18800 fschmid 2142
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16255 fschmid 2143
begin
13293 subik 2144
/renmatrix {
2145
 
20313 craig 2146
    20 dict begin
13293 subik 2147
 
20313 craig 2148
    /args exch def
13293 subik 2149
 
20313 craig 2150
    % Default options
2151
    /width 1 def
2152
    /height 1 def
2153
    /barcolor (unset) def
2154
    /backgroundcolor (unset) def
22439 craig 2155
    /colormap (unset) def
25039 craig 2156
    /dotty false def
21413 craig 2157
    /inkspread 0 def
2158
    /inkspreadh 0 def
2159
    /inkspreadv 0 def
22439 craig 2160
    /includetext false def
2161
    /txt [] def
2162
    /textcolor (unset) def
2163
    /textxalign (unset) def
2164
    /textyalign (unset) def
2165
    /textfont (Courier) def
2166
    /textsize 10 def
2167
    /textxoffset 0 def
2168
    /textyoffset 0 def
2169
    /textgaps 0 def
2170
    /alttext () def
13293 subik 2171
 
20313 craig 2172
    % Apply the renderer options and the user options
2173
    args {def} forall
2174
    opt {def} forall
13293 subik 2175
 
20313 craig 2176
    /width width cvr def
2177
    /height height cvr def
2178
    /barcolor barcolor cvlit def
2179
    /backgroundcolor backgroundcolor cvlit def
21413 craig 2180
    /inkspread inkspread cvr def
2181
    /inkspreadh inkspreadh cvr def
2182
    /inkspreadv inkspreadv cvr def
22439 craig 2183
    /textcolor textcolor cvlit def
2184
    /textxalign textxalign cvlit def
2185
    /textyalign textyalign cvlit def
2186
    /textfont textfont cvlit def
2187
    /textsize textsize cvr def
2188
    /textxoffset textxoffset cvr def
2189
    /textyoffset textyoffset cvr def
2190
    /textgaps textgaps cvr def
2191
    /alttext alttext cvlit def
13293 subik 2192
 
21413 craig 2193
    inkspread 0 ne {/inkspreadh inkspread def} if
2194
    inkspread 0 ne {/inkspreadv inkspread def} if
2195
 
25039 craig 2196
    /xyget { pixx mul add pixs exch get} bind def
2197
    /cget { pixx mul add cache exch get and} bind def
2198
    /cput {  % Optimise by only storing "stem" corners
2199
        dup 4 mod 0 eq { % dir is up or left
2200
            3 1 roll pixx mul add cache exch 2 copy get 4 -1 roll or put
2201
        } {
2202
            pop pop pop
2203
        } ifelse
21413 craig 2204
    } bind def
2205
 
25039 craig 2206
    /abcd {
2207
        4 string 0 [
2208
            5 -2 roll
2209
            pixx mul add dup
2210
            pixs exch 2 getinterval aload pop 3 -1 roll  % A B
2211
            pixs exch pixx add 2 getinterval aload pop   % C D
2212
        ] {3 copy 48 add put pop 1 add} forall pop
2213
    } bind def
2214
 
2215
    /right {dir 1 ne {x y dir cput [x y]} if  /x x 1 add def  /dir 1 def} bind def
2216
    /down  {dir 2 ne {x y dir cput [x y]} if  /y y 1 add def  /dir 2 def} bind def
2217
    /left  {dir 4 ne {x y dir cput [x y]} if  /x x 1 sub def  /dir 4 def} bind def
2218
    /up    {dir 8 ne {x y dir cput [x y]} if  /y y 1 sub def  /dir 8 def} bind def
2219
 
21413 craig 2220
    /trace {
2221
        % Walk the outline of a region emitting edge coordinates of the path
2222
        /y exch def  /x exch def
25039 craig 2223
        % dir 1:right 2:down 4:left 8:up
2224
        /dir x 1 add y 1 add xyget 1 eq {8} {4} ifelse def
21413 craig 2225
        /sx x def  /sy y def  /sdir dir def
25039 craig 2226
 
2227
        % A B
2228
        % C D
2229
        mark {
2230
            x y abcd
2231
            1 {  % Common exit
2232
                dup dup (0001) eq exch dup (0011) eq exch (1011) eq or or {pop right exit} if
2233
                dup dup (0010) eq exch dup (1010) eq exch (1110) eq or or {pop down  exit} if
2234
                dup dup (1000) eq exch dup (1100) eq exch (1101) eq or or {pop left  exit} if
2235
                dup dup (0100) eq exch dup (0101) eq exch (0111) eq or or {pop up    exit} if
2236
                dup (1001) eq {
2237
                    dir 2 eq {pop left exit} {pop right exit} ifelse
2238
                } {  % 0110
2239
                    dir 1 eq {pop down exit} {pop up exit} ifelse
21413 craig 2240
                } ifelse
25039 craig 2241
            } repeat
21413 craig 2242
            x sx eq y sy eq and dir sdir eq and {exit} if
2243
        } loop
2244
        counttomark array astore exch pop
2245
 
2246
    } bind def
2247
 
20313 craig 2248
    % Set RGB or CMYK color depending on length of given hex string
2249
    /setanycolor {
2250
        /anycolor exch def
2251
        anycolor length 6 eq {
2252
            (<      >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
2253
        } if
2254
        anycolor length 8 eq {
2255
            (<        >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
2256
        } if
2257
    } bind def
13293 subik 2258
 
22439 craig 2259
    % Plot a layer of single colour
2260
    /drawlayer {
2261
 
2262
        /pixsorig pixs def
2263
        /pixs exch def
2264
 
2265
        % Pad the bitmap on all sides
2266
        /pixs [
2267
            pixx 2 add {0} repeat
2268
 
2269
 
2270
                pixs exch pixx getinterval aload pop
2271
 
2272
            } for
2273
            pixx 2 add {0} repeat
2274
        ] def
2275
        /pixx pixx 2 add def
2276
        /pixy pixy 2 add def
2277
 
25039 craig 2278
        % Cache of visited corners for each direction
2279
        /cache [ pixs length {0} repeat ] def
22439 craig 2280
 
25039 craig 2281
        % Construct paths by tracing regions avoiding duplication by using the cache
22439 craig 2282
        /paths [
25039 craig 2283
 
22439 craig 2284
                /j exch def
25039 craig 2285
 
22439 craig 2286
                    /i exch def
25039 craig 2287
                    /k i j abcd def
2288
                    k (0001) eq k (1001) eq or {  % Black region stem corners
2289
                        8 i j cget 0 eq {
2290
                            i j trace
2291
                        } if
22439 craig 2292
                    } if
25039 craig 2293
                    k (1110) eq {  % White region stem corner
2294
                        4 i j cget 0 eq {
2295
                            i j trace
2296
                        } if
2297
                    } if
22439 craig 2298
                } for
2299
            } for
2300
        ] def
2301
 
2302
        % Revert the bitmap size
2303
        /pixx pixx 2 sub def
2304
        /pixy pixy 2 sub def
2305
 
2306
        % Draw the image
2307
        newpath
2308
        paths {
2309
            /p exch def
2310
            /len p length def
2311
            p len 1 sub get aload pop
2312
            p 0 get aload pop
2313
 
2314
                /i exch def
2315
                p i 1 add len mod get aload pop 6 -2 roll  % x3 y3 x1 y1 x2 y2
2316
                5 index inkspreadh
2317
                4 index 4 -1 roll lt {add} {sub} ifelse    % y3<y1 ? x2+i : x2-i
2318
                4 1 roll
2319
                4 index inkspreadv
2320
                4 index 4 -1 roll gt {add} {sub} ifelse    % x3>x1 ? y2+i : y2-i
2321
                4 -1 roll exch pixy exch sub
2322
                i 0 eq {moveto} {lineto} ifelse
2323
            } for                                          % x2 y2 x3 y3
2324
            closepath
2325
            pop pop pop pop
2326
        } forall
2327
        fill
2328
 
2329
        /pixs pixsorig def
2330
 
2331
    } bind def
2332
 
25039 craig 2333
    /drawlayerdots {
2334
 
2335
        /pixsorig pixs def
2336
        /pixs exch def
2337
 
2338
        newpath
2339
 
2340
            dup pixx mod /x exch def
2341
            pixx idiv /y exch def
2342
            x y xyget 1 eq {
2343
               x 0.5 add pixy y sub 0.5 sub moveto
2344
               x 0.5 add pixy y sub 0.5 sub 0.5 inkspread sub 0 360 arc
2345
            } if
2346
        } for
2347
        fill
2348
 
2349
        /pixs pixsorig def
2350
 
2351
    } bind def
2352
 
22439 craig 2353
    gsave
2354
 
20313 craig 2355
    % Draw the image
25039 craig 2356
    /inkspread  inkspread  2 div def
21413 craig 2357
    /inkspreadh inkspreadh 2 div def
2358
    /inkspreadv inkspreadv 2 div def
20313 craig 2359
    currentpoint translate
2360
    width pixx div 72 mul height pixy div 72 mul scale
2361
 
21413 craig 2362
    backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
22439 craig 2363
 
2364
    colormap (unset) eq {
2365
        /colormap << 1 barcolor >> def
2366
    } if
2367
 
2368
    colormap {
2369
        setanycolor
2370
        /key exch def
2371
        [
2372
            pixs { key eq {1} {0} ifelse } forall
25039 craig 2373
        ] dotty {drawlayerdots} {drawlayer} ifelse
21413 craig 2374
    } forall
22439 craig 2375
 
2376
    % Display the text for elements in the text array
2377
    textcolor (unset) ne { textcolor setanycolor } if
2378
    includetext {
2379
        textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
2380
            /s 0 def /fn () def
2381
            txt {
2382
                {} forall
2383
                2 copy s ne exch fn ne or {
2384
                    2 copy /s exch def /fn exch def
2385
                    selectfont
2386
                } {
2387
                    pop pop
2388
                } ifelse
2389
                moveto show
2390
            } forall
2391
        } {
2392
            textfont textsize selectfont
2393
            alttext () eq {
2394
                /txt [ txt { 0 get {} forall } forall ] def
2395
                /tstr txt length string def
2396
 
2397
            } {
2398
                /tstr alttext def
2399
            } ifelse
2400
 
2401
            % Find true ascent of font
2402
            tstr length 0 eq {
2403
 
2404
            } {
2405
                gsave
2406
                newpath 0 0 moveto (0) false charpath pathbbox
2407
                4 1 roll pop pop pop
2408
                grestore
2409
                currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
2410
                currentfont /StrokeWidth known and {
2411
                    currentfont /StrokeWidth get 2 div 0 exch
2412
                    currentfont /FontMatrix get dtransform
2413
                    dup mul exch dup mul add sqrt
2414
                    add
2415
                } if
2416
            } ifelse
2417
            /textascent exch def
2418
            /textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def
2419
 
2420
            /textxpos textxoffset x textwidth sub 2 div add def
2421
            textxalign (left) eq { /textxpos textxoffset def } if
2422
            textxalign (right) eq { /textxpos x textxoffset sub textwidth sub def } if
2423
            textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
2424
            textxalign (offright) eq { /textxpos x textxoffset add def } if
2425
            textxalign (justify) eq textwidth x lt and {
2426
                /textxpos 0 def
2427
                /textgaps x textwidth sub tstr length 1 sub div def
2428
            } if
2429
            /textypos textyoffset textascent add 1 add neg def
2430
            textyalign (above) eq { /textypos textyoffset pixy add 1 add def } if
2431
            textyalign (center) eq { /textypos textyoffset pixy textascent sub 2 div add def } if
2432
            textxpos textypos moveto textgaps 0 tstr ashow
2433
        } ifelse
2434
    } if
2435
 
20313 craig 2436
    grestore
13293 subik 2437
 
20313 craig 2438
    end
13293 subik 2439
 
25039 craig 2440
}
2441
[/barcode] {null def} forall
2442
bind def
16255 fschmid 2443
/renmatrix dup load /uk.co.terryburton.bwipp defineresource pop
2444
end
2445
/setpacking where {pop setpacking} if
18800 fschmid 2446
%%EndData
2447
%%EndResource
13293 subik 2448
% --END RENDERER renmatrix--
2449
 
2450
% --BEGIN RENDERER renmaximatrix--
18800 fschmid 2451
% --REQUIRES preamble raiseerror--
25039 craig 2452
%%BeginResource: uk.co.terryburton.bwipp renmaximatrix 0.0 2021092800 50254 49916
2453
%%BeginData:         81 ASCII Lines
16255 fschmid 2454
/setpacking where {pop currentpacking true setpacking} if
2455
1 dict
18800 fschmid 2456
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16255 fschmid 2457
begin
13293 subik 2458
/renmaximatrix {
2459
 
20313 craig 2460
    20 dict begin
13293 subik 2461
 
20313 craig 2462
    /args exch def   % We are given some arguments
13293 subik 2463
 
20313 craig 2464
    % Default options
2465
    /barcolor (unset) def
2466
    /backgroundcolor (unset) def
18800 fschmid 2467
 
20313 craig 2468
    % Apply the renderer options and the user options
2469
    args {def} forall
2470
    opt {def} forall
18800 fschmid 2471
 
20313 craig 2472
    /barcolor barcolor cvlit def
2473
    /backgroundcolor backgroundcolor cvlit def
18800 fschmid 2474
 
20313 craig 2475
    % Set RGB or CMYK color depending on length of given hex string
2476
    /setanycolor {
2477
        /anycolor exch def
2478
        anycolor length 6 eq {
2479
            (<      >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
2480
        } if
2481
        anycolor length 8 eq {
2482
            (<        >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
2483
        } if
2484
    } bind def
18800 fschmid 2485
 
20313 craig 2486
    gsave
13293 subik 2487
 
20313 craig 2488
    currentpoint translate
13293 subik 2489
 
22439 craig 2490
    2.4945 dup scale  % from 1pt to 0.88mm
18800 fschmid 2491
 
20313 craig 2492
 
22439 craig 2493
    backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
20313 craig 2494
    barcolor (unset) ne { barcolor setanycolor } if
18800 fschmid 2495
 
20313 craig 2496
    0.5 0.5774 translate
13293 subik 2497
 
20313 craig 2498
    newpath
2499
    pixs {
22439 craig 2500
        dup
2501
        /x exch 30 mod def
20313 craig 2502
        /y exch 30 idiv def
2503
        y 2 mod 0 eq {x} {x 0.5 add} ifelse
2504
        32 y sub 0.8661 mul
2505
        moveto
2506
 
2507
        -0.5 -0.2887 rlineto
2508
 
2509
        0.5  -0.2887 rlineto
2510
        0.5   0.2887 rlineto
2511
 
2512
        -0.5  0.2887 rlineto
2513
        closepath
2514
    } forall
2515
    fill
13293 subik 2516
 
20313 craig 2517
    % Plot the locator symbol
2518
    newpath 14 13.8576 0.5774 0 360 arc closepath
2519
    14 13.8576 1.3359 360 0 arcn closepath fill
2520
    newpath 14 13.8576 2.1058 0 360 arc closepath
2521
    14 13.8576 2.8644 360 0 arcn closepath fill
2522
    newpath 14 13.8576 3.6229 0 360 arc closepath
2523
    14 13.8576 4.3814 360 0 arcn closepath fill
13293 subik 2524
 
20313 craig 2525
    grestore
13293 subik 2526
 
20313 craig 2527
    end
13293 subik 2528
 
25039 craig 2529
}
2530
[/barcode] {null def} forall
2531
bind def
16255 fschmid 2532
/renmaximatrix dup load /uk.co.terryburton.bwipp defineresource pop
2533
end
2534
/setpacking where {pop setpacking} if
18800 fschmid 2535
%%EndData
2536
%%EndResource
13293 subik 2537
% --END RENDERER renmaximatrix--
2538
 
2539
% --BEGIN ENCODER ean5--
18800 fschmid 2540
% --REQUIRES preamble raiseerror renlinear--
13293 subik 2541
% --DESC: EAN-5 (5 digit addon)
2542
% --EXAM: 90200
2543
% --EXOP: includetext guardwhitespace
2544
% --RNDR: renlinear
25039 craig 2545
%%BeginResource: uk.co.terryburton.bwipp ean5 0.0 2021092800 58142 57964
2546
%%BeginData:        137 ASCII Lines
16255 fschmid 2547
/setpacking where {pop currentpacking true setpacking} if
2548
1 dict
18800 fschmid 2549
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16255 fschmid 2550
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
2551
begin
13293 subik 2552
/ean5 {
2553
 
20313 craig 2554
    20 dict begin
13293 subik 2555
 
20313 craig 2556
    /options exch def                   % We are given an option string
2557
    /barcode exch def                   % We are given a barcode string
13293 subik 2558
 
20313 craig 2559
    /dontdraw false def
2560
    /includetext false def              % Enable/disable text
2561
    /textfont /Helvetica def
2562
    /textsize 12 def
2563
    /textxoffset 0 def
2564
    /textyoffset (unset) def
25039 craig 2565
    /height 0.7 def
2566
 
20313 craig 2567
    % Parse the input options
2568
    options type /stringtype eq {
2569
        1 dict begin
2570
        options {
2571
            token false eq {exit} if dup length string cvs (=) search
2572
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
2573
        } loop
2574
        currentdict end /options exch def
2575
    } if
25039 craig 2576
    options {def} forall
2577
 
20313 craig 2578
    /textfont textfont cvlit def
2579
    /textsize textsize cvr def
2580
    /height height cvr def
2581
    /textxoffset textxoffset cvr def
2582
    textyoffset (unset) eq {
2583
        /textyoffset height 72 mul 1 add def
2584
    } {
2585
        /textyoffset textyoffset cvr def
2586
    } ifelse
18800 fschmid 2587
 
20313 craig 2588
    % Validate input
2589
    barcode length 5 ne {
2590
        /bwipp.ean5badLength (EAN-5 add-on must be 5 digits) //raiseerror exec
2591
    } if
2592
    barcode {
2593
        dup 48 lt exch 57 gt or {
2594
            /bwipp.ean5badCharacter (EAN-5 add-on must contain only digits) //raiseerror exec
2595
        } if
2596
    } forall
25039 craig 2597
 
20313 craig 2598
    % Create an array containing the character mappings
2599
    /encs
2600
    [ (3211) (2221) (2122) (1411) (1132)
2601
      (1231) (1114) (1312) (1213) (3112)
2602
      (112) (11)
2603
    ] def
13293 subik 2604
 
20313 craig 2605
    % Create a string of the available characters
2606
    /barchars (0123456789) def
13293 subik 2607
 
20313 craig 2608
    % Determine the mirror map based on mod 10 checksum
2609
    /mirrormaps
2610
    [ (11000) (10100) (10010) (10001) (01100)
2611
      (00110) (00011) (01010) (01001) (00101)
2612
    ] def
2613
    /checksum 0 def
2614
 
2615
        /i exch def
2616
        /barchar barcode i get 48 sub def
2617
        i 2 mod 0 eq {
2618
            /checksum barchar 3 mul checksum add def
2619
        } {
2620
            /checksum barchar 9 mul checksum add def
2621
        } ifelse
2622
    } for
2623
    /checksum checksum 10 mod def
2624
    /mirrormap mirrormaps checksum get def
13293 subik 2625
 
20313 craig 2626
    /sbs 31 string def
2627
    /txt 5 array def
25039 craig 2628
 
20313 craig 2629
 
2630
        /i exch def
13293 subik 2631
 
20313 craig 2632
        % Prefix with either a start character or separator character
2633
        i 0 eq {
2634
            sbs 0 encs 10 get putinterval
2635
        } {
2636
            sbs i 1 sub 6 mul 7 add encs 11 get putinterval
2637
        } ifelse
13293 subik 2638
 
20313 craig 2639
        % Lookup the encoding for the barcode character
2640
        barcode i 1 getinterval barchars exch search
2641
        pop                     % Discard true leaving pre
2642
        length /indx exch def   % indx is the length of pre
2643
        pop pop                 % Discard seek and post
2644
        /enc encs indx get def  % Get the indxth encoding
2645
        mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
2646
            /enclen enc length def
2647
            /revenc enclen string def
2648
 
2649
                /j exch def
2650
                /char enc j get def
2651
                revenc enclen j sub 1 sub char put
2652
            } for
2653
            /enc revenc def
2654
        } if
2655
        sbs i 6 mul 3 add enc putinterval   % Put encoded digit into sbs
2656
        txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textxoffset add textyoffset textfont textsize] put
2657
    } for
13293 subik 2658
 
20313 craig 2659
    % Return the arguments
2660
    <<
2661
    /ren //renlinear
2662
    /sbs [sbs {48 sub} forall]
2663
    /bhs [16{height}repeat]
2664
    /bbs [16{0}repeat]
2665
    includetext {
2666
        /txt txt
2667
    } if
2668
    /opt options
2669
    /guardrightpos 10
2670
    /guardrightypos textyoffset 4 add
2671
    /bordertop 10
2672
    >>
13293 subik 2673
 
20313 craig 2674
    dontdraw not //renlinear if
13293 subik 2675
 
20313 craig 2676
    end
13293 subik 2677
 
25039 craig 2678
}
2679
[/barcode] {null def} forall
2680
bind def
16255 fschmid 2681
/ean5 dup load /uk.co.terryburton.bwipp defineresource pop
2682
end
2683
/setpacking where {pop setpacking} if
18800 fschmid 2684
%%EndData
2685
%%EndResource
13293 subik 2686
% --END ENCODER ean5--
2687
 
2688
% --BEGIN ENCODER ean2--
18800 fschmid 2689
% --REQUIRES preamble raiseerror renlinear--
13293 subik 2690
% --DESC: EAN-2 (2 digit addon)
2691
% --EXAM: 05
2692
% --EXOP: includetext guardwhitespace
2693
% --RNDR: renlinear
25039 craig 2694
%%BeginResource: uk.co.terryburton.bwipp ean2 0.0 2021092800 56699 56466
2695
%%BeginData:        122 ASCII Lines
16255 fschmid 2696
/setpacking where {pop currentpacking true setpacking} if
2697
1 dict
18800 fschmid 2698
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16255 fschmid 2699
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
2700
begin
13293 subik 2701
/ean2 {
2702
 
20313 craig 2703
    20 dict begin
13293 subik 2704
 
20313 craig 2705
    /options exch def                   % We are given an options string
2706
    /barcode exch def                   % We are given a barcode string
13293 subik 2707
 
20313 craig 2708
    /dontdraw false def
2709
    /includetext false def               % Enable/disable text
2710
    /textfont /Helvetica def
2711
    /textsize 12 def
2712
    /textxoffset 0 def
2713
    /textyoffset (unset) def
2714
    /height 0.7 def
25039 craig 2715
 
20313 craig 2716
    % Parse the input options
2717
    options type /stringtype eq {
2718
        1 dict begin
2719
        options {
2720
            token false eq {exit} if dup length string cvs (=) search
2721
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
2722
        } loop
2723
        currentdict end /options exch def
2724
    } if
2725
    options {def} forall
25039 craig 2726
 
20313 craig 2727
    /textfont textfont cvlit def
2728
    /textsize textsize cvr def
2729
    /height height cvr def
2730
    /textxoffset textxoffset cvr def
2731
    textyoffset (unset) eq {
2732
        /textyoffset height 72 mul 1 add def
2733
    } {
2734
        /textyoffset textyoffset cvr def
2735
    } ifelse
18800 fschmid 2736
 
20313 craig 2737
    % Validate input
2738
    barcode length 2 ne {
2739
      /bwipp.ean2badLength (EAN-2 add-on must be 2 digits) //raiseerror exec
2740
    } if
2741
    barcode {
2742
        dup 48 lt exch 57 gt or {
2743
            /bwipp.ean2badCharacter (EAN-2 add-on must contain only digits) //raiseerror exec
2744
        } if
2745
    } forall
25039 craig 2746
 
20313 craig 2747
    % Create an array containing the character mappings
2748
    /encs
2749
    [ (3211) (2221) (2122) (1411) (1132)
2750
      (1231) (1114) (1312) (1213) (3112)
2751
      (112) (11)
2752
    ] def
13293 subik 2753
 
20313 craig 2754
    % Create a string of the available characters
2755
    /barchars (0123456789) def
13293 subik 2756
 
20313 craig 2757
    % Determine the mirror map based on mod 4 checksum
2758
    /mirrormap [(00) (01) (10) (11)] barcode 0 2 getinterval cvi 4 mod get def
13293 subik 2759
 
20313 craig 2760
    /sbs 13 string def
2761
    /txt 2 array def
25039 craig 2762
 
20313 craig 2763
 
2764
        /i exch def
13293 subik 2765
 
20313 craig 2766
        % Prefix with either a start character or separator character
2767
        i 0 eq {
2768
            sbs 0 encs 10 get putinterval
2769
        } {
2770
            sbs i 1 sub 6 mul 7 add encs 11 get putinterval
2771
        } ifelse
13293 subik 2772
 
20313 craig 2773
        % Lookup the encoding for the barcode character
2774
        barcode i 1 getinterval barchars exch search
2775
        pop                     % Discard true leaving pre
2776
        length /indx exch def   % indx is the length of pre
2777
        pop pop                 % Discard seek and post
2778
        /enc encs indx get def  % Get the indxth encoding
25039 craig 2779
        mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
20313 craig 2780
            /enclen enc length def
2781
            /revenc enclen string def
2782
 
2783
                /j exch def
2784
                /char enc j get def
2785
                revenc enclen j sub 1 sub char put
2786
            } for
2787
            /enc revenc def
2788
        } if
2789
        sbs i 6 mul 3 add enc putinterval   % Put encoded digit into sbs
2790
        txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textxoffset add textyoffset textfont textsize] put
2791
    } for
13293 subik 2792
 
20313 craig 2793
    % Return the arguments
2794
    <<
2795
    /ren //renlinear
2796
    /sbs [sbs {48 sub} forall]
2797
    /bhs [12{height}repeat]
2798
    /bbs [12{0}repeat]
2799
    includetext {
2800
        /txt txt
2801
    } if
2802
    /opt options
2803
    /guardrightpos 10
2804
    /guardrightypos textyoffset 4 add
2805
    /bordertop 10
2806
    >>
13293 subik 2807
 
20313 craig 2808
    dontdraw not //renlinear if
13293 subik 2809
 
20313 craig 2810
    end
13293 subik 2811
 
25039 craig 2812
}
2813
[/barcode] {null def} forall
2814
bind def
16255 fschmid 2815
/ean2 dup load /uk.co.terryburton.bwipp defineresource pop
2816
end
2817
/setpacking where {pop setpacking} if
18800 fschmid 2818
%%EndData
2819
%%EndResource
13293 subik 2820
% --END ENCODER ean2--
2821
 
4460 subik 2822
% --BEGIN ENCODER ean13--
18800 fschmid 2823
% --REQUIRES preamble raiseerror renlinear ean5 ean2--
7162 subik 2824
% --DESC: EAN-13
18800 fschmid 2825
% --EXAM: 2112345678900
11277 subik 2826
% --EXOP: includetext guardwhitespace
2827
% --RNDR: renlinear
25039 craig 2828
%%BeginResource: uk.co.terryburton.bwipp ean13 0.0 2021092800 77528 80639
2829
%%BeginData:        217 ASCII Lines
16255 fschmid 2830
/setpacking where {pop currentpacking true setpacking} if
2831
1 dict
18800 fschmid 2832
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16255 fschmid 2833
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
2834
dup /ean2 dup /uk.co.terryburton.bwipp findresource put
2835
dup /ean5 dup /uk.co.terryburton.bwipp findresource put
2836
begin
4460 subik 2837
/ean13 {
2838
 
20313 craig 2839
    20 dict begin
4460 subik 2840
 
20313 craig 2841
    /options exch def                  % We are given an option string
2842
    /barcode exch def                  % We are given a barcode string
4460 subik 2843
 
20313 craig 2844
    /dontdraw false def
2845
    /includetext false def             % Enable/disable text
2846
    /textfont /Helvetica def
2847
    /textsize 12 def
2848
    /textxoffset -10 def
2849
    /textyoffset -4 def
2850
    /height 1 def
2851
    /addongap 12 def
2852
    /addontextfont (unset) def
2853
    /addontextsize (unset) def
2854
    /addontextxoffset (unset) def
2855
    /addontextyoffset (unset) def
13293 subik 2856
 
20313 craig 2857
    % Parse the input options, either a string or a dict
2858
    options type /stringtype eq {
2859
        1 dict begin
2860
        options {
2861
            token false eq {exit} if dup length string cvs (=) search
2862
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
2863
        } loop
2864
        currentdict end /options exch def
2865
    } if
2866
    options {def} forall
13293 subik 2867
 
20313 craig 2868
    /textfont textfont cvlit def
2869
    /textsize textsize cvr def
2870
    /textxoffset textxoffset cvr def
2871
    /textyoffset textyoffset cvr def
2872
    /height height cvr def
25039 craig 2873
    /addongap addongap cvr def
20313 craig 2874
    addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if
2875
    addontextsize (unset) ne {/addontextsize addontextsize cvr def} if
2876
    addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if
2877
    addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if
4460 subik 2878
 
20313 craig 2879
    % Split off the addon
2880
    barcode ( ) search {
2881
        /barcode exch def
2882
        pop
2883
        /addon exch def
2884
    } {
2885
        pop
2886
        /addon () def
2887
    } ifelse
18800 fschmid 2888
 
20313 craig 2889
    % Validate the input
2890
    barcode length 12 ne barcode length 13 ne and {
2891
        /bwipp.ean13badLength (EAN-13 must be 12 or 13 digits) //raiseerror exec
2892
    } if
2893
    barcode {
2894
        dup 48 lt exch 57 gt or {
2895
            /bwipp.ean13badCharacter (EAN-13 must contain only digits) //raiseerror exec
2896
        } if
2897
    } forall
2898
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
2899
        /bwipp.ean13badAddOnLength (Add-on for EAN-13 must be 2 or 5 digits) //raiseerror exec
2900
    } if
18800 fschmid 2901
 
20313 craig 2902
    % Add checksum digit
2903
    /pad 13 string def
2904
    /checksum 0 def
2905
 
2906
        /i exch def
2907
        /barchar barcode i get 48 sub def
2908
        i 2 mod 0 eq {
2909
            /checksum barchar checksum add def
2910
        } {
2911
            /checksum barchar 3 mul checksum add def
2912
        } ifelse
2913
    } for
2914
    /checksum 10 checksum 10 mod sub 10 mod def
2915
    barcode length 13 eq {
2916
        barcode 12 get checksum 48 add ne {
2917
            /bwipp.ean13badCheckDigit (Incorrect EAN-13 check digit provided) //raiseerror exec
2918
        } if
2919
    } if
2920
    pad 0 barcode putinterval       % Add barcode to the start of the pad
2921
    pad 12 checksum 48 add put      % Put ascii for checksum at end of pad
2922
    /barcode pad def
4460 subik 2923
 
20313 craig 2924
    % Create an array containing the character mappings
2925
    /encs
2926
    [ (3211) (2221) (2122) (1411) (1132)
2927
      (1231) (1114) (1312) (1213) (3112)
2928
      (111) (11111) (111)
2929
    ] def
4460 subik 2930
 
20313 craig 2931
    % Create a string of the available characters
2932
    /barchars (0123456789) def
4460 subik 2933
 
20313 craig 2934
    % Digits to mirror on left side
2935
    /mirrormaps
2936
    [ (000000) (001011) (001101) (001110) (010011)
2937
      (011001) (011100) (010101) (010110) (011010)
2938
    ] def
4460 subik 2939
 
20313 craig 2940
    /sbs 59 string def
2941
    /txt 13 array def
25039 craig 2942
 
20313 craig 2943
    % Put the start character
2944
    sbs 0 encs 10 get putinterval
4460 subik 2945
 
20313 craig 2946
    % First digit - determine mirrormap by this and show before guard bars
2947
    /mirrormap mirrormaps barcode 0 get 48 sub get def
2948
    txt 0 [barcode 0 1 getinterval textxoffset textyoffset textfont textsize] put
4460 subik 2949
 
20313 craig 2950
    % Left side - performs mirroring
2951
    1 1 6 {
2952
        % Lookup the encoding for the each barcode character
2953
        /i exch def
2954
        barcode i 1 getinterval barchars exch search
2955
        pop                            % Discard true leaving pre
2956
        length /indx exch def          % indx is the length of pre
2957
        pop pop                        % Discard seek and post
2958
        /enc encs indx get def         % Get the indxth encoding
2959
        mirrormap i 1 sub get 49 eq {   % Reverse enc if 1 in this position in mirrormap
2960
            /enclen enc length def
2961
            /revenc enclen string def
2962
 
2963
                /j exch def
2964
                /char enc j get def
2965
                revenc enclen j sub 1 sub char put
2966
            } for
2967
            /enc revenc def
2968
        } if
2969
        sbs i 1 sub 4 mul 3 add enc putinterval   % Put encoded digit into sbs
2970
        txt i [barcode i 1 getinterval i 1 sub 7 mul 14 add textxoffset add textyoffset textfont textsize] put
2971
    } for
4460 subik 2972
 
20313 craig 2973
    % Put the middle character
2974
    sbs 7 1 sub 4 mul 3 add encs 11 get putinterval
4460 subik 2975
 
20313 craig 2976
    % Right side
2977
    7 1 12 {
2978
        % Lookup the encoding for the each barcode character
2979
        /i exch def
2980
        barcode i 1 getinterval barchars exch search
2981
        pop                            % Discard true leaving pre
2982
        length /indx exch def          % indx is the length of pre
2983
        pop pop                        % Discard seek and post
2984
        /enc encs indx get def         % Get the indxth encoding
2985
        sbs i 1 sub 4 mul 8 add enc putinterval  % Put encoded digit into sbs
2986
        txt i [barcode i 1 getinterval i 1 sub 7 mul 18 add textxoffset add textyoffset textfont textsize] put
2987
    } for
4460 subik 2988
 
20313 craig 2989
    % Put the end character
2990
    sbs 56 encs 12 get putinterval
13293 subik 2991
 
20313 craig 2992
    /sbs [sbs {48 sub} forall] def
2993
    includetext {
2994
        /bhs [height height 12{height .075 sub}repeat height height 12{height .075 sub}repeat height height] def
2995
        /bbs [0 0 12{.075}repeat 0 0 12{.075}repeat 0 0] def
2996
    } {
2997
        /bhs [30{height}repeat] def
2998
        /bbs [30{0}repeat] def
2999
        /txt [] def
3000
    } ifelse
3001
    /guardrightypos 0 def
13293 subik 3002
 
20313 craig 3003
    % Append the addon
3004
    addon () ne {
3005
        /addopts <<
3006
            /dontdraw true
3007
            /includetext true
3008
            /height height 0.15 sub
3009
            /textxoffset addontextxoffset (unset) ne {addontextxoffset} {95 addongap add} ifelse
3010
            addontextyoffset (unset) ne {/textyoffset addontextyoffset} if
3011
            /textsize addontextsize (unset) ne {addontextsize} {textsize} ifelse
3012
            /textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse
3013
        >> def
3014
        addon length 2 eq {addon addopts //ean2 exec} if
3015
        addon length 5 eq {addon addopts //ean5 exec} if
3016
        /addcode exch def
3017
        /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
3018
        /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
3019
        /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
3020
        /txt [txt aload pop addcode (txt) get aload pop] def
3021
        /guardrightypos height 72 mul 6 sub def
25039 craig 3022
    } if
3023
 
20313 craig 3024
    % Return the arguments
3025
    <<
3026
    /ren //renlinear
3027
    /sbs sbs
3028
    /bhs bhs
3029
    /bbs bbs
3030
    /txt txt
3031
    /opt options
3032
    /guardrightpos 10
3033
    /guardrightypos guardrightypos
3034
    /borderbottom 5
3035
    >>
13293 subik 3036
 
20313 craig 3037
    dontdraw not //renlinear if
13293 subik 3038
 
20313 craig 3039
    end
4460 subik 3040
 
25039 craig 3041
}
3042
[/barcode] {null def} forall
3043
bind def
16255 fschmid 3044
/ean13 dup load /uk.co.terryburton.bwipp defineresource pop
3045
end
3046
/setpacking where {pop setpacking} if
18800 fschmid 3047
%%EndData
3048
%%EndResource
4460 subik 3049
% --END ENCODER ean13--
3050
 
3051
% --BEGIN ENCODER ean8--
18800 fschmid 3052
% --REQUIRES preamble raiseerror renlinear ean5 ean2--
7162 subik 3053
% --DESC: EAN-8
18800 fschmid 3054
% --EXAM: 02345673
3055
% --EXOP: includetext guardwhitespace
11277 subik 3056
% --RNDR: renlinear
25039 craig 3057
%%BeginResource: uk.co.terryburton.bwipp ean8 0.0 2021092800 74726 77866
3058
%%BeginData:        198 ASCII Lines
16255 fschmid 3059
/setpacking where {pop currentpacking true setpacking} if
3060
1 dict
18800 fschmid 3061
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16255 fschmid 3062
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
3063
dup /ean2 dup /uk.co.terryburton.bwipp findresource put
3064
dup /ean5 dup /uk.co.terryburton.bwipp findresource put
3065
begin
4460 subik 3066
/ean8 {
3067
 
20313 craig 3068
    20 dict begin
4460 subik 3069
 
20313 craig 3070
    /options exch def                  % We are given an option string
3071
    /barcode exch def                  % We are given a barcode string
4460 subik 3072
 
20313 craig 3073
    /dontdraw false def
3074
    /includetext false def              % Enable/disable text
3075
    /textfont /Helvetica def
3076
    /textsize 12 def
3077
    /textxoffset 4 def
3078
    /textyoffset -4 def
3079
    /height 1 def
3080
    /addongap 12 def
3081
    /addontextfont (unset) def
3082
    /addontextsize (unset) def
3083
    /addontextxoffset (unset) def
3084
    /addontextyoffset (unset) def
25039 craig 3085
 
20313 craig 3086
    % Parse the input options, either a string or a dict
3087
    options type /stringtype eq {
3088
        1 dict begin
3089
        options {
3090
            token false eq {exit} if dup length string cvs (=) search
3091
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
3092
        } loop
3093
        currentdict end /options exch def
3094
    } if
3095
    options {def} forall
25039 craig 3096
 
20313 craig 3097
    /textfont textfont cvlit def
3098
    /textsize textsize cvr def
3099
    /textxoffset textxoffset cvr def
3100
    /textyoffset textyoffset cvr def
3101
    /height height cvr def
3102
    /addongap addongap cvr def
3103
    addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if
3104
    addontextsize (unset) ne {/addontextsize addontextsize cvr def} if
3105
    addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if
3106
    addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if
13293 subik 3107
 
20313 craig 3108
    % Split off the addon
3109
    barcode ( ) search {
3110
        /barcode exch def
3111
        pop
3112
        /addon exch def
3113
    } {
3114
        pop
3115
        /addon () def
3116
    } ifelse
16255 fschmid 3117
 
20313 craig 3118
    % Validate the input
3119
    barcode length 7 ne barcode length 8 ne and {
3120
        /bwipp.ean8badLength (EAN-8 must be 7 or 8 digits) //raiseerror exec
3121
    } if
3122
    barcode {
3123
        dup 48 lt exch 57 gt or {
3124
            /bwipp.ean8badCharacter (EAN-8 must contain only digits) //raiseerror exec
3125
        } if
3126
    } forall
3127
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
3128
        /bwipp.ean8badAddOnLength (Add-on for EAN-8 must be 2 or 5 digits) //raiseerror exec
3129
    } if
18800 fschmid 3130
 
20313 craig 3131
    % Add checksum digit
3132
    /pad 8 string def
3133
    /checksum 0 def
3134
 
3135
        /i exch def
3136
        /barchar barcode i get 48 sub def
3137
        i 2 mod 0 ne {
3138
            /checksum barchar checksum add def
3139
        } {
3140
            /checksum barchar 3 mul checksum add def
3141
        } ifelse
3142
    } for
3143
    /checksum 10 checksum 10 mod sub 10 mod def
3144
    barcode length 8 eq {
3145
        barcode 7 get checksum 48 add ne {
3146
            /bwipp.ean8badCheckDigit (Incorrect EAN-8 check digit provided) //raiseerror exec
3147
        } if
3148
    } if
3149
    pad 0 barcode putinterval      % Add barcode to the start of the pad
3150
    pad 7 checksum 48 add put      % Put ascii for checksum at end of pad
3151
    /barcode pad def
25039 craig 3152
 
20313 craig 3153
    % Create an array containing the character mappings
3154
    /encs
3155
    [ (3211) (2221) (2122) (1411) (1132)
3156
      (1231) (1114) (1312) (1213) (3112)
3157
      (111) (11111) (111)
3158
    ] def
4460 subik 3159
 
20313 craig 3160
    % Create a string of the available characters
3161
    /barchars (0123456789) def
4460 subik 3162
 
20313 craig 3163
    /sbs 43 string def
3164
    /txt 8 array def
25039 craig 3165
 
20313 craig 3166
    % Put the start character
3167
    sbs 0 encs 10 get putinterval
4460 subik 3168
 
20313 craig 3169
    % Left side
3170
 
3171
        % Lookup the encoding for the each barcode character
3172
        /i exch def
3173
        barcode i 1 getinterval barchars exch search
3174
        pop                                % Discard true leaving pre
3175
        length /indx exch def              % indx is the length of pre
3176
        pop pop                            % Discard seek and post
3177
        /enc encs indx get def             % Get the indxth encoding
3178
        sbs i 4 mul 3 add enc putinterval  % Put encoded digit into sbs
3179
        txt i [barcode i 1 getinterval i 7 mul textxoffset add textyoffset textfont textsize] put
3180
    } for
4460 subik 3181
 
20313 craig 3182
    % Put the middle character
3183
    sbs 4 4 mul 3 add encs 11 get putinterval
4460 subik 3184
 
20313 craig 3185
    % Right side
3186
    4 1 7 {
3187
        % Lookup the encoding for the each barcode character
3188
        /i exch def
3189
        barcode i 1 getinterval barchars exch search
3190
        pop                                % Discard true leaving pre
3191
        length /indx exch def              % indx is the length of pre
3192
        pop pop                            % Discard seek and post
3193
        /enc encs indx get def             % Get the indxth encoding
3194
        sbs i 4 mul 8 add enc putinterval  % Put encoded digit into sbs
3195
        txt i [barcode i 1 getinterval i 7 mul textxoffset add 4 add textyoffset textfont textsize] put
3196
    } for
4460 subik 3197
 
20313 craig 3198
    % Put the end character
3199
    sbs 40 encs 12 get putinterval
4460 subik 3200
 
20313 craig 3201
    /sbs [sbs {48 sub} forall] def
3202
    includetext {
3203
        /bhs [height height 8{height .075 sub}repeat height height 8{height .075 sub}repeat height height] def
3204
        /bbs [0 0 8{.075}repeat 0 0 8{.075}repeat 0 0] def
3205
    } {
3206
        /bhs [22{height}repeat] def
3207
        /bbs [22{0}repeat] def
3208
        /txt [] def
3209
    } ifelse
3210
    /guardrightypos 0 def
4460 subik 3211
 
20313 craig 3212
    % Append the addon
3213
    addon () ne {
3214
        /addopts <<
3215
            /dontdraw true
3216
            /includetext true
3217
            /height height 0.15 sub
3218
            /textxoffset addontextxoffset (unset) ne {addontextxoffset} {67 addongap add} ifelse
3219
            addontextyoffset (unset) ne {/textyoffset addontextyoffset} if
3220
            /textsize addontextsize (unset) ne {addontextsize} {textsize} ifelse
3221
            /textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse
3222
        >> def
3223
        addon length 2 eq {addon addopts //ean2 exec} if
3224
        addon length 5 eq {addon addopts //ean5 exec} if
3225
        /addcode exch def
3226
        /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
3227
        /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
3228
        /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
3229
        /txt [txt aload pop addcode (txt) get aload pop] def
3230
        /guardrightypos height 72 mul 6 sub def
25039 craig 3231
    } if
13293 subik 3232
 
20313 craig 3233
    % Return the arguments
3234
    <<
3235
    /ren //renlinear
3236
    /sbs sbs
3237
    /bhs bhs
3238
    /bbs bbs
3239
    /txt txt
3240
    /opt options
3241
    /guardleftpos 10
3242
    /guardrightpos 10
3243
    /guardrightypos guardrightypos
3244
    /borderbottom 5
3245
    >>
13293 subik 3246
 
20313 craig 3247
    dontdraw not //renlinear if
13293 subik 3248
 
20313 craig 3249
    end
4460 subik 3250
 
25039 craig 3251
}
3252
[/barcode] {null def} forall
3253
bind def
16255 fschmid 3254
/ean8 dup load /uk.co.terryburton.bwipp defineresource pop
3255
end
3256
/setpacking where {pop setpacking} if
18800 fschmid 3257
%%EndData
3258
%%EndResource
4460 subik 3259
% --END ENCODER ean8--
3260
 
3261
% --BEGIN ENCODER upca--
18800 fschmid 3262
% --REQUIRES preamble raiseerror renlinear ean5 ean2--
7162 subik 3263
% --DESC: UPC-A
18800 fschmid 3264
% --EXAM: 416000336108
11277 subik 3265
% --EXOP: includetext
3266
% --RNDR: renlinear
25039 craig 3267
%%BeginResource: uk.co.terryburton.bwipp upca 0.0 2021092800 82465 85414
3268
%%BeginData:        250 ASCII Lines
16255 fschmid 3269
/setpacking where {pop currentpacking true setpacking} if
3270
1 dict
18800 fschmid 3271
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16255 fschmid 3272
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
3273
dup /ean2 dup /uk.co.terryburton.bwipp findresource put
3274
dup /ean5 dup /uk.co.terryburton.bwipp findresource put
3275
begin
4460 subik 3276
/upca {
3277
 
20313 craig 3278
    20 dict begin
4460 subik 3279
 
20313 craig 3280
    /options exch def
3281
    /barcode exch def             % We are given a barcode string
4460 subik 3282
 
20313 craig 3283
    /dontdraw false def
3284
    /includetext false def         % Enable/disable text
3285
    /textfont /Helvetica def
3286
    /textsize 12 def
3287
    /textxoffset -7 def
3288
    /textyoffset -4 def
25039 craig 3289
    /height 1 def
20313 craig 3290
    /addongap 12 def
3291
    /addontextfont (unset) def
3292
    /addontextsize (unset) def
3293
    /addontextxoffset (unset) def
3294
    /addontextyoffset (unset) def
13293 subik 3295
 
20313 craig 3296
    % Parse the input options
3297
    options type /stringtype eq {
3298
        1 dict begin
3299
        options {
3300
            token false eq {exit} if dup length string cvs (=) search
3301
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
3302
        } loop
3303
        currentdict end /options exch def
3304
    } if
25039 craig 3305
    options {def} forall
13293 subik 3306
 
20313 craig 3307
    /textfont textfont cvlit def
3308
    /textsize textsize cvr def
3309
    /textxoffset textxoffset cvr def
3310
    /textyoffset textyoffset cvr def
3311
    /height height cvr def
3312
    /addongap addongap cvr def
3313
    addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if
3314
    addontextsize (unset) ne {/addontextsize addontextsize cvr def} if
3315
    addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if
3316
    addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if
18224 jghali 3317
 
20313 craig 3318
    % Split off the addon
3319
    barcode ( ) search {
3320
        /barcode exch def
3321
        pop
3322
        /addon exch def
3323
    } {
3324
        pop
3325
        /addon () def
3326
    } ifelse
18800 fschmid 3327
 
20313 craig 3328
    % Expand a given UPC-E
3329
    barcode length 7 eq barcode length 8 eq or {
3330
        % Validate the input
3331
        barcode {
3332
            dup 48 lt exch 57 gt or {
3333
                /bwipp.upcAupcEbadCharacter (UPC-E must contain only digits) //raiseerror exec
3334
            } if
3335
        } forall
3336
        barcode 0 get dup 48 ne exch 49 ne and {
3337
            /bwipp.upcAupcEbadNumberSystem (UPC-E must have number system 0 or 1) //raiseerror exec
3338
        } if
3339
        1 {  % Common exit
3340
            /upcacode barcode length 8 eq {12} {11} ifelse string def
3341
            barcode 6 get 48 sub 2 le {
3342
                upcacode 0 barcode 0 3 getinterval putinterval
3343
                upcacode 3 barcode 6 1 getinterval putinterval
3344
                upcacode 4 (0000) putinterval
3345
                upcacode 8 barcode 3 3 getinterval putinterval
3346
                exit
3347
            } if
3348
            barcode 6 get 48 sub 3 eq {
3349
                upcacode 0 barcode 0 4 getinterval putinterval
3350
                upcacode 4 (00000) putinterval
3351
                upcacode 9 barcode 4 2 getinterval putinterval
3352
                exit
3353
            } if
3354
            barcode 6 get 48 sub 4 eq {
3355
                upcacode 0 barcode 0 5 getinterval putinterval
3356
                upcacode 5 (00000) putinterval
3357
                upcacode 10 barcode 5 1 getinterval putinterval
3358
                exit
3359
            } if
3360
            barcode 6 get 48 sub 5 ge {
3361
                upcacode 0 barcode 0 6 getinterval putinterval
3362
                upcacode 6 (0000) putinterval
3363
                upcacode 10 barcode 6 1 getinterval putinterval
3364
                exit
3365
            } if
3366
        } repeat
3367
        barcode length 8 eq {
3368
            upcacode 11 barcode 7 1 getinterval putinterval
3369
        } if
3370
        /barcode upcacode def
3371
    } if
19685 fschmid 3372
 
20313 craig 3373
    % Validate the input
3374
    barcode length 11 ne barcode length 12 ne and {
3375
        /bwipp.upcAbadLength (UPC-A must be 11 or 12 digits) //raiseerror exec
3376
    } if
3377
    barcode {
3378
        dup 48 lt exch 57 gt or {
3379
            /bwipp.upcAbadCharacter (UPC-A must contain only digits) //raiseerror exec
3380
        } if
3381
    } forall
3382
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
3383
        /bwipp.upcAbadAddOnLength (Add-on for UPC-A must be 2 or 5 digits) //raiseerror exec
3384
    } if
25039 craig 3385
 
20313 craig 3386
    % Add checksum digit to barcode
3387
    /pad 12 string def   % Create pad one bigger than barcode
3388
    /checksum 0 def
3389
 
3390
        /i exch def
3391
        /barchar barcode i get 48 sub def
3392
        i 2 mod 0 ne {
3393
            /checksum checksum barchar add def
3394
        } {
3395
            /checksum checksum barchar 3 mul add def
3396
        } ifelse
3397
    } for
3398
    /checksum 10 checksum 10 mod sub 10 mod def
3399
    barcode length 12 eq {
3400
        barcode 11 get checksum 48 add ne {
3401
            /bwipp.upcAbadCheckDigit (Incorrect UPC check digit provided) //raiseerror exec
3402
        } if
3403
    } if
3404
    pad 0 barcode putinterval       % Add barcode to the start of the pad
3405
    pad 11 checksum 48 add put      % Put ascii for checksum at end of pad
3406
    /barcode pad def
4460 subik 3407
 
20313 craig 3408
    % Create an array containing the character mappings
3409
    /encs
3410
    [ (3211) (2221) (2122) (1411) (1132)
3411
      (1231) (1114) (1312) (1213) (3112)
3412
      (111) (11111) (111)
3413
    ] def
4460 subik 3414
 
20313 craig 3415
    % Create a string of the available characters
3416
    /barchars (0123456789) def
4460 subik 3417
 
20313 craig 3418
    /sbs 59 string def
3419
    /txt 12 array def
4460 subik 3420
 
20313 craig 3421
    % Put the start character
3422
    sbs 0 encs 10 get putinterval
4460 subik 3423
 
20313 craig 3424
    % Left side
3425
 
3426
        % Lookup the encoding for the each barcode character
3427
        /i exch def
3428
        barcode i 1 getinterval barchars exch search
3429
        pop                                % Discard true leaving pre
3430
        length /indx exch def              % indx is the length of pre
3431
        pop pop                            % Discard seek and post
3432
        /enc encs indx get def             % Get the indxth encoding
3433
        sbs i 4 mul 3 add enc putinterval  % Put encoded digit into sbs
3434
        i 0 eq {      % First digit is before the guard bars
3435
            txt 0 [barcode 0 1 getinterval textxoffset textyoffset textfont textsize 2 sub] put
3436
        } {
3437
            txt i [barcode i 1 getinterval i 7 mul 11 add textxoffset add textyoffset textfont textsize] put
3438
        } ifelse
3439
    } for
4460 subik 3440
 
20313 craig 3441
    % Put the middle character
3442
    sbs 6 4 mul 3 add encs 11 get putinterval
4460 subik 3443
 
20313 craig 3444
    % Right side
3445
    6 1 11 {
3446
        % Lookup the encoding for the each barcode character
3447
        /i exch def
3448
        barcode i 1 getinterval barchars exch search
3449
        pop                                % Discard true leaving pre
3450
        length /indx exch def              % indx is the length of pre
3451
        pop pop                            % Discard seek and post
3452
        /enc encs indx get def             % Get the indxth encoding
3453
        sbs i 4 mul 8 add enc putinterval  % Put encoded digit into sbs
3454
        i 11 eq {       % Last digit is after guard bars
3455
            txt 11 [barcode 11 1 getinterval textxoffset 103 add textyoffset textfont textsize 2 sub] put
3456
        } {
3457
            txt i [barcode i 1 getinterval i 7 mul textxoffset add 15 add textyoffset textfont textsize] put
3458
        } ifelse
3459
    } for
4460 subik 3460
 
20313 craig 3461
    % Put the end character
3462
    sbs 56 encs 12 get putinterval
4460 subik 3463
 
20313 craig 3464
    /sbs [sbs {48 sub} forall] def
3465
    includetext {
3466
        /bhs [4{height}repeat 10{height .075 sub}repeat height height 10{height .075 sub}repeat 4{height}repeat] def
3467
        /bbs [0 0 0 0 10{.075}repeat 0 0 10{.075}repeat 0 0 0 0] def
3468
    } {
3469
        /bhs [30{height}repeat] def
3470
        /bbs [30{0}repeat] def
3471
        /txt [] def
3472
    } ifelse
3473
    /guardrightypos 0 def
4460 subik 3474
 
20313 craig 3475
    % Append the addon
3476
    addon () ne {
3477
        /addopts <<
3478
            /dontdraw true
3479
            /includetext true
3480
            /height height 0.15 sub
3481
            /textxoffset addontextxoffset (unset) ne {addontextxoffset} {95 addongap add} ifelse
3482
            addontextyoffset (unset) ne {/textyoffset addontextyoffset} if
3483
            /textsize addontextsize (unset) ne {addontextsize} {textsize} ifelse
3484
            /textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse
3485
        >> def
3486
        addon length 2 eq {addon addopts //ean2 exec} if
3487
        addon length 5 eq {addon addopts //ean5 exec} if
3488
        /addcode exch def
3489
        /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
3490
        /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
3491
        /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
3492
        /txt [txt aload pop addcode (txt) get aload pop] def
3493
        /guardrightypos height 72 mul 6 sub def
25039 craig 3494
    } if
13293 subik 3495
 
20313 craig 3496
    % Return the arguments
3497
    <<
3498
    /ren //renlinear
3499
    /sbs sbs
3500
    /bhs bhs
3501
    /bbs bbs
3502
    /txt txt
3503
    /opt options
3504
    /guardrightpos 10
3505
    /guardrightypos guardrightypos
3506
    /borderbottom 5
3507
    >>
13293 subik 3508
 
20313 craig 3509
    dontdraw not //renlinear if
13293 subik 3510
 
20313 craig 3511
    end
4460 subik 3512
 
25039 craig 3513
}
3514
[/barcode] {null def} forall
3515
bind def
16255 fschmid 3516
/upca dup load /uk.co.terryburton.bwipp defineresource pop
3517
end
3518
/setpacking where {pop setpacking} if
18800 fschmid 3519
%%EndData
3520
%%EndResource
4460 subik 3521
% --END ENCODER upca--
3522
 
3523
% --BEGIN ENCODER upce--
18800 fschmid 3524
% --REQUIRES preamble raiseerror renlinear ean5 ean2--
7162 subik 3525
% --DESC: UPC-E
18224 jghali 3526
% --EXAM: 00123457
18800 fschmid 3527
% --EXOP: includetext
11277 subik 3528
% --RNDR: renlinear
25039 craig 3529
%%BeginResource: uk.co.terryburton.bwipp upce 0.0 2021092800 87070 90062
3530
%%BeginData:        289 ASCII Lines
16255 fschmid 3531
/setpacking where {pop currentpacking true setpacking} if
3532
1 dict
18800 fschmid 3533
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16255 fschmid 3534
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
3535
dup /ean2 dup /uk.co.terryburton.bwipp findresource put
3536
dup /ean5 dup /uk.co.terryburton.bwipp findresource put
3537
begin
4460 subik 3538
/upce {
3539
 
20313 craig 3540
    20 dict begin
4460 subik 3541
 
20313 craig 3542
    /options exch def                   % We are given an option string
3543
    /barcode exch def                   % We are given a barcode string
4460 subik 3544
 
20313 craig 3545
    /dontdraw false def
3546
    /includetext false def               % Enable/disable text
3547
    /textfont /Helvetica def
3548
    /textsize 12 def
3549
    /textxoffset -7 def
3550
    /textyoffset -4 def
3551
    /height 1 def
3552
    /addongap 12 def
3553
    /addontextfont (unset) def
3554
    /addontextsize (unset) def
3555
    /addontextxoffset (unset) def
3556
    /addontextyoffset (unset) def
25039 craig 3557
 
20313 craig 3558
    % Parse the input options
3559
    options type /stringtype eq {
3560
        1 dict begin
3561
        options {
3562
            token false eq {exit} if dup length string cvs (=) search
3563
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
3564
        } loop
3565
        currentdict end /options exch def
3566
    } if
3567
    options {def} forall
25039 craig 3568
 
20313 craig 3569
    /textfont textfont cvlit def
3570
    /textsize textsize cvr def
3571
    /textxoffset textxoffset cvr def
3572
    /textyoffset textyoffset cvr def
3573
    /height height cvr def
3574
    /addongap addongap cvr def
3575
    addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if
3576
    addontextsize (unset) ne {/addontextsize addontextsize cvr def} if
3577
    addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if
3578
    addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if
4460 subik 3579
 
20313 craig 3580
    % Split off the addon
3581
    barcode ( ) search {
3582
        /barcode exch def
3583
        pop
3584
        /addon exch def
3585
    } {
3586
        pop
3587
        /addon () def
3588
    } ifelse
13293 subik 3589
 
20313 craig 3590
    % Compress a given UPC-A
3591
    barcode length 11 eq barcode length 12 eq or {
3592
        % Validate the input
3593
        barcode {
3594
            dup 48 lt exch 57 gt or {
3595
                /bwipp.upcEupcAbadCharacter (UPC-A must contain only digits) //raiseerror exec
3596
            } if
3597
        } forall
3598
        1 {  % Common exit
3599
            /upcecode barcode length 12 eq {8} {7} ifelse string def
3600
            barcode 3 get 48 sub 2 le barcode 4 4 getinterval (0000) eq and {
3601
                upcecode 0 barcode  0 3 getinterval putinterval
3602
                upcecode 3 barcode  8 3 getinterval putinterval
3603
                upcecode 6 barcode  3 1 getinterval putinterval
3604
                exit
3605
            } if
3606
            barcode 4 5 getinterval (00000) eq {
3607
                upcecode 0 barcode  0 4 getinterval putinterval
3608
                upcecode 4 barcode  9 2 getinterval putinterval
3609
                upcecode 6 (3) putinterval
3610
                exit
3611
            } if
3612
            barcode 5 5 getinterval (00000) eq {
3613
                upcecode 0 barcode  0 5 getinterval putinterval
3614
                upcecode 5 barcode 10 1 getinterval putinterval
3615
                upcecode 6 (4) putinterval
3616
                exit
3617
            } if
3618
            barcode 10 get 48 sub 5 ge barcode 6 4 getinterval (0000) eq and {
3619
                upcecode 0 barcode  0 6 getinterval putinterval
3620
                upcecode 6 barcode 10 1 getinterval putinterval
3621
                exit
3622
            } if
3623
            /bwipp.upcEupcAnotCompressible (UPC-A cannot be converted to a UPC-E) //raiseerror exec
3624
        } repeat
3625
        barcode length 12 eq {
3626
            upcecode 7 barcode 11 1 getinterval putinterval
3627
        } if
3628
        /barcode upcecode def
3629
    } if
19685 fschmid 3630
 
20313 craig 3631
    % Validate the input
3632
    barcode length 7 ne barcode length 8 ne and {
3633
        /bwipp.upcEbadLength (UPC-E must be 7 or 8 digits) //raiseerror exec
3634
    } if
3635
    barcode {
3636
        dup 48 lt exch 57 gt or {
3637
            /bwipp.upcEbadCharacter (UPC-E must contain only digits) //raiseerror exec
3638
        } if
3639
    } forall
3640
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
3641
        /bwipp.upcEbadAddOnLength (Add-on for UPC-E must be 2 or 5 digits) //raiseerror exec
3642
    } if
18800 fschmid 3643
 
20313 craig 3644
    % Ensure 0 or 1 number systems
3645
    barcode 0 get dup 48 ne exch 49 ne and {
3646
        /bwipp.upcEbadNumberSystem (UPC-E must have number system 0 or 1) //raiseerror exec
3647
    } if
18800 fschmid 3648
 
20313 craig 3649
    % Create an array containing the character mappings
3650
    /encs
3651
    [ (3211) (2221) (2122) (1411) (1132)
3652
      (1231) (1114) (1312) (1213) (3112)
3653
      (111) (111111)
3654
    ] def
4460 subik 3655
 
20313 craig 3656
    % Create a string of the available characters
3657
    /barchars (0123456789) def
4460 subik 3658
 
20313 craig 3659
    /mirrormaps
3660
    [ (000111) (001011) (001101) (001110) (010011)
3661
      (011001) (011100) (010101) (010110) (011010)
3662
    ] def
4460 subik 3663
 
20313 craig 3664
    % Derive the equivalent UPC-A for its checksum
3665
    1 {  % Common exit
3666
        /upcacode 11 string def
3667
        barcode 6 get 48 sub 2 le {
3668
            upcacode 0 barcode 0 3 getinterval putinterval
3669
            upcacode 3 barcode 6 1 getinterval putinterval
3670
            upcacode 4 (0000) putinterval
3671
            upcacode 8 barcode 3 3 getinterval putinterval
3672
            exit
3673
        } if
3674
        barcode 6 get 48 sub 3 eq {
3675
            upcacode 0 barcode 0 4 getinterval putinterval
3676
            upcacode 4 (00000) putinterval
3677
            upcacode 9 barcode 4 2 getinterval putinterval
3678
            exit
3679
        } if
3680
        barcode 6 get 48 sub 4 eq {
3681
            upcacode 0 barcode 0 5 getinterval putinterval
3682
            upcacode 5 (00000) putinterval
3683
            upcacode 10 barcode 5 1 getinterval putinterval
3684
            exit
3685
        } if
3686
        barcode 6 get 48 sub 5 ge {
3687
            upcacode 0 barcode 0 6 getinterval putinterval
3688
            upcacode 6 (0000) putinterval
3689
            upcacode 10 barcode 6 1 getinterval putinterval
3690
            exit
3691
        } if
3692
    } repeat
3693
    /checksum 0 def
3694
 
3695
       /i exch def
3696
       /barchar upcacode i get 48 sub def
3697
       i 2 mod 0 ne {
3698
           /checksum checksum barchar add def
3699
       } {
3700
           /checksum checksum barchar 3 mul add def
3701
       } ifelse
3702
    } for
3703
    /checksum 10 checksum 10 mod sub 10 mod def
3704
    barcode length 8 eq {
3705
        barcode 7 get checksum 48 add ne {
3706
            /bwipp.upcEbadCheckDigit (Incorrect UPC check digit provided) //raiseerror exec
3707
        } if
3708
    } if
3709
    /pad 8 string def
3710
    pad 0 barcode putinterval       % Add barcode to the start of the pad
3711
    pad 7 checksum 48 add put       % Put ascii for checksum at end of pad
3712
    /barcode pad def
3713
    /txt 8 array def
3714
    txt 0 [barcode 0 1 getinterval textxoffset textyoffset textfont textsize 2 sub] put
4460 subik 3715
 
20313 craig 3716
    % Determine the mirror map based on checksum
3717
    /mirrormap mirrormaps checksum get def
4460 subik 3718
 
20313 craig 3719
    % Invert the mirrormap if we are using a non-zero number system
3720
    barcode 0 get 48 eq {
3721
        /invt mirrormap length string def
3722
 
3723
            /i exch def
3724
            mirrormap i get 48 eq {
3725
                invt i 49 put
3726
            } {
3727
                invt i 48 put
3728
            } ifelse
3729
        } for
3730
        /mirrormap invt def
3731
    } if
4460 subik 3732
 
20313 craig 3733
    /sbs 33 string def
4460 subik 3734
 
20313 craig 3735
    % Put the start character
3736
    sbs 0 encs 10 get putinterval
4460 subik 3737
 
20313 craig 3738
    1 1 6 {
3739
        /i exch def
3740
        % Lookup the encoding for the each barcode character
3741
        barcode i 1 getinterval barchars exch search
3742
        pop                            % Discard true leaving pre
3743
        length /indx exch def          % indx is the length of pre
3744
        pop pop                        % Discard seek and post
3745
        /enc encs indx get def         % Get the indxth encoding
25039 craig 3746
        mirrormap i 1 sub get 49 eq {  % Reverse enc if 1 in this position in mirrormap
20313 craig 3747
            /enclen enc length def
3748
            /revenc enclen string def
3749
 
3750
                /j exch def
3751
                /char enc j get def
3752
                revenc enclen j sub 1 sub char put
3753
            } for
3754
            /enc revenc def
3755
        } if
3756
        sbs i 1 sub 4 mul 3 add enc putinterval   % Put encoded digit into sbs
3757
        txt i [barcode i 1 getinterval i 1 sub 7 mul 11 add textxoffset add textyoffset textfont textsize] put
3758
    } for
4460 subik 3759
 
20313 craig 3760
    txt 7 [barcode 7 1 getinterval 6 7 mul 18 add textxoffset add textyoffset textfont textsize 2 sub] put
4460 subik 3761
 
20313 craig 3762
    % Put the end character
3763
    sbs 27 encs 11 get putinterval
4460 subik 3764
 
20313 craig 3765
    /sbs [sbs {48 sub} forall] def
3766
    includetext {
3767
        /bhs [height height 12{height .075 sub}repeat height height height] def
3768
        /bbs [0 0 12{.075}repeat 0 0 0] def
3769
    } {
3770
        /bhs [17{height}repeat] def
3771
        /bbs [17{0}repeat] def
3772
        /txt [] def
3773
    } ifelse
3774
    /guardrightypos 0 def
4460 subik 3775
 
20313 craig 3776
    % Append the addon
3777
    addon () ne {
3778
        /addopts <<
3779
            /dontdraw true
3780
            /includetext true
3781
            /height height 0.15 sub
3782
            /textxoffset addontextxoffset (unset) ne {addontextxoffset} {51 addongap add} ifelse
3783
            addontextyoffset (unset) ne {/textyoffset addontextyoffset} if
3784
            /textsize addontextsize (unset) ne {addontextsize} {textsize} ifelse
3785
            /textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse
3786
        >> def
3787
        addon length 2 eq {addon addopts //ean2 exec} if
3788
        addon length 5 eq {addon addopts //ean5 exec} if
3789
        /addcode exch def
3790
        /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
3791
        /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
3792
        /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
3793
        /txt [txt aload pop addcode (txt) get aload pop] def
3794
        /guardrightypos height 72 mul 6 sub def
3795
    } if
4460 subik 3796
 
20313 craig 3797
    % Return the arguments
3798
    <<
3799
    /ren //renlinear
3800
    /sbs sbs
3801
    /bhs bhs
3802
    /bbs bbs
3803
    /txt txt
3804
    /opt options
3805
    /guardrightpos 10
3806
    /guardrightypos guardrightypos
3807
    /borderbottom 5
3808
    >>
4460 subik 3809
 
20313 craig 3810
    dontdraw not //renlinear if
4460 subik 3811
 
20313 craig 3812
    end
4460 subik 3813
 
25039 craig 3814
}
3815
[/barcode] {null def} forall
3816
bind def
16255 fschmid 3817
/upce dup load /uk.co.terryburton.bwipp defineresource pop
3818
end
3819
/setpacking where {pop setpacking} if
18800 fschmid 3820
%%EndData
3821
%%EndResource
13293 subik 3822
% --END ENCODER upce--
4460 subik 3823
 
3824
% --BEGIN ENCODER isbn--
18800 fschmid 3825
% --REQUIRES preamble raiseerror renlinear ean5 ean2 ean13--
7162 subik 3826
% --DESC: ISBN
25039 craig 3827
% --EXAM: 978-1-56581-231-4 90000
11277 subik 3828
% --EXOP: includetext guardwhitespace
3829
% --RNDR: renlinear
25039 craig 3830
%%BeginResource: uk.co.terryburton.bwipp isbn 0.0 2021092800 89478 88857
3831
%%BeginData:        254 ASCII Lines
16255 fschmid 3832
/setpacking where {pop currentpacking true setpacking} if
3833
1 dict
18800 fschmid 3834
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16255 fschmid 3835
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
3836
dup /ean13 dup /uk.co.terryburton.bwipp findresource put
3837
begin
4460 subik 3838
/isbn {
3839
 
20313 craig 3840
    20 dict begin
4460 subik 3841
 
20313 craig 3842
    /options exch def      % We are given an options string
3843
    /barcode exch def      % We are given the isbn text with dashes
4460 subik 3844
 
20313 craig 3845
    /dontdraw false def
3846
    /includetext false def  % Enable/disable ISBN text
3847
    /isbntextfont /Courier def
3848
    /isbntextsize 9 def
3849
    /isbntextxoffset (unset) def
3850
    /isbntextyoffset (unset) def
3851
    /height 1 def
25039 craig 3852
    /addongap 12 def
20313 craig 3853
    /legacy false def
25039 craig 3854
 
20313 craig 3855
    % Parse the input options
3856
    options type /stringtype eq {
3857
        1 dict begin
3858
        options {
3859
            token false eq {exit} if dup length string cvs (=) search
3860
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
3861
        } loop
3862
        currentdict end /options exch def
3863
    } if
3864
    options {def} forall
25039 craig 3865
 
20313 craig 3866
    /isbntextfont isbntextfont cvlit def
3867
    /isbntextsize isbntextsize cvr def
3868
    isbntextxoffset (unset) ne {/isbntextxoffset isbntextxoffset cvr def} if
3869
    isbntextyoffset (unset) ne {/isbntextyoffset isbntextyoffset cvr def} if
3870
    /height height cvr def
3871
    /addongap addongap cvr def
16255 fschmid 3872
 
20313 craig 3873
    % Split off the addon
3874
    barcode ( ) search {
3875
        /barcode exch def
3876
        pop
3877
        /addon exch def
3878
    } {
3879
        pop
3880
        /addon () def
3881
    } ifelse
18800 fschmid 3882
 
20313 craig 3883
    % Validate the input
3884
    barcode length 15 ne barcode length 17 ne and
3885
    barcode length 11 ne barcode length 13 ne and and {
3886
        /bwipp.isbnBadLength (ISBN-13 must be 15 or 17 characters including dashes. ISBN-10 must be 11 or 13 characters including dashes) //raiseerror exec
3887
    } if
3888
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
3889
        /bwipp.isbnBadAddOnLength (Add-on for ISBN must be 2 or 5 digits) //raiseerror exec
3890
    } if
3891
    barcode length 15 ge {  % ISBN-13
3892
        barcode 0 4 getinterval dup (978-) ne exch (979-) ne and {
3893
            /bwipp.isbn13badPrefix (ISBN-13 prefix must be 978- or 979-) //raiseerror exec
3894
        } if
3895
        /wasdash false def /numdash 0 def /numdigit 0 def
3896
        barcode 5 9 getinterval {
3897
            dup
3898
            45 eq {
3899
                wasdash {
3900
                    /bwipp.isbn13adjacentDashes (ISBN-13 does not permit adjacent dashes) //raiseerror exec
3901
                } if
3902
                /wasdash true def
3903
                /numdash numdash 1 add def
3904
            } if
3905
            dup 48 ge exch 57 le and {
3906
                /wasdash false def
3907
                /numdigit numdigit 1 add def
3908
            } if
3909
        } forall
3910
        numdash 2 ne numdigit 7 ne or {
3911
            /bwipp.isbn13numDashesDigits (Incorrect number of dashes and digits for ISBN-13) //raiseerror exec
3912
        } if
3913
        barcode 14 get dup 48 lt exch 57 gt or {
3914
            /bwipp.isbn13character15 (ISBN-13 character 15 must be a digit) //raiseerror exec
3915
        } if
3916
        barcode length 17 eq {
3917
            barcode 15 1 getinterval (-) ne {
3918
                /bwipp.isbn13character16 (ISBN-13 penultimate character must be a dash) //raiseerror exec
3919
            } if
3920
            barcode 16 get dup 48 lt exch 57 gt or {
3921
                /bwipp.isbn13character17 (ISBN-13 final character must be a digit) //raiseerror exec
3922
            } if
3923
        } if
3924
    } {  % ISBN-10
3925
        barcode 0 get dup 48 lt exch 57 gt or {
3926
            /bwipp.isbn10FirstDigit (ISBN-10 first character must be a digit) //raiseerror exec
3927
        } if
3928
        /wasdash false def /numdash 0 def /numdigit 0 def
3929
        barcode 1 9 getinterval {
3930
            dup
3931
            45 eq {
3932
                wasdash {
3933
                    /bwipp.isbn10adjacentDashes (ISBN-10 does not permit adjacent dashes) //raiseerror exec
3934
                } if
3935
                /wasdash true def
3936
                /numdash numdash 1 add def
3937
            } if
3938
            dup 48 ge exch 57 le and {
3939
                /wasdash false def
3940
                /numdigit numdigit 1 add def
3941
            } if
3942
        } forall
3943
        numdash 2 ne numdigit 7 ne or {
3944
            /bwipp.isbn10numDashesDigits (Incorrect number of dashes and digits for ISBN-10) //raiseerror exec
3945
        } if
3946
        barcode 10 get dup 48 lt exch 57 gt or {
3947
            /bwipp.isbn10character11 (ISBN-10 character 11 must be a digit) //raiseerror exec
3948
        } if
3949
        barcode length 13 eq {
3950
            barcode 11 1 getinterval (-) ne {
3951
                /bwipp.isbn10character12 (ISBN-10 penultimate character must be a dash) //raiseerror exec
3952
            } if
3953
            barcode 12 get dup dup 48 lt exch 57 gt or exch 88 ne and {
3954
                /bwipp.isbn10character13 (ISBN-10 final character must be a digit or X) //raiseerror exec
3955
            } if
3956
        } if
3957
    } ifelse
16255 fschmid 3958
 
20313 craig 3959
    /isbntxt barcode def
19685 fschmid 3960
 
20313 craig 3961
    % Read the digits from isbntxt and validate checksum for ISBN-10
3962
    isbntxt length 13 le {
3963
        /isbn 10 string def
3964
        /checksum 0 def
3965
        /i 0 def /n 0 def
3966
        { % loop
3967
            /isbnchar isbntxt i get 48 sub def
3968
            isbnchar -3 ne {     % Ignore dashes
3969
                isbn n isbnchar 48 add put
3970
                n 9 lt {
3971
                    /checksum checksum 10 n sub isbnchar mul add def
3972
                } if
3973
                /n n 1 add def
3974
            } if
3975
            /i i 1 add def
3976
            i isbntxt length eq {exit} if
3977
        } loop
3978
        /checksum 11 checksum 11 mod sub 11 mod dup 10 eq {pop 40} if 48 add def
3979
        /isbn isbn 0 9 getinterval def
3980
        isbntxt length 13 eq {
3981
            isbntxt 12 get checksum ne {
3982
                /bwipp.isbn10badCheckDigit (Incorrect ISBN-10 check digit provided) //raiseerror exec
3983
            } if
3984
        } if
3985
    } if
4460 subik 3986
 
20313 craig 3987
    legacy not isbntxt length 15 ge or {
19685 fschmid 3988
 
20313 craig 3989
        % Convert ISBN-10 to ISBN-13
3990
        isbntxt length 13 le {
3991
            /pad 15 string def
3992
            pad 0 (978-) putinterval
3993
            pad 4 isbntxt 0 11 getinterval putinterval
3994
            /isbntxt pad def
3995
        } if
19685 fschmid 3996
 
20313 craig 3997
        % Read the digits from isbntxt and validate checksum for ISBN-13
3998
        /isbn 13 string def
3999
        /checksum 0 def
4000
        /i 0 def /n 0 def
4001
        { % loop
4002
            /isbnchar isbntxt i get 48 sub def
4003
            isbnchar -3 ne {     % Ignore dashes
4004
                isbn n isbnchar 48 add put
4005
                n 12 lt {
4006
                    /checksum isbnchar n 2 mod 0 ne {3 mul} if checksum add def
4007
                } if
4008
                /n n 1 add def
4009
            } if
4010
            /i i 1 add def
4011
            i isbntxt length eq {exit} if
4012
        } loop
4013
        /checksum 10 checksum 10 mod sub 10 mod 48 add def
4014
        /isbn isbn 0 12 getinterval def
4015
        isbntxt length 17 eq {
4016
            isbntxt 16 get checksum ne {
4017
                /bwipp.isbn13badCheckDigit (Incorrect ISBN-13 check digit provided) //raiseerror exec
4018
            } if
4019
        } if
19685 fschmid 4020
 
20313 craig 4021
    } if
19685 fschmid 4022
 
20313 craig 4023
    % Add the ISBN header to the isbntxt
4024
    /pad isbn length 12 eq {22} {18} ifelse string def
4025
    pad 0 (ISBN ) putinterval
4026
    pad 5 isbntxt putinterval
4027
    pad pad length 2 sub 45 put
4028
    pad pad length 1 sub checksum put
4029
    /isbntxt pad def
4460 subik 4030
 
20313 craig 4031
    % Convert ISBN digits to EAN-13
4032
    /barcode 12 string def
25039 craig 4033
    isbn length 9 eq {
20313 craig 4034
        barcode 0 (978) putinterval
4035
        barcode 3 isbn putinterval
4036
    } {
4037
        barcode 0 isbn putinterval
4038
    } ifelse
4460 subik 4039
 
20313 craig 4040
    % Append the addon
4041
    addon () ne {
25039 craig 4042
        12 addon length add 1 add string
20313 craig 4043
        dup 0 barcode putinterval
4044
        dup 12 ( ) putinterval
4045
        dup 13 addon putinterval
4046
        /barcode exch def
4047
    } if
4460 subik 4048
 
20313 craig 4049
    % Get the result of encoding with ean13
4050
    options (dontdraw) true put
25039 craig 4051
    options (addongap) addongap put
20313 craig 4052
    /args barcode options //ean13 exec def
13293 subik 4053
 
20313 craig 4054
    % Add the ISBN text
4055
    includetext {
4056
        isbntextxoffset (unset) eq {
4057
            /isbntextxoffset isbn length 9 eq {-1} {-12} ifelse def
4058
        } if
4059
        isbntextyoffset (unset) eq {
4060
            /isbntextyoffset height 72 mul 3 add def
4061
        } if
4062
        args (txt) known {
4063
            /txt args (txt) get def
4064
            /newtxt txt length 1 add array def
4065
            newtxt 0 txt putinterval
4066
            newtxt newtxt length 1 sub [isbntxt isbntextxoffset isbntextyoffset isbntextfont isbntextsize] put
4067
            args (txt) newtxt put
4068
        } {
4069
            args (txt) [ [isbntxt isbntextxoffset isbntextyoffset isbntextfont isbntextsize] ] put
4070
        } ifelse
4071
    } if
4460 subik 4072
 
20313 craig 4073
    args (opt) options put
4074
    args
4460 subik 4075
 
20313 craig 4076
    dontdraw not //renlinear if
13293 subik 4077
 
20313 craig 4078
    end
25039 craig 4079
 
4080
}
4081
[/barcode] {null def} forall
4082
bind def
16255 fschmid 4083
/isbn dup load /uk.co.terryburton.bwipp defineresource pop
4084
end
4085
/setpacking where {pop setpacking} if
18800 fschmid 4086
%%EndData
4087
%%EndResource
4460 subik 4088
% --END ENCODER isbn--
4089
 
16255 fschmid 4090
% --BEGIN ENCODER ismn--
18800 fschmid 4091
% --REQUIRES preamble raiseerror renlinear ean5 ean2 ean13--
16255 fschmid 4092
% --DESC: ISMN
18800 fschmid 4093
% --EXAM: 979-0-2605-3211-3
16255 fschmid 4094
% --EXOP: includetext guardwhitespace
4095
% --RNDR: renlinear
25039 craig 4096
%%BeginResource: uk.co.terryburton.bwipp ismn 0.0 2021092800 85922 85418
4097
%%BeginData:        233 ASCII Lines
16255 fschmid 4098
/setpacking where {pop currentpacking true setpacking} if
4099
1 dict
18800 fschmid 4100
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16255 fschmid 4101
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
4102
dup /ean13 dup /uk.co.terryburton.bwipp findresource put
4103
begin
4104
/ismn {
4105
 
20313 craig 4106
    20 dict begin
16255 fschmid 4107
 
20313 craig 4108
    /options exch def      % We are given an options string
4109
    /barcode exch def      % We are given the ismn text with dashes
16255 fschmid 4110
 
20313 craig 4111
    /dontdraw false def
4112
    /includetext false def  % Enable/disable ISMN text
4113
    /ismntextfont /Courier def
4114
    /ismntextsize 9 def
4115
    /ismntextxoffset (unset) def
4116
    /ismntextyoffset (unset) def
4117
    /height 1 def
25039 craig 4118
    /addongap 12 def
20313 craig 4119
    /legacy false def
16255 fschmid 4120
 
20313 craig 4121
    % Parse the input options
4122
    options type /stringtype eq {
4123
        1 dict begin
4124
        options {
4125
            token false eq {exit} if dup length string cvs (=) search
4126
            true eq {cvlit exch pop exch def} {cvlit true def} ifelse
4127
        } loop
4128
        currentdict end /options exch def
4129
    } if
4130
    options {def} forall
25039 craig 4131
 
20313 craig 4132
    /ismntextfont ismntextfont cvlit def
4133
    /ismntextsize ismntextsize cvr def
4134
    ismntextxoffset (unset) ne {/ismntextxoffset ismntextxoffset cvr def} if
4135
    ismntextyoffset (unset) ne {/ismntextyoffset ismntextyoffset cvr def} if
4136
    /height height cvr def
4137
    /addongap addongap cvr def
25039 craig 4138
 
20313 craig 4139
    % Split off the addon
4140
    barcode ( ) search {
4141
        /barcode exch def
4142
        pop
4143
        /addon exch def
4144
    } {
4145
        pop
4146
        /addon () def
4147
    } ifelse
16255 fschmid 4148
 
20313 craig 4149
    % Validate the input
4150
    barcode length 15 ne barcode length 17 ne and
4151
    barcode length 11 ne barcode length 13 ne and and {
4152
        /bwipp.ismnBadLength (ISMN-13 must be 15 or 17 characters including dashes. ISMN-10 must be 11 or 13 characters including dashes) //raiseerror exec
4153
    } if
4154
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
4155
        /bwipp.ismnBadAddOnLength (Add-on for ISMN must be 2 or 5 digits) //raiseerror exec
4156
    } if
4157
    barcode length 15 ge {  % ISMN-13
4158
        barcode 0 4 getinterval (979-) ne {
4159
            /bwipp.ismn13badPrefix (ISMN-13 prefix must be 979-) //raiseerror exec
4160
        } if
4161
        /wasdash false def /numdash 0 def /numdigit 0 def
4162
        barcode 5 9 getinterval {
4163
            dup
4164
            45 eq {
4165
                wasdash {
4166
                    /bwipp.ismn13adjacentDashes (ISMN-13 does not permit adjacent dashes) //raiseerror exec
4167
                } if
4168
                /wasdash true def
4169
                /numdash numdash 1 add def
4170
            } if
4171
            dup 48 ge exch 57 le and {
4172
                /wasdash false def
4173
                /numdigit numdigit 1 add def
4174
            } if
4175
        } forall
4176
        numdash 2 ne numdigit 7 ne or {
4177
            /bwipp.ismn13numDashesDigits (Incorrect number of dashes and digits for ISMN-13) //raiseerror exec
4178
        } if
4179
        barcode 14 get dup 48 lt exch 57 gt or {
4180
            /bwipp.ismn13character15 (ISMN-13 character 15 must be a digit) //raiseerror exec
4181
        } if
4182
        barcode length 17 eq {
4183
            barcode 15 1 getinterval (-) ne {
4184
                /bwipp.ismn13character16 (ISMN-13 penultimate character must be a dash) //raiseerror exec
4185
            } if
4186
            barcode 16 get dup 48 lt exch 57 gt or {
4187
                /bwipp.ismn13character17 (ISMN-13 final character must be a digit) //raiseerror exec
4188
            } if
4189
        } if
4190
    } {  % ISMN-10
4191
        barcode 0 2 getinterval (M-) ne {
4192
            /bwipp.ismn10badPrefix (ISMN-10 prefix must be M-) //raiseerror exec
4193
        } if
4194
        barcode 2 get dup 48 lt exch 57 gt or {
4195
            /bwipp.ismn10character3 (ISMN-10 character 3 must be a digit) //raiseerror exec
4196
        } if
4197
        /wasdash false def /numdash 0 def /numdigit 0 def
4198
        barcode 3 7 getinterval {
4199
            dup
4200
            45 eq {
4201
                wasdash {
4202
                    /bwipp.ismn10adjacentDashes (ISMN-10 does not permit adjacent dashes) //raiseerror exec
4203
                } if
4204
                /wasdash true def
4205
                /numdash numdash 1 add def
4206
            } if
4207
            dup 48 ge exch 57 le and {
4208
                /wasdash false def
4209
                /numdigit numdigit 1 add def
4210
            } if
4211
        } forall
4212
        numdash 1 ne numdigit 6 ne or {
4213
            /bwipp.ismn10numDashesDigits (Incorrect number of dashes and digits for ISMN-10) //raiseerror exec
4214
        } if
4215
        barcode 10 get dup 48 lt exch 57 gt or {
4216
            /bwipp.ismn10character11 (ISMN-10 character 11 must be a digit) //raiseerror exec
4217
        } if
4218
        barcode length 13 eq {
4219
            barcode 11 1 getinterval (-) ne {
4220
                /bwipp.ismn10character12 (ISMN-10 penultimate character must be a dash) //raiseerror exec
4221
            } if
4222
            barcode 12 get dup dup 48 lt exch 57 gt or exch 88 ne and {
4223
                /bwipp.ismn10character13 (ISMN-10 final character must be a digit or X) //raiseerror exec
4224
            } if
4225
        } if
4226
    } ifelse
19685 fschmid 4227
 
20313 craig 4228
    /ismntxt barcode def
19685 fschmid 4229
 
20313 craig 4230
    % Convert old ISMN to ISMN-13
4231
    /legacytxt () def
4232
    ismntxt length 13 le {
4233
        /legacytxt ismntxt def
4234
        /pad ismntxt length 4 add string def
4235
        pad 0 (979-0-) putinterval
4236
        pad 6 ismntxt 2 ismntxt length 2 sub getinterval putinterval
4237
        /ismntxt pad def
4238
    } if
16255 fschmid 4239
 
20313 craig 4240
    % Read the digits from ismntxt and calculate checksums
4241
    /ismn 13 string def
4242
    /checksum 0 def
4243
    /i 0 def /n 0 def
4244
    { % loop
4245
        /ismnchar ismntxt i get 48 sub def
4246
        ismnchar -3 ne {           % Ignore dashes
4247
            ismn n ismnchar 48 add put
4248
            n 12 lt {
4249
                n 2 mod 0 eq {
4250
                    /checksum ismnchar checksum add def
4251
                } {
4252
                    /checksum ismnchar 3 mul checksum add def
4253
                } ifelse
4254
            } if
4255
            /n n 1 add def
4256
        } if
4257
        /i i 1 add def
4258
        i ismntxt length eq {exit} if
4259
    } loop
4260
    /checksum 10 checksum 10 mod sub 10 mod 48 add def
16255 fschmid 4261
 
20313 craig 4262
    % Validate the checksum
4263
    barcode length 13 eq barcode length 17 eq or {
4264
        barcode dup length 1 sub get checksum ne {
4265
            /bwipp.ismnBadCheckDigit (Incorrect ISMN check digit provided) //raiseerror exec
4266
        } if
4267
    } if
19685 fschmid 4268
 
20313 craig 4269
    % Add the ISMN header and checksum to the ismntxt
4270
    legacy legacytxt () ne and {
4271
        /ismntxt legacytxt def
4272
        /pad 18 string def
4273
    } {
4274
        /pad 22 string def
4275
    } ifelse
4276
    pad 0 (ISMN ) putinterval
4277
    pad 5 ismntxt putinterval
4278
    pad pad length 2 sub 45 put
4279
    pad pad length 1 sub checksum put
4280
    /ismntxt pad def
16255 fschmid 4281
 
20313 craig 4282
    % Convert ISMN digits to EAN-13
25039 craig 4283
    /barcode ismn 0 12 getinterval def
16255 fschmid 4284
 
20313 craig 4285
    % Append the addon
4286
    addon () ne {
25039 craig 4287
        12 addon length add 1 add string
20313 craig 4288
        dup 0 barcode putinterval
4289
        dup 12 ( ) putinterval
4290
        dup 13 addon putinterval
4291
        /barcode exch def
4292
    } if
16255 fschmid 4293
 
20313 craig 4294
    % Get the result of encoding with ean13
4295
    options (dontdraw) true put
25039 craig 4296
    options (addongap) addongap put
20313 craig 4297
    /args barcode options //ean13 exec def
16255 fschmid 4298
 
20313 craig 4299
    % Add the ISMN text
4300
    includetext {
4301
        ismntextxoffset (unset) eq {
4302
            /ismntextxoffset ismntxt length 18 eq {-1} {-12} ifelse def
4303
        } if
4304
        ismntextyoffset (unset) eq {
4305
            /ismntextyoffset height 72 mul 3 add def
4306
        } if
4307
        args (txt) known {
4308
            /txt args (txt) get def
4309
            /newtxt txt length 1 add array def
4310
            newtxt 0 txt putinterval
4311
            newtxt newtxt length 1 sub [ismntxt ismntextxoffset ismntextyoffset ismntextfont ismntextsize] put
4312
            args (txt) newtxt put
4313
        } {
4314
            args (txt) [ [ismntxt ismntextxoffset ismntextyoffset ismntextfont ismntextsize] ] put
4315
        } ifelse
4316
    } if
16255 fschmid 4317
 
20313 craig 4318
    args (opt) options put
4319
    args
16255 fschmid 4320
 
20313 craig 4321
    dontdraw not //renlinear if
16255 fschmid 4322
 
20313 craig 4323
    end
25039 craig 4324
 
4325
}
4326
[/barcode] {null def} forall
4327
bind def
16255 fschmid 4328
/ismn dup load /uk.co.terryburton.bwipp defineresource pop
4329
end
4330
/setpacking where {pop setpacking} if
18800 fschmid 4331
%%EndData
4332
%%EndResource
16255 fschmid 4333
% --END ENCODER ismn--
4334
 
4335
% --BEGIN ENCODER issn--
18800 fschmid 4336
% --REQUIRES preamble raiseerror renlinear ean2 ean5 ean13--
16255 fschmid 4337
% --DESC: ISSN
19685 fschmid 4338
% --EXAM: 0311-175X 00 17
16255 fschmid 4339
% --EXOP: includetext guardwhitespace
4340
% --RNDR: renlinear
25039 craig 4341
%%BeginResource: uk.co.terryburton.bwipp issn 0.0 2021092800 77354 76846
4342
%%BeginData:        178 ASCII Lines
16255 fschmid 4343
/setpacking where {pop currentpacking true setpacking} if
4344
1 dict
18800 fschmid 4345
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
16255 fschmid 4346
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
4347
dup /ean13 dup /uk.co.terryburton.bwipp findresource put
4348
begin
4349
/issn {
4350
 
20313 craig 4351
    20 dict begin
16255 fschmid 4352
 
20313 craig 4353
    /options exch def      % We are given an options string
4354
    /issntxt exch def      % We are given the issn text with dashes
16255 fschmid 4355
 
20313 craig 4356
    /dontdraw false def
4357
    /includetext false def  % Enable/disable ISSN text
4358
    /issntextfont /Courier def
4359
    /issntextsize 9 def
4360
    /issntextxoffset (unset) def
4361
    /issntextyoffset (unset) def
4362
    /height 1 def