-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathdatabarexpanded.ps.src
902 lines (811 loc) · 28.9 KB
/
databarexpanded.ps.src
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
% Barcode Writer in Pure PostScript
% https://bwipp.terryburton.co.uk
%
% Copyright (c) 2004-2024 Terry Burton
%
% $Id$
%
% Permission is hereby granted, free of charge, to any
% person obtaining a copy of this software and associated
% documentation files (the "Software"), to deal in the
% Software without restriction, including without
% limitation the rights to use, copy, modify, merge,
% publish, distribute, sublicense, and/or sell copies of
% the Software, and to permit persons to whom the Software
% is furnished to do so, subject to the following
% conditions:
%
% The above copyright notice and this permission notice
% shall be included in all copies or substantial portions
% of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
% KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
% THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
% THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
% DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
% CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
% IN THE SOFTWARE.
% --BEGIN ENCODER databarexpanded--
% --REQUIRES preamble loadctx unloadctx raiseerror processoptions parseinput gs1process renlinear renmatrix--
% --DESC: GS1 DataBar Expanded
% --EXAM: (01)09521234543213(3103)000123
% --EXOP:
% --RNDR: renlinear renmatrix
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /loadctx dup /uk.co.terryburton.bwipp findresource put
dup /unloadctx dup /uk.co.terryburton.bwipp findresource put
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /processoptions dup /uk.co.terryburton.bwipp findresource put
dup /gs1process dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/databarexpanded {
20 dict begin % Confine variables to local scope
/ctx null def
/parse false def
/dontlint false def
/lintreqs true def
/dontdraw false def
/height 34.0 72 div def
/format (expanded) def
/segments -1 def
/linkage false def
/barxmult 34 def
//processoptions exec /options exch def
/barcode exch def
/databarexpanded //loadctx exec
barxmult 34 lt {
/bwipp.databarStackedOmniBarXmult (GS1 DataBar Expanded Stacked must have a barxmult of at least 34) //raiseerror exec
} if
format (expanded) ne format (expandedstacked) ne and {
/bwipp.databarexpandedBadFormat (Valid formats are expanded and expandedstacked) //raiseerror exec
} if
segments -1 eq {
/segments format (expandedstacked) eq {4} {22} ifelse def
} {
segments 2 lt segments 22 gt or segments 2 mod 0 ne or {
/bwipp.gs1databarexpandedBadSegments (The number of segments must be even from 2 to 22) //raiseerror exec
} if
} ifelse
barcode /ai //gs1process exec
/fncs exch def
/vals exch def
/ais exch def
% Method selection
{ % common exit
% (01)9...(3103)...
ais length 2 eq {
ais 0 get (01) eq ais 1 get (3103) eq and {
vals 0 get 0 1 getinterval (9) eq vals 1 get cvi 32767 le and {
(0100) false exit
} if
} if
} if
% (01)9...(3202)...
ais length 2 eq {
ais 0 get (01) eq ais 1 get (3202) eq and {
vals 0 get 0 1 getinterval (9) eq vals 1 get cvi 9999 le and {
(0101) false exit
} if
} if
} if
% (01)9...(3203)...
ais length 2 eq {
ais 0 get (01) eq ais 1 get (3203) eq and {
vals 0 get 0 1 getinterval (9) eq vals 1 get cvi 22767 le and {
(0101) false exit
} if
} if
} if
% (01)9...(310x/320x)...[(11/13/15/17)...]
ais length dup 2 eq exch 3 eq or {
/ai310x false 3100 1 3109 {10 4 string cvrs ais 1 get eq or} for def
/ai320x false 3200 1 3209 {10 4 string cvrs ais 1 get eq or} for def
ais length 3 eq {
/aibad true [ (11) (13) (15) (17) ] {ais 2 get ne and} forall def
} {
/aibad false def
} ifelse
ais 0 get (01) eq ai310x ai320x or and aibad not and {
ais length 3 eq {
vals 0 get 0 1 getinterval (9) eq
vals 1 get cvi 99999 le and
vals 2 get 2 2 getinterval cvi dup 1 ge exch 12 le and and % Month 1-12
vals 2 get 4 2 getinterval cvi dup 0 ge exch 31 le and and { % Day 0-31
ai310x ais 2 get (11) eq and { (0111000) false exit } if
ai320x ais 2 get (11) eq and { (0111001) false exit } if
ai310x ais 2 get (13) eq and { (0111010) false exit } if
ai320x ais 2 get (13) eq and { (0111011) false exit } if
ai310x ais 2 get (15) eq and { (0111100) false exit } if
ai320x ais 2 get (15) eq and { (0111101) false exit } if
ai310x ais 2 get (17) eq and { (0111110) false exit } if
ai320x ais 2 get (17) eq and { (0111111) false exit } if
} if
} {
vals 0 get 0 1 getinterval (9) eq
vals 1 get cvi 99999 le and {
ai310x { (0111000) false exit } if
ai320x { (0111001) false exit } if
} if
} ifelse
} if
} if
% (01)9...(392x)...
ais length 2 ge {
/ai392x false 3920 1 3923 {10 4 string cvrs ais 1 get eq or} for def
ais 0 get (01) eq ai392x and {
vals 0 get 0 1 getinterval (9) eq { (01100) true exit } if
} if
} if
% (01)9...(393x)...
ais length 2 ge {
/ai393x false 3930 1 3933 {10 4 string cvrs ais 1 get eq or} for def
ais 0 get (01) eq ai393x and {
vals 0 get 0 1 getinterval (9) eq { (01101) true exit } if
} if
} if
% (01)...
ais 0 get (01) eq { (1) true exit } if
% Freeform
(00) true exit
} loop
/gpfallow exch def
/method exch def
/conv12to40 {
(0000000000000000000000000000000000000000) 40 string copy
2 copy 0 10 getinterval exch 0 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval
2 copy 10 10 getinterval exch 3 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval
2 copy 20 10 getinterval exch 6 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval
2 copy 30 10 getinterval exch 9 3 getinterval cvi 2 10 string cvrs dup length 10 exch sub exch putinterval
exch pop
} def
/conv13to44 {
(00000000000000000000000000000000000000000000) 44 string copy
2 copy 0 4 getinterval exch 0 1 getinterval cvi 2 4 string cvrs dup length 4 exch sub exch putinterval
dup 3 -1 roll 1 12 getinterval conv12to40 4 exch putinterval
} def
/tobin {
string dup length 1 sub 0 exch 1 exch {1 index exch 48 put} for
dup 3 -1 roll 2 2 index length string cvrs dup length 2 index length exch sub exch putinterval
} def
/fnc1 -1 def /lnumeric -2 def /lalphanumeric -3 def /liso646 -4 def
method (00) eq {
/cdf [] def
/gpf [] def
} if
method (1) eq {
/cdf vals 0 get 0 13 getinterval conv13to44 def
/cdf [ cdf {48 sub} forall ] def
/gpf [] def
/ais ais 1 ais length 1 sub getinterval def
/vals vals 1 vals length 1 sub getinterval def
/fncs fncs 1 fncs length 1 sub getinterval def
} if
method (0100) eq {
/cdf 55 string def
cdf 0 vals 0 get 1 12 getinterval conv12to40 putinterval
cdf 40 vals 1 get cvi 15 tobin putinterval
/cdf [ cdf {48 sub} forall ] def
/gpf [] def
/ais [] def
/vals [] def
/fncs [] def
} if
method (0101) eq {
/cdf 55 string def
cdf 0 vals 0 get 1 12 getinterval conv12to40 putinterval
ais 1 get (3202) eq {
vals 1 get cvi 15 tobin
} {
vals 1 get cvi 10000 add 15 tobin
} ifelse
cdf exch 40 exch putinterval
/cdf [ cdf {48 sub} forall ] def
/gpf [] def
/ais [] def
/vals [] def
/fncs [] def
} if
method length 7 eq {
/cdf 76 string def
cdf 0 vals 0 get 1 12 getinterval conv12to40 putinterval
6 string dup 0 ais 1 get 3 1 getinterval putinterval
dup vals 1 get 1 5 getinterval 1 exch putinterval cvi 20 tobin
cdf exch 40 exch putinterval
ais length 3 eq {
vals 2 get
dup 0 2 getinterval cvi 384 mul exch
dup 2 2 getinterval cvi 1 sub 32 mul exch
4 2 getinterval cvi add add
} {
38400
} ifelse
16 tobin cdf exch 60 exch putinterval
/cdf [ cdf {48 sub} forall ] def
/gpf [] def
/ais [] def
/vals [] def
/fncs [] def
} if
method (01100) eq {
/cdf 42 string def
cdf 0 vals 0 get 1 12 getinterval conv12to40 putinterval
cdf 40 ais 1 get 3 1 getinterval cvi 2 tobin putinterval
/cdf [ cdf {48 sub} forall ] def
/gpf [ vals 1 get {} forall ais length 2 gt { fnc1 } if ] def
/ais ais 2 ais length 2 sub getinterval def
/vals vals 2 vals length 2 sub getinterval def
/fncs fncs 2 fncs length 2 sub getinterval def
} if
method (01101) eq {
/cdf 52 string def
cdf 0 vals 0 get 1 12 getinterval conv12to40 putinterval
cdf 40 ais 1 get 3 1 getinterval cvi 2 tobin putinterval
cdf 42 vals 1 get 0 3 getinterval cvi 10 tobin putinterval
/cdf [ cdf {48 sub} forall ] def
/gpf [ vals 1 get dup length 3 sub 3 exch getinterval {} forall ais length 2 gt { fnc1 } if ] def
/ais ais 2 ais length 2 sub getinterval def
/vals vals 2 vals length 2 sub getinterval def
/fncs fncs 2 fncs length 2 sub getinterval def
} if
% Variable length symbol field
gpfallow {
/vlf 2 array def
} {
/vlf [] def
} ifelse
{
/numeric <<
0 1 119 {
dup (00) 2 string copy dup 3 -1 roll 11 2 string cvrs
dup length 2 exch sub exch putinterval
dup 0 get 65 eq {dup 0 94 put} if
dup 1 get 65 eq {dup 1 94 put} if
exch 8 add
(0000000) 7 string copy dup 3 -1 roll 2 7 string cvrs
dup length 7 exch sub exch putinterval
} for
lalphanumeric (0000)
>> def
/alphanumeric <<
48 1 57 {dup 43 sub 5 tobin} for
fnc1 (01111)
65 1 90 {dup 33 sub 6 tobin} for
42 (111010)
44 1 47 {dup 15 add 6 tobin} for
lnumeric (000)
liso646 (00100)
>> def
/iso646 <<
48 1 57 {dup 43 sub 5 tobin} for
fnc1 (01111)
65 1 90 {dup 1 sub 7 tobin} for
97 1 122 {dup 7 sub 7 tobin} for
33 (11101000)
34 (11101001)
37 1 47 {dup 197 add 8 tobin} for
58 1 63 {dup 187 add 8 tobin} for
95 (11111011)
32 (11111100)
lnumeric (000)
lalphanumeric (00100)
>> def
} ctxdef
% Append the remaining AI data
0 1 ais length 1 sub {
/i exch def
/ai ais i get def
/val vals i get def
gpf length ai length add val length add array
dup 0 gpf putinterval
dup gpf length ai [ exch {} forall ] putinterval
dup gpf length ai length add val [ exch {} forall ] putinterval
/gpf exch def
i ais length 1 sub ne fncs i get and { % Append FNC1
gpf length 1 add array
dup 0 gpf putinterval
dup gpf length fnc1 put
/gpf exch def
} if
} for
% Calculate the number of bits remaining to the next valid symbol size
/rembits {
dup
12 div ceiling cvi 12 mul % Round up to multiple of 12
48 2 copy lt {exch} if pop % At least 4 symbols
dup 12 idiv dup segments mod 1 eq { % At least 2 symbols on last row of stacked symbol
1 add 12 mul exch pop
} {
pop
} ifelse
exch sub
} def
/encode {
dup /raw ne {exch get} {pop} ifelse
dup length j add 252 ge {
pop /bwipp.gs1databarexpandedTooLong (Maximum length exceeded) //raiseerror exec
} if
[ exch {48 sub} forall ]
dup length exch
gpfenc exch j exch putinterval
/j exch j add def
} def
% Pre-compute alphanumeric and numeric runlengths and position of next ISO646-only characters
/numericruns [ gpf length {0} repeat 0 -1 ] def
/alphanumericruns [ gpf length {0} repeat 0 ] def
/nextiso646only [ gpf length {0} repeat 9999 ] def
gpf length 1 sub -1 0 {
/i exch def
gpf i get
(00) 2 string copy
dup 0 gpf i get dup fnc1 eq {pop 94} if put
i gpf length 1 sub lt {dup 1 gpf i 1 add get dup fnc1 eq {pop 94} if put} if
numeric exch known {
numericruns i numericruns i 2 add get 2 add put
} {
numericruns i 0 put
} ifelse
dup alphanumeric exch known {
alphanumericruns i alphanumericruns i 1 add get 1 add put
} {
alphanumericruns i 0 put
} ifelse
dup iso646 exch known exch alphanumeric exch known not and {
nextiso646only i 0 put
} {
nextiso646only i nextiso646only i 1 add get 1 add put
} ifelse
} for
% Encode the general purpose field
/gpfenc 252 array def
/i 0 def /j 0 def /mode (numeric) def
{ % loop
i gpf length eq {exit} if
{ % not a loop but common exit point
mode (numeric) eq {
i gpf length 2 sub le {
2 string
dup 0 gpf i get dup fnc1 eq {pop 94} if put
dup 1 gpf i 1 add get dup fnc1 eq {pop 94} if put
dup numeric exch known {
numeric encode
/i i 2 add def
exit
} if
pop
lalphanumeric numeric encode
/mode (alphanumeric) def
exit
} {
gpf i get dup 48 lt exch 57 gt or {
lalphanumeric numeric encode
/mode (alphanumeric) def
exit
} if
/rem 12 1 add method length add vlf length add cdf length add j add rembits def
rem 4 ge rem 6 le and { % C1 + 1 into 4 to 6 bits
(000000) 6 string copy 0 rem getinterval
dup gpf i get 47 sub 2 4 string cvrs
dup length 4 exch sub exch putinterval /raw encode
/i i 1 add def
exit
} { % C1.FNC1
2 string dup 0 gpf i get put dup 1 94 put numeric encode
/i i 1 add def
exit
} ifelse
} ifelse
} if
mode (alphanumeric) eq {
gpf i get fnc1 eq {
fnc1 alphanumeric encode
/mode (numeric) def
/i i 1 add def
exit
} if
gpf i get dup iso646 exch known exch alphanumeric exch known not and {
liso646 alphanumeric encode
/mode (iso646) def
exit
} if
numericruns i get 6 ge {
lnumeric alphanumeric encode
/mode (numeric) def
exit
} if
numericruns i get dup 4 ge exch i add gpf length eq and {
lnumeric alphanumeric encode
/mode (numeric) def
exit
} if
gpf i get alphanumeric encode
/i i 1 add def
exit
} if
mode (iso646) eq {
gpf i get fnc1 eq {
fnc1 iso646 encode
/mode (numeric) def
/i i 1 add def
exit
} if
numericruns i get 4 ge nextiso646only i get 10 ge and {
lnumeric iso646 encode
/mode (numeric) def
exit
} if
alphanumericruns i get 5 ge nextiso646only i get 10 ge and {
lalphanumeric iso646 encode
/mode (alphanumeric) def
exit
} if
gpf i get iso646 encode
/i i 1 add def
exit
} if
} loop
} loop
/gpf gpfenc 0 j getinterval def
% Complete the variable length field and create pad
1 12 add method length add vlf length add cdf length add gpf length add
dup rembits dup array /pad exch def
vlf length 0 ne {
add 12 idiv
dup 2 mod vlf exch 0 exch put
14 le {0} {1} ifelse vlf exch 1 exch put
} {
pop pop
} ifelse
pad length 0 gt {
0 5 pad length 1 sub { % Fill with 00100
/i exch def
pad i [ 0 0 1 0 0 ] 0 pad length i sub 5 2 copy gt {exch} if pop getinterval putinterval
} for
mode (numeric) eq { % Prefix shift from numeric to ASCII
/pad [ 0 0 0 0 pad aload pop ] 0 pad length getinterval def
} if
} if
% Concatenate fields
/binval [
linkage {1} {0} ifelse
method {48 sub} forall
vlf aload pop
cdf aload pop
gpf aload pop
pad aload pop
] def
/datalen binval length 12 idiv def
/ncr { % n r
2 copy sub 2 copy lt {exch} if % n r maxd mind
1 1 5 3 roll % mind j=1 v=1 n maxd
1 add -1 exch { % mind j v n -1 maxd+1
mul % mind j v*i
1 index 3 index le {
1 index idiv exch 1 add exch
} if
} for
{ % mind j v
1 index 3 index gt {exit} if
1 index idiv exch 1 add exch
} loop
exch pop exch pop
} def
/getRSSwidths {
/oe exch def
/el exch def
/mw exch def
/nm exch def
/val exch def
/out el array def
/mask 0 def
0 1 el 2 sub {
/bar exch def
/ew 1 def
/mask mask 1 bar bitshift or def {
/sval nm ew sub 1 sub el bar sub 2 sub ncr def
oe mask 0 eq and nm ew sub el 2 mul sub bar 2 mul add -2 ge and {
/sval sval nm ew sub el sub bar add el bar sub 2 sub ncr sub def
} if
el bar sub 2 gt {
/lval 0 def
nm ew sub el sub bar add 2 add -1 mw 1 add {
nm exch sub ew sub 1 sub el bar sub 3 sub ncr
/lval exch lval add def
} for
/sval sval lval el bar sub 1 sub mul sub def
} {
nm ew sub mw gt {/sval sval 1 sub def} if
} ifelse
/val val sval sub def
val 0 lt {exit} if
/ew ew 1 add def
/mask mask 1 bar bitshift not and def
} loop
/val val sval add def
/nm nm ew sub def
out bar ew put
} for
out el 1 sub nm put
out
} def
{
/tab174 [
347 0 12 5 7 2 87 4
1387 348 10 7 5 4 52 20
2947 1388 8 9 4 5 30 52
3987 2948 6 11 3 6 10 104
4191 3988 4 13 1 8 1 204
] def
} ctxdef
/dxw datalen array def
0 1 datalen 1 sub {
/x exch def
/d binval x 12 mul 12 getinterval def
/d 0 0 1 11 {/j exch def 2 11 j sub exp cvi d j get mul add} for def
/j 0 def {
d tab174 j get le {
tab174 j 1 add 7 getinterval aload pop
/dte exch def /dto exch def
/dmwe exch def /dmwo exch def
/dele exch def /delo exch def
/dgs exch def
exit
} if
/j j 8 add def
} loop
/dwo d dgs sub dte idiv delo dmwo 4 true getRSSwidths def
/dwe d dgs sub dte mod dele dmwe 4 false getRSSwidths def
/dw 8 array def
x 2 mod 0 eq {
0 1 3 {
/j exch def
dw 7 j 2 mul sub dwo j get put
dw 6 j 2 mul sub dwe j get put
} for
} {
0 1 3 {
/j exch def
dw j 2 mul dwo j get put
dw j 2 mul 1 add dwe j get put
} for
} ifelse
dxw x dw put
} for
{
/finderwidths [
1 8 4 1 1 1 1 4 8 1
3 6 4 1 1 1 1 4 6 3
3 4 6 1 1 1 1 6 4 3
3 2 8 1 1 1 1 8 2 3
2 6 5 1 1 1 1 5 6 2
2 2 9 1 1 1 1 9 2 2
] def
/finderseq [
[0 1]
[0 3 2]
[0 5 2 7]
[0 9 2 7 4]
[0 9 2 7 6 11]
[0 9 2 7 8 11 10]
[0 1 2 3 4 5 6 7]
[0 1 2 3 4 5 6 9 8]
[0 1 2 3 4 5 6 9 10 11]
[0 1 2 3 4 7 6 9 8 11 10]
] def
} ctxdef
/seq finderseq datalen 2 sub 2 idiv get def
/fxw seq length array def
0 1 seq length 1 sub {
/x exch def
fxw x finderwidths seq x get 5 mul 5 getinterval put
} for
{
/checkweights [
-1 -1 -1 -1 -1 -1 -1 -1 % A1L
77 96 32 81 27 9 3 1 % A1R
20 60 180 118 143 7 21 63 % A2L
205 209 140 117 39 13 145 189 % A2R
193 157 49 147 19 57 171 91 % B1L
132 44 85 169 197 136 186 62 % B1R
185 133 188 142 4 12 36 108 % B2L
50 87 29 80 97 173 128 113 % B2R
150 28 84 41 123 158 52 156 % C1L
166 196 206 139 187 203 138 46 % C1R
76 17 51 153 37 111 122 155 % C2L
146 119 110 107 106 176 129 43 % C2R
16 48 144 10 30 90 59 177 % D1L
164 125 112 178 200 137 116 109 % D1R
70 210 208 202 184 130 179 115 % D2L
190 204 68 93 31 151 191 134 % D2R
148 22 66 198 172 94 71 2 % E1L
40 154 192 64 162 54 18 6 % E1R
120 149 25 75 14 42 126 167 % E2L
175 199 207 69 23 78 26 79 % E2R
103 98 83 38 114 131 182 124 % F1L
159 53 88 170 127 183 61 161 % F1R
55 165 73 8 24 72 5 15 % F2L
89 100 174 58 160 194 135 45 % F2R
] def
} ctxdef
/checkweightseq [
seq {16 mul checkweights exch 16 getinterval aload pop} forall
] dup length 8 sub 8 exch getinterval def
/widths [
dxw {aload pop} forall
] def
/checksum 0 def
0 1 widths length 1 sub {
/i exch def
/checksum checksum widths i get checkweightseq i get mul add def
} for
/checksum checksum 211 mod datalen 3 sub 211 mul add def
/i 0 def {
checksum tab174 i get le {
tab174 i 1 add 7 getinterval aload pop
/cte exch def /cto exch def
/cmwe exch def /cmwo exch def
/cele exch def /celo exch def
/cgs exch def
exit
} if
/i i 8 add def
} loop
/cwo checksum cgs sub cte idiv celo cmwo 4 true getRSSwidths def
/cwe checksum cgs sub cte mod cele cmwe 4 false getRSSwidths def
/cw 8 array def
0 1 3 {
/i exch def
cw i 2 mul cwo i get put
cw i 2 mul 1 add cwe i get put
} for
22 array dup dup
0 cw put 1 dxw putinterval 0 datalen 1 add getinterval
/dxw exch def
/datalen dxw length def
% Encode row runlengths
/rows datalen segments div ceiling cvi array def
/numrows rows length def
0 1 numrows 1 sub {
/r exch def
mark
segments 4 mod 0 ne r 2 mod 1 eq and {0} if
1 1
0 1 segments 1 sub {
/pos exch r segments mul add def
pos datalen lt {
dxw pos get aload pop
pos 2 mod 0 eq {fxw pos 2 idiv get aload pop} if
} if
} for
1 1
counttomark array astore rows exch r exch put pop
} for
format (expandedstacked) ne { % Linear
% Remove leading space
/sbs rows 0 get dup length 1 sub 1 exch getinterval def
/sbs [
1
0 1 datalen 1 sub {
/i exch def
dxw i get aload pop
i 2 mod 0 eq {fxw i 2 idiv get aload pop} if
} for
1 1
] def
<<
/ren /renlinear
/sbs sbs
/bhs [sbs length 1 add 2 idiv {height} repeat]
/bbs [sbs length 1 add 2 idiv {0} repeat]
/borderleft 0.0
/borderright 0.0
/bordertop 0.0
/borderbottom 0.0
/opt options
>>
dontdraw not //renlinear if
} { % expandedstacked
/seps numrows array def
0 1 numrows 1 sub {
/r exch def
/row rows r get def
% Sample runlengths into bitmap
mark
0 2 row length 1 sub {
/i exch def
row i get {0} repeat
i row length 1 sub lt {row i 1 add get {1} repeat} if
} for
counttomark array astore /row exch def pop
% Derive the separator pattern
/sep [ row {1 exch sub} forall ] def
/finderpos [ % Finder pattern module positions
19 98 row length 13 sub {} for
68 98 row length 13 sub {} for
] def
finderpos {
dup 14 add 1 exch {
/i exch def
row i get 0 eq {
row i 1 sub get 1 eq {
1
} {
sep i 1 sub get 0 eq {1} {0} ifelse
} ifelse
} {
0
} ifelse
sep exch i exch put
} for
} forall
sep 0 [ 0 0 0 0 ] putinterval
sep row length 4 sub [ 0 0 0 0 ] putinterval
% For even segment-pair symbols reverse alternate rows
segments 4 mod 0 eq r 2 mod 1 eq and {
rows r get length rows 0 get length ne % Except partial width last row
finderpos length 2 mod 1 eq and { % with odd finders
/row [ 0 row aload pop ] def
/sep [ 0 sep aload pop ] def
} {
row length 1 sub -1 0 {row exch get} for
row astore pop
sep length 1 sub -1 0 {sep exch get} for
sep astore pop
} ifelse
} if
rows r row put
seps r sep put
} for
% Extend last row and separator to fill width of symbol
/pixx rows 0 get length def
[ pixx {0} repeat ] dup 0 rows numrows 1 sub get putinterval
rows exch numrows 1 sub exch put
[ pixx {0} repeat ] dup 0 seps numrows 1 sub get putinterval
seps exch numrows 1 sub exch put
% Middle separator pattern
/sep [ pixx 2 idiv 1 add { 0 1 } repeat ] 0 pixx getinterval def
sep 0 [0 0 0 0] putinterval
sep pixx 4 sub [0 0 0 0] putinterval
% Compose the symbol
/pixs [
0 1 numrows 1 sub {
/r exch def
r 0 ne {
seps r get aload pop
} if
barxmult {rows r get aload pop} repeat
r numrows 1 sub ne {
seps r get aload pop
sep aload pop
} if
} for
] def
<<
/ren /renmatrix
/pixs pixs
/pixx pixx
/pixy pixs length pixx idiv
/height pixs length pixx idiv 72 div
/width pixx 72 div
/borderleft 0.0
/borderright 0.0
/bordertop 0.0
/borderbottom 0.0
/opt options
>>
dontdraw not //renmatrix if
} ifelse
//unloadctx exec
end
}
[/barcode] {null def} forall
bind def
/databarexpanded dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
% --END ENCODER databarexpanded--