-
Notifications
You must be signed in to change notification settings - Fork 12
/
uplatnica.tpl
4003 lines (3867 loc) · 214 KB
/
uplatnica.tpl
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
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%!PS-Adobe-3.0
%%Creator: cairo 1.14.2 (http://cairographics.org)
%%CreationDate: Fri Feb 12 01:44:36 2016
%%Pages: 1
%%DocumentData: Clean7Bit
%%LanguageLevel: 2
%%DocumentMedia: 225x114mm 637 323 0 () ()
%%BoundingBox: 0 -1 638 323
%%EndComments
%%BeginProlog
/languagelevel where
{ pop languagelevel } { 1 } ifelse
2 lt { /Helvetica findfont 12 scalefont setfont 50 500 moveto
(This print job requires a PostScript Language Level 2 printer.) show
showpage quit } if
/q { gsave } bind def
/Q { grestore } bind def
/cm { 6 array astore concat } bind def
/w { setlinewidth } bind def
/J { setlinecap } bind def
/j { setlinejoin } bind def
/M { setmiterlimit } bind def
/d { setdash } bind def
/m { moveto } bind def
/l { lineto } bind def
/c { curveto } bind def
/h { closepath } bind def
/re { exch dup neg 3 1 roll 5 3 roll moveto 0 rlineto
0 exch rlineto 0 rlineto closepath } bind def
/S { stroke } bind def
/f { fill } bind def
/f* { eofill } bind def
/n { newpath } bind def
/W { clip } bind def
/W* { eoclip } bind def
/BT { } bind def
/ET { } bind def
/pdfmark where { pop globaldict /?pdfmark /exec load put }
{ globaldict begin /?pdfmark /pop load def /pdfmark
/cleartomark load def end } ifelse
/BDC { mark 3 1 roll /BDC pdfmark } bind def
/EMC { mark /EMC pdfmark } bind def
/cairo_store_point { /cairo_point_y exch def /cairo_point_x exch def } def
/Tj { show currentpoint cairo_store_point } bind def
/TJ {
{
dup
type /stringtype eq
{ show } { -0.001 mul 0 cairo_font_matrix dtransform rmoveto } ifelse
} forall
currentpoint cairo_store_point
} bind def
/cairo_selectfont { cairo_font_matrix aload pop pop pop 0 0 6 array astore
cairo_font exch selectfont cairo_point_x cairo_point_y moveto } bind def
/Tf { pop /cairo_font exch def /cairo_font_matrix where
{ pop cairo_selectfont } if } bind def
/Td { matrix translate cairo_font_matrix matrix concatmatrix dup
/cairo_font_matrix exch def dup 4 get exch 5 get cairo_store_point
/cairo_font where { pop cairo_selectfont } if } bind def
/Tm { 2 copy 8 2 roll 6 array astore /cairo_font_matrix exch def
cairo_store_point /cairo_font where { pop cairo_selectfont } if } bind def
/g { setgray } bind def
/rg { setrgbcolor } bind def
/d1 { setcachedevice } bind def
/cairo_set_page_size {
% Change paper size, but only if different from previous paper size otherwise
% duplex fails. PLRM specifies a tolerance of 5 pts when matching paper size
% so we use the same when checking if the size changes.
/setpagedevice where {
pop currentpagedevice
/PageSize known {
2 copy
currentpagedevice /PageSize get aload pop
exch 4 1 roll
sub abs 5 gt
3 1 roll
sub abs 5 gt
or
} {
true
} ifelse
{
2 array astore
2 dict begin
/PageSize exch def
/ImagingBBox null def
currentdict end
setpagedevice
} {
pop pop
} ifelse
} {
pop
} ifelse
} def
%%EndProlog
%%BeginSetup
% --BEGIN RESOURCE preamble--
%%BeginResource: Category uk.co.terryburton.bwipp 0.0 2015112400 31191 34576
%%BeginData: 6 ASCII Lines
currentglobal
true setglobal
/Generic /Category findresource dup length 1 add dict copy dup
/InstanceType /setpacking where {pop /packedarraytype} {/arraytype} ifelse put
/uk.co.terryburton.bwipp exch /Category defineresource pop
setglobal
%%EndData
%%EndResource
% --END RESOURCE preamble--
% --BEGIN RESOURCE raiseerror--
% --REQUIRES preamble--
%%BeginResource: uk.co.terryburton.bwipp raiseerror 0.0 2015112400 44890 44440
%%BeginData: 13 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/raiseerror {
$error exch /errorinfo exch put
$error exch /errorname exch put
$error /command null put
$error /newerror true put
handleerror quit
} bind def
/raiseerror dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RESOURCE raiseerror--
% --BEGIN RENDERER renmatrix--
% --REQUIRES preamble raiseerror--
%%BeginResource: uk.co.terryburton.bwipp renmatrix 0.0 2015112400 54074 54076
%%BeginData: 66 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
begin
/renmatrix {
20 dict begin
/args exch def
% Default options
/width 1 def
/height 1 def
/barcolor (unset) def
/backgroundcolor (unset) def
% Apply the renderer options and the user options
args {def} forall
opt {def} forall
/width width cvr def
/height height cvr def
/barcolor barcolor cvlit def
/backgroundcolor backgroundcolor cvlit def
% Set RGB or CMYK color depending on length of given hex string
/setanycolor {
/anycolor exch def
anycolor length 6 eq {
(< >) 8 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setrgbcolor
} if
anycolor length 8 eq {
(< >) 10 string copy dup 1 anycolor putinterval cvx exec {255 div} forall setcmykcolor
} if
} bind def
% Draw the image
gsave
currentpoint translate
width pixx div 72 mul height pixy div 72 mul scale
0 0 moveto pixx 0 lineto pixx pixy lineto 0 pixy lineto closepath
backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
barcolor (unset) ne { barcolor setanycolor } if
/xyget {pixx mul add get} bind def
newpath
0 1 pixs length 1 sub {
dup pixx mod /x exch def
pixx idiv /y exch def
pixs x y xyget 1 eq {
x pixy y sub 1 sub moveto
0 1 rlineto
1 0 rlineto
0 -1 rlineto
-1 0 rlineto
closepath
} if
} for
fill
grestore
end
} bind def
/renmatrix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RENDERER renmatrix--
% --BEGIN ENCODER pdf417--
% --REQUIRES preamble raiseerror renmatrix--
% --DESC: PDF417
% --EXAM: This is PDF417
% --EXOP: columns=2
% --RNDR: renmatrix
/setpacking where {pop currentpacking true setpacking} if
1 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/pdf417 {
20 dict begin
/options exch def
/barcode exch def
/dontdraw false def
/compact false def
/eclevel -1 def
/columns 0 def
/rows 0 def
/rowmult 3 def
/encoding (auto) def
/ccc false def
/raw false def
/parse false def
% Parse the input options
options type /stringtype eq {
1 dict begin
options {
token false eq {exit} if dup length string cvs (=) search
true eq {cvlit exch pop exch def} {cvlit true def} ifelse
} loop
currentdict end /options exch def
} if
options {def} forall
/eclevel eclevel cvi def
/columns columns cvi def
/rows rows cvi def
/rowmult rowmult cvr def
% Parse ordinals of the form ^NNN to ASCII
parse {
/msg barcode length string def
/j 0 def
barcode
{ % loop
(^) search {
dup msg exch j exch putinterval
length j add 1 add /j exch def
pop
dup 0 3 getinterval cvi msg exch j 1 sub exch put
dup length 3 sub 3 exch getinterval
} {
dup msg exch j exch putinterval
length j add /j exch def
/barcode msg 0 j getinterval def
exit
} ifelse
} loop
} if
raw {/encoding (raw) def} if
% Convert input into array of codewords
encoding (raw) eq {
/datcws barcode length array def
/i 0 def /j 0 def
{ % loop
i barcode length eq {exit} if
/cw barcode i 1 add 3 getinterval cvi def
datcws j cw put
/i i 4 add def
/j j 1 add def
} loop
/datcws datcws 0 j getinterval def
} if
/barcode [ barcode {} forall ] def
/barlen barcode length def
ccc {/encoding (ccc) def} if
/encb {
/in exch def
/inlen in length def
/out inlen 6 idiv 5 mul inlen 6 mod add array def
0 1 inlen 6 idiv 1 sub {
/k exch def
/msbs [ in k 6 mul 3 getinterval aload pop ] def
/mscs [
msbs aload pop exch 256 mul add exch 65536 mul add
3 {dup 900 mod exch 900 idiv} repeat
] def
/lsbs [ in k 6 mul 3 add 3 getinterval aload pop ] def
/lscs [
lsbs aload pop exch 256 mul add exch 65536 mul add
3 {dup 900 mod exch 900 idiv} repeat
] def
lscs 0 get mscs 0 get 316 mul add
out k 5 mul 4 add 2 index 900 mod put
900 idiv lscs 1 get add mscs 0 get 641 mul add mscs 1 get 316 mul add
out k 5 mul 3 add 2 index 900 mod put
900 idiv lscs 2 get add mscs 0 get 20 mul add mscs 1 get 641 mul add mscs 2 get 316 mul add
out k 5 mul 2 add 2 index 900 mod put
900 idiv lscs 3 get add mscs 1 get 20 mul add mscs 2 get 641 mul add
out k 5 mul 1 add 2 index 900 mod put
900 idiv mscs 2 get 20 mul add
out k 5 mul 3 -1 roll 900 mod put
} for
/rem inlen 6 mod def
rem 0 ne {
out out length rem sub
[ in inlen rem sub rem getinterval aload pop ]
putinterval
} if
out
} bind def
encoding (byte) eq encoding (ccc) eq or {
/datcws barlen 6 idiv 5 mul barlen 6 mod add 1 add array def
datcws 0 barlen 6 mod 0 eq {924} {901} ifelse put
datcws 1 barcode encb putinterval
encoding (ccc) eq {/datcws [920 datcws aload pop] def} if
} if
encoding (auto) eq {
% Modes and text submodes
/T 0 def /N 1 def /B 2 def
/A 0 def /L 1 def /M 2 def /P 3 def
% Special function characters for mode switching
/tl -1 def /nl -2 def /bl -3 def /bl6 -4 def /bs -5 def
% Special function characters for text mode
/al -6 def /ll -7 def /ml -8 def /pl -9 def /as -10 def /ps -11 def
% Character maps for each state
/charmaps [
% A L M P
[ (A) (a) (0) (;) ] % 0
[ (B) (b) (1) (<) ] % 1
[ (C) (c) (2) (>) ] % 2
[ (D) (d) (3) (@) ] % 3
[ (E) (e) (4) ([) ] % 4
[ (F) (f) (5) 92 ] % 5
[ (G) (g) (6) (]) ] % 6
[ (H) (h) (7) (_) ] % 7
[ (I) (i) (8) (`) ] % 8
[ (J) (j) (9) (~) ] % 9
[ (K) (k) (&) (!) ] % 10
[ (L) (l) 13 13 ] % 11
[ (M) (m) 9 9 ] % 12
[ (N) (n) (,) (,) ] % 13
[ (O) (o) (:) (:) ] % 14
[ (P) (p) (#) 10 ] % 15
[ (Q) (q) (-) (-) ] % 16
[ (R) (r) (.) (.) ] % 17
[ (S) (s) ($) ($) ] % 18
[ (T) (t) (/) (/) ] % 19
[ (U) (u) (+) (") ] % 20
[ (V) (v) (%) (|) ] % 21
[ (W) (w) (*) (*) ] % 22
[ (X) (x) (=) 40 ] % 23
[ (Y) (y) (^) 41 ] % 24
[ (Z) (z) pl (?) ] % 25
[ ( ) ( ) ( ) ({) ] % 26
[ ll as ll (}) ] % 27
[ ml ml al (') ] % 28
[ ps ps ps al ] % 29
] def
% Invert charmaps to give character to value maps for each state
/charvals [ 30 dict 30 dict 30 dict 30 dict ] def
/alltext 104 dict def
0 1 charmaps length 1 sub {
/i exch def
/encs charmaps i get def
0 1 3 {
/j exch def
encs j get dup type /stringtype eq {0 get} if % convert string to ASCII if required
dup charvals j get exch i put
alltext exch -1 put
} for
} for
/e 10000 def % "Empty"
/latlen [ % Bit length of latch between submodes
% To: A L M P From
[ 0 1 1 2 ] % A
[ 2 0 1 2 ] % L
[ 1 1 0 1 ] % M
[ 1 2 2 0 ] % P
] def
/latseq [ % Latch sequences between submodes
% To: A L M P From
[ [] [ll] [ml] [ml pl] ] % A
[ [ml al] [] [ml] [ml pl] ] % L
[ [al] [ll] [] [pl] ] % M
[ [al] [al ll] [al ml] [] ] % P
] def
/shftlen [ % Bit length of shift to submode
% To: A L M P From
[ e e e 1 ] % A
[ 1 e e 1 ] % L
[ e e e 1 ] % M
[ e e e e ] % P
] def
% Determine runlengths of digits
/numdigits [ barlen {0} repeat 0 ] def
/numtext [ barlen {0} repeat 0 ] def
/numbytes [ barlen {0} repeat 0 ] def
barlen 1 sub -1 0 {
/i exch def
barcode i get dup 48 ge exch 57 le and {
numdigits i numdigits i 1 add get 1 add put
} if
alltext barcode i get known numdigits i get 13 lt and {
numtext i numtext i 1 add get 1 add put
} if
numtext i get 5 lt numdigits i get 13 lt and {
numbytes i numbytes i 1 add get 1 add put
} if
} for
/numdigits numdigits 0 barlen getinterval def
/numtext numtext 0 barlen getinterval def
/numbytes numbytes 0 barlen getinterval def
/seq [] def /seqlen 0 def /state T def /p 0 def { % loop
p barlen eq {exit} if
/n numdigits p get def
n 13 ge {
/seq [
seq aload pop
nl
[ barcode p n getinterval aload pop ]
] def
/state N def
/p p n add def
/seqlen seqlen 1 add n add def
} { % next
/t numtext p get def
t 5 ge {
/seq [
seq aload pop
state T ne {tl} if
[ barcode p t getinterval aload pop ]
] def
/state T def
/p p t add def
/seqlen seqlen 1 add t add def % ish
} { % next
/b numbytes p get def
b 1 eq state T eq and {
/seq [
seq aload pop
bs
[ barcode p get ]
] def
/p p b add def
/seqlen seqlen 2 add def
} { % next
/seq [
seq aload pop
b 6 mod 0 ne {bl} {bl6} ifelse
[ barcode p b getinterval aload pop ]
] def
/state B def
/p p b add def
/seqlen seqlen 1 add b add def
} ifelse } ifelse } ifelse
} loop
/latchcws <<
tl 900 bl 901 bl6 924 nl 902 bs 913
>> def
% Submode encoding functions
/enca {charvals A get exch get} bind def
/encl {charvals L get exch get} bind def
/encm {charvals M get exch get} bind def
/encp {charvals P get exch get} bind def
/textencfuncs [ /enca /encl /encm /encp ] def
/addtotext {
text exch l exch put
/l l 1 add def
} bind def
/enct {
/in exch def
/curlen [ e e e e ] def
curlen submode 0 put
/curseq [ [] [] [] [] ] def
% Derive the optimal sequences ending in each submode
in {
/char exch def
% Check for optimisations in the current sequences by latching from x to y
{ % loop
/imp false def
[ A L M P ] {
/x exch def
[ A L M P ] {
/y exch def
/cost curlen x get latlen x get y get add def
cost curlen y get lt {
curlen y cost put
curseq y [
curseq x get aload pop
latseq x get y get aload pop
] put
/imp true def
} if
} forall
} forall
imp not {exit} if % Repeat unless no improvement
} loop
% Determine optimal next sequences for each valid encoding
/nxtlen [ e e e e ] def
/nxtseq 4 array def
[ A L M P ] {
/x exch def
{ % loop for common exit
charvals x get char known not {exit} if
% Extend directly
/cost curlen x get 1 add def
cost nxtlen x get lt {
nxtlen x cost put
nxtseq x [ curseq x get aload pop char ] put
} if
% Optimise for direct shifts from y to x
[ A L M P ] {
/y exch def
x y ne {
/cost curlen y get shftlen y get x get add 1 add def
cost nxtlen y get lt {
nxtlen y cost put
nxtseq y [
curseq y get aload pop
x A eq {as} {ps} ifelse
char
] put
} if
} if
} forall
exit
} loop
} forall
/curlen nxtlen def
/curseq nxtseq def
} forall
% Select the optimal sequence
/minseq e def
[ A L M P ] {
/k exch def
curlen k get minseq lt {
/minseq curlen k get def
/txtseq curseq k get def
} if
} forall
% Encode the sequence
/text minseq array def
/k 0 def /l 0 def {
k txtseq length ge {exit} if
/char txtseq k get def
% Encode character
char textencfuncs submode get load exec addtotext
/k k 1 add def
% Encode shifted next character
char as eq char ps eq or {
txtseq k get char as eq {enca} {encp} ifelse addtotext
/k k 1 add def
} if
% Latches to new submode
char al eq {/submode A def} if
char ll eq {/submode L def} if
char ml eq {/submode M def} if
char pl eq {/submode P def} if
} loop
text length 2 mod 1 eq {
submode P eq {
/pad al encp def
/submode A def
} {
/pad ps textencfuncs submode get load exec def
} ifelse
/text [ text aload pop pad ] def
} if
/out text length 2 idiv array def
0 1 out length 1 sub {
/k exch def
out k text k 2 mul get 30 mul text k 2 mul 1 add get add put
} for
out
} bind def
/encn {
/in exch def
/out [] def
0 44 in length 1 sub {
/k exch def
/gmod [
1 in k in length k sub dup 44 gt {pop 44} if getinterval
{48 sub} forall
] def
/cwn [] def {
/dv 900 def
/gmul [] def /val 0 def {
gmod length 0 eq {exit} if
/val val 10 mul gmod 0 get add def
/gmod gmod 1 gmod length 1 sub getinterval def
val dv lt {
gmul length 0 ne {
/gmul [ gmul aload pop 0 ] def
} if
} {
/gmul [ gmul aload pop val dv idiv ] def
} ifelse
/val val dv mod def
} loop
/dv val def
/cwn [ dv cwn aload pop ] def
/gmod gmul def
gmul length 0 eq {exit} if
} loop
/out [ out aload pop cwn aload pop ] def
} for
out
} bind def
/encfuncs [ /enct /encn /encb ] def
/addtocws {
dup datcws j 3 -1 roll putinterval
length j add /j exch def
} bind def
% Encode the sequence
/state T def /submode A def
/datcws seqlen array def
/i 0 def /j 0 def {
i seq length ge {exit} if
/chars seq i get def
chars type /arraytype eq { % Encode data according to mode
chars encfuncs state get load exec addtocws
} { % Encode the latch to new state or byte shift
[ latchcws chars get ] addtocws
chars tl eq {/state T def /submode A def} if
chars nl eq {/state N def} if
chars bl eq chars bl6 eq or {/state B def} if
chars bs eq {
/i i 1 add def
seq i get encb addtocws
} if
} ifelse
/i i 1 add def
} loop
/datcws datcws 0 j getinterval def
} if
% Determine the error correction level if unspecified
/m datcws length def
eclevel -1 eq {
m 40 le {/eclevel 2 def} if
m 41 ge m 160 le and {/eclevel 3 def} if
m 161 ge m 320 le and {/eclevel 4 def} if
m 321 ge {/eclevel 5 def} if
} if
% Reduce the error level so that it does not cause an excessive number of codewords
/maxeclevel 928 1 sub m sub ln 2 ln div cvi 1 sub def
eclevel maxeclevel gt {/eclevel maxeclevel def} if
/k 2 eclevel 1 add exp cvi def
% To determine size of matrix, number of columns if given by user...
columns 0 eq {/columns m k add 3 div sqrt round cvi def} if
columns 1 ge columns 30 le and {/c columns def} if
% ... and rows is greater of those required and that given by user within limits
/r m k add 1 add columns div ceiling cvi def % Required
r rows lt rows 90 le and {/r rows def} if
r 3 lt {/r 3 def} if
% Opportunistically raise the error level if a better fit to the matrix is possible
/maxeclevel c r mul 1 sub m sub ln 2 ln div cvi 1 sub 8 2 copy gt {exch} if pop def
maxeclevel eclevel gt {
/eclevel maxeclevel def
/k 2 eclevel 1 add exp cvi def
} if
% Create codewords array with one extra working space element and add padding
/n c r mul k sub def
/cws c r mul 1 add array def
cws 0 n put
cws 1 datcws putinterval
cws m 1 add [ n m sub 1 sub {900} repeat ] putinterval
cws n [ k {0} repeat 0 ] putinterval
% Calculate the log and anti-log tables
/rsalog [ 1 928 {dup 3 mul 929 mod} repeat ] def
/rslog 929 array def
1 1 928 {dup rsalog exch get exch rslog 3 1 roll put} for
% Function to calculate the product in the field
/rsprod {
2 copy 0 ne exch 0 ne and {
rslog exch get exch rslog exch get add 928 mod rsalog exch get
} {
pop pop 0
} ifelse
} bind def
% Generate the coefficients
/coeffs [ 1 k {0} repeat ] def
1 1 k {
/i exch def
coeffs i coeffs i 1 sub get put
i 1 sub -1 1 {
/j exch def
coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod add 929 mod put
} for
coeffs 0 coeffs 0 get rsalog i get rsprod put
} for
/coeffs coeffs 0 coeffs length 1 sub getinterval def
coeffs length 1 sub -2 0 {coeffs exch 2 copy get 929 exch sub put} for
% Derive the error codewords
0 1 n 1 sub {
/t exch cws exch get cws n get add 929 mod def
0 1 k 1 sub {
/j exch def
cws n j add cws n j add 1 add get 929 t coeffs k j sub 1 sub get mul 929 mod sub add 929 mod put
} for
} for
n 1 n k add { dup cws exch 929 cws 5 -1 roll get sub 929 mod put } for
% Trim the working space from the end of the codewords
/cws cws 0 cws length 1 sub getinterval def
% Base 10 encoding of the bar space successions for the codewords in each cluster
/clusters [
[
120256 125680 128380 120032 125560 128318 108736 119920 108640 86080 108592 86048
110016 120560 125820 109792 120440 125758 88256 109680 88160 89536 110320 120700
89312 110200 120638 89200 110140 89840 110460 89720 110398 89980 128506 119520
125304 128190 107712 119408 125244 107616 119352 84032 107568 119324 84000 107544
83984 108256 119672 125374 85184 108144 119612 85088 108088 119582 85040 108060
85728 108408 119742 85616 108348 85560 108318 85880 108478 85820 85790 107200
119152 125116 107104 119096 125086 83008 107056 119068 82976 107032 82960 82952
83648 107376 119228 83552 107320 119198 83504 107292 83480 83468 83824 107452
83768 107422 83740 83900 106848 118968 125022 82496 106800 118940 82464 106776
118926 82448 106764 82440 106758 82784 106936 119006 82736 106908 82712 106894
82700 82694 106974 82830 82240 106672 118876 82208 106648 118862 82192 106636
82184 106630 82180 82352 82328 82316 82080 118830 106572 106566 82050 117472
124280 127678 103616 117360 124220 103520 117304 124190 75840 103472 75808 104160
117624 124350 76992 104048 117564 76896 103992 76848 76824 77536 104312 117694
77424 104252 77368 77340 77688 104382 77628 77758 121536 126320 128700 121440
126264 128670 111680 121392 126236 111648 121368 126222 111632 121356 103104 117104
124092 112320 103008 117048 124062 112224 121656 126366 93248 74784 102936 117006
93216 112152 93200 75456 103280 117180 93888 75360 103224 117150 93792 112440
121758 93744 75288 93720 75632 103356 94064 75576 103326 94008 112542 93980
75708 94140 75678 94110 121184 126136 128606 111168 121136 126108 111136 121112
126094 111120 121100 111112 111108 102752 116920 123998 111456 102704 116892 91712
74272 121244 116878 91680 74256 102668 91664 111372 102662 74244 74592 102840
116958 92000 74544 102812 91952 111516 102798 91928 74508 74502 74680 102878
92088 74652 92060 74638 92046 92126 110912 121008 126044 110880 120984 126030
110864 120972 110856 120966 110852 110850 74048 102576 116828 90944 74016 102552
116814 90912 111000 121038 90896 73992 102534 90888 110982 90884 74160 102620
91056 74136 102606 91032 111054 91020 74118 91014 91100 91086 110752 120920
125998 110736 120908 110728 120902 110724 110722 73888 102488 116782 90528 73872
102476 90512 110796 102470 90504 73860 90500 73858 73944 90584 90572 90566
120876 120870 110658 102444 73800 90312 90308 90306 101056 116080 123580 100960
116024 70720 100912 115996 70688 100888 70672 70664 71360 101232 116156 71264
101176 116126 71216 101148 71192 71180 71536 101308 71480 101278 71452 71612
71582 118112 124600 127838 105024 118064 124572 104992 118040 124558 104976 118028
104968 118022 100704 115896 123486 105312 100656 115868 79424 70176 118172 115854
79392 105240 100620 79376 70152 79368 70496 100792 115934 79712 70448 118238
79664 105372 100750 79640 70412 79628 70584 100830 79800 70556 79772 70542
70622 79838 122176 126640 128860 122144 126616 128846 122128 126604 122120 126598
122116 104768 117936 124508 113472 104736 126684 124494 113440 122264 126670 113424
104712 117894 113416 122246 104706 69952 100528 115804 78656 69920 100504 115790
96064 78624 104856 117966 96032 113560 122318 100486 96016 78600 104838 96008
69890 70064 100572 78768 70040 100558 96176 78744 104910 96152 113614 70022
78726 70108 78812 70094 96220 78798 122016 126552 128814 122000 126540 121992
126534 121988 121986 104608 117848 124462 113056 104592 126574 113040 122060 117830
113032 104580 113028 104578 113026 69792 100440 115758 78240 69776 100428 95136
78224 104652 100422 95120 113100 69764 95112 78212 69762 78210 69848 100462
78296 69836 95192 78284 69830 95180 78278 69870 95214 121936 126508 121928
126502 121924 121922 104528 117804 112848 104520 117798 112840 121958 112836 104514
112834 69712 100396 78032 69704 100390 94672 78024 104550 94664 112870 69698
94660 78018 94658 78060 94700 94694 126486 121890 117782 104484 104482 69672
77928 94440 69666 77922 99680 68160 99632 68128 99608 115342 68112 99596
68104 99590 68448 99768 115422 68400 99740 68376 99726 68364 68358 68536
99806 68508 68494 68574 101696 116400 123740 101664 116376 101648 116364 101640
116358 101636 67904 99504 115292 72512 67872 116444 115278 72480 101784 116430
72464 67848 99462 72456 101766 67842 68016 99548 72624 67992 99534 72600
101838 72588 67974 68060 72668 68046 72654 118432 124760 127918 118416 124748
118408 124742 118404 118402 101536 116312 105888 101520 116300 105872 118476 116294
105864 101508 105860 101506 105858 67744 99416 72096 67728 116334 80800 72080
101580 99398 80784 105932 67716 80776 72068 67714 72066 67800 99438 72152
67788 80856 72140 67782 80844 72134 67822 72174 80878 126800 128940 126792
128934 126788 126786 118352 124716 122576 126828 124710 122568 126822 122564 118338
122562 101456 116268 105680 101448 116262 114128 105672 118374 114120 122598 101442
114116 105666 114114 67664 99372 71888 67656 99366 80336 71880 101478 97232
80328 105702 67650 97224 114150 71874 97220 67692 71916 67686 80364 71910
97260 80358 97254 126760 128918 126756 126754 118312 124694 122472 126774 122468
118306 122466 101416 116246 105576 101412 113896 105572 101410 113892 105570 113890
67624 99350 71784 101430 80104 71780 67618 96744 80100 71778 96740 80098
96738 71798 96758 126738 122420 122418 105524 113780 113778 71732 79988 96500
96498 66880 66848 98968 66832 66824 66820 66992 66968 66956 66950 67036
67022 100000 99984 115532 99976 115526 99972 99970 66720 98904 69024 100056
98892 69008 100044 69000 100038 68996 66690 68994 66776 98926 69080 100078
69068 66758 69062 66798 69102 116560 116552 116548 116546 99920 102096 116588
115494 102088 116582 102084 99906 102082 66640 68816 66632 98854 73168 68808
66628 73160 68804 66626 73156 68802 66668 68844 66662 73196 68838 73190
124840 124836 124834 116520 118632 124854 118628 116514 118626 99880 115478 101992
116534 106216 101988 99874 106212 101986 106210 66600 98838 68712 99894 72936
68708 66594 81384 72932 68706 81380 72930 66614 68726 72950 81398 128980
128978 124820 126900 124818 126898 116500 118580 116498 122740 118578 122738 99860
101940 99858 106100 101938 114420
] [
128352 129720 125504 128304 129692 125472 128280 129678 125456 128268 125448 128262
125444 125792 128440 129758 120384 125744 128412 120352 125720 128398 120336 125708
120328 125702 120324 120672 125880 128478 110144 120624 125852 110112 120600 125838
110096 120588 110088 120582 110084 110432 120760 125918 89664 110384 120732 89632
110360 120718 89616 110348 89608 110342 89952 110520 120798 89904 110492 89880
110478 89868 90040 110558 90012 89998 125248 128176 129628 125216 128152 129614
125200 128140 125192 128134 125188 125186 119616 125360 128220 119584 125336 128206
119568 125324 119560 125318 119556 119554 108352 119728 125404 108320 119704 125390
108304 119692 108296 119686 108292 108290 85824 108464 119772 85792 108440 119758
85776 108428 85768 108422 85764 85936 108508 85912 108494 85900 85894 85980
85966 125088 128088 129582 125072 128076 125064 128070 125060 125058 119200 125144
128110 119184 125132 119176 125126 119172 119170 107424 119256 125166 107408 119244
107400 119238 107396 107394 83872 107480 119278 83856 107468 83848 107462 83844
83842 83928 107502 83916 83910 83950 125008 128044 125000 128038 124996 124994
118992 125036 118984 125030 118980 118978 106960 119020 106952 119014 106948 106946
82896 106988 82888 106982 82884 82882 82924 82918 124968 128022 124964 124962
118888 124982 118884 118882 106728 118902 106724 106722 82408 106742 82404 82402
124948 124946 118836 118834 106612 106610 124224 127664 129372 124192 127640 129358
124176 127628 124168 127622 124164 124162 117568 124336 127708 117536 124312 127694
117520 124300 117512 124294 117508 117506 104256 117680 124380 104224 117656 124366
104208 117644 104200 117638 104196 104194 77632 104368 117724 77600 104344 117710
77584 104332 77576 104326 77572 77744 104412 77720 104398 77708 77702 77788
77774 128672 129880 93168 128656 129868 92664 128648 129862 92412 128644 128642
124064 127576 129326 126368 124048 129902 126352 128716 127558 126344 124036 126340
124034 126338 117152 124120 127598 121760 117136 124108 121744 126412 124102 121736
117124 121732 117122 121730 103328 117208 124142 112544 103312 117196 112528 121804
117190 112520 103300 112516 103298 112514 75680 103384 117230 94112 75664 103372
94096 112588 103366 94088 75652 94084 75650 75736 103406 94168 75724 94156
75718 94150 75758 128592 129836 91640 128584 129830 91388 128580 91262 128578
123984 127532 126160 123976 127526 126152 128614 126148 123970 126146 116944 124012
121296 116936 124006 121288 126182 121284 116930 121282 102864 116972 111568 102856
116966 111560 121318 111556 102850 111554 74704 102892 92112 74696 102886 92104
111590 92100 74690 92098 74732 92140 74726 92134 128552 129814 90876 128548
90750 128546 123944 127510 126056 128566 126052 123938 126050 116840 123958 121064
116836 121060 116834 121058 102632 116854 111080 121078 111076 102626 111074 74216
102646 91112 74212 91108 74210 91106 74230 91126 128532 90494 128530 123924
126004 123922 126002 116788 120948 116786 120946 102516 110836 102514 110834 73972
90612 73970 90610 128522 123914 125978 116762 120890 102458 110714 123552 127320
129198 123536 127308 123528 127302 123524 123522 116128 123608 127342 116112 123596
116104 123590 116100 116098 101280 116184 123630 101264 116172 101256 116166 101252
101250 71584 101336 116206 71568 101324 71560 101318 71556 71554 71640 101358
71628 71622 71662 127824 129452 79352 127816 129446 79100 127812 78974 127810
123472 127276 124624 123464 127270 124616 127846 124612 123458 124610 115920 123500
118224 115912 123494 118216 124646 118212 115906 118210 100816 115948 105424 100808
115942 105416 118246 105412 100802 105410 70608 100844 79824 70600 100838 79816
105446 79812 70594 79810 70636 79852 70630 79846 129960 95728 113404 129956
95480 113278 129954 95356 95294 127784 129430 78588 128872 129974 95996 78462
128868 127778 95870 128866 123432 127254 124520 123428 126696 128886 123426 126692
124514 126690 115816 123446 117992 115812 122344 117988 115810 122340 117986 122338
100584 115830 104936 100580 113640 104932 100578 113636 104930 113634 70120 100598
78824 70116 96232 78820 70114 96228 78818 96226 70134 78838 129940 94968
113022 129938 94844 94782 127764 78206 128820 127762 95102 128818 123412 124468
123410 126580 124466 126578 115764 117876 115762 122100 117874 122098 100468 104692
100466 113140 104690 113138 69876 78324 69874 95220 78322 95218 129930 94588
94526 127754 128794 123402 124442 126522 115738 117818 121978 100410 104570 112890
69754 78074 94714 94398 123216 127148 123208 127142 123204 123202 115408 123244
115400 123238 115396 115394 99792 115436 99784 115430 99780 99778 68560 99820
68552 99814 68548 68546 68588 68582 127400 129238 72444 127396 72318 127394
123176 127126 123752 123172 123748 123170 123746 115304 123190 116456 115300 116452
115298 116450 99560 115318 101864 99556 101860 99554 101858 68072 99574 72680
68068 72676 68066 72674 68086 72694 129492 80632 105854 129490 80508 80446
127380 72062 127924 127378 80766 127922 123156 123700 123154 124788 123698 124786
115252 116340 115250 118516 116338 118514 99444 101620 99442 105972 101618 105970
67828 72180 67826 80884 72178 80882 97008 114044 96888 113982 96828 96798
129482 80252 130010 97148 80190 97086 127370 127898 128954 123146 123674 124730
126842 115226 116282 118394 122618 99386 101498 105722 114170 67706 71930 80378
96632 113854 96572 96542 80062 96702 96444 96414 96350 123048 123044 123042
115048 123062 115044 115042 99048 115062 99044 99042 67048 99062 67044 67042
67062 127188 68990 127186 123028 123316 123026 123314 114996 115572 114994 115570
98932 100084 98930 100082 66804 69108 66802 69106 129258 73084 73022 127178
127450 123018 123290 123834 114970 115514 116602 98874 99962 102138 66682 68858
73210 81272 106174 81212 81182 72894 81342 97648 114364 97592 114334 97564
97550 81084 97724 81054 97694 97464 114270 97436 97422 80990 97502 97372
97358 97326 114868 114866 98676 98674 66292 66290 123098 114842 115130 98618
99194 66170 67322 69310 73404 73374 81592 106334 81564 81550 73310 81630
97968 114524 97944 114510 97932 97926 81500 98012 81486 97998 97880 114478
97868 97862 81454 97902 97836 97830 69470 73564 73550 81752 106414 81740
81734 73518 81774 81708 81702
] [
109536 120312 86976 109040 120060 86496 108792 119934 86256 108668 86136 129744
89056 110072 129736 88560 109820 129732 88312 109694 129730 88188 128464 129772
89592 128456 129766 89340 128452 89214 128450 125904 128492 125896 128486 125892
125890 120784 125932 120776 125926 120772 120770 110544 120812 110536 120806 110532
84928 108016 119548 84448 107768 119422 84208 107644 84088 107582 84028 129640
85488 108284 129636 85240 108158 129634 85116 85054 128232 129654 85756 128228
85630 128226 125416 128246 125412 125410 119784 125430 119780 119778 108520 119798
108516 108514 83424 107256 119166 83184 107132 83064 107070 83004 82974 129588
83704 107390 129586 83580 83518 128116 83838 128114 125172 125170 119284 119282
107508 107506 82672 106876 82552 106814 82492 82462 129562 82812 82750 128058
125050 119034 82296 106686 82236 82206 82366 82108 82078 76736 103920 117500
76256 103672 117374 76016 103548 75896 103486 75836 129384 77296 104188 129380
77048 104062 129378 76924 76862 127720 129398 77564 127716 77438 127714 124392
127734 124388 124386 117736 124406 117732 117730 104424 117750 104420 104418 112096
121592 126334 92608 111856 121468 92384 111736 121406 92272 111676 92216 111646
92188 75232 103160 117118 93664 74992 103036 93424 112252 102974 93304 74812
93244 74782 93214 129332 75512 103294 129908 129330 93944 75388 129906 93820
75326 93758 127604 75646 128756 127602 94078 128754 124148 126452 124146 126450
117236 121844 117234 121842 103412 103410 91584 111344 121212 91360 111224 121150
91248 111164 91192 111134 91164 91150 74480 102780 91888 74360 102718 91768
111422 91708 74270 91678 129306 74620 129850 92028 74558 91966 127546 128634
124026 126202 116986 121338 102906 90848 110968 121022 90736 110908 90680 110878
90652 90638 74104 102590 91000 74044 90940 74014 90910 74174 91070 90480
110780 90424 110750 90396 90382 73916 90556 73886 90526 90296 110686 90268
90254 73822 90334 90204 90190 71136 101112 116094 70896 100988 70776 100926
70716 70686 129204 71416 101246 129202 71292 71230 127348 71550 127346 123636
123634 116212 116210 101364 101362 79296 105200 118140 79072 105080 118078 78960
105020 78904 104990 78876 78862 70384 100732 79600 70264 100670 79480 105278
79420 70174 79390 129178 70524 129466 79740 70462 79678 127290 127866 123514
124666 115962 118266 100858 113376 122232 126654 95424 113264 122172 95328 113208
122142 95280 113180 95256 113166 95244 78560 104824 117950 95968 78448 104764
95856 113468 104734 95800 78364 95772 78350 95758 70008 100542 78712 69948
96120 78652 69918 96060 78622 96030 70078 78782 96190 94912 113008 122044
94816 112952 122014 94768 112924 94744 112910 94732 94726 78192 104636 95088
78136 104606 95032 113054 95004 78094 94990 69820 78268 69790 95164 78238
95134 94560 112824 121950 94512 112796 94488 112782 94476 94470 78008 104542
94648 77980 94620 77966 94606 69726 78046 94686 94384 112732 94360 112718
94348 94342 77916 94428 77902 94414 94296 112686 94284 94278 77870 94318
94252 94246 68336 99708 68216 99646 68156 68126 68476 68414 127162 123258
115450 99834 72416 101752 116414 72304 101692 72248 101662 72220 72206 67960
99518 72568 67900 72508 67870 72478 68030 72638 80576 105840 118460 80480
105784 118430 80432 105756 80408 105742 80396 80390 72048 101564 80752 71992
101534 80696 71964 80668 71950 80654 67772 72124 67742 80828 72094 80798
114016 122552 126814 96832 113968 122524 96800 113944 122510 96784 113932 96776
113926 96772 80224 105656 118366 97120 80176 105628 97072 114076 105614 97048
80140 97036 80134 97030 71864 101470 80312 71836 97208 80284 71822 97180
80270 97166 67678 71902 80350 97246 96576 113840 122460 96544 113816 122446
96528 113804 96520 113798 96516 96514 80048 105564 96688 80024 105550 96664
113870 96652 80006 96646 71772 80092 71758 96732 80078 96718 96416 113752
122414 96400 113740 96392 113734 96388 96386 79960 105518 96472 79948 96460
79942 96454 71726 79982 96494 96336 113708 96328 113702 96324 96322 79916
96364 79910 96358 96296 113686 96292 96290 79894 96310 66936 99006 66876
66846 67006 68976 100028 68920 99998 68892 68878 66748 69052 66718 69022
73056 102072 116574 73008 102044 72984 102030 72972 72966 68792 99934 73144
68764 73116 68750 73102 66654 68830 73182 81216 106160 118620 81184 106136
118606 81168 106124 81160 106118 81156 81154 72880 101980 81328 72856 101966
81304 106190 81292 72838 81286 68700 72924 68686 81372 72910 81358 114336
122712 126894 114320 122700 114312 122694 114308 114306 81056 106072 118574 97696