summaryrefslogtreecommitdiff
path: root/graphics/pstricks/contrib/pst-barcode/dvips/pst-barcode.pro
blob: 6a6c95c9779e6b40f6d8dbde6857a706c520dc2d (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
23312
23313
23314
23315
23316
23317
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
23333
23334
23335
23336
23337
23338
23339
23340
23341
23342
23343
23344
23345
23346
23347
23348
23349
23350
23351
23352
23353
23354
23355
23356
23357
23358
23359
23360
23361
23362
23363
23364
23365
23366
23367
23368
23369
23370
23371
23372
23373
23374
23375
23376
23377
23378
23379
23380
23381
23382
23383
23384
23385
23386
23387
23388
23389
23390
23391
23392
23393
23394
23395
23396
23397
23398
23399
23400
23401
23402
23403
23404
23405
23406
23407
23408
23409
23410
23411
23412
23413
23414
23415
23416
23417
23418
23419
23420
23421
23422
23423
23424
23425
23426
23427
23428
23429
23430
23431
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
23454
23455
23456
23457
23458
23459
23460
23461
23462
23463
23464
23465
23466
23467
23468
23469
23470
23471
23472
23473
23474
23475
23476
23477
23478
23479
23480
23481
23482
23483
23484
23485
23486
23487
23488
23489
23490
23491
23492
23493
23494
23495
23496
23497
23498
23499
23500
23501
23502
23503
23504
23505
23506
23507
23508
23509
23510
23511
23512
23513
23514
23515
23516
23517
23518
23519
23520
23521
23522
23523
23524
23525
23526
23527
23528
23529
23530
23531
23532
23533
23534
23535
23536
23537
23538
23539
23540
23541
23542
23543
23544
23545
23546
23547
23548
23549
23550
23551
23552
23553
23554
23555
23556
23557
23558
23559
23560
23561
23562
23563
23564
23565
23566
23567
23568
23569
23570
23571
23572
23573
23574
23575
23576
23577
23578
23579
23580
23581
23582
23583
23584
23585
23586
23587
23588
23589
23590
23591
23592
23593
23594
23595
23596
23597
23598
23599
23600
23601
23602
23603
23604
23605
23606
23607
23608
23609
23610
23611
23612
23613
23614
23615
23616
23617
23618
23619
23620
23621
23622
23623
23624
23625
23626
23627
23628
23629
23630
23631
23632
23633
23634
23635
23636
23637
23638
23639
23640
23641
23642
23643
23644
23645
23646
23647
23648
23649
23650
23651
23652
23653
23654
23655
23656
23657
23658
23659
23660
23661
23662
23663
23664
23665
23666
23667
23668
23669
23670
23671
23672
23673
23674
23675
23676
23677
23678
23679
23680
23681
23682
23683
23684
23685
23686
23687
23688
23689
23690
23691
23692
23693
23694
23695
23696
23697
23698
23699
23700
23701
23702
23703
23704
23705
23706
23707
23708
23709
23710
23711
23712
23713
23714
23715
23716
23717
23718
23719
23720
23721
23722
23723
23724
23725
23726
23727
23728
23729
23730
23731
23732
23733
23734
23735
23736
23737
23738
23739
23740
23741
23742
23743
23744
23745
23746
23747
23748
23749
23750
23751
23752
23753
23754
23755
23756
23757
23758
23759
23760
23761
23762
23763
23764
23765
23766
23767
23768
23769
23770
23771
23772
23773
23774
23775
23776
23777
23778
23779
23780
23781
23782
23783
23784
23785
23786
23787
23788
23789
23790
23791
23792
23793
23794
23795
23796
23797
23798
23799
23800
23801
23802
23803
23804
23805
23806
23807
23808
23809
23810
23811
23812
23813
23814
23815
23816
23817
23818
23819
23820
23821
23822
23823
23824
23825
23826
23827
23828
23829
23830
23831
23832
23833
23834
23835
23836
23837
23838
23839
23840
23841
23842
23843
23844
23845
23846
23847
23848
23849
23850
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
23866
23867
23868
23869
23870
23871
23872
23873
23874
23875
23876
23877
23878
23879
23880
23881
23882
23883
23884
23885
23886
23887
23888
23889
23890
23891
23892
23893
23894
23895
23896
23897
23898
23899
23900
23901
23902
23903
23904
23905
23906
23907
23908
23909
23910
23911
23912
23913
23914
23915
23916
23917
23918
23919
23920
23921
23922
23923
23924
23925
23926
23927
23928
23929
23930
23931
23932
23933
23934
23935
23936
23937
23938
23939
23940
23941
23942
23943
23944
23945
23946
23947
23948
23949
23950
23951
23952
23953
23954
23955
23956
23957
23958
23959
23960
23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986
23987
23988
23989
23990
23991
23992
23993
23994
23995
23996
23997
23998
23999
24000
24001
24002
24003
24004
24005
24006
24007
24008
24009
24010
24011
24012
24013
24014
24015
24016
24017
24018
24019
24020
24021
24022
24023
24024
24025
24026
24027
24028
24029
24030
24031
24032
24033
24034
24035
24036
24037
24038
24039
24040
24041
24042
24043
24044
24045
24046
24047
24048
24049
24050
24051
24052
24053
24054
24055
24056
24057
24058
24059
24060
24061
24062
24063
24064
24065
24066
24067
24068
24069
24070
24071
24072
24073
24074
24075
24076
24077
24078
24079
24080
24081
24082
24083
24084
24085
24086
24087
24088
24089
24090
24091
24092
24093
24094
24095
24096
24097
24098
24099
24100
24101
24102
24103
24104
24105
24106
24107
24108
24109
24110
24111
24112
24113
24114
24115
24116
24117
24118
24119
24120
24121
24122
24123
24124
24125
24126
24127
24128
24129
24130
24131
24132
24133
24134
24135
24136
24137
24138
24139
24140
24141
24142
24143
24144
24145
24146
24147
24148
24149
24150
24151
24152
24153
24154
24155
24156
24157
24158
24159
24160
24161
24162
24163
24164
24165
24166
24167
24168
24169
24170
24171
24172
24173
24174
24175
24176
24177
24178
24179
24180
24181
24182
24183
24184
24185
24186
24187
24188
24189
24190
24191
24192
24193
24194
24195
24196
24197
24198
24199
24200
24201
24202
24203
24204
24205
24206
24207
24208
24209
24210
24211
24212
24213
24214
24215
24216
24217
24218
24219
24220
24221
24222
24223
24224
24225
24226
24227
24228
24229
24230
24231
24232
24233
24234
24235
24236
24237
24238
24239
24240
24241
24242
24243
24244
24245
24246
24247
24248
24249
24250
24251
24252
24253
24254
24255
24256
24257
24258
24259
24260
24261
24262
24263
24264
24265
24266
24267
24268
24269
24270
24271
24272
24273
24274
24275
24276
24277
24278
24279
24280
24281
24282
24283
24284
24285
24286
24287
24288
24289
24290
24291
24292
24293
24294
24295
24296
24297
24298
24299
24300
24301
24302
24303
24304
24305
24306
24307
24308
24309
24310
24311
24312
24313
24314
24315
24316
24317
24318
24319
24320
24321
24322
24323
24324
24325
24326
24327
24328
24329
24330
24331
24332
24333
24334
24335
24336
24337
24338
24339
24340
24341
24342
24343
24344
24345
24346
24347
24348
24349
24350
24351
24352
24353
24354
24355
24356
24357
24358
24359
24360
24361
24362
24363
24364
24365
24366
24367
24368
24369
24370
24371
24372
24373
24374
24375
24376
24377
24378
24379
24380
24381
24382
24383
24384
24385
24386
24387
24388
24389
24390
24391
24392
24393
24394
24395
24396
24397
24398
24399
24400
24401
24402
24403
24404
24405
24406
24407
24408
24409
24410
24411
24412
24413
24414
24415
24416
24417
24418
24419
24420
24421
24422
24423
24424
24425
24426
24427
24428
24429
24430
24431
24432
24433
24434
24435
24436
24437
24438
24439
24440
24441
24442
24443
24444
24445
24446
24447
24448
24449
24450
24451
24452
24453
24454
24455
24456
24457
24458
24459
24460
24461
24462
24463
24464
24465
24466
24467
24468
24469
24470
24471
24472
24473
24474
24475
24476
24477
24478
24479
24480
24481
24482
24483
24484
24485
24486
24487
24488
24489
24490
24491
24492
24493
24494
24495
24496
24497
24498
24499
24500
24501
24502
24503
24504
24505
24506
24507
24508
24509
24510
24511
24512
24513
24514
24515
24516
24517
24518
24519
24520
24521
24522
24523
24524
24525
24526
24527
24528
24529
24530
24531
24532
24533
24534
24535
24536
24537
24538
24539
24540
24541
24542
24543
24544
24545
24546
24547
24548
24549
24550
24551
24552
24553
24554
24555
24556
24557
24558
24559
24560
24561
24562
24563
24564
24565
24566
24567
24568
24569
24570
24571
24572
24573
24574
24575
24576
24577
24578
24579
24580
24581
24582
24583
24584
24585
24586
24587
24588
24589
24590
24591
24592
24593
24594
24595
24596
24597
24598
24599
24600
24601
24602
24603
24604
24605
24606
24607
24608
24609
24610
24611
24612
24613
24614
24615
24616
24617
24618
24619
24620
24621
24622
24623
24624
24625
24626
24627
24628
24629
24630
24631
24632
24633
24634
24635
24636
24637
24638
24639
24640
24641
24642
24643
24644
24645
24646
24647
24648
24649
24650
24651
24652
24653
24654
24655
24656
24657
24658
24659
24660
24661
24662
24663
24664
24665
24666
24667
24668
24669
24670
24671
24672
24673
24674
24675
24676
24677
24678
24679
24680
24681
24682
24683
24684
24685
24686
24687
24688
24689
24690
24691
24692
24693
24694
24695
24696
24697
24698
24699
24700
24701
24702
24703
24704
24705
24706
24707
24708
24709
24710
24711
24712
24713
24714
24715
24716
24717
24718
24719
24720
24721
24722
24723
24724
24725
24726
24727
24728
24729
24730
24731
24732
24733
24734
24735
24736
24737
24738
24739
24740
24741
24742
24743
24744
24745
24746
24747
24748
24749
24750
24751
24752
24753
24754
24755
24756
24757
24758
24759
24760
24761
24762
24763
24764
24765
24766
24767
24768
24769
24770
24771
24772
24773
24774
24775
24776
24777
24778
24779
24780
24781
24782
24783
24784
24785
24786
24787
24788
24789
24790
24791
24792
24793
24794
24795
24796
24797
24798
24799
24800
24801
24802
24803
24804
24805
24806
24807
24808
24809
24810
24811
24812
24813
24814
24815
24816
24817
24818
24819
24820
24821
24822
24823
24824
24825
24826
24827
24828
24829
24830
24831
24832
24833
24834
24835
24836
24837
24838
24839
24840
24841
24842
24843
24844
24845
24846
24847
24848
24849
24850
24851
24852
24853
24854
24855
24856
24857
24858
24859
24860
24861
24862
24863
24864
24865
24866
24867
24868
24869
24870
24871
24872
24873
24874
24875
24876
24877
24878
24879
24880
24881
24882
24883
24884
24885
24886
24887
24888
24889
24890
24891
24892
24893
24894
24895
24896
24897
24898
24899
24900
24901
24902
24903
24904
24905
24906
24907
24908
24909
24910
24911
24912
24913
24914
24915
24916
24917
24918
24919
24920
24921
24922
24923
24924
24925
24926
24927
24928
24929
24930
24931
24932
24933
24934
24935
24936
24937
24938
24939
24940
24941
24942
24943
24944
24945
24946
24947
24948
24949
24950
24951
24952
24953
24954
24955
24956
24957
24958
24959
24960
24961
24962
24963
24964
24965
24966
24967
24968
24969
24970
24971
24972
24973
24974
24975
24976
24977
24978
24979
24980
24981
24982
24983
24984
24985
24986
24987
24988
24989
24990
24991
24992
24993
24994
24995
24996
24997
24998
24999
25000
25001
25002
25003
25004
25005
25006
25007
25008
25009
25010
25011
25012
25013
25014
25015
25016
25017
25018
25019
25020
25021
25022
25023
25024
25025
25026
25027
25028
25029
25030
25031
25032
25033
25034
25035
25036
25037
25038
25039
25040
25041
25042
25043
25044
25045
25046
25047
25048
25049
25050
25051
25052
25053
25054
25055
25056
25057
25058
25059
25060
25061
25062
25063
25064
25065
25066
25067
25068
25069
25070
25071
25072
25073
25074
25075
25076
25077
25078
25079
25080
25081
25082
25083
25084
25085
25086
25087
25088
25089
25090
25091
25092
25093
25094
25095
25096
25097
25098
25099
25100
25101
25102
25103
25104
25105
25106
25107
25108
25109
25110
25111
25112
25113
25114
25115
25116
25117
25118
25119
25120
25121
25122
25123
25124
25125
25126
25127
25128
25129
25130
25131
25132
25133
25134
25135
25136
25137
25138
25139
25140
25141
25142
25143
25144
25145
25146
25147
25148
25149
25150
25151
25152
25153
25154
25155
25156
25157
25158
25159
25160
25161
25162
25163
25164
25165
25166
25167
25168
25169
25170
25171
25172
25173
25174
25175
25176
25177
25178
25179
25180
25181
25182
25183
25184
25185
25186
25187
25188
25189
25190
25191
25192
25193
25194
25195
25196
25197
25198
25199
25200
25201
25202
25203
25204
25205
25206
25207
25208
25209
25210
25211
25212
25213
25214
25215
25216
25217
25218
25219
25220
25221
25222
25223
25224
25225
25226
25227
25228
25229
25230
25231
25232
25233
25234
25235
25236
25237
25238
25239
25240
25241
25242
25243
25244
25245
25246
25247
25248
25249
25250
25251
25252
25253
25254
25255
25256
25257
25258
25259
25260
25261
25262
25263
25264
25265
25266
25267
25268
25269
25270
25271
25272
25273
25274
25275
25276
25277
25278
25279
25280
25281
25282
25283
25284
25285
25286
25287
25288
25289
25290
25291
25292
25293
25294
25295
25296
25297
25298
25299
25300
25301
25302
25303
25304
25305
25306
25307
25308
25309
25310
25311
25312
25313
25314
25315
25316
25317
25318
25319
25320
25321
25322
25323
25324
25325
25326
25327
25328
25329
25330
25331
25332
25333
25334
25335
25336
25337
25338
25339
25340
25341
25342
25343
25344
25345
25346
25347
25348
25349
25350
25351
25352
25353
25354
25355
25356
25357
25358
25359
25360
25361
25362
25363
25364
25365
25366
25367
25368
25369
25370
25371
25372
25373
25374
25375
25376
25377
25378
25379
25380
25381
25382
25383
25384
25385
25386
25387
25388
25389
25390
25391
25392
25393
25394
25395
25396
25397
25398
25399
25400
25401
25402
25403
25404
25405
25406
25407
25408
25409
25410
25411
25412
25413
25414
25415
25416
25417
25418
25419
25420
25421
25422
25423
25424
25425
25426
25427
25428
25429
25430
25431
25432
25433
25434
25435
25436
25437
25438
25439
25440
25441
25442
25443
25444
25445
25446
25447
25448
25449
25450
25451
25452
25453
25454
25455
25456
25457
25458
25459
25460
25461
25462
25463
25464
25465
25466
25467
25468
25469
25470
25471
25472
25473
25474
25475
25476
25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
25522
25523
25524
25525
25526
25527
25528
25529
25530
25531
25532
25533
25534
25535
25536
25537
25538
25539
25540
25541
25542
25543
25544
25545
25546
25547
25548
25549
25550
25551
25552
25553
25554
25555
25556
25557
25558
25559
25560
25561
25562
25563
25564
25565
25566
25567
25568
25569
25570
25571
25572
25573
25574
25575
25576
25577
25578
25579
25580
25581
25582
25583
25584
25585
25586
25587
25588
25589
25590
25591
25592
25593
25594
25595
25596
25597
25598
25599
25600
25601
25602
25603
25604
25605
25606
25607
25608
25609
25610
25611
25612
25613
25614
25615
25616
25617
25618
25619
25620
25621
25622
25623
25624
25625
25626
25627
25628
25629
25630
25631
25632
25633
25634
25635
25636
25637
25638
25639
25640
25641
25642
25643
25644
25645
25646
25647
25648
25649
25650
25651
25652
25653
25654
25655
25656
25657
25658
25659
25660
25661
25662
25663
25664
25665
25666
25667
25668
25669
25670
25671
25672
25673
25674
25675
25676
25677
25678
25679
25680
25681
25682
25683
25684
25685
25686
25687
25688
25689
25690
25691
25692
25693
25694
25695
25696
25697
25698
25699
25700
25701
25702
25703
25704
25705
25706
25707
25708
25709
25710
25711
25712
25713
25714
25715
25716
25717
25718
25719
25720
25721
25722
25723
25724
25725
25726
25727
25728
25729
25730
25731
25732
25733
25734
25735
25736
25737
25738
25739
25740
25741
25742
25743
25744
25745
25746
25747
25748
25749
25750
25751
25752
25753
25754
25755
25756
25757
25758
25759
25760
25761
25762
25763
25764
25765
25766
25767
25768
25769
25770
25771
25772
25773
25774
25775
25776
25777
25778
25779
25780
25781
25782
25783
25784
25785
25786
25787
25788
25789
25790
25791
25792
25793
25794
25795
25796
25797
25798
25799
25800
25801
25802
25803
25804
25805
25806
25807
25808
25809
25810
25811
25812
25813
25814
25815
25816
25817
25818
25819
25820
25821
25822
25823
25824
25825
25826
25827
25828
25829
25830
25831
25832
25833
25834
25835
25836
25837
25838
25839
25840
25841
25842
25843
25844
25845
25846
25847
25848
25849
25850
25851
25852
25853
25854
25855
25856
25857
25858
25859
25860
25861
25862
25863
25864
25865
25866
25867
25868
25869
25870
25871
25872
25873
25874
25875
25876
25877
25878
25879
25880
25881
25882
25883
25884
25885
25886
25887
25888
25889
25890
25891
25892
25893
25894
25895
25896
25897
25898
25899
25900
25901
25902
25903
25904
25905
25906
25907
25908
25909
25910
25911
25912
25913
25914
25915
25916
25917
25918
25919
25920
25921
25922
25923
25924
25925
25926
25927
25928
25929
25930
25931
25932
25933
25934
25935
25936
25937
25938
25939
25940
25941
25942
25943
25944
25945
25946
25947
25948
25949
25950
25951
25952
25953
25954
25955
25956
25957
25958
25959
25960
25961
25962
25963
25964
25965
25966
25967
25968
25969
25970
25971
25972
25973
25974
25975
25976
25977
25978
25979
25980
25981
25982
25983
25984
25985
25986
25987
25988
25989
25990
25991
25992
25993
25994
25995
25996
25997
25998
25999
26000
26001
26002
26003
26004
26005
26006
26007
26008
26009
26010
26011
26012
26013
26014
26015
26016
26017
26018
26019
26020
26021
26022
26023
26024
26025
26026
26027
26028
26029
26030
26031
26032
26033
26034
26035
26036
26037
26038
26039
26040
26041
26042
26043
26044
26045
26046
26047
26048
26049
26050
26051
26052
26053
26054
26055
26056
26057
26058
26059
26060
26061
26062
26063
26064
26065
26066
26067
26068
26069
26070
26071
26072
26073
26074
26075
26076
26077
26078
26079
26080
26081
26082
26083
26084
26085
26086
26087
26088
26089
26090
26091
26092
26093
26094
26095
26096
26097
26098
26099
26100
26101
26102
26103
26104
26105
26106
26107
26108
26109
26110
26111
26112
26113
26114
26115
26116
26117
26118
26119
26120
26121
26122
26123
26124
26125
26126
26127
26128
26129
26130
26131
26132
26133
26134
26135
26136
26137
26138
26139
26140
26141
26142
26143
26144
26145
26146
26147
26148
26149
26150
26151
26152
26153
26154
26155
26156
26157
26158
26159
26160
26161
26162
26163
26164
26165
26166
26167
26168
26169
26170
26171
26172
26173
26174
26175
26176
26177
26178
26179
26180
26181
26182
26183
26184
26185
26186
26187
26188
26189
26190
26191
26192
26193
26194
26195
26196
26197
26198
26199
26200
26201
26202
26203
26204
26205
26206
26207
26208
26209
26210
26211
26212
26213
26214
26215
26216
26217
26218
26219
26220
26221
26222
26223
26224
26225
26226
26227
26228
26229
26230
26231
26232
26233
26234
26235
26236
26237
26238
26239
26240
26241
26242
26243
26244
26245
26246
26247
26248
26249
26250
26251
26252
26253
26254
26255
26256
26257
26258
26259
26260
26261
26262
26263
26264
26265
26266
26267
26268
26269
26270
26271
26272
26273
26274
26275
26276
26277
26278
26279
26280
26281
26282
26283
26284
26285
26286
26287
26288
26289
26290
26291
26292
26293
26294
26295
26296
26297
26298
26299
26300
26301
26302
26303
26304
26305
26306
26307
26308
26309
26310
26311
26312
26313
26314
26315
26316
26317
26318
26319
26320
26321
26322
26323
26324
26325
26326
26327
26328
26329
26330
26331
26332
26333
26334
26335
26336
26337
26338
26339
26340
26341
26342
26343
26344
26345
26346
26347
26348
26349
26350
26351
26352
26353
26354
26355
26356
26357
26358
26359
26360
26361
26362
26363
26364
26365
26366
26367
26368
26369
26370
26371
26372
26373
26374
26375
26376
26377
26378
26379
26380
26381
26382
26383
26384
26385
26386
26387
26388
26389
26390
26391
26392
26393
26394
26395
26396
26397
26398
26399
26400
26401
26402
26403
26404
26405
26406
26407
26408
26409
26410
26411
26412
26413
26414
26415
26416
26417
26418
26419
26420
26421
26422
26423
26424
26425
26426
26427
26428
26429
26430
26431
26432
26433
26434
26435
26436
26437
26438
26439
26440
26441
26442
26443
26444
26445
26446
26447
26448
26449
26450
26451
26452
26453
26454
26455
26456
26457
26458
26459
26460
26461
26462
26463
26464
26465
26466
26467
26468
26469
26470
26471
26472
26473
26474
26475
26476
26477
26478
26479
26480
26481
26482
26483
26484
26485
26486
26487
26488
26489
26490
26491
26492
26493
26494
26495
26496
26497
26498
26499
26500
26501
26502
26503
26504
26505
26506
26507
26508
26509
26510
26511
26512
26513
26514
26515
26516
26517
26518
26519
26520
26521
26522
26523
26524
26525
26526
26527
26528
26529
26530
26531
26532
26533
26534
26535
26536
26537
26538
26539
26540
26541
26542
26543
26544
26545
26546
26547
26548
26549
26550
26551
26552
26553
26554
26555
26556
26557
26558
26559
26560
26561
26562
26563
26564
26565
26566
26567
26568
26569
26570
26571
26572
26573
26574
26575
26576
26577
26578
26579
26580
26581
26582
26583
26584
26585
26586
26587
26588
26589
26590
26591
26592
26593
26594
26595
26596
26597
26598
26599
26600
26601
26602
26603
26604
26605
26606
26607
26608
26609
26610
26611
26612
26613
26614
26615
26616
26617
26618
26619
26620
26621
26622
26623
26624
26625
26626
26627
26628
26629
26630
26631
26632
26633
26634
26635
26636
26637
26638
26639
26640
26641
26642
26643
26644
26645
26646
26647
26648
26649
26650
26651
26652
26653
26654
26655
26656
26657
26658
26659
26660
26661
26662
26663
26664
26665
26666
26667
26668
26669
26670
26671
26672
26673
26674
26675
26676
26677
26678
26679
26680
26681
26682
26683
26684
26685
26686
26687
26688
26689
26690
26691
26692
26693
26694
26695
26696
26697
26698
26699
26700
26701
26702
26703
26704
26705
26706
26707
26708
26709
26710
26711
26712
26713
26714
26715
26716
26717
26718
26719
26720
26721
26722
26723
26724
26725
26726
26727
26728
26729
26730
26731
26732
26733
26734
26735
26736
26737
26738
26739
26740
26741
26742
26743
26744
26745
26746
26747
26748
26749
26750
26751
26752
26753
26754
26755
26756
26757
26758
26759
26760
26761
26762
26763
26764
26765
26766
26767
26768
26769
26770
26771
26772
26773
26774
26775
26776
26777
26778
26779
26780
26781
26782
26783
26784
26785
26786
26787
26788
26789
26790
26791
26792
26793
26794
26795
26796
26797
26798
26799
26800
26801
26802
26803
26804
26805
26806
26807
26808
26809
26810
26811
26812
26813
26814
26815
26816
26817
26818
26819
26820
26821
26822
26823
26824
26825
26826
26827
26828
26829
26830
26831
26832
26833
26834
26835
26836
26837
26838
26839
26840
26841
26842
26843
26844
26845
26846
26847
26848
26849
26850
26851
26852
26853
26854
26855
26856
26857
26858
26859
26860
26861
26862
26863
26864
26865
26866
26867
26868
26869
26870
26871
26872
26873
26874
26875
26876
26877
26878
26879
26880
26881
26882
26883
26884
26885
26886
26887
26888
26889
26890
26891
26892
26893
26894
26895
26896
26897
26898
26899
26900
26901
26902
26903
26904
26905
26906
26907
26908
26909
26910
26911
26912
26913
26914
26915
26916
26917
26918
26919
26920
26921
26922
26923
26924
26925
26926
26927
26928
26929
26930
26931
26932
26933
26934
26935
26936
26937
26938
26939
26940
26941
26942
26943
26944
26945
26946
26947
26948
26949
26950
26951
26952
26953
26954
26955
26956
26957
26958
26959
26960
26961
26962
26963
26964
26965
26966
26967
26968
26969
26970
26971
26972
26973
26974
26975
26976
26977
26978
26979
26980
26981
26982
26983
26984
26985
26986
26987
26988
26989
26990
26991
26992
26993
26994
26995
26996
26997
26998
26999
27000
27001
27002
27003
27004
27005
27006
27007
27008
27009
27010
27011
27012
27013
27014
27015
27016
27017
27018
27019
27020
27021
27022
27023
27024
27025
27026
27027
27028
27029
27030
27031
27032
27033
27034
27035
27036
27037
27038
27039
27040
27041
27042
27043
27044
27045
27046
27047
27048
27049
27050
27051
27052
27053
27054
27055
27056
27057
27058
27059
27060
27061
27062
27063
27064
27065
27066
27067
27068
27069
27070
27071
27072
27073
27074
27075
27076
27077
27078
27079
27080
27081
27082
27083
27084
27085
27086
27087
27088
27089
27090
27091
27092
27093
27094
27095
27096
27097
27098
27099
27100
27101
27102
27103
27104
27105
27106
27107
27108
27109
27110
27111
27112
27113
27114
27115
27116
27117
27118
27119
27120
27121
27122
27123
27124
27125
27126
27127
27128
27129
27130
27131
27132
27133
27134
27135
27136
27137
27138
27139
27140
27141
27142
27143
27144
27145
27146
27147
27148
27149
27150
27151
27152
27153
27154
27155
27156
27157
27158
27159
27160
27161
27162
27163
27164
27165
27166
27167
27168
27169
27170
27171
27172
27173
27174
27175
27176
27177
27178
27179
27180
27181
27182
27183
27184
27185
27186
27187
27188
27189
27190
27191
27192
27193
27194
27195
27196
27197
27198
27199
27200
27201
27202
27203
27204
27205
27206
27207
27208
27209
27210
27211
27212
27213
27214
27215
27216
27217
27218
27219
27220
27221
27222
27223
27224
27225
27226
27227
27228
27229
27230
27231
27232
27233
27234
27235
27236
27237
27238
27239
27240
27241
27242
27243
27244
27245
27246
27247
27248
27249
27250
27251
27252
27253
27254
27255
27256
27257
27258
27259
27260
27261
27262
27263
27264
27265
27266
27267
27268
27269
27270
27271
27272
27273
27274
27275
27276
27277
27278
27279
27280
27281
27282
27283
27284
27285
27286
27287
27288
27289
27290
27291
27292
27293
27294
27295
27296
27297
27298
27299
27300
27301
27302
27303
27304
27305
27306
27307
27308
27309
27310
27311
27312
27313
27314
27315
27316
27317
27318
27319
27320
27321
27322
27323
27324
27325
27326
27327
27328
27329
27330
27331
27332
27333
27334
27335
27336
27337
27338
27339
27340
27341
27342
27343
27344
27345
27346
27347
27348
27349
27350
27351
27352
27353
27354
27355
27356
27357
27358
27359
27360
27361
27362
27363
27364
27365
27366
27367
27368
27369
27370
27371
27372
27373
27374
27375
27376
27377
27378
27379
27380
27381
27382
27383
27384
27385
27386
27387
27388
27389
27390
27391
27392
27393
27394
27395
27396
27397
27398
27399
27400
27401
27402
27403
27404
27405
27406
27407
27408
27409
27410
27411
27412
27413
27414
27415
27416
27417
27418
27419
27420
27421
27422
27423
27424
27425
27426
27427
27428
27429
27430
27431
27432
27433
27434
27435
27436
27437
27438
27439
27440
27441
27442
27443
27444
27445
27446
27447
27448
27449
27450
27451
27452
27453
27454
27455
27456
27457
27458
27459
27460
27461
27462
27463
27464
27465
27466
27467
27468
27469
27470
27471
27472
27473
27474
27475
27476
27477
27478
27479
27480
27481
27482
27483
27484
27485
27486
27487
27488
27489
27490
27491
27492
27493
27494
27495
27496
27497
27498
27499
27500
27501
27502
27503
27504
27505
27506
27507
27508
27509
27510
27511
27512
27513
27514
27515
27516
27517
27518
27519
27520
27521
27522
27523
27524
27525
27526
27527
27528
27529
27530
27531
27532
27533
27534
27535
27536
27537
27538
27539
27540
27541
27542
27543
27544
27545
27546
27547
27548
27549
27550
27551
27552
27553
27554
27555
27556
27557
27558
27559
27560
27561
27562
27563
27564
27565
27566
27567
27568
27569
27570
27571
27572
27573
27574
27575
27576
27577
27578
27579
27580
27581
27582
27583
27584
27585
27586
27587
27588
27589
27590
27591
27592
27593
27594
27595
27596
27597
27598
27599
27600
27601
27602
27603
27604
27605
27606
27607
27608
27609
27610
27611
27612
27613
27614
27615
27616
27617
27618
27619
27620
27621
27622
27623
27624
27625
27626
27627
27628
27629
27630
27631
27632
27633
27634
27635
27636
27637
27638
27639
27640
27641
27642
27643
27644
27645
27646
27647
27648
27649
27650
27651
27652
27653
27654
27655
27656
27657
27658
27659
27660
27661
27662
27663
27664
27665
27666
27667
27668
27669
27670
27671
27672
27673
27674
27675
27676
27677
27678
27679
27680
27681
27682
27683
27684
27685
27686
27687
27688
27689
27690
27691
27692
27693
27694
27695
27696
27697
27698
27699
27700
27701
27702
27703
27704
27705
27706
27707
27708
27709
27710
27711
27712
27713
27714
27715
27716
27717
27718
27719
27720
27721
27722
27723
27724
27725
27726
27727
27728
27729
27730
27731
27732
27733
27734
27735
27736
27737
27738
27739
27740
27741
27742
27743
27744
27745
27746
27747
27748
27749
27750
27751
27752
27753
27754
27755
27756
27757
27758
27759
27760
27761
27762
27763
27764
27765
27766
27767
27768
27769
27770
27771
27772
27773
27774
27775
27776
27777
27778
27779
27780
27781
27782
27783
27784
27785
27786
27787
27788
27789
27790
27791
27792
27793
27794
27795
27796
27797
27798
27799
27800
27801
27802
27803
27804
27805
27806
27807
27808
27809
27810
27811
27812
27813
27814
27815
27816
27817
27818
27819
27820
27821
27822
27823
27824
27825
27826
27827
27828
27829
27830
27831
27832
27833
27834
27835
27836
27837
27838
27839
27840
27841
27842
27843
27844
27845
27846
27847
27848
27849
27850
27851
27852
27853
27854
27855
27856
27857
27858
27859
27860
27861
27862
27863
27864
27865
27866
27867
27868
27869
27870
27871
27872
27873
27874
27875
27876
27877
27878
27879
27880
27881
27882
27883
27884
27885
27886
27887
27888
27889
27890
27891
27892
27893
27894
27895
27896
27897
27898
27899
27900
27901
27902
27903
27904
27905
27906
27907
27908
27909
27910
27911
27912
27913
27914
27915
27916
27917
27918
27919
27920
27921
27922
27923
27924
27925
27926
27927
27928
27929
27930
27931
27932
27933
27934
27935
27936
27937
27938
27939
27940
27941
27942
27943
27944
27945
27946
27947
27948
27949
27950
27951
27952
27953
27954
27955
27956
27957
27958
27959
27960
27961
27962
27963
27964
27965
27966
27967
27968
27969
27970
27971
27972
27973
27974
27975
27976
27977
27978
27979
27980
27981
27982
27983
27984
27985
27986
27987
27988
27989
27990
27991
27992
27993
27994
27995
27996
27997
27998
27999
28000
28001
28002
28003
28004
28005
28006
28007
28008
28009
28010
28011
28012
28013
28014
28015
28016
28017
28018
28019
28020
28021
28022
28023
28024
28025
28026
28027
28028
28029
28030
28031
28032
28033
28034
28035
28036
28037
28038
28039
28040
28041
28042
28043
28044
28045
28046
28047
28048
28049
28050
28051
28052
28053
28054
28055
28056
28057
28058
28059
28060
28061
28062
28063
28064
28065
28066
28067
28068
28069
28070
28071
28072
28073
28074
28075
28076
28077
28078
28079
28080
28081
28082
28083
28084
28085
28086
28087
28088
28089
28090
28091
28092
28093
28094
28095
28096
28097
28098
28099
28100
28101
28102
28103
28104
28105
28106
28107
28108
28109
28110
28111
28112
28113
28114
28115
28116
28117
28118
28119
28120
28121
28122
28123
28124
28125
28126
28127
28128
28129
28130
28131
28132
28133
28134
28135
28136
28137
28138
28139
28140
28141
28142
28143
28144
28145
28146
28147
28148
28149
28150
28151
28152
28153
28154
28155
28156
28157
28158
28159
28160
28161
28162
28163
28164
28165
28166
28167
28168
28169
28170
28171
28172
28173
28174
28175
28176
28177
28178
28179
28180
28181
28182
28183
28184
28185
28186
28187
28188
28189
28190
28191
28192
28193
28194
28195
28196
28197
28198
28199
28200
28201
28202
28203
28204
28205
28206
28207
28208
28209
28210
28211
28212
28213
28214
28215
28216
28217
28218
28219
28220
28221
28222
28223
28224
28225
28226
28227
28228
28229
28230
28231
28232
28233
28234
28235
28236
28237
28238
28239
28240
28241
28242
28243
28244
28245
28246
28247
28248
28249
28250
28251
28252
28253
28254
28255
28256
28257
28258
28259
28260
28261
28262
28263
28264
28265
28266
28267
28268
28269
28270
28271
28272
28273
28274
28275
28276
28277
28278
28279
28280
28281
28282
28283
28284
28285
28286
28287
28288
28289
28290
28291
28292
28293
28294
28295
28296
28297
28298
28299
28300
28301
28302
28303
28304
28305
28306
28307
28308
28309
28310
28311
28312
28313
28314
28315
28316
28317
28318
28319
28320
28321
28322
28323
28324
28325
28326
28327
28328
28329
28330
28331
28332
28333
28334
28335
28336
28337
28338
28339
28340
28341
28342
28343
28344
28345
28346
28347
28348
28349
28350
28351
28352
28353
28354
28355
28356
28357
28358
28359
28360
28361
28362
28363
28364
28365
28366
28367
28368
28369
28370
28371
28372
28373
28374
28375
28376
28377
28378
28379
28380
28381
28382
28383
28384
28385
28386
28387
28388
28389
28390
28391
28392
28393
28394
28395
28396
28397
28398
28399
28400
28401
28402
28403
28404
28405
28406
28407
28408
28409
28410
28411
28412
28413
28414
28415
28416
28417
28418
28419
28420
28421
28422
28423
28424
28425
28426
28427
28428
28429
28430
28431
28432
28433
28434
28435
28436
28437
28438
28439
28440
28441
28442
28443
28444
28445
28446
28447
28448
28449
28450
28451
28452
28453
28454
28455
28456
28457
28458
28459
28460
28461
28462
28463
28464
28465
28466
28467
28468
28469
28470
28471
28472
28473
28474
28475
28476
28477
28478
28479
28480
28481
28482
28483
28484
28485
28486
28487
28488
28489
28490
28491
28492
28493
28494
28495
28496
28497
28498
28499
28500
28501
28502
28503
28504
28505
28506
28507
28508
28509
28510
28511
28512
28513
28514
28515
28516
28517
28518
28519
28520
28521
28522
28523
28524
28525
28526
28527
28528
28529
28530
28531
28532
28533
28534
28535
28536
28537
28538
28539
28540
28541
28542
28543
28544
28545
28546
28547
28548
28549
28550
28551
28552
28553
28554
28555
28556
28557
28558
28559
28560
28561
28562
28563
28564
28565
28566
28567
28568
28569
28570
28571
28572
28573
28574
28575
28576
28577
28578
28579
28580
28581
28582
28583
28584
28585
28586
28587
28588
28589
28590
28591
28592
28593
28594
28595
28596
28597
28598
28599
28600
28601
28602
28603
28604
28605
28606
28607
28608
28609
28610
28611
28612
28613
28614
28615
28616
28617
28618
28619
28620
28621
28622
28623
28624
28625
28626
28627
28628
28629
28630
28631
28632
28633
28634
28635
28636
28637
28638
28639
28640
28641
28642
28643
28644
28645
28646
28647
28648
28649
28650
28651
28652
28653
28654
28655
28656
28657
28658
28659
28660
28661
28662
28663
28664
28665
28666
28667
28668
28669
28670
28671
28672
28673
28674
28675
28676
28677
28678
28679
28680
28681
28682
28683
28684
28685
28686
28687
28688
28689
28690
28691
28692
28693
28694
28695
28696
28697
28698
28699
28700
28701
28702
28703
28704
28705
28706
28707
28708
28709
28710
28711
28712
28713
28714
28715
28716
28717
28718
28719
28720
28721
28722
28723
28724
28725
28726
28727
28728
28729
28730
28731
28732
28733
28734
28735
28736
28737
28738
28739
28740
28741
28742
28743
28744
28745
28746
28747
28748
28749
28750
28751
28752
28753
28754
28755
28756
28757
28758
28759
28760
28761
28762
28763
28764
28765
28766
28767
28768
28769
28770
28771
28772
28773
28774
28775
28776
28777
28778
28779
28780
28781
28782
28783
28784
28785
28786
28787
28788
28789
28790
28791
28792
28793
28794
28795
28796
28797
28798
28799
28800
28801
28802
28803
28804
28805
28806
28807
28808
28809
28810
28811
28812
28813
28814
28815
28816
28817
28818
28819
28820
28821
28822
28823
28824
28825
28826
28827
28828
28829
28830
28831
28832
28833
28834
28835
28836
28837
28838
28839
28840
28841
28842
28843
28844
28845
28846
28847
28848
28849
28850
28851
28852
28853
28854
28855
28856
28857
28858
28859
28860
28861
28862
28863
28864
28865
28866
28867
28868
28869
28870
28871
28872
28873
28874
28875
28876
28877
28878
28879
28880
28881
28882
28883
28884
28885
28886
28887
28888
28889
28890
28891
28892
28893
28894
28895
28896
28897
28898
28899
28900
28901
28902
28903
28904
28905
28906
28907
28908
28909
28910
28911
28912
28913
28914
28915
28916
28917
28918
28919
28920
28921
28922
28923
28924
28925
28926
28927
28928
28929
28930
28931
28932
28933
28934
28935
28936
28937
28938
28939
28940
28941
28942
28943
28944
28945
28946
28947
28948
28949
28950
28951
28952
28953
28954
28955
28956
28957
28958
28959
28960
28961
28962
28963
28964
28965
28966
28967
28968
28969
28970
28971
28972
28973
28974
28975
28976
28977
28978
28979
28980
28981
28982
28983
28984
28985
28986
28987
28988
28989
28990
28991
28992
28993
28994
28995
28996
28997
28998
28999
29000
29001
29002
29003
29004
29005
29006
29007
29008
29009
29010
29011
29012
29013
29014
29015
29016
29017
29018
29019
29020
29021
29022
29023
29024
29025
29026
29027
29028
29029
29030
29031
29032
29033
29034
29035
29036
29037
29038
29039
29040
29041
29042
29043
29044
29045
29046
29047
29048
29049
29050
29051
29052
29053
29054
29055
29056
29057
29058
29059
29060
29061
29062
29063
29064
29065
29066
29067
29068
29069
29070
29071
29072
29073
29074
29075
29076
29077
29078
29079
29080
29081
29082
29083
29084
29085
29086
29087
29088
29089
29090
29091
29092
29093
29094
29095
29096
29097
29098
29099
29100
29101
29102
29103
29104
29105
29106
29107
29108
29109
29110
29111
29112
29113
29114
29115
29116
29117
29118
29119
29120
29121
29122
29123
29124
29125
29126
29127
29128
29129
29130
29131
29132
29133
29134
29135
29136
29137
29138
29139
29140
29141
29142
29143
29144
29145
29146
29147
29148
29149
29150
29151
29152
29153
29154
29155
29156
29157
29158
29159
29160
29161
29162
29163
29164
29165
29166
29167
29168
29169
29170
29171
29172
29173
29174
29175
29176
29177
29178
29179
29180
29181
29182
29183
29184
29185
29186
29187
29188
29189
29190
29191
29192
29193
29194
29195
29196
29197
29198
29199
29200
29201
29202
29203
29204
29205
29206
29207
29208
29209
29210
29211
29212
29213
29214
29215
29216
29217
29218
29219
29220
29221
29222
29223
29224
29225
29226
29227
29228
29229
29230
29231
29232
29233
29234
29235
29236
29237
29238
29239
29240
29241
29242
29243
29244
29245
29246
29247
29248
29249
29250
29251
29252
29253
29254
29255
29256
29257
29258
29259
29260
29261
29262
29263
29264
29265
29266
29267
29268
29269
29270
29271
29272
29273
29274
29275
29276
29277
29278
29279
29280
29281
29282
29283
29284
29285
29286
29287
29288
29289
29290
29291
29292
29293
29294
29295
29296
29297
29298
29299
29300
29301
29302
29303
29304
29305
29306
29307
29308
29309
29310
29311
29312
29313
29314
29315
29316
29317
29318
29319
29320
29321
29322
29323
29324
29325
29326
29327
29328
29329
29330
29331
29332
29333
29334
29335
29336
29337
29338
29339
29340
29341
29342
29343
29344
29345
29346
29347
29348
29349
29350
29351
29352
29353
29354
29355
29356
29357
29358
29359
29360
29361
29362
29363
29364
29365
29366
29367
29368
29369
29370
29371
29372
29373
29374
29375
29376
29377
29378
29379
29380
29381
29382
29383
29384
29385
29386
29387
29388
29389
29390
29391
29392
29393
29394
29395
29396
29397
29398
29399
29400
29401
29402
29403
29404
29405
29406
29407
29408
29409
29410
29411
29412
29413
29414
29415
29416
29417
29418
29419
29420
29421
29422
29423
29424
29425
29426
29427
29428
29429
29430
29431
29432
29433
29434
29435
29436
29437
29438
29439
29440
29441
29442
29443
29444
29445
29446
29447
29448
29449
29450
29451
29452
29453
29454
29455
29456
29457
29458
29459
29460
29461
29462
29463
29464
29465
29466
29467
29468
29469
29470
29471
29472
29473
29474
29475
29476
29477
29478
29479
29480
29481
29482
29483
29484
29485
29486
29487
29488
29489
29490
29491
29492
29493
29494
29495
29496
29497
29498
29499
29500
29501
29502
29503
29504
29505
29506
29507
29508
29509
29510
29511
29512
29513
29514
29515
29516
29517
29518
29519
29520
29521
29522
29523
29524
29525
29526
29527
29528
29529
29530
29531
29532
29533
29534
29535
29536
29537
29538
29539
29540
29541
29542
29543
29544
29545
29546
29547
29548
29549
29550
29551
29552
29553
29554
29555
29556
29557
29558
29559
29560
29561
29562
29563
29564
29565
29566
29567
29568
29569
29570
29571
29572
29573
29574
29575
29576
29577
29578
29579
29580
29581
29582
29583
29584
29585
29586
29587
29588
29589
29590
29591
29592
29593
29594
29595
29596
29597
29598
29599
29600
29601
29602
29603
29604
29605
29606
29607
29608
29609
29610
29611
29612
29613
29614
29615
29616
29617
29618
29619
29620
29621
29622
29623
29624
29625
29626
29627
29628
29629
29630
29631
29632
29633
29634
29635
29636
29637
29638
29639
29640
29641
29642
29643
29644
29645
29646
29647
29648
29649
29650
29651
29652
29653
29654
29655
29656
29657
29658
29659
29660
29661
29662
29663
29664
29665
29666
29667
29668
29669
29670
29671
29672
29673
29674
29675
29676
29677
29678
29679
29680
29681
29682
29683
29684
29685
29686
29687
29688
29689
29690
29691
29692
29693
29694
29695
29696
29697
29698
29699
29700
29701
29702
29703
29704
29705
29706
29707
29708
29709
29710
29711
29712
29713
29714
29715
29716
29717
29718
29719
29720
29721
29722
29723
29724
29725
29726
29727
29728
29729
29730
29731
29732
29733
29734
29735
29736
29737
29738
29739
29740
29741
29742
29743
29744
29745
29746
29747
29748
29749
29750
29751
29752
29753
29754
29755
29756
29757
29758
29759
29760
29761
29762
29763
29764
29765
29766
29767
29768
29769
29770
29771
29772
29773
29774
29775
29776
29777
29778
29779
29780
29781
29782
29783
29784
29785
29786
29787
29788
29789
29790
29791
29792
29793
29794
29795
29796
29797
29798
29799
29800
29801
29802
29803
29804
29805
29806
29807
29808
29809
29810
29811
29812
29813
29814
29815
29816
29817
29818
29819
29820
29821
29822
29823
29824
29825
29826
29827
29828
29829
29830
29831
29832
29833
29834
29835
29836
29837
29838
29839
29840
29841
29842
29843
29844
29845
29846
29847
29848
29849
29850
29851
29852
29853
29854
29855
29856
29857
29858
29859
29860
29861
29862
29863
29864
29865
29866
29867
29868
29869
29870
29871
29872
29873
29874
29875
29876
29877
29878
29879
29880
29881
29882
29883
29884
29885
29886
29887
29888
29889
29890
29891
29892
29893
29894
29895
29896
29897
29898
29899
29900
29901
29902
29903
29904
29905
29906
29907
29908
29909
29910
29911
29912
29913
29914
29915
29916
29917
29918
29919
29920
29921
29922
29923
29924
29925
29926
29927
29928
29929
29930
29931
29932
29933
29934
29935
29936
29937
29938
29939
29940
29941
29942
29943
29944
29945
29946
29947
29948
29949
29950
29951
29952
29953
29954
29955
29956
29957
29958
29959
29960
29961
29962
29963
29964
29965
29966
29967
29968
29969
29970
29971
29972
29973
29974
29975
29976
29977
29978
29979
29980
29981
29982
29983
29984
29985
29986
29987
29988
29989
29990
29991
29992
29993
29994
29995
29996
29997
29998
29999
30000
30001
30002
30003
30004
30005
30006
30007
30008
30009
30010
30011
30012
30013
30014
30015
30016
30017
30018
30019
30020
30021
30022
30023
30024
30025
30026
30027
30028
30029
30030
30031
30032
30033
30034
30035
30036
30037
30038
30039
30040
30041
30042
30043
30044
30045
30046
30047
30048
30049
30050
30051
30052
30053
30054
30055
30056
30057
30058
30059
30060
30061
30062
30063
30064
30065
30066
30067
30068
30069
30070
30071
30072
30073
30074
30075
30076
30077
30078
30079
30080
30081
30082
30083
30084
30085
30086
30087
30088
30089
30090
30091
30092
30093
30094
30095
30096
30097
30098
30099
30100
30101
30102
30103
30104
30105
30106
30107
30108
30109
30110
30111
30112
30113
30114
30115
30116
30117
30118
30119
30120
30121
30122
30123
30124
30125
30126
30127
30128
30129
30130
30131
30132
30133
30134
30135
30136
30137
30138
30139
30140
30141
30142
30143
30144
30145
30146
30147
30148
30149
30150
30151
30152
30153
30154
30155
30156
30157
30158
30159
30160
30161
30162
30163
30164
30165
30166
30167
30168
30169
30170
30171
30172
30173
30174
30175
30176
30177
30178
30179
30180
30181
30182
30183
30184
30185
30186
30187
30188
30189
30190
30191
30192
30193
30194
30195
30196
30197
30198
30199
30200
30201
30202
30203
30204
30205
30206
30207
30208
30209
30210
30211
30212
30213
30214
30215
30216
30217
30218
30219
30220
30221
30222
30223
30224
30225
30226
30227
30228
30229
30230
30231
30232
30233
30234
30235
30236
30237
30238
30239
30240
30241
30242
30243
30244
30245
30246
30247
30248
30249
30250
30251
30252
30253
30254
30255
30256
30257
30258
30259
30260
30261
30262
30263
30264
30265
30266
30267
30268
30269
30270
30271
30272
30273
30274
30275
30276
30277
30278
30279
30280
30281
30282
30283
30284
30285
30286
30287
30288
30289
30290
30291
30292
30293
30294
30295
30296
30297
30298
30299
30300
30301
30302
30303
30304
30305
30306
30307
30308
30309
30310
30311
30312
30313
30314
30315
30316
30317
30318
30319
30320
30321
30322
30323
30324
30325
30326
30327
30328
30329
30330
30331
30332
30333
30334
30335
30336
30337
30338
30339
30340
30341
30342
30343
30344
30345
30346
30347
30348
30349
30350
30351
30352
30353
30354
30355
30356
30357
30358
30359
30360
30361
30362
30363
30364
30365
30366
30367
30368
30369
30370
30371
30372
30373
30374
30375
30376
30377
30378
30379
30380
30381
30382
30383
30384
30385
30386
30387
30388
30389
30390
30391
30392
30393
30394
30395
30396
30397
30398
30399
30400
30401
30402
30403
30404
30405
30406
30407
30408
30409
30410
30411
30412
30413
30414
30415
30416
30417
30418
30419
30420
30421
30422
30423
30424
30425
30426
30427
30428
30429
30430
30431
30432
30433
30434
30435
30436
30437
30438
30439
30440
30441
30442
30443
30444
30445
30446
30447
30448
30449
30450
30451
30452
30453
30454
30455
30456
30457
30458
30459
30460
30461
30462
30463
30464
30465
30466
30467
30468
30469
30470
30471
30472
30473
30474
30475
30476
30477
30478
30479
30480
30481
30482
30483
30484
30485
30486
30487
30488
30489
30490
30491
30492
30493
30494
30495
30496
30497
30498
30499
30500
30501
30502
30503
30504
30505
30506
30507
30508
30509
30510
30511
30512
30513
30514
30515
30516
30517
30518
30519
30520
30521
30522
30523
30524
30525
30526
30527
30528
30529
30530
30531
30532
30533
30534
30535
30536
30537
30538
30539
30540
30541
30542
30543
30544
30545
30546
30547
30548
30549
30550
30551
30552
30553
30554
30555
30556
30557
30558
30559
30560
30561
30562
30563
30564
30565
30566
30567
30568
30569
30570
30571
30572
30573
30574
30575
30576
30577
30578
30579
30580
30581
30582
30583
30584
30585
30586
30587
30588
30589
30590
30591
30592
30593
30594
30595
30596
30597
30598
30599
30600
30601
30602
30603
30604
30605
30606
30607
30608
30609
30610
30611
30612
30613
30614
30615
30616
30617
30618
30619
30620
30621
30622
30623
30624
30625
30626
30627
30628
30629
30630
30631
30632
30633
30634
30635
30636
30637
30638
30639
30640
30641
30642
30643
30644
30645
30646
30647
30648
30649
30650
30651
30652
30653
30654
30655
30656
30657
30658
30659
30660
30661
30662
30663
30664
30665
30666
30667
30668
30669
30670
30671
30672
30673
30674
30675
30676
30677
30678
30679
30680
30681
30682
30683
30684
30685
30686
30687
30688
30689
30690
30691
30692
30693
30694
30695
30696
30697
30698
30699
30700
30701
30702
30703
30704
30705
30706
30707
30708
30709
30710
30711
30712
30713
30714
30715
30716
30717
30718
30719
30720
30721
30722
30723
30724
30725
30726
30727
30728
30729
30730
30731
30732
30733
30734
30735
30736
30737
30738
30739
30740
30741
30742
30743
30744
30745
30746
30747
30748
30749
30750
30751
30752
30753
30754
30755
30756
30757
30758
30759
30760
30761
30762
30763
30764
30765
30766
30767
30768
30769
30770
30771
30772
30773
30774
30775
30776
30777
30778
30779
30780
30781
30782
30783
30784
30785
30786
30787
30788
30789
30790
30791
30792
30793
30794
30795
30796
30797
30798
30799
30800
30801
30802
30803
30804
30805
30806
30807
30808
30809
30810
30811
30812
30813
30814
30815
30816
30817
30818
30819
30820
30821
30822
30823
30824
30825
30826
30827
30828
30829
30830
30831
30832
30833
30834
30835
30836
30837
30838
30839
30840
30841
30842
30843
30844
30845
30846
30847
30848
30849
30850
30851
30852
30853
30854
30855
30856
30857
30858
30859
30860
30861
30862
30863
30864
30865
30866
30867
30868
30869
30870
30871
30872
30873
30874
30875
30876
30877
30878
30879
30880
30881
30882
30883
30884
30885
30886
30887
30888
30889
30890
30891
30892
30893
30894
30895
30896
30897
30898
30899
30900
30901
30902
30903
30904
30905
30906
30907
30908
30909
30910
30911
30912
30913
30914
30915
30916
30917
30918
30919
30920
30921
30922
30923
30924
30925
30926
30927
30928
30929
30930
30931
30932
30933
30934
30935
30936
30937
30938
30939
30940
30941
30942
30943
30944
30945
30946
30947
30948
30949
30950
30951
30952
30953
30954
30955
30956
30957
30958
30959
30960
30961
30962
30963
30964
30965
30966
30967
30968
30969
30970
30971
30972
30973
30974
30975
30976
30977
30978
30979
30980
30981
30982
30983
30984
30985
30986
30987
30988
30989
30990
30991
30992
30993
30994
30995
30996
30997
30998
30999
31000
31001
31002
31003
31004
31005
31006
31007
31008
31009
31010
31011
31012
31013
31014
31015
31016
31017
31018
31019
31020
31021
31022
31023
31024
31025
31026
31027
31028
31029
31030
31031
31032
31033
31034
31035
31036
31037
31038
31039
31040
31041
31042
31043
31044
31045
31046
31047
31048
31049
31050
31051
31052
31053
31054
31055
31056
31057
31058
31059
31060
31061
31062
31063
31064
31065
31066
31067
31068
31069
31070
31071
31072
31073
31074
31075
31076
31077
31078
31079
31080
31081
31082
31083
31084
31085
31086
31087
31088
31089
31090
31091
31092
31093
31094
31095
31096
31097
31098
31099
31100
31101
31102
31103
31104
31105
31106
31107
31108
31109
31110
31111
31112
31113
31114
31115
31116
31117
31118
31119
31120
31121
31122
31123
31124
31125
31126
31127
31128
31129
31130
31131
31132
31133
31134
31135
31136
31137
31138
31139
31140
31141
31142
31143
31144
31145
31146
31147
31148
31149
31150
31151
31152
31153
31154
31155
31156
31157
31158
31159
31160
31161
31162
31163
31164
31165
31166
31167
31168
31169
31170
31171
31172
31173
31174
31175
31176
31177
31178
31179
31180
31181
31182
31183
31184
31185
31186
31187
31188
31189
31190
31191
31192
31193
31194
31195
31196
31197
31198
31199
31200
31201
31202
31203
31204
31205
31206
31207
31208
31209
31210
31211
31212
31213
31214
31215
31216
31217
31218
31219
31220
31221
31222
31223
31224
31225
31226
31227
31228
31229
31230
31231
31232
31233
31234
31235
31236
31237
31238
31239
31240
31241
31242
31243
31244
31245
31246
31247
31248
31249
31250
31251
31252
31253
31254
31255
31256
31257
31258
31259
31260
31261
31262
31263
31264
31265
31266
31267
31268
31269
31270
31271
31272
31273
31274
31275
31276
31277
31278
31279
31280
31281
31282
31283
31284
31285
31286
31287
31288
31289
31290
31291
31292
31293
31294
31295
31296
31297
31298
31299
31300
31301
31302
31303
31304
31305
31306
31307
31308
31309
31310
31311
31312
31313
31314
31315
31316
31317
31318
31319
31320
31321
31322
31323
31324
31325
31326
31327
31328
31329
31330
31331
31332
31333
31334
31335
31336
31337
31338
31339
31340
31341
31342
31343
31344
31345
31346
31347
31348
31349
31350
31351
31352
31353
31354
31355
31356
31357
31358
31359
31360
31361
31362
31363
31364
31365
31366
31367
31368
31369
31370
31371
31372
31373
31374
31375
31376
31377
31378
31379
31380
31381
31382
31383
31384
31385
31386
31387
31388
31389
31390
31391
31392
31393
31394
31395
%!PS
%% $Id: pst-barcode.pro 588 2022-08-23 16:49:51Z herbert $

% Barcode Writer in Pure PostScript - Version 2022-08-21
% https://bwipp.terryburton.co.uk
%
% Copyright (c) 2004-2022 Terry Burton
%
% 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 TEMPLATE--

% --BEGIN RESOURCE preamble--
%%BeginResource: Category uk.co.terryburton.bwipp 0.0 2022082100 29733 32838
%%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 loadctx--
% --REQUIRES preamble--
%%BeginResource: uk.co.terryburton.bwipp loadctx 0.0 2022082100 40205 39999
%%BeginData:         25 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/loadctx {
    % Place a context dictionary just below the current dictionary, which can
    % be populated with static data on the first run and then carried between
    % invocations of the encoder
    /ctxname exch def
    ctx null ne {
        ctx ctxname known not {
            ctx ctxname 10 dict put
            /ctxdef {ctx ctxname get begin exec end} def
        } {
            /ctxdef {pop} def  % No need to redefine within the existing context
        } ifelse
        currentdict ctx ctxname get end begin begin
    } {
        /ctxdef {exec} def  % No context provided, so define ephemerally
    } ifelse
}
[/barcode] {null def} forall
bind def
/loadctx dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RESOURCE loadctx--

% --BEGIN RESOURCE unloadctx--
% --REQUIRES preamble--
%%BeginResource: uk.co.terryburton.bwipp unloadctx 0.0 2022082100 38856 38677
%%BeginData:         14 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
1 dict
begin
/unloadctx {
    % Remove the context which is expected to be just underneath currentdict
    ctx null ne {
        currentdict end end begin
    } if
}
[/barcode] {null def} forall
bind def
/unloadctx dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RESOURCE unloadctx--

% --BEGIN RESOURCE raiseerror--
% --REQUIRES preamble--
%%BeginResource: uk.co.terryburton.bwipp raiseerror 0.0 2022082100 39029 38860
%%BeginData:         15 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
begin
/raiseerror {
    $error exch /errorinfo exch put
    $error exch /errorname exch put
    $error /command null put
    $error /newerror true put
    stop
}
[/barcode] {null def} forall
bind def
/raiseerror dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RESOURCE raiseerror--

% --BEGIN RESOURCE parseinput--
% --REQUIRES preamble loadctx unloadctx raiseerror--
%%BeginResource: uk.co.terryburton.bwipp parseinput 0.0 2022082100 73377 69190
%%BeginData:        174 ASCII Lines
/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
begin
/parseinput {

    20 dict begin

    /parseinput //loadctx exec

    /fncvals exch def
    /barcode exch def

    /parse     dup dup fncvals exch get def fncvals exch undef
    /parsefnc  dup dup fncvals exch get def fncvals exch undef
    /parseonly dup dup fncvals exch known def fncvals exch undef
    /eci       dup dup fncvals exch known def fncvals exch undef

    % Control character names to ordinals
{
    <<
        [
            /NUL /SOH /STX /ETX /EOT /ENQ /ACK /BEL
            /BS  /TAB /LF  /VT  /FF  /CR  ()   ()    % SO and SI prefix clash with SOH
            /DLE /DC1 /DC2 /DC3 /DC4 /NAK /SYN /ETB
            /CAN /EM  /SUB /ESC /FS  /GS  /RS  /US
        ]
        0 exch {
            1 index 1 add 3 1 roll exch 3 -1 roll
        } forall pop
    >> /ctrl exch def
} ctxdef

    /msg barcode length array def
    /j 0 def
    barcode {  % loop
        (^) search exch
        % Copy characters up to a "^"
        dup length exch
        msg exch j exch [ exch {} forall ] putinterval
        j add /j exch def
        {  % Found a "^" escape character
            pop
            1 {  % common exit

                parse not parsefnc not and {  % "^" as is
                    msg j 94 put
                    /j j 1 add def
                    exit
                } if

                % Encode "^" to start with
                msg j 94 put
                /j j 1 add def

                % parse
                parse {
                    dup length 3 ge {  % "^XXX" byte
                        dup 0 3 getinterval ctrl exch
                        2 copy known {
                            /j j 1 sub def  % Replace "^" with ordinal
                            get msg exch j exch put
                            /j j 1 add def
                            dup length 3 sub 3 exch getinterval
                            exit
                        } {
                            pop pop
                        } ifelse
                    } if
                    dup length 2 ge {  % "^XX" to byte
                        dup 0 2 getinterval ctrl exch
                        2 copy known {
                            /j j 1 sub def  % Replace "^" with ordinal
                            get msg exch j exch put
                            /j j 1 add def
                            dup length 2 sub 2 exch getinterval
                            exit
                        } {
                            pop pop
                        } ifelse
                    } if
                    dup length 3 ge {  % "^NNN" to byte
                        dup 0 3 getinterval true exch {
                            dup 48 lt exch 57 gt or { pop false } if
                        } forall
                        {
                            dup 0 3 getinterval cvi dup 255 gt {
                                pop pop
                                /bwipp.invalidOrdinal (Ordinal must be 000 to 255) //raiseerror exec
                            } if
                            /j j 1 sub def  % Replace "^" with ordinal
                            msg exch j exch put
                            /j j 1 add def
                            dup length 3 sub 3 exch getinterval
                        } if
                    } if
                } if

                parseonly
                parsefnc not or
                msg j 1 sub get 94 ne  % Carat was substituted away
                or {exit} if

                % parsefnc
                /j j 1 sub def
                dup length 3 lt {
                    pop
                    /bwipp.truncatedFNC (Function character truncated) //raiseerror exec
                } if
                dup 0 get 94 eq {  % "^^" -> "^"
                    msg j 94 put
                    /j j 1 add def
                    dup length 1 sub 1 exch getinterval
                    exit
                } if
                dup 0 3 getinterval (ECI) eq eci and {  % "^ECInnnnnn" -> -1nnnnnn
                    dup length 9 lt {
                        pop
                        /bwipp.truncatedECI (ECI truncated) //raiseerror exec
                    } if
                    dup 3 6 getinterval
                    dup {
                        dup 48 lt exch 57 gt or {
                            pop pop
                            /bwipp.invalidECI (ECI must be 000000 to 999999) //raiseerror exec
                        } if
                    } forall
                    0 exch {48 sub sub 10 mul} forall 10 idiv 1000000 sub
                    msg exch j exch put
                    /j j 1 add def
                    dup length 9 sub 9 exch getinterval
                    exit
                } if
                dup length 4 lt {  % "^FNCx" -> fncvals{FNCx}
                    pop
                    /bwipp.truncatedFNC (Function character truncated) //raiseerror exec
                } if
                dup 0 4 getinterval dup fncvals exch known not {
                    dup length 28 add string dup 28 4 -1 roll putinterval
                    dup 0 (Unknown function character: ) putinterval
                    exch pop
                    /bwipp.unknownFNC exch //raiseerror exec
                } if
                fncvals exch get
                msg exch j exch put
                /j j 1 add def
                dup length 4 sub 4 exch getinterval
                exit

            } repeat
        } {  % No more "^" characters
            exit
        }  ifelse
    } loop

    parseonly not {
        msg 0 j getinterval
    } {
        j string
        0 1 j 1 sub { 1 index exch dup msg exch get put } for
    } ifelse

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/parseinput dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RESOURCE parseinput--

% --BEGIN RESOURCE gs1process--
% --REQUIRES preamble loadctx unloadctx parseinput raiseerror--
%%BeginResource: uk.co.terryburton.bwipp gs1process 0.0 2022082100 526019 593612
%%BeginData:       2909 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
begin
/gs1process {

    20 dict begin

    /gs1process //loadctx exec

{
    % Extracted from the GS1 Syntax Dictionary
    /gs1syntax <<

        <<
            /parts [
                << /cset /N  /min 18  /max 18  /opt false  /linters [ /lintcsum /lintkey ] >>
            ]
            /dlpkey [ ]
        >>
        (00) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 14  /max 14  /opt false  /linters [ /lintcsum /lintkey ] >>
            ]
            /ex     [ (02) (255) (37) ]
            /dlpkey [ [ (22) (10) (21) ] [ (235) ] ]
        >>
        (01) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 14  /max 14  /opt false  /linters [ /lintcsum /lintkey ] >>
            ]
            /req    [ [ (37) ] ]
        >>
        (02) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) (8006) (8026) ] ]
        >>
        (10) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [ /lintyymmd0 ] >>
            ]
            /req    [ [ (01) (02) (8006) (8026) ] ]
        >>
        (11) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [ /lintyymmd0 ] >>
            ]
            /req    [ [ (8020) ] ]
        >>
        (12) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [ /lintyymmd0 ] >>
            ]
            /req    [ [ (01) (02) (8006) (8026) ] ]
        >>
        (13) exch dup
        (15) exch dup
        (16) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [ /lintyymmd0 ] >>
            ]
            /req    [ [ (01) (02) (255) (8006) (8026) ] ]
        >>
        (17) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  2  /max  2  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) (8006) (8026) ] ]
        >>
        (20) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /ex     [ (235) ]
            /req    [ [ (01) (8006) ] ]
        >>
        (21) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /req    [ [ (01) ] ]
        >>
        (22) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 28  /opt false  /linters [] >>
            ]
            /req    [ [ (01) ] ]
        >>
        (235) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 30  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) (8006) (8026) ] ]
        >>
        (240) exch dup
        (241) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max  6  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) (8006) (8026) ] ]
        >>
        (242) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /req    [ [ (01) ] ]
        >>
        (243) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 30  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (8006) ] [ (21) ] ]
        >>
        (250) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 30  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (8006) ] ]
        >>
        (251) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 13  /max 13  /opt false  /linters [ /lintcsum /lintkey ] >>
                << /cset /X  /min  1  /max 17  /opt true   /linters [] >>
            ]
            /dlpkey [ ]
        >>
        (253) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /req    [ [ (414) ] ]
        >>
        (254) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 13  /max 13  /opt false  /linters [ /lintcsum /lintkey ] >>
                << /cset /N  /min  1  /max 12  /opt true   /linters [] >>
            ]
            /ex     [ (01) (02) (415) (8006) (8020) (8026) ]
            /dlpkey [ ]
        >>
        (255) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max  8  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (30) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (310n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3100) exch dup
        (3101) exch dup
        (3102) exch dup
        (3103) exch dup
        (3104) exch dup
        (3105) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (311n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3110) exch dup
        (3111) exch dup
        (3112) exch dup
        (3113) exch dup
        (3114) exch dup
        (3115) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (312n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3120) exch dup
        (3121) exch dup
        (3122) exch dup
        (3123) exch dup
        (3124) exch dup
        (3125) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (313n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3130) exch dup
        (3131) exch dup
        (3132) exch dup
        (3133) exch dup
        (3134) exch dup
        (3135) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (314n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3140) exch dup
        (3141) exch dup
        (3142) exch dup
        (3143) exch dup
        (3144) exch dup
        (3145) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (315n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3150) exch dup
        (3151) exch dup
        (3152) exch dup
        (3153) exch dup
        (3154) exch dup
        (3155) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (316n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3160) exch dup
        (3161) exch dup
        (3162) exch dup
        (3163) exch dup
        (3164) exch dup
        (3165) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (320n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3200) exch dup
        (3201) exch dup
        (3202) exch dup
        (3203) exch dup
        (3204) exch dup
        (3205) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (321n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3210) exch dup
        (3211) exch dup
        (3212) exch dup
        (3213) exch dup
        (3214) exch dup
        (3215) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (322n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3220) exch dup
        (3221) exch dup
        (3222) exch dup
        (3223) exch dup
        (3224) exch dup
        (3225) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (323n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3230) exch dup
        (3231) exch dup
        (3232) exch dup
        (3233) exch dup
        (3234) exch dup
        (3235) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (324n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3240) exch dup
        (3241) exch dup
        (3242) exch dup
        (3243) exch dup
        (3244) exch dup
        (3245) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (325n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3250) exch dup
        (3251) exch dup
        (3252) exch dup
        (3253) exch dup
        (3254) exch dup
        (3255) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (326n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3260) exch dup
        (3261) exch dup
        (3262) exch dup
        (3263) exch dup
        (3264) exch dup
        (3265) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (327n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3270) exch dup
        (3271) exch dup
        (3272) exch dup
        (3273) exch dup
        (3274) exch dup
        (3275) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (328n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3280) exch dup
        (3281) exch dup
        (3282) exch dup
        (3283) exch dup
        (3284) exch dup
        (3285) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (329n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3290) exch dup
        (3291) exch dup
        (3292) exch dup
        (3293) exch dup
        (3294) exch dup
        (3295) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (330n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3300) exch dup
        (3301) exch dup
        (3302) exch dup
        (3303) exch dup
        (3304) exch dup
        (3305) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (331n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3310) exch dup
        (3311) exch dup
        (3312) exch dup
        (3313) exch dup
        (3314) exch dup
        (3315) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (332n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3320) exch dup
        (3321) exch dup
        (3322) exch dup
        (3323) exch dup
        (3324) exch dup
        (3325) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (333n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3330) exch dup
        (3331) exch dup
        (3332) exch dup
        (3333) exch dup
        (3334) exch dup
        (3335) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (334n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3340) exch dup
        (3341) exch dup
        (3342) exch dup
        (3343) exch dup
        (3344) exch dup
        (3345) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (335n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3350) exch dup
        (3351) exch dup
        (3352) exch dup
        (3353) exch dup
        (3354) exch dup
        (3355) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (336n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3360) exch dup
        (3361) exch dup
        (3362) exch dup
        (3363) exch dup
        (3364) exch dup
        (3365) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (337n) ]
            /req    [ [ (01) ] ]
        >>
        (3370) exch dup
        (3371) exch dup
        (3372) exch dup
        (3373) exch dup
        (3374) exch dup
        (3375) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (340n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3400) exch dup
        (3401) exch dup
        (3402) exch dup
        (3403) exch dup
        (3404) exch dup
        (3405) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (341n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3410) exch dup
        (3411) exch dup
        (3412) exch dup
        (3413) exch dup
        (3414) exch dup
        (3415) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (342n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3420) exch dup
        (3421) exch dup
        (3422) exch dup
        (3423) exch dup
        (3424) exch dup
        (3425) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (343n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3430) exch dup
        (3431) exch dup
        (3432) exch dup
        (3433) exch dup
        (3434) exch dup
        (3435) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (344n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3440) exch dup
        (3441) exch dup
        (3442) exch dup
        (3443) exch dup
        (3444) exch dup
        (3445) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (345n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3450) exch dup
        (3451) exch dup
        (3452) exch dup
        (3453) exch dup
        (3454) exch dup
        (3455) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (346n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3460) exch dup
        (3461) exch dup
        (3462) exch dup
        (3463) exch dup
        (3464) exch dup
        (3465) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (347n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3470) exch dup
        (3471) exch dup
        (3472) exch dup
        (3473) exch dup
        (3474) exch dup
        (3475) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (348n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3480) exch dup
        (3481) exch dup
        (3482) exch dup
        (3483) exch dup
        (3484) exch dup
        (3485) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (349n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3490) exch dup
        (3491) exch dup
        (3492) exch dup
        (3493) exch dup
        (3494) exch dup
        (3495) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (350n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3500) exch dup
        (3501) exch dup
        (3502) exch dup
        (3503) exch dup
        (3504) exch dup
        (3505) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (351n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3510) exch dup
        (3511) exch dup
        (3512) exch dup
        (3513) exch dup
        (3514) exch dup
        (3515) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (352n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3520) exch dup
        (3521) exch dup
        (3522) exch dup
        (3523) exch dup
        (3524) exch dup
        (3525) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (353n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3530) exch dup
        (3531) exch dup
        (3532) exch dup
        (3533) exch dup
        (3534) exch dup
        (3535) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (354n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3540) exch dup
        (3541) exch dup
        (3542) exch dup
        (3543) exch dup
        (3544) exch dup
        (3545) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (355n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3550) exch dup
        (3551) exch dup
        (3552) exch dup
        (3553) exch dup
        (3554) exch dup
        (3555) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (356n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3560) exch dup
        (3561) exch dup
        (3562) exch dup
        (3563) exch dup
        (3564) exch dup
        (3565) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (357n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3570) exch dup
        (3571) exch dup
        (3572) exch dup
        (3573) exch dup
        (3574) exch dup
        (3575) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (360n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3600) exch dup
        (3601) exch dup
        (3602) exch dup
        (3603) exch dup
        (3604) exch dup
        (3605) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (361n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3610) exch dup
        (3611) exch dup
        (3612) exch dup
        (3613) exch dup
        (3614) exch dup
        (3615) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (362n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3620) exch dup
        (3621) exch dup
        (3622) exch dup
        (3623) exch dup
        (3624) exch dup
        (3625) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (363n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3630) exch dup
        (3631) exch dup
        (3632) exch dup
        (3633) exch dup
        (3634) exch dup
        (3635) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (364n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3640) exch dup
        (3641) exch dup
        (3642) exch dup
        (3643) exch dup
        (3644) exch dup
        (3645) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (365n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3650) exch dup
        (3651) exch dup
        (3652) exch dup
        (3653) exch dup
        (3654) exch dup
        (3655) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (366n) ]
            /req    [ [ (01) (02) ] ]
        >>
        (3660) exch dup
        (3661) exch dup
        (3662) exch dup
        (3663) exch dup
        (3664) exch dup
        (3665) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (367n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3670) exch dup
        (3671) exch dup
        (3672) exch dup
        (3673) exch dup
        (3674) exch dup
        (3675) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (368n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3680) exch dup
        (3681) exch dup
        (3682) exch dup
        (3683) exch dup
        (3684) exch dup
        (3685) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (369n) ]
            /req    [ [ (00) (01) ] ]
        >>
        (3690) exch dup
        (3691) exch dup
        (3692) exch dup
        (3693) exch dup
        (3694) exch dup
        (3695) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max  8  /opt false  /linters [] >>
            ]
            /req    [ [ (00) ] [ (02) (8026) ] ]
        >>
        (37) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max 15  /opt false  /linters [] >>
            ]
            /ex     [ (390n) (391n) (394n) (8111) ]
            /req    [ [ (255) (8020) ] ]
        >>
        (3900) exch dup
        (3901) exch dup
        (3902) exch dup
        (3903) exch dup
        (3904) exch dup
        (3905) exch dup
        (3906) exch dup
        (3907) exch dup
        (3908) exch dup
        (3909) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  3  /max  3  /opt false  /linters [ /lintiso4217 ] >>
                << /cset /N  /min  1  /max 15  /opt false  /linters [] >>
            ]
            /ex     [ (391n) ]
            /req    [ [ (8020) ] ]
        >>
        (3910) exch dup
        (3911) exch dup
        (3912) exch dup
        (3913) exch dup
        (3914) exch dup
        (3915) exch dup
        (3916) exch dup
        (3917) exch dup
        (3918) exch dup
        (3919) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max 15  /opt false  /linters [] >>
            ]
            /ex     [ (392n) (393n) ]
            /req    [ [ (01) ] [ (30) (31nn) (32nn) (35nn) (36nn) ] ]
        >>
        (3920) exch dup
        (3921) exch dup
        (3922) exch dup
        (3923) exch dup
        (3924) exch dup
        (3925) exch dup
        (3926) exch dup
        (3927) exch dup
        (3928) exch dup
        (3929) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  3  /max  3  /opt false  /linters [ /lintiso4217 ] >>
                << /cset /N  /min  1  /max 15  /opt false  /linters [] >>
            ]
            /ex     [ (393n) ]
            /req    [ [ (30) (31nn) (32nn) (35nn) (36nn) ] ]
        >>
        (3930) exch dup
        (3931) exch dup
        (3932) exch dup
        (3933) exch dup
        (3934) exch dup
        (3935) exch dup
        (3936) exch dup
        (3937) exch dup
        (3938) exch dup
        (3939) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  4  /max  4  /opt false  /linters [] >>
            ]
            /ex     [ (394n) (8111) ]
            /req    [ [ (255) ] ]
        >>
        (3940) exch dup
        (3941) exch dup
        (3942) exch dup
        (3943) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /ex     [ (392n) (393n) (395n) (8005) ]
            /req    [ [ (30) (31nn) (32nn) (35nn) (36nn) ] ]
        >>
        (3950) exch dup
        (3951) exch dup
        (3952) exch dup
        (3953) exch dup
        (3954) exch dup
        (3955) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 30  /opt false  /linters [] >>
            ]
        >>
        (400) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 30  /opt false  /linters [ /lintkey ] >>
            ]
            /dlpkey [ ]
        >>
        (401) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 17  /max 17  /opt false  /linters [ /lintcsum /lintkey ] >>
            ]
            /dlpkey [ ]
        >>
        (402) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 30  /opt false  /linters [] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (403) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 13  /max 13  /opt false  /linters [ /lintcsum /lintkey ] >>
            ]
        >>
        (410) exch dup
        (411) exch dup
        (412) exch dup
        (413) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 13  /max 13  /opt false  /linters [ /lintcsum /lintkey ] >>
            ]
            /dlpkey [ [ (254) ] [ (7040) ] ]
        >>
        (414) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 13  /max 13  /opt false  /linters [ /lintcsum /lintkey ] >>
            ]
            /req    [ [ (8020) ] ]
        >>
        (415) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 13  /max 13  /opt false  /linters [ /lintcsum /lintkey ] >>
            ]
        >>
        (416) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 13  /max 13  /opt false  /linters [ /lintcsum /lintkey ] >>
            ]
            /dlpkey [ [ (7040) ] ]
        >>
        (417) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /ex     [ (421) ]
        >>
        (420) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  3  /max  3  /opt false  /linters [ /lintiso3166 ] >>
                << /cset /X  /min  1  /max  9  /opt false  /linters [] >>
            ]
            /ex     [ (4307) ]
        >>
        (421) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  3  /max  3  /opt false  /linters [ /lintiso3166 ] >>
            ]
            /ex     [ (426) ]
            /req    [ [ (01) (02) (8006) (8026) ] ]
        >>
        (422) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max 15  /opt false  /linters [ /lintiso3166list ] >>
            ]
            /ex     [ (426) ]
            /req    [ [ (01) (02) ] ]
        >>
        (423) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  3  /max  3  /opt false  /linters [ /lintiso3166 ] >>
            ]
            /ex     [ (426) ]
            /req    [ [ (01) (02) ] ]
        >>
        (424) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max 15  /opt false  /linters [ /lintiso3166list ] >>
            ]
            /ex     [ (426) ]
            /req    [ [ (01) (02) ] ]
        >>
        (425) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  3  /max  3  /opt false  /linters [ /lintiso3166 ] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (426) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max  3  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) ] [ (422) ] ]
        >>
        (427) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 35  /opt false  /linters [ /lintpcenc ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4300) exch dup
        (4301) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 70  /opt false  /linters [ /lintpcenc ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4302) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 70  /opt false  /linters [ /lintpcenc ] >>
            ]
            /req    [ [ (4302) ] ]
        >>
        (4303) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 70  /opt false  /linters [ /lintpcenc ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4304) exch dup
        (4305) exch dup
        (4306) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  2  /max  2  /opt false  /linters [ /lintiso3166alpha2 ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4307) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 30  /opt false  /linters [] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4308) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 20  /max 20  /opt false  /linters [ /lintlatlong ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4309) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 35  /opt false  /linters [ /lintpcenc ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4310) exch dup
        (4311) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 70  /opt false  /linters [ /lintpcenc ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4312) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 70  /opt false  /linters [ /lintpcenc ] >>
            ]
            /req    [ [ (4312) ] ]
        >>
        (4313) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 70  /opt false  /linters [ /lintpcenc ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4314) exch dup
        (4315) exch dup
        (4316) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  2  /max  2  /opt false  /linters [ /lintiso3166alpha2 ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4317) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4318) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 30  /opt false  /linters [] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4319) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 35  /opt false  /linters [ /lintpcenc ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4320) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max  1  /opt false  /linters [ /lintyesno ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4321) exch dup
        (4322) exch dup
        (4323) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [ /lintyymmd0 ] >>
                << /cset /N  /min  4  /max  4  /opt false  /linters [ /linthhmm ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4324) exch dup
        (4325) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [ /lintyymmdd ] >>
            ]
            /req    [ [ (00) ] ]
        >>
        (4326) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 13  /max 13  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) (8006) (8026) ] ]
        >>
        (7001) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 30  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (7002) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [ /lintyymmdd ] >>
                << /cset /N  /min  4  /max  4  /opt false  /linters [ /linthhmm ] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (7003) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max  4  /opt false  /linters [] >>
            ]
            /req    [ [ (01) ] [ (10) ] ]
        >>
        (7004) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 12  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (7005) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [ /lintyymmdd ] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (7006) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [ /lintyymmdd ] >>
                << /cset /N  /min  6  /max  6  /opt true   /linters [ /lintyymmdd ] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (7007) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max  3  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (7008) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 10  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (7009) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max  2  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (7010) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [ /lintyymmdd ] >>
                << /cset /N  /min  4  /max  4  /opt true   /linters [ /linthhmm ] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (7011) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (8006) ] [ (416) ] ]
        >>
        (7020) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (8006) ] ]
        >>
        (7021) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /req    [ [ (7021) ] ]
        >>
        (7022) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 30  /opt false  /linters [ /lintkey ] >>
            ]
        >>
        (7023) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  3  /max  3  /opt false  /linters [ /lintiso3166999 ] >>
                << /cset /X  /min  1  /max 27  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (7030) exch dup
        (7031) exch dup
        (7032) exch dup
        (7033) exch dup
        (7034) exch dup
        (7035) exch dup
        (7036) exch dup
        (7037) exch dup
        (7038) exch dup
        (7039) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max  1  /opt false  /linters [] >>
                << /cset /X  /min  1  /max  1  /opt false  /linters [] >>
                << /cset /X  /min  1  /max  1  /opt false  /linters [] >>
                << /cset /X  /min  1  /max  1  /opt false  /linters [ /lintimporteridx ] >>
            ]
        >>
        (7040) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /req    [ [ (01) ] ]
        >>
        (710) exch dup
        (711) exch dup
        (712) exch dup
        (713) exch dup
        (714) exch dup
        (715) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  2  /max  2  /opt false  /linters [] >>
                << /cset /X  /min  1  /max 28  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (8004) ] ]
        >>
        (7230) exch dup
        (7231) exch dup
        (7232) exch dup
        (7233) exch dup
        (7234) exch dup
        (7235) exch dup
        (7236) exch dup
        (7237) exch dup
        (7238) exch dup
        (7239) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (8006) ] ]
        >>
        (7240) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  4  /max  4  /opt false  /linters [ /lintnonzero ] >>
                << /cset /N  /min  5  /max  5  /opt false  /linters [ /lintnonzero ] >>
                << /cset /N  /min  3  /max  3  /opt false  /linters [ /lintnonzero ] >>
                << /cset /N  /min  1  /max  1  /opt false  /linters [ /lintwinding ] >>
                << /cset /N  /min  1  /max  1  /opt false  /linters [] >>
            ]
            /req    [ [ (01) ] ]
        >>
        (8001) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
        >>
        (8002) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max  1  /opt false  /linters [ /lintzero ] >>
                << /cset /N  /min 13  /max 13  /opt false  /linters [ /lintcsum /lintkey ] >>
                << /cset /X  /min  1  /max 16  /opt true   /linters [] >>
            ]
            /dlpkey [ ]
        >>
        (8003) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 30  /opt false  /linters [ /lintkey ] >>
            ]
            /dlpkey [ [ (7040) ] ]
        >>
        (8004) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  6  /max  6  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (8005) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 14  /max 14  /opt false  /linters [ /lintcsum ] >>
                << /cset /N  /min  4  /max  4  /opt false  /linters [ /lintpieceoftotal ] >>
            ]
            /ex     [ (01) (37) ]
            /dlpkey [ [ (22) (10) (21) ] ]
        >>
        (8006) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 34  /opt false  /linters [ /lintiban ] >>
            ]
            /req    [ [ (415) ] ]
        >>
        (8007) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  8  /max  8  /opt false  /linters [ /lintyymmddhh ] >>
                << /cset /N  /min  1  /max  4  /opt true   /linters [ /lintmmoptss ] >>
            ]
            /req    [ [ (01) (02) ] ]
        >>
        (8008) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 50  /opt false  /linters [] >>
            ]
            /req    [ [ (00) (01) ] ]
        >>
        (8009) exch dup
        pop

        <<
            /parts [
                << /cset /Y  /min  1  /max 30  /opt false  /linters [ /lintkey ] >>
            ]
            /dlpkey [ [ (8011) ] ]
        >>
        (8010) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max 12  /opt false  /linters [ /lintnozeroprefix ] >>
            ]
            /req    [ [ (8010) ] ]
        >>
        (8011) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 20  /opt false  /linters [] >>
            ]
            /req    [ [ (01) (8006) ] ]
        >>
        (8012) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 25  /opt false  /linters [ /lintcsumalpha /lintkey ] >>
            ]
            /dlpkey [ ]
        >>
        (8013) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 18  /max 18  /opt false  /linters [ /lintcsum ] >>
            ]
            /dlpkey [ [ (8019) ] ]
        >>
        (8017) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 18  /max 18  /opt false  /linters [ /lintcsum ] >>
            ]
            /ex     [ (8017) ]
            /dlpkey [ [ (8019) ] ]
        >>
        (8018) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  1  /max 10  /opt false  /linters [] >>
            ]
            /req    [ [ (8017) (8018) ] ]
        >>
        (8019) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 25  /opt false  /linters [] >>
            ]
            /req    [ [ (415) ] ]
        >>
        (8020) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min 14  /max 14  /opt false  /linters [ /lintcsum ] >>
                << /cset /N  /min  4  /max  4  /opt false  /linters [ /lintpieceoftotal ] >>
            ]
            /ex     [ (02) (8006) ]
            /req    [ [ (37) ] ]
        >>
        (8026) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 70  /opt false  /linters [ /lintcouponcode ] >>
            ]
        >>
        (8110) exch dup
        pop

        <<
            /parts [
                << /cset /N  /min  4  /max  4  /opt false  /linters [] >>
            ]
            /req    [ [ (255) ] ]
        >>
        (8111) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 70  /opt false  /linters [ /lintcouponposoffer ] >>
            ]
        >>
        (8112) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 70  /opt false  /linters [] >>
            ]
            /req    [ [ (01) ] ]
        >>
        (8200) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 30  /opt false  /linters [] >>
            ]
        >>
        (90) exch dup
        pop

        <<
            /parts [
                << /cset /X  /min  1  /max 90  /opt false  /linters [] >>
            ]
        >>
        (91) exch dup
        (92) exch dup
        (93) exch dup
        (94) exch dup
        (95) exch dup
        (96) exch dup
        (97) exch dup
        (98) exch dup
        (99) exch dup
        pop

    >> def
} ctxdef

    % Extract AIs and vals from provided GS1 data in the indicated format

    /ai eq {  % Bracketed AI element string

        % Parse out AIs and values
        (\() anchorsearch not {
            pop /bwipp.GS1aiMissingOpenParen (AIs must start with '\(') //raiseerror exec
        } if
        pop
        mark exch {  % loop
            dup () eq {pop exit} if
            (\)) search not {
                cleartomark /bwipp.GS1aiMissingCloseParen (AIs must end with '\)') //raiseerror exec
            } if
            exch pop exch
            (\() search { exch pop exch } { () } ifelse
        } loop
        counttomark dup 0 gt {dup 2 idiv 1 add -1 exch {-1 roll} for} {pop} ifelse
        counttomark 2 idiv array astore /ais exch def
        counttomark array astore [ exch {  % Expand ordinals of the form ^NNN to ASCII
            << /parse parse /parseonly true /parsefnc false >> //parseinput exec
        } forall ] /vals exch def
        pop

    } {  % Digital Link URI

        % Validate and strip the scheme
        (http://) anchorsearch not {
        (https://) anchorsearch not {
            pop /bwipp.GS1dlURIbadScheme (Scheme must be http:// or https://) //raiseerror exec
        } if} if
        pop

        % Strip the domain
        (/) search not {
            pop /bwipp.GS1dlMissingDomainOrPathInfo (URI must contain a domain and path info) //raiseerror exec
        } if
        pop pop

        % Fragment delimits end of data
        (#) search {
            exch pop exch pop
        } if

        % Query parameter marker splits path info and query parameters
        (?) search not {
            () exch null exch
        } if
        /pp exch def
        pop
        /qp exch def

        % Find positions of character immediately following "/" in the path info
        mark 0
        0 pp {
            (/) search not {pop exit} if
            length 1 add exch pop 2 index add exch
        } loop
        counttomark 1 sub array astore /pipos exch def pop pop
        pipos length 1 le {
            /bwipp.GS1dlNoAIinfo (The path was too short to contain AI info) //raiseerror exec
        } if

        % Walk backwards to find the right-most path element that is a valid dlpkey
        false
        pipos length 2 sub -2 0 {
            dup
            dup pipos exch get
            exch pipos exch 1 add get 1 index sub 1 sub pp 3 1 roll getinterval
            dup gs1syntax exch known {
                gs1syntax exch get /dlpkey known {
                    exch pop true exit
                } if
            } {
                pop
            } ifelse
            pop
        } for
        not {
            /bwipp.GS1dlNoAIinfo (The path does not contain a valid primary key) //raiseerror exec
        } if
        pipos exch get dup pp length exch sub pp 3 1 roll getinterval /pp exch def

        /uriunescape {
            /in exch def
            /out in length string def
            0 0 {
                1 index in length ge {exit} if
                in 2 index get
                dup 43 eq {  % "+" -> " "
                    pop out 1 index 32 put
                    1 add exch 1 add exch
                } {
                dup 37 eq 3 index in length 2 sub lt and {  % "%nn" -> ord
                    pop
                    (<  >) 4 string copy dup 1 in 5 index 1 add 2 getinterval putinterval cvx
                    stopped {
                        pop pop /bwipp.GS1dlBadHexCharacter (Invalid hex character) //raiseerror exec
                    } if
                    0 get out exch 2 index exch put
                    1 add exch 3 add exch
                } {
                    out exch 2 index exch put
                    1 add exch 1 add exch
                } ifelse } ifelse
            } loop
            out exch 0 exch getinterval /out exch def
            pop
            out
        } def

        /ais 99 array def
        /vals 99 array def
        0

        % Extract AIs from the path components
        pp {
            (/) search {
                ais exch 4 index exch put
                pop
                (/) search {exch pop} {() exch} ifelse
                vals exch 3 index exch uriunescape put
            } {
                pop exit
            } ifelse
            exch 1 add exch
        } loop

        % Validate the key-qualifiers in the path info sequence
        dup 1 gt {
            false
            gs1syntax ais 0 get get /dlpkey get {
                /seq exch def
                /i 1 def  /j 0 def
                {
                    i ais length ge {exit} if
                    j seq length ge {exit} if
                    ais i get seq j get eq {
                        /i i 1 add def
                    } if
                    /j j 1 add def
                } loop
                i 2 index eq {pop true exit} if
            } forall
            not {
                pop /bwipp.GS1dlBadPathInfo (The AIs in the path are not a valid key-qualifier sequence for the key) //raiseerror exec
            } if
        } if

        % Extract AIs from the query parameters
        qp {
            dup () eq {pop exit} if
            (&) search {exch pop} {() exch} ifelse
            (=) search {
                true 1 index {dup 48 ge exch 57 le and and} forall {
                    ais exch 5 index exch put
                    pop
                    vals exch 3 index exch uriunescape put
                    exch 1 add exch
                } {  % Ignore non-numeric parameters
                    pop pop pop
                } ifelse
            } {  % Ignore singletons and empty parameters
                pop
            } ifelse
        } loop

        /ais ais 0 3 index getinterval def
        /vals vals 0 3 index getinterval def
        pop

        % Expand any extracted GTINs
        0 1 ais length 1 sub {
            dup ais exch get (01) eq {
                dup vals exch get
                dup length dup 8 eq exch dup 12 eq exch 13 eq or or {
                    (00000000000000) 14 string copy dup 3 -1 roll dup length 14 exch sub exch putinterval
                    vals exch 2 index exch put
                } {
                    pop
                } ifelse
            } if
            pop
        } for

    } ifelse

    % AIs not requiring FNC1 separation
{
    /aifixed << [
        (00) (01) (02) (03) (04)
        (11) (12) (13) (14) (15) (16) (17) (18) (19) (20)
        % (23)   % Reassigned to variable-length AI (235)!
        (31) (32) (33) (34) (35) (36)
        (41)
    ] {dup} forall >> def
} ctxdef

    /fncs [
        ais {
            true exch
            dup length 2 ge {
                0 2 getinterval aifixed exch known {pop false} if
            } {
                pop
            } ifelse
        } forall
    ] def


    % Linter routines for validating AI components

    /lintnumeric {
        true exch {
            dup 48 lt exch 57 gt or { pop false exit } if
        } forall
        not { pop /bwipp.GS1notNumeric (Not numeric) false exit } if
    } def

    /lintcset82 {
        true exch {
            1 string dup 0 4 -1 roll put
            (!"%&'()*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz)
            exch search not { pop pop false exit } if
            pop pop pop
        } forall
        not { pop /bwipp.GS1badCSET82character (Invalid CSET 82 character) false exit } if
    } def

    /lintcset39 {
        true exch {
            1 string dup 0 4 -1 roll put
            (#-/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ)
            exch search not { pop pop false exit } if
            pop pop pop
        } forall
        not { pop /bwipp.GS1badCSET39character  (Invalid CSET 39 character) false exit } if
    } def

    /lintkey {
        dup length 2 lt { pop pop /bwipp.GS1keyTooShort (Key is too short) false exit } if
        dup 0 get dup 48 lt exch 57 gt or exch
        1 get dup 48 lt exch 57 gt or or {
            pop /bwipp.GS1badGCP (Non-numeric company prefix) false exit
        } if
    } def

    /lintimporteridx {
        (-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz)
        exch search not {pop pop /bwipp.GS1badImporterIndex (Invalid importer index) false exit} if
        pop pop pop
    } def

    /lintcsum {
        mark exch
        dup length 2 mod 0 eq {3} {1} ifelse
        exch { 48 sub 1 index mul exch 4 exch sub } forall pop
        0 counttomark 1 sub {add} repeat exch pop
        10 mod 0 ne { pop /bwipp.GS1badChecksum (Bad checksum) false exit } if
    } def

{
    /cset82 <<
        0 (!"%&'\(\)*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz)
        { exch dup 1 add } forall pop
    >> def

    /cset32 <<
        0 (23456789ABCDEFGHJKLMNPQRSTUVWXYZ)
        { exch dup 1 add } forall pop
    >> def
} ctxdef

    /lintcsumalpha {
        dup length 2 lt { pop pop /bwipp.GS1alphaTooShort (Alphanumeric string is too short to check) false exit} if
        dup length 2 sub
        2 copy
        0 exch getinterval mark exch {
            dup cset82 exch known { cset82 exch get } { -1 exit } ifelse
        } forall
        dup -1 eq { cleartomark pop pop pop /bwipp.GS1UnknownCSET82Character (Unknown CSET 82 character) false exit} if
        counttomark array astore exch pop
        3 1 roll
        2 getinterval mark exch {
            dup cset32 exch known { cset32 exch get } { -1 exit } ifelse
        } forall
        dup -1 eq { cleartomark pop pop /bwipp.GS1UnknownCSET32Character (Unknown CSET 32 character) false exit} if
        counttomark array astore exch pop
        dup 0 get 5 bitshift exch 1 get add exch
        [ 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 ]
        1 index length
        dup 2 index length gt { pop pop pop pop pop /bwipp.GS1alphaTooLong (Alphanumeric string is too long to check) false exit} if
        0 exch getinterval {exch} forall
        0 exch { 3 -1 roll exch mul add } forall 1021 mod
        ne { pop /bwipp.GS1badAlphaCheckCharacters (Bad alphanumeric check characters) false exit} if
    } def

{
    /iso3166 << [
        /004 /008 /010 /012 /016 /020 /024 /028 /031 /032 /036 /040 /044 /048
        /050 /051 /052 /056 /060 /064 /068 /070 /072 /074 /076 /084 /086 /090 /092 /096
        /100 /104 /108 /112 /116 /120 /124 /132 /136 /140 /144 /148
        /152 /156 /158 /162 /166 /170 /174 /175 /178 /180 /184 /188 /191 /192 /196
        /203 /204 /208 /212 /214 /218 /222 /226 /231 /232 /233 /234 /238 /239 /242 /246 /248
        /250 /254 /258 /260 /262 /266 /268 /270 /275 /276 /288 /292 /296
        /300 /304 /308 /312 /316 /320 /324 /328 /332 /334 /336 /340 /344 /348
        /352 /356 /360 /364 /368 /372 /376 /380 /384 /388 /392 /398
        /400 /404 /408 /410 /414 /417 /418 /422 /426 /428 /430 /434 /438 /440 /442 /446
        /450 /454 /458 /462 /466 /470 /474 /478 /480 /484 /492 /496 /498 /499
        /500 /504 /508 /512 /516 /520 /524 /528 /531 /533 /534 /535 /540 /548
        /554 /558 /562 /566 /570 /574 /578 /580 /581 /583 /584 /585 /586 /591 /598
        /600 /604 /608 /612 /616 /620 /624 /626 /630 /634 /638 /642 /643 /646
        /652 /654 /659 /660 /662 /663 /666 /670 /674 /678 /682 /686 /688 /690 /694
        /702 /703 /704 /705 /706 /710 /716 /724 /728 /729 /732 /740 /744 /748
        /752 /756 /760 /762 /764 /768 /772 /776 /780 /784 /788 /792 /795 /796 /798
        /800 /804 /807 /818 /826 /831 /832 /833 /834 /840
        /850 /854 /858 /860 /862 /876 /882 /887 /894
    ] {dup} forall >> def
} ctxdef

    /lintiso3166 {
        iso3166 exch known not { pop /bwipp.GS1UnknownCountry (Unknown country code) false exit } if
    } def

    /lintiso3166999 {
        dup /999 ne {
            iso3166 exch known not { pop /bwipp.GS1UnknownCountryOr999 (Unknown country code or not 999) false exit } if
        } {
            pop
        } ifelse
    } def

    /lintiso3166list {
        dup length 3 mod 0 ne {
            pop pop /bwipp.GS1BadCountryListLength (Not a group of three-digit country codes) false exit
        } if
        true
        0 3 3 index length 1 sub {
            2 index exch 3 getinterval
            iso3166 exch known not { pop pop false exit } if
        } for
        not { pop /bwipp.GS1UnknownCountry (Unknown country code) false exit } if
        pop
    } def

{
    /iso3166alpha2 << [
        /AD /AE /AF /AG /AI /AL /AM /AO /AQ /AR /AS /AT /AU /AW /AX /AZ
        /BA /BB /BD /BE /BF /BG /BH /BI /BJ /BL /BM /BN /BO /BQ /BR /BS /BT /BV /BW /BY /BZ
        /CA /CC /CD /CF /CG /CH /CI /CK /CL /CM /CN /CO /CR /CU /CV /CW /CX /CY /CZ
        /DE /DJ /DK /DM /DO /DZ
        /EC /EE /EG /EH /ER /ES /ET
        /FI /FJ /FK /FM /FO /FR
        /GA /GB /GD /GE /GF /GG /GH /GI /GL /GM /GN /GP /GQ /GR /GS /GT /GU /GW /GY
        /HK /HM /HN /HR /HT /HU
        /ID /IE /IL /IM /IN /IO /IQ /IR /IS /IT /JE /JM /JO /JP
        /KE /KG /KH /KI /KM /KN /KP /KR /KW /KY /KZ
        /LA /LB /LC /LI /LK /LR /LS /LT /LU /LV /LY
        /MA /MC /MD /ME /MF /MG /MH /MK /ML /MM /MN /MO /MP /MQ /MR /MS /MT /MU /MV /MW /MX /MY /MZ
        /NA /NC /NE /NF /NG /NI /NL /NO /NP /NR /NU /NZ
        /OM
        /PA /PE /PF /PG /PH /PK /PL /PM /PN /PR /PS /PT /PW /PY
        /QA
        /RE /RO /RS /RU /RW
        /SA /SB /SC /SD /SE /SG /SH /SI /SJ /SK /SL /SM /SN /SO /SR /SS /ST /SV /SX /SY /SZ
        /TC /TD /TF /TG /TH /TJ /TK /TL /TM /TN /TO /TR /TT /TV /TW /TZ
        /UA /UG /UM /US /UY /UZ
        /VA /VC /VE /VG /VI /VN /VU
        /WF /WS
        /YE /YT
        /ZA /ZM /ZW
    ] {dup} forall >> def
} ctxdef

    /lintiso3166alpha2 {
        iso3166alpha2 exch known not { pop /bwipp.GS1UnknownCountryAlpha (Unknown country alpha code) false exit } if
    } def

{
    /iso4217 << [
        /008 /012 /032 /036 /044 /048
        /050 /051 /052 /060 /064 /068 /072 /084 /090 /096
        /104 /108 /116 /124 /132 /136 /144
        /152 /156 /170 /174 /188 /191 /192
        /203 /208 /214 /222 /230 /232 /238 /242 /262 /270 /292
        /320 /324 /328 /332 /340 /344 /348
        /352 /356 /360 /364 /368 /376 /388 /392 /398
        /400 /404 /408 /410 /414 /417 /418
        /422 /426 /430 /434 /446
        /454 /458 /462 /480 /484 /496 /498
        /504 /512 /516 /524 /532 /533 /548
        /554 /558 /566 /578 /586 /590 /598
        /600 /604 /608 /634 /643 /646 /654 /682 /690 /694
        /702 /704 /706 /710 /728 /748
        /752 /756 /760 /764 /776 /780 /784 /788
        /800 /807 /818 /826 /834 /840 /858 /860 /882 /886
        /901 /925 /927 /928 /929 /930 /931 /932 /933 /934 /936 /938
        /940 /941 /943 /944 /946 /947 /948 /949
        /950 /951 /952 /953 /955 /956 /957 /958 /959
        /960 /961 /962 /963 /964 /965 /967 /968 /969
        /970 /971 /972 /973 /975 /976 /977 /978 /979
        /980 /981 /984 /985 /986 /990 /994 /997 /999
    ] {dup} forall >> def
} ctxdef

    /lintiso4217 {
        iso4217 exch known not { pop /bwipp.GS1UnknownCurrency (Unknown currency code) false exit } if
    } def

    /lintiban {
        dup length 4 le { pop pop /bwipp.GS1tooShort (IBAN too short) false exit } if
        dup true exch {
            1 string dup 0 4 -1 roll put
            (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ)
            exch search not { pop pop false exit } if
            pop pop pop
        } forall
        not { pop /bwipp.GS1badIBANcharacter (Invalid IBAN character) false exit } if
        dup mark exch mark exch {} forall counttomark -4 roll counttomark array astore exch pop {
            48 sub dup 9 gt {7 sub dup 10 idiv exch 10 mod} if
        } forall counttomark array astore exch pop
        0 exch {exch 10 mul add 97 mod} forall
        1 ne { pop pop /bwipp.GS1badIBANchecksum (IBAN checksum incorrect) false exit } if
        0 2 getinterval lintiso3166alpha2
    } def

    /lintzero {
        (0) ne { pop /bwipp.GS1zeroRequired (Zero is required) false exit } if
    } def

    /lintnonzero {
        false exch { 48 ne {pop true} if } forall
        not { pop /bwipp.GS1zeroNotPermitted (Zero not permitted) false exit } if
    } def

    /lintnozeroprefix {
        dup length 1 gt exch 0 get 48 eq and {
            pop /bwipp.GS1badZeroPrefix (Zero prefix is not permitted) false exit
        } if
    } def

    /lintyymmd0 {
        dup 2 2 getinterval cvi dup 1 lt exch 12 gt or { pop /bwipp.GS1badMonth (Invalid month) false exit } if
        dup 0 2 getinterval cvi dup  21  sub  % Update 20YY periodically for century calculation
        dup 51 ge {pop 1900 add} { -50 le {2100 add} {2000 add} ifelse} ifelse  % YYYY
        dup 400 mod 0 eq exch dup 4 mod 0 eq exch 100 mod 0 ne and or           % Leap year?
        [ 31  3 -1 roll {29} {28} ifelse  31 30 31 30 31 31 30 31 30 31 ]
        1 index 2 2 getinterval cvi 1 sub get
        exch 4 2 getinterval cvi lt { pop /bwipp.GS1badDay (Invalid day of month) false exit } if
    } def

    /lintyymmdd {
        dup length 6 ne { pop /bwipp.GS1badDateLength (Invalid length for date) false exit } if
        dup 4 2 getinterval cvi 1 lt { pop /bwipp.GS1badDay (Invalid day of month) false exit } if
        lintyymmd0
    } def

    /lintyymmddhh {
        dup length 8 ne { pop /bwipp.GS1badYYMMDDHHLength (Invalid length for date with hour) false exit } if
        dup 6 2 getinterval cvi 23 gt { pop pop /bwipp.GS1badHour (Invalid hour of day) false exit } if
        0 6 getinterval lintyymmdd
    } def

    /linthhmm {
        dup 0 2 getinterval cvi 23 gt { pop pop /bwipp.GS1badHour (Invalid hour of day) false exit } if
        2 2 getinterval cvi 59 gt { pop /bwipp.GS1badMinute (Invalid minute in the hour) false exit } if
    } def

    /lintmmoptss {
        dup length dup 2 ne exch 4 ne and {
            pop /bwipp.GS1badTimeLength (Invalid length for optional minutes and seconds) false exit
        } if
        dup 0 2 getinterval cvi 59 gt { pop pop /bwipp.GS1badMinute (Invalid minute in the hour) false exit } if
        dup length 4 ge {
            dup 2 2 getinterval cvi 59 gt { pop pop /bwipp.GS1badSecond (Invalid second in the minute) false exit } if
        } if
        pop
    } def

    /lintyesno {
        dup (0) ne exch (1) ne and {
            pop /bwipp.GS1badBoolean (Neither 0 nor 1 for yes or no) false exit
        } if
    } def

    /lintwinding {
        dup (0) ne exch dup (1) ne exch (9) ne and and {
            pop /bwipp.GS1badWinding (Invalid winding direction) false exit
        } if
    } def

    /lintpieceoftotal {
        dup length 2 mod 0 ne { pop pop /bwipp.GS1badPieceTotalLength (Invalid piece/total length) false exit } if
        dup dup length 2 idiv 0 exch getinterval cvi
        dup 0 eq { pop pop pop /bwipp.GS1badPieceNumber (Invalid piece number) false exit } if
        exch dup length 2 idiv dup getinterval cvi
        dup 0 eq { pop pop pop /bwipp.GS1badPieceTotal (Invalid total number) false exit } if
        gt { pop /bwipp.GS1pieceExceedsTotal (Piece number exceeds total) false exit } if
    } def

    /lintpcenc {
        {
            (%) search not {pop exit} if
            pop pop dup length 2 lt { pop pop /bwipp.GS1badPercentEscape (Invalid % escape) false exit } if
            dup 0 2 getinterval true exch {
                1 string dup 0 4 -1 roll put
                (0123456789ABCDEFabcdef)
                exch search not { pop pop false exit } if
                pop pop pop
            } forall
            not { pop pop /bwipp.GS1badPercentChars (Invalid characters for percent encoding) false exit } if
        } loop
    } def

    /lintcouponcode {
        dup true exch {
            dup 48 lt exch 57 gt or { pop false exit } if
        } forall
        not { pop pop /bwipp.GS1couponNotNumeric (Coupon not numeric) false exit } if

        % GCP VLI and value
        dup length 1 lt {
            pop pop /bwipp.GS1couponTooShortGCPVLI (Coupon too short: Missing GCP VLI) false exit
        } if
        dup 0 1 getinterval cvi dup 6 gt {
            pop pop /bwipp.GS1couponBadGCPVLI (Coupon GCP length indicator must be 0-6) false exit
        } if
        6 add 1 add
        2 copy exch length gt {
            pop pop pop /bwipp.GS1couponTooShortGCP (Coupon too short: GCP truncated) false exit
        } if
        dup 2 index length exch sub getinterval

        % Offer Code
        dup length 6 lt {
            pop pop /bwipp.GS1couponTooShortOfferCode (Coupon too short: Offer Code truncated) false exit
        } if
        dup length 6 sub 6 exch getinterval

        % Save Value VLI and value
        dup length 1 lt {
            pop pop /bwipp.GS1couponTooShortSaveValueVLI (Coupon too short: Missing Save Value VLI) false exit
        } if
        dup 0 1 getinterval cvi dup dup 1 lt exch 5 gt or {
            pop pop /bwipp.GS1couponBadSaveValueVLI (Coupon Save Value length indicator must be 1-5) false exit
        } if
        1 add
        2 copy exch length gt {
            pop pop pop /bwipp.GS1couponTooShortSaveValue (Coupon too short: Save Value truncated) false exit
        } if
        dup 2 index length exch sub getinterval

        % 1st Purchase Requirement VLI and value
        dup length 1 lt {
            pop pop /bwipp.GS1couponTooShort1stPurchaseRequirementVLI (Coupon too short: Missing 1st Purchase Requirement VLI) false exit
        } if
        dup 0 1 getinterval cvi dup dup 1 lt exch 5 gt or {
            pop pop /bwipp.GS1couponBad1stPurchaseRequirementVLI (Coupon 1st Purchase Requirement length indicator must be 1-5) false exit
        } if
        1 add
        2 copy exch length gt {
            pop pop pop /bwipp.GS1couponTooShort1stPurchaseRequirement (Coupon too short: 1st Purchase Requirement truncated) false exit
        } if
        dup 2 index length exch sub getinterval

        % 1st Purchase Requirement Code
        dup length 1 lt {
            pop pop /bwipp.GS1couponTooShort1stPurchaseRequirementCode (Coupon too short: Missing 1st Purchase Requirement Code) false exit
        } if
        dup 0 1 getinterval cvi dup 4 gt exch 9 ne and {
            pop pop /bwipp.GS1couponBad1stPurchaseRequirementCode (Coupon 1st Purchase Requirement Code must be 0-4 or 9) false exit
        } if
        dup length 1 sub 1 exch getinterval

        % 1st Purchase Family Code
        dup length 3 lt {
            pop pop /bwipp.GS1couponTooShort1stPurchaseFamilyCode (Coupon too short: 1st Purchase Family Code truncated) false exit
        } if
        dup length 3 sub 3 exch getinterval

        % Optional field 1
        dup length 1 ge { dup 0 1 getinterval cvi 1 eq {
            1 dup 2 index length exch sub getinterval

            % Additional Purchase Rules Code
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShortAdditionalPurchaseRulesCode (Coupon too short: Missing Additional Purchase Rules Code) false exit
            } if
            dup 0 1 getinterval cvi 3 gt {
                pop pop /bwipp.GS1couponBadAdditionalPurchaseRulesCode (Coupon Additional Purchase Rules Code must be 0-3) false exit
            } if
            dup length 1 sub 1 exch getinterval

            % 2nd Purchase RequirementVLI and value
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShort2ndPurchaseRequirementVLI (Coupon too short: Missing 2nd Purchase Requirement VLI) false exit
            } if
            dup 0 1 getinterval cvi dup dup 1 lt exch 5 gt or {
                pop pop /bwipp.GS1couponBad2ndPurchaseRequirementVLI (Coupon 2nd Purchase Requirement length indicator must be 1-5) false exit
            } if
            1 add
            2 copy exch length gt {
                pop pop pop /bwipp.GS1couponTooShort2ndPurchaseRequirement (Coupon too short: 2nd Purchase Requirement truncated) false exit
            } if
            dup 2 index length exch sub getinterval

            % 2nd Purchase Requirement Code
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShort2ndPurchaseRequirementCode (Coupon too short: Missing 2nd Purchase Requirement Code) false exit
            } if
            dup 0 1 getinterval cvi dup 4 gt exch 9 ne and {
                pop pop /bwipp.GS1couponBad2ndPurchaseRequirementCode (Coupon 2nd Purchase Requirement Code must be 0-4 or 9) false exit
            } if
            dup length 1 sub 1 exch getinterval

            % 2nd Purchase Family Code
            dup length 3 lt {
                pop pop /bwipp.GS1couponTooShort2ndPurchaseFamilyCode (Coupon too short: 2nd Purchase Family Code truncated) false exit
            } if
            dup length 3 sub 3 exch getinterval

            % 2nd Purchase GCP VLI and value
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShort2ndPurchaseGCPVLI (Coupon too short: Missing 2nd Purchase GCP VLI) false exit
            } if
            dup 0 1 getinterval cvi dup dup 6 gt exch 9 ne and {
                pop pop /bwipp.GS1couponBad2ndPurchaseGCPVLI (Coupon 2nd Purchase GCP length indicator must be 0-6 or 9) false exit
            } if
            dup 9 ne {6 add} {pop 0} ifelse 1 add
            2 copy exch length gt {
                pop pop pop /bwipp.GS1couponTooShort2ndPurchaseGCP (Coupon too short: 2nd Purchase GCP truncated) false exit
            } if
            dup 2 index length exch sub getinterval

        } if } if

        % Optional field 2
        dup length 1 ge { dup 0 1 getinterval cvi 2 eq {
            1 dup 2 index length exch sub getinterval

            % 3rd Purchase RequirementVLI and value
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShort3rdPurchaseRequirementVLI (Coupon too short: Missing 3rd Purchase Requirement VLI) false exit
            } if
            dup 0 1 getinterval cvi dup dup 1 lt exch 5 gt or {
                pop pop /bwipp.GS1couponBad3rdPurchaseRequirementVLI (Coupon 3rd Purchase Requirement length indicator must be 1-5) false exit
            } if
            1 add
            2 copy exch length gt {
                pop pop pop /bwipp.GS1couponTooShort3rdPurchaseRequirement (Coupon too short: 3rd Purchase Requirement truncated) false exit
            } if
            dup 2 index length exch sub getinterval

            % 3rd Purchase Requirement Code
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShort3rdPurchaseRequirementCode (Coupon too short: Missing 3rd Purchase Requirement Code) false exit
            } if
            dup 0 1 getinterval cvi dup 4 gt exch 9 ne and {
                pop pop /bwipp.GS1couponBad3rdPurchaseRequirementCode (Coupon 3rd Purchase Requirement Code must be 0-4 or 9) false exit
            } if
            dup length 1 sub 1 exch getinterval

            % 3rd Purchase Family Code
            dup length 3 lt {
                pop pop /bwipp.GS1couponTooShort3rdPurchaseFamilyCode (Coupon too short: 3rd Purchase Family Code truncated) false exit
            } if
            dup length 3 sub 3 exch getinterval

            % 3rd Purchase GCP VLI and value
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShort3rdPurchaseGCPVLI (Coupon too short: Missing 3rd Purchase GCP VLI) false exit
            } if
            dup 0 1 getinterval cvi dup dup 6 gt exch 9 ne and {
                pop pop /bwipp.GS1couponBad3rdPurchaseGCPVLI (Coupon 3rd Purchase GCP length indicator must be 0-6 or 9) false exit
            } if
            dup 9 ne {6 add} {pop 0} ifelse 1 add
            2 copy exch length gt {
                pop pop pop /bwipp.GS1couponTooShort3rdPurchaseGCP (Coupon too short: 3rd Purchase GCP truncated) false exit
            } if
            dup 2 index length exch sub getinterval

        } if } if

        % Optional field 3
        /couponexpire -1 def
        dup length 1 ge { dup 0 1 getinterval cvi 3 eq {
            1 dup 2 index length exch sub getinterval

            % Expiration date
            dup length 6 lt {
                pop pop /bwipp.GS1couponTooShortExpirationDate (Coupon too short: Expiration date) false exit
            } if
            dup 2 2 getinterval cvi dup 1 lt exch 12 gt or { pop pop /bwipp.GS1couponExpirationDateBadMonth (Invalid month in expiration date) false exit } if
            dup 0 2 getinterval cvi dup 21 sub  % Update 20YY periodically for century calculation
            dup 51 ge {pop 1900 add} { -50 le {2100 add} {2000 add} ifelse} ifelse  % YYYY
            dup 400 mod 0 eq exch dup 4 mod 0 eq exch 100 mod 0 ne and or           % Leap year?
            [ 31  3 -1 roll {29} {28} ifelse  31 30 31 30 31 31 30 31 30 31 ]
            1 index 2 2 getinterval cvi 1 sub get
            1 index 4 2 getinterval cvi dup 3 1 roll lt
            exch 1 lt or { pop pop /bwipp.GS1couponExpirationDateBadDay (Invalid day of month in expiration date) false exit } if
            dup 0 6 getinterval cvi /couponexpire exch def
            dup length 6 sub 6 exch getinterval

        } if } if

        % Optional field 4
        dup length 1 ge { dup 0 1 getinterval cvi 4 eq {
            1 dup 2 index length exch sub getinterval

            % Start date
            dup length 6 lt {
                pop pop /bwipp.GS1couponTooShortStartDate (Coupon too short: Start date) false exit
            } if
            dup 2 2 getinterval cvi dup 1 lt exch 12 gt or { pop pop /bwipp.GS1couponStartDateBadMonth (Invalid month in start date) false exit } if
            dup 0 2 getinterval cvi dup 21 sub  % Update 20YY periodically for century calculation
            dup 51 ge {pop 1900 add} { -50 le {2100 add} {2000 add} ifelse} ifelse  % YYYY
            dup 400 mod 0 eq exch dup 4 mod 0 eq exch 100 mod 0 ne and or           % Leap year?
            [ 31  3 -1 roll {29} {28} ifelse  31 30 31 30 31 31 30 31 30 31 ]
            1 index 2 2 getinterval cvi 1 sub get
            1 index 4 2 getinterval cvi dup 3 1 roll lt
            exch 1 lt or { pop pop /bwipp.GS1couponStartDateBadDay (Invalid day of month in start date) false exit } if
            dup 0 6 getinterval cvi /couponstart exch def
            couponexpire -1 ne couponexpire couponstart lt and {
                pop pop /bwipp.GS1couponExpireDateBeforeStartDate (Coupon expires before it starts) false exit
            } if
            dup length 6 sub 6 exch getinterval

        } if } if

        % Optional field 5
        dup length 1 ge { dup 0 1 getinterval cvi 5 eq {
            1 dup 2 index length exch sub getinterval

            % Serial Number VLI and value
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShortSerialNumberVLI (Coupon too short: Missing Serial Number VLI) false exit
            } if
            dup 0 1 getinterval cvi 6 add 1 add
            2 copy exch length gt {
                pop pop pop /bwipp.GS1couponTooShortSerialNumber (Coupon too short: Serial Number truncated) false exit
            } if
            dup 2 index length exch sub getinterval

        } if } if

        % Optional field 6
        dup length 1 ge { dup 0 1 getinterval cvi 6 eq {
            1 dup 2 index length exch sub getinterval

            % Retailer GCP/GLN VLI and value
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShortRetailerGCPGLNVLI (Coupon too short: Missing Retailer GCP/GLN VLI) false exit
            } if
            dup 0 1 getinterval cvi dup dup 1 lt exch 7 gt or {
                pop pop /bwipp.GS1couponBadRetailerGCPGLNVLI (Coupon Retailer GCP/GLN length indicator must be 1-7) false exit
            } if
            6 add 1 add
            2 copy exch length gt {
                pop pop pop /bwipp.GS1couponTooShortRetailerGCPGLN (Coupon too short: Retailer GCP/GLN truncated) false exit
            } if
            dup 2 index length exch sub getinterval

        } if } if

        % Optional field 9
        dup length 1 ge { dup 0 1 getinterval cvi 9 eq {
            1 dup 2 index length exch sub getinterval

            % Save Value Code
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShortSaveValueCode (Coupon too short: Missing Save Value Code) false exit
            } if
            dup 0 1 getinterval cvi dup 6 gt exch dup 3 eq exch 4 eq or or {
                pop pop /bwipp.GS1couponBadSaveValueCode (Coupon Save Value Code must be 0,1,2,5 or 6) false exit
            } if
            dup length 1 sub 1 exch getinterval

            % Save Value Applies to Item
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShortSaveValueAppliesToItem (Coupon too short: Missing Save Value Applies to Item) false exit
            } if
            dup 0 1 getinterval cvi 2 gt {
                pop pop /bwipp.GS1couponBadSaveValueAppliesToItem (Coupon Save Value Applies to Item must be 0-2) false exit
            } if
            dup length 1 sub 1 exch getinterval

            % Store Coupon Flag
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShortStoreCouponFlag (Coupon too short: Missing Store Coupon Flag) false exit
            } if
            dup length 1 sub 1 exch getinterval

            % Don't Multiply Flag
            dup length 1 lt {
                pop pop /bwipp.GS1couponTooShortDontMultiplyFlag (Coupon too short: Missing Don't Multiply Flag) false exit
            } if
            dup 0 1 getinterval cvi 1 gt {
                pop pop /bwipp.GS1couponBadDontMultiplyFlag (Don't Multiply Flag must be 0 or 1) false exit
            } if
            dup length 1 sub 1 exch getinterval

        } if } if

        dup length 0 ne {
            pop pop /bwipp.GS1couponUnrecognisedOptionalField (Coupon fields must be 1,2,3,4,5,6 or 9, increasing order) false exit
        } if
        pop
    } def

    /lintcouponposoffer {
        dup true exch {
            dup 48 lt exch 57 gt or { pop false exit } if
        } forall
        not { pop pop /bwipp.GS1couponNotNumeric (Coupon not numeric) false exit } if
        % Format Code
        dup length 1 lt {
            pop pop /bwipp.GS1couponTooShortFormatCode (Coupon too short: Missing Format Code) false exit
        } if
        dup 0 1 getinterval dup (0) ne exch (1) ne and {
            pop pop /bwipp.GS1couponBadFormatCode (Coupon format must be 0 or 1) false exit
        } if
        dup length 1 sub 1 exch getinterval
        % Funder ID VLI and Funder ID
        dup length 1 lt {
            pop pop /bwipp.GS1couponTooShortFunderVLI (Coupon too short: Missing Funder VLI) false exit
        } if
        dup 0 1 getinterval cvi dup 6 gt {
            pop pop pop /bwipp.GS1couponBadFunderVLI (Coupon Funder length indicator must be 0-6) false exit
        } if
        6 add 1 add
        2 copy exch length gt {
            pop pop pop /bwipp.GS1couponTooShortFunder (Coupon too short: Truncated Funder ID) false exit
        } if
        dup 2 index length exch sub getinterval
        % Offer Code
        dup length 6 lt {
            pop pop /bwipp.GS1couponTooShortOfferCode (Coupon too short: Truncated Offer Code) false exit
        } if
        dup length 6 sub 6 exch getinterval
        % Serial Number VLI and Serial Number
        dup length 1 lt {
            pop pop /bwipp.GS1couponTooShortSnVLI (Coupon too short: Missing SN VLI) false exit
        } if
        dup 0 1 getinterval cvi
        6 add 1 add
        2 copy exch length gt {
            pop pop pop /bwipp.GS1couponTooShortSn (Coupon too short: Truncated SN) false exit
        } if
        dup 2 index length exch sub getinterval
        dup length 0 ne {
            pop pop /bwipp.GS1couponTooLong (Coupon too long) false exit
        } if
        pop
    } def

    /lintlatlong {
        dup length 20 ne {
            pop /bwipp.GS1badGeoLength (Invalid length for a geo-location) false exit
        } if
        dup  0 10 getinterval cvi 1800000000 gt { pop /bwipp.GS1badLatitude (Invalid value for latitude) false exit } if
        dup 10 10 getinterval cvi 3600000000 gt { pop /bwipp.GS1badLongitude (Invalid value for longitude) false exit } if
        pop
    } def

    dontlint not {

        % Validate AI contents
        true
        0 1 vals length 1 sub {
            dup ais exch get /ai exch def
            vals exch get /val exch def
            gs1syntax ai known {
                gs1syntax ai get /parts get
                % Overall length checks, e.g. to report "too long", not "checksum failure"
                dup 0 exch {dup /opt get {pop 0} {/min get} ifelse add} forall val length gt {
                    pop /bwipp.GS1valueTooShort (Too short) false exit
                } if
                dup 0 exch {/max get add} forall val length lt {
                    pop /bwipp.GS1valueTooLong (Too long) false exit
                } if
                {  % Checks for each component of the AI
                    /props exch def
                    props /max get val length 2 copy gt {exch} if pop
                    val exch 0 exch getinterval /eval exch def
                    /val val eval length dup val length exch sub getinterval def
                    eval length 0 eq {
                        props /opt get not {
                            pop /bwipp.GS1valueTooShort (Too short) false exit
                        } if
                    } {
                        eval length props /min get lt {
                            pop /bwipp.GS1valueTooShort (Too short) false exit
                        } if
                        << /N /lintnumeric  /X /lintcset82  /Y /lintcset39 >> props /cset get get eval exch load exec
                        props /linters get { eval exch load exec } forall
                    } ifelse
                } forall
                dup not {exit} if
                val length 0 ne {  % Not all data consumed by components
                    pop /bwipp.GS1valueTooLong (Too long) false exit
                } if
            } {
                pop /bwipp.GS1unknownAI (Unrecognised AI) false exit
            } ifelse
        } for
        not {
            dup length ai length add 5 add string
            dup 0 (AI ) putinterval
            dup 3 ai putinterval
            dup 3 ai length add (: ) putinterval
            dup 5 ai length add 4 -1 roll putinterval
            //raiseerror exec
        } if

        % Search for "patt" matching an AIs, excluding "this" AI
        /aiexists {
            /this exch def
            /patt exch def
            1 {  % common exit
                aivals patt known {true exit} if  % Fast path
                patt length 4 eq {
                    patt 3 1 getinterval (n) eq {
                        /pfxlen patt 2 1 getinterval (n) eq {2} {3} ifelse def
                        false
                        ais {
                            dup dup this ne exch length 4 eq and {
                                0 pfxlen getinterval patt 0 pfxlen getinterval eq {
                                    pop true
                                } if
                            } {
                                pop
                            } ifelse
                        } forall
                        exit
                    } if
                    false exit
                } if
                false exit
            } repeat
        } def

        % Build AI dict and validate repeats
        /aivals vals length dict def
        0 1 vals length 1 sub {
            dup ais exch get /ai exch def
            vals exch get /val exch def
            aivals ai known {
                aivals ai get val ne {
                    ai length 40 add string
                    dup 0 (Repeated AIs \() putinterval
                    dup 14 ai putinterval
                    dup 14 ai length add (\) must have the same value) putinterval
                    /bwipp.GS1repeatedDifferingAIs exch //raiseerror exec
                } if
            } {
                aivals ai val put
            } ifelse
        } for

        % Validate ex and req pairings
        0 1 vals length 1 sub {
            ais exch get /ai exch def
            gs1syntax ai get /ex 2 copy known {
                get {
                    /patt exch def
                    patt ai aiexists {
                        ai length patt length add 36 add string
                        dup 0 (AIs \() putinterval
                        dup 5 ai putinterval
                        dup 5 ai length add (\) and \() putinterval
                        dup 12 ai length add patt putinterval
                        dup 12 ai length add patt length add (\) are mutually exclusive) putinterval
                        /bwipp.GS1exclusiveAIs exch //raiseerror exec
                    } if
                } forall
            } {
                pop pop
            } ifelse
            lintreqs {
                gs1syntax ai get /req 2 copy known {
                    get {  % For each req attribute group
                        false exch {  % Any req AI in the group is fine
                            ai aiexists {pop true} if
                        } forall
                        not {
                            ai length 47 add string
                            dup 0 (One of more requisite AIs for AI \() putinterval
                            dup 34 ai putinterval
                            dup 34 ai length add (\) are missing) putinterval
                            /bwipp.GS1missingAIs exch //raiseerror exec
                        } if
                    } forall
                } {
                    pop pop
                } ifelse
            } if
        } for

    } if  % dontlint

    ais vals fncs

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/gs1process dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RESOURCE gs1process--

% --BEGIN RENDERER renlinear--
% --REQUIRES preamble raiseerror--
%%BeginResource: uk.co.terryburton.bwipp renlinear 0.0 2022082100 75512 74718
%%BeginData:        246 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
begin
/renlinear {

    20 dict begin          % Confine variables to local scope

    /args exch def   % We are given some arguments

    % Default options
    /sbs [] def
    /bhs [] def
    /bbs [] def
    /txt [] def
    /barcolor (unset) def
    /includetext false def
    /textcolor (unset) def
    /textxalign (unset) def
    /textyalign (unset) def
    /textfont (Courier) def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset 0 def
    /textgaps 0 def
    /alttext () def
    /bordercolor (unset) def
    /backgroundcolor (unset) def
    /inkspread 0.15 def
    /width 0 def
    /barratio 1 def
    /spaceratio 1 def
    /showborder false def
    /borderleft 10 def
    /borderright 10 def
    /bordertop 1 def
    /borderbottom 1 def
    /borderwidth 0.5 def
    /guardwhitespace false def
    /guardleftpos 0 def
    /guardleftypos 0 def
    /guardrightpos 0 def
    /guardrightypos 0 def
    /guardwidth 6 def
    /guardheight 7 def

    % Apply the renderer options and the user options
    args {def} forall
    opt {def} forall

    /barcolor barcolor cvlit def
    /textcolor textcolor cvlit def
    /textxalign textxalign cvlit def
    /textyalign textyalign cvlit def
    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /textgaps textgaps cvr def
    /alttext alttext cvlit def
    /bordercolor bordercolor cvlit def
    /backgroundcolor backgroundcolor cvlit def
    /inkspread inkspread cvr def
    /width width cvr def
    /barratio barratio cvr def
    /spaceratio spaceratio cvr def
    /borderleft borderleft cvr def
    /borderright borderright cvr def
    /bordertop bordertop cvr def
    /borderbottom borderbottom cvr def
    /borderwidth borderwidth cvr def
    /guardleftpos guardleftpos cvr def
    /guardleftypos guardleftypos cvr def
    /guardrightpos guardrightpos cvr def
    /guardrightypos guardrightypos cvr def
    /guardwidth guardwidth cvr def
    /guardheight guardheight cvr def

    % Create bar elements and put them into the bars array
    /bars sbs length 1 add 2 idiv array def
    /pixx 0 def /pixy 0 def
    0 1 sbs length 1 add 2 idiv 2 mul 2 sub {
        /i exch def
        i 2 mod 0 eq {           % i is even
            /d sbs i get barratio mul barratio sub 1 add def  % d = digit*r-r+1
            sbs i get 0 ne {
                /h bhs i 2 idiv get 72 mul def  % Height from bhs
                /c d 2 div pixx add def         % Centre of the bar = pixx + d/2
                /y bbs i 2 idiv get 72 mul def  % Baseline from bbs
                /w d inkspread sub def          % bar width = digit - inkspread
                bars i 2 idiv [h c y w] put     % Add the bar entry
                h y add pixy gt {/pixy h y add def} if
            } {
                bars i 2 idiv -1 put            % Dummy entry
            } ifelse
        } {
            /d sbs i get spaceratio mul spaceratio sub 1 add def  % d = digit*r-r+1
        } ifelse
        /pixx pixx d add def  % pixx += d
    } for

    gsave

    currentpoint translate

    % Force symbol to given width
    width 0 ne {
        width 72 mul pixx div 1 scale
    } if

    % 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
    } def

    % Display the border and background
    newpath
    borderleft neg borderbottom neg moveto
    pixx borderleft add borderright add 0 rlineto
    0 pixy borderbottom add bordertop add rlineto
    pixx borderleft add borderright add neg 0 rlineto
    0 pixy borderbottom add bordertop add neg rlineto
    closepath
    backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
    showborder {
        gsave
        bordercolor (unset) ne { bordercolor setanycolor } if
        borderwidth setlinewidth stroke
        grestore
    } if

    % Display the bars for elements in the bars array
    gsave
    barcolor (unset) ne { barcolor setanycolor } if
    newpath
    bars {
        dup -1 ne {
            aload pop  % h x y w
            2 index 1 index 2 div sub 2 index moveto
            0 4 index rlineto
            dup 0 rlineto
            0 4 index neg rlineto
            closepath
            pop pop pop pop
        } {
            pop
        } ifelse
    } forall
    fill
    grestore

    % Display the text for elements in the text array
    textcolor (unset) ne { textcolor setanycolor } if
    includetext {
        textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
            /s 0 def /fn () def
            txt {
                {} forall
                2 copy s ne exch fn ne or {
                    2 copy /s exch def /fn exch def
                    selectfont
                } {
                    pop pop
                } ifelse
                moveto show
            } forall
        } {
            textfont textsize selectfont
            alttext () eq {
                /txt [ txt { 0 get {} forall } forall ] def
                /tstr txt length string def
                0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
            } {
                /tstr alttext def
            } ifelse

            % Find true ascent of font
            tstr length 0 eq {
                0
            } {
                gsave
                newpath 0 0 moveto (0) false charpath pathbbox
                4 1 roll pop pop pop
                grestore
                currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
                currentfont /StrokeWidth known and {
                    currentfont /StrokeWidth get 2 div 0 exch
                    currentfont /FontMatrix get dtransform
                    dup mul exch dup mul add sqrt
                    add
                } if
            } ifelse
            /textascent exch def
            /textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def

            /textxpos textxoffset pixx textwidth sub 2 div add def
            textxalign (left) eq { /textxpos textxoffset def } if
            textxalign (right) eq { /textxpos pixx textxoffset sub textwidth sub def } if
            textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
            textxalign (offright) eq { /textxpos pixx textxoffset add def } if
            textxalign (justify) eq textwidth pixx lt and {
                /textxpos 0 def
                /textgaps pixx textwidth sub tstr length 1 sub div def
            } if
            /textypos textyoffset textascent add 1 add neg def
            textyalign (above) eq { /textypos textyoffset pixy add 1 add def } if
            textyalign (center) eq { /textypos textyoffset pixy textascent sub 2 div add def } if
            textxpos textypos moveto textgaps 0 tstr ashow
        } ifelse
    } if

    % Display the guard elements
    guardwhitespace {
        0.75 setlinewidth
        guardleftpos 0 ne {
            newpath
            guardleftpos neg guardwidth add guardleftypos guardwidth 2 div add moveto
            guardwidth neg guardheight -2 div rlineto
            guardwidth guardheight -2 div rlineto
            stroke
        } if
        guardrightpos 0 ne {
            newpath
            guardrightpos pixx add guardwidth sub guardrightypos guardheight 2 div add moveto
            guardwidth guardheight -2 div rlineto
            guardwidth neg guardheight -2 div rlineto
            stroke
        } if
    } if

    grestore

    end

}
[/barcode] {null def} forall
bind def
/renlinear dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RENDERER renlinear--

% --BEGIN RENDERER renmatrix--
% --REQUIRES preamble raiseerror--
%%BeginResource: uk.co.terryburton.bwipp renmatrix 0.0 2022082100 89491 88705
%%BeginData:        306 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 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
    /colormap (unset) def
    /dotty false def
    /inkspread 0 def
    /inkspreadh 0 def
    /inkspreadv 0 def
    /includetext false def
    /txt [] def
    /textcolor (unset) def
    /textxalign (unset) def
    /textyalign (unset) def
    /textfont (Courier) def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset 0 def
    /textgaps 0 def
    /alttext () 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
    /inkspread inkspread cvr def
    /inkspreadh inkspreadh cvr def
    /inkspreadv inkspreadv cvr def
    /textcolor textcolor cvlit def
    /textxalign textxalign cvlit def
    /textyalign textyalign cvlit def
    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /textgaps textgaps cvr def
    /alttext alttext cvlit def

    inkspread 0 ne {/inkspreadh inkspread def} if
    inkspread 0 ne {/inkspreadv inkspread def} if

    /xyget { pixx mul add pixs exch get} def
    /cget { pixx mul add cache exch get and} def
    /cput {  % Optimise by only storing "stem" corners
        dup 4 mod 0 eq { % dir is up or left
            3 1 roll pixx mul add cache exch 2 copy get 4 -1 roll or put
        } {
            pop pop pop
        } ifelse
    } def

    /abcd {
        4 string 0 [
            5 -2 roll
            pixx mul add dup
            pixs exch 2 getinterval aload pop 3 -1 roll  % A B
            pixs exch pixx add 2 getinterval aload pop   % C D
        ] {3 copy 48 add put pop 1 add} forall pop
    } def

    /right {dir 1 ne {x y dir cput [x y]} if  /x x 1 add def  /dir 1 def} def
    /down  {dir 2 ne {x y dir cput [x y]} if  /y y 1 add def  /dir 2 def} def
    /left  {dir 4 ne {x y dir cput [x y]} if  /x x 1 sub def  /dir 4 def} def
    /up    {dir 8 ne {x y dir cput [x y]} if  /y y 1 sub def  /dir 8 def} def

    /trace {
        % Walk the outline of a region emitting edge coordinates of the path
        /y exch def  /x exch def
        % dir 1:right 2:down 4:left 8:up
        /dir x 1 add y 1 add xyget 1 eq {8} {4} ifelse def
        /sx x def  /sy y def  /sdir dir def

        % A B
        % C D
        mark {
            x y abcd
            1 {  % Common exit
                dup dup (0001) eq exch dup (0011) eq exch (1011) eq or or {pop right exit} if
                dup dup (0010) eq exch dup (1010) eq exch (1110) eq or or {pop down  exit} if
                dup dup (1000) eq exch dup (1100) eq exch (1101) eq or or {pop left  exit} if
                dup dup (0100) eq exch dup (0101) eq exch (0111) eq or or {pop up    exit} if
                dup (1001) eq {
                    dir 2 eq {pop left exit} {pop right exit} ifelse
                } {  % 0110
                    dir 1 eq {pop down exit} {pop up exit} ifelse
                } ifelse
            } repeat
            x sx eq y sy eq and dir sdir eq and {exit} if
        } loop
        counttomark array astore exch pop

    } 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
    } def

    % Plot a layer of single colour
    /drawlayer {

        /pixsorig pixs def
        /pixs exch def

        % Pad the bitmap on all sides
        /pixs [
            pixx 2 add {0} repeat
            0 pixx pixs length 1 sub {
                0 exch
                pixs exch pixx getinterval aload pop
                0
            } for
            pixx 2 add {0} repeat
        ] def
        /pixx pixx 2 add def
        /pixy pixy 2 add def

        % Cache of visited corners for each direction
        /cache [ pixs length {0} repeat ] def

        % Construct paths by tracing regions avoiding duplication by using the cache
        /paths [
            0 1 pixy 2 sub {
                /j exch def
                0 1 pixx 2 sub {
                    /i exch def
                    /k i j abcd def
                    k (0001) eq k (1001) eq or {  % Black region stem corners
                        8 i j cget 0 eq {
                            i j trace
                        } if
                    } if
                    k (1110) eq {  % White region stem corner
                        4 i j cget 0 eq {
                            i j trace
                        } if
                    } if
                } for
            } for
        ] def

        % Revert the bitmap size
        /pixx pixx 2 sub def
        /pixy pixy 2 sub def

        % Draw the image
        newpath
        paths {
            /p exch def
            /len p length def
            p len 1 sub get aload pop
            p 0 get aload pop
            0 1 len 1 sub {                                % x1 y1 x2 y2
                /i exch def
                p i 1 add len mod get aload pop 6 -2 roll  % x3 y3 x1 y1 x2 y2
                5 index inkspreadh
                4 index 4 -1 roll lt {add} {sub} ifelse    % y3<y1 ? x2+i : x2-i
                4 1 roll
                4 index inkspreadv
                4 index 4 -1 roll gt {add} {sub} ifelse    % x3>x1 ? y2+i : y2-i
                4 -1 roll exch pixy exch sub
                i 0 eq {moveto} {lineto} ifelse
            } for                                          % x2 y2 x3 y3
            closepath
            pop pop pop pop
        } forall
        fill

        /pixs pixsorig def

    } def

    /drawlayerdots {

        /pixsorig pixs def
        /pixs exch def

        newpath
        0 1 pixs length 1 sub {
            dup pixx mod /x exch def
            pixx idiv /y exch def
            x y xyget 1 eq {
               x 0.5 add pixy y sub 0.5 sub moveto
               x 0.5 add pixy y sub 0.5 sub 0.5 inkspread sub 0 360 arc
            } if
        } for
        fill

        /pixs pixsorig def

    } def

    gsave

    % Draw the image
    /inkspread  inkspread  2 div def
    /inkspreadh inkspreadh 2 div def
    /inkspreadv inkspreadv 2 div def
    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

    colormap (unset) eq {
        /colormap << 1 barcolor >> def
    } if

    colormap {
        setanycolor
        /key exch def
        [
            pixs { key eq {1} {0} ifelse } forall
        ] dotty {drawlayerdots} {drawlayer} ifelse
    } forall

    % Display the text for elements in the text array
    textcolor (unset) ne { textcolor setanycolor } if
    includetext {
        textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
            /s 0 def /fn () def
            txt {
                {} forall
                2 copy s ne exch fn ne or {
                    2 copy /s exch def /fn exch def
                    selectfont
                } {
                    pop pop
                } ifelse
                moveto show
            } forall
        } {
            textfont textsize selectfont
            alttext () eq {
                /txt [ txt { 0 get {} forall } forall ] def
                /tstr txt length string def
                0 1 txt length 1 sub { dup txt exch get tstr 3 1 roll put } for
            } {
                /tstr alttext def
            } ifelse

            % Find true ascent of font
            tstr length 0 eq {
                0
            } {
                gsave
                newpath 0 0 moveto (0) false charpath pathbbox
                4 1 roll pop pop pop
                grestore
                currentfont /PaintType known {currentfont /PaintType get 2 eq} {false} ifelse
                currentfont /StrokeWidth known and {
                    currentfont /StrokeWidth get 2 div 0 exch
                    currentfont /FontMatrix get dtransform
                    dup mul exch dup mul add sqrt
                    add
                } if
            } ifelse
            /textascent exch def
            /textwidth tstr stringwidth pop tstr length 1 sub textgaps mul add def

            /textxpos textxoffset pixx textwidth sub 2 div add def
            textxalign (left) eq { /textxpos textxoffset def } if
            textxalign (right) eq { /textxpos pixx textxoffset sub textwidth sub def } if
            textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
            textxalign (offright) eq { /textxpos pixx textxoffset add def } if
            textxalign (justify) eq textwidth pixx lt and {
                /textxpos 0 def
                /textgaps pixx textwidth sub tstr length 1 sub div def
            } if
            /textypos textyoffset textascent add 1 add neg def
            textyalign (above) eq { /textypos textyoffset pixy add 1 add def } if
            textyalign (center) eq { /textypos textyoffset pixy textascent sub 2 div add def } if
            textxpos textypos moveto textgaps 0 tstr ashow
        } ifelse
    } if

    grestore

    end

}
[/barcode] {null def} forall
bind def
/renmatrix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RENDERER renmatrix--

% --BEGIN RENDERER renmaximatrix--
% --REQUIRES preamble raiseerror--
%%BeginResource: uk.co.terryburton.bwipp renmaximatrix 0.0 2022082100 50058 49824
%%BeginData:         81 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
begin
/renmaximatrix {

    20 dict begin

    /args exch def   % We are given some arguments

    % Default options
    /barcolor (unset) def
    /backgroundcolor (unset) def

    % Apply the renderer options and the user options
    args {def} forall
    opt {def} forall

    /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
    } def

    gsave

    currentpoint translate

    2.4945 dup scale  % from 1pt to 0.88mm

    0 0 moveto 30 0 lineto 30 29 lineto 0 29 lineto closepath
    backgroundcolor (unset) ne { gsave backgroundcolor setanycolor fill grestore } if
    barcolor (unset) ne { barcolor setanycolor } if

    0.5 0.5774 translate

    newpath
    pixs {
        dup
        /x exch 30 mod def
        /y exch 30 idiv def
        y 2 mod 0 eq {x} {x 0.5 add} ifelse
        32 y sub 0.8661 mul
        moveto
        0     0.5774 rmoveto
        -0.5 -0.2887 rlineto
        0    -0.5774 rlineto
        0.5  -0.2887 rlineto
        0.5   0.2887 rlineto
        0     0.5774 rlineto
        -0.5  0.2887 rlineto
        closepath
    } forall
    fill

    % Plot the locator symbol
    newpath 14 13.8576 0.5774 0 360 arc closepath
    14 13.8576 1.3359 360 0 arcn closepath fill
    newpath 14 13.8576 2.1058 0 360 arc closepath
    14 13.8576 2.8644 360 0 arcn closepath fill
    newpath 14 13.8576 3.6229 0 360 arc closepath
    14 13.8576 4.3814 360 0 arcn closepath fill

    grestore

    end

}
[/barcode] {null def} forall
bind def
/renmaximatrix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END RENDERER renmaximatrix--

% --BEGIN ENCODER ean5--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: EAN-5 (5 digit addon)
% --EXAM: 90200
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean5 0.0 2022082100 67660 63946
%%BeginData:        147 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/ean5 {

    20 dict begin

    /options exch def                   % We are given an option string
    /barcode exch def                   % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def              % Enable/disable text
    /textfont /Helvetica def
    /textsize 12 def
    /textxoffset 0 def
    /textyoffset (unset) def
    /height 0.7 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /height height cvr def
    /textxoffset textxoffset cvr def
    textyoffset (unset) eq {
        /textyoffset height 72 mul 1 add def
    } {
        /textyoffset textyoffset cvr def
    } ifelse

    /ean5 //loadctx exec

    % Validate input
    barcode length 5 ne {
        /bwipp.ean5badLength (EAN-5 add-on must be 5 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.ean5badCharacter (EAN-5 add-on must contain only digits) //raiseerror exec
        } if
    } forall

{
    % Create an array containing the character mappings
    /encs
    [ (3211) (2221) (2122) (1411) (1132)
      (1231) (1114) (1312) (1213) (3112)
      (112) (11)
    ] def

    % Create a string of the available characters
    /barchars (0123456789) def

    % Determine the mirror map based on mod 10 checksum
    /mirrormaps
    [ (11000) (10100) (10010) (10001) (01100)
      (00110) (00011) (01010) (01001) (00101)
    ] def
} ctxdef

    /checksum 0 def
    0 1 4 {
        /i exch def
        /barchar barcode i get 48 sub def
        i 2 mod 0 eq {
            /checksum barchar 3 mul checksum add def
        } {
            /checksum barchar 9 mul checksum add def
        } ifelse
    } for
    /checksum checksum 10 mod def
    /mirrormap mirrormaps checksum get def

    /sbs 31 string def
    /txt 5 array def

    0 1 4 {
        /i exch def

        % Prefix with either a start character or separator character
        i 0 eq {
            sbs 0 encs 10 get putinterval
        } {
            sbs i 1 sub 6 mul 7 add encs 11 get putinterval
        } ifelse

        % Lookup the encoding for the barcode character
        barcode i 1 getinterval barchars exch search
        pop                     % Discard true leaving pre
        length /indx exch def   % indx is the length of pre
        pop pop                 % Discard seek and post
        /enc encs indx get def  % Get the indxth encoding
        mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
            /enclen enc length def
            /revenc enclen string def
            0 1 enclen 1 sub {
                /j exch def
                /char enc j get def
                revenc enclen j sub 1 sub char put
            } for
            /enc revenc def
        } if
        sbs i 6 mul 3 add enc putinterval   % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textxoffset add textyoffset textfont textsize] put
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [16{height}repeat]
    /bbs [16{0}repeat]
    includetext {
        /txt txt
    } if
    /opt options
    /guardrightpos 10
    /guardrightypos textyoffset 4 add
    /bordertop 10
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/ean5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER ean5--

% --BEGIN ENCODER ean2--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: EAN-2 (2 digit addon)
% --EXAM: 05
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean2 0.0 2022082100 66307 62648
%%BeginData:        133 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/ean2 {

    20 dict begin

    /options exch def                   % We are given an options string
    /barcode exch def                   % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def               % Enable/disable text
    /textfont /Helvetica def
    /textsize 12 def
    /textxoffset 0 def
    /textyoffset (unset) def
    /height 0.7 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /height height cvr def
    /textxoffset textxoffset cvr def
    textyoffset (unset) eq {
        /textyoffset height 72 mul 1 add def
    } {
        /textyoffset textyoffset cvr def
    } ifelse

    /ean2 //loadctx exec

    % Validate input
    barcode length 2 ne {
      /bwipp.ean2badLength (EAN-2 add-on must be 2 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.ean2badCharacter (EAN-2 add-on must contain only digits) //raiseerror exec
        } if
    } forall

{
    % Create an array containing the character mappings
    /encs
    [ (3211) (2221) (2122) (1411) (1132)
      (1231) (1114) (1312) (1213) (3112)
      (112) (11)
    ] def

    % Create a string of the available characters
    /barchars (0123456789) def

    % Determine the mirror map based on mod 4 checksum
    /mirrormaps [(00) (01) (10) (11)] def
} ctxdef

    /mirrormap mirrormaps barcode 0 2 getinterval cvi 4 mod get def

    /sbs 13 string def
    /txt 2 array def

    0 1 1 {
        /i exch def

        % Prefix with either a start character or separator character
        i 0 eq {
            sbs 0 encs 10 get putinterval
        } {
            sbs i 1 sub 6 mul 7 add encs 11 get putinterval
        } ifelse

        % Lookup the encoding for the barcode character
        barcode i 1 getinterval barchars exch search
        pop                     % Discard true leaving pre
        length /indx exch def   % indx is the length of pre
        pop pop                 % Discard seek and post
        /enc encs indx get def  % Get the indxth encoding
        mirrormap i get 49 eq { % Reverse enc if 1 in this position in mirrormap
            /enclen enc length def
            /revenc enclen string def
            0 1 enclen 1 sub {
                /j exch def
                /char enc j get def
                revenc enclen j sub 1 sub char put
            } for
            /enc revenc def
        } if
        sbs i 6 mul 3 add enc putinterval   % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i 1 sub 9 mul 13 add textxoffset add textyoffset textfont textsize] put
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [12{height}repeat]
    /bbs [12{0}repeat]
    includetext {
        /txt txt
    } if
    /opt options
    /guardrightpos 10
    /guardrightypos textyoffset 4 add
    /bordertop 10
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/ean2 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER ean2--

% --BEGIN ENCODER ean13--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear ean5 ean2--
% --DESC: EAN-13
% --EXAM: 2112345678900
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean13 0.0 2022082100 87150 86773
%%BeginData:        226 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /ean2 dup /uk.co.terryburton.bwipp findresource put
dup /ean5 dup /uk.co.terryburton.bwipp findresource put
begin
/ean13 {

    20 dict begin

    /options exch def                  % We are given an option string
    /barcode exch def                  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def             % Enable/disable text
    /textfont /Helvetica def
    /textsize 12 def
    /textxoffset -10 def
    /textyoffset -4 def
    /height 1 def
    /addongap 12 def
    /addontextfont (unset) def
    /addontextsize (unset) def
    /addontextxoffset (unset) def
    /addontextyoffset (unset) def

    % Parse the input options, either a string or a dict
    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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def
    /addongap addongap cvr def
    addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if
    addontextsize (unset) ne {/addontextsize addontextsize cvr def} if
    addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if
    addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if

    /ean13 //loadctx exec

    % Split off the addon
    barcode ( ) search {
        /barcode exch def
        pop
        /addon exch def
    } {
        pop
        /addon () def
    } ifelse

    % Validate the input
    barcode length 12 ne barcode length 13 ne and {
        /bwipp.ean13badLength (EAN-13 must be 12 or 13 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.ean13badCharacter (EAN-13 must contain only digits) //raiseerror exec
        } if
    } forall
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
        /bwipp.ean13badAddOnLength (Add-on for EAN-13 must be 2 or 5 digits) //raiseerror exec
    } if

    % Add checksum digit
    /pad 13 string def
    /checksum 0 def
    0 1 11 {
        /i exch def
        /barchar barcode i get 48 sub def
        i 2 mod 0 eq {
            /checksum barchar checksum add def
        } {
            /checksum barchar 3 mul checksum add def
        } ifelse
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 13 eq {
        barcode 12 get checksum 48 add ne {
            /bwipp.ean13badCheckDigit (Incorrect EAN-13 check digit provided) //raiseerror exec
        } if
    } if
    pad 0 barcode putinterval       % Add barcode to the start of the pad
    pad 12 checksum 48 add put      % Put ascii for checksum at end of pad
    /barcode pad def

{
    % Create an array containing the character mappings
    /encs
    [ (3211) (2221) (2122) (1411) (1132)
      (1231) (1114) (1312) (1213) (3112)
      (111) (11111) (111)
    ] def

    % Create a string of the available characters
    /barchars (0123456789) def

    % Digits to mirror on left side
    /mirrormaps
    [ (000000) (001011) (001101) (001110) (010011)
      (011001) (011100) (010101) (010110) (011010)
    ] def
} ctxdef

    /sbs 59 string def
    /txt 13 array def

    % Put the start character
    sbs 0 encs 10 get putinterval

    % First digit - determine mirrormap by this and show before guard bars
    /mirrormap mirrormaps barcode 0 get 48 sub get def
    txt 0 [barcode 0 1 getinterval textxoffset textyoffset textfont textsize] put

    % Left side - performs mirroring
    1 1 6 {
        % Lookup the encoding for the each barcode character
        /i exch def
        barcode i 1 getinterval barchars exch search
        pop                            % Discard true leaving pre
        length /indx exch def          % indx is the length of pre
        pop pop                        % Discard seek and post
        /enc encs indx get def         % Get the indxth encoding
        mirrormap i 1 sub get 49 eq {   % Reverse enc if 1 in this position in mirrormap
            /enclen enc length def
            /revenc enclen string def
            0 1 enclen 1 sub {
                /j exch def
                /char enc j get def
                revenc enclen j sub 1 sub char put
            } for
            /enc revenc def
        } if
        sbs i 1 sub 4 mul 3 add enc putinterval   % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i 1 sub 7 mul 14 add textxoffset add textyoffset textfont textsize] put
    } for

    % Put the middle character
    sbs 7 1 sub 4 mul 3 add encs 11 get putinterval

    % Right side
    7 1 12 {
        % Lookup the encoding for the each barcode character
        /i exch def
        barcode i 1 getinterval barchars exch search
        pop                            % Discard true leaving pre
        length /indx exch def          % indx is the length of pre
        pop pop                        % Discard seek and post
        /enc encs indx get def         % Get the indxth encoding
        sbs i 1 sub 4 mul 8 add enc putinterval  % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i 1 sub 7 mul 18 add textxoffset add textyoffset textfont textsize] put
    } for

    % Put the end character
    sbs 56 encs 12 get putinterval

    /sbs [sbs {48 sub} forall] def
    includetext {
        /bhs [height height 12{height .075 sub}repeat height height 12{height .075 sub}repeat height height] def
        /bbs [0 0 12{.075}repeat 0 0 12{.075}repeat 0 0] def
    } {
        /bhs [30{height}repeat] def
        /bbs [30{0}repeat] def
        /txt [] def
    } ifelse
    /guardrightypos 0 def

    % Append the addon
    addon () ne {
        /addopts <<
            /dontdraw true
            /includetext true
            /height height 0.15 sub
            /textxoffset addontextxoffset (unset) ne {addontextxoffset} {95 addongap add} ifelse
            addontextyoffset (unset) ne {/textyoffset addontextyoffset} if
            /textsize addontextsize (unset) ne {addontextsize} {textsize} ifelse
            /textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse
        >> def
        addon length 2 eq {addon addopts //ean2 exec} if
        addon length 5 eq {addon addopts //ean5 exec} if
        /addcode exch def
        /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
        /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
        /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
        /txt [txt aload pop addcode (txt) get aload pop] def
        /guardrightypos height 72 mul 6 sub def
    } if

    % Return the arguments
    <<
    /ren //renlinear
    /sbs sbs
    /bhs bhs
    /bbs bbs
    /txt txt
    /opt options
    /guardrightpos 10
    /guardrightypos guardrightypos
    /borderbottom 5
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/ean13 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER ean13--

% --BEGIN ENCODER ean8--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear ean5 ean2--
% --DESC: EAN-8
% --EXAM: 02345673
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean8 0.0 2022082100 84180 83888
%%BeginData:        207 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /ean2 dup /uk.co.terryburton.bwipp findresource put
dup /ean5 dup /uk.co.terryburton.bwipp findresource put
begin
/ean8 {

    20 dict begin

    /options exch def                  % We are given an option string
    /barcode exch def                  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def              % Enable/disable text
    /textfont /Helvetica def
    /textsize 12 def
    /textxoffset 4 def
    /textyoffset -4 def
    /height 1 def
    /addongap 12 def
    /addontextfont (unset) def
    /addontextsize (unset) def
    /addontextxoffset (unset) def
    /addontextyoffset (unset) def

    % Parse the input options, either a string or a dict
    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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def
    /addongap addongap cvr def
    addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if
    addontextsize (unset) ne {/addontextsize addontextsize cvr def} if
    addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if
    addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if

    /ean8 //loadctx exec

    % Split off the addon
    barcode ( ) search {
        /barcode exch def
        pop
        /addon exch def
    } {
        pop
        /addon () def
    } ifelse

    % Validate the input
    barcode length 7 ne barcode length 8 ne and {
        /bwipp.ean8badLength (EAN-8 must be 7 or 8 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.ean8badCharacter (EAN-8 must contain only digits) //raiseerror exec
        } if
    } forall
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
        /bwipp.ean8badAddOnLength (Add-on for EAN-8 must be 2 or 5 digits) //raiseerror exec
    } if

    % Add checksum digit
    /pad 8 string def
    /checksum 0 def
    0 1 6 {
        /i exch def
        /barchar barcode i get 48 sub def
        i 2 mod 0 ne {
            /checksum barchar checksum add def
        } {
            /checksum barchar 3 mul checksum add def
        } ifelse
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 8 eq {
        barcode 7 get checksum 48 add ne {
            /bwipp.ean8badCheckDigit (Incorrect EAN-8 check digit provided) //raiseerror exec
        } if
    } if
    pad 0 barcode putinterval      % Add barcode to the start of the pad
    pad 7 checksum 48 add put      % Put ascii for checksum at end of pad
    /barcode pad def

    % Create an array containing the character mappings
{
    /encs
    [ (3211) (2221) (2122) (1411) (1132)
      (1231) (1114) (1312) (1213) (3112)
      (111) (11111) (111)
    ] def

    % Create a string of the available characters
    /barchars (0123456789) def
} ctxdef

    /sbs 43 string def
    /txt 8 array def

    % Put the start character
    sbs 0 encs 10 get putinterval

    % Left side
    0 1 3 {
        % Lookup the encoding for the each barcode character
        /i exch def
        barcode i 1 getinterval barchars exch search
        pop                                % Discard true leaving pre
        length /indx exch def              % indx is the length of pre
        pop pop                            % Discard seek and post
        /enc encs indx get def             % Get the indxth encoding
        sbs i 4 mul 3 add enc putinterval  % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i 7 mul textxoffset add textyoffset textfont textsize] put
    } for

    % Put the middle character
    sbs 4 4 mul 3 add encs 11 get putinterval

    % Right side
    4 1 7 {
        % Lookup the encoding for the each barcode character
        /i exch def
        barcode i 1 getinterval barchars exch search
        pop                                % Discard true leaving pre
        length /indx exch def              % indx is the length of pre
        pop pop                            % Discard seek and post
        /enc encs indx get def             % Get the indxth encoding
        sbs i 4 mul 8 add enc putinterval  % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i 7 mul textxoffset add 4 add textyoffset textfont textsize] put
    } for

    % Put the end character
    sbs 40 encs 12 get putinterval

    /sbs [sbs {48 sub} forall] def
    includetext {
        /bhs [height height 8{height .075 sub}repeat height height 8{height .075 sub}repeat height height] def
        /bbs [0 0 8{.075}repeat 0 0 8{.075}repeat 0 0] def
    } {
        /bhs [22{height}repeat] def
        /bbs [22{0}repeat] def
        /txt [] def
    } ifelse
    /guardrightypos 0 def

    % Append the addon
    addon () ne {
        /addopts <<
            /dontdraw true
            /includetext true
            /height height 0.15 sub
            /textxoffset addontextxoffset (unset) ne {addontextxoffset} {67 addongap add} ifelse
            addontextyoffset (unset) ne {/textyoffset addontextyoffset} if
            /textsize addontextsize (unset) ne {addontextsize} {textsize} ifelse
            /textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse
        >> def
        addon length 2 eq {addon addopts //ean2 exec} if
        addon length 5 eq {addon addopts //ean5 exec} if
        /addcode exch def
        /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
        /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
        /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
        /txt [txt aload pop addcode (txt) get aload pop] def
        /guardrightypos height 72 mul 6 sub def
    } if

    % Return the arguments
    <<
    /ren //renlinear
    /sbs sbs
    /bhs bhs
    /bbs bbs
    /txt txt
    /opt options
    /guardleftpos 10
    /guardrightpos 10
    /guardrightypos guardrightypos
    /borderbottom 5
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/ean8 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER ean8--

% --BEGIN ENCODER upca--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear ean5 ean2--
% --DESC: UPC-A
% --EXAM: 416000336108
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp upca 0.0 2022082100 92023 91540
%%BeginData:        259 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /ean2 dup /uk.co.terryburton.bwipp findresource put
dup /ean5 dup /uk.co.terryburton.bwipp findresource put
begin
/upca {

    20 dict begin

    /options exch def
    /barcode exch def             % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def         % Enable/disable text
    /textfont /Helvetica def
    /textsize 12 def
    /textxoffset -7 def
    /textyoffset -4 def
    /height 1 def
    /addongap 12 def
    /addontextfont (unset) def
    /addontextsize (unset) def
    /addontextxoffset (unset) def
    /addontextyoffset (unset) 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def
    /addongap addongap cvr def
    addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if
    addontextsize (unset) ne {/addontextsize addontextsize cvr def} if
    addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if
    addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if

    /upca //loadctx exec

    % Split off the addon
    barcode ( ) search {
        /barcode exch def
        pop
        /addon exch def
    } {
        pop
        /addon () def
    } ifelse

    % Expand a given UPC-E
    barcode length 7 eq barcode length 8 eq or {
        % Validate the input
        barcode {
            dup 48 lt exch 57 gt or {
                /bwipp.upcAupcEbadCharacter (UPC-E must contain only digits) //raiseerror exec
            } if
        } forall
        barcode 0 get dup 48 ne exch 49 ne and {
            /bwipp.upcAupcEbadNumberSystem (UPC-E must have number system 0 or 1) //raiseerror exec
        } if
        1 {  % Common exit
            /upcacode barcode length 8 eq {12} {11} ifelse string def
            barcode 6 get 48 sub 2 le {
                upcacode 0 barcode 0 3 getinterval putinterval
                upcacode 3 barcode 6 1 getinterval putinterval
                upcacode 4 (0000) putinterval
                upcacode 8 barcode 3 3 getinterval putinterval
                exit
            } if
            barcode 6 get 48 sub 3 eq {
                upcacode 0 barcode 0 4 getinterval putinterval
                upcacode 4 (00000) putinterval
                upcacode 9 barcode 4 2 getinterval putinterval
                exit
            } if
            barcode 6 get 48 sub 4 eq {
                upcacode 0 barcode 0 5 getinterval putinterval
                upcacode 5 (00000) putinterval
                upcacode 10 barcode 5 1 getinterval putinterval
                exit
            } if
            barcode 6 get 48 sub 5 ge {
                upcacode 0 barcode 0 6 getinterval putinterval
                upcacode 6 (0000) putinterval
                upcacode 10 barcode 6 1 getinterval putinterval
                exit
            } if
        } repeat
        barcode length 8 eq {
            upcacode 11 barcode 7 1 getinterval putinterval
        } if
        /barcode upcacode def
    } if

    % Validate the input
    barcode length 11 ne barcode length 12 ne and {
        /bwipp.upcAbadLength (UPC-A must be 11 or 12 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.upcAbadCharacter (UPC-A must contain only digits) //raiseerror exec
        } if
    } forall
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
        /bwipp.upcAbadAddOnLength (Add-on for UPC-A must be 2 or 5 digits) //raiseerror exec
    } if

    % Add checksum digit to barcode
    /pad 12 string def   % Create pad one bigger than barcode
    /checksum 0 def
    0 1 10 {
        /i exch def
        /barchar barcode i get 48 sub def
        i 2 mod 0 ne {
            /checksum checksum barchar add def
        } {
            /checksum checksum barchar 3 mul add def
        } ifelse
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 12 eq {
        barcode 11 get checksum 48 add ne {
            /bwipp.upcAbadCheckDigit (Incorrect UPC check digit provided) //raiseerror exec
        } if
    } if
    pad 0 barcode putinterval       % Add barcode to the start of the pad
    pad 11 checksum 48 add put      % Put ascii for checksum at end of pad
    /barcode pad def

    % Create an array containing the character mappings
{
    /encs
    [ (3211) (2221) (2122) (1411) (1132)
      (1231) (1114) (1312) (1213) (3112)
      (111) (11111) (111)
    ] def

    % Create a string of the available characters
    /barchars (0123456789) def
} ctxdef

    /sbs 59 string def
    /txt 12 array def

    % Put the start character
    sbs 0 encs 10 get putinterval

    % Left side
    0 1 5 {
        % Lookup the encoding for the each barcode character
        /i exch def
        barcode i 1 getinterval barchars exch search
        pop                                % Discard true leaving pre
        length /indx exch def              % indx is the length of pre
        pop pop                            % Discard seek and post
        /enc encs indx get def             % Get the indxth encoding
        sbs i 4 mul 3 add enc putinterval  % Put encoded digit into sbs
        i 0 eq {      % First digit is before the guard bars
            txt 0 [barcode 0 1 getinterval textxoffset textyoffset textfont textsize 2 sub] put
        } {
            txt i [barcode i 1 getinterval i 7 mul 11 add textxoffset add textyoffset textfont textsize] put
        } ifelse
    } for

    % Put the middle character
    sbs 6 4 mul 3 add encs 11 get putinterval

    % Right side
    6 1 11 {
        % Lookup the encoding for the each barcode character
        /i exch def
        barcode i 1 getinterval barchars exch search
        pop                                % Discard true leaving pre
        length /indx exch def              % indx is the length of pre
        pop pop                            % Discard seek and post
        /enc encs indx get def             % Get the indxth encoding
        sbs i 4 mul 8 add enc putinterval  % Put encoded digit into sbs
        i 11 eq {       % Last digit is after guard bars
            txt 11 [barcode 11 1 getinterval textxoffset 103 add textyoffset textfont textsize 2 sub] put
        } {
            txt i [barcode i 1 getinterval i 7 mul textxoffset add 15 add textyoffset textfont textsize] put
        } ifelse
    } for

    % Put the end character
    sbs 56 encs 12 get putinterval

    /sbs [sbs {48 sub} forall] def
    includetext {
        /bhs [4{height}repeat 10{height .075 sub}repeat height height 10{height .075 sub}repeat 4{height}repeat] def
        /bbs [0 0 0 0 10{.075}repeat 0 0 10{.075}repeat 0 0 0 0] def
    } {
        /bhs [30{height}repeat] def
        /bbs [30{0}repeat] def
        /txt [] def
    } ifelse
    /guardrightypos 0 def

    % Append the addon
    addon () ne {
        /addopts <<
            /dontdraw true
            /includetext true
            /height height 0.15 sub
            /textxoffset addontextxoffset (unset) ne {addontextxoffset} {95 addongap add} ifelse
            addontextyoffset (unset) ne {/textyoffset addontextyoffset} if
            /textsize addontextsize (unset) ne {addontextsize} {textsize} ifelse
            /textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse
        >> def
        addon length 2 eq {addon addopts //ean2 exec} if
        addon length 5 eq {addon addopts //ean5 exec} if
        /addcode exch def
        /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
        /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
        /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
        /txt [txt aload pop addcode (txt) get aload pop] def
        /guardrightypos height 72 mul 6 sub def
    } if

    % Return the arguments
    <<
    /ren //renlinear
    /sbs sbs
    /bhs bhs
    /bbs bbs
    /txt txt
    /opt options
    /guardrightpos 10
    /guardrightypos guardrightypos
    /borderbottom 5
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/upca dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER upca--

% --BEGIN ENCODER upce--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear ean5 ean2--
% --DESC: UPC-E
% --EXAM: 00123457
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp upce 0.0 2022082100 96548 96108
%%BeginData:        298 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /ean2 dup /uk.co.terryburton.bwipp findresource put
dup /ean5 dup /uk.co.terryburton.bwipp findresource put
begin
/upce {

    20 dict begin

    /options exch def                   % We are given an option string
    /barcode exch def                   % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def               % Enable/disable text
    /textfont /Helvetica def
    /textsize 12 def
    /textxoffset -7 def
    /textyoffset -4 def
    /height 1 def
    /addongap 12 def
    /addontextfont (unset) def
    /addontextsize (unset) def
    /addontextxoffset (unset) def
    /addontextyoffset (unset) 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def
    /addongap addongap cvr def
    addontextfont (unset) ne {/addontextfont addontextfont cvlit def} if
    addontextsize (unset) ne {/addontextsize addontextsize cvr def} if
    addontextxoffset (unset) ne {/addontextxoffset addontextxoffset cvr def} if
    addontextyoffset (unset) ne {/addontextyoffset addontextyoffset cvr def} if

    /upce //loadctx exec

    % Split off the addon
    barcode ( ) search {
        /barcode exch def
        pop
        /addon exch def
    } {
        pop
        /addon () def
    } ifelse

    % Compress a given UPC-A
    barcode length 11 eq barcode length 12 eq or {
        % Validate the input
        barcode {
            dup 48 lt exch 57 gt or {
                /bwipp.upcEupcAbadCharacter (UPC-A must contain only digits) //raiseerror exec
            } if
        } forall
        1 {  % Common exit
            /upcecode barcode length 12 eq {8} {7} ifelse string def
            barcode 3 get 48 sub 2 le barcode 4 4 getinterval (0000) eq and {
                upcecode 0 barcode  0 3 getinterval putinterval
                upcecode 3 barcode  8 3 getinterval putinterval
                upcecode 6 barcode  3 1 getinterval putinterval
                exit
            } if
            barcode 4 5 getinterval (00000) eq {
                upcecode 0 barcode  0 4 getinterval putinterval
                upcecode 4 barcode  9 2 getinterval putinterval
                upcecode 6 (3) putinterval
                exit
            } if
            barcode 5 5 getinterval (00000) eq {
                upcecode 0 barcode  0 5 getinterval putinterval
                upcecode 5 barcode 10 1 getinterval putinterval
                upcecode 6 (4) putinterval
                exit
            } if
            barcode 10 get 48 sub 5 ge barcode 6 4 getinterval (0000) eq and {
                upcecode 0 barcode  0 6 getinterval putinterval
                upcecode 6 barcode 10 1 getinterval putinterval
                exit
            } if
            /bwipp.upcEupcAnotCompressible (UPC-A cannot be converted to a UPC-E) //raiseerror exec
        } repeat
        barcode length 12 eq {
            upcecode 7 barcode 11 1 getinterval putinterval
        } if
        /barcode upcecode def
    } if

    % Validate the input
    barcode length 7 ne barcode length 8 ne and {
        /bwipp.upcEbadLength (UPC-E must be 7 or 8 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.upcEbadCharacter (UPC-E must contain only digits) //raiseerror exec
        } if
    } forall
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
        /bwipp.upcEbadAddOnLength (Add-on for UPC-E must be 2 or 5 digits) //raiseerror exec
    } if

    % Ensure 0 or 1 number systems
    barcode 0 get dup 48 ne exch 49 ne and {
        /bwipp.upcEbadNumberSystem (UPC-E must have number system 0 or 1) //raiseerror exec
    } if

{
    % Create an array containing the character mappings
    /encs
    [ (3211) (2221) (2122) (1411) (1132)
      (1231) (1114) (1312) (1213) (3112)
      (111) (111111)
    ] def

    % Create a string of the available characters
    /barchars (0123456789) def

    /mirrormaps
    [ (000111) (001011) (001101) (001110) (010011)
      (011001) (011100) (010101) (010110) (011010)
    ] def
} ctxdef

    % Derive the equivalent UPC-A for its checksum
    1 {  % Common exit
        /upcacode 11 string def
        barcode 6 get 48 sub 2 le {
            upcacode 0 barcode 0 3 getinterval putinterval
            upcacode 3 barcode 6 1 getinterval putinterval
            upcacode 4 (0000) putinterval
            upcacode 8 barcode 3 3 getinterval putinterval
            exit
        } if
        barcode 6 get 48 sub 3 eq {
            upcacode 0 barcode 0 4 getinterval putinterval
            upcacode 4 (00000) putinterval
            upcacode 9 barcode 4 2 getinterval putinterval
            exit
        } if
        barcode 6 get 48 sub 4 eq {
            upcacode 0 barcode 0 5 getinterval putinterval
            upcacode 5 (00000) putinterval
            upcacode 10 barcode 5 1 getinterval putinterval
            exit
        } if
        barcode 6 get 48 sub 5 ge {
            upcacode 0 barcode 0 6 getinterval putinterval
            upcacode 6 (0000) putinterval
            upcacode 10 barcode 6 1 getinterval putinterval
            exit
        } if
    } repeat
    /checksum 0 def
    0 1 10 {
       /i exch def
       /barchar upcacode i get 48 sub def
       i 2 mod 0 ne {
           /checksum checksum barchar add def
       } {
           /checksum checksum barchar 3 mul add def
       } ifelse
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 8 eq {
        barcode 7 get checksum 48 add ne {
            /bwipp.upcEbadCheckDigit (Incorrect UPC check digit provided) //raiseerror exec
        } if
    } if
    /pad 8 string def
    pad 0 barcode putinterval       % Add barcode to the start of the pad
    pad 7 checksum 48 add put       % Put ascii for checksum at end of pad
    /barcode pad def
    /txt 8 array def
    txt 0 [barcode 0 1 getinterval textxoffset textyoffset textfont textsize 2 sub] put

    % Determine the mirror map based on checksum
    /mirrormap mirrormaps checksum get def

    % Invert the mirrormap if we are using a non-zero number system
    barcode 0 get 48 eq {
        /invt mirrormap length string def
        0 1 mirrormap length 1 sub {
            /i exch def
            mirrormap i get 48 eq {
                invt i 49 put
            } {
                invt i 48 put
            } ifelse
        } for
        /mirrormap invt def
    } if

    /sbs 33 string def

    % Put the start character
    sbs 0 encs 10 get putinterval

    1 1 6 {
        /i exch def
        % Lookup the encoding for the each barcode character
        barcode i 1 getinterval barchars exch search
        pop                            % Discard true leaving pre
        length /indx exch def          % indx is the length of pre
        pop pop                        % Discard seek and post
        /enc encs indx get def         % Get the indxth encoding
        mirrormap i 1 sub get 49 eq {  % Reverse enc if 1 in this position in mirrormap
            /enclen enc length def
            /revenc enclen string def
            0 1 enclen 1 sub {
                /j exch def
                /char enc j get def
                revenc enclen j sub 1 sub char put
            } for
            /enc revenc def
        } if
        sbs i 1 sub 4 mul 3 add enc putinterval   % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i 1 sub 7 mul 11 add textxoffset add textyoffset textfont textsize] put
    } for

    txt 7 [barcode 7 1 getinterval 6 7 mul 18 add textxoffset add textyoffset textfont textsize 2 sub] put

    % Put the end character
    sbs 27 encs 11 get putinterval

    /sbs [sbs {48 sub} forall] def
    includetext {
        /bhs [height height 12{height .075 sub}repeat height height height] def
        /bbs [0 0 12{.075}repeat 0 0 0] def
    } {
        /bhs [17{height}repeat] def
        /bbs [17{0}repeat] def
        /txt [] def
    } ifelse
    /guardrightypos 0 def

    % Append the addon
    addon () ne {
        /addopts <<
            /dontdraw true
            /includetext true
            /height height 0.15 sub
            /textxoffset addontextxoffset (unset) ne {addontextxoffset} {51 addongap add} ifelse
            addontextyoffset (unset) ne {/textyoffset addontextyoffset} if
            /textsize addontextsize (unset) ne {addontextsize} {textsize} ifelse
            /textfont addontextfont (unset) ne {addontextfont} {textfont} ifelse
        >> def
        addon length 2 eq {addon addopts //ean2 exec} if
        addon length 5 eq {addon addopts //ean5 exec} if
        /addcode exch def
        /sbs [sbs aload pop addongap addcode (sbs) get aload pop] def
        /bhs [bhs aload pop addcode (bhs) get {.075 sub} forall] def
        /bbs [bbs aload pop addcode (bbs) get {.075 add} forall] def
        /txt [txt aload pop addcode (txt) get aload pop] def
        /guardrightypos height 72 mul 6 sub def
    } if

    % Return the arguments
    <<
    /ren //renlinear
    /sbs sbs
    /bhs bhs
    /bbs bbs
    /txt txt
    /opt options
    /guardrightpos 10
    /guardrightypos guardrightypos
    /borderbottom 5
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/upce dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER upce--

% --BEGIN ENCODER isbn--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear ean5 ean2 ean13--
% --DESC: ISBN
% --EXAM: 978-1-56581-231-4 90000
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp isbn 0.0 2022082100 95230 94623
%%BeginData:        255 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /ean13 dup /uk.co.terryburton.bwipp findresource put
begin
/isbn {

    20 dict begin

    /options exch def      % We are given an options string
    /barcode exch def      % We are given the isbn text with dashes

    /ctx null def
    /dontdraw false def
    /includetext false def  % Enable/disable ISBN text
    /isbntextfont /Courier def
    /isbntextsize 9 def
    /isbntextxoffset (unset) def
    /isbntextyoffset (unset) def
    /height 1 def
    /addongap 12 def
    /legacy 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

    /isbntextfont isbntextfont cvlit def
    /isbntextsize isbntextsize cvr def
    isbntextxoffset (unset) ne {/isbntextxoffset isbntextxoffset cvr def} if
    isbntextyoffset (unset) ne {/isbntextyoffset isbntextyoffset cvr def} if
    /height height cvr def
    /addongap addongap cvr def

    % Split off the addon
    barcode ( ) search {
        /barcode exch def
        pop
        /addon exch def
    } {
        pop
        /addon () def
    } ifelse

    % Validate the input
    barcode length 15 ne barcode length 17 ne and
    barcode length 11 ne barcode length 13 ne and and {
        /bwipp.isbnBadLength (ISBN-13 must be 15 or 17 characters including dashes. ISBN-10 must be 11 or 13 characters including dashes) //raiseerror exec
    } if
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
        /bwipp.isbnBadAddOnLength (Add-on for ISBN must be 2 or 5 digits) //raiseerror exec
    } if
    barcode length 15 ge {  % ISBN-13
        barcode 0 4 getinterval dup (978-) ne exch (979-) ne and {
            /bwipp.isbn13badPrefix (ISBN-13 prefix must be 978- or 979-) //raiseerror exec
        } if
        /wasdash false def /numdash 0 def /numdigit 0 def
        barcode 5 9 getinterval {
            dup
            45 eq {
                wasdash {
                    /bwipp.isbn13adjacentDashes (ISBN-13 does not permit adjacent dashes) //raiseerror exec
                } if
                /wasdash true def
                /numdash numdash 1 add def
            } if
            dup 48 ge exch 57 le and {
                /wasdash false def
                /numdigit numdigit 1 add def
            } if
        } forall
        numdash 2 ne numdigit 7 ne or {
            /bwipp.isbn13numDashesDigits (Incorrect number of dashes and digits for ISBN-13) //raiseerror exec
        } if
        barcode 14 get dup 48 lt exch 57 gt or {
            /bwipp.isbn13character15 (ISBN-13 character 15 must be a digit) //raiseerror exec
        } if
        barcode length 17 eq {
            barcode 15 1 getinterval (-) ne {
                /bwipp.isbn13character16 (ISBN-13 penultimate character must be a dash) //raiseerror exec
            } if
            barcode 16 get dup 48 lt exch 57 gt or {
                /bwipp.isbn13character17 (ISBN-13 final character must be a digit) //raiseerror exec
            } if
        } if
    } {  % ISBN-10
        barcode 0 get dup 48 lt exch 57 gt or {
            /bwipp.isbn10FirstDigit (ISBN-10 first character must be a digit) //raiseerror exec
        } if
        /wasdash false def /numdash 0 def /numdigit 0 def
        barcode 1 9 getinterval {
            dup
            45 eq {
                wasdash {
                    /bwipp.isbn10adjacentDashes (ISBN-10 does not permit adjacent dashes) //raiseerror exec
                } if
                /wasdash true def
                /numdash numdash 1 add def
            } if
            dup 48 ge exch 57 le and {
                /wasdash false def
                /numdigit numdigit 1 add def
            } if
        } forall
        numdash 2 ne numdigit 7 ne or {
            /bwipp.isbn10numDashesDigits (Incorrect number of dashes and digits for ISBN-10) //raiseerror exec
        } if
        barcode 10 get dup 48 lt exch 57 gt or {
            /bwipp.isbn10character11 (ISBN-10 character 11 must be a digit) //raiseerror exec
        } if
        barcode length 13 eq {
            barcode 11 1 getinterval (-) ne {
                /bwipp.isbn10character12 (ISBN-10 penultimate character must be a dash) //raiseerror exec
            } if
            barcode 12 get dup dup 48 lt exch 57 gt or exch 88 ne and {
                /bwipp.isbn10character13 (ISBN-10 final character must be a digit or X) //raiseerror exec
            } if
        } if
    } ifelse

    /isbntxt barcode def

    % Read the digits from isbntxt and validate checksum for ISBN-10
    isbntxt length 13 le {
        /isbn 10 string def
        /checksum 0 def
        /i 0 def /n 0 def
        { % loop
            /isbnchar isbntxt i get 48 sub def
            isbnchar -3 ne {     % Ignore dashes
                isbn n isbnchar 48 add put
                n 9 lt {
                    /checksum checksum 10 n sub isbnchar mul add def
                } if
                /n n 1 add def
            } if
            /i i 1 add def
            i isbntxt length eq {exit} if
        } loop
        /checksum 11 checksum 11 mod sub 11 mod dup 10 eq {pop 40} if 48 add def
        /isbn isbn 0 9 getinterval def
        isbntxt length 13 eq {
            isbntxt 12 get checksum ne {
                /bwipp.isbn10badCheckDigit (Incorrect ISBN-10 check digit provided) //raiseerror exec
            } if
        } if
    } if

    legacy not isbntxt length 15 ge or {

        % Convert ISBN-10 to ISBN-13
        isbntxt length 13 le {
            /pad 15 string def
            pad 0 (978-) putinterval
            pad 4 isbntxt 0 11 getinterval putinterval
            /isbntxt pad def
        } if

        % Read the digits from isbntxt and validate checksum for ISBN-13
        /isbn 13 string def
        /checksum 0 def
        /i 0 def /n 0 def
        { % loop
            /isbnchar isbntxt i get 48 sub def
            isbnchar -3 ne {     % Ignore dashes
                isbn n isbnchar 48 add put
                n 12 lt {
                    /checksum isbnchar n 2 mod 0 ne {3 mul} if checksum add def
                } if
                /n n 1 add def
            } if
            /i i 1 add def
            i isbntxt length eq {exit} if
        } loop
        /checksum 10 checksum 10 mod sub 10 mod 48 add def
        /isbn isbn 0 12 getinterval def
        isbntxt length 17 eq {
            isbntxt 16 get checksum ne {
                /bwipp.isbn13badCheckDigit (Incorrect ISBN-13 check digit provided) //raiseerror exec
            } if
        } if

    } if

    % Add the ISBN header to the isbntxt
    /pad isbn length 12 eq {22} {18} ifelse string def
    pad 0 (ISBN ) putinterval
    pad 5 isbntxt putinterval
    pad pad length 2 sub 45 put
    pad pad length 1 sub checksum put
    /isbntxt pad def

    % Convert ISBN digits to EAN-13
    /barcode 12 string def
    isbn length 9 eq {
        barcode 0 (978) putinterval
        barcode 3 isbn putinterval
    } {
        barcode 0 isbn putinterval
    } ifelse

    % Append the addon
    addon () ne {
        12 addon length add 1 add string
        dup 0 barcode putinterval
        dup 12 ( ) putinterval
        dup 13 addon putinterval
        /barcode exch def
    } if

    % Get the result of encoding with ean13
    options (dontdraw) true put
    options (addongap) addongap put
    /args barcode options //ean13 exec def

    % Add the ISBN text
    includetext {
        isbntextxoffset (unset) eq {
            /isbntextxoffset isbn length 9 eq {-1} {-12} ifelse def
        } if
        isbntextyoffset (unset) eq {
            /isbntextyoffset height 72 mul 3 add def
        } if
        args (txt) known {
            /txt args (txt) get def
            /newtxt txt length 1 add array def
            newtxt 0 txt putinterval
            newtxt newtxt length 1 sub [isbntxt isbntextxoffset isbntextyoffset isbntextfont isbntextsize] put
            args (txt) newtxt put
        } {
            args (txt) [ [isbntxt isbntextxoffset isbntextyoffset isbntextfont isbntextsize] ] put
        } ifelse
    } if

    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/isbn dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER isbn--

% --BEGIN ENCODER ismn--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear ean5 ean2 ean13--
% --DESC: ISMN
% --EXAM: 979-0-2605-3211-3
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ismn 0.0 2022082100 91802 91288
%%BeginData:        234 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /ean13 dup /uk.co.terryburton.bwipp findresource put
begin
/ismn {

    20 dict begin

    /options exch def      % We are given an options string
    /barcode exch def      % We are given the ismn text with dashes

    /ctx null def
    /dontdraw false def
    /includetext false def  % Enable/disable ISMN text
    /ismntextfont /Courier def
    /ismntextsize 9 def
    /ismntextxoffset (unset) def
    /ismntextyoffset (unset) def
    /height 1 def
    /addongap 12 def
    /legacy 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

    /ismntextfont ismntextfont cvlit def
    /ismntextsize ismntextsize cvr def
    ismntextxoffset (unset) ne {/ismntextxoffset ismntextxoffset cvr def} if
    ismntextyoffset (unset) ne {/ismntextyoffset ismntextyoffset cvr def} if
    /height height cvr def
    /addongap addongap cvr def

    % Split off the addon
    barcode ( ) search {
        /barcode exch def
        pop
        /addon exch def
    } {
        pop
        /addon () def
    } ifelse

    % Validate the input
    barcode length 15 ne barcode length 17 ne and
    barcode length 11 ne barcode length 13 ne and and {
        /bwipp.ismnBadLength (ISMN-13 must be 15 or 17 characters including dashes. ISMN-10 must be 11 or 13 characters including dashes) //raiseerror exec
    } if
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
        /bwipp.ismnBadAddOnLength (Add-on for ISMN must be 2 or 5 digits) //raiseerror exec
    } if
    barcode length 15 ge {  % ISMN-13
        barcode 0 4 getinterval (979-) ne {
            /bwipp.ismn13badPrefix (ISMN-13 prefix must be 979-) //raiseerror exec
        } if
        /wasdash false def /numdash 0 def /numdigit 0 def
        barcode 5 9 getinterval {
            dup
            45 eq {
                wasdash {
                    /bwipp.ismn13adjacentDashes (ISMN-13 does not permit adjacent dashes) //raiseerror exec
                } if
                /wasdash true def
                /numdash numdash 1 add def
            } if
            dup 48 ge exch 57 le and {
                /wasdash false def
                /numdigit numdigit 1 add def
            } if
        } forall
        numdash 2 ne numdigit 7 ne or {
            /bwipp.ismn13numDashesDigits (Incorrect number of dashes and digits for ISMN-13) //raiseerror exec
        } if
        barcode 14 get dup 48 lt exch 57 gt or {
            /bwipp.ismn13character15 (ISMN-13 character 15 must be a digit) //raiseerror exec
        } if
        barcode length 17 eq {
            barcode 15 1 getinterval (-) ne {
                /bwipp.ismn13character16 (ISMN-13 penultimate character must be a dash) //raiseerror exec
            } if
            barcode 16 get dup 48 lt exch 57 gt or {
                /bwipp.ismn13character17 (ISMN-13 final character must be a digit) //raiseerror exec
            } if
        } if
    } {  % ISMN-10
        barcode 0 2 getinterval (M-) ne {
            /bwipp.ismn10badPrefix (ISMN-10 prefix must be M-) //raiseerror exec
        } if
        barcode 2 get dup 48 lt exch 57 gt or {
            /bwipp.ismn10character3 (ISMN-10 character 3 must be a digit) //raiseerror exec
        } if
        /wasdash false def /numdash 0 def /numdigit 0 def
        barcode 3 7 getinterval {
            dup
            45 eq {
                wasdash {
                    /bwipp.ismn10adjacentDashes (ISMN-10 does not permit adjacent dashes) //raiseerror exec
                } if
                /wasdash true def
                /numdash numdash 1 add def
            } if
            dup 48 ge exch 57 le and {
                /wasdash false def
                /numdigit numdigit 1 add def
            } if
        } forall
        numdash 1 ne numdigit 6 ne or {
            /bwipp.ismn10numDashesDigits (Incorrect number of dashes and digits for ISMN-10) //raiseerror exec
        } if
        barcode 10 get dup 48 lt exch 57 gt or {
            /bwipp.ismn10character11 (ISMN-10 character 11 must be a digit) //raiseerror exec
        } if
        barcode length 13 eq {
            barcode 11 1 getinterval (-) ne {
                /bwipp.ismn10character12 (ISMN-10 penultimate character must be a dash) //raiseerror exec
            } if
            barcode 12 get dup dup 48 lt exch 57 gt or exch 88 ne and {
                /bwipp.ismn10character13 (ISMN-10 final character must be a digit or X) //raiseerror exec
            } if
        } if
    } ifelse

    /ismntxt barcode def

    % Convert old ISMN to ISMN-13
    /legacytxt () def
    ismntxt length 13 le {
        /legacytxt ismntxt def
        /pad ismntxt length 4 add string def
        pad 0 (979-0-) putinterval
        pad 6 ismntxt 2 ismntxt length 2 sub getinterval putinterval
        /ismntxt pad def
    } if

    % Read the digits from ismntxt and calculate checksums
    /ismn 13 string def
    /checksum 0 def
    /i 0 def /n 0 def
    { % loop
        /ismnchar ismntxt i get 48 sub def
        ismnchar -3 ne {           % Ignore dashes
            ismn n ismnchar 48 add put
            n 12 lt {
                n 2 mod 0 eq {
                    /checksum ismnchar checksum add def
                } {
                    /checksum ismnchar 3 mul checksum add def
                } ifelse
            } if
            /n n 1 add def
        } if
        /i i 1 add def
        i ismntxt length eq {exit} if
    } loop
    /checksum 10 checksum 10 mod sub 10 mod 48 add def

    % Validate the checksum
    barcode length 13 eq barcode length 17 eq or {
        barcode dup length 1 sub get checksum ne {
            /bwipp.ismnBadCheckDigit (Incorrect ISMN check digit provided) //raiseerror exec
        } if
    } if

    % Add the ISMN header and checksum to the ismntxt
    legacy legacytxt () ne and {
        /ismntxt legacytxt def
        /pad 18 string def
    } {
        /pad 22 string def
    } ifelse
    pad 0 (ISMN ) putinterval
    pad 5 ismntxt putinterval
    pad pad length 2 sub 45 put
    pad pad length 1 sub checksum put
    /ismntxt pad def

    % Convert ISMN digits to EAN-13
    /barcode ismn 0 12 getinterval def

    % Append the addon
    addon () ne {
        12 addon length add 1 add string
        dup 0 barcode putinterval
        dup 12 ( ) putinterval
        dup 13 addon putinterval
        /barcode exch def
    } if

    % Get the result of encoding with ean13
    options (dontdraw) true put
    options (addongap) addongap put
    /args barcode options //ean13 exec def

    % Add the ISMN text
    includetext {
        ismntextxoffset (unset) eq {
            /ismntextxoffset ismntxt length 18 eq {-1} {-12} ifelse def
        } if
        ismntextyoffset (unset) eq {
            /ismntextyoffset height 72 mul 3 add def
        } if
        args (txt) known {
            /txt args (txt) get def
            /newtxt txt length 1 add array def
            newtxt 0 txt putinterval
            newtxt newtxt length 1 sub [ismntxt ismntextxoffset ismntextyoffset ismntextfont ismntextsize] put
            args (txt) newtxt put
        } {
            args (txt) [ [ismntxt ismntextxoffset ismntextyoffset ismntextfont ismntextsize] ] put
        } ifelse
    } if

    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/ismn dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER ismn--

% --BEGIN ENCODER issn--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear ean2 ean5 ean13--
% --DESC: ISSN
% --EXAM: 0311-175X 00 17
% --EXOP: includetext guardwhitespace
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp issn 0.0 2022082100 83234 82612
%%BeginData:        179 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /ean13 dup /uk.co.terryburton.bwipp findresource put
begin
/issn {

    20 dict begin

    /options exch def      % We are given an options string
    /issntxt exch def      % We are given the issn text with dashes

    /ctx null def
    /dontdraw false def
    /includetext false def  % Enable/disable ISSN text
    /issntextfont /Courier def
    /issntextsize 9 def
    /issntextxoffset (unset) def
    /issntextyoffset (unset) def
    /height 1 def
    /addongap 12 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

    /issntextfont issntextfont cvlit def
    /issntextsize issntextsize cvr def
    issntextxoffset (unset) ne {/issntextxoffset issntextxoffset cvr def} if
    issntextyoffset (unset) ne {/issntextyoffset issntextyoffset cvr def} if
    /height height cvr def
    /addongap addongap cvr def

    % Split off the ISSN
    issntxt ( ) search {
        /issntxt exch def
        pop
        /seqvar exch def
    } {
        pop
        /seqvar (00) def
    } ifelse

    % Split off the sequence variant and addon
    seqvar ( ) search {
        /seqvar exch def
        pop
        /addon exch def
    } {
        pop
        /addon () def
    } ifelse

    % Validate the input
    issntxt length 8 ne issntxt length 9 ne and {
        /bwipp.issnBadLength (ISSN must be 8 or 9 characters including dash, in the format XXXX-XXXX) //raiseerror exec
    } if
    issntxt 0 4 getinterval {
        dup 48 lt exch 57 gt or {
            /bwipp.issnFirstThroughFourthNotNumeric (ISSN first four characters must be numeral characters) //raiseerror exec
        } if
    } forall
    issntxt 4 1 getinterval (-) ne {
        /bwipp.issnNeedsDash (ISSN fifth character must be a dash) //raiseerror exec
    } if
    issntxt 5 3 getinterval {
        dup 48 lt exch 57 gt or {
            /bwipp.issnSixthThroughEighthNotNumeric (ISSN sixth through eighth characters must be numerals) //raiseerror exec
        } if
    } forall
    issntxt length 9 eq {
        issntxt 8 get dup dup 48 lt exch 57 gt or exch 88 ne and {  % Digits or X
            /bwipp.issnNinthCharacterBadFormat (ISSN ninth character must be a number or the character X) //raiseerror exec
        } if
    } if
    seqvar length 2 ne {
        /bwipp.issnBadSequenceVariantLength (Sequence variant for ISSN must be 2 digits) //raiseerror exec
    } if
    seqvar {
        dup 48 lt exch 57 gt or {
           /bwipp.issnSequenceVariantBadCharacter (Sequence variant for ISSN must contain only digits) //raiseerror exec
        } if
    } forall
    addon length 0 ne addon length 2 ne and addon length 5 ne and {
        /bwipp.issnBadAddOnLength (Add-on for ISSN must be 2 or 5 digits) //raiseerror exec
    } if

    % Read the digits from issntxt and calculate checksums
    /issn 8 string def
    /checksum 0 def
    /i 0 def /n 0 def
    { % loop
        /issnchar issntxt i get 48 sub def
        issnchar -3 ne {           % Ignore dashes
            issn n issnchar 48 add put
            n 7 lt {
                /checksum checksum issnchar 8 n sub mul add def
            } if
            /n n 1 add def
        } if
        /i i 1 add def
        i issntxt length eq {exit} if
    } loop
    /checksum 11 checksum 11 mod sub 11 mod def
    /checksum checksum 48 add dup 58 eq {pop 88} if def
    issntxt length 9 eq {
        issntxt 8 get checksum ne {
            /bwipp.issnBadCheckDigit (Incorrect ISSN check digit provided) //raiseerror exec
        } if
    } if

    % Add the ISSN header and checksum to the issntxt
    /pad 14 string def
    pad 0 (ISSN ) putinterval
    pad 5 issntxt putinterval  % Add issntxt to the pad
    pad 13 checksum put
    /issntxt pad def

    % Convert ISSN digits to EAN-13
    /barcode issn 0 7 getinterval def

    % Append the sequence variant
    /barcode 12 string def
    barcode 0 (977) putinterval
    barcode 3 issn putinterval
    barcode 10 seqvar putinterval

    % Append the addon
    addon () ne {
        12 addon length add 1 add string
        dup 0 barcode putinterval
        dup 12 ( ) putinterval
        dup 13 addon putinterval
        /barcode exch def
    } if

    % Get the result of encoding with ean13
    options (dontdraw) true put
    options (addongap) addongap put
    /args barcode options //ean13 exec def

    % Add the ISSN text
    includetext {
        issntextxoffset (unset) eq {/issntextxoffset 10 def} if
        issntextyoffset (unset) eq {
            /issntextyoffset height 72 mul 3 add def
        } if
        args (txt) known {
            /txt args (txt) get def
            /newtxt txt length 1 add array def
            newtxt 0 txt putinterval
            newtxt newtxt length 1 sub [issntxt issntextxoffset issntextyoffset issntextfont issntextsize] put
            args (txt) newtxt put
        } {
            args (txt) [ [issntxt issntextxoffset issntextyoffset issntextfont issntextsize] ] put
        } ifelse
    } if

    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/issn dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER issn--

% --BEGIN ENCODER mands--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear ean2 ean5 ean8--
% --DESC: Marks & Spencer
% --EXAM: 0642118
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp mands 0.0 2022082100 71641 71714
%%BeginData:         83 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /ean8 dup /uk.co.terryburton.bwipp findresource put
begin
/mands {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /includetext 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

    /barlen barcode length def

    % Validate the input
    barlen 7 ne barlen 8 ne and {
        /bwipp.MandSbadLength (M&S barcode must be 7 or 8 characters) //raiseerror exec
    } if

    barlen 7 eq {
        /barcode (00000000) 8 string copy dup 1 barcode putinterval def
    } if

    % Get the result of encoding with ean8
    options (dontdraw) true put
    /args barcode options //ean8 exec def

    % Remove the centre guard
    args (bbs) get dup
    dup 2 get 10 exch put
    dup 2 get 11 exch put
    args (bhs) get dup
    dup 2 get 10 exch put
    dup 2 get 11 exch put

    % Fix up the text for 7-digit inputs
    /txt args (txt) get def
    barlen 7 eq {
        0 1 6 {
            txt exch 2 copy
            1 add get 0 get 3 1 roll get
            0 get exch 0 exch putinterval
        } for
        txt 7 get 0 get 0 ( ) putinterval
    } if

    % Add the M and S guards
    10 array dup 0 txt putinterval /txt exch def
    txt 0 get dup length array copy txt exch 8 exch put
    txt 0 get dup length array copy txt exch 9 exch put
    txt 8 get 0 (M) put txt 8 get 1 -12 put
    txt 9 get 0 (S) put txt 9 get 1 69 put

    args (txt) txt put
    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/mands dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER mands--

% --BEGIN ENCODER code128--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renlinear--
% --DESC: Code 128
% --EXAM: Count01234567!
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code128 0.0 2022082100 125925 128825
%%BeginData:        438 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code128 {

    20 dict begin                  % Confine variables to local scope

    /options exch def        % We are given an option string
    /barcode exch def        % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 1 def
    /encoding (auto) def
    /raw false def
    /parse false def
    /parsefnc 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /code128 //loadctx exec

    % Special function characters
{
    /sta  -1 def  /stb  -2 def  /stc  -3 def
    /swa  -4 def  /swb  -5 def  /swc  -6 def
    /fn1  -7 def  /fn2  -8 def  /fn3  -9 def
    /fn4 -10 def  /sft -11 def  /stp -12 def
    /lka -13 def  /lkc -14 def  % CC-A/B and CC-C linkage
} ctxdef

    % Parse the input
    /fncvals <<
        /parse parse
        /parsefnc parsefnc
        (FNC1) fn1
        (FNC1) fn1
        (FNC2) fn2
        (FNC3) fn3
%        (FNC4) fn4    Not user accessible as encoded automatically
        (LNKA) lka
        (LNKC) lkc
    >> def
    /msg barcode fncvals //parseinput exec def
    /msglen msg length def

    % Character maps for each state
{
    /charmaps [
      %  A    B    C         A    B    C         A    B    C
      [  32   32  (00) ]  [ (!)  (!)  (01) ]  [ (")  (")  (02) ]  % 0-2
      [ (#)  (#)  (03) ]  [ ($)  ($)  (04) ]  [ (%)  (%)  (05) ]  % 3-5
      [ (&)  (&)  (06) ]  [ (')  (')  (07) ]  [  40   40  (08) ]  % 6-8
      [  41   41  (09) ]  [ (*)  (*)  (10) ]  [ (+)  (+)  (11) ]  % 9-11
      [ (,)  (,)  (12) ]  [ (-)  (-)  (13) ]  [ (.)  (.)  (14) ]  % 12-14
      [ (/)  (/)  (15) ]  [ (0)  (0)  (16) ]  [ (1)  (1)  (17) ]  % 15-17
      [ (2)  (2)  (18) ]  [ (3)  (3)  (19) ]  [ (4)  (4)  (20) ]  % 18-20
      [ (5)  (5)  (21) ]  [ (6)  (6)  (22) ]  [ (7)  (7)  (23) ]  % 21-23
      [ (8)  (8)  (24) ]  [ (9)  (9)  (25) ]  [ (:)  (:)  (26) ]  % 24-26
      [ (;)  (;)  (27) ]  [ (<)  (<)  (28) ]  [ (=)  (=)  (29) ]  % 27-29
      [ (>)  (>)  (30) ]  [ (?)  (?)  (31) ]  [ (@)  (@)  (32) ]  % 30-32
      [ (A)  (A)  (33) ]  [ (B)  (B)  (34) ]  [ (C)  (C)  (35) ]  % 33-35
      [ (D)  (D)  (36) ]  [ (E)  (E)  (37) ]  [ (F)  (F)  (38) ]  % 36-38
      [ (G)  (G)  (39) ]  [ (H)  (H)  (40) ]  [ (I)  (I)  (41) ]  % 39-41
      [ (J)  (J)  (42) ]  [ (K)  (K)  (43) ]  [ (L)  (L)  (44) ]  % 42-44
      [ (M)  (M)  (45) ]  [ (N)  (N)  (46) ]  [ (O)  (O)  (47) ]  % 45-47
      [ (P)  (P)  (48) ]  [ (Q)  (Q)  (49) ]  [ (R)  (R)  (50) ]  % 48-50
      [ (S)  (S)  (51) ]  [ (T)  (T)  (52) ]  [ (U)  (U)  (53) ]  % 51-53
      [ (V)  (V)  (54) ]  [ (W)  (W)  (55) ]  [ (X)  (X)  (56) ]  % 54-56
      [ (Y)  (Y)  (57) ]  [ (Z)  (Z)  (58) ]  [ ([)  ([)  (59) ]  % 57-59
      [  92   92  (60) ]  [ (])  (])  (61) ]  [ (^)  (^)  (62) ]  % 60-62
      [ (_)  (_)  (63) ]  [   0  (`)  (64) ]  [   1  (a)  (65) ]  % 63-65
      [   2  (b)  (66) ]  [   3  (c)  (67) ]  [   4  (d)  (68) ]  % 66-68
      [   5  (e)  (69) ]  [   6  (f)  (70) ]  [   7  (g)  (71) ]  % 69-71
      [   8  (h)  (72) ]  [   9  (i)  (73) ]  [  10  (j)  (74) ]  % 72-74
      [  11  (k)  (75) ]  [  12  (l)  (76) ]  [  13  (m)  (77) ]  % 75-77
      [  14  (n)  (78) ]  [  15  (o)  (79) ]  [  16  (p)  (80) ]  % 78-80
      [  17  (q)  (81) ]  [  18  (r)  (82) ]  [  19  (s)  (83) ]  % 81-83
      [  20  (t)  (84) ]  [  21  (u)  (85) ]  [  22  (v)  (86) ]  % 84-86
      [  23  (w)  (87) ]  [  24  (x)  (88) ]  [  25  (y)  (89) ]  % 87-89
      [  26  (z)  (90) ]  [  27  ({)  (91) ]  [  28  (|)  (92) ]  % 90-92
      [  29  (})  (93) ]  [  30  (~)  (94) ]  [  31  127  (95) ]  % 93-95
      [ fn3  fn3  (96) ]  [ fn2  fn2  (97) ]  [ sft  sft  (98) ]  % 96-98
      [ swc  swc  (99) ]  [ swb  fn4  swb  ]  [ fn4  swa  swa  ]  % 99-101
      [ fn1  fn1  fn1  ]  [ sta  sta  sta  ]  [ stb  stb  stb  ]  % 102-104
      [ stc  stc  stc  ]  [ stp  stp  stp  ]                      % 105-106
    ] def

    % Invert charmaps to give character to value maps for each state
    /charvals [ 109 dict 109 dict 109 dict ] def
    0 1 charmaps length 1 sub {
        /i exch def
        /encs charmaps i get def
        0 1 2 {
            /j exch def
            encs j get dup type /stringtype eq {0 get} if  % convert string to ASCII if required
            charvals j get exch i put
        } for
    } for
    /seta charvals 0 get def
    /setb charvals 1 get def
    /setc charvals 2 get def
} ctxdef

    % Include pseudo characters for GS1-128 Composite linkage identifiers
    seta lka seta swb get put  seta lkc seta swc get put
    setb lka setb swc get put  setb lkc setb swa get put
    setc lka setc swa get put  setc lkc setc swb get put

    raw {/encoding (raw) def} if

    encoding (raw) eq {
        /cws 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
            cws j cw put
            /i i 4 add def
            /j j 1 add def
        } loop
        /cws cws 0 j getinterval def
        /text () def
    } if

    encoding (auto) eq {

        /text msglen string def
        0 1 msglen 1 sub {
            /i exch def
            text i msg i get dup 0 lt { pop 32 } if put
        } for

        % Standard and extended ASCII runlength at position
        /numSA [ msglen {0} repeat 0 ] def
        /numEA [ msglen {0} repeat 0 ] def
        msglen 1 sub -1 0 {
            /i exch def
            msg i get 0 ge {
                msg i get 128 ge {
                    numEA i numEA i 1 add get 1 add put
                } {
                    numSA i numSA i 1 add get 1 add put
                } ifelse
            } if
        } for

        % FNC4 codeword insertion for extended ASCII
        /ea false def /msgtmp [] def
        0 1 msglen 1 sub {
            /i exch def
            /c msg i get def
            ea c 128 lt xor not c 0 ge and {  % Other mode required
                ea {numSA} {numEA} ifelse i get dup  % Runlength of other mode
                i add msglen eq {3} {5} ifelse       % Does run terminate symbol
                lt {  % Shift
                    /msgtmp [ msgtmp aload pop fn4 ] def
                } {   % Latch
                    /msgtmp [ msgtmp aload pop fn4 fn4 ] def
                    /ea ea not def
                } ifelse
            } if
            /msgtmp [ msgtmp aload pop c 0 ge {c 127 and} {c} ifelse ] def
        } for
        /msg msgtmp def
        /msglen msg length def

        % Determine digit runlength and characters from given position
        /numsscr {
            /n 0 def /s 0 def
            /p exch def {
                p msglen ge {exit} if
                msg p get
                dup setc exch known not {pop exit} if
                dup -1 le {
                    % FNC1 in odd position of run like two digits
                    fn1 eq s 2 mod 0 eq and {/s s 1 add def} {exit} ifelse
                } {
                    pop
                } ifelse
                /n n 1 add def
                /s s 1 add def
                /p p 1 add def
            } loop
            n s
        } def

        % Encoding for each alphabet
        /enca {
            seta exch get cws exch j exch put
            /j j 1 add def
        } def
        /encb {
            setb exch get cws exch j exch put
            /j j 1 add def
        } def
        /encc {
            dup type /arraytype ne {
                setc exch get
            } {
                aload pop 48 sub exch 48 sub 10 mul add
            } ifelse
            cws exch j exch put
            /j j 1 add def
        } def

        % Character exclusively in either alphabet A or B
        /anotb {dup seta exch known exch setb exch known not and} def
        /bnota {dup setb exch known exch seta exch known not and} def

        % Pre-compute relative position of next anotb and next bnota characters
        /nextanotb [ msg length {0} repeat 9999 ] def
        /nextbnota [ msg length {0} repeat 9999 ] def
        msg length 1 sub -1 0 {
            /i exch def
            msg i get anotb {
                nextanotb i 0 put
            } {
                nextanotb i nextanotb i 1 add get 1 add put
            } ifelse
            msg i get bnota {
                nextbnota i 0 put
            } {
                nextbnota i nextbnota i 1 add get 1 add put
            } ifelse
        } for

        % Does a-only come before b-only after given position and vice versa
        /abeforeb {dup nextanotb exch get exch nextbnota exch get lt} def
        /bbeforea {dup nextbnota exch get exch nextanotb exch get lt} def

        /cws barcode length 2 mul 3 add array def

        % Select start character
        /j 0 def
        msglen 0 gt {0 numsscr} {-1 -1} ifelse /nums exch def /nchars exch def
        {  % common exit
            msglen 0 eq {
                stb enca
                /cset (setb) def
                exit
            } if
            msglen 2 eq nums 2 eq and {
                stc enca
                /cset (setc) def
                exit
            } if
            nums 4 ge {
                stc enca
                /cset (setc) def
                exit
            } if
            0 abeforeb {
                sta enca
                /cset (seta) def
                exit
            } if
            stb enca
            /cset (setb) def
            exit
        } loop

        % Main encoding loop
        /i 0 def {
            i msglen eq {exit} if

            i numsscr /nums exch def /nchars exch def

            % Determine switches and shifts
            {  % common exit
                cset (seta) eq cset (setb) eq or nums 4 ge and
                msg i get fn1 ne and {
                    nums 2 mod 0 eq {
                        swc cset (seta) eq {enca} {encb} ifelse
                        /cset (setc) def
                        exit
                    } {
                        msg i get cset (seta) eq {enca} {encb} ifelse
                        /i i 1 add def
                        swc cset (seta) eq {enca} {encb} ifelse
                        /cset (setc) def
                        exit
                    } ifelse
                } if
                cset (setb) eq msg i get anotb and {
                    i msglen 1 sub lt {
                        i 1 add bbeforea {
                            sft encb
                            msg i get enca
                            /i i 1 add def
                            exit
                        } if
                    } if
                    swa encb
                    /cset (seta) def
                    exit
                } if
                cset (seta) eq msg i get bnota and {
                    i msglen 1 sub lt {
                        i 1 add abeforeb {
                            sft enca
                            msg i get encb
                            /i i 1 add def
                            exit
                        } if
                    } if
                    swb enca
                    /cset (setb) def
                    exit
                } if
                cset (setc) eq nums 2 lt and msg i get -1 gt and {
                    i abeforeb {
                        swa encc
                        /cset (seta) def
                        exit
                    } if
                    swb encc
                    /cset (setb) def
                    exit
                } if

                % No switches or latches so encode
                cset (seta) eq {
                    msg i get enca
                    /i i 1 add def
                    exit
                } if
                cset (setb) eq {
                    msg i get encb
                    /i i 1 add def
                    exit
                } if
                cset (setc) eq {
                    msg i get -1 le {
                        msg i get encc
                        /i i 1 add def
                    } {
                        msg i 2 getinterval encc
                        /i i 2 add def
                    } ifelse
                    exit
                } if

                exit
            } loop

        } loop
        /cws cws 0 j getinterval def
    } if  % auto encoding

    % Derive checksum and place stop character
    /cws j 2 add array dup 0 cws putinterval def
    /csum cws 0 get def
    1 1 j 1 sub {
        /i exch def
        /csum csum cws i get i mul add def
    } for
    /csum csum 103 mod def
    cws j csum put
    cws j 1 add seta stp get put

    % Create an array containing the character mappings
{
    /encs
    [ (212222) (222122) (222221) (121223) (121322) (131222) (122213)
      (122312) (132212) (221213) (221312) (231212) (112232) (122132)
      (122231) (113222) (123122) (123221) (223211) (221132) (221231)
      (213212) (223112) (312131) (311222) (321122) (321221) (312212)
      (322112) (322211) (212123) (212321) (232121) (111323) (131123)
      (131321) (112313) (132113) (132311) (211313) (231113) (231311)
      (112133) (112331) (132131) (113123) (113321) (133121) (313121)
      (211331) (231131) (213113) (213311) (213131) (311123) (311321)
      (331121) (312113) (312311) (332111) (314111) (221411) (431111)
      (111224) (111422) (121124) (121421) (141122) (141221) (112214)
      (112412) (122114) (122411) (142112) (142211) (241211) (221114)
      (413111) (241112) (134111) (111242) (121142) (121241) (114212)
      (124112) (124211) (411212) (421112) (421211) (212141) (214121)
      (412121) (111143) (111341) (131141) (114113) (114311) (411113)
      (411311) (113141) (114131) (311141) (411131) (211412) (211214)
      (211232) (2331112)
    ] def
} ctxdef

    % Derive space bar succession
    /sbs cws length 6 mul 1 add string def
    0 1 cws length 1 sub {
        /i exch def
        sbs i 6 mul encs cws i get get putinterval
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    /txt [ [text textxoffset textyoffset textfont textsize] ]
    /textxalign (center)
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/code128 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER code128--

% --BEGIN ENCODER gs1-128--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear code128--
% --DESC: GS1-128
% --EXAM: (01)95012345678903(3103)000123
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp gs1-128 0.0 2022082100 80068 76461
%%BeginData:        114 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput 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 /code128 dup /uk.co.terryburton.bwipp findresource put
begin
/gs1-128 {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 0.5 def
    /linkagea false def
    /linkagec false def
    /parse false def
    /dontlint false def
    /lintreqs 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /text barcode def

    barcode /ai //gs1process exec
    /fncs exch def
    /vals exch def
    /ais exch def

    % Create the code128 data
    /fnc1 -1 def
    /c128 [ fnc1 ] def
    0 1 ais length 1 sub {
        /i exch def
        /ai ais i get def
        /val vals i get def
        c128 length ai length add val length add array
        dup 0 c128 putinterval
        dup c128 length ai [ exch {} forall ] putinterval
        dup c128 length ai length add val [ exch {} forall ] putinterval
        /c128 exch def
        i ais length 1 sub ne fncs i get and {  % Append FNC1
            c128 length 1 add array
            dup 0 c128 putinterval
            dup c128 length fnc1 put
            /c128 exch def
        } if
    } for

    % Compose input to code128
    /barcode c128 length 1 add 5 mul string def
    /i 0 def /j 0 def {
        i c128 length eq {exit} if
        c128 i get dup fnc1 eq {
            pop barcode j (^FNC1) putinterval
            /j j 4 add def
        } {
            barcode exch j exch put
        } ifelse
        /i i 1 add def
        /j j 1 add def
    } loop
    linkagea linkagec or {
        barcode j linkagea {(^LNKA)} {(^LNKC)} ifelse putinterval
        /j j 5 add def
    } if
    /barcode barcode 0 j getinterval def

    % Get the result of encoding with code128
    options (parse) undef
    options (height) height put
    options (dontdraw) true put
    options (parsefnc) true put
    /args barcode options //code128 exec def

    args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
    args (textxalign) (center) put
    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/gs1-128 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER gs1-128--

% --BEGIN ENCODER ean14--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renlinear code128--
% --DESC: GS1-14
% --EXAM: (01) 0 46 01234 56789 3
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp ean14 0.0 2022082100 72494 72450
%%BeginData:        108 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code128 dup /uk.co.terryburton.bwipp findresource put
begin
/ean14 {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    % Strip spaces from the given data
    /text barcode def
    barcode dup length string exch 0 exch
    {dup 32 ne {3 copy put pop 1 add} {pop} ifelse} forall
    0 exch getinterval /barcode exch def
    /hasspace text length barcode length ne def

    % Validate the input
    barcode 0 4 getinterval (\(01\)) ne {
        /bwipp.ean14badAI (GS1-14 must begin with (01) application identifier) //raiseerror exec
    } if
    barcode length 17 ne barcode length 18 ne and {
        /bwipp.ean14badLength (GS1-14 must be 13 or 14 digits) //raiseerror exec
    } if
    barcode 4 barcode length 4 sub getinterval {
        dup 48 lt exch 57 gt or {
            /bwipp.ean14badCharacter (GS1-14 must contain only digits) //raiseerror exec
        } if
    } forall

    % Calculate checksum and add to end of barcode
    /checksum 0 def
    0 1 12 {
        /i exch def
        /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 18 eq {
        barcode 17 get checksum 48 add ne {
            /bwipp.ean14badCheckDigit (Incorrect GS1-14 check digit provided) //raiseerror exec
        } if
    } {
        18 string
        dup 0 barcode putinterval
        dup 17 checksum 48 add put
        /barcode exch def
        text length hasspace {2} {1} ifelse add string
        dup dup length 2 sub ( ) putinterval
        dup dup length 1 sub checksum 48 add put
        dup 0 text putinterval
        /text exch def
    } ifelse
    /gtin barcode 4 14 getinterval def

    % Compose input to code128
    /barcode 21 string def
    barcode 0 (^FNC101) putinterval
    barcode 7 gtin putinterval

    % Get the result of encoding with code128
    options (dontdraw) true put
    options (parsefnc) true put
    /args barcode options //code128 exec def

    args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
    args (textxalign) (center) put
    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/ean14 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER ean14--

% --BEGIN ENCODER sscc18--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renlinear code128--
% --DESC: SSCC-18
% --EXAM: (00) 0 0614141 123456789 0
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp sscc18 0.0 2022082100 72506 72457
%%BeginData:        108 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code128 dup /uk.co.terryburton.bwipp findresource put
begin
/sscc18 {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    % Strip spaces from the given data
    /text barcode def
    barcode dup length string exch 0 exch
    {dup 32 ne {3 copy put pop 1 add} {pop} ifelse} forall
    0 exch getinterval /barcode exch def
    /hasspace text length barcode length ne def

    % Validate the input
    barcode 0 4 getinterval (\(00\)) ne {
        /bwipp.sscc18badAI (SSCC-18 must begin with (00) application identifier) //raiseerror exec
    } if
    barcode length 21 ne barcode length 22 ne and {
        /bwipp.sscc18badLength (SSCC-18 must be 17 or 18 digits) //raiseerror exec
    } if
    barcode 4 barcode length 4 sub getinterval {
        dup 48 lt exch 57 gt or {
            /bwipp.sscc18badCharacter (SSCC-18 must contain only digits) //raiseerror exec
        } if
    } forall

    % Calculate checksum and add to end of barcode
    /checksum 0 def
    0 1 16 {
        /i exch def
        /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 22 eq {
        barcode 21 get checksum 48 add ne {
            /bwipp.sscc18badCheckDigit (Incorrect SSCC-18 check digit provided) //raiseerror exec
        } if
    } {
        22 string
        dup 0 barcode putinterval
        dup 21 checksum 48 add put
        /barcode exch def
        text length hasspace {2} {1} ifelse add string
        dup dup length 2 sub ( ) putinterval
        dup dup length 1 sub checksum 48 add put
        dup 0 text putinterval
        /text exch def
    } ifelse
    /sscc barcode 4 18 getinterval def

    % Compose input to code128
    /barcode 25 string def
    barcode 0 (^FNC100) putinterval
    barcode 7 sscc putinterval

    % Get the result of encoding with code128
    options (dontdraw) true put
    options (parsefnc) true put
    /args barcode options //code128 exec def

    args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
    args (textxalign) (center) put
    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/sscc18 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER sscc18--

% --BEGIN ENCODER code39--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: Code 39
% --EXAM: THIS IS CODE 39
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code39 0.0 2022082100 72416 68679
%%BeginData:        154 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code39 {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includecheck false def
    /validatecheck false def
    /includetext false def
    /includecheckintext false def
    /hidestars false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /code39 //loadctx exec

    % Create a string of the available characters
{
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
    /charvals 43 dict def
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.code39badCharacter (Code 39 must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {1 sub} if def

    /checksum 0 def
    0 1 barlen 1 sub {
        barcode exch 1 getinterval charvals exch get
        checksum add /checksum exch def
    } for
    /checksum checksum 43 mod def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.code39badCheckDigit (Incorrect Code 39 check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
        /includecheck true def
    } if

    % Create an array containing the character mappings
{
    /encs
    [ (1113313111) (3113111131) (1133111131) (3133111111) (1113311131)
      (3113311111) (1133311111) (1113113131) (3113113111) (1133113111)
      (3111131131) (1131131131) (3131131111) (1111331131) (3111331111)
      (1131331111) (1111133131) (3111133111) (1131133111) (1111333111)
      (3111111331) (1131111331) (3131111311) (1111311331) (3111311311)
      (1131311311) (1111113331) (3111113311) (1131113311) (1111313311)
      (3311111131) (1331111131) (3331111111) (1311311131) (3311311111)
      (1331311111) (1311113131) (3311113111) (1331113111) (1313131111)
      (1313111311) (1311131311) (1113131311) (1311313111)
    ] def
} ctxdef

    /sbs barlen includecheck {3} {2} ifelse add 10 mul string def
    /txt barlen includecheck {3} {2} ifelse add array def

    % Put the start character
    sbs 0 encs 43 get putinterval
    hidestars not {
        txt 0 [(*) 0 textyoffset textfont textsize] put
    } {
        txt 0 [() 0 textyoffset textfont textsize] put
    } ifelse

    0 1 barlen 1 sub {
        /i exch def
        /indx charvals barcode i 1 getinterval get def
        sbs i 10 mul 10 add encs indx get putinterval
        txt i 1 add [barcode i 1 getinterval i 1 add 16 mul textyoffset textfont textsize] put
    } for

    % Put the checksum and end characters
    includecheck {
        sbs barlen 10 mul 10 add encs checksum get putinterval
        includecheckintext {
            txt barlen 1 add [barchars checksum 1 getinterval barlen 1 add 16 mul textyoffset textfont textsize] put
        } {
            txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put
        } ifelse
        sbs barlen 10 mul 20 add encs 43 get putinterval
        hidestars not {
            txt barlen 2 add [(*) barlen 2 add 16 mul textyoffset textfont textsize] put
        } {
            txt barlen 2 add [() barlen 2 add 16 mul textyoffset textfont textsize] put
        } ifelse
    } {
        sbs barlen 10 mul 10 add encs 43 get putinterval
        hidestars not {
            txt barlen 1 add [(*) barlen 1 add 16 mul textyoffset textfont textsize] put
        } {
            txt barlen 1 add [() barlen 1 add 16 mul textyoffset textfont textsize] put
        } ifelse
    } ifelse

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/code39 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER code39--

% --BEGIN ENCODER code39ext--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renlinear code39--
% --DESC: Code 39 Extended
% --EXAM: Code39 Ext!
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code39ext 0.0 2022082100 71249 70993
%%BeginData:        109 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code39 dup /uk.co.terryburton.bwipp findresource put
begin
/code39ext {

    20 dict begin

    /options exch def      % We are given an options string
    /barcode exch def      % We are given the code39extended text

    /ctx null def
    /dontdraw false def
    /includetext 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

    /code39ext //loadctx exec

    % Parse ordinals of the form ^NNN to ASCII
    /fncvals <<
        /parse parse
        /parseonly true
        /parsefnc false
    >> def
    /barcode barcode fncvals //parseinput exec def
    /barlen barcode length def
    options (parse) undef

    % Validate the input
    barcode {
        128 ge {
            /bwipp.code39extBadCharacter (Code 39 Extended must contain only ASCII characters) //raiseerror exec
        } if
    } forall

    % Extended alphabet to non-extended alphabet
{
    /extencs
    [ (%U) ($A) ($B) ($C) ($D) ($E) ($F) ($G) ($H) ($I) ($J) ($K) ($L) ($M) ($N) ($O)
      ($P) ($Q) ($R) ($S) ($T) ($U) ($V) ($W) ($X) ($Y) ($Z) (%A) (%B) (%C) (%D) (%E)
      ( )  (/A) (/B) (/C) (/D) (/E) (/F) (/G) (/H) (/I) (/J) (/K) (/L) (-)  (.)  (/O)
      (0)  (1)  (2)  (3)  (4)  (5)  (6)  (7)  (8)  (9)  (/Z) (%F) (%G) (%H) (%I) (%J)
      (%V) (A)  (B)  (C)  (D)  (E)  (F)  (G)  (H)  (I)  (J)  (K)  (L)  (M)  (N)  (O)
      (P)  (Q)  (R)  (S)  (T)  (U)  (V)  (W)  (X)  (Y)  (Z)  (%K) (%L) (%M) (%N) (%O)
      (%W) (+A) (+B) (+C) (+D) (+E) (+F) (+G) (+H) (+I) (+J) (+K) (+L) (+M) (+N) (+O)
      (+P) (+Q) (+R) (+S) (+T) (+U) (+V) (+W) (+X) (+Y) (+Z) (%P) (%Q) (%R) (%S) (%T)
    ] def
} ctxdef

    /newcode barlen 2 mul string def
    /newtext barlen 2 mul string def
    /j 0 def
    0 1 barlen 1 sub {
        /i exch def
        /extchar extencs barcode i get get def
        newcode j extchar putinterval
        newtext j barcode i get put
        extchar length 1 ne {newtext j 1 add ( ) putinterval} if
        /j j extchar length add def
    } for
    /newcode newcode 0 j getinterval def
    /newtext newtext 0 j getinterval def

    % Get the result of encoding with code39
    options (dontdraw) true put
    /args newcode options //code39 exec def

    % Replace chars in /txt with chars in newtext
    includetext {
        /txt args (txt) get def
        0 1 newtext length 1 sub {
            /i exch def
            /txtentry txt i 1 add get def
            txtentry 0 newtext i 1 getinterval put
            txt i 1 add txtentry put
        } for
        args (txt) txt put
    } if
    args (opt) options put
    args

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/code39ext dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER code39ext--

% --BEGIN ENCODER code32--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear code39--
% --DESC: Italian Pharmacode
% --EXAM: 01234567
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code32 0.0 2022082100 63967 67382
%%BeginData:        102 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code39 dup /uk.co.terryburton.bwipp findresource put
begin
/code32 {

    20 dict begin

    /options exch def      % We are given an options string
    /barcode exch def      % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def  % Enable/disable code32 text
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /textxoffset 0 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    % Validate the input
    barcode length 8 ne barcode length 9 ne and {
        /bwipp.code32badLength (Italian Pharmacode must be 8 or 9 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.code32badCharacter (Italian Pharmacode must contain only digits) //raiseerror exec
        } if
    } forall

    % Calculate check digit
    /checksum 0 def
    0 1 7 {
        /i exch def
        barcode i get 48 sub i 2 mod 0 ne {2 mul} if dup 9 gt {9 sub} if
        checksum add /checksum exch def
    } for
    /checksum checksum 10 mod def
    barcode length 9 eq {
        barcode 8 get checksum 48 add ne {
            /bwipp.code32badCheckDigit (Incorrect Italian Pharmacode check digit provided) //raiseerror exec
        } if
    } if
    10 string
    dup 0 barcode putinterval
    dup 8 checksum 48 add put
    /text exch def

    % convert number from base10 to base32
    /val text cvi 32 6 string cvrs def
    /barcode 6 string def
    0 1 5 {barcode exch 48 put} for
    barcode 6 val length sub val putinterval

    % convert base32 number to specified character set
    0 1 5 {
        dup barcode exch get
        dup (AEIO) {ge {1 add} if dup} forall pop
        barcode 3 1 roll put
    } for

    % format HRI
    text 1 text 0 9 getinterval putinterval
    text 0 65 put

    % Get the result of encoding with code39
    options (dontdraw) true put
    /args barcode options //code39 exec def

    args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
    args (textxalign) (center) put
    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/code32 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER code32--

% --BEGIN ENCODER pzn--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear code39--
% --DESC: Pharmazentralnummer (PZN)
% --EXAM: 123456
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp pzn 0.0 2022082100 64062 67298
%%BeginData:        103 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code39 dup /uk.co.terryburton.bwipp findresource put
begin
/pzn {

    20 dict begin

    /options exch def      % We are given an options string
    /barcode exch def      % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def  % Enable/disable code32 text
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /textxoffset 0 def
    /height 1 def
    /pzn8 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /textxoffset textxoffset cvr def
    /height height cvr def

    % Validate the input
    pzn8 {
        barcode length 7 ne barcode length 8 ne and {
            /bwipp.pzn8badLength (PZN8 must be 7 or 8 digits) //raiseerror exec
        } if
    } {
        barcode length 6 ne barcode length 7 ne and {
            /bwipp.pzn7badLength (PZN7 must be 6 or 7 digits) //raiseerror exec
        } if
    } ifelse
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.pznBadCharacter (PZN must contain only digits) //raiseerror exec
        } if
    } forall

    % Calculate check digit
    /msglen pzn8 {9} {8} ifelse def
    /checksum 0 def
    0 1 msglen 3 sub {
        /i exch def
        barcode i get 48 sub i pzn8 {1} {2} ifelse add mul
        checksum add /checksum exch def
    } for
    /checksum checksum 11 mod def
    checksum 10 eq {
        /bwipp.pznBadInputSequence (Incorrect PZN input sequence provided) //raiseerror exec
    } if
    barcode length msglen 1 sub eq {
        barcode msglen 2 sub get checksum 48 add ne {
            /bwipp.pznBadCheckDigit (Incorrect PZN check digit provided) //raiseerror exec
        } if
    } if
    msglen string
    dup 0 45 put
    dup 1 barcode putinterval
    dup msglen 1 sub checksum 48 add put
    /msg exch def

    % Get the result of encoding with code39
    options (dontdraw) true put
    /args msg options //code39 exec def

    % format HRI
    /text msglen 5 add string def
    text 0 (PZN - ) putinterval
    text 6 msg 1 msglen 1 sub getinterval putinterval

    args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
    args (textxalign) (center) put
    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/pzn dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER pzn--

% --BEGIN ENCODER code93--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renlinear--
% --DESC: Code 93
% --EXAM: THIS IS CODE 93
% --EXOP: includetext includecheck
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code93 0.0 2022082100 68234 71403
%%BeginData:        144 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code93 {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includecheck false def  % Enable/disable checkdigit
    /includetext false def   % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 1 def
    /parse false def
    /parsefnc 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /code93 //loadctx exec

{
    /encs
    [ (131112) (111213) (111312) (111411) (121113)
      (121212) (121311) (111114) (131211) (141111)
      (211113) (211212) (211311) (221112) (221211)
      (231111) (112113) (112212) (112311) (122112)
      (132111) (111123) (111222) (111321) (121122)
      (131121) (212112) (212211) (211122) (211221)
      (221121) (222111) (112122) (112221) (122121)
      (123111) (121131) (311112) (311211) (321111)
      (112131) (113121) (211131) (121221) (312111)
      (311121) (122211) (111141) (1111411)
    ] def

    % Create a string of the available characters
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def

    /sft1 -1 def  /sft2 -2 def  /sft3 -3 def  /sft4 -4 def
} ctxdef

    % Special function characters
    /fncvals <<
        /parse parse
        /parsefnc parsefnc
        (SFT$) sft1
        (SFT%) sft2
        (SFT/) sft3
        (SFT+) sft4
    >> def
    /msg barcode fncvals //parseinput exec def
    /msglen msg length def

    includecheck {
        /sbs msglen 6 mul 25 add string def
    } {
        /sbs msglen 6 mul 13 add string def
    } ifelse
    /txt msglen array def

    % Put the start character
    sbs 0 encs 47 get putinterval

    /checksum1 0 def /checksum2 0 def
    0 1 msglen 1 sub {
        /i exch def
        % Lookup the encoding for the each barcode character
        msg i get dup 0 lt {
            42 exch sub /indx exch def
            /char ( ) def
        } {
            1 string dup 0 4 -1 roll put /char exch def
            barchars char search
            pop                                  % Discard true leaving pre
            length /indx exch def                % indx is the length of pre
            pop pop                              % Discard seek and post
        } ifelse
        /enc encs indx get def                   % Get the indxth encoding
        sbs i 6 mul 6 add enc putinterval        % Put encoded digit into sbs
        txt i [char i 9 mul 9 add textyoffset textfont textsize] put
        /checksum1 checksum1 msglen i sub 1 sub 20 mod 1 add indx mul add def
        /checksum2 checksum2 msglen i sub 15 mod 1 add indx mul add def
    } for

    includecheck {
        % Put the first checksum character
        /checksum1 checksum1 47 mod def
        /checksum2 checksum2 checksum1 add 47 mod def
        sbs msglen 6 mul 6 add encs checksum1 get putinterval
        sbs msglen 6 mul 12 add encs checksum2 get putinterval
        % Put the end character
        sbs msglen 6 mul 18 add encs 48 get putinterval
    } {
        % Put the end character
        sbs msglen 6 mul 6 add encs 48 get putinterval
    } ifelse

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/code93 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER code93--

% --BEGIN ENCODER code93ext--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renlinear code93--
% --DESC: Code 93 Extended
% --EXAM: Code93 Ext!
% --EXOP: includetext includecheck
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code93ext 0.0 2022082100 71471 71350
%%BeginData:        113 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code93 dup /uk.co.terryburton.bwipp findresource put
begin
/code93ext {

    20 dict begin

    /options exch def      % We are given an options string
    /barcode exch def      % We are given the code39extended text

    /ctx null def
    /dontdraw false def
    /includetext 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

    /code93ext //loadctx exec

    % Parse ordinals of the form ^NNN to ASCII
    /fncvals <<
        /parse parse
        /parseonly true
        /parsefnc false
    >> def
    /barcode barcode fncvals //parseinput exec def
    /barlen barcode length def
    options (parse) undef

    % Extended alphabet to non-extended alphabet
{
    /extencs
    [ (^SFT%U) (^SFT$A) (^SFT$B) (^SFT$C) (^SFT$D) (^SFT$E) (^SFT$F) (^SFT$G)
      (^SFT$H) (^SFT$I) (^SFT$J) (^SFT$K) (^SFT$L) (^SFT$M) (^SFT$N) (^SFT$O)
      (^SFT$P) (^SFT$Q) (^SFT$R) (^SFT$S) (^SFT$T) (^SFT$U) (^SFT$V) (^SFT$W)
      (^SFT$X) (^SFT$Y) (^SFT$Z) (^SFT%A) (^SFT%B) (^SFT%C) (^SFT%D) (^SFT%E)
      ( )      (^SFT/A) (^SFT/B) (^SFT/C) ($)      (%)      (^SFT/F) (^SFT/G)
      (^SFT/H) (^SFT/I) (^SFT/J) (+)      (^SFT/L) (-)      (.)      (/)
      (0)      (1)      (2)      (3)      (4)      (5)      (6)      (7)
      (8)      (9)      (^SFT/Z) (^SFT%F) (^SFT%G) (^SFT%H) (^SFT%I) (^SFT%J)
      (^SFT%V) (A)      (B)      (C)      (D)      (E)      (F)      (G)
      (H)      (I)      (J)      (K)      (L)      (M)      (N)      (O)
      (P)      (Q)      (R)      (S)      (T)      (U)      (V)      (W)
      (X)      (Y)      (Z)      (^SFT%K) (^SFT%L) (^SFT%M) (^SFT%N) (^SFT%O)
      (^SFT%W) (^SFT+A) (^SFT+B) (^SFT+C) (^SFT+D) (^SFT+E) (^SFT+F) (^SFT+G)
      (^SFT+H) (^SFT+I) (^SFT+J) (^SFT+K) (^SFT+L) (^SFT+M) (^SFT+N) (^SFT+O)
      (^SFT+P) (^SFT+Q) (^SFT+R) (^SFT+S) (^SFT+T) (^SFT+U) (^SFT+V) (^SFT+W)
      (^SFT+X) (^SFT+Y) (^SFT+Z) (^SFT%P) (^SFT%Q) (^SFT%R) (^SFT%S) (^SFT%T)
    ] def
} ctxdef

    /newcode barlen 6 mul string def
    /newtext barlen 6 mul string def
    /j 0 def /k 0 def
    0 1 barlen 1 sub {
        /i exch def
        /extchar extencs barcode i get get def
        /extlen extchar length def
        newcode j extchar putinterval
        newtext k barcode i get put
        extlen 1 ne {newtext k 1 add ( ) putinterval} if
        /j j extlen add def
        /k k extlen 1 eq {1} {2} ifelse add def
    } for
    /newcode newcode 0 j getinterval def
    /newtext newtext 0 k getinterval def

    % Get the result of encoding with code93
    options (dontdraw) true put
    options (parsefnc) true put
    /args newcode options //code93 exec def

    % Replace chars in /txt with chars in newtext
    includetext {
        /txt args (txt) get def
        0 1 newtext length 1 sub {
            /i exch def
            /txtentry txt i get def
            txtentry 0 newtext i 1 getinterval put
            txt i txtentry put
        } for
        args (txt) txt put
    } if
    args (opt) options put
    args

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/code93ext dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER code93ext--

% --BEGIN ENCODER interleaved2of5--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: Interleaved 2 of 5 (ITF)
% --EXAM: 2401234567
% --EXOP: height=0.5 includecheck includetext includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp interleaved2of5 0.0 2022082100 70795 67054
%%BeginData:        162 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/interleaved2of5 {

    20 dict begin         % Confine variables to local scope

    /options exch def               % We are given an option string
    /barcode exch def               % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includecheck false def         % Enable/disable checkdigit
    /includetext false def          % Enable/disable text
    /includecheckintext false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /interleaved2of5 //loadctx exec

    % Validate the input
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.interleaved2of5badCharacter (Interleaved 2 of 5 must contain only digits) //raiseerror exec
        } if
    } forall

    /barlen barcode length def      % Length of the code

    % Prefix 0 to barcode if length is even and including checkdigit
    % or length is odd and not including checkdigit
    barlen 2 mod 0 eq includecheck and          % even & includecheck
    barlen 2 mod 0 ne includecheck not and or { % odd  & !includecheck
        /pad barlen 1 add string def  % Create pad one bigger than barcode
        pad 0 48 put                  % Put ascii 0 at start of pad
        pad 1 barcode putinterval     % Add barcode to the end of pad
        /barcode pad def              % barcode=pad
        /barlen barlen 1 add def      % barlen++
    } if

    % Add checksum to end of barcode
    includecheck {
        /checksum 0 def
        0 1 barlen 1 sub {
            /i exch def
            i 2 mod 0 eq {
                /checksum checksum barcode i get 48 sub 3 mul add def
            } {
                /checksum checksum barcode i get 48 sub add def
            } ifelse
        } for
        /checksum 10 checksum 10 mod sub 10 mod def
        /pad barlen 1 add string def    % Create pad one bigger than barcode
        pad 0 barcode putinterval       % Add barcode to the start of pad
        pad barlen checksum 48 add put  % Add checksum to end of pad
        /barcode pad def                % barcode=pad
        /barlen barlen 1 add def        % barlen++
    } if

    % Create an array containing the character mappings
{
    /encs
    [ (11221) (21112) (12112) (22111) (11212)
      (21211) (12211) (11122) (21121) (12121)
      (1111)  (2111)
    ] def

    % Create a string of the available characters
    /barchars (0123456789) def
} ctxdef

    /sbs barlen 5 mul 8 add string def
    /txt barlen array def

    % Put the start character
    sbs 0 encs 10 get putinterval

    0 2 barlen 1 sub {
    /i exch def
        % Lookup the encodings for two consecutive barcode characters
        barcode i 1 getinterval barchars exch search
        pop                           % Discard true leaving pre
        length /indx exch def         % indx is the length of pre
        pop pop                       % Discard seek and post
        /enca encs indx get def       % Get the indxth encoding

        barcode i 1 add 1 getinterval barchars exch search
        pop                           % Discard true leaving pre
        length /indx exch def         % indx is the length of pre
        pop pop                       % Discard seek and post
        /encb encs indx get def       % Get the indxth encoding

        % Interleave the two character encodings
        /intl enca length 2 mul string def
        0 1 enca length 1 sub {
            /j exch def
            /achar enca j get def
            /bchar encb j get def
            intl j 2 mul achar put
            intl j 2 mul 1 add bchar put
        } for

        sbs i 5 mul 4 add intl putinterval   % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i 9 mul 4 add textyoffset textfont textsize] put
        includecheck includecheckintext not and barlen 2 sub i eq and {
            txt i 1 add [( ) i 1 add 9 mul 4 add textyoffset textfont textsize] put
        } {
            txt i 1 add [barcode i 1 add 1 getinterval i 1 add 9 mul 4 add textyoffset textfont textsize] put
        } ifelse
    } for

    % Put the end character
    sbs barlen 5 mul 4 add encs 11 get putinterval

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    includetext {
        /txt txt
    } if
    /barratio 2
    /spaceratio 2
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/interleaved2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER interleaved2of5--

% --BEGIN ENCODER itf14--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear interleaved2of5--
% --DESC: ITF-14
% --EXAM: 0 46 01234 56789 3
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp itf14 0.0 2022082100 66573 69883
%%BeginData:        112 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /interleaved2of5 dup /uk.co.terryburton.bwipp findresource put
begin
/itf14 {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def
    /includecheckintext true def
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset 3 def
    /height 0.5 def
    /showborder true def
    /borderwidth 4 def
    /borderleft 15 def
    /borderright 15 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def
    /borderwidth borderwidth cvr def
    /borderleft borderleft cvr def
    /borderright borderright cvr def

    % Strip spaces from the given data
    /text barcode def
    barcode dup length string exch 0 exch
    {dup 32 ne {3 copy put pop 1 add} {pop} ifelse} forall
    0 exch getinterval /barcode exch def
    /hasspace text length barcode length ne def

    % Validate the input
    barcode length 13 ne barcode length 14 ne and {
        /bwipp.itf14badLength (ITF-14 must be 13 or 14 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.itf14badCharacter (ITF-14 must contain only digits) //raiseerror exec
        } if
    } forall

    % Calculate ITF checksum and add to end of barcode
    /checksum 0 def
    0 1 12 {
        /i exch def
        /checksum checksum barcode i get 48 sub i 2 mod 0 eq {3 mul} if add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 14 eq {
        barcode 13 get checksum 48 add ne {
            /bwipp.itf14badCheckDigit (Incorrect ITF-14 check digit provided) //raiseerror exec
        } if
    } {
        14 string
        dup 0 barcode putinterval
        dup 13 checksum 48 add put
        /barcode exch def
        text length hasspace {2} {1} ifelse add string
        dup dup length 2 sub ( ) putinterval
        dup dup length 1 sub checksum 48 add put
        dup 0 text putinterval
        /text exch def
    } ifelse

    % Get the result of encoding with interleaved2of5
    options (dontdraw) true put
    options (showborder) showborder put
    options (borderwidth) borderwidth put
    options (borderleft) borderleft put
    options (borderright) borderright put
    options (height) height put
    options (textyoffset) textyoffset put
    /args barcode options //interleaved2of5 exec def

    args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
    args (textxalign) (center) put
    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/itf14 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER itf14--

% --BEGIN ENCODER identcode--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear interleaved2of5--
% --DESC: Deutsche Post Identcode
% --EXAM: 563102430313
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp identcode 0.0 2022082100 62988 66378
%%BeginData:         94 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /interleaved2of5 dup /uk.co.terryburton.bwipp findresource put
begin
/identcode {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    % Validate the input
    barcode length 11 ne barcode length 12 ne and {
        /bwipp.identcodeBadLength (Deutsche Post Identcode must be 11 or 12 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.identcodeBadCharacter (Deutsche Post Identcode must contain only digits) //raiseerror exec
        } if
    } forall

    % Calculate checksum and add to end of barcode
    /checksum 0 def
    0 1 10 {
        /i exch def
        /checksum checksum barcode i get 48 sub i 2 mod 0 eq {4 mul} {9 mul} ifelse add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 12 eq {
        barcode 11 get checksum 48 add ne {
            /bwipp.identcodeBadCheckDigit (Incorrect Deutsche Post Identcode check digit provided) //raiseerror exec
        } if
    } if
    12 string
    dup 0 barcode putinterval
    dup 11 checksum 48 add put
    /barcode exch def

    % Compose the human readable text
    /text (  .       .     ) 16 string copy def
    text  0 barcode  0 2 getinterval putinterval
    text  3 barcode  2 3 getinterval putinterval
    text  7 barcode  5 3 getinterval putinterval
    text 11 barcode  8 3 getinterval putinterval
    text 15 barcode 11 1 getinterval putinterval

    % Get the result of encoding with interleaved2of5
    options (dontdraw) true put
    options (includecheck) false put
    /args barcode options //interleaved2of5 exec def

    args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
    args (textxalign) (center) put
    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/identcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER identcode--

% --BEGIN ENCODER leitcode--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear interleaved2of5--
% --DESC: Deutsche Post Leitcode
% --EXAM: 21348075016401
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp leitcode 0.0 2022082100 62980 66374
%%BeginData:         94 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /interleaved2of5 dup /uk.co.terryburton.bwipp findresource put
begin
/leitcode {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    % Validate the input
    barcode length 13 ne barcode length 14 ne and {
        /bwipp.leitcodeBadLength (Deutsche Post Leitcode must be 13 or 14 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.leitcodeBadCharacter (Deutsche Post Leitcode must contain only digits) //raiseerror exec
        } if
    } forall

    % Calculate checksum and add to end of barcode
    /checksum 0 def
    0 1 12 {
        /i exch def
        /checksum checksum barcode i get 48 sub i 2 mod 0 eq {4 mul} {9 mul} ifelse add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 14 eq {
        barcode 13 get checksum 48 add ne {
            /bwipp.leitcodeBadCheckDigit (Incorrect Deutsche Post Leitcode check digit provided) //raiseerror exec
        } if
    } if
    14 string
    dup 0 barcode putinterval
    dup 13 checksum 48 add put
    /barcode exch def

    % Compose the human readable text
    /text (     .   .   .    ) 18 string copy def
    text  0 barcode  0 5 getinterval putinterval
    text  6 barcode  5 3 getinterval putinterval
    text 10 barcode  8 3 getinterval putinterval
    text 14 barcode 11 2 getinterval putinterval
    text 17 barcode 13 1 getinterval putinterval

    % Get the result of encoding with interleaved2of5
    options (dontdraw) true put
    options (includecheck) false put
    /args barcode options //interleaved2of5 exec def

    args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
    args (textxalign) (center) put
    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/leitcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER leitcode--

% --BEGIN ENCODER databaromni--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear renmatrix--
% --DESC: GS1 DataBar Omnidirectional
% --EXAM: (01)24012345678905
% --EXOP:
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databaromni 0.0 2022082100 115183 110835
%%BeginData:        436 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
20 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 /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/databaromni {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /height 33 72 div def
    /linkage false def
    /format (omni) def
    /barxmult 33 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

    format (truncated) eq {/height 13 72 div def} if
    /height height cvr def
    /barxmult barxmult cvi def

    /databaromni //loadctx exec

    % Validate the input
    barcode 0 4 getinterval (\(01\)) ne {
        /bwipp.databaromniBadAI (GS1 DataBar Omnidirectional must begin with (01) application identifier) //raiseerror exec
    } if
    barcode length 17 ne barcode length 18 ne and {
        /bwipp.databaromniBadLength (GS1 DataBar Omnidirectional must be 13 or 14 digits) //raiseerror exec
    } if
    barcode 4 barcode length 4 sub getinterval {
        dup 48 lt exch 57 gt or {
            /bwipp.databaromniBadCharacter (GS1 DataBar Omnidirectional must contain only digits) //raiseerror exec
        } if
    } forall

    % Calculate checksum and add to end of barcode
    /checksum 0 def
    0 1 12 {
        /i exch def
        /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 18 eq {
        barcode 17 get checksum 48 add ne {
            /bwipp.databaromniBadCheckDigit (Incorrect GS1 DataBar Omnidirectional check digit provided) //raiseerror exec
        } if
    } if
    18 string
    dup 0 barcode putinterval
    dup 17 checksum 48 add put
    /barcode exch def

    % Create the human readable text
    /txt barcode length array def
    0 1 barcode length 1 sub {
        /i exch def
        txt i [barcode i 1 getinterval 0 0 () 0] put
    } for

    /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

    /binval [
        linkage {1} {0} ifelse
        barcode 4 13 getinterval {48 sub} forall
    ] def

    0 1 12 {
        /i exch def
        binval i 1 add 2 copy get binval i get 4537077 mod 10 mul add put
        binval i binval i get 4537077 idiv put
    } for
    /right binval 13 get 4537077 mod def
    binval 13 2 copy get 4537077 idiv put

    /left 0 def
    /i true def
    0 1 13 {
        /j exch def
        binval j get
        dup 0 eq i and {
            pop
        } {
            /i false def
            /left left 3 -1 roll 10 13 j sub exp cvi mul add def
        } ifelse
    } for

    /d1 left 1597 idiv def
    /d2 left 1597 mod def
    /d3 right 1597 idiv def
    /d4 right 1597 mod def

{
    /tab164 [
        160   0     12 4   8 1  161   1
        960   161   10 6   6 3  80   10
        2014  961   8  8   4 5  31   34
        2714  2015  6  10  3 6  10   70
        2840  2715  4  12  1 8  1    126
    ] def

    /tab154 [
        335   0     5  10  2 7  4   84
        1035  336   7  8   4 5  20  35
        1515  1036  9  6   6 3  48  10
        1596  1516  11 4   8 1  81  1
    ] def
} ctxdef

    /i 0 def {
        d1 tab164 i get le {
            tab164 i 1 add 7 getinterval {} forall
            /d1te exch def /d1to exch def
            /d1mwe exch def /d1mwo exch def
            /d1ele exch def /d1elo exch def
            /d1gs exch def
            exit
        } if
        /i i 8 add def
    } loop

    /i 0 def {
        d2 tab154 i get le {
            tab154 i 1 add 7 getinterval {} forall
            /d2te exch def /d2to exch def
            /d2mwe exch def /d2mwo exch def
            /d2ele exch def /d2elo exch def
            /d2gs exch def
            exit
        } if
        /i i 8 add def
    } loop

    /i 0 def {
        d3 tab164 i get le {
            tab164 i 1 add 7 getinterval {} forall
            /d3te exch def /d3to exch def
            /d3mwe exch def /d3mwo exch def
            /d3ele exch def /d3elo exch def
            /d3gs exch def
            exit
        } if
        /i i 8 add def
    } loop

    /i 0 def {
        d4 tab154 i get le {
            tab154 i 1 add 7 getinterval {} forall
            /d4te exch def /d4to exch def
            /d4mwe exch def /d4mwo exch def
            /d4ele exch def /d4elo exch def
            /d4gs exch def
            exit
        } if
        /i i 8 add def
    } loop

    /d1wo d1 d1gs sub d1te idiv d1elo d1mwo 4 false getRSSwidths def
    /d1we d1 d1gs sub d1te mod  d1ele d1mwe 4 true  getRSSwidths def
    /d2wo d2 d2gs sub d2to mod  d2elo d2mwo 4 true  getRSSwidths def
    /d2we d2 d2gs sub d2to idiv d2ele d2mwe 4 false getRSSwidths def
    /d3wo d3 d3gs sub d3te idiv d3elo d3mwo 4 false getRSSwidths def
    /d3we d3 d3gs sub d3te mod  d3ele d3mwe 4 true  getRSSwidths def
    /d4wo d4 d4gs sub d4to mod  d4elo d4mwo 4 true  getRSSwidths def
    /d4we d4 d4gs sub d4to idiv d4ele d4mwe 4 false getRSSwidths def

    /d1w 8 array def
    0 1 3 {
        /i exch def
        d1w i 2 mul d1wo i get put
        d1w i 2 mul 1 add d1we i get put
    } for

    /d2w 8 array def
    0 1 3 {
        /i exch def
        d2w 7 i 2 mul sub d2wo i get put
        d2w 6 i 2 mul sub d2we i get put
    } for

    /d3w 8 array def
    0 1 3 {
        /i exch def
        d3w 7 i 2 mul sub d3wo i get put
        d3w 6 i 2 mul sub d3we i get put
    } for

    /d4w 8 array def
    0 1 3 {
        /i exch def
        d4w i 2 mul d4wo i get put
        d4w i 2 mul 1 add d4we i get put
    } for

    /widths [
        d1w {} forall
        d2w {} forall
        d3w {} forall
        d4w {} forall
    ] def

{
    /checkweights [
        1   3   9   27  2   6   18  54
        58  72  24  8   29  36  12  4
        74  51  17  32  37  65  48  16
        64  34  23  69  49  68  46  59
    ] def

    /checkwidths [
        3 8 2 1 1   3 5 5 1 1   3 3 7 1 1
        3 1 9 1 1   2 7 4 1 1   2 5 6 1 1
        2 3 8 1 1   1 5 7 1 1   1 3 9 1 1
    ] def
} ctxdef

    /checksum 0 def
    0 1 31 {
        /i exch def
        /checksum checksum widths i get checkweights i get mul add def
    } for
    /checksum checksum 79 mod def
    checksum 8 ge {/checksum checksum 1 add def} if
    checksum 72 ge {/checksum checksum 1 add def} if
    /checklt checkwidths checksum 9 idiv 5 mul 5 getinterval def
    /checkrtrev checkwidths checksum 9 mod 5 mul 5 getinterval def
    /checkrt 5 array def
    0 1 4 {
        /i exch def
        checkrt i checkrtrev 4 i sub get put
    } for

    % Stacked format
    format (omni) eq format (truncated) eq or {  % linear

        /sbs [
            1 d1w {} forall checklt {} forall d2w {} forall
            d4w {} forall checkrt {} forall d3w {} forall 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]
        /txt txt
        /textxalign (center)
        /opt options
        >>

        dontdraw not //renlinear if

    } {  % 2D - stacked or stackedomni

        /top [ 1 1 d1w {} forall checklt {} forall d2w {} forall 1 1 0 ] def
        /bot [ 1 1 d4w {} forall checkrt {} forall d3w {} forall 1 1 0 ] def
        0 2 24 {
            /i exch def
            top i get {0} repeat
            top i 1 add get {1} repeat
        } for
        50 array astore /top exch def
        0 2 24 {
            /i exch def
            bot i get {1} repeat
            bot i 1 add get {0} repeat
        } for
        50 array astore /bot exch def

        % Stacked
        format (stacked) eq {
            /sep 50 array def
            sep 0 0 put
            1 1 49 {
                /i exch def
                top i get bot i get eq {
                    sep i 1 top i get sub put
                } {
                    sep i 1 sep i 1 sub get sub put
                } ifelse
            } for
            sep 0  [ 0 0 0 0 ] putinterval
            sep 46 [ 0 0 0 0 ] putinterval
            /pixs [
                5 {top aload pop} repeat
                sep aload pop
                7 {bot aload pop} repeat
            ] def
            /pixy pixs length 50 idiv def
        } if

        % Stacked omnidirectional
        format (stackedomni) eq {
            /sep1 [ top {1 exch sub} forall ] def
            sep1 0  [ 0 0 0 0 ] putinterval
            sep1 46 [ 0 0 0 0 ] putinterval
            18 1 30 {
                /i exch def
                top i get 0 eq {
                    top i 1 sub get 1 eq {
                        1
                    } {
                        sep1 i 1 sub get 0 eq {1} {0} ifelse
                    } ifelse
                } {
                    0
                } ifelse
                sep1 exch i exch put
            } for
            /sep2 [ 0 0 0 0 21 { 0 1 } repeat 0 0 0 0 ] def
            /sep3 [ bot {1 exch sub} forall ] def
            sep3 0  [ 0 0 0 0 ] putinterval
            sep3 46 [ 0 0 0 0 ] putinterval
            19 1 31 {
                /i exch def
                bot i get 0 eq {
                    bot i 1 sub get 1 eq {
                        1
                    } {
                        sep3 i 1 sub get 0 eq {1} {0} ifelse
                    } ifelse
                } {
                    0
                } ifelse
                sep3 exch i exch put
            } for
            /f3 [1 1 1 1 1 1 1 1 1 0 1 1 1] def
            true 0 1 12 {dup bot exch 19 add get exch f3 exch get eq and} for {
                % Right shifted module for value 3 finder
                sep3 19 [ 0 0 0 0 0 0 0 0 0 0 1 0 0 ] putinterval
            } if
            /pixs [
                barxmult {top aload pop} repeat
                sep1 aload pop
                sep2 aload pop
                sep3 aload pop
                barxmult {bot aload pop} repeat
            ] def
            /pixy pixs length 50 idiv def
        } if

        % Return the arguments
        <<
        /ren //renmatrix
        /pixs pixs
        /pixx 50
        /pixy pixy
        /height pixy 72 div
        /width 50 72 div
        /opt options
        >>

        dontdraw not //renmatrix if

    } ifelse

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/databaromni dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databaromni--

% --BEGIN ENCODER databarstacked--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear renmatrix databaromni--
% --DESC: GS1 DataBar Stacked
% --EXAM: (01)24012345678905
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp databarstacked 0.0 2022082100 67310 63705
%%BeginData:         76 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /databaromni dup /uk.co.terryburton.bwipp findresource put
begin
/databarstacked {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw 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

    % Validate the input
    barcode 0 4 getinterval (\(01\)) ne {
        /bwipp.databarstackedBadAI (GS1 DataBar Stacked must begin with (01) application identifier) //raiseerror exec
    } if
    barcode length 17 ne barcode length 18 ne and {
        /bwipp.databarstackedBadLength (GS1 DataBar Stacked must be 13 or 14 digits) //raiseerror exec
    } if
    barcode 4 barcode length 4 sub getinterval {
        dup 48 lt exch 57 gt or {
            /bwipp.databarstackedBadCharacter (GS1 DataBar Stacked must contain only digits) //raiseerror exec
        } if
    } forall

    % Calculate checksum and add to end of barcode
    /checksum 0 def
    0 1 12 {
        /i exch def
        /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 18 eq {
        barcode 17 get checksum 48 add ne {
            /bwipp.databarstackedBadCheckDigit (Incorrect GS1 DataBar Stacked check digit provided) //raiseerror exec
        } if
    } if
    18 string
    dup 0 barcode putinterval
    dup 17 checksum 48 add put
    /barcode exch def

    % Get the result of encoding with databaromni with format=stacked
    options (dontdraw) true put
    options (format) (stacked) put

    /args barcode options //databaromni exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/databarstacked dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databarstacked--

% --BEGIN ENCODER databarstackedomni--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear renmatrix databaromni--
% --DESC: GS1 DataBar Stacked Omnidirectional
% --EXAM: (01)24012345678905
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp databarstackedomni 0.0 2022082100 67410 63785
%%BeginData:         76 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /databaromni dup /uk.co.terryburton.bwipp findresource put
begin
/databarstackedomni {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw 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

    % Validate the input
    barcode 0 4 getinterval (\(01\)) ne {
        /bwipp.databarstackedomniBadAI (GS1 DataBar Stacked Omnidirectional must begin with (01) application identifier) //raiseerror exec
    } if
    barcode length 17 ne barcode length 18 ne and {
        /bwipp.databarstackedomniBadLength (GS1 DataBar Stacked Omnidirectional must be 13 or 14 digits) //raiseerror exec
    } if
    barcode 4 barcode length 4 sub getinterval {
        dup 48 lt exch 57 gt or {
            /bwipp.databarstackedomniBadCharacter (GS1 DataBar Stacked Omnidirectional must contain only digits) //raiseerror exec
        } if
    } forall

    % Calculate checksum and add to end of barcode
    /checksum 0 def
    0 1 12 {
        /i exch def
        /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 18 eq {
        barcode 17 get checksum 48 add ne {
            /bwipp.databarstackedomniBadCheckDigit (Incorrect GS1 DataBar Stacked Omnidirectional check digit provided) //raiseerror exec
        } if
    } if
    18 string
    dup 0 barcode putinterval
    dup 17 checksum 48 add put
    /barcode exch def

    % Get the result of encoding with databaromni with format=stackedomni
    options (dontdraw) true put
    options (format) (stackedomni) put

    /args barcode options //databaromni exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/databarstackedomni dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databarstackedomni--

% --BEGIN ENCODER databartruncated--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear renmatrix databaromni--
% --DESC: GS1 DataBar Truncated
% --EXAM: (01)24012345678905
% --EXOP:
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databartruncated 0.0 2022082100 67336 63721
%%BeginData:         76 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /databaromni dup /uk.co.terryburton.bwipp findresource put
begin
/databartruncated {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw 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

    % Validate the input
    barcode 0 4 getinterval (\(01\)) ne {
        /bwipp.databartruncatedBadAI (GS1 DataBar Truncated must begin with (01) application identifier) //raiseerror exec
    } if
    barcode length 17 ne barcode length 18 ne and {
        /bwipp.databartruncatedBadLength (GS1 DataBar Truncated must be 13 or 14 digits) //raiseerror exec
    } if
    barcode 4 barcode length 4 sub getinterval {
        dup 48 lt exch 57 gt or {
            /bwipp.databartruncatedBadCharacter (GS1 DataBar Truncated must contain only digits) //raiseerror exec
        } if
    } forall

    % Calculate checksum and add to end of barcode
    /checksum 0 def
    0 1 12 {
        /i exch def
        /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 18 eq {
        barcode 17 get checksum 48 add ne {
            /bwipp.databartruncatedBadCheckDigit (Incorrect GS1 DataBar Truncated check digit provided) //raiseerror exec
        } if
    } if
    18 string
    dup 0 barcode putinterval
    dup 17 checksum 48 add put
    /barcode exch def

    % Get the result of encoding with databaromni with format=truncated
    options (dontdraw) true put
    options (format) (truncated) put

    /args barcode options //databaromni exec def

    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/databartruncated dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databartruncated--

% --BEGIN ENCODER databarlimited--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: GS1 DataBar Limited
% --EXAM: (01)15012345678907
% --EXOP:
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp databarlimited 0.0 2022082100 90886 86535
%%BeginData:        291 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
20 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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/databarlimited {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /height 10 72 div def
    /linkage 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

    /height height cvr def

    /databarlimited //loadctx exec

    % Validate the input
    barcode 0 4 getinterval (\(01\)) ne {
        /bwipp.databarlimitedBadAI (GS1 DataBar Limited must begin with (01) application identifier) //raiseerror exec
    } if
    barcode length 17 ne barcode length 18 ne and {
        /bwipp.databarlimitedBadLength (GS1 DataBar Limited must be 13 or 14 digits) //raiseerror exec
    } if
    barcode 4 get dup 48 lt exch 49 gt or {
        /bwipp.databarlimitedBadStartDigit (GS1 DataBar Limited must begin with 0 or 1) //raiseerror exec
    } if
    barcode 5 barcode length 5 sub getinterval {
        dup 48 lt exch 57 gt or {
            /bwipp.databarlimitedBadCharacter (GS1 DataBar Limited must contain only digits) //raiseerror exec
        } if
    } forall

    % Calculate checksum and add to end of barcode
    /checksum 0 def
    0 1 12 {
        /i exch def
        /checksum checksum barcode i 4 add get 48 sub i 2 mod 0 eq {3 mul} if add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    barcode length 18 eq {
        barcode 17 get checksum 48 add ne {
            /bwipp.databarlimitedBadCheckDigit (Incorrect GS1 DataBar Limited check digit provided) //raiseerror exec
        } if
    } if
    18 string
    dup 0 barcode putinterval
    dup 17 checksum 48 add put
    /barcode exch def

    % Strip the AI and optional check digit
{
    /linkval [ 2 0 1 5 1 3 3 5 3 1 0 9 6 ] def
} ctxdef
    /binval [
        barcode 4 13 getinterval {48 sub} forall
    ] def
    linkage {
        0 1 binval length 1 sub {
            /i exch def
            binval i binval i get linkval i get add put
        } for
    } if

    % Create the human readable text
    /txt barcode length array def
    0 1 barcode length 1 sub {
        /i exch def
        txt i [barcode i 1 getinterval 0 0 () 0] put
    } for

    /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

    0 1 11 {
        /i exch def
        binval i 1 add 2 copy get binval i get 2013571 mod 10 mul add put
        binval i binval i get 2013571 idiv put
    } for
    /d2 binval 12 get 2013571 mod def
    binval 12 2 copy get 2013571 idiv put

    /d1 0 def
    /i true def
    0 1 12 {
        /j exch def
        binval j get
        dup 0 eq i and {
            pop
        } {
            /i false def
            /d1 d1 3 -1 roll 10 12 j sub exp cvi mul add def
        } ifelse
    } for

{
    /tab267 [
        183063   0        17 9   6 3  6538   28
        820063   183064   13 13  5 4  875    728
        1000775  820064   9  17  3 6  28     6454
        1491020  1000776  15 11  5 4  2415   203
        1979844  1491021  11 15  4 5  203    2408
        1996938  1979845  19 7   8 1  17094  1
        2013570  1996939  7  19  1 8  1      16632
    ] def
} ctxdef

    /i 0 def {
        d1 tab267 i get le {
            tab267 i 1 add 7 getinterval {} forall
            /d1te exch def /d1to exch def
            /d1mwe exch def /d1mwo exch def
            /d1ele exch def /d1elo exch def
            /d1gs exch def
            exit
        } if
        /i i 8 add def
    } loop

    /i 0 def {
        d2 tab267 i get le {
            tab267 i 1 add 7 getinterval {} forall
            /d2te exch def /d2to exch def
            /d2mwe exch def /d2mwo exch def
            /d2ele exch def /d2elo exch def
            /d2gs exch def
            exit
        } if
        /i i 8 add def
    } loop

    /d1wo d1 d1gs sub d1te idiv d1elo d1mwo 7 false getRSSwidths def
    /d1we d1 d1gs sub d1te mod  d1ele d1mwe 7 true  getRSSwidths def
    /d2wo d2 d2gs sub d2te idiv d2elo d2mwo 7 false getRSSwidths def
    /d2we d2 d2gs sub d2te mod  d2ele d2mwe 7 true  getRSSwidths def

    /d1w 14 array def
    0 1 6 {
        /i exch def
        d1w i 2 mul d1wo i get put
        d1w i 2 mul 1 add d1we i get put
    } for

    /d2w 14 array def
    0 1 6 {
        /i exch def
        d2w i 2 mul d2wo i get put
        d2w i 2 mul 1 add d2we i get put
    } for

    /widths [
        d1w {} forall
        d2w {} forall
    ] def

{
    /checkweights [
        1  3  9  27 81 65 17 51 64 14 42 37 22 66
        20 60 2  6  18 54 73 41 34 13 39 28 84 74
    ] def

    /checkseq [
        0 1 43 {} for
        45 52 57
        63 1 66 {} for
        73 1 79 {} for
        82
        126 1 130 {} for
        132
        141 1 146 {} for
        210 1 217 {} for
        220
        316 1 320 {} for
        322 323
        326 337
    ] def
} ctxdef

    /checksum 0 def
    0 1 27 {
        /i exch def
        /checksum checksum widths i get checkweights i get mul add def
    } for
    /checksum checksum 89 mod def
    /seq checkseq checksum get def
    /swidths seq 21 idiv 8 3 6 false getRSSwidths def
    /bwidths seq 21 mod  8 3 6 false getRSSwidths def

    /checkwidths [0 0 0 0 0 0 0 0 0 0 0 0 1 1] def
    0 1 5 {
        /i exch def
        checkwidths i 2 mul swidths i get put
        checkwidths i 2 mul 1 add bwidths i get put
    } for

    /sbs [
        1 d1w {} forall checkwidths {} forall d2w {} forall 1 1 5
    ] def

    % Return the arguments
    <<
    /ren //renlinear
    /sbs sbs
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    /txt txt
    /textxalign (center)
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/databarlimited dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databarlimited--

% --BEGIN ENCODER databarexpanded--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix--
% --DESC: GS1 DataBar Expanded
% --EXAM: (01)95012345678903(3103)000123
% --EXOP:
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databarexpanded 0.0 2022082100 246206 245007
%%BeginData:        863 ASCII Lines
/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 /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

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /parse false def
    /dontlint false def
    /lintreqs true def
    /dontdraw false def
    /height 34 72 div def
    /format (expanded) def
    /segments -1 def
    /linkage false def
    /barxmult 34 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

    /height height cvr def
    /segments segments cvi def
    /barxmult barxmult cvi def

    /databarexpanded //loadctx exec

    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
        [ 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 {} forall
                /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 {{} forall} 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 {} forall
            /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 {} forall
                pos 2 mod 0 eq {fxw pos 2 idiv get {} forall} 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 {} forall
                i 2 mod 0 eq {fxw i 2 idiv get {} forall} if
            } for
            1 1
        ] def

        options (parse) undef

        <<
        /ren //renlinear
        /sbs sbs
        /bhs [sbs length 1 add 2 idiv {height} repeat]
        /bbs [sbs length 1 add 2 idiv {0} repeat]
        /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

        options (parse) undef

        <<
        /ren //renmatrix
        /pixs pixs
        /pixx pixx
        /pixy pixs length pixx idiv
        /height pixs length pixx idiv 72 div
        /width pixx 72 div
        /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
%%EndData
%%EndResource
% --END ENCODER databarexpanded--

% --BEGIN ENCODER databarexpandedstacked--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix databarexpanded--
% --DESC: GS1 DataBar Expanded Stacked
% --EXAM: (01)95012345678903(3103)000123
% --EXOP: segments=4
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databarexpandedstacked 0.0 2022082100 72659 72245
%%BeginData:         46 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /databarexpanded dup /uk.co.terryburton.bwipp findresource put
begin
/databarexpandedstacked {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw 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

    % Get the result of encoding with databarexpanded with format=expandedstacked
    options (dontdraw) true put
    options (format) (expandedstacked) put

    /args barcode options //databarexpanded exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/databarexpandedstacked dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databarexpandedstacked--

% --BEGIN ENCODER gs1northamericancoupon--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix databarexpanded databarexpandedstacked--
% --DESC: GS1 North American Coupon
% --EXAM: (8110)106141416543213500110000310123196000
% --EXOP: includetext segments=8
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp gs1northamericancoupon 0.0 2022082100 84394 87545
%%BeginData:        105 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /gs1process dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /databarexpandedstacked dup /uk.co.terryburton.bwipp findresource put
begin
/gs1northamericancoupon {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def  % Enable/disable coupon text
    /coupontextfont /Helvetica def
    /coupontextsize 9 def
    /coupontextxoffset (unset) def
    /coupontextyoffset (unset) def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    /coupontextfont coupontextfont cvlit def
    /coupontextsize coupontextsize cvr def
    coupontextxoffset (unset) ne {/coupontextxoffset coupontextxoffset cvr def} if
    coupontextyoffset (unset) ne {/coupontextyoffset coupontextyoffset cvr def} if

    barcode /ai //gs1process exec
    pop
    /vals exch def
    /ais exch def

    % Validate the AI structure
    ais length 1 ne {
      /bwipp.gs1northamericancouponBadAIStructure (A GS1 North American Coupon should consist of a single AI (8110)) //raiseerror exec
    } if
    ais 0 get (8110) ne {
      /bwipp.gs1northamericancouponBadAIStructure (A GS1 North American Coupon should consist of a single AI (8110)) //raiseerror exec
    } if

    % Parse out the Company Prefix and Offer Code
    /val vals 0 get def
    /vli val 0 get 48 sub def
    vli 0 lt vli 6 gt or {
      /bwipp.gs1northamericancouponBadVLI (The AI (8110) data should start with a Company Prefix length indicator in the range 0 to 6) //raiseerror exec
    } if
    /gcp val 1 vli 6 add getinterval def
    /cod val vli 7 add 6 getinterval def
    /coupontext gcp length 7 add string def
    coupontext 0 gcp putinterval
    coupontext gcp length (-) putinterval
    coupontext gcp length 1 add cod putinterval

    % Get the result of encoding with databarexpandedstacked
    options (parse) undef
    options (dontdraw) true put

    /args barcode options //databarexpandedstacked exec def

    % Add the coupon text
    includetext {
        coupontextxoffset (unset) eq {
            /coupontextxoffset 0 def
        } if
        coupontextyoffset (unset) eq {
            /coupontextyoffset args (height) get 72 mul 3 add def
        } if
        args (txt) known {
            /txt args (txt) get def
            /newtxt txt length 1 add array def
            newtxt 0 txt putinterval
            newtxt newtxt length 1 sub [coupontext coupontextxoffset coupontextyoffset coupontextfont coupontextsize] put
            args (txt) newtxt put
        } {
            args (txt) [ [coupontext coupontextxoffset coupontextyoffset coupontextfont coupontextsize] ] put
        } ifelse
    } if

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/gs1northamericancoupon dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER gs1northamericancoupon--

% --BEGIN ENCODER pharmacode--
% --REQUIRES preamble raiseerror renlinear--
% --DESC: Pharmaceutical Binary Code
% --EXAM: 117480
% --EXOP: showborder
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp pharmacode 0.0 2022082100 55057 54908
%%BeginData:         94 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/pharmacode {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /height 8 2.835 mul 72 div def
    /nwidth 0.5 2.835 mul def
    /wwidth 1.5 2.835 mul def
    /swidth 1.0 2.835 mul 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

    /height height cvr def
    /nwidth nwidth cvr def
    /wwidth wwidth cvr def
    /swidth swidth cvr def

    % Validate the input
    barcode length 1 lt barcode length 6 gt or {
        /bwipp.pharmacodeBadLength (Pharmacode must be 1 to 6 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.pharmacodeBadCharacter (Pharmacode must contain only digits) //raiseerror exec
        } if
    } forall
    barcode cvi dup 3 lt exch 131070 gt or {
        /bwipp.pharmacodeBadValue (Pharmacode value must be between 3 and 131070) //raiseerror exec
    } if

    % Create the human readable text
    /txt barcode length array def
    0 1 barcode length 1 sub {
        /i exch def
        txt i [barcode i 1 getinterval 0 0 () 0] put
    } for

    % Convert the integer into the paramacode string
    /barcode barcode cvi 1 add 2 17 string cvrs def
    /barcode barcode 1 barcode length 1 sub getinterval def

    /barlen barcode length def  % Length of the code
    /sbs barlen 2 mul array def

    0 1 barlen 1 sub {
        /i exch def
        /enc barcode i 1 getinterval def
        enc (0) eq {
            sbs i 2 mul nwidth put
        } {
            sbs i 2 mul wwidth put
        } ifelse
        sbs i 2 mul 1 add swidth put
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /sbs sbs
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    /txt txt
    /textxalign (center)
    /opt options
    >>

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/pharmacode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER pharmacode--

% --BEGIN ENCODER pharmacode2--
% --REQUIRES preamble raiseerror renlinear--
% --DESC: Two-track Pharmacode
% --EXAM: 117480
% --EXOP: includetext showborder
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp pharmacode2 0.0 2022082100 55888 55662
%%BeginData:         99 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/pharmacode2 {

    20 dict begin

    /options exch def           % We are given an option string
    /barcode exch def           % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def      % Enable/disable text
    /height 4 def               % Height of short bars in millimetres

    % 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

    /height height cvr def

    % Validate the input
    barcode length 1 lt barcode length 8 gt or {
        /bwipp.pharmacode2BadLength (Two-track Pharmacode must be 1 to 6 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.pharmacode2badCharacter (Two-track Pharmacode must contain only digits) //raiseerror exec
        } if
    } forall
    barcode cvi dup 4 lt exch 64570080 gt or {
        /bwipp.pharmacode2badValue (Two-track Pharmacode value must be between 4 and 64570080) //raiseerror exec
    } if

    % Create the human readable text
    /txt barcode length array def
    0 1 barcode length 1 sub {
        /i exch def
        txt i [barcode i 1 getinterval 0 0 () 0] put
    } for

    /encstr 16 string def
    /sbs 32 array def
    /bar 1 25.4 div height mul def     % bar height (mm)
    /spc 1 25.4 div 72 mul def         % bar width & spacing (1mm)

    % Convert number into a base3 representation
    /i 15 def
    /val barcode cvi def
    {  % loop
        val 0 eq {exit} if
        val 3 mod dup
        [3 1 2] exch get val exch sub 3 idiv /val exch def
        encstr i [2 0 1] 4 -1 roll get put
        /i i 1 sub def
    } loop
    /encstr encstr i 1 add 15 i sub getinterval def

    % Generate the bar pattern
    /bhs encstr length array def
    /bbs encstr length array def
    0 1 encstr length 1 sub {
        /i exch def
        encstr i get dup
        bhs i bar [1 1 2] 5 -1 roll get mul put
        bbs i [0 bar 0] 4 -1 roll get put
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /bhs bhs
    /bbs bbs
    /sbs [encstr length 2 mul {spc} repeat]
    /txt txt
    /textxalign (center)
    /textyoffset 4
    /opt options
    >>

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/pharmacode2 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER pharmacode2--

% --BEGIN ENCODER code2of5--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: Code 25
% --EXAM: 01234567
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code2of5 0.0 2022082100 73003 69031
%%BeginData:        165 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code2of5 {

    20 dict begin                 % Confine variable to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includecheck false def
    /validatecheck false def
    /includetext false def   % Enable/disable text
    /includecheckintext false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 1 def
    /version (industrial) 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /code2of5 //loadctx exec

    % Validate input
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.code2of5badCharacter (Code 25 must contain only digits) //raiseerror exec
        } if
    } forall

    /barlen barcode length validatecheck {1 sub} if def

    /checksum 0 def
    0 1 barlen 1 sub {
        /i exch def
        /checksum checksum barcode i get 48 sub barlen i sub 2 mod 0 ne {3 mul} if add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    validatecheck {
        barcode barlen get checksum 48 add ne {
            /bwipp.code2of5badCheckDigit (Incorrect Code 25 check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
        /includecheck true def
    } if

    % Create an array containing the character mappings
{
    /versions <<
    /industrial
        [ (1111313111) (3111111131) (1131111131) (3131111111)
          (1111311131) (3111311111) (1131311111) (1111113131)
          (3111113111) (1131113111) (313111)     (31113)
        ]
    /iata
        [ (1111313111) (3111111131) (1131111131) (3131111111)
          (1111311131) (3111311111) (1131311111) (1111113131)
          (3111113111) (1131113111) (1111)       (311)
        ]
    /matrix
        [ (113311) (311131) (131131) (331111) (113131) (313111)
          (133111) (111331) (311311) (131311) (311111) (31111)
        ]
    /coop
        [ (331111) (111331) (113131) (113311) (131131) (131311)
          (133111) (311131) (311311) (313111) (3131)   (133)
        ]
    /datalogic
        [ (113311) (311131) (131131) (331111) (113131) (313111)
          (133111) (111331) (311311) (131311) (1111)   (311)
        ]
    >> def
} ctxdef

    versions version known not {
        /bwipp.code2of5badVersion (Unrecognised Code 25 version) //raiseerror exec
    } if
    /encs versions version get def

    /cs encs 0 get length def
    /cw 0 encs 0 get {48 sub add} forall def
    /ss encs 10 get length def
    /sw 0 encs 10 get {48 sub add} forall def
    /es encs 11 get length def

    % Create a string of the available characters
{
    /barchars (0123456789) def
} ctxdef

    /sbs barlen includecheck {1 add} if cs mul ss add es add string def
    /txt barlen includecheck {1 add} if array def

    % Put the start character
    sbs 0 encs 10 get putinterval
    0 1 barlen 1 sub {
        /i exch def
        % Lookup the encoding for the each barcode character
        barcode i 1 getinterval barchars exch search
        pop                                 % Discard true leaving pre
        length /indx exch def               % indx is the length of pre
        pop pop                             % Discard seek and post
        /enc encs indx get def              % Get the indxth encoding
        sbs i cs mul ss add enc putinterval % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i cw mul sw add textyoffset textfont textsize] put
    } for

    % Put the checksum and end characters
    includecheck {
        sbs barlen cs mul ss add encs checksum get putinterval
        sbs barlen cs mul cs add ss add encs 11 get putinterval
        includecheckintext {
            txt barlen [barchars checksum 1 getinterval barlen cw mul sw add textyoffset textfont textsize] put
        } {
            txt barlen [( ) barlen cw mul sw add textyoffset textfont textsize] put
        } ifelse
    } {
        sbs barlen cs mul ss add encs 11 get putinterval
    } ifelse

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/code2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER code2of5--

% --BEGIN ENCODER industrial2of5--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear code2of5--
% --DESC: Industrial 2 of 5
% --EXAM: 01234567
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp industrial2of5 0.0 2022082100 57292 60792
%%BeginData:         58 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code2of5 dup /uk.co.terryburton.bwipp findresource put
begin
/industrial2of5 {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    % Get the result of encoding with code2of5 with version=industrial
    options (dontdraw) true put
    options (version) (industrial) put

    /args barcode options //code2of5 exec def

    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/industrial2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER industrial2of5--

% --BEGIN ENCODER iata2of5--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear code2of5--
% --DESC: IATA 2 of 5
% --EXAM: 01234567
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp iata2of5 0.0 2022082100 57262 60768
%%BeginData:         58 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code2of5 dup /uk.co.terryburton.bwipp findresource put
begin
/iata2of5 {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    % Get the result of encoding with code2of5 with version=iata
    options (dontdraw) true put
    options (version) (iata) put

    /args barcode options //code2of5 exec def

    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/iata2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER iata2of5--

% --BEGIN ENCODER matrix2of5--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear code2of5--
% --DESC: Matrix 2 of 5
% --EXAM: 01234567
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp matrix2of5 0.0 2022082100 57272 60776
%%BeginData:         58 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code2of5 dup /uk.co.terryburton.bwipp findresource put
begin
/matrix2of5 {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    % Get the result of encoding with code2of5 with version=matrix
    options (dontdraw) true put
    options (version) (matrix) put

    /args barcode options //code2of5 exec def

    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/matrix2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER matrix2of5--

% --BEGIN ENCODER coop2of5--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear code2of5--
% --DESC: COOP 2 of 5
% --EXAM: 01234567
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp coop2of5 0.0 2022082100 57262 60768
%%BeginData:         58 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code2of5 dup /uk.co.terryburton.bwipp findresource put
begin
/coop2of5 {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    % Get the result of encoding with code2of5 with version=coop
    options (dontdraw) true put
    options (version) (coop) put

    /args barcode options //code2of5 exec def

    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/coop2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER coop2of5--

% --BEGIN ENCODER datalogic2of5--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear code2of5--
% --DESC: Datalogic 2 of 5
% --EXAM: 01234567
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp datalogic2of5 0.0 2022082100 57287 60788
%%BeginData:         58 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code2of5 dup /uk.co.terryburton.bwipp findresource put
begin
/datalogic2of5 {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    % Get the result of encoding with code2of5 with version=datalogic
    options (dontdraw) true put
    options (version) (datalogic) put

    /args barcode options //code2of5 exec def

    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/datalogic2of5 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER datalogic2of5--

% --BEGIN ENCODER code11--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: Code 11
% --EXAM: 0123456789
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp code11 0.0 2022082100 74329 70384
%%BeginData:        169 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/code11 {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includecheck false def
    /validatecheck false def
    /includetext false def
    /includecheckintext false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /code11 //loadctx exec

    % Create an array containing the character mappings
{
    /encs
    [ (111131) (311131) (131131) (331111) (113131)
      (313111) (133111) (111331) (311311) (311111)
      (113111) (113311)
    ] def

    % Create a string of the available characters
    /barchars (0123456789-) def
    /charvals 11 dict def
    0 1 10 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.code11badCharacter (Code 11 must contain only digits and dashes) //raiseerror exec
        } if
    } for

    /barlen barcode length def
    validatecheck {
        barlen 11 eq {
            /bwipp.code11badLength (Code 11 cannot be 11 characters using check digits) //raiseerror exec
        } if
        /barlen barlen barlen 10 le {1} {2} ifelse sub def
    } if

    /numchecks includecheck validatecheck or {barlen 10 ge {2} {1} ifelse} {0} ifelse def
    /checksum1 0 def /checksum2 0 def
    0 1 barlen 1 sub {
        /i exch def
        /indx charvals barcode i 1 getinterval get def
        /checksum1 checksum1 barlen i sub 1 sub 10 mod 1 add indx mul add def
        /checksum2 checksum2 barlen i sub 9 mod 1 add indx mul add def
    } for
    /checksum1 checksum1 11 mod def
    /checksum2 checksum2 checksum1 add 11 mod def
    validatecheck {
        numchecks 1 eq {
            barcode barlen get barchars checksum1 get ne {
                /bwipp.code11badCheckDigit (Incorrect Code 11 check digit provided) //raiseerror exec
            } if
        } {
            barcode barlen get barchars checksum1 get ne
            barcode barlen 1 add get barchars checksum2 get ne or {
                /bwipp.code11badCheckDigits (Incorrect Code 11 check digits provided) //raiseerror exec
            } if
        } ifelse
        /barcode barcode 0 barlen getinterval def
        /includecheck true def
    } if

    /sbs barlen numchecks add 6 mul 12 add string def
    /txt barlen numchecks add array def

    % Put the start character
    sbs 0 encs 11 get putinterval

    /xpos 8 def
    0 1 barlen 1 sub {
        /i exch def
        /indx charvals barcode i 1 getinterval get def
        /enc encs indx get def
        sbs i 6 mul 6 add enc putinterval
        txt i [barcode i 1 getinterval xpos textyoffset textfont textsize] put
        0 1 5 {       % xpos+=width of the character
            /xpos exch enc exch get 48 sub xpos add def
        } for
    } for

    % Put the checksum and end characters
    includecheck {
        barlen 10 ge {
            sbs barlen 6 mul 6 add encs checksum1 get putinterval
            sbs barlen 6 mul 12 add encs checksum2 get putinterval
            includecheckintext {
                txt barlen [barchars checksum1 1 getinterval xpos textyoffset textfont textsize] put
                /enc encs checksum1 get def
                0 1 5 {       % xpos+=width of the character
                    /xpos exch enc exch get 48 sub xpos add def
                } for
                txt barlen 1 add [barchars checksum2 1 getinterval xpos textyoffset textfont textsize] put
            } {
                txt barlen [() xpos textyoffset textfont textsize] put
                txt barlen 1 add [() xpos textyoffset textfont textsize] put
            } ifelse
            sbs barlen 6 mul 18 add encs 11 get putinterval
        } {
            sbs barlen 6 mul 6 add encs checksum1 get putinterval
            includecheckintext {
                txt barlen [barchars checksum1 1 getinterval xpos textyoffset textfont textsize] put
            } {
                txt barlen [() xpos textyoffset textfont textsize] put
            } ifelse
            sbs barlen 6 mul 12 add encs 11 get putinterval
        } ifelse
    } {
        sbs barlen 6 mul 6 add encs 11 get putinterval
    } ifelse

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/code11 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER code11--

% --BEGIN ENCODER bc412--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: BC412
% --EXAM: BC412
% --EXOP: semi includetext includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp bc412 0.0 2022082100 75365 71341
%%BeginData:        203 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/bc412 {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includecheck false def
    /validatecheck false def
    /includetext false def
    /includecheckintext false def
    /includestartstop false def
    /semi false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    semi {
        % Implies includecheck and includecheckintext also
        /includestartstop true def
    } if

    /bc412 //loadctx exec

    % Create a string of the available characters
{
    /barchars (0R9GLVHA8EZ4NTS1J2Q6C7DYKBUIX3FWP5M) def
    /charvals 35 dict def
    0 1 34 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.bc412badCharacter (BC412 must contain only digits and capital letters except O) //raiseerror exec
        } if
    } for

    semi {
        % Validate length
        validatecheck {
            barcode length 8 lt barcode length 19 gt or {
                /bwipp.bc412semivalidateBadLength (BC412 semi with check digit must be 8 to 19 characters long) //raiseerror exec
            } if
        } {
            barcode length 7 lt barcode length 18 gt or {
                /bwipp.bc412semiBadLength (BC412 semi must be 7 to 18 characters long) //raiseerror exec
            } if
        } ifelse

        /barlen barcode length def
        validatecheck not {  % Place dummy (0) in checksum position (1-based 2nd)
            /barlen barlen 1 add def
            /sbarcode barlen string def
            sbarcode 0 barcode 0 get put
            sbarcode 1 48 put  % (0)
            sbarcode 2 barcode 1 barlen 2 sub getinterval putinterval
            /barcode sbarcode def
        } if
        /sumodd 0 def /sumeven 0 def
        0 1 barlen 1 sub {
            /i exch def
            barcode i 1 getinterval charvals exch get
            i 2 mod 0 eq {  % 1-based odd
                sumodd add /sumodd exch def
            } {
                sumeven add /sumeven exch def
            } ifelse
        } for
        /checksum sumodd 35 mod sumeven 35 mod 2 mul add 35 mod def  % F = Mod35( Mod35( Fodd ) + 2 * Mod35( Feven ) )
        validatecheck {
            checksum 0 ne {
                /bwipp.bc412semiBadCheckDigit (Incorrect BC412 semi check digit provided) //raiseerror exec
            } if
        } {
            /checksum checksum 17 mul 35 mod def  % CD = Mod35( 17 * F )
            barcode 1 barchars checksum get put
        } ifelse
    } {
        /barlen barcode length validatecheck {1 sub} if def

        /checksum 0 def
        0 1 barlen 1 sub {
            barcode exch 1 getinterval charvals exch get
            checksum add /checksum exch def
        } for
        /checksum checksum 35 mod def
        validatecheck {
            barcode barlen get barchars checksum get ne {
                /bwipp.bc412badCheckDigit (Incorrect BC412 check digit provided) //raiseerror exec
            } if
            /barcode barcode 0 barlen getinterval def
            /includecheck true def
        } if
    } ifelse

    % Create an array containing the character mappings
{
    /encs
    [ (11111115) (13111212) (11131113) (12111213) (12121311)  % 0R9GL
      (13131111) (12111312) (11131212) (11121411) (11151111)  % VHA8E
      (15111111) (11111511) (12131211) (13121112) (13111311)  % Z4NTS
      (11111214) (12121113) (11111313) (13111113) (11121213)  % 1J2Q6
      (11141112) (11121312) (11141211) (14121111) (12121212)  % C7DYK
      (11131311) (13121211) (12111411) (14111211) (11111412)  % BUIX3
      (12111114) (14111112) (12141111) (11121114) (12131112)  % FWP5M
      (12) (111)  % Start Stop
    ] def
} ctxdef

    /sbs barlen 1 add 8 mul 5 add string def
    includecheck {
        /txt barlen 1 add array def
    } {
        /txt barlen array def
    } ifelse

    % Put the start character
    includestartstop {
        sbs 0 encs 35 get putinterval
        /pos 2 def
        /txtpos 3 def
    } {
        /pos 0 def
        /txtpos 0 def
    } ifelse

    0 1 barlen 1 sub {
        /i exch def
        /indx charvals barcode i 1 getinterval get def
        sbs pos encs indx get putinterval
        txt i [barcode i 1 getinterval i 12 mul txtpos add textyoffset textfont textsize] put
        /pos pos 8 add def
    } for

    % Put the checksum
    includecheck {
        sbs pos encs checksum get putinterval
        includecheckintext {
            txt barlen [barchars checksum 1 getinterval barlen 12 mul txtpos add textyoffset textfont textsize] put
        } {
            txt barlen [() barlen 12 mul txtpos add textyoffset textfont textsize] put
        } ifelse
        /pos pos 8 add def
    } if

    % Put the stop character
    includestartstop {
        sbs pos encs 36 get putinterval
        /pos pos 3 add def
    } if

    % Return the arguments
    /sbs sbs 0 pos getinterval def
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/bc412 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER bc412--

% --BEGIN ENCODER rationalizedCodabar--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: Codabar
% --EXAM: A0123456789B
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp rationalizedCodabar 0.0 2022082100 75010 71044
%%BeginData:        167 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/rationalizedCodabar {

    20 dict begin                    % Confine variables to local scope

    /options exch def          % We are given an option string
    /barcode exch def          % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /altstartstop false def
    /includecheck false def     % Enable/disable checkdigit
    /validatecheck false def
    /includetext false def      % Enable/disable text
    /includecheckintext false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /rationalizedCodabar //loadctx exec

{
    % Create an array containing the character mappings
    /encs
    [ (11111331) (11113311) (11131131) (33111111) (11311311)
      (31111311) (13111131) (13113111) (13311111) (31131111)
      (11133111) (11331111) (31113131) (31311131) (31313111)
      (11313131) (11331311) (13131131) (11131331) (11133311)
    ] def

    % Create a string of the available characters
    /barcharsnormal (0123456789-$:/.+ABCD) def
    /barcharsalt (0123456789-$:/.+TN*E) def
} ctxdef

    /barchars altstartstop {barcharsalt} {barcharsnormal} ifelse def

    /charvals 20 dict def
    0 1 19 {charvals exch dup barchars exch 1 getinterval exch put} for
    /bodyvals 16 dict def
    0 1 15 {bodyvals exch dup barchars exch 1 getinterval exch put} for
    /ssvals 4 dict def
    16 1 19 {ssvals exch dup barchars exch 1 getinterval exch put} for

    % Validate the input
    barcode 0 1 getinterval ssvals exch known not
    barcode barcode length 1 sub 1 getinterval ssvals exch known not or {
        altstartstop {
            /bwipp.rationalizedCodabarBadAltStartStop (Codabar start and stop characters must be one of E N T or *) //raiseerror exec
        } {
            /bwipp.rationalizedCodabarBadStartStop (Codabar start and stop characters must be one of A B C or D) //raiseerror exec
        } ifelse
    } if
    1 1 barcode length 2 sub {
        barcode exch 1 getinterval bodyvals exch known not {
            /bwipp.rationalizedCodabarBadCharacter (Codabar body must contain only digits and symbols - $ : / . +) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {1 sub} if def

    /checksum 0 def
    0 1 barlen 2 sub {
        barcode exch 1 getinterval charvals exch get
        checksum add /checksum exch def
    } for
    barcode barcode length 1 sub 1 getinterval charvals exch get
    checksum add /checksum exch def
    /checksum 16 checksum 16 mod sub 16 mod def
    validatecheck {
        barcode barlen 1 sub get barchars checksum get ne {
            /bwipp.rationalizedCodabarBadCheckDigit (Incorrect Codabar check digit provided) //raiseerror exec
        } if
        barlen string
        dup 0 barcode 0 barlen 1 sub getinterval putinterval
        dup barlen 1 sub barcode barlen 1 getinterval putinterval
        /barcode exch def
        /includecheck true def
    } if

    /sbs barlen includecheck {1 add} if 8 mul string def
    /txt barlen includecheck {1 add} if array def

    /xpos 0 def
    0 1 barlen 2 sub {
        /i exch def
        /indx charvals barcode i 1 getinterval get def
        /enc encs indx get def
        sbs i 8 mul enc putinterval  % Put encoded digit into sbs
        txt i [barcode i 1 getinterval xpos textyoffset textfont textsize] put
        0 1 7 {       % xpos+=width of the character
            /xpos exch enc exch get 48 sub xpos add def
        } for
    } for

    % Put the checksum character and stop character
    includecheck {
        % Put the checksum character
        sbs barlen 8 mul 8 sub encs checksum get putinterval
        includecheckintext {
            txt barlen 1 sub [barchars checksum 1 getinterval xpos textyoffset textfont textsize] put
        } {
            txt barlen 1 sub [( ) xpos textyoffset textfont textsize] put
        } ifelse
        0 1 7 {       % xpos+=width of the character
            /xpos exch encs checksum get exch get 48 sub xpos add def
        } for
        % Put the end character
        /indx charvals barcode barlen 1 sub 1 getinterval get def
        /enc encs indx get def            % Get the indxth encoding
        sbs barlen 8 mul enc putinterval  % Put encoded digit into sbs
        txt barlen [barcode barlen 1 sub 1 getinterval xpos textyoffset textfont textsize] put
    } {
        % Put the end character
        /indx charvals barcode barlen 1 sub 1 getinterval get def
        /enc encs indx get def                  % Get the indxth encoding
        sbs barlen 8 mul 8 sub enc putinterval  % Put encoded digit into sbs
        txt barlen 1 sub [barcode barlen 1 sub 1 getinterval xpos textyoffset textfont textsize] put
    } ifelse

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/rationalizedCodabar dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER rationalizedCodabar--

% --BEGIN ENCODER onecode--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: USPS Intelligent Mail
% --EXAM: 0123456709498765432101234567891
% --EXOP: barcolor=FF0000
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp onecode 0.0 2022082100 108651 104892
%%BeginData:        348 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/onecode {

    20 dict begin

    /options exch def              % We are given an option string
    /barcode exch def              % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /height 0.15 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

    /height height cvr def

    /onecode //loadctx exec

    /barlen barcode length def

    % Create the human readable text
    /txtdict <<
        2 dup
        5 dup
        barcode 5 1 getinterval (9) eq {14} {11} ifelse dup
        20 dup
        25 dup
        29 dup
    >> def
    /txt barlen 6 add array def
    /spacecnt 0 def
    0 1 barlen 1 sub {
        /i exch def
        txtdict i known {
            txt i spacecnt add [( ) 0 0 () 0] put
            /spacecnt spacecnt 1 add def
        } if
        txt i spacecnt add [barcode i 1 getinterval 0 0 () 0] put
    } for
    /txt txt 0 barcode length spacecnt add getinterval def

    /normalize {
        /base exch def
        /num exch def
        num length 1 sub -1 1 {
            /i exch def
            num i 1 sub 2 copy get num i get base idiv add put
            num i num i get base mod put
        } for
        { %loop - extend input as necessary
            num 0 get base lt {exit} if
            /num [0 num {} forall] def
            num 0 num 0 get num 1 get base idiv add put
            num 1 num 1 get base mod put
        } loop
        % Trim leading zeros
        /num [/i true def num {dup 0 eq i and {pop} {/i false def} ifelse} forall] def
        num length 0 eq {/num [0] def} if
        num
    } def

    /bigadd {
        2 copy length exch length
        2 copy sub abs /offset exch def
        lt {exch} if
        /a exch def /b exch def
        0 1 b length 1 sub {
            dup a exch offset add 2 copy get b 5 -1 roll get add put
        } for
        a
    } def

    % Conversion of data fields into binary data
    barlen 20 eq {[0]} if
    barlen 25 eq {[1]} if
    barlen 29 eq {[1 0 0 0 0 1]} if
    barlen 31 eq {[1 0 0 0 1 0 0 0 0 1]} if
    /binval exch [barcode 20 barlen 20 sub getinterval {48 sub} forall] bigadd def
    /binval [binval {} forall barcode 0 get 48 sub] def
    /binval [binval {5 mul} forall] [barcode 1 get 48 sub] bigadd 10 normalize def
    /binval [binval {} forall barcode 2 18 getinterval {48 sub} forall] def

    % Conversion of binary data into byte array
    /bytes 13 array def
    /bintmp [binval {} forall] def
    12 -1 0 {
        /i exch def
        0 1 bintmp length 2 sub {
            /j exch def
            bintmp j 1 add 2 copy get bintmp j get 256 mod 10 mul add put
            bintmp j bintmp j get 256 idiv put
        } for
        bytes i bintmp bintmp length 1 sub get 256 mod put
        bintmp bintmp length 1 sub 2 copy get 256 idiv put
    } for

    % Generation of 11-bit CRC on byte array
    /fcs 2047 def
    /dat bytes 0 get 5 bitshift def
    6 {
        fcs dat xor 1024 and 0 ne {
            /fcs fcs 1 bitshift 3893 xor def
        } {
            /fcs fcs 1 bitshift def
        } ifelse
        /fcs fcs 2047 and def
        /dat dat 1 bitshift def
    } repeat
    1 1 12 {
        bytes exch get 3 bitshift /dat exch def
        8 {
            fcs dat xor 1024 and 0 ne {
                /fcs fcs 1 bitshift 3893 xor def
            } {
                /fcs fcs 1 bitshift def
            } ifelse
            /fcs fcs 2047 and def
            /dat dat 1 bitshift def
        } repeat
    } for

    % Conversion from binary data to codewords
    /codewords 10 array def
    9 -1 0 {
        /i exch def
        i 9 eq {
            /b 636 def
        } {
            /b 1365 def
        } ifelse
        0 1 binval length 2 sub {
            /j exch def
            binval j 1 add 2 copy get binval j get b mod 10 mul add put
            binval j binval j get b idiv put
        } for
        codewords i binval binval length 1 sub get b mod put
        binval binval length 1 sub 2 copy get b idiv put
    } for

    % Inserting additional information into codewords
    codewords 9 codewords 9 get 2 mul put
    fcs 1024 and 0 ne {
        codewords 0 codewords 0 get 659 add put
    } if

    % Conversion from codewords to characters
{
    /tab513 [
        31 7936   47 7808   55 7552   59 7040   61 6016   62 3968   79 7744   87
      7488   91 6976   93 5952   94 3904  103 7360  107 6848  109 5824  110 3776
       115 6592  117 5568  118 3520  121 5056  122 3008  124 1984  143 7712  151
      7456  155 6944  157 5920  158 3872  167 7328  171 6816  173 5792  174 3744
       179 6560  181 5536  182 3488  185 5024  186 2976  188 1952  199 7264  203
      6752  205 5728  206 3680  211 6496  213 5472  214 3424  217 4960  218 2912
       220 1888  227 6368  229 5344  230 3296  233 4832  234 2784  236 1760  241
      4576  242 2528  244 1504  248  992  271 7696  279 7440  283 6928  285 5904
       286 3856  295 7312  299 6800  301 5776  302 3728  307 6544  309 5520  310
      3472  313 5008  314 2960  316 1936  327 7248  331 6736  333 5712  334 3664
       339 6480  341 5456  342 3408  345 4944  346 2896  348 1872  355 6352  357
      5328  358 3280  361 4816  362 2768  364 1744  369 4560  370 2512  372 1488
       376  976  391 7216  395 6704  397 5680  398 3632  403 6448  405 5424  406
      3376  409 4912  410 2864  412 1840  419 6320  421 5296  422 3248  425 4784
       426 2736  428 1712  433 4528  434 2480  436 1456  440  944  451 6256  453
      5232  454 3184  457 4720  458 2672  460 1648  465 4464  466 2416  468 1392
       472  880  481 4336  482 2288  484 1264  488  752  527 7688  535 7432  539
      6920  541 5896  542 3848  551 7304  555 6792  557 5768  558 3720  563 6536
       565 5512  566 3464  569 5000  570 2952  572 1928  583 7240  587 6728  589
      5704  590 3656  595 6472  597 5448  598 3400  601 4936  602 2888  604 1864
       611 6344  613 5320  614 3272  617 4808  618 2760  620 1736  625 4552  626
      2504  628 1480  632  968  647 7208  651 6696  653 5672  654 3624  659 6440
       661 5416  662 3368  665 4904  666 2856  668 1832  675 6312  677 5288  678
      3240  681 4776  682 2728  684 1704  689 4520  690 2472  692 1448  696  936
       707 6248  709 5224  710 3176  713 4712  714 2664  716 1640  721 4456  722
      2408  724 1384  728  872  737 4328  738 2280  740 1256  775 7192  779 6680
       781 5656  782 3608  787 6424  789 5400  790 3352  793 4888  794 2840  796
      1816  803 6296  805 5272  806 3224  809 4760  810 2712  812 1688  817 4504
       818 2456  820 1432  824  920  835 6232  837 5208  838 3160  841 4696  842
      2648  844 1624  849 4440  850 2392  852 1368  865 4312  866 2264  868 1240
       899 6200  901 5176  902 3128  905 4664  906 2616  908 1592  913 4408  914
      2360  916 1336  929 4280  930 2232  932 1208  961 4216  962 2168  964 1144
      1039 7684 1047 7428 1051 6916 1053 5892 1054 3844 1063 7300 1067 6788 1069
      5764 1070 3716 1075 6532 1077 5508 1078 3460 1081 4996 1082 2948 1084 1924
      1095 7236 1099 6724 1101 5700 1102 3652 1107 6468 1109 5444 1110 3396 1113
      4932 1114 2884 1116 1860 1123 6340 1125 5316 1126 3268 1129 4804 1130 2756
      1132 1732 1137 4548 1138 2500 1140 1476 1159 7204 1163 6692 1165 5668 1166
      3620 1171 6436 1173 5412 1174 3364 1177 4900 1178 2852 1180 1828 1187 6308
      1189 5284 1190 3236 1193 4772 1194 2724 1196 1700 1201 4516 1202 2468 1204
      1444 1219 6244 1221 5220 1222 3172 1225 4708 1226 2660 1228 1636 1233 4452
      1234 2404 1236 1380 1249 4324 1250 2276 1287 7188 1291 6676 1293 5652 1294
      3604 1299 6420 1301 5396 1302 3348 1305 4884 1306 2836 1308 1812 1315 6292
      1317 5268 1318 3220 1321 4756 1322 2708 1324 1684 1329 4500 1330 2452 1332
      1428 1347 6228 1349 5204 1350 3156 1353 4692 1354 2644 1356 1620 1361 4436
      1362 2388 1377 4308 1378 2260 1411 6196 1413 5172 1414 3124 1417 4660 1418
      2612 1420 1588 1425 4404 1426 2356 1441 4276 1442 2228 1473 4212 1474 2164
      1543 7180 1547 6668 1549 5644 1550 3596 1555 6412 1557 5388 1558 3340 1561
      4876 1562 2828 1564 1804 1571 6284 1573 5260 1574 3212 1577 4748 1578 2700
      1580 1676 1585 4492 1586 2444 1603 6220 1605 5196 1606 3148 1609 4684 1610
      2636 1617 4428 1618 2380 1633 4300 1634 2252 1667 6188 1669 5164 1670 3116
      1673 4652 1674 2604 1681 4396 1682 2348 1697 4268 1698 2220 1729 4204 1730
      2156 1795 6172 1797 5148 1798 3100 1801 4636 1802 2588 1809 4380 1810 2332
      1825 4252 1826 2204 1857 4188 1858 2140 1921 4156 1922 2108 2063 7682 2071
      7426 2075 6914 2077 5890 2078 3842 2087 7298 2091 6786 2093 5762 2094 3714
      2099 6530 2101 5506 2102 3458 2105 4994 2106 2946 2119 7234 2123 6722 2125
      5698 2126 3650 2131 6466 2133 5442 2134 3394 2137 4930 2138 2882 2147 6338
      2149 5314 2150 3266 2153 4802 2154 2754 2161 4546 2162 2498 2183 7202 2187
      6690 2189 5666 2190 3618 2195 6434 2197 5410 2198 3362 2201 4898 2202 2850
      2211 6306 2213 5282 2214 3234 2217 4770 2218 2722 2225 4514 2226 2466 2243
      6242 2245 5218 2246 3170 2249 4706 2250 2658 2257 4450 2258 2402 2273 4322
      2311 7186 2315 6674 2317 5650 2318 3602 2323 6418 2325 5394 2326 3346 2329
      4882 2330 2834 2339 6290 2341 5266 2342 3218 2345 4754 2346 2706 2353 4498
      2354 2450 2371 6226 2373 5202 2374 3154 2377 4690 2378 2642 2385 4434 2401
      4306 2435 6194 2437 5170 2438 3122 2441 4658 2442 2610 2449 4402 2465 4274
      2497 4210 2567 7178 2571 6666 2573 5642 2574 3594 2579 6410 2581 5386 2582
      3338 2585 4874 2586 2826 2595 6282 2597 5258 2598 3210 2601 4746 2602 2698
      2609 4490 2627 6218 2629 5194 2630 3146 2633 4682 2641 4426 2657 4298 2691
      6186 2693 5162 2694 3114 2697 4650 2705 4394 2721 4266 2753 4202 2819 6170
      2821 5146 2822 3098 2825 4634 2833 4378 2849 4250 2881 4186 2945 4154 3079
      7174 3083 6662 3085 5638 3086 3590 3091 6406 3093 5382 3094 3334 3097 4870
      3107 6278 3109 5254 3110 3206 3113 4742 3121 4486 3139 6214 3141 5190 3145
      4678 3153 4422 3169 4294 3203 6182 3205 5158 3209 4646 3217 4390 3233 4262
      3265 4198 3331 6166 3333 5142 3337 4630 3345 4374 3361 4246 3393 4182 3457
      4150 3587 6158 3589 5134 3593 4622 3601 4366 3617 4238 3649 4174 3713 4142
      3841 4126 4111 7681 4119 7425 4123 6913 4125 5889 4135 7297 4139 6785 4141
      5761 4147 6529 4149 5505 4153 4993 4167 7233 4171 6721 4173 5697 4179 6465
      4181 5441 4185 4929 4195 6337 4197 5313 4201 4801 4209 4545 4231 7201 4235
      6689 4237 5665 4243 6433 4245 5409 4249 4897 4259 6305 4261 5281 4265 4769
      4273 4513 4291 6241 4293 5217 4297 4705 4305 4449 4359 7185 4363 6673 4365
      5649 4371 6417 4373 5393 4377 4881 4387 6289 4389 5265 4393 4753 4401 4497
      4419 6225 4421 5201 4425 4689 4483 6193 4485 5169 4489 4657 4615 7177 4619
      6665 4621 5641 4627 6409 4629 5385 4633 4873 4643 6281 4645 5257 4649 4745
      4675 6217 4677 5193 4739 6185 4741 5161 4867 6169 4869 5145 5127 7173 5131
      6661 5133 5637 5139 6405 5141 5381 5155 6277 5157 5253 5187 6213 5251 6181
      5379 6165 5635 6157 6151 7171 6155 6659 6163 6403 6179 6275 6211 5189 4681
      4433 4321 3142 2634 2386 2274 1612 1364 1252  856  744  496
    ] def

    /tab213 [
         3 6144    5 5120    6 3072    9 4608   10 2560   12 1536   17 4352   18
      2304   20 1280   24  768   33 4224   34 2176   36 1152   40  640   48  384
        65 4160   66 2112   68 1088   72  576   80  320   96  192  129 4128  130
      2080  132 1056  136  544  144  288  257 4112  258 2064  260 1040  264  528
       513 4104  514 2056  516 1032 1025 4100 1026 2052 2049 4098 4097 2050 1028
       520  272  160
    ] def
} ctxdef

    /chars 10 array def
    0 1 9 {
        /i exch def
        codewords i get dup 1286 le {
            tab513 exch get
        } {
            tab213 exch 1287 sub get
        } ifelse
        chars i 3 -1 roll put
    } for

    9 -1 0 {
        /i exch def
        2 i exp cvi fcs and 0 ne {
            chars i chars i get 8191 xor put
        } if
    } for

    % Conversion from characters to the OneCode encoding
{
    /barmap [
        7 2 4 3    1 10 0 0   9 12 2 8   5 5 6 11   8 9 3 1
        0 1 5 12   2 5 1 8    4 4 9 11   6 3 8 10   3 9 7 6
        5 11 1 4   8 5 2 12   9 10 0 2   7 1 6 7    3 6 4 9
        0 3 8 6    6 4 2 7    1 1 9 9    7 10 5 2   4 0 3 8
        6 2 0 4    8 11 1 0   9 8 3 12   2 6 7 7    5 1 4 10
        1 12 6 9   7 3 8 0    5 8 9 7    4 6 2 10   3 4 0 5
        8 4 5 7    7 11 1 9   6 0 9 6    0 6 4 8    2 1 3 2
        5 9 8 12   4 11 6 1   9 5 7 4    3 3 1 2    0 7 2 0
        1 3 4 1    6 10 3 5   8 7 9 4    2 11 5 6   0 8 7 12
        4 2 8 1    5 10 3 0   9 3 0 9    6 5 2 4    7 8 1 7
        5 0 4 5    2 3 0 10   6 12 9 2   3 11 1 6   8 8 7 9
        5 4 0 11   1 5 2 2    9 1 4 12   8 3 6 6    7 0 3 7
        4 7 7 5    0 12 1 11  2 9 9 0    6 8 5 3    3 10 8 2
    ] def
} ctxdef

    /bbs 65 array def
    /bhs 65 array def
    0 1 64 {
        /i exch def
        /dec chars barmap i 4 mul get get 2 barmap i 4 mul 1 add get exp cvi and 0 ne def
        /asc chars barmap i 4 mul 2 add get get 2 barmap i 4 mul 3 add get exp cvi and 0 ne def
        dec not asc not and {
            bbs i 3 height mul 8 div put
            bhs i 2 height mul 8 div put
        } if
        dec not asc and {
            bbs i 3 height mul 8 div put
            bhs i 5 height mul 8 div put
        } if
        dec asc not and {
            bbs i 0 height mul 8 div put
            bhs i 5 height mul 8 div put
        } if
        dec asc and {
            bbs i 0 height mul 8 div put
            bhs i 8 height mul 8 div put
        } if
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /bbs bbs
    /bhs bhs
    /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
    /txt txt
    /textxalign (left)
    /textfont /Helvetica
    /textyoffset 1
    /textxoffset -0.3
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/onecode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER onecode--

% --BEGIN ENCODER postnet--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: USPS POSTNET
% --EXAM: 01234
% --EXOP: includetext includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp postnet 0.0 2022082100 70644 66913
%%BeginData:        151 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/postnet {

    20 dict begin

    /options exch def              % We are given an option string
    /barcode exch def              % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def          % Enable/disable text
    /validatecheck false def
    /includecheckintext false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 0.125 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /postnet //loadctx exec

    /barlen barcode length validatecheck {1 sub} if def

    % Validate the input
    barlen 5 ne barlen 9 ne and barlen 11 ne and {
        /bwipp.postnetBadLength (USPS POSTNET must be 5, 9 or 11 digits excluding check digit) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.postnetBadCharacter (USPS POSTNET must contain only digits) //raiseerror exec
        } if
    } forall

{
    % Create a string of the available characters
    /barchars (0123456789) def

    % Create an array containing the character mappings
    /encs
    [ (55222) (22255) (22525) (22552) (25225)
      (25252) (25522) (52225) (52252) (52522)
      (5) (5)
    ] def
} ctxdef

    /checksum 0 def
    0 1 barlen 1 sub {
        /i exch def
        /checksum checksum barcode i get 48 sub add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.postnetBadCheckDigit (Incorrect USPS POSTNET check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /bhs barlen 5 mul 7 add array def
    /txt barlen 1 add array def

    % Put start character
    /enc encs 10 get def
    /heights enc length array def
    0 1 enc length 1 sub {
        /j exch def
        heights j enc j 1 getinterval cvi height mul 5 div put
    } for
    bhs 0 heights putinterval   % Put encoded digit into sbs

    0 1 barlen 1 sub {
        /i exch def
        /enc encs barcode i get 48 sub get def
        /heights enc length array def
        0 1 enc length 1 sub {
            /j exch def
            heights j enc j 1 getinterval cvi height mul 5 div put
        } for
        bhs i 5 mul 1 add heights putinterval   % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i 5 mul 1 add 3.312 mul textyoffset textfont textsize] put
    } for

    % Put the checksum character
    /enc encs checksum get def
    /heights enc length array def
    0 1 enc length 1 sub {
        /j exch def
        heights j enc j 1 getinterval cvi height mul 5 div put
    } for
    bhs barlen 5 mul 1 add heights putinterval

    includecheckintext {
        txt barlen [barchars checksum 1 getinterval barlen 5 mul 1 add 3.312 mul textyoffset textfont textsize] put
    } {
        txt barlen [( ) barlen 5 mul 1 add 72 mul 25 div textyoffset textfont textsize] put
    } ifelse

    % Put end character
    /enc encs 11 get def
    /heights enc length array def
    0 1 enc length 1 sub {
        /j exch def
        heights j enc j 1 getinterval cvi height mul 5 div put
    } for
    bhs barlen 5 mul 6 add heights putinterval

    % Return the arguments
    <<
    /ren //renlinear
    /bhs bhs
    /bbs [bhs length {0} repeat]
    /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/postnet dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER postnet--

% --BEGIN ENCODER planet--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: USPS PLANET
% --EXAM: 01234567890
% --EXOP: includetext includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp planet 0.0 2022082100 70504 66777
%%BeginData:        152 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/planet {

    20 dict begin

    /options exch def              % We are given an option string
    /barcode exch def              % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def          % Enable/disable text
    /validatecheck false def
    /includecheckintext false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 0.125 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /planet //loadctx exec

    /barlen barcode length validatecheck {1 sub} if def

    % Validate the input
    barlen 11 ne barlen 13 ne and {
        /bwipp.planetBadLength (USPS PLANET must be 11 or 13 digits excluding check digit) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.planetBadCharacter (USPS PLANET must contain only digits) //raiseerror exec
        } if
    } forall

{
    % Create a string of the available characters
    /barchars (0123456789) def

    % Create an array containing the character mappings
    /encs
    [ (22555) (55522) (55252) (55225) (52552)
      (52525) (52255) (25552) (25525) (25255)
      (5) (5)
    ] def
} ctxdef

    % Calculate the checksum
    /checksum 0 def
    0 1 barlen 1 sub {
        /i exch def
        /checksum checksum barcode i get 48 sub add def
    } for
    /checksum 10 checksum 10 mod sub 10 mod def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.planetBadCheckDigit (Incorrect USPS PLANET check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /bhs barlen 5 mul 7 add array def
    /txt barlen 1 add array def

    % Put start character
    /enc encs 10 get def
    /heights enc length array def
    0 1 enc length 1 sub {
        /j exch def
        heights j enc j 1 getinterval cvi height mul 5 div put
    } for
    bhs 0 heights putinterval   % Put encoded digit into sbs

    0 1 barlen 1 sub {
        /i exch def
        /enc encs barcode i get 48 sub get def
        /heights enc length array def
        0 1 enc length 1 sub {
            /j exch def
            heights j enc j 1 getinterval cvi height mul 5 div put
        } for
        bhs i 5 mul 1 add heights putinterval   % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i 5 mul 1 add 3.312 mul textyoffset textfont textsize] put
    } for

    % Put the checksum character
    /enc encs checksum get def
    /heights enc length array def
    0 1 enc length 1 sub {
        /j exch def
        heights j enc j 1 getinterval cvi height mul 5 div put
    } for
    bhs barlen 5 mul 1 add heights putinterval

    includecheckintext {
        txt barlen [barchars checksum 1 getinterval barlen 5 mul 1 add 3.312 mul textyoffset textfont textsize] put
    } {
        txt barlen [( ) barlen 5 mul 1 add 72 mul 25 div textyoffset textfont textsize] put
    } ifelse

    % Put end character
    /enc encs 11 get def
    /heights enc length array def
    0 1 enc length 1 sub {
        /j exch def
        heights j enc j 1 getinterval cvi height mul 5 div put
    } for
    bhs barlen 5 mul 6 add heights putinterval

    % Return the arguments
    <<
    /ren //renlinear
    /bhs bhs
    /bbs [bhs length {0} repeat]
    /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/planet dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER planet--

% --BEGIN ENCODER royalmail--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: Royal Mail 4 State Customer Code
% --EXAM: LE28HS9Z
% --EXOP: includetext barcolor=FF0000
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp royalmail 0.0 2022082100 71475 67703
%%BeginData:        156 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/royalmail {

    20 dict begin

    /options exch def              % We are given an option string
    /barcode exch def              % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def          % Enable/disable text
    /validatecheck false def
    /includecheckintext false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 0.175 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /royalmail //loadctx exec

{
    % Create a string of the available characters
    /barchars (ZUVWXY501234B6789AHCDEFGNIJKLMTOPQRS) def
    /charvals 36 dict def
    0 1 35 {charvals exch dup barchars exch 1 getinterval exch put} for

    % Create an array containing the character mappings
    /encs
    [ (3300) (2211) (2301) (2310) (3201) (3210)
      (1122) (0033) (0123) (0132) (1023) (1032)
      (1302) (0213) (0303) (0312) (1203) (1212)
      (1320) (0231) (0321) (0330) (1221) (1230)
      (3102) (2013) (2103) (2112) (3003) (3012)
      (3120) (2031) (2121) (2130) (3021) (3030)
      (2) (3)
    ] def
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.royalmailBadCharacter (RM4SCC must contain only capital letters and digits) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {1 sub} if def

    /checksumrow 0 def
    /checksumcol 0 def
    0 1 barlen 1 sub {
        /i exch def
        /indx charvals barcode i 1 getinterval get def
        /checksumrow checksumrow indx 6 idiv add def
        /checksumcol checksumcol indx 6 mod add def
    } for
    /checksum checksumrow 6 mod 6 mul checksumcol 6 mod add def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.royalmailBadCheckDigit (Incorrect RM4SCC check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /encstr barlen 4 mul 6 add string def
    /txt barlen 1 add array def

    % Put start character
    encstr 0 encs 36 get putinterval

    0 1 barlen 1 sub {
        /i exch def
        /indx charvals barcode i 1 getinterval get def
        encstr i 4 mul 1 add encs indx get putinterval
        txt i [barcode i 1 getinterval i 4 mul 1 add 3.312 mul textyoffset textfont textsize] put
    } for

    % Put the checksum character
    encstr barlen 4 mul 1 add encs checksum get putinterval
    includecheckintext {
        txt barlen [barchars checksum 1 getinterval barlen 4 mul 1 add 3.312 mul textyoffset textfont textsize] put
    } {
        txt barlen [( ) barlen 4 mul 1 add 3.312 mul textyoffset textfont textsize] put
    } ifelse

    % Put end character
    encstr barlen 4 mul 5 add encs 37 get putinterval

    /bbs encstr length array def
    /bhs encstr length array def
    0 1 encstr length 1 sub {
        /i exch def
        /enc encstr i 1 getinterval def
        enc (0) eq {
            bbs i 3 height mul 8 div put
            bhs i 2 height mul 8 div put
        } if
        enc (1) eq {
            bbs i 0 height mul 8 div put
            bhs i 5 height mul 8 div put
        } if
        enc (2) eq {
            bbs i 3 height mul 8 div put
            bhs i 5 height mul 8 div put
        } if
        enc (3) eq {
            bbs i 0 height mul 8 div put
            bhs i 8 height mul 8 div put
        } if
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /bbs bbs
    /bhs bhs
    /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/royalmail dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER royalmail--

% --BEGIN ENCODER auspost--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: AusPost 4 State Customer Code
% --EXAM: 5956439111ABA 9
% --EXOP: includetext custinfoenc=character
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp auspost 0.0 2022082100 82406 78597
%%BeginData:        215 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/auspost {

    20 dict begin

    /options exch def              % We are given an option string
    /barcode exch def              % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def         % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 0.175 def
    /custinfoenc (character) 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /ausport //loadctx exec

    % Create an array containing the character mappings
{
    /encs
    [ (000) (001) (002) (010) (011) (012) (020) (021)
      (022) (100) (101) (102) (110) (111) (112) (120)
      (121) (122) (200) (201) (202) (210) (211) (212)
      (220) (221) (222) (300) (301) (302) (310) (311)
      (312) (320) (321) (322) (023) (030) (031) (032)
      (033) (103) (113) (123) (130) (131) (132) (133)
      (203) (213) (223) (230) (231) (232) (233) (303)
      (313) (323) (330) (331) (332) (333) (003) (013)
      (00) (01) (02) (10) (11) (12) (20) (21) (22) (30)
      (13) (3)
    ] def

    % Create a string of the available characters
    /barchars (ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz #) def
} ctxdef

    /barlen barcode length def
    barcode 0 2 getinterval (11) eq {37} if
    barcode 0 2 getinterval (45) eq {37} if
    barcode 0 2 getinterval (59) eq {52} if
    barcode 0 2 getinterval (62) eq {67} if
    /encstr exch string def
    /txt barlen 2 sub array def

    % Put start character
    encstr 0 encs 74 get putinterval

    % Encode the FCC
    0 1 1 {
        /i exch def
        encs barcode i 1 getinterval cvi 64 add get
        encstr i 2 mul 2 add 3 2 roll putinterval
    } for

    % Encode the DPID
    2 1 9 {
        /i exch def
        encs barcode i 1 getinterval cvi 64 add get
        encstr i 2 mul 2 add 3 2 roll putinterval
        txt i 2 sub [barcode i 1 getinterval i 2 sub 2 mul 6 add 3.312 mul textyoffset textfont textsize] put
    } for

    % Encode the customer information
    custinfoenc (numeric) eq {
        0 1 barlen 11 sub {
            /i exch def
            encs barcode i 10 add 1 getinterval cvi 64 add get
            encstr i 2 mul 22 add 3 2 roll putinterval
            txt i 8 add [barcode i 10 add 1 getinterval i 2 mul 22 add 3.312 mul textyoffset textfont textsize] put
        } for
        /ciflen barlen 10 sub 2 mul def
    } {
        0 1 barlen 11 sub {
            /i exch def
            barcode i 10 add 1 getinterval barchars exch search
            pop
            length /indx exch def
            pop pop
            /enc encs indx get def
            encstr i 3 mul 22 add enc putinterval
            txt i 8 add [barcode i 10 add 1 getinterval i 3 mul 22 add 3.312 mul textyoffset textfont textsize] put
        } for
        /ciflen barlen 10 sub 3 mul def
    } ifelse

    % Add any filler characters
    22 ciflen add 1 encstr length 14 sub {
        encstr exch encs 75 get putinterval
    } for

    % Create the 64x64 Reed-Solomon table
{
    /rstable 64 64 mul array def
    rstable 0 [ 64 {0} repeat ] putinterval
    rstable 64 [ 0 1 63 {} for ] putinterval
    /prev 1 def
    64 {
        /next prev 1 bitshift def
        next 64 and 0 ne {
            /next next 67 xor def
        } if
        0 1 63 {
            /j exch def
            /nextcell {rstable 64 next mul j add} def
            nextcell rstable 64 prev mul j add get 1 bitshift put
            nextcell get 64 and 0 ne {
                nextcell nextcell get 67 xor put
            } if
        } for
        /prev next def
    } repeat
} ctxdef

    % Calculate the Reed-Solomon codes for triples
    /rscodes encstr length 16 sub 3 idiv 4 add array def
    rscodes 0 [ 4 {0} repeat ] putinterval
    2 3 encstr length 16 sub {
        /i exch def
        rscodes rscodes length i 2 sub 3 idiv sub 1 sub
        encstr i 1 getinterval cvi 16 mul
        encstr i 1 add 1 getinterval cvi 4 mul add
        encstr i 2 add 1 getinterval cvi add
        put
    } for
    rscodes length 5 sub -1 0 {
       /i exch def
       0 1 4 {
           /j exch def
           rscodes i j add rscodes i j add get
           rstable 64 [48 17 29 30 1] j get mul rscodes i 4 add get add get
           xor put
       } for
    } for
    /checkcode (000000000000) 12 string copy def
    0 1 3 {
        /i exch def
        /enc rscodes 3 i sub get 4 3 string cvrs def
        checkcode i 3 mul 3 enc length sub add enc putinterval
    } for

    % Put checkcode and end characters
    encstr encstr length 14 sub checkcode putinterval
    encstr encstr length 2 sub encs 74 get putinterval

    /bbs encstr length array def
    /bhs encstr length array def
    0 1 encstr length 1 sub {
        /i exch def
        /enc encstr i 1 getinterval def
        enc (0) eq {
            bbs i 0 height mul 8 div put
            bhs i 8 height mul 8 div put
        } if
        enc (1) eq {
            bbs i 3 height mul 8 div put
            bhs i 5 height mul 8 div put
        } if
        enc (2) eq {
            bbs i 0 height mul 8 div put
            bhs i 5 height mul 8 div put
        } if
        enc (3) eq {
            bbs i 3 height mul 8 div put
            bhs i 2 height mul 8 div put
        } if
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /bbs bbs
    /bhs bhs
    /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/auspost dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER auspost--

% --BEGIN ENCODER kix--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: Royal Dutch TPG Post KIX
% --EXAM: 1231FZ13XHS
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp kix 0.0 2022082100 66705 63002
%%BeginData:        122 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/kix {

    20 dict begin

    /options exch def              % We are given an option string
    /barcode exch def              % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def          % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 0.175 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /kix //loadctx exec

{
    % Create an array containing the character mappings
    /encs
    [ (0033) (0123) (0132) (1023) (1032) (1122)
      (0213) (0303) (0312) (1203) (1212) (1302)
      (0231) (0321) (0330) (1221) (1230) (1320)
      (2013) (2103) (2112) (3003) (3012) (3102)
      (2031) (2121) (2130) (3021) (3030) (3120)
      (2211) (2301) (2310) (3201) (3210) (3300)
    ] def

    % Create a string of the available characters
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ) def
    /charvals 36 dict def
    0 1 35 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.kixBadCharacter (KIX must contain only capital letters and digits) //raiseerror exec
        } if
    } for

    /barlen barcode length def
    /encstr barlen 4 mul string def
    /txt barlen array def

    0 1 barlen 1 sub {
        /i exch def
        /indx charvals barcode i 1 getinterval get def
        encstr i 4 mul encs indx get putinterval
        txt i [barcode i 1 getinterval i 4 mul 3.312 mul textyoffset textfont textsize] put
    } for

    /bbs encstr length array def
    /bhs encstr length array def
    0 1 encstr length 1 sub {
        /i exch def
        /enc encstr i 1 getinterval def
        enc (0) eq {
            bbs i 3 height mul 8 div put
            bhs i 2 height mul 8 div put
        } if
        enc (1) eq {
            bbs i 0 height mul 8 div put
            bhs i 5 height mul 8 div put
        } if
        enc (2) eq {
            bbs i 3 height mul 8 div put
            bhs i 5 height mul 8 div put
        } if
        enc (3) eq {
            bbs i 0 height mul 8 div put
            bhs i 8 height mul 8 div put
        } if
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /bbs bbs
    /bhs bhs
    /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/kix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER kix--

% --BEGIN ENCODER japanpost--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: Japan Post 4 State Customer Code
% --EXAM: 6540123789-A-K-Z
% --EXOP: includetext includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp japanpost 0.0 2022082100 71516 67819
%%BeginData:        174 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/japanpost {

    20 dict begin

    /options exch def              % We are given an option string
    /barcode exch def              % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def          % Enable/disable text
    /includecheckintext false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 0.175 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /barlen barcode length def

    /japanpost //loadctx exec

{
    % Create an array containing the character mappings
    % 0123456789- C1C2C3C4C5C6C7C8 ST EN
    /encs
    [ (300) (330) (312) (132) (321) (303) (123) (231) (213) (033) (030)
      (120) (102) (210) (012) (201) (021) (003) (333)
      (31) (13)
    ] def

    % Create a string of the available characters
    /barchars (0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ) def
} ctxdef

    /encstr 20 1 add 3 mul 4 add string def
    /digits 20 array def
    /txt barlen 1 add array def

    % Put start character
    encstr 0 encs 19 get putinterval

    /checksum 0 def
    /j 0 def /i 0 def
    0 1 barlen 1 sub {
        /i exch def
        barcode i 1 getinterval barchars exch search
        pop                                  % Discard true leaving pre
        length /indx exch def                % indx is the length of pre
        pop pop                              % Discard match and post
        indx 11 ge indx 37 lt and {          % Insert escape
            j 18 gt {exit} if                % Should fit in 20 chars
                                             % 11-20: C1 (11)
                                             % 21-30: C2 (12)
                                             % 31-36: C3 (13)
            /digit indx 1 sub 10 idiv 10 add def
            encstr j 3 mul 2 add encs digit get putinterval
            /checksum checksum digit add def
            digits j digit put
            /j j 1 add def
        } if
        j 19 gt {exit} if                    % Should fit in 20 chars
        /digit 0 def
        indx 37 eq {
            /digit 14 def                    % space (C14)
        } if
        indx 11 ge indx 37 lt and {
            /digit indx 1 sub 10 mod def
        } if
        indx 11 lt {
            /digit indx def
        } if
        encstr j 3 mul 2 add encs digit get putinterval % space
        /checksum checksum digit add def
        digits j digit put
        txt i [barcode i 1 getinterval j 3 mul 2 add 3.312 mul textyoffset textfont textsize] put
        /j j 1 add def
    } for

    % Fill spaces (c14) at right end
    j 1 20 1 sub {
        /k exch def
        encstr k 3 mul 2 add encs 14 get putinterval
        /checksum checksum 14 add def
        digits k 14 put
    } for

    % Put the checksum character
    /checksum checksum 19 mod 19 exch sub def
    encstr 2 20 3 mul add encs checksum get putinterval

    % Put end character
    encstr 2 21 3 mul add encs 20 get putinterval
    /checkdigit ( ) def
    includecheckintext {
        /checkdigit barchars checksum 1 getinterval def
    } if
    txt i 1 add [ checkdigit 20 3 mul 2 add 3.312 mul textyoffset textfont textsize] put

    % Put end character
    encstr 20 1 add 3 mul 2 add encs 20 get putinterval

    /bbs 21 3 mul 4 add array def
    /bhs bbs length array def
    0 1 bbs length 1 sub {
        /i exch def
        /enc encstr i 1 getinterval def
        /bunit 0 def
        /hunit 0 def
        enc (0) eq {
            /bunit 3 def
            /hunit 2 def
        } if
        enc (1) eq {
            /bunit 0 def
            /hunit 5 def
        } if
        enc (2) eq {
            /bunit 3 def
            /hunit 5 def
        } if
        enc (3) eq {
            /bunit 0 def
            /hunit 8 def
        } if
        bbs i bunit height mul 8 div put
        bhs i hunit height mul 8 div put
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /bbs bbs
    /bhs bhs
    /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/japanpost dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER japanpost--

% --BEGIN ENCODER msi--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: MSI Modified Plessey
% --EXAM: 0123456789
% --EXOP: includetext includecheck includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp msi 0.0 2022082100 76335 72636
%%BeginData:        150 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/msi {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includecheck false def  % Enable/disable checkdigit
    /includetext false def   % Enable/disable text
    /includecheckintext false def
    /checktype (mod10) def
    /badmod11 false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /msi //loadctx exec

{
    % Create an array containing the character mappings
    /encs
    [ (12121212) (12121221) (12122112) (12122121) (12211212)
      (12211221) (12212112) (12212121) (21121212) (21121221)
      (21) (121)
    ] def

    % Create a string of the available characters
    /barchars (0123456789) def
} ctxdef

    /barlen barcode length def     % Length of the code
    /txtlen barlen def

    /mod10 {
        /code exch def
        0 0 code {48 sub exch 10 mul add exch} forall pop 2 mul
        0 {1 index 10 mod add exch 10 idiv dup 0 eq {pop exit} if exch} loop
        0 0 code {48 sub add exch} forall exch pop add
        10 mod 10 exch sub 10 mod
        code length 1 add string dup 0 code putinterval dup code length 4 -1 roll 48 add put
    } def

    /mod11 {
        /code exch def
        code length 1 sub code {48 sub exch dup 1 sub exch 6 mod 2 add exch} forall pop
        0 code length {3 1 roll mul add} repeat
        11 mod 11 exch sub 11 mod
        dup 10 eq badmod11 and {
            pop code length 2 add string dup 0 code putinterval dup code length (10) putinterval
        } {
            code length 1 add string dup 0 code putinterval dup code length 4 -1 roll 48 add put
        } ifelse
    } def

    /ncrmod11 {
        /code exch def
        code length 1 sub code {48 sub exch dup 1 sub exch 8 mod 2 add exch} forall pop
        0 code length {3 1 roll mul add} repeat
        11 mod 11 exch sub 11 mod
        dup 10 eq badmod11 and {
            pop code length 2 add string dup 0 code putinterval dup code length (10) putinterval
        } {
            code length 1 add string dup 0 code putinterval dup code length 4 -1 roll 48 add put
        } ifelse
    } def

    % Calculate checksum
    includecheck {
        checktype (mod10) eq      {barcode mod10} if
        checktype (mod1010) eq    {barcode mod10 mod10} if
        checktype (mod11) eq      {barcode mod11} if
        checktype (ncrmod11) eq   {barcode ncrmod11} if
        checktype (mod1110) eq    {barcode mod11 mod10} if
        checktype (ncrmod1110) eq {barcode ncrmod11 mod10} if
        /barcode exch def
        /barlen barcode length def
        includecheckintext {/txtlen barlen def} if
    } if

    /sbs barlen 8 mul 5 add string def
    /txt barlen array def

    % Put start character
    sbs 0 encs 10 get putinterval

    0 1 barlen 1 sub {
        /i exch def
        % Lookup the encoding for the each barcode character
        barcode i 1 getinterval barchars exch search
        pop                                % Discard true leaving pre
        length /indx exch def              % indx is the length of pre
        pop pop                            % Discard seek and post
        /enc encs indx get def             % Get the indxth encoding
        sbs i 8 mul 2 add enc putinterval  % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i 12 mul 3 add textyoffset textfont textsize] put
    } for

    % Put the end character
    sbs barlen 8 mul 2 add encs 11 get putinterval

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    includetext {
        /txt txt 0 txtlen getinterval
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/msi dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER msi--

% --BEGIN ENCODER plessey--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: Plessey UK
% --EXAM: 01234ABCD
% --EXOP: includetext includecheckintext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp plessey 0.0 2022082100 73069 69275
%%BeginData:        157 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/plessey {

    20 dict begin                  % Confine variables to local scope

    /options exch def        % We are given an option string
    /barcode exch def        % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /validatecheck false def
    /includecheckintext false def
    /unidirectional false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /plessey //loadctx exec

    % Create a string of the available characters
{
    /barchars (0123456789ABCDEF) def
    /charvals 16 dict def
    0 1 15 {charvals exch dup barchars exch 1 getinterval exch put} for

    % Create an array containing the character mappings
    /encs
    [ (14141414) (32141414) (14321414) (32321414)
      (14143214) (32143214) (14323214) (32323214)
      (14141432) (32141432) (14321432) (32321432)
      (14143232) (32143232) (14323232) (32323232)
      (32321432) (541412323) (323)
    ] def
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.plesseyBadCharacter (Plessey must contain only digits and letters A B C D E F) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {2 sub} if def

    % Calculate the checksums
    /checkbits barlen 4 mul 8 add array def
    checkbits barlen 4 mul [ 0 0 0 0 0 0 0 0 ] putinterval
    0 1 barlen 1 sub {
        /i exch def
        /indx charvals barcode i 1 getinterval get def
        checkbits i 4 mul [
                indx 1 and
                indx -1 bitshift 1 and
                indx -2 bitshift 1 and
                indx -3 bitshift
        ] putinterval
    } for
    /checksalt [ 1 1 1 1 0 1 0 0 1 ] def
    0 1 barlen 4 mul 1 sub {
        /i exch def
        checkbits i get 1 eq {
            0 1 8 {
                /j exch def
                checkbits i j add checkbits i j add get checksalt j get xor put
            } for
        } if
    } for
    /checkval 0 def
    0 1 7 {
        /i exch def
        /checkval checkval 2 i exp cvi checkbits barlen 4 mul i add get mul add def
    } for
    /checksum1 checkval 15 and def
    /checksum2 checkval -4 bitshift def
    validatecheck {
        barcode barlen get barchars checksum1 get ne
        barcode barlen 1 add get barchars checksum2 get ne or {
            /bwipp.plesseyBadCheckDigits (Incorrect Plessey check digits provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /sbs barlen 8 mul unidirectional {27} {33} ifelse add string def
    /txt barlen 2 add array def

    % Put start character
    sbs 0 encs 16 get putinterval

    0 1 barlen 1 sub {
        /i exch def
        /indx charvals barcode i 1 getinterval get def
        sbs i 8 mul 8 add encs indx get putinterval
        txt i [barcode i 1 getinterval i 20 mul 20 add textyoffset textfont textsize] put
    } for

    % Put the checksum characters
    sbs barlen 8 mul 8 add encs checksum1 get putinterval
    sbs barlen 8 mul 16 add encs checksum2 get putinterval
    includecheckintext {
        txt barlen [barchars checksum1 1 getinterval barlen 20 mul 20 add textyoffset textfont textsize] put
        txt barlen 1 add [barchars checksum2 1 getinterval barlen 1 add 20 mul 20 add textyoffset textfont textsize] put
    } {
        txt barlen [( ) barlen 20 mul 20 add textyoffset textfont textsize] put
        txt barlen 1 add [( ) barlen 1 add 20 mul 20 add textyoffset textfont textsize] put
    } ifelse

    % Put end character
    sbs barlen 8 mul 24 add encs unidirectional {18} {17} ifelse get putinterval

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/plessey dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER plessey--

% --BEGIN ENCODER telepen--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renlinear--
% --DESC: Telepen
% --EXAM: ABCDEF
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp telepen 0.0 2022082100 71738 74915
%%BeginData:        174 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/telepen {

    20 dict begin                  % Confine variables to local scope

    /options exch def        % We are given an option string
    /barcode exch def        % We are given a barcode string

    /ctx null def
    /numeric false def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /telepen //loadctx exec

    % Parse ordinals of the form ^NNN to ASCII
    /fncvals <<
        /parse parse
        /parseonly true
        /parsefnc false
    >> def
    /barcode barcode fncvals //parseinput exec def
    /barlen barcode length def
    options (parse) undef

    % Create an array containing the character mappings
{
    /encs
    [ (31313131)        (1131313111)     (33313111)       (1111313131)
      (3111313111)      (11333131)       (13133131)       (111111313111)
      (31333111)        (1131113131)     (33113131)       (1111333111)
      (3111113131)      (1113133111)     (1311133111)     (111111113131)
      (3131113111)      (11313331)       (333331)         (111131113111)
      (31113331)        (1133113111)     (1313113111)     (1111113331)
      (31131331)        (113111113111)   (3311113111)     (1111131331)
      (311111113111)    (1113111331)     (1311111331)     (11111111113111)
      (31313311)        (1131311131)     (33311131)       (1111313311)
      (3111311131)      (11333311)       (13133311)       (111111311131)
      (31331131)        (1131113311)     (33113311)       (1111331131)
      (3111113311)      (1113131131)     (1311131131)     (111111113311)
      (3131111131)      (1131131311)     (33131311)       (111131111131)
      (3111131311)      (1133111131)     (1313111131)     (111111131311)
      (3113111311)      (113111111131)   (3311111131)     (111113111311)
      (311111111131)    (111311111311)   (131111111311)   (11111111111131)
      (3131311111)      (11313133)       (333133)         (111131311111)
      (31113133)        (1133311111)     (1313311111)     (1111113133)
      (313333)          (113111311111)   (3311311111)     (11113333)
      (311111311111)    (11131333)       (13111333)       (11111111311111)
      (31311133)        (1131331111)     (33331111)       (1111311133)
      (3111331111)      (11331133)       (13131133)       (111111331111)
      (3113131111)      (1131111133)     (33111133)       (111113131111)
      (3111111133)      (111311131111)   (131111131111)   (111111111133)
      (31311313)        (113131111111)   (3331111111)     (1111311313)
      (311131111111)    (11331313)       (13131313)       (11111131111111)
      (3133111111)      (1131111313)     (33111313)       (111133111111)
      (3111111313)      (111313111111)   (131113111111)   (111111111313)
      (313111111111)    (1131131113)     (33131113)       (11113111111111)
      (3111131113)      (113311111111)   (131311111111)   (111111131113)
      (3113111113)      (11311111111111) (331111111111)   (111113111113)
      (31111111111111)  (111311111113)   (131111111113)   (1111111111111111)
    ] def
} ctxdef

    /barlen barcode length def    % Length of the code
    /sbs barlen 16 mul 48 add string def
    /txt barlen array def

    % Put the start character ASCII 95
    /enc encs 95 get def
    sbs 0 enc putinterval
    /l enc length def

    /checksum 0 def
    /i 0 def /j 0 def
    { % loop
        i barlen eq {exit} if
        numeric {  % numeric mode: 00-99 & 0X-9X
            barcode i get 16 gt {
                /np barcode i 2 getinterval def
                np 1 1 getinterval (X) eq {  % X in even position amongst digits
                    /indx np 0 1 getinterval cvi 17 add def
                } {
                    /indx np cvi 27 add def
                } ifelse
                txt j [np j 16 mul 16 add textyoffset textfont textsize] put
                /i i 2 add def
            } {
                /indx barcode i get def
                txt j [( ) j 16 mul 16 add textyoffset textfont textsize] put
                /i i 1 add def
            } ifelse
        } {  % ASCII mode
            /indx barcode i get def
            indx 32 ge indx 126 le and {
                txt j [barcode i 1 getinterval j 16 mul 16 add textyoffset textfont textsize] put
            } {
                txt j [( ) j 16 mul 16 add textyoffset textfont textsize] put
            } ifelse
            /i i 1 add def
        } ifelse
        /checksum checksum indx add def
        /enc encs indx get def
        sbs l enc putinterval          % Put encoded digit into sbs
        /l l enc length add def
        /j j 1 add def
    } loop

    % Put the checksum character
    /checksum 127 checksum 127 mod sub 127 mod def
    /enc encs checksum get def
    sbs l enc putinterval
    /l l enc length add def

    % Put the end character ASCII 122
    /enc encs 122 get def
    sbs l enc putinterval
    /l l enc length add def

    % Shrink sbs and txt to fit exactly
    /sbs sbs 0 l getinterval def
    /txt txt 0 j getinterval def

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    includetext {
        /txt txt
    } if
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/telepen dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER telepen--

% --BEGIN ENCODER telepennumeric--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renlinear telepen--
% --DESC: Telepen Numeric
% --EXAM: 01234567
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp telepennumeric 0.0 2022082100 63671 63649
%%BeginData:         58 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /telepen dup /uk.co.terryburton.bwipp findresource put
begin
/telepennumeric {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 1 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    % Get the result of encoding with telepen with numeric=true
    options (dontdraw) true put
    options (numeric) true put

    /args barcode options //telepen exec def

    args (opt) options put
    args

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/telepennumeric dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER telepennumeric--

% --BEGIN ENCODER posicode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renlinear--
% --DESC: PosiCode
% --EXAM: ABC123
% --EXOP: version=b inkspread=-0.5 parsefnc includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp posicode 0.0 2022082100 113193 116240
%%BeginData:        399 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/posicode {

    20 dict begin                  % Confine variables to local scope

    /options exch def        % We are given an option string
    /barcode exch def        % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def    % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textxoffset 0 def
    /textyoffset -7 def
    /height 1 def
    /encoding (auto) def
    /version (a) def
    /checkoffset 0 def
    /raw false def
    /parse false def
    /parsefnc 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textxoffset textxoffset cvr def
    /textyoffset textyoffset cvr def
    /encoding encoding cvlit def
    /version version cvlit def
    /checkoffset checkoffset cvi def
    /height height cvr def

    /posicode //loadctx exec

{
    % Special function characters
    /la0  -1 def  /la1  -2 def  /la2  -3 def
    /sf0  -4 def  /sf1  -5 def  /sf2  -6 def
    /fn1  -7 def  /fn2  -8 def  /fn3  -9 def  /fn4 -10 def

    % Character maps for each state
    /charmapsnormal [
          %  0    1    2        0    1    2        0    1    2
          [ (0)  (^)  (') ]  [ (1)  (;)   27 ]  [ (2)  (<)   28 ]  % 0-2
          [ (3)  (=)   29 ]  [ (4)  (>)   30 ]  [ (5)  (?)   31 ]  % 3-5
          [ (6)  (@)  (!) ]  [ (7)  ([)  (") ]  [ (8)   92  (#) ]  % 6-8
          [ (9)  (])  (&) ]  [ (A)  (a)    1 ]  [ (B)  (b)    2 ]  % 9-11
          [ (C)  (c)    3 ]  [ (D)  (d)    4 ]  [ (E)  (e)    5 ]  % 12-14
          [ (F)  (f)    6 ]  [ (G)  (g)    7 ]  [ (H)  (h)    8 ]  % 15-17
          [ (I)  (i)    9 ]  [ (J)  (j)   10 ]  [ (K)  (k)   11 ]  % 18-20
          [ (L)  (l)   12 ]  [ (M)  (m)   13 ]  [ (N)  (n)   14 ]  % 21-23
          [ (O)  (o)   15 ]  [ (P)  (p)   16 ]  [ (Q)  (q)   17 ]  % 24-26
          [ (R)  (r)   18 ]  [ (S)  (s)   19 ]  [ (T)  (t)   20 ]  % 27-29
          [ (U)  (u)   21 ]  [ (V)  (v)   22 ]  [ (W)  (w)   23 ]  % 30-32
          [ (X)  (x)   24 ]  [ (Y)  (y)   25 ]  [ (Z)  (z)   26 ]  % 33-35
          [ (-)  (_)   40 ]  [ (.)  (`)   41 ]  [ ( )  127    0 ]  % 36-38
          [ ($)  ({)  (*) ]  [ (/)  (|)  (,) ]  [ (+)  (})  (:) ]  % 39-41
          [ (%)  (~)  fn1 ]  [ la1  la0  fn2 ]  [ sf1  sf0  fn3 ]  % 42-44
          [ sf2  sf2  fn4 ]                                        % 45
    ] def
    /chapmapslimited [
          [ (0)  -98  -98 ]  [ (1)  -98   -98 ]  [ (2)  -98  -98 ]  % 0-2
          [ (3)  -98  -98 ]  [ (4)  -98   -98 ]  [ (5)  -98  -98 ]  % 3-5
          [ (6)  -98  -98 ]  [ (7)  -98   -98 ]  [ (8)  -98  -98 ]  % 6-8
          [ (9)  -98  -98 ]  [ (A)  -98   -98 ]  [ (B)  -98  -98 ]  % 9-11
          [ (C)  -98  -98 ]  [ (D)  -98   -98 ]  [ (E)  -98  -98 ]  % 12-14
          [ (F)  -98  -98 ]  [ (G)  -98   -98 ]  [ (H)  -98  -98 ]  % 15-17
          [ (I)  -98  -98 ]  [ (J)  -98   -98 ]  [ (K)  -98  -98 ]  % 18-20
          [ (L)  -98  -98 ]  [ (M)  -98   -98 ]  [ (N)  -98  -98 ]  % 21-23
          [ (O)  -98  -98 ]  [ (P)  -98   -98 ]  [ (Q)  -98  -98 ]  % 24-26
          [ (R)  -98  -98 ]  [ (S)  -98   -98 ]  [ (T)  -98  -98 ]  % 27-29
          [ (U)  -98  -98 ]  [ (V)  -98   -98 ]  [ (W)  -98  -98 ]  % 30-32
          [ (X)  -98  -98 ]  [ (Y)  -98   -98 ]  [ (Z)  -98  -98 ]  % 33-35
          [ (-)  -98  -98 ]  [ (.)  -98   -98 ]                     % 36-37
    ] def
} ctxdef

    /charmaps version (a) eq version (b) eq or {charmapsnormal} {chapmapslimited} ifelse def

    % Invert charmaps to give character to value maps for each state
    /charvals [
        charmaps length dict charmaps length dict charmaps length dict
    ] def
    0 1 charmaps length 1 sub {
        /i exch def
        /encs charmaps i get def
        0 1 2 {
            /j exch def
            encs j get dup type /stringtype eq {0 get} if  % convert string to ASCII if required
            charvals j get exch i put
        } for
    } for
    /set0 charvals 0 get def
    /set1 charvals 1 get def
    /set2 charvals 2 get def

    raw {/encoding (raw) def} if

    encoding (raw) eq {
        /cws 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
            cws j cw put
            /i i 4 add def
            /j j 1 add def
        } loop
        /cws cws 0 j getinterval def
        /text () def
    } if

    encoding (auto) eq {

        % Parse the input
        /fncvals <<
            /parse parse
            /parsefnc parsefnc
            (FNC1) fn1
            (FNC2) fn2
            (FNC3) fn3
%            (FNC4) fn4        Not user accessible as encoded automatically
        >> def
        /msg barcode fncvals //parseinput exec def
        /msglen msg length def

        /text msglen string def
        0 1 msglen 1 sub {
            /i exch def
            text i msg i get dup 0 lt { pop 32 } if put
        } for

        % Standard and extended ASCII runlength at position
        /numSA [ msglen {0} repeat 0 ] def
        /numEA [ msglen {0} repeat 0 ] def
        msglen 1 sub -1 0 {
            /i exch def
            msg i get 0 ge {
                msg i get 128 ge {
                    numEA i numEA i 1 add get 1 add put
                } {
                    numSA i numSA i 1 add get 1 add put
                } ifelse
            } if
        } for

        % FNC4 codeword insertion for extended ASCII
        /ea false def /msgtmp [] def
        0 1 msglen 1 sub {
            /i exch def
            /c msg i get def
            ea c 128 lt xor not c 0 ge and {  % Other mode required
                ea {numSA} {numEA} ifelse i get dup  % Runlength of other mode
                i add msglen eq {3} {5} ifelse       % Does run terminate symbol
                lt {  % Shift
                    /msgtmp [ msgtmp aload pop fn4 ] def
                } {   % Latch
                    /msgtmp [ msgtmp aload pop fn4 fn4 ] def
                    /ea ea not def
                } ifelse
            } if
            /msgtmp [ msgtmp aload pop c 0 ge {c 127 and} {c} ifelse ] def
        } for
        /msg msgtmp def
        /msglen msg length def

        % Convert the input message to codewords
        /enc {
            exch get cws exch j exch put
            /j j 1 add def
        } def

        /cws msglen 2 mul array def
        /i 0 def /j 0 def /cset (set0) def
        {
            i msglen eq {exit} if

            {  % common exit

                % Read next two characters
                /char1 msg i get def
                /char2 i 1 add msglen lt {msg i 1 add get} {-99} ifelse def

                % If current mode is sufficient then directly encode
                cset load char1 known {
                    char1 cset load enc
                    /i i 1 add def
                    exit
                } if

                % If char1 is in set2 then shift encode
                set2 char1 known {
                    sf2 cset load enc
                    char1 set2 enc
                    /i i 1 add def
                    exit
                } if

                % If char2 is also not in this set then latch else shift encode
                cset load char2 known not {
                    cset (set0) eq {
                       la1 cset load enc
                       /cset (set1) def
                    } {
                       la0 cset load enc
                       /cset (set0) def
                    } ifelse
                    exit
                } {
                    cset (set0) eq {
                        sf1 cset load enc
                        char1 set1 enc
                    } {
                        sf0 cset load enc
                        char1 set0 enc
                    } ifelse
                    /i i 1 add def
                    exit
                } ifelse

                exit
            } loop

        } loop
        /cws cws 0 j getinterval def
    } if  % auto encoding

    % Create an array containing the character mappings
{
    /encmaps <<   % ";"=11, "<"=12
    /a
        [ (141112) (131212) (121312) (111412) (131113)
          (121213) (111313) (121114) (111214) (111115)
          (181111) (171211) (161311) (151411) (141511)
          (131611) (121711) (111811) (171112) (161212)
          (151312) (141412) (131512) (121612) (111712)
          (161113) (151213) (141313) (131413) (121513)
          (111613) (151114) (141214) (131314) (121414)
          (111514) (141115) (131215) (121315) (111415)
          (131116) (121216) (111316) (121117) (111217)
          (111118) (1<111112) (111111111;1)
        ]
    /b
        [ (151213) (141313) (131413) (121513) (141214)
          (131314) (121414) (131215) (121315) (121216)
          (191212) (181312) (171412) (161512) (151612)
          (141712) (131812) (121912) (181213) (171313)
          (161413) (151513) (141613) (131713) (121813)
          (171214) (161314) (151414) (141514) (131614)
          (121714) (161215) (151315) (141415) (131515)
          (121615) (151216) (141316) (131416) (121516)
          (141217) (131317) (121417) (131218) (121318)
          (121219) (1<121312) (121212121<1)
        ]
    /limiteda
        [ (111411) (111312) (111213) (111114) (121311)
          (121212) (121113) (141111) (131211) (131112)
          (171111) (161211) (151311) (141411) (131511)
          (121611) (111711) (161112) (151212) (141312)
          (131412) (121512) (111612) (151113) (141213)
          (131313) (121413) (111513) (141114) (131214)
          (121314) (111414) (131115) (121215) (111315)
          (121116) (111216) (111117) (151111) (1)
        ]
    /limitedb
        [ (121512) (121413) (121314) (121215) (131412)
          (131313) (131214) (151212) (141312) (141213)
          (181212) (171312) (161412) (151512) (141612)
          (131712) (121812) (171213) (161313) (151413)
          (141513) (131613) (121713) (161214) (151314)
          (141414) (131514) (121614) (151215) (141315)
          (131415) (121515) (141216) (131316) (121416)
          (131217) (121317) (121218) (141212) (1)
        ]
    >> def
} ctxdef
    encmaps version get /encs exch def

{
    /c2w [
        [ 495 330 210 126  70  35  15   5 ]
        [ 165 120  84  56  35  20  10   4 ]
        [  45  36  28  21  15  10   6   3 ]
        [   9   8   7   6   5   4   3   2 ]
        [   1   1   1   1   1   1   1   1 ]
    ] def
} ctxdef
    /v 0 def
    cws {
        /cw exch def
        6 {
            cw v xor 1 and 0 ne {
                /v v 7682 xor def
            } if
            /v v -1 bitshift def
            /cw cw -1 bitshift def
        } repeat
    } forall
    /v v checkoffset add def

    version (limiteda) eq version (limitedb) eq or {
        /v v 1023 and def
        v 824 gt v 853 lt and {
            /v v 292 add def
        } if
    } {
        /v v 1023 and 45 add def
    } ifelse

    /d [ 2 2 2 2 2 2 ] def
    /r 0 def /c 0 def /w 0 def /sum 0 def
    {
        sum v eq {exit} if
        /t sum c2w r get c get add def
        t v eq {
            /w w 1 add def
            d r w 2 add put
            /sum t def
        } if
        t v gt {
            d r w 2 add put
            /r r 1 add def
            /w 0 def
        } if
        t v lt {
            /c c 1 add def
            /w w 1 add def
            /sum t def
        } if
    } loop
    20 0 1 4 {d exch get sub} for
    d exch 5 exch put
    version (b) eq version (limitedb) eq or {
        /d [ d {1 add} forall ] def
    } if
    /cbs (111111111111) 12 string copy def
    5 -1 0 {
        /i exch def
        cbs 5 i sub 2 mul 1 add d i get 47 add put
    } for

    % Concatenate the space bar successions
    /sbs cws length 6 mul 31 add string def
    encs encs length 2 sub get dup
    sbs exch 0 exch putinterval
    length /j exch def
    0 1 cws length 1 sub {
        /i exch def
        sbs j encs cws i get get putinterval
        /j j 6 add def
    } for
    sbs j cbs putinterval
    /j j 12 add def
    encs encs length 1 sub get dup
    sbs exch j exch putinterval
    length j add /j exch def
    /sbs sbs 0 j getinterval def

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    /txt [ [text textxoffset textyoffset textfont textsize] ]
    /textxalign (center)
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/posicode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER posicode--

% --BEGIN ENCODER codablockf--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: Codablock F
% --EXAM: CODABLOCK F 34567890123456789010040digit
% --EXOP: columns=8
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp codablockf 0.0 2022082100 134261 137478
%%BeginData:        501 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/codablockf {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /rows -1 def
    /columns 8 def
    /rowheight 10 def
    /sepheight 1 def
    /parse false def
    /parsefnc 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

    /rows rows cvi def
    /columns columns cvi def
    /rowheight rowheight cvi def
    /sepheight sepheight cvi def

    /c columns 4 ge columns 62 le and {columns} {8} ifelse def
    /rows rows 2 ge rows 44 le and {rows} {-1} ifelse def

    /codablockf //loadctx exec

    % Convert input into bytes accounting for FNC characters
    /swa -1 def  /swb -2 def  /swc -3 def  /sft -4 def
    /fn1 -5 def  /fn2 -6 def  /fn3 -7 def  /fn4 -8 def
    /sta -9 def  /stp -10 def

    % Parse the input
    /fncvals <<
        /parse parse
        /parsefnc parsefnc
        (FNC1) fn1
%        (FNC2) fn2      Not permitted for Codablock F
        (FNC3) fn3
%        (FNC4) fn4      Not user accessible as encoded automatically
    >> def
    /msg barcode fncvals //parseinput exec def
    /msglen msg length def

    % FNC4 codeword insertion for extended ASCII
    /msgtmp [] def
    msg {
        /char exch def
        /msgtmp [ msgtmp aload pop char 128 lt {char} {fn4 char 127 and} ifelse ] def
    } forall
    /msg msgtmp def
    /msglen msg length def

    % Character maps for each state
{
    /charmaps [
      %  A    B    C         A    B    C         A    B    C
      [  32   32  (00) ]  [ (!)  (!)  (01) ]  [ (")  (")  (02) ]  % 0-2
      [ (#)  (#)  (03) ]  [ ($)  ($)  (04) ]  [ (%)  (%)  (05) ]  % 3-5
      [ (&)  (&)  (06) ]  [ (')  (')  (07) ]  [  40   40  (08) ]  % 6-8
      [  41   41  (09) ]  [ (*)  (*)  (10) ]  [ (+)  (+)  (11) ]  % 9-11
      [ (,)  (,)  (12) ]  [ (-)  (-)  (13) ]  [ (.)  (.)  (14) ]  % 12-14
      [ (/)  (/)  (15) ]  [ (0)  (0)  (16) ]  [ (1)  (1)  (17) ]  % 15-17
      [ (2)  (2)  (18) ]  [ (3)  (3)  (19) ]  [ (4)  (4)  (20) ]  % 18-20
      [ (5)  (5)  (21) ]  [ (6)  (6)  (22) ]  [ (7)  (7)  (23) ]  % 21-23
      [ (8)  (8)  (24) ]  [ (9)  (9)  (25) ]  [ (:)  (:)  (26) ]  % 24-26
      [ (;)  (;)  (27) ]  [ (<)  (<)  (28) ]  [ (=)  (=)  (29) ]  % 27-29
      [ (>)  (>)  (30) ]  [ (?)  (?)  (31) ]  [ (@)  (@)  (32) ]  % 30-32
      [ (A)  (A)  (33) ]  [ (B)  (B)  (34) ]  [ (C)  (C)  (35) ]  % 33-35
      [ (D)  (D)  (36) ]  [ (E)  (E)  (37) ]  [ (F)  (F)  (38) ]  % 36-38
      [ (G)  (G)  (39) ]  [ (H)  (H)  (40) ]  [ (I)  (I)  (41) ]  % 39-41
      [ (J)  (J)  (42) ]  [ (K)  (K)  (43) ]  [ (L)  (L)  (44) ]  % 42-44
      [ (M)  (M)  (45) ]  [ (N)  (N)  (46) ]  [ (O)  (O)  (47) ]  % 45-47
      [ (P)  (P)  (48) ]  [ (Q)  (Q)  (49) ]  [ (R)  (R)  (50) ]  % 48-50
      [ (S)  (S)  (51) ]  [ (T)  (T)  (52) ]  [ (U)  (U)  (53) ]  % 51-53
      [ (V)  (V)  (54) ]  [ (W)  (W)  (55) ]  [ (X)  (X)  (56) ]  % 54-56
      [ (Y)  (Y)  (57) ]  [ (Z)  (Z)  (58) ]  [ ([)  ([)  (59) ]  % 57-59
      [  92   92  (60) ]  [ (])  (])  (61) ]  [ (^)  (^)  (62) ]  % 60-62
      [ (_)  (_)  (63) ]  [   0  (`)  (64) ]  [   1  (a)  (65) ]  % 63-65
      [   2  (b)  (66) ]  [   3  (c)  (67) ]  [   4  (d)  (68) ]  % 66-68
      [   5  (e)  (69) ]  [   6  (f)  (70) ]  [   7  (g)  (71) ]  % 69-71
      [   8  (h)  (72) ]  [   9  (i)  (73) ]  [  10  (j)  (74) ]  % 72-74
      [  11  (k)  (75) ]  [  12  (l)  (76) ]  [  13  (m)  (77) ]  % 75-77
      [  14  (n)  (78) ]  [  15  (o)  (79) ]  [  16  (p)  (80) ]  % 78-80
      [  17  (q)  (81) ]  [  18  (r)  (82) ]  [  19  (s)  (83) ]  % 81-83
      [  20  (t)  (84) ]  [  21  (u)  (85) ]  [  22  (v)  (86) ]  % 84-86
      [  23  (w)  (87) ]  [  24  (x)  (88) ]  [  25  (y)  (89) ]  % 87-89
      [  26  (z)  (90) ]  [  27  ({)  (91) ]  [  28  (|)  (92) ]  % 90-92
      [  29  (})  (93) ]  [  30  (~)  (94) ]  [  31  127  (95) ]  % 93-95
      [ fn3  fn3  (96) ]  [ fn2  fn2  (97) ]  [ sft  sft  (98) ]  % 96-98
      [ swc  swc  (99) ]  [ swb  fn4  swb  ]  [ fn4  swa  swa  ]  % 99-101
      [ fn1  fn1  fn1  ]  [ sta  sta  sta  ]  [ stp  stp  stp  ]  % 102-104
    ] def

    % Invert charmaps to give character to value maps for each state
    /charvals [ 105 dict 105 dict 105 dict ] def
    0 1 charmaps length 1 sub {
        /i exch def
        /encs charmaps i get def
        0 1 2 {
            /j exch def
            encs j get dup type /stringtype eq {0 get} if  % convert string to ASCII if required
            charvals j get exch i put
        } for
    } for
    /seta charvals 0 get def
    /setb charvals 1 get def
    /setc charvals 2 get def
} ctxdef

    % Determine digit runlength and characters from given position
    /numsscr {
        /n 0 def /s 0 def
        /p exch def {
            p msglen ge {exit} if
            msg p get
            dup setc exch known not {pop exit} if
            fn1 eq {
                % FNC1 in odd position of run like two digits
                s 2 mod 0 eq {/s s 1 add def} {exit} ifelse
            } if
            /n n 1 add def
            /s s 1 add def
            /p p 1 add def
        } loop
        n s
    } def

    % Encoding for each alphabet
    /enca {
        seta exch get cws exch j exch put
        /j j 1 add def
    } def
    /encb {
        setb exch get cws exch j exch put
        /j j 1 add def
    } def
    /encc {
        dup type /arraytype ne {
            setc exch get
        } {
            aload pop 48 sub exch 48 sub 10 mul add
        } ifelse
        cws exch j exch put
        /j j 1 add def
    } def

    % Character exclusively in either alphabet A or B
    /anotb {dup seta exch known exch setb exch known not and} def
    /bnota {dup setb exch known exch seta exch known not and} def

    % Pre-compute relative position of next anotb and next bnota characters
    /nextanotb [ msg length {0} repeat 9999 ] def
    /nextbnota [ msg length {0} repeat 9999 ] def
    msg length 1 sub -1 0 {
        /i exch def
        msg i get anotb {
            nextanotb i 0 put
        } {
            nextanotb i nextanotb i 1 add get 1 add put
        } ifelse
        msg i get bnota {
            nextbnota i 0 put
        } {
            nextbnota i nextbnota i 1 add get 1 add put
        } ifelse
    } for

    % Does a-only come before b-only after given position and vice versa
    /abeforeb {dup nextanotb exch get exch nextbnota exch get lt} def
    /bbeforea {dup nextbnota exch get exch nextanotb exch get lt} def

    % Add padding to row
    /padrow {
        {
           {  % common exit
               cset (seta) eq {swc enca /cset (setc) def exit} if
               cset (setb) eq {swc encb /cset (setc) def exit} if
               cset (setc) eq {swb encc /cset (setb) def exit} if
           } loop
        } repeat
    } def

    % Convert message to codewords
    /cws c 5 add 44 mul array def

    /i 0 def /j 0 def /r 1 def
    /lastrow false def {

        lastrow {exit} if

        % Add start character and code subset selector
        sta enca
        i msglen lt {i numsscr} {-1 -1} ifelse /nums exch def /nchars exch def
        {  % common exit
            msglen 0 eq {
                swb enca
                /cset (setb) def
                exit
            } if
            nums 2 ge {
                swc enca
                /cset (setc) def
                exit
            } if
            i abeforeb {
                sft enca
                /cset (seta) def
                exit
            } if
            swb enca
            /cset (setb) def
            exit
        } loop
        /j j 1 add def  % Skip row indicator position

        % Main encoding loop
        /endofrow false def {
            /rem c 3 add j c 5 add mod sub def  % Codewords to end of row

            i msglen eq endofrow or {exit} if

            i numsscr /nums exch def /nchars exch def
            /remnums nums rem 2 mul gt {rem 2 mul} {nums} ifelse def

            % Determine switches and shifts
            {  % common exit
                cset (seta) eq cset (setb) eq or remnums 4 ge and
                msg i get fn1 ne and {
                    remnums 2 mod 0 eq
                    rem 3 ge and {
                        swc cset (seta) eq {enca} {encb} ifelse
                        /cset (setc) def
                        2 {
                            msg i get fn1 eq {
                                fn1 encc
                                /i i 1 add def
                            } {
                                msg i 2 getinterval encc
                                /i i 2 add def
                            } ifelse
                        } repeat
                        exit
                    } if
                    remnums 2 mod 0 ne
                    rem 4 ge and {
                        msg i get cset (seta) eq {enca} {encb} ifelse
                        /i i 1 add def
                        swc cset (seta) eq {enca} {encb} ifelse
                        /cset (setc) def
                        2 {
                            msg i get fn1 eq {
                                fn1 encc
                                /i i 1 add def
                            } {
                                msg i 2 getinterval encc
                                /i i 2 add def
                            } ifelse
                        } repeat
                        exit
                    } if
                } if
                cset (setb) eq msg i get anotb and
                rem 2 ge and {
                    i msglen 1 sub lt {
                        i 1 add bbeforea {
                            sft encb
                            msg i get enca
                            /i i 1 add def
                            exit
                        } if
                    } if
                    swa encb
                    /cset (seta) def
                    msg i get enca
                    /i i 1 add def
                    exit
                } if
                cset (seta) eq msg i get bnota and
                rem 2 ge and {
                    i msglen 1 sub lt {
                        i 1 add abeforeb {
                            sft enca
                            msg i get encb
                            /i i 1 add def
                            exit
                        } if
                    } if
                    swb enca
                    /cset (setb) def
                    msg i get encb
                    /i i 1 add def
                    exit
                } if
                cset (setc) eq remnums 2 lt and
                rem 2 ge and {
                    i abeforeb {
                        swa encc
                        /cset (seta) def
                        msg i get enca
                        /i i 1 add def
                        exit
                    } if
                    swb encc
                    /cset (setb) def
                    msg i get encb
                    /i i 1 add def
                    exit
                } if

                % No switches or latches so try to encode
                cset (seta) eq seta msg i get known and
                rem 1 ge and {
                    msg i get enca
                    /i i 1 add def
                    exit
                } if
                cset (setb) eq setb msg i get known and
                rem 1 ge and {
                    msg i get encb
                    /i i 1 add def
                    exit
                } if
                cset (setc) eq remnums 2 ge and
                rem 1 ge and {
                    msg i get fn1 eq {
                        fn1 encc
                        /i i 1 add def
                    } {
                        msg i 2 getinterval encc
                        /i i 2 add def
                    } ifelse
                    exit
                } if

                % Encoding does not fit in the row
                /endofrow true def
                exit

            } loop  % common exit

        } loop

        % Determine whether this is the final row
        r rows ge rows -1 eq or r 1 gt and i msglen eq and rem 2 ge and {
            rem 2 sub padrow
            /j j 3 add def  % Skip symbol and row checksum character positions
            stp enca
            /lastrow true def
        } {
            rem padrow
            /j j 1 add def  % Skip row checksum character positions
            stp enca
            /r r 1 add def
        } ifelse

    } loop
    /cws cws 0 j getinterval def

    % Maps for row indicators and symbol checksums
{
    /abmap [
        64 1 95 {} for
         0 1 15 {} for
        26 1 63 {} for
    ] def
    /cmap [ 0 1 85 {} for ] def
} ctxdef

    % Add symbol check characters to last row
    /chkmsg msglen array def
    /j 0 def
    0 1 msglen 1 sub {
        /i exch def
        /char msg i get def
        char 0 ge {chkmsg j char put /j j 1 add def} if
        char fn1 eq i 0 ne and {chkmsg j 29 put /j j 1 add def} if
    } for
    /t1 0 def /t2 0 def /k1 0 def /k2 0 def
    0 1 j 1 sub {
        /i exch def
        /t1 chkmsg i get i mul 86 mod def
        /t2 t1 chkmsg i get add 86 mod def
        /k1 k1 t2 add 86 mod def
        /k2 k2 t1 add 86 mod def
    } for
    cws cws length 4 sub cset (setc) ne {abmap} {cmap} ifelse k1 get put
    cws cws length 3 sub cset (setc) ne {abmap} {cmap} ifelse k2 get put

    % Populate row indicators
    cws 2 2 copy 1 sub get 99 ne {abmap} {cmap} ifelse r 2 sub get put
    1 1 r 1 sub {
        /i exch def
        cws i c 5 add mul 2 add 2 copy 1 sub get 99 ne {abmap} {cmap} ifelse i 42 add get put
    } for

    % Calculate row check characters
    0 1 r 1 sub {
        cws exch c 5 add mul c 4 add getinterval /rcws exch def
        /csum rcws 0 get def
        1 1 rcws length 2 sub {
            /i exch def
            /csum csum rcws i get i mul add def
        } for
        rcws rcws length 1 sub csum 103 mod put
    } for

    % Create an array containing the character mappings
{
    /encs
    [ (212222) (222122) (222221) (121223) (121322) (131222) (122213)
      (122312) (132212) (221213) (221312) (231212) (112232) (122132)
      (122231) (113222) (123122) (123221) (223211) (221132) (221231)
      (213212) (223112) (312131) (311222) (321122) (321221) (312212)
      (322112) (322211) (212123) (212321) (232121) (111323) (131123)
      (131321) (112313) (132113) (132311) (211313) (231113) (231311)
      (112133) (112331) (132131) (113123) (113321) (133121) (313121)
      (211331) (231131) (213113) (213311) (213131) (311123) (311321)
      (331121) (312113) (312311) (332111) (314111) (221411) (431111)
      (111224) (111422) (121124) (121421) (141122) (141221) (112214)
      (112412) (122114) (122411) (142112) (142211) (241211) (221114)
      (413111) (241112) (134111) (111242) (121142) (121241) (114212)
      (124112) (124211) (411212) (421112) (421211) (212141) (214121)
      (412121) (111143) (111341) (131141) (114113) (114311) (411113)
      (411311) (113141) (114131) (311141) (411131) (211412) (2331112)
    ] def
} ctxdef

    % Derive the bits for each row
    /rowbits r array def
    0 1 r 1 sub {
        /i exch def
        /sbs [
            cws i c 5 add mul c 5 add getinterval {
                encs exch get {48 sub} forall
            } forall
        ] def
        mark
        0 sbs {1 index 1 eq {{0}} {{1}} ifelse repeat} forall
        counttomark 1 sub array astore exch pop exch pop
        rowbits i 3 -1 roll put
    } for

    % Populate the bitmap
    /symwid c 11 mul 57 add def
    /pixs [
        symwid sepheight mul {1} repeat
        0 1 r 2 sub {
            /i exch def
            rowheight {rowbits i get aload pop} repeat
            sepheight {
                1 1 0 1 0 0 0 0 1 0 0
                symwid 24 sub {1} repeat
                1 1 0 0 0 1 1 1 0 1 0 1 1
            } repeat
        } for
        rowheight {rowbits r 1 sub get aload pop} repeat
        symwid sepheight mul {1} repeat
    ] def

    % Return the arguments
    <<
    /ren //renmatrix
    /pixs pixs
    /pixx symwid
    /pixy pixs length symwid idiv
    /height pixs length symwid idiv 72 div
    /width symwid 72 div
    /opt options
    >>

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/codablockf dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER codablockf--

% --BEGIN ENCODER code16k--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: Code 16K
% --EXAM: Abcd-1234567890-wxyZ
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp code16k 0.0 2022082100 158983 161726
%%BeginData:        725 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/code16k {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /mode -1 def
    /pos -1 def
    /rows 0 def
    /rowheight 8 def
    /sepheight 1 def
    /encoding (auto) def
    /raw false def
    /parse false def
    /parsefnc 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

    /mode mode cvi def
    /pos pos cvi def
    /rows rows cvi def
    /rowheight rowheight cvi def
    /sepheight sepheight cvi def

    /code16k //loadctx exec

    pos -1 ne {/rows 16 def} if

    % Convert input into bytes accounting for FNC characters
{
    /swa  -1 def  /swb  -2 def  /swc  -3 def
    /sa1  -4 def  /sb1  -5 def  /sc1  -6 def
    /sa2  -7 def  /sb2  -8 def  /sc2  -9 def
    /pad -10 def  /sb3 -11 def  /sc3 -12 def
    /fn1 -13 def  /fn2 -14 def  /fn3 -15 def  /fn4 -16 def

    % Character maps for each state
    /charmaps [
      %  A    B    C         A    B    C         A    B    C
      [  32   32  (00) ]  [ (!)  (!)  (01) ]  [ (")  (")  (02) ]  % 0-2
      [ (#)  (#)  (03) ]  [ ($)  ($)  (04) ]  [ (%)  (%)  (05) ]  % 3-5
      [ (&)  (&)  (06) ]  [ (')  (')  (07) ]  [  40   40  (08) ]  % 6-8
      [  41   41  (09) ]  [ (*)  (*)  (10) ]  [ (+)  (+)  (11) ]  % 9-11
      [ (,)  (,)  (12) ]  [ (-)  (-)  (13) ]  [ (.)  (.)  (14) ]  % 12-14
      [ (/)  (/)  (15) ]  [ (0)  (0)  (16) ]  [ (1)  (1)  (17) ]  % 15-17
      [ (2)  (2)  (18) ]  [ (3)  (3)  (19) ]  [ (4)  (4)  (20) ]  % 18-20
      [ (5)  (5)  (21) ]  [ (6)  (6)  (22) ]  [ (7)  (7)  (23) ]  % 21-23
      [ (8)  (8)  (24) ]  [ (9)  (9)  (25) ]  [ (:)  (:)  (26) ]  % 24-26
      [ (;)  (;)  (27) ]  [ (<)  (<)  (28) ]  [ (=)  (=)  (29) ]  % 27-29
      [ (>)  (>)  (30) ]  [ (?)  (?)  (31) ]  [ (@)  (@)  (32) ]  % 30-32
      [ (A)  (A)  (33) ]  [ (B)  (B)  (34) ]  [ (C)  (C)  (35) ]  % 33-35
      [ (D)  (D)  (36) ]  [ (E)  (E)  (37) ]  [ (F)  (F)  (38) ]  % 36-38
      [ (G)  (G)  (39) ]  [ (H)  (H)  (40) ]  [ (I)  (I)  (41) ]  % 39-41
      [ (J)  (J)  (42) ]  [ (K)  (K)  (43) ]  [ (L)  (L)  (44) ]  % 42-44
      [ (M)  (M)  (45) ]  [ (N)  (N)  (46) ]  [ (O)  (O)  (47) ]  % 45-47
      [ (P)  (P)  (48) ]  [ (Q)  (Q)  (49) ]  [ (R)  (R)  (50) ]  % 48-50
      [ (S)  (S)  (51) ]  [ (T)  (T)  (52) ]  [ (U)  (U)  (53) ]  % 51-53
      [ (V)  (V)  (54) ]  [ (W)  (W)  (55) ]  [ (X)  (X)  (56) ]  % 54-56
      [ (Y)  (Y)  (57) ]  [ (Z)  (Z)  (58) ]  [ ([)  ([)  (59) ]  % 57-59
      [  92   92  (60) ]  [ (])  (])  (61) ]  [ (^)  (^)  (62) ]  % 60-62
      [ (_)  (_)  (63) ]  [   0  (`)  (64) ]  [   1  (a)  (65) ]  % 63-65
      [   2  (b)  (66) ]  [   3  (c)  (67) ]  [   4  (d)  (68) ]  % 66-68
      [   5  (e)  (69) ]  [   6  (f)  (70) ]  [   7  (g)  (71) ]  % 69-71
      [   8  (h)  (72) ]  [   9  (i)  (73) ]  [  10  (j)  (74) ]  % 72-74
      [  11  (k)  (75) ]  [  12  (l)  (76) ]  [  13  (m)  (77) ]  % 75-77
      [  14  (n)  (78) ]  [  15  (o)  (79) ]  [  16  (p)  (80) ]  % 78-80
      [  17  (q)  (81) ]  [  18  (r)  (82) ]  [  19  (s)  (83) ]  % 81-83
      [  20  (t)  (84) ]  [  21  (u)  (85) ]  [  22  (v)  (86) ]  % 84-86
      [  23  (w)  (87) ]  [  24  (x)  (88) ]  [  25  (y)  (89) ]  % 87-89
      [  26  (z)  (90) ]  [  27  ({)  (91) ]  [  28  (|)  (92) ]  % 90-92
      [  29  (})  (93) ]  [  30  (~)  (94) ]  [  31  127  (95) ]  % 93-95
      [ fn3  fn3  (96) ]  [ fn2  fn2  (97) ]  [ sb1  sa1  (98) ]  % 96-98
      [ swc  swc  (99) ]  [ swb  fn4  swb  ]  [ fn4  swa  swa  ]  % 99-101
      [ fn1  fn1  fn1  ]  [ pad  pad  pad  ]  [ sb2  sa2  sb1  ]  % 102-104
      [ sc2  sc2  sb2  ]  [ sc3  sc3  sb3  ]                      % 105-106
    ] def

    % Invert charmaps to give character to value maps for each state
    /charvals [ 109 dict 109 dict 109 dict ] def
    0 1 charmaps length 1 sub {
        /i exch def
        /encs charmaps i get def
        0 1 2 {
            /j exch def
            encs j get dup type /stringtype eq {0 get} if  % convert string to ASCII if required
            charvals j get exch i put
        } for
    } for
    /seta charvals 0 get def
    /setb charvals 1 get def
    /setc charvals 2 get def
} ctxdef

    raw {/encoding (raw) def} if

    encoding (raw) eq {
        /cws 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
            cws j cw put
            /i i 4 add def
            /j j 1 add def
        } loop
        /cws cws 0 j getinterval def
    } if

    encoding (auto) eq {

        % Parse the input
        /fncvals <<
            /parse parse
            /parsefnc parsefnc
            /eci true
            (FNC1) fn1
            (FNC2) fn2
            (FNC3) fn3
%            (FNC4) fn4        Not user accessible as encoded automatically
        >> def
        /msg barcode fncvals //parseinput exec def
        /msglen msg length def

        % Standard and extended ASCII runlength at position
        /numSA [ msglen {0} repeat 0 ] def
        /numEA [ msglen {0} repeat 0 ] def
        msglen 1 sub -1 0 {
            /i exch def
            msg i get 0 ge {
                msg i get 128 ge {
                    numEA i numEA i 1 add get 1 add put
                } {
                    numSA i numSA i 1 add get 1 add put
                } ifelse
            } if
        } for

        % FNC4 codeword insertion for extended ASCII
        /ea false def /msgtmp [] def
        0 1 msglen 1 sub {
            /i exch def
            /c msg i get def
            ea c 128 lt xor not c 0 ge and {  % Other mode required
                ea {numSA} {numEA} ifelse i get dup  % Runlength of other mode
                i add msglen eq {3} {5} ifelse       % Does run terminate symbol
                lt {  % Shift
                    /msgtmp [ msgtmp aload pop fn4 ] def
                } {   % Latch
                    /msgtmp [ msgtmp aload pop fn4 fn4 ] def
                    /ea ea not def
                } ifelse
            } if
            /msgtmp [ msgtmp aload pop c 0 ge {c 127 and} {c} ifelse ] def
        } for
        /msg msgtmp def
        /msglen msg length def

        % Determine digit runlength and characters from given position
        /numsscr {
            /n 0 def /s 0 def
            /p exch def {
                p msglen ge {exit} if
                msg p get
                dup setc exch known not {pop exit} if
                fn1 eq {
                    % FNC1 in odd position of run like two digits
                    s 2 mod 0 eq {/s s 1 add def} {exit} ifelse
                } if
                /n n 1 add def
                /s s 1 add def
                /p p 1 add def
            } loop
            n s
        } def

        % Encoding for each alphabet
        /enca {
            seta exch get cws exch j exch put
            /j j 1 add def
        } def
        /encb {
            setb exch get cws exch j exch put
            /j j 1 add def
        } def
        /encc {
            dup type /arraytype ne {
                setc exch get
            } {
                aload pop 48 sub exch 48 sub 10 mul add
            } ifelse
            cws exch j exch put
            /j j 1 add def
        } def

        % Character exclusively in either alphabet A or B
        /anotb {dup seta exch known exch setb exch known not and} def
        /bnota {dup setb exch known exch seta exch known not and} def

        % Pre-compute relative position of next anotb and next bnota characters
        /nextanotb [ msg length {0} repeat 9999 ] def
        /nextbnota [ msg length {0} repeat 9999 ] def
        msg length 1 sub -1 0 {
            /i exch def
            msg i get anotb {
                nextanotb i 0 put
            } {
                nextanotb i nextanotb i 1 add get 1 add put
            } ifelse
            msg i get bnota {
                nextbnota i 0 put
            } {
                nextbnota i nextbnota i 1 add get 1 add put
            } ifelse
        } for

        % Does a-only come before b-only after given position and vice versa
        /abeforeb {dup nextanotb exch get exch nextbnota exch get lt} def
        /bbeforea {dup nextbnota exch get exch nextanotb exch get lt} def

        /cws barcode length 2 mul 3 add array def

        % Select mode and encode first characters
        /i 0 def /j 0 def
        {  % common exit
            % extended data length
            pos -1 ne {
                % encode one and two
                cws 0 pos 10 idiv 1 sub put
                cws 1 pos 10 mod 1 sub put
                /j 2 def
                /cset (setb) def
                /mode 7 def
                exit
            } if
            % empty => b
            msglen 0 eq {
                /cset (setb) def
                /mode 1 def
                exit
            } if
            % FNC1 . 2+ nums => c fnc1
            msglen 2 ge {
                msg 0 get fn1 eq 1 numsscr exch pop 2 ge and {
                    /cset (setc) def
                    /mode 4 def
                    /i 1 def
                    exit
                } if
            } if
            % FNC1 => b fnc1
            msg 0 get fn1 eq {
                /cset (setb) def
                /mode 3 def
                /i 1 def
                exit
            } if
            msglen 2 ge {
                % 2+ even nums => c
                0 numsscr exch pop dup 2 ge exch 2 mod 0 eq and {
                    /cset (setc) def
                    /mode 2 def
                    exit
                } if
                % 3+ odd nums => c sb1 encode
                0 numsscr exch pop dup 3 ge exch 2 mod 1 eq and {
                    msg 0 get encb
                    /cset (setc) def
                    /mode 5 def
                    /i 1 def
                    exit
                } if
                % b . 2+ even nums => c sb1 encode
                setb msg 0 get known
                1 numsscr exch pop dup 2 ge exch 2 mod 0 eq and and {
                    msg 0 get encb
                    /cset (setc) def
                    /mode 5 def
                    /i 1 def
                    exit
                } if
                % b . 3+ odd nums => c sb2 encode
                setb msg 0 get known
                1 numsscr exch pop dup 3 ge exch 2 mod 1 eq and and {
                    msg 0 get encb
                    msg 1 get encb
                    /cset (setc) def
                    /mode 6 def
                    /i 2 def
                    exit
                } if
                % b . b . 2+ even nums => c sb2 encode
                setb msg 0 get known
                setb msg 1 get known and
                2 numsscr exch pop dup 2 ge exch 2 mod 0 eq and and {
                    msg 0 get encb
                    msg 1 get encb
                    /cset (setc) def
                    /mode 6 def
                    /i 2 def
                    exit
                } if
            } if
            % anotb before bnota => a
            0 abeforeb {
                /cset (seta) def
                /mode 0 def
                exit
            } if
            % otherwise => b
            /cset (setb) def
            /mode 1 def
            exit
        } loop

        {  % Encode remainder
            i msglen eq {exit} if

            i numsscr /nums exch def /nchars exch def

            % Determine switches and shifts
            {  % common exit
                cset (seta) eq {
                    % bnota . anotb before bnota => sb1 encode
                    i msglen 1 sub lt {
                        msg i get bnota
                        i 1 add abeforeb and {
                            sb1 enca
                            msg i get encb
                            /i i 1 add def
                            exit
                        } if
                    } if
                    % bnota . bnota . anotb before bnota => sb2 encode
                    i msglen 2 sub lt {
                        msg i get bnota
                        msg i 1 add get bnota and
                        i 2 add abeforeb and {
                            sb2 enca
                            msg i get encb
                            msg i 1 add get encb
                            /i i 2 add def
                            exit
                        } if
                    } if
                    % bnota => swb
                    msg i get bnota {
                        swb enca
                        /cset (setb) def
                        exit
                    } if
                    % 4 nums . a => sc2 encode
                    i msglen 4 sub lt {
                        nums 4 eq
                        seta msg i 4 add get known and {
                            sc2 enca
                            2 {
                                msg i get fn1 eq {
                                    fn1 encc
                                    /i i 1 add def
                                } {
                                    msg i 2 getinterval encc
                                    /i i 2 add def
                                } ifelse
                            } repeat
                            exit
                        } if
                    } if
                    % 6 nums . a => sc3 encode
                    i msglen 6 sub lt {
                        nums 6 eq
                        seta msg i 6 add get known and {
                            sc3 enca
                            3 {
                                msg i get fn1 eq {
                                    fn1 encc
                                    /i i 1 add def
                                } {
                                    msg i 2 getinterval encc
                                    /i i 2 add def
                                } ifelse
                            } repeat
                            exit
                        } if
                    } if
                    % 4+ even nums => swc
                    nums 4 ge nums 2 mod 0 eq and {
                        swc enca
                        /cset (setc) def
                        exit
                    } if
                    % otherwise => encode
                    msg i get enca
                    /i i 1 add def
                    exit
                } if
                cset (setb) eq {
                    % anotb . bnota before anotb => sa1 encode
                    i msglen 1 sub lt {
                        msg i get anotb
                        i 1 add bbeforea and {
                            sa1 encb
                            msg i get enca
                            /i i 1 add def
                            exit
                        } if
                    } if
                    % anotb . anotb . bnota before anotb => sa2 encode
                    i msglen 2 sub lt {
                        msg i get anotb
                        msg i 1 add get anotb and
                        i 2 add bbeforea and {
                            sa2 encb
                            msg i get enca
                            msg i 1 add get enca
                            /i i 2 add def
                            exit
                        } if
                    } if
                    % anotb => swa
                    msg i get anotb {
                        swa encb
                        /cset (seta) def
                        exit
                    } if
                    % 4 nums . b => sc2 encode
                    i msglen 4 sub lt {
                        nums 4 eq
                        setb msg i 4 add get known and {
                            sc2 encb
                            2 {
                                msg i get fn1 eq {
                                    fn1 encc
                                    /i i 1 add def
                                } {
                                    msg i 2 getinterval encc
                                    /i i 2 add def
                                } ifelse
                            } repeat
                            exit
                        } if
                    } if
                    % 6 nums . b => sc3 encode
                    i msglen 6 sub lt {
                        nums 6 eq
                        setb msg i 6 add get known and {
                            sc3 encb
                            3 {
                                msg i get fn1 eq {
                                    fn1 encc
                                    /i i 1 add def
                                } {
                                    msg i 2 getinterval encc
                                    /i i 2 add def
                                } ifelse
                            } repeat
                            exit
                        } if
                    } if
                    % 4+ even nums => swc
                    nums 4 ge nums 2 mod 0 eq and {
                        swc encb
                        /cset (setc) def
                        exit
                    } if
                    % otherwise => encode
                    msg i get encb
                    /i i 1 add def
                    exit
                } if
                cset (setc) eq {
                    % 2+ nums => encode
                    nums 2 ge {
                        msg i get fn1 eq {
                            fn1 encc
                            /i i 1 add def
                        } {
                            msg i 2 getinterval encc
                            /i i 2 add def
                        } ifelse
                        exit
                    } if
                    % b . 2+ even nums => sb1 encode
                    i msglen 1 sub lt {
                        setb msg i get known
                        i 1 add numsscr exch pop dup 2 ge exch 2 mod 0 eq and and {
                            sb1 encc
                            msg i get encb
                            /i i 1 add def
                            exit
                        } if
                    } if
                    % b . 3+ odd nums => sb2 encode
                    i msglen 1 sub lt {
                        setb msg i get known
                        i 1 add numsscr exch pop dup 3 ge exch 2 mod 1 eq and and {
                            sb2 encc
                            msg i get encb
                            msg i 1 add get encb
                            /i i 2 add def
                            exit
                        } if
                    } if
                    % b . b . 2+ even nums => sb2 encode
                    i msglen 2 sub lt {
                        setb msg i get known
                        setb msg i 1 add get known and
                        i 2 add numsscr exch pop dup 2 ge exch 2 mod 0 eq and and {
                            sb2 encc
                            msg i get encb
                            msg i 1 add get encb
                            /i i 2 add def
                            exit
                        } if
                    } if
                    % b . b . 3+ odd nums => sb3 encode
                    i msglen 3 sub lt {
                        setb msg i get known
                        setb msg i 1 add get known and
                        i 2 add numsscr exch pop dup 3 ge exch 2 mod 1 eq and and {
                            sb3 encc
                            msg i get encb
                            msg i 1 add get encb
                            msg i 2 add get encb
                            /i i 3 add def
                            exit
                        } if
                    } if
                    % b . b . b . 2+ even nums => sb3 encode
                    i msglen 3 sub lt {
                        setb msg i get known
                        setb msg i 1 add get known and
                        setb msg i 2 add get known and
                        i 3 add numsscr exch pop dup 2 ge exch 2 mod 0 eq and and {
                            sb3 encc
                            msg i get encb
                            msg i 1 add get encb
                            msg i 2 add get encb
                            /i i 3 add def
                            exit
                        } if
                    } if
                    % anotb before bnota => swa
                    i abeforeb {
                        swa encc
                        /cset (seta) def
                        exit
                    } if
                    % otherwise => swb
                    swb encc
                    /cset (setb) def
                    exit
                } if
                exit
            } loop

        } loop
        /cws cws 0 j getinterval def
    } if  % auto encoding

    % Basic metrics for the each symbol
    %     r  dcws
{
    /metrics [
        [  2    7 ]
        [  3   12 ]
        [  4   17 ]
        [  5   22 ]
        [  6   27 ]
        [  7   32 ]
        [  8   37 ]
        [  9   42 ]
        [ 10   47 ]
        [ 11   52 ]
        [ 12   57 ]
        [ 13   62 ]
        [ 14   67 ]
        [ 15   72 ]
        [ 16   77 ]
    ] def
} ctxdef

    % Select metrics of an appropriate symbol
    /urows rows def
    /i 0 def
    { % loop
        /m metrics i get def
        /r    m 0 get def        % Columns in symbol
        /dcws m 1 get def        % Data codewords in symbol
        /okay true def
        urows 0 ne urows r ne and {/okay false def} if
        cws length dcws gt {/okay false def} if
        okay {exit} if
        /i i 1 add def
    } loop

    % Extend cws to ncws codewords by addition of pad characters
    /cws [ cws aload pop dcws cws length sub {103} repeat ] def

    % Add the start character
    /cws [ r 2 sub 7 mul mode add cws aload pop ] def

    % Calculate the check characters
    0 0 1 dcws {dup 2 add exch cws exch get mul add} for
    107 mod /c1 exch def
    0 0 1 dcws {dup 1 add exch cws exch get mul add} for
    c1 dcws 2 add mul add 107 mod /c2 exch def
    /cws [ cws aload pop c1 c2 ] def

    % Create an array containing the character mappings
{
    /encs
    [ (212222) (222122) (222221) (121223) (121322) (131222) (122213)
      (122312) (132212) (221213) (221312) (231212) (112232) (122132)
      (122231) (113222) (123122) (123221) (223211) (221132) (221231)
      (213212) (223112) (312131) (311222) (321122) (321221) (312212)
      (322112) (322211) (212123) (212321) (232121) (111323) (131123)
      (131321) (112313) (132113) (132311) (211313) (231113) (231311)
      (112133) (112331) (132131) (113123) (113321) (133121) (313121)
      (211331) (231131) (213113) (213311) (213131) (311123) (311321)
      (331121) (312113) (312311) (332111) (314111) (221411) (431111)
      (111224) (111422) (121124) (121421) (141122) (141221) (112214)
      (112412) (122114) (122411) (142112) (142211) (241211) (221114)
      (413111) (241112) (134111) (111242) (121142) (121241) (114212)
      (124112) (124211) (411212) (421112) (421211) (212141) (214121)
      (412121) (111143) (111341) (131141) (114113) (114311) (411113)
      (411311) (113141) (114131) (311141) (411131) (211412) (211214)
      (211232) (211133)
    ] def

    % Start/stop character encodings
    /startencs [
        (3211) (2221) (2122) (1411) (1132) (1231) (1114) (3112)
        (3211) (2221) (2122) (1411) (1132) (1231) (1114) (3112)
    ] def
    /stopencsodd [
        (3211) (2221) (2122) (1411) (1132) (1231) (1114) (3112)
        (1132) (1231) (1114) (3112) (3211) (2221) (2122) (1411)
    ] def
    /stopencseven [
        (2122) (1411) (1132) (1231) (1114) (3112) (1132) (1231)
        (1114) (3112) (3211) (2221) (2122) (1411) (3211) (2221)
    ] def
} ctxdef

    pos -1 eq pos 10 idiv 2 mod 1 eq or {
        /stopencs stopencsodd def
    } {
        /stopencs stopencseven def
    } ifelse

    % Derive the bits for each row
    /rowbits r array def
    0 1 r 1 sub {
        /i exch def
        /sbs [
            10
            startencs i get {48 sub} forall
            1
            cws i 5 mul 5 getinterval {
                encs exch get {48 sub} forall
            } forall
            stopencs i get {48 sub} forall
            1
        ] def
        mark
        1 sbs {1 index 0 eq {{1}} {{0}} ifelse repeat} forall
        counttomark 1 sub array astore exch pop exch pop
        rowbits i 3 -1 roll put
    } for

    % Populate the bitmap
    /pixs [
        81 sepheight mul {1} repeat
        0 1 r 2 sub {
            /i exch def
            rowheight {rowbits i get aload pop} repeat
            sepheight {10 {0} repeat 70 {1} repeat 0} repeat
        } for
        rowheight {rowbits r 1 sub get aload pop} repeat
        81 sepheight mul {1} repeat
    ] def

    % Return the arguments
    <<
    /ren //renmatrix
    /pixs pixs
    /pixx 81
    /pixy pixs length 81 idiv
    /height pixs length 81 idiv 72 div
    /width 81 72 div
    /opt options
    >>

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/code16k dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER code16k--

% --BEGIN ENCODER code49--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: Code 49
% --EXAM: MULTIPLE ROWS IN CODE 49
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp code49 0.0 2022082100 261468 264326
%%BeginData:       1063 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/code49 {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /mode -1 def
    /pos -1 def
    /rows 0 def
    /rowheight 8 def
    /sepheight 1 def
    /parse false def
    /parsefnc 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

    /mode mode cvi def
    /pos pos cvi def
    /rows rows cvi def
    /rowheight rowheight cvi def
    /sepheight sepheight cvi def

    /code49 //loadctx exec

{
    /s1 -1 def /s2 -2 def /fn1 -3 def /fn2 -4 def /fn3 -5 def /ns -6 def
} ctxdef

    % Parse the input
    /fncvals <<
        /parse parse
        /parsefnc parsefnc
        (FNC1) fn1
        (FNC2) fn2
        (FNC3) fn3
    >> def
    /msg barcode fncvals //parseinput exec def
    /msglen msg length def

{
    % Character encodings
    /charmap [
        (0) (1) (2) (3) (4) (5) (6) (7) (8) (9)
        (A) (B) (C) (D) (E) (F) (G) (H) (I) (J) (K) (L) (M)
        (N) (O) (P) (Q) (R) (S) (T) (U) (V) (W) (X) (Y) (Z)
        (-) (.) ( ) ($) (/) (+) (%)
        s1  s2  fn1 fn2 fn3 ns
    ] def

    % Invert charmap to give character to value map
    /charvals 49 dict def
    0 1 48 {
        /i exch def
        charmap i get
        dup type /stringtype eq {0 get} if  % convert string to ASCII if required
        charvals exch i put
    } for

    % Shifted character encodings
    /combos
    [ (1 ) (1A) (1B) (1C) (1D) (1E) (1F) (1G) (1H) (1I) (1J) (1K) (1L) (1M) (1N) (1O)
      (1P) (1Q) (1R) (1S) (1T) (1U) (1V) (1W) (1X) (1Y) (1Z) (11) (12) (13) (14) (15)
      (  ) (16) (17) (18) ( $) ( %) (19) (10) (1-) (1.) (1$) ( +) (1/) ( -) ( .) ( /)
      ( 0) ( 1) ( 2) ( 3) ( 4) ( 5) ( 6) ( 7) ( 8) ( 9) (1+) (21) (22) (23) (24) (25)
      (26) ( A) ( B) ( C) ( D) ( E) ( F) ( G) ( H) ( I) ( J) ( K) ( L) ( M) ( N) ( O)
      ( P) ( Q) ( R) ( S) ( T) ( U) ( V) ( W) ( X) ( Y) ( Z) (27) (28) (29) (20) (2-)
      (2.) (2A) (2B) (2C) (2D) (2E) (2F) (2G) (2H) (2I) (2J) (2K) (2L) (2M) (2N) (2O)
      (2P) (2Q) (2R) (2S) (2T) (2U) (2V) (2W) (2X) (2Y) (2Z) (2$) (2/) (2+) (2%) (2 )
    ] def
    0 1 127 {
        /i exch def
        combos i get dup 0 get /c1 exch def 1 get /c2 exch def
        c1 49 eq {  % s1 char
            charvals i [ charvals s1 get charvals c2 get ] put
        } if
        c1 50 eq {  % s2 char
            charvals i [ charvals s2 get charvals c2 get ] put
        } if
    } for
} ctxdef

    /encodealpha {
        charvals exch get
        dup type /arraytype ne {1 array astore} if
        dup cws exch j exch putinterval
        length j add /j exch def
    } def

    /base48 {
        0 exch {48 sub exch 10 mul add} forall
        [ 3 1 roll exch 1 sub {dup 48 mod exch 48 idiv} repeat ]
        [ exch dup length 1 sub -1 0 {1 index exch get exch} for pop ]
        dup cws exch j exch putinterval
        length j add /j exch def
    } def

    /encodenumeric {
        /nums exch def
        /pre nums length dup 5 mod dup 2 ne {sub} {sub 5 sub} ifelse def
        0 5 pre 1 sub {nums exch 5 getinterval 3 exch base48} for
        /nums nums pre nums length pre sub getinterval def
        nums length
        dup 1 eq {nums i get encodealpha} if
        dup 3 eq {2 nums base48} if
        dup 4 eq {3 [49 48 nums aload pop] base48} if
        7 eq {
            3 [49 48 nums 0 4 getinterval aload pop] base48
            2 nums 4 3 getinterval base48
        } if
    } def

    % Pre-compute alphanumeric and numeric runlengths
    /numericruns [ msglen {0} repeat 0 ] def
    msglen 1 sub -1 0 {
        /i exch def
        msg i get
        dup 48 ge exch 57 le and {
            numericruns i numericruns i 1 add get 1 add put
        } {
            numericruns i 0 put
        } ifelse
    } for

    % Autoselect mode
    mode -1 eq {
        {  % common exit
            pos -1 ne {/mode 3 def exit} if
            numericruns 0 get 5 ge {/mode 2 def exit} if
            charvals msg 0 get get
            dup type /arraytype ne {pop /mode 0 def exit} if
            0 get 43 eq {4} {5} ifelse /mode exch def
            exit
        } loop
    } if

    /cws msglen 2 mul 1 add array def
    /method (alpha) def /i -1 def /j -1 def

{
    /posval [
        12 22
        13 23 33
        14 24 34 44
        15 25 35 45 55
        16 26 36 46 56 66
        17 27 37 47 57 67 77
        18 28 38 48 58 68 78 88
        19 29 39 49 59 69 79 89 99
    ] def
} ctxdef

    % Handle start for each mode
    mode 0 eq mode 1 eq or {/method (alpha) def /i 0 def /j 0 def} if
    mode 2 eq {/method (numeric) def /i 0 def /j 0 def} if
    mode 3 eq {
        cws 0 0 1 43 {dup posval exch get pos ne {pop} if} for 1 add put
        /method (alpha) def /i 0 def /j 1 def
    } if
    mode 4 eq mode 5 eq or {
        cws 0 charvals msg 0 get get 1 get put
        /method (alpha) def /i 1 def /j 1 def
    } if

    % Encode remainder
    {
        i msglen eq {exit} if
        {  % not a loop but common exit point
            method (alpha) eq {
                numericruns i get 5 ge {
                    ns encodealpha
                    /method (numeric) def
                    exit
                } if
                msg i get encodealpha
                /i i 1 add def
                exit
            } if
            method (numeric) eq {
                numericruns i get 5 lt {
                    ns encodealpha
                    /method (alpha) def
                    exit
                } if
                msg i numericruns i get getinterval encodenumeric
                /i i numericruns i get add def
                exit
            } if
        } loop
    } loop
    /cws cws 0 j getinterval def

    % Basic metrics for the each symbol
    %     r dcws
{
    /metrics [
        [ 2    9 ]
        [ 3   16 ]
        [ 4   23 ]
        [ 5   30 ]
        [ 6   37 ]
        [ 7   42 ]
        [ 8   49 ]
    ] def
} ctxdef

    % Select metrics of an appropriate symbol
    /urows rows def
    /i 0 def
    { % loop
        /m metrics i get def
        /r    m 0 get def        % Columns in symbol
        /dcws m 1 get def        % Data codewords in symbol
        /okay true def
        urows 0 ne urows r ne and {/okay false def} if
        cws length dcws gt {/okay false def} if
        okay {exit} if
        /i i 1 add def
    } loop

    % Extend cws to ncws codewords by addition of pad characters
    /cws [ cws aload pop dcws cws length sub {48} repeat ] def

    % Populate code character array and add row check characters
    /ccs r 8 mul array def
    /j 0 def
    0 1 r 2 sub {
        /i exch def
        /cc cws j 7 getinterval def
        ccs i 8 mul cc putinterval
        ccs i 8 mul 7 add 0 cc {add} forall 49 mod put
        /j j 7 add def
    } for
    j dcws lt {
        ccs ccs length 8 sub cws j dcws j sub getinterval putinterval
    } if

    % Place row count character
    /cr7 r 2 sub 7 mul mode add def
    ccs ccs length 2 sub cr7 put

    % Calculate the symbol check characters
{
    [  1  9 31 26  2 12 17 23 37 18 22  6 27 44 15 43 39
      11 13  5 41 33 36  8  4 32  3 19 40 25 29 10 24 30 ]
    dup [ exch 20 exch 0 32 getinterval aload pop ] /weightx exch def
    dup [ exch 16 exch 1 32 getinterval aload pop ] /weighty exch def
        [ exch 38 exch 2 32 getinterval aload pop ] /weightz exch def
} ctxdef
    /calccheck {
        /weights exch def
        /score 0 def
        0 1 r 1 sub 8 mul 2 idiv 1 sub {
            /i exch def
            ccs i 2 mul get 49 mul ccs i 2 mul 1 add get add
            weights i 1 add get mul /score exch score add def
        } for
        score
    } def
    /lastrow ccs ccs length 8 sub 8 getinterval def

    % wr1 check character
    r 7 ge {
        cr7 weightz 0 get mul weightz calccheck add 2401 mod
        dup 49 idiv exch 49 mod 2 array astore
        lastrow 0 3 -1 roll putinterval
    } if
    /wr1 lastrow 0 get 49 mul lastrow 1 get add def

    % wr2 check character
    cr7 weighty 0 get mul weighty calccheck add
    wr1 weighty r 4 mul 3 sub get mul add
    2401 mod dup /wr2 exch def
    dup 49 idiv exch 49 mod 2 array astore
    lastrow 2 3 -1 roll putinterval

    % wr3 check character
    cr7 weightx 0 get mul weightx calccheck add
    wr1 weightx r 4 mul 3 sub get mul add
    wr2 weightx r 4 mul 2 sub get mul add
    2401 mod
    dup 49 idiv exch 49 mod 2 array astore
    lastrow 4 3 -1 roll putinterval

    % Place last row check character
    ccs ccs length 8 sub 7 getinterval 0 exch {add} forall 49 mod
    ccs ccs length 1 sub 3 -1 roll put

{
    /patterns [
        [  % Even parity
            (11521132) (25112131) (14212132) (25121221) (14221222) (12412132) (23321221)
            (12421222) (21521221) (15112222) (15121312) (13312222) (24221311) (13321312)
            (11512222) (22421311) (11521312) (25112311) (14212312) (23312311) (12412312)
            (21512311) (16121131) (14321131) (12521131) (15212131) (15221221) (13412131)
            (13421221) (11612131) (16112221) (16121311) (14312221) (14321311) (12512221)
            (12521311) (15212311) (13412311) (11612311) (11131135) (31131133) (51131131)
            (21122134) (41122132) (21131224) (41131222) (11113135) (31113133) (51113131)
            (11122225) (31122223) (51122221) (11131315) (31131313) (51131311) (21113224)
            (41113222) (21122314) (41122312) (11113315) (31113313) (51113311) (12131134)
            (32131132) (21231133) (41231131) (22122133) (42122131) (11222134) (22131223)
            (42131221) (11231224) (31231222) (12113134) (32113132) (12122224) (32122222)
            (12131314) (32131312) (21231313) (41231311) (22113223) (42113221) (11213224)
            (22122313) (42122311) (11222314) (31222312) (12113314) (32113312) (21213313)
            (41213311) (13131133) (33131131) (22231132) (11331133) (31331131) (23122132)
            (12222133) (23131222) (12231223) (32231221) (21331222) (13113133) (33113131)
            (13122223) (33122221) (11313133) (13131313) (33131311) (11322223) (22231312)
            (11331313) (31331311) (23113222) (12213223) (23122312) (12222313) (32222311)
            (21322312) (13113313) (33113311) (22213312) (11313313) (31313311) (14131132)
            (23231131) (12331132) (21431131) (24122131) (13222132) (24131221) (13231222)
            (11422132) (22331221) (11431222) (14113132) (14122222) (12313132) (14131312)
            (12322222) (23231311) (12331312) (21431311) (24113221) (13213222) (24122311)
            (13222312) (11413222) (22322311) (11422312) (14113312) (23213311) (12313312)
            (21413311) (15131131) (13331131) (14222131) (14231221) (12422131) (12431221)
            (15113131) (15122221) (13313131) (15131311) (13322221) (11513131) (13331311)
            (11522221) (14213221) (14222311) (12413221) (12422311) (15113311) (13313311)
            (11513311) (11141134) (31141132) (21132133) (41132131) (21141223) (41141221)
            (11123134) (31123132) (11132224) (31132222) (11141314) (31141312) (21114133)
            (41114131) (21123223) (41123221) (21132313) (41132311) (11114224) (31114222)
            (11123314) (31123312) (21114313) (41114311) (12141133) (32141131) (21241132)
            (22132132) (11232133) (22141222) (11241223) (31241221) (12123133) (32123131)
            (12132223) (32132221) (12141313) (32141311) (21241312) (22114132) (11214133)
            (22123222) (11223223) (22132312) (11232313) (31232311) (12114223) (32114221)
            (12123313) (32123311) (21223312) (22114312) (11214313) (31214311) (13141132)
            (22241131) (11341132) (23132131) (12232132) (23141221) (12241222) (21341221)
            (13123132) (13132222) (11323132) (13141312) (11332222) (22241311) (11341312)
            (23114131) (12214132) (23123221) (12223222) (23132311) (12232312) (21332311)
            (13114222) (13123312) (11314222) (22223311) (11323312) (23114311) (12214312)
            (21314311) (14141131) (12341131) (13232131) (13241221) (11432131) (14123131)
            (14132221) (12323131) (14141311) (12332221) (12341311) (13214131) (13223221)
            (11414131) (13232311) (11423221) (11432311) (14114221) (14123311) (12314221)
            (12323311) (13214311) (11414311) (11151133) (31151131) (21142132) (21151222)
            (11133133) (31133131) (11142223) (31142221) (11151313) (31151311) (21124132)
            (21133222) (21142312) (11115133) (31115131) (11124223) (31124221) (11133313)
            (31133311) (21115222) (21124312) (12151132) (21251131) (22142131) (11242132)
            (22151221) (11251222) (12133132) (12142222) (12151312) (21251311) (22124131)
            (11224132) (22133221) (11233222) (22142311) (11242312) (12115132) (12124222)
            (12133312) (21233311) (22115221) (11215222) (22124311) (11224312) (13151131)
            (12242131) (12251221) (13133131) (13142221) (11333131) (13151311) (11342221)
            (12224131) (12233221) (12242311) (13115131) (13124221) (11315131) (13133311)
            (11324221) (11333311) (12215221) (12224311) (11161132) (21152131) (21161221)
            (11143132) (11152222) (11161312) (21134131) (21143221) (21152311) (11125132)
            (11134222) (11143312) (21116131) (21125221) (21134311) (12161131) (11252131)
            (12143131) (12152221) (12161311) (11234131) (11243221) (11252311) (12125131)
            (12134221) (12143311) (11216131) (11225221) (11234311) (11111236) (31111234)
            (51111232) (21111325) (41111323) (61111321) (11111416) (31111414) (51111412)
            (31211143) (51211141) (12111235) (32111233) (52111231) (21211234) (41211232)
            (22111324) (42111322) (11211325) (31211323) (51211321) (12111415) (32111413)
            (52111411) (21211414) (41211412) (12211144) (32211142) (21311143) (41311141)
            (13111234) (33111232) (22211233) (42211231) (11311234) (31311232) (23111323)
            (43111321) (12211324) (32211322) (21311323) (41311321) (13111414) (33111412)
            (22211413) (42211411) (11311414) (31311412) (13211143) (33211141) (22311142)
            (11411143) (31411141) (14111233) (34111231) (23211232) (12311233) (32311231)
            (21411232) (24111322) (13211323) (33211321) (22311322) (11411323) (31411321)
            (14111413) (34111411) (23211412) (12311413) (32311411) (21411412) (14211142)
            (23311141) (12411142) (21511141) (15111232) (24211231) (13311232) (22411231)
            (11511232) (25111321) (14211322) (23311321) (12411322) (21511321) (15111412)
            (24211411) (13311412) (22411411) (11511412) (15211141) (13411141) (11611141)
            (16111231) (14311231) (12511231) (15211321) (13411321) (11611321) (16111411)
            (14311411) (12511411) (21121144) (41121142) (11112145) (31112143) (51112141)
            (11121235) (31121233) (51121231) (21112234) (41112232) (21121324) (41121322)
            (11112325) (31112323) (51112321) (11121415) (31121413) (51121411) (21112414)
            (41112412) (22121143) (42121141) (11221144) (31221142) (12112144) (32112142)
            (12121234) (32121232) (21221233) (41221231) (22112233) (42112231) (11212234)
            (22121323) (42121321) (11221324) (31221322) (12112324) (32112322) (12121414)
            (32121412) (21221413) (41221411) (22112413) (42112411) (11212414) (31212412)
            (23121142) (12221143) (32221141) (21321142) (13112143) (33112141) (13121233)
            (33121231) (11312143) (22221232) (11321233) (31321231) (23112232) (12212233)
            (23121322) (12221323) (32221321) (21321322) (13112323) (33112321) (13121413)
            (33121411) (11312323) (22221412) (11321413) (31321411) (23112412) (12212413)
            (32212411) (21312412) (24121141) (13221142) (22321141) (11421142) (14112142)
            (14121232) (12312142) (23221231) (12321232) (21421231) (24112231) (13212232)
            (24121321) (13221322) (11412232) (22321321) (11421322) (14112322) (14121412)
            (12312322) (23221411) (12321412) (21421411) (24112411) (13212412) (22312411)
            (11412412) (14221141) (12421141) (15112141) (15121231) (13312141) (13321231)
            (11512141) (11521231) (14212231) (14221321) (12412231) (12421321) (15112321)
            (15121411) (13312321) (13321411) (11512321) (11521411) (14212411) (12412411)
            (21131143) (41131141) (11122144) (31122142) (11131234) (31131232) (21113143)
            (41113141) (21122233) (41122231) (21131323) (41131321) (11113234) (31113232)
            (11122324) (31122322) (11131414) (31131412) (21113323) (41113321) (21122413)
            (41122411) (11113414) (31113412) (22131142) (11231143) (31231141) (12122143)
            (32122141) (12131233) (32131231) (21231232) (22113142) (11213143) (22122232)
            (11222233) (22131322) (11231323) (31231321) (12113233) (32113231) (12122323)
            (32122321) (12131413) (32131411) (21231412) (22113322) (11213323) (22122412)
            (11222413) (31222411) (12113413) (32113411) (21213412) (23131141) (12231142)
            (21331141) (13122142) (13131232) (11322142) (22231231) (11331232) (23113141)
            (12213142) (23122231) (12222232) (23131321) (12231322) (21331321) (13113232)
            (13122322) (11313232) (13131412) (11322322) (22231411) (11331412) (23113321)
            (12213322) (23122411) (12222412) (21322411) (13113412) (22213411) (11313412)
            (13231141) (11431141) (14122141) (14131231) (12322141) (12331231) (13213141)
            (13222231) (11413141) (13231321) (11422231) (11431321) (14113231) (14122321)
            (12313231) (14131411) (12322321) (12331411) (13213321) (13222411) (11413321)
            (11422411) (14113411) (12313411) (21141142) (11132143) (31132141) (11141233)
            (31141231) (21123142) (21132232) (21141322) (11114143) (31114141) (11123233)
            (31123231) (11132323) (31132321) (11141413) (31141411) (21114232) (21123322)
            (21132412) (11114323) (31114321) (11123413) (31123411) (22141141) (11241142)
            (12132142) (12141232) (21241231) (22123141) (11223142) (22132231) (11232232)
            (22141321) (11241322) (12114142) (12123232) (12132322) (12141412) (21241411)
            (22114231) (11214232) (22123321) (11223322) (22132411) (11232412) (12114322)
            (12123412) (21223411) (12241141) (13132141) (13141231) (11332141) (11341231)
            (12223141) (12232231) (12241321) (13114141) (13123231) (11314141) (13132321)
            (11323231) (13141411) (11332321) (11341411) (12214231) (12223321) (12232411)
            (13114321) (13123411) (11314321) (11323411) (21151141) (11142142) (11151232)
            (21133141) (21142231) (21151321) (11124142) (11133232) (11142322) (11151412)
            (21115141) (21124231) (21133321) (21142411) (11115232) (11124322) (11133412)
            (11251141) (12142141) (12151231) (11233141) (11242231) (11251321) (12124141)
            (12133231) (12142321) (12151411) (11215141) (11224231) (11233321) (11242411)
            (12115231) (12124321) (12133411) (11152141) (11161231) (11134141) (11143231)
            (11152321) (11161411) (11116141) (11125231) (11134321) (11143411) (21111244)
            (41111242) (11111335) (31111333) (51111331) (21111424) (41111422) (11111515)
            (31111513) (51111511) (21211153) (41211151) (22111243) (42111241) (11211244)
            (31211242) (12111334) (32111332) (21211333) (41211331) (22111423) (42111421)
            (11211424) (31211422) (12111514) (32111512) (21211513) (41211511) (22211152)
            (11311153) (31311151) (23111242) (12211243) (32211241) (21311242) (13111333)
            (33111331) (22211332) (11311333) (31311331) (23111422) (12211423) (32211421)
            (21311422) (13111513) (33111511) (22211512) (11311513) (31311511) (23211151)
            (12311152) (21411151) (24111241) (13211242) (22311241) (11411242) (14111332)
            (23211331) (12311332) (21411331) (24111421) (13211422) (22311421) (11411422)
            (14111512) (23211511) (12311512) (21411511) (13311151) (11511151) (14211241)
            (12411241) (15111331) (13311331) (11511331) (14211421) (12411421) (15111511)
            (13311511) (11511511) (31121152) (21112153) (41112151) (21121243) (41121241)
            (11112244) (31112242) (11121334) (31121332) (21112333) (41112331) (21121423)
            (41121421) (11112424) (31112422) (11121514) (31121512) (21112513) (41112511)
            (12121153) (32121151) (21221152) (22112152) (11212153) (22121242) (11221243)
            (31221241) (12112243) (32112241) (12121333) (32121331) (21221332) (22112332)
            (11212333) (22121422) (11221423) (31221421) (12112423) (32112421) (12121513)
            (32121511) (21221512) (22112512) (11212513) (31212511) (13121152) (22221151)
            (11321152) (23112151) (12212152) (23121241) (12221242) (21321241) (13112242)
            (13121332) (11312242) (22221331) (11321332) (23112331) (12212332) (23121421)
            (12221422) (21321421) (13112422) (13121512) (11312422) (22221511) (11321512)
            (23112511) (12212512) (21312511) (14121151) (12321151) (13212151) (13221241)
            (11412151) (11421241) (14112241) (14121331) (12312241) (12321331) (13212331)
            (13221421) (11412331) (11421421) (14112421) (14121511) (12312421) (12321511)
            (13212511) (11412511) (11131153) (31131151) (21122152) (21131242) (11113153)
            (31113151) (11122243) (31122241) (11131333) (31131331) (21113242) (21122332)
            (21131422) (11113333) (31113331) (11122423) (31122421) (11131513) (31131511)
            (21113422) (21122512) (12131152) (21231151) (22122151) (11222152) (22131241)
            (11231242) (12113152) (12122242) (12131332) (21231331) (22113241) (11213242)
            (22122331) (11222332) (22131421) (11231422) (12113332) (12122422) (12131512)
            (21231511) (22113421) (11213422) (22122511) (11222512) (13131151) (11331151)
            (12222151) (12231241) (13113151) (13122241) (11313151) (13131331) (11322241)
            (11331331) (12213241) (12222331) (12231421) (13113331) (13122421) (11313331)
            (13131511) (11322421) (11331511) (12213421) (12222511) (11141152) (21132151)
            (21141241) (11123152) (11132242) (11141332) (21114151) (21123241) (21132331)
            (21141421) (11114242) (11123332) (11132422) (11141512) (21114331) (21123421)
            (21132511) (12141151) (11232151) (11241241) (12123151) (12132241) (12141331)
            (11214151) (11223241) (11232331) (11241421) (12114241) (12123331) (12132421)
            (12141511) (11214331) (11223421) (11232511) (11151151) (11133151) (11142241)
            (11151331) (11115151) (11124241) (11133331) (11142421) (11151511) (11111254)
            (31111252) (21111343) (41111341) (11111434) (31111432) (21111523) (41111521)
            (11111614) (31111612) (31211161) (12111253) (32111251) (21211252) (22111342)
            (11211343) (31211341) (12111433) (32111431) (21211432) (22111522) (11211523)
            (31211521) (12111613) (32111611) (21211612) (12211162) (21311161) (13111252)
            (22211251) (11311252) (23111341) (12211342) (21311341) (13111432) (22211431)
            (11311432) (23111521) (12211522) (21311521) (13111612) (22211611) (11311612)
            (13211161) (11411161) (14111251) (12311251) (13211341) (11411341) (14111431)
            (12311431) (13211521) (11411521) (14111611) (12311611) (21121162) (11112163)
            (31112161) (11121253) (31121251) (21112252) (21121342) (11112343) (31112341)
            (11121433) (31121431) (21112432) (21121522) (11112523) (31112521) (11121613)
            (31121611) (22121161) (11221162) (12112162) (12121252) (21221251) (22112251)
            (11212252) (22121341) (11221342) (12112342) (12121432) (21221431) (22112431)
            (11212432) (22121521) (11221522) (12112522) (12121612) (21221611) (12221161)
            (13112161) (13121251) (11312161) (11321251) (32121115) (52121113) (21221116)
            (41221114) (61221112) (22112116) (42112114) (31212115) (51212113) (13121116)
            (33121114) (22221115) (42221113) (11321116) (31321114) (51321112) (23112115)
            (43112113) (12212116) (32212114) (52212112) (21312115) (41312113) (61312111)
            (14121115) (34121113) (23221114) (43221112) (12321115) (32321113) (52321111)
            (21421114) (41421112) (24112114) (13212115) (33212113) (22312114) (42312112)
            (11412115) (31412113) (51412111) (15121114) (24221113) (13321114) (33321112)
            (22421113) (42421111) (11521114) (31521112) (25112113) (14212114) (34212112)
            (23312113) (43312111) (12412114) (32412112) (21512113) (41512111) (16121113)
            (25221112) (14321113) (34321111) (23421112) (12521113) (32521111) (15212113)
            (24312112) (13412113) (33412111) (22512112) (11612113) (31612111) (31131115)
            (51131113) (21122116) (41122114) (61122112) (31113115) (51113113) (12131116)
            (32131114) (52131112) (21231115) (41231113) (61231111) (22122115) (42122113)
            (11222116) (31222114) (51222112) (12113116) (32113114) (52113112) (21213115)
            (41213113) (61213111) (13131115) (33131113) (22231114) (42231112) (11331115)
            (31331113) (51331111) (23122114) (43122112) (12222115) (32222113) (52222111)
            (21322114) (41322112) (13113115) (33113113) (22213114) (42213112) (11313115)
            (31313113) (51313111) (14131114) (34131112) (23231113) (43231111) (12331114)
            (32331112) (21431113) (41431111) (24122113) (13222114) (33222112) (22322113)
            (42322111) (11422114) (31422112) (14113114) (34113112) (23213113) (43213111)
            (12313114) (32313112) (21413113) (41413111) (15131113) (24231112) (13331113)
            (33331111) (22431112) (25122112) (14222113) (34222111) (23322112) (12422113)
            (32422111) (21522112) (15113113) (24213112) (13313113) (33313111) (22413112)
            (11513113) (31513111) (16131112) (25231111) (14331112) (23431111) (15222112)
            (24322111) (13422112) (22522111) (16113112) (25213111) (14313112) (23413111)
            (12513112) (21613111) (11141116) (31141114) (51141112) (21132115) (41132113)
            (61132111) (11123116) (31123114) (51123112) (21114115) (41114113) (61114111)
            (12141115) (32141113) (52141111) (21241114) (41241112) (22132114) (42132112)
            (11232115) (31232113) (51232111) (12123115) (32123113) (52123111) (21223114)
            (41223112) (22114114) (42114112) (11214115) (31214113) (51214111) (13141114)
            (33141112) (22241113) (42241111) (11341114) (31341112) (23132113) (43132111)
            (12232114) (32232112) (21332113) (41332111) (13123114) (33123112) (22223113)
            (42223111) (11323114) (31323112) (23114113) (43114111) (12214114) (32214112)
            (21314113) (41314111) (14141113) (34141111) (23241112) (12341113) (32341111)
            (24132112) (13232113) (33232111) (22332112) (11432113) (31432111) (14123113)
            (34123111) (23223112) (12323113) (32323111) (21423112) (24114112) (13214113)
            (33214111) (22314112) (11414113) (31414111) (15141112) (24241111) (13341112)
            (25132111) (14232112) (23332111) (12432112) (15123112) (24223111) (13323112)
            (22423111) (11523112) (25114111) (14214112) (23314111) (12414112) (21514111)
            (16141111) (14341111) (15232111) (13432111) (16123111) (14323111) (12523111)
            (15214111) (13414111) (11614111) (11151115) (31151113) (51151111) (21142114)
            (41142112) (11133115) (31133113) (51133111) (21124114) (41124112) (11115115)
            (31115113) (51115111) (12151114) (32151112) (21251113) (41251111) (22142113)
            (42142111) (11242114) (31242112) (12133114) (32133112) (21233113) (41233111)
            (22124113) (42124111) (11224114) (31224112) (12115114) (32115112) (21215113)
            (41215111) (13151113) (33151111) (22251112) (23142112) (12242113) (32242111)
            (21342112) (13133113) (33133111) (22233112) (11333113) (31333111) (23124112)
            (12224113) (32224111) (21324112) (13115113) (33115111) (22215112) (11315113)
            (31315111) (14151112) (23251111) (24142111) (13242112) (22342111) (14133112)
            (23233111) (12333112) (21433111) (24124111) (13224112) (22324111) (11424112)
            (14115112) (23215111) (12315112) (21415111) (15151111) (14242111) (15133111)
            (13333111) (14224111) (12424111) (15115111) (13315111) (11515111) (11161114)
            (31161112) (21152113) (41152111) (11143114) (31143112) (21134113) (41134111)
            (11125114) (31125112) (21116113) (41116111) (12161113) (32161111) (22152112)
            (11252113) (31252111) (12143113) (32143111) (21243112) (22134112) (11234113)
            (31234111) (12125113) (32125111) (21225112) (22116112) (11216113) (31216111)
            (13161112) (23152111) (12252112) (13143112) (22243111) (11343112) (23134111)
            (12234112) (21334111) (13125112) (22225111) (11325112) (23116111) (12216112)
            (21316111) (14161111) (13252111) (14143111) (12343111) (13234111) (11434111)
            (14125111) (12325111) (13216111) (11416111) (31111216) (51111214) (31211125)
            (51211123) (32111215) (52111213) (21211216) (41211214) (61211212) (12211126)
            (32211124) (52211122) (21311125) (41311123) (61311121) (13111216) (33111214)
            (22211215) (42211213) (11311216) (31311214) (51311212) (13211125) (33211123)
            (22311124) (42311122) (11411125) (31411123) (51411121) (14111215) (34111213)
            (23211214) (43211212) (12311215) (32311213) (52311211) (21411214) (41411212)
            (14211124) (34211122) (23311123) (43311121) (12411124) (32411122) (21511123)
            (41511121) (15111214) (24211213) (13311214) (33311212) (22411213) (42411211)
            (11511214) (31511212) (15211123) (24311122) (13411123) (33411121) (22511122)
            (11611123) (31611121) (16111213) (25211212) (14311213) (34311211) (23411212)
            (12511213) (32511211) (21611212) (21121126) (41121124) (61121122) (31112125)
            (51112123) (31121215) (51121213) (21112216) (41112214) (61112212) (22121125)
            (42121123) (11221126) (31221124) (51221122) (12112126) (32112124) (52112122)
            (12121216) (32121214) (52121212) (21221215) (41221213) (61221211) (22112215)
            (42112213) (11212216) (31212214) (51212212) (23121124) (43121122) (12221125)
            (32221123) (52221121) (21321124) (41321122) (13112125) (33112123) (13121215)
            (33121213) (11312125) (22221214) (42221212) (11321215) (31321213) (51321211)
            (23112214) (43112212) (12212215) (32212213) (52212211) (21312214) (41312212)
            (24121123) (13221124) (33221122) (22321123) (42321121) (11421124) (31421122)
            (14112124) (34112122) (14121214) (34121212) (12312124) (23221213) (43221211)
            (12321214) (32321212) (21421213) (41421211) (24112213) (13212214) (33212212)
            (22312213) (42312211) (11412214) (31412212) (25121122) (14221123) (34221121)
            (23321122) (12421123) (32421121) (21521122) (15112123) (15121213) (13312123)
            (24221212) (13321213) (33321211) (11512123) (22421212) (11521213) (31521211)
            (25112212) (14212213) (34212211) (23312212) (12412213) (32412211) (21512212)
            (15221122) (24321121) (13421122) (22521121) (16112122) (16121212) (14312122)
            (25221211) (14321212) (12512122) (23421211) (12521212) (15212212) (24312211)
            (13412212) (22512211) (11612212) (21131125) (41131123) (61131121) (11122126)
            (31122124) (51122122) (11131216) (31131214) (51131212) (21113125) (41113123)
            (61113121) (21122215) (41122213) (61122211) (11113216) (31113214) (51113212)
            (22131124) (42131122) (11231125) (31231123) (51231121) (12122125) (32122123)
            (52122121) (12131215) (32131213) (52131211) (21231214) (41231212) (22113124)
            (42113122) (11213125) (22122214) (42122212) (11222215) (31222213) (51222211)
            (12113215) (32113213) (52113211) (21213214) (41213212) (23131123) (43131121)
            (12231124) (32231122) (21331123) (41331121) (13122124) (33122122) (13131214)
            (33131212) (11322124) (22231213) (42231211) (11331214) (31331212) (23113123)
            (43113121) (12213124) (23122213) (43122211) (12222214) (32222212) (21322213)
            (41322211) (13113214) (33113212) (22213213) (42213211) (11313214) (31313212)
            (24131122) (13231123) (33231121) (22331122) (11431123) (31431121) (14122123)
            (34122121) (14131213) (34131211) (12322123) (23231212) (12331213) (32331211)
            (21431212) (24113122) (13213123) (24122212) (13222213) (33222211) (11413123)
            (22322212) (11422213) (31422211) (14113213) (34113211) (23213212) (12313213)
            (32313211) (21413212) (25131121) (14231122) (23331121) (12431122) (15122122)
            (15131212) (13322122) (24231211) (13331212) (11522122) (22431211) (25113121)
            (14213122) (25122211) (14222212) (12413122) (23322211) (12422212) (21522211)
            (15113212) (24213211) (13313212) (22413211) (11513212) (15231121) (13431121)
            (16122121) (16131211) (14322121) (14331211) (12522121) (15213121) (15222211)
            (13413121) (13422211) (11613121) (16113211) (14313211) (12513211) (21141124)
            (41141122) (11132125) (31132123) (51132121) (11141215) (31141213) (51141211)
            (21123124) (41123122) (21132214) (41132212) (11114125) (31114123) (51114121)
            (11123215) (31123213) (51123211) (21114214) (41114212) (22141123) (42141121)
            (11241124) (31241122) (12132124) (32132122) (12141214) (32141212) (21241213)
            (41241211) (22123123) (42123121) (11223124) (22132213) (42132211) (11232214)
            (31232212) (12114124) (32114122) (12123214) (32123212) (21223213) (41223211)
            (22114213) (42114211) (11214214) (31214212) (23141122) (12241123) (32241121)
            (21341122) (13132123) (33132121) (13141213) (33141211) (11332123) (22241212)
            (11341213) (31341211) (23123122) (12223123) (23132212) (12232213) (32232211)
            (21332212) (13114123) (33114121) (13123213) (33123211) (11314123) (22223212)
            (11323213) (31323211) (23114212) (12214213) (32214211) (21314212) (24141121)
            (13241122) (22341121) (14132122) (14141212) (12332122) (23241211) (12341212)
            (24123121) (13223122) (24132211) (13232212) (11423122) (22332211) (11432212)
            (14114122) (14123212) (12314122) (23223211) (12323212) (21423211) (24114211)
            (13214212) (22314211) (11414212) (14241121) (15132121) (15141211) (13332121)
            (13341211) (14223121) (14232211) (12423121) (12432211) (15114121) (15123211)
            (13314121) (13323211) (11514121) (11523211) (14214211) (12414211) (21151123)
            (41151121) (11142124) (31142122) (11151214) (31151212) (21133123) (41133121)
            (21142213) (41142211) (11124124) (31124122) (11133214) (31133212) (21115123)
            (41115121) (21124213) (41124211) (11115214) (31115212) (22151122) (11251123)
            (31251121) (12142123) (32142121) (12151213) (32151211) (21251212) (22133122)
            (11233123) (22142212) (11242213) (31242211) (12124123) (32124121) (12133213)
            (32133211) (21233212) (22115122) (11215123) (22124212) (11224213) (31224211)
            (12115213) (32115211) (21215212) (23151121) (12251122) (13142122) (13151212)
            (11342122) (22251211) (23133121) (12233122) (23142211) (12242212) (21342211)
            (13124122) (13133212) (11324122) (22233211) (11333212) (23115121) (12215122)
            (23124211) (12224212) (21324211) (13115212) (22215211) (11315212) (13251121)
            (14142121) (14151211) (12342121) (13233121) (13242211) (11433121) (14124121)
            (14133211) (12324121) (12333211) (13215121) (13224211) (11415121) (11424211)
            (14115211) (12315211) (21161122) (11152123) (31152121) (11161213) (31161211)
            (21143122) (21152212) (11134123) (31134121) (11143213) (31143211) (21125122)
            (21134212) (11116123) (31116121) (11125213) (31125211) (22161121) (12152122)
            (12161212) (22143121) (11243122) (22152211) (11252212) (12134122) (12143212)
            (21243211) (22125121) (11225122) (22134211) (11234212) (12116122) (12125212)
            (21225211) (13152121) (13161211) (12243121) (12252211) (13134121) (13143211)
            (11334121) (11343211) (12225121) (12234211) (13116121) (13125211) (11316121)
            (11325211) (21111226) (41111224) (61111222) (31111315) (51111313) (21211135)
            (41211133) (61211131) (22111225) (42111223) (11211226) (31211224) (51211222)
            (12111316) (32111314) (52111312) (21211315) (41211313) (61211311) (22211134)
            (42211132) (11311135) (31311133) (51311131) (23111224) (43111222) (12211225)
            (32211223) (52211221) (21311224) (41311222) (13111315) (33111313) (22211314)
            (42211312) (11311315) (31311313) (51311311) (23211133) (43211131) (12311134)
            (32311132) (21411133) (41411131) (24111223) (13211224) (33211222) (22311223)
            (42311221) (11411224) (31411222) (14111314) (34111312) (23211313) (43211311)
            (12311314) (32311312) (21411313) (41411311) (24211132) (13311133) (33311131)
            (22411132) (11511133) (31511131) (25111222) (14211223) (34211221) (23311222)
            (12411223) (32411221) (21511222) (15111313) (24211312) (13311313) (33311311)
            (22411312) (11511313) (31511311) (25211131) (14311132) (23411131) (12511132)
            (21611131) (15211222) (24311221) (13411222) (22511221) (11611222) (16111312)
            (25211311) (14311312) (23411311) (12511312) (21611311) (31121134) (51121132)
            (21112135) (41112133) (61112131) (21121225) (41121223) (61121221) (11112226)
            (31112224) (51112222) (11121316) (31121314) (51121312) (21112315) (41112313)
            (61112311) (12121135) (32121133) (52121131) (21221134) (41221132) (22112134)
            (42112132) (11212135) (22121224) (42121222) (11221225) (31221223) (51221221)
            (12112225) (32112223) (52112221) (12121315) (32121313) (52121311) (21221314)
            (41221312) (22112314) (42112312) (11212315) (31212313) (51212311) (13121134)
            (33121132) (22221133) (42221131) (11321134) (31321132) (23112133) (43112131)
            (12212134) (23121223) (43121221) (12221224) (32221222) (21321223) (41321221)
            (13112224) (33112222) (13121314) (33121312) (11312224) (22221313) (42221311)
            (11321314) (31321312) (23112313) (43112311) (12212314) (32212312) (21312313)
            (41312311) (14121133) (34121131) (23221132) (12321133) (32321131) (21421132)
            (24112132) (13212133) (24121222) (13221223) (33221221) (11412133) (22321222)
            (11421223) (31421221) (14112223) (34112221) (14121313) (34121311) (12312223)
            (23221312) (12321313) (32321311) (21421312) (24112312) (13212313) (33212311)
            (22312312) (11412313) (31412311) (15121132) (24221131) (13321132) (22421131)
        ] [  % Odd parity
            (22121116) (42121114) (31221115) (51221113) (32112115) (52112113) (21212116)
            (41212114) (61212112) (23121115) (43121113) (12221116) (32221114) (52221112)
            (21321115) (41321113) (61321111) (13112116) (33112114) (22212115) (42212113)
            (11312116) (31312114) (51312112) (24121114) (13221115) (33221113) (22321114)
            (42321112) (11421115) (31421113) (51421111) (14112115) (34112113) (23212114)
            (43212112) (12312115) (32312113) (52312111) (21412114) (41412112) (25121113)
            (14221114) (34221112) (23321113) (43321111) (12421114) (32421112) (21521113)
            (41521111) (15112114) (24212113) (13312114) (33312112) (22412113) (42412111)
            (11512114) (31512112) (15221113) (24321112) (13421113) (33421111) (22521112)
            (16112113) (25212112) (14312113) (34312111) (23412112) (12512113) (32512111)
            (21612112) (21131116) (41131114) (61131112) (31122115) (51122113) (21113116)
            (41113114) (61113112) (22131115) (42131113) (11231116) (31231114) (51231112)
            (12122116) (32122114) (52122112) (21222115) (41222113) (61222111) (22113115)
            (42113113) (11213116) (31213114) (51213112) (23131114) (43131112) (12231115)
            (32231113) (52231111) (21331114) (41331112) (13122115) (33122113) (22222114)
            (42222112) (11322115) (31322113) (51322111) (23113114) (43113112) (12213115)
            (32213113) (52213111) (21313114) (41313112) (24131113) (13231114) (33231112)
            (22331113) (42331111) (11431114) (31431112) (14122114) (34122112) (23222113)
            (43222111) (12322114) (32322112) (21422113) (41422111) (24113113) (13213114)
            (33213112) (22313113) (42313111) (11413114) (31413112) (25131112) (14231113)
            (34231111) (23331112) (12431113) (32431111) (15122113) (24222112) (13322113)
            (33322111) (22422112) (11522113) (31522111) (25113112) (14213113) (34213111)
            (23313112) (12413113) (32413111) (21513112) (15231112) (24331111) (13431112)
            (16122112) (25222111) (14322112) (23422111) (12522112) (15213112) (24313111)
            (13413112) (22513111) (11613112) (21141115) (41141113) (61141111) (11132116)
            (31132114) (51132112) (21123115) (41123113) (61123111) (11114116) (31114114)
            (51114112) (22141114) (42141112) (11241115) (31241113) (51241111) (12132115)
            (32132113) (52132111) (21232114) (41232112) (22123114) (42123112) (11223115)
            (31223113) (51223111) (12114115) (32114113) (52114111) (21214114) (41214112)
            (23141113) (43141111) (12241114) (32241112) (21341113) (41341111) (13132114)
            (33132112) (22232113) (42232111) (11332114) (31332112) (23123113) (43123111)
            (12223114) (32223112) (21323113) (41323111) (13114114) (33114112) (22214113)
            (42214111) (11314114) (31314112) (24141112) (13241113) (33241111) (22341112)
            (14132113) (34132111) (23232112) (12332113) (32332111) (21432112) (24123112)
            (13223113) (33223111) (22323112) (11423113) (31423111) (14114113) (34114111)
            (23214112) (12314113) (32314111) (21414112) (25141111) (14241112) (23341111)
            (15132112) (24232111) (13332112) (22432111) (25123111) (14223112) (23323111)
            (12423112) (21523111) (15114112) (24214111) (13314112) (22414111) (11514112)
            (15241111) (16132111) (14332111) (15223111) (13423111) (16114111) (14314111)
            (12514111) (21151114) (41151112) (11142115) (31142113) (51142111) (21133114)
            (41133112) (11124115) (31124113) (51124111) (21115114) (41115112) (22151113)
            (42151111) (11251114) (31251112) (12142114) (32142112) (21242113) (41242111)
            (22133113) (42133111) (11233114) (31233112) (12124114) (32124112) (21224113)
            (41224111) (22115113) (42115111) (11215114) (31215112) (23151112) (12251113)
            (32251111) (13142113) (33142111) (22242112) (11342113) (31342111) (23133112)
            (12233113) (32233111) (21333112) (13124113) (33124111) (22224112) (11324113)
            (31324111) (23115112) (12215113) (32215111) (21315112) (24151111) (13251112)
            (14142112) (23242111) (12342112) (24133111) (13233112) (22333111) (11433112)
            (14124112) (23224111) (12324112) (21424111) (24115111) (13215112) (22315111)
            (11415112) (14251111) (15142111) (13342111) (14233111) (12433111) (15124111)
            (13324111) (11524111) (14215111) (12415111) (21161113) (41161111) (11152114)
            (31152112) (21143113) (41143111) (11134114) (31134112) (21125113) (41125111)
            (11116114) (31116112) (22161112) (12152113) (32152111) (21252112) (22143112)
            (11243113) (31243111) (12134113) (32134111) (21234112) (22125112) (11225113)
            (31225111) (12116113) (32116111) (21216112) (23161111) (13152112) (22252111)
            (23143111) (12243112) (21343111) (13134112) (22234111) (11334112) (23125111)
            (12225112) (21325111) (13116112) (22216111) (11316112) (14152111) (13243111)
            (14134111) (12334111) (13225111) (11425111) (14116111) (12316111) (41111215)
            (61111213) (21211126) (41211124) (61211122) (22111216) (42111214) (31211215)
            (51211213) (22211125) (42211123) (11311126) (31311124) (51311122) (23111215)
            (43111213) (12211216) (32211214) (52211212) (21311215) (41311213) (61311211)
            (23211124) (43211122) (12311125) (32311123) (52311121) (21411124) (41411122)
            (24111214) (13211215) (33211213) (22311214) (42311212) (11411215) (31411213)
            (51411211) (24211123) (13311124) (33311122) (22411123) (42411121) (11511124)
            (31511122) (25111213) (14211214) (34211212) (23311213) (43311211) (12411214)
            (32411212) (21511213) (41511211) (25211122) (14311123) (34311121) (23411122)
            (12511123) (32511121) (21611122) (15211213) (24311212) (13411213) (33411211)
            (22511212) (11611213) (31611211) (31121125) (51121123) (21112126) (41112124)
            (61112122) (21121216) (41121214) (61121212) (31112215) (51112213) (12121126)
            (32121124) (52121122) (21221125) (41221123) (61221121) (22112125) (42112123)
            (11212126) (22121215) (42121213) (11221216) (31221214) (51221212) (12112216)
            (32112214) (52112212) (21212215) (41212213) (61212211) (13121125) (33121123)
            (22221124) (42221122) (11321125) (31321123) (51321121) (23112124) (43112122)
            (12212125) (23121214) (43121212) (12221215) (32221213) (52221211) (21321214)
            (41321212) (13112215) (33112213) (22212214) (42212212) (11312215) (31312213)
            (51312211) (14121124) (34121122) (23221123) (43221121) (12321124) (32321122)
            (21421123) (41421121) (24112123) (13212124) (24121213) (13221214) (33221212)
            (11412124) (22321213) (42321211) (11421214) (31421212) (14112214) (34112212)
            (23212213) (43212211) (12312214) (32312212) (21412213) (41412211) (15121123)
            (24221122) (13321123) (33321121) (22421122) (11521123) (31521121) (25112122)
            (14212123) (25121212) (14221213) (34221211) (12412123) (23321212) (12421213)
            (32421211) (21521212) (15112213) (24212212) (13312213) (33312211) (22412212)
            (11512213) (31512211) (16121122) (25221121) (14321122) (23421121) (12521122)
            (15212122) (15221212) (13412122) (24321211) (13421212) (11612122) (22521211)
            (16112212) (25212211) (14312212) (23412211) (12512212) (21612211) (11131126)
            (31131124) (51131122) (21122125) (41122123) (61122121) (21131215) (41131213)
            (61131211) (11113126) (31113124) (51113122) (11122216) (31122214) (51122212)
            (21113215) (41113213) (61113211) (12131125) (32131123) (52131121) (21231124)
            (41231122) (22122124) (42122122) (11222125) (22131214) (42131212) (11231215)
            (31231213) (51231211) (12113125) (32113123) (52113121) (12122215) (32122213)
            (52122211) (21222214) (41222212) (22113214) (42113212) (11213215) (31213213)
            (51213211) (13131124) (33131122) (22231123) (42231121) (11331124) (31331122)
            (23122123) (43122121) (12222124) (23131213) (43131211) (12231214) (32231212)
            (21331213) (41331211) (13113124) (33113122) (13122214) (33122212) (11313124)
            (22222213) (42222211) (11322214) (31322212) (23113213) (43113211) (12213214)
            (32213212) (21313213) (41313211) (14131123) (34131121) (23231122) (12331123)
            (32331121) (21431122) (24122122) (13222123) (24131212) (13231213) (33231211)
            (11422123) (22331212) (11431213) (31431211) (14113123) (34113121) (14122213)
            (34122211) (12313123) (23222212) (12322213) (32322211) (21422212) (24113212)
            (13213213) (33213211) (22313212) (11413213) (31413211) (15131122) (24231121)
            (13331122) (22431121) (25122121) (14222122) (25131211) (14231212) (12422122)
            (23331211) (12431212) (15113122) (15122212) (13313122) (24222211) (13322212)
            (11513122) (22422211) (11522212) (25113211) (14213212) (23313211) (12413212)
            (21513211) (16131121) (14331121) (15222121) (15231211) (13422121) (13431211)
            (16113121) (16122211) (14313121) (14322211) (12513121) (12522211) (15213211)
            (13413211) (11613211) (11141125) (31141123) (51141121) (21132124) (41132122)
            (21141214) (41141212) (11123125) (31123123) (51123121) (11132215) (31132213)
            (51132211) (21114124) (41114122) (21123214) (41123212) (11114215) (31114213)
            (51114211) (12141124) (32141122) (21241123) (41241121) (22132123) (42132121)
            (11232124) (22141213) (42141211) (11241214) (31241212) (12123124) (32123122)
            (12132214) (32132212) (21232213) (41232211) (22114123) (42114121) (11214124)
            (22123213) (42123211) (11223214) (31223212) (12114214) (32114212) (21214213)
            (41214211) (13141123) (33141121) (22241122) (11341123) (31341121) (23132122)
            (12232123) (23141212) (12241213) (32241211) (21341212) (13123123) (33123121)
            (13132213) (33132211) (11323123) (22232212) (11332213) (31332211) (23114122)
            (12214123) (23123212) (12223213) (32223211) (21323212) (13114213) (33114211)
            (22214212) (11314213) (31314211) (14141122) (23241121) (12341122) (24132121)
            (13232122) (24141211) (13241212) (11432122) (22341211) (14123122) (14132212)
            (12323122) (23232211) (12332212) (21432211) (24114121) (13214122) (24123211)
            (13223212) (11414122) (22323211) (11423212) (14114212) (23214211) (12314212)
            (21414211) (15141121) (13341121) (14232121) (14241211) (12432121) (15123121)
            (15132211) (13323121) (13332211) (11523121) (14214121) (14223211) (12414121)
            (12423211) (15114211) (13314211) (11514211) (11151124) (31151122) (21142123)
            (41142121) (21151213) (41151211) (11133124) (31133122) (11142214) (31142212)
            (21124123) (41124121) (21133213) (41133211) (11115124) (31115122) (11124214)
            (31124212) (21115213) (41115211) (12151123) (32151121) (21251122) (22142122)
            (11242123) (22151212) (11251213) (31251211) (12133123) (32133121) (12142213)
            (32142211) (21242212) (22124122) (11224123) (22133212) (11233213) (31233211)
            (12115123) (32115121) (12124213) (32124211) (21224212) (22115212) (11215213)
            (31215211) (13151122) (22251121) (23142121) (12242122) (23151211) (12251212)
            (13133122) (13142212) (11333122) (22242211) (11342212) (23124121) (12224122)
            (23133211) (12233212) (21333211) (13115122) (13124212) (11315122) (22224211)
            (11324212) (23115211) (12215212) (21315211) (14151121) (13242121) (13251211)
            (14133121) (14142211) (12333121) (12342211) (13224121) (13233211) (11424121)
            (11433211) (14115121) (14124211) (12315121) (12324211) (13215211) (11415211)
            (11161123) (31161121) (21152122) (21161212) (11143123) (31143121) (11152213)
            (31152211) (21134122) (21143212) (11125123) (31125121) (11134213) (31134211)
            (21116122) (21125212) (12161122) (22152121) (11252122) (22161211) (12143122)
            (12152212) (21252211) (22134121) (11234122) (22143211) (11243212) (12125122)
            (12134212) (21234211) (22116121) (11216122) (22125211) (11225212) (13161121)
            (12252121) (13143121) (13152211) (11343121) (12234121) (12243211) (13125121)
            (13134211) (11325121) (11334211) (12216121) (12225211) (31111225) (51111223)
            (21111316) (41111314) (61111312) (31211134) (51211132) (12111226) (32111224)
            (52111222) (21211225) (41211223) (61211221) (22111315) (42111313) (11211316)
            (31211314) (51211312) (12211135) (32211133) (52211131) (21311134) (41311132)
            (13111225) (33111223) (22211224) (42211222) (11311225) (31311223) (51311221)
            (23111314) (43111312) (12211315) (32211313) (52211311) (21311314) (41311312)
            (13211134) (33211132) (22311133) (42311131) (11411134) (31411132) (14111224)
            (34111222) (23211223) (43211221) (12311224) (32311222) (21411223) (41411221)
            (24111313) (13211314) (33211312) (22311313) (42311311) (11411314) (31411312)
            (14211133) (34211131) (23311132) (12411133) (32411131) (21511132) (15111223)
            (24211222) (13311223) (33311221) (22411222) (11511223) (31511221) (25111312)
            (14211313) (34211311) (23311312) (12411313) (32411311) (21511312) (15211132)
            (24311131) (13411132) (22511131) (11611132) (16111222) (25211221) (14311222)
            (23411221) (12511222) (21611221) (15211312) (24311311) (13411312) (22511311)
            (11611312) (21121135) (41121133) (61121131) (11112136) (31112134) (51112132)
            (11121226) (31121224) (51121222) (21112225) (41112223) (61112221) (21121315)
            (41121313) (61121311) (11112316) (31112314) (51112312) (22121134) (42121132)
            (11221135) (31221133) (51221131) (12112135) (32112133) (52112131) (12121225)
            (32121223) (52121221) (21221224) (41221222) (22112224) (42112222) (11212225)
            (22121314) (42121312) (11221315) (31221313) (51221311) (12112315) (32112313)
            (52112311) (21212314) (41212312) (23121133) (43121131) (12221134) (32221132)
            (21321133) (41321131) (13112134) (33112132) (13121224) (33121222) (11312134)
            (22221223) (42221221) (11321224) (31321222) (23112223) (43112221) (12212224)
            (23121313) (43121311) (12221314) (32221312) (21321313) (41321311) (13112314)
            (33112312) (22212313) (42212311) (11312314) (31312312) (24121132) (13221133)
            (33221131) (22321132) (11421133) (31421131) (14112133) (34112131) (14121223)
            (34121221) (12312133) (23221222) (12321223) (32321221) (21421222) (24112222)
            (13212223) (24121312) (13221313) (33221311) (11412223) (22321312) (11421313)
            (31421311) (14112313) (34112311) (23212312) (12312313) (32312311) (21412312)
            (25121131) (14221132) (23321131) (12421132) (21521131) (15112132) (15121222)
            (13312132) (24221221) (13321222) (11512132) (22421221) (11521222) (25112221)
            (14212222) (25121311) (14221312) (12412222) (23321311) (12421312) (21521311)
            (15112312) (24212311) (13312312) (22412311) (11512312) (15221131) (13421131)
            (16112131) (16121221) (14312131) (14321221) (12512131) (12521221) (15212221)
            (15221311) (13412221) (13421311) (11612221) (16112311) (14312311) (12512311)
            (21131134) (41131132) (11122135) (31122133) (51122131) (11131225) (31131223)
            (51131221) (21113134) (41113132) (21122224) (41122222) (21131314) (41131312)
            (11113225) (31113223) (51113221) (11122315) (31122313) (51122311) (21113314)
            (41113312) (22131133) (42131131) (11231134) (31231132) (12122134) (32122132)
            (12131224) (32131222) (21231223) (41231221) (22113133) (42113131) (11213134)
            (22122223) (42122221) (11222224) (22131313) (42131311) (11231314) (31231312)
            (12113224) (32113222) (12122314) (32122312) (21222313) (41222311) (22113313)
            (42113311) (11213314) (31213312) (23131132) (12231133) (32231131) (21331132)
            (13122133) (33122131) (13131223) (33131221) (11322133) (22231222) (11331223)
            (31331221) (23113132) (12213133) (23122222) (12222223) (23131312) (12231313)
            (32231311) (21331312) (13113223) (33113221) (13122313) (33122311) (11313223)
            (22222312) (11322313) (31322311) (23113312) (12213313) (32213311) (21313312)
            (24131131) (13231132) (22331131) (11431132) (14122132) (14131222) (12322132)
            (23231221) (12331222) (21431221) (24113131) (13213132) (24122221) (13222222)
            (24131311) (11413132) (13231312) (11422222) (22331311) (11431312) (14113222)
            (14122312) (12313222) (23222311) (12322312) (21422311) (24113311) (13213312)
            (22313311) (11413312) (14231131) (12431131) (15122131) (15131221) (13322131)
            (13331221) (11522131) (14213131) (14222221) (12413131) (14231311) (12422221)
            (12431311) (15113221) (15122311) (13313221) (13322311) (11513221) (11522311)
            (14213311) (12413311) (21141133) (41141131) (11132134) (31132132) (11141224)
            (31141222) (21123133) (41123131) (21132223) (41132221) (21141313) (41141311)
            (11114134) (31114132) (11123224) (31123222) (11132314) (31132312) (21114223)
            (41114221) (21123313) (41123311) (11114314) (31114312) (22141132) (11241133)
            (31241131) (12132133) (32132131) (12141223) (32141221) (21241222) (22123132)
            (11223133) (22132222) (11232223) (22141312) (11241313) (31241311) (12114133)
            (32114131) (12123223) (32123221) (12132313) (32132311) (21232312) (22114222)
            (11214223) (22123312) (11223313) (31223311) (12114313) (32114311) (21214312)
            (23141131) (12241132) (21341131) (13132132) (13141222) (11332132) (22241221)
            (11341222) (23123131) (12223132) (23132221) (12232222) (23141311) (12241312)
            (21341311) (13114132) (13123222) (11314132) (13132312) (11323222) (22232311)
            (11332312) (23114221) (12214222) (23123311) (12223312) (21323311) (13114312)
            (22214311) (11314312) (13241131) (14132131) (14141221) (12332131) (12341221)
            (13223131) (13232221) (11423131) (13241311) (11432221) (14114131) (14123221)
            (12314131) (14132311) (12323221) (12332311) (13214221) (13223311) (11414221)
            (11423311) (14114311) (12314311) (21151132) (11142133) (31142131) (11151223)
            (31151221) (21133132) (21142222) (21151312) (11124133) (31124131) (11133223)
            (31133221) (11142313) (31142311) (21115132) (21124222) (21133312) (11115223)
            (31115221) (11124313) (31124311) (22151131) (11251132) (12142132) (12151222)
            (21251221) (22133131) (11233132) (22142221) (11242222) (22151311) (11251312)
            (12124132) (12133222) (12142312) (21242311) (22115131) (11215132) (22124221)
            (11224222) (22133311) (11233312) (12115222) (12124312) (21224311) (12251131)
            (13142131) (13151221) (11342131) (12233131) (12242221) (12251311) (13124131)
            (13133221) (11324131) (13142311) (11333221) (11342311) (12215131) (12224221)
            (12233311) (13115221) (13124311) (11315221) (11324311) (21161131) (11152132)
            (11161222) (21143131) (21152221) (21161311) (11134132) (11143222) (11152312)
            (21125131) (21134221) (21143311) (11116132) (11125222) (11134312) (12152131)
            (12161221) (11243131) (11252221) (12134131) (12143221) (12152311) (11225131)
            (11234221) (11243311) (12116131) (12125221) (12134311) (21111235) (41111233)
            (61111231) (11111326) (31111324) (51111322) (21111415) (41111413) (61111411)
            (21211144) (41211142) (22111234) (42111232) (11211235) (31211233) (51211231)
            (12111325) (32111323) (52111321) (21211324) (41211322) (22111414) (42111412)
            (11211415) (31211413) (51211411) (22211143) (42211141) (11311144) (31311142)
            (23111233) (43111231) (12211234) (32211232) (21311233) (41311231) (13111324)
            (33111322) (22211323) (42211321) (11311324) (31311322) (23111413) (43111411)
            (12211414) (32211412) (21311413) (41311411) (23211142) (12311143) (32311141)
            (21411142) (24111232) (13211233) (33211231) (22311232) (11411233) (31411231)
            (14111323) (34111321) (23211322) (12311323) (32311321) (21411322) (24111412)
            (13211413) (33211411) (22311412) (11411413) (31411411) (24211141) (13311142)
            (22411141) (11511142) (25111231) (14211232) (23311231) (12411232) (21511231)
            (15111322) (24211321) (13311322) (22411321) (11511322) (25111411) (14211412)
            (23311411) (12411412) (21511411) (14311141) (12511141) (15211231) (13411231)
            (11611231) (16111321) (14311321) (12511321) (15211411) (13411411) (11611411)
            (31121143) (51121141) (21112144) (41112142) (21121234) (41121232) (11112235)
            (31112233) (51112231) (11121325) (31121323) (51121321) (21112324) (41112322)
            (21121414) (41121412) (11112415) (31112413) (51112411) (12121144) (32121142)
            (21221143) (41221141) (22112143) (42112141) (11212144) (22121233) (42121231)
            (11221234) (31221232) (12112234) (32112232) (12121324) (32121322) (21221323)
            (41221321) (22112323) (42112321) (11212324) (22121413) (42121411) (11221414)
            (31221412) (12112414) (32112412) (21212413) (41212411) (13121143) (33121141)
            (22221142) (11321143) (31321141) (23112142) (12212143) (23121232) (12221233)
            (32221231) (21321232) (13112233) (33112231) (13121323) (33121321) (11312233)
            (22221322) (11321323) (31321321) (23112322) (12212323) (23121412) (12221413)
            (32221411) (21321412) (13112413) (33112411) (22212412) (11312413) (31312411)
            (14121142) (23221141) (12321142) (21421141) (24112141) (13212142) (24121231)
            (13221232) (11412142) (22321231) (11421232) (14112232) (14121322) (12312232)
            (23221321) (12321322) (21421321) (24112321) (13212322) (24121411) (13221412)
            (11412322) (22321411) (11421412) (14112412) (23212411) (12312412) (21412411)
            (15121141) (13321141) (11521141) (14212141) (14221231) (12412141) (12421231)
            (15112231) (15121321) (13312231) (13321321) (11512231) (11521321) (14212321)
            (14221411) (12412321) (12421411) (15112411) (13312411) (11512411) (11131144)
            (31131142) (21122143) (41122141) (21131233) (41131231) (11113144) (31113142)
            (11122234) (31122232) (11131324) (31131322) (21113233) (41113231) (21122323)
            (41122321) (21131413) (41131411) (11113324) (31113322) (11122414) (31122412)
            (21113413) (41113411) (12131143) (32131141) (21231142) (22122142) (11222143)
            (22131232) (11231233) (31231231) (12113143) (32113141) (12122233) (32122231)
            (12131323) (32131321) (21231322) (22113232) (11213233) (22122322) (11222323)
            (22131412) (11231413) (31231411) (12113323) (32113321) (12122413) (32122411)
            (21222412) (22113412) (11213413) (31213411) (13131142) (22231141) (11331142)
            (23122141) (12222142) (23131231) (12231232) (21331231) (13113142) (13122232)
            (11313142) (13131322) (11322232) (22231321) (11331322) (23113231) (12213232)
            (23122321) (12222322) (23131411) (12231412) (21331411) (13113322) (13122412)
            (11313322) (22222411) (11322412) (23113411) (12213412) (21313411) (14131141)
            (12331141) (13222141) (13231231) (11422141) (11431231) (14113141) (14122231)
            (12313141) (14131321) (12322231) (12331321) (13213231) (13222321) (11413231)
            (13231411) (11422321) (11431411) (14113321) (14122411) (12313321) (12322411)
            (13213411) (11413411) (11141143) (31141141) (21132142) (21141232) (11123143)
            (31123141) (11132233) (31132231) (11141323) (31141321) (21114142) (21123232)
            (21132322) (21141412) (11114233) (31114231) (11123323) (31123321) (11132413)
            (31132411) (21114322) (21123412) (12141142) (21241141) (22132141) (11232142)
            (22141231) (11241232) (12123142) (12132232) (12141322) (21241321) (22114141)
            (11214142) (22123231) (11223232) (22132321) (11232322) (22141411) (11241412)
            (12114232) (12123322) (12132412) (21232411) (22114321) (11214322) (22123411)
            (11223412) (13141141) (11341141) (12232141) (12241231) (13123141) (13132231)
            (11323141) (13141321) (11332231) (11341321) (12214141) (12223231) (12232321)
            (12241411) (13114231) (13123321) (11314231) (13132411) (11323321) (11332411)
            (12214321) (12223411) (11151142) (21142141) (21151231) (11133142) (11142232)
            (11151322) (21124141) (21133231) (21142321) (21151411) (11115142) (11124232)
            (11133322) (11142412) (21115231) (21124321) (21133411) (12151141) (11242141)
            (11251231) (12133141) (12142231) (12151321) (11224141) (11233231) (11242321)
            (11251411) (12115141) (12124231) (12133321) (12142411) (11215231) (11224321)
            (11233411) (11161141) (11143141) (11152231) (11161321) (11125141) (11134231)
            (11143321) (11152411) (11111245) (31111243) (51111241) (21111334) (41111332)
            (11111425) (31111423) (51111421) (21111514) (41111512) (31211152) (12111244)
            (32111242) (21211243) (41211241) (22111333) (42111331) (11211334) (31211332)
            (12111424) (32111422) (21211423) (41211421) (22111513) (42111511) (11211514)
            (31211512) (12211153) (32211151) (21311152) (13111243) (33111241) (22211242)
            (11311243) (31311241) (23111332) (12211333) (32211331) (21311332) (13111423)
            (33111421) (22211422) (11311423) (31311421) (23111512) (12211513) (32211511)
            (21311512) (13211152) (22311151) (11411152) (14111242) (23211241) (12311242)
            (21411241) (24111331) (13211332) (22311331) (11411332) (14111422) (23211421)
            (12311422) (21411421) (24111511) (13211512) (22311511) (11411512) (14211151)
            (12411151) (15111241) (13311241) (11511241) (14211331) (12411331) (15111421)
            (13311421) (11511421) (14211511) (12411511) (21121153) (41121151) (11112154)
            (31112152) (11121244) (31121242) (21112243) (41112241) (21121333) (41121331)
            (11112334) (31112332) (11121424) (31121422) (21112423) (41112421) (21121513)
            (41121511) (11112514) (31112512) (22121152) (11221153) (31221151) (12112153)
            (32112151) (12121243) (32121241) (21221242) (22112242) (11212243) (22121332)
            (11221333) (31221331) (12112333) (32112331) (12121423) (32121421) (21221422)
            (22112422) (11212423) (22121512) (11221513) (31221511) (12112513) (32112511)
            (21212512) (23121151) (12221152) (21321151) (13112152) (13121242) (11312152)
            (22221241) (11321242) (23112241) (12212242) (23121331) (12221332) (21321331)
            (13112332) (13121422) (11312332) (22221421) (11321422) (23112421) (12212422)
            (23121511) (12221512) (21321511) (13112512) (22212511) (11312512) (13221151)
            (11421151) (14112151) (14121241) (12312151) (12321241) (13212241) (13221331)
            (11412241) (11421331) (14112331) (14121421) (12312331) (12321421) (13212421)
            (13221511) (11412421) (11421511) (14112511) (12312511) (21131152) (11122153)
            (31122151) (11131243) (31131241) (21113152) (21122242) (21131332) (11113243)
            (31113241) (11122333) (31122331) (11131423) (31131421) (21113332) (21122422)
            (21131512) (11113423) (31113421) (11122513) (31122511) (22131151) (11231152)
            (12122152) (12131242) (21231241) (22113151) (11213152) (22122241) (11222242)
            (22131331) (11231332) (12113242) (12122332) (12131422) (21231421) (22113331)
            (11213332) (22122421) (11222422) (22131511) (11231512) (12113422) (12122512)
            (21222511) (12231151) (13122151) (13131241) (11322151) (11331241) (12213151)
            (12222241) (12231331) (13113241) (13122331) (11313241) (13131421) (11322331)
            (11331421) (12213331) (12222421) (12231511) (13113421) (13122511) (11313421)
            (11322511) (21141151) (11132152) (11141242) (21123151) (21132241) (21141331)
            (11114152) (11123242) (11132332) (11141422) (21114241) (21123331) (21132421)
            (21141511) (11114332) (11123422) (11132512) (11241151) (12132151) (12141241)
            (11223151) (11232241) (11241331) (12114151) (12123241) (12132331) (12141421)
            (11214241) (11223331) (11232421) (11241511) (12114331) (12123421) (12132511)
            (11142151) (11151241) (11124151) (11133241) (11142331) (11151421) (11115241)
            (11124331) (11133421) (11142511) (21111253) (41111251) (11111344) (31111342)
            (21111433) (41111431) (11111524) (31111522) (21111613) (41111611) (21211162)
            (22111252) (11211253) (31211251) (12111343) (32111341) (21211342) (22111432)
            (11211433) (31211431) (12111523) (32111521) (21211522) (22111612) (11211613)
            (31211611) (22211161) (11311162) (23111251) (12211252) (21311251) (13111342)
            (22211341) (11311342) (23111431) (12211432) (21311431) (13111522) (22211521)
            (11311522) (23111611) (12211612) (21311611) (12311161) (13211251) (11411251)
            (14111341) (12311341) (13211431) (11411431) (14111521) (12311521) (13211611)
            (11411611) (31121161) (21112162) (21121252) (11112253) (31112251) (11121343)
            (31121341) (21112342) (21121432) (11112433) (31112431) (11121523) (31121521)
            (21112522) (21121612) (12121162) (21221161) (22112161) (11212162) (22121251)
            (11221252) (12112252) (12121342) (21221341) (22112341) (11212342) (22121431)
            (11221432) (12112432) (12121522) (21221521) (22112521) (11212522) (22121611)
            (11221612) (13121161) (11321161) (12212161) (12221251) (13112251) (13121341)
            (11312251) (11321341) (12212341) (12221431) (13112431) (13121521) (11312431)
            (11321521) (12212521) (12221611) (11131162) (21122161) (21131251) (11113162)
        ]
    ] def

    /parity [
        (1001) (0101) (1100) (0011) (1010) (0110) (1111) (0000)
    ] def
} ctxdef

    % Derive the bits for each row
    /rowbits r array def
    0 1 r 1 sub {
        /i exch def
        /p i r 1 sub ne {parity i get} {(0000)} ifelse def
        /ccrow ccs i 8 mul 8 getinterval def
        /scrow [
            0 2 7 {ccrow exch 2 getinterval aload pop exch 49 mul add} for
        ] def
        /sbs [
            10 1 1
            0 1 3 {
                /j exch def
                patterns p j get 48 sub get scrow j get get {48 sub} forall
            } for
            4 1
        ] def
        mark
        1 sbs {1 index 0 eq {{1}} {{0}} ifelse repeat} forall
        counttomark 1 sub array astore exch pop exch pop
        rowbits i 3 -1 roll put
    } for

    % Populate the bitmap
    /pixs [
        81 sepheight mul {1} repeat
        0 1 r 2 sub {
            /i exch def
            rowheight {rowbits i get aload pop} repeat
            sepheight {10 {0} repeat 70 {1} repeat 0} repeat
        } for
        rowheight {rowbits r 1 sub get aload pop} repeat
        81 sepheight mul {1} repeat
    ] def

    % Return the arguments
    <<
    /ren //renmatrix
    /pixs pixs
    /pixx 81
    /pixy pixs length 81 idiv
    /height pixs length 81 idiv 72 div
    /width 81 72 div
    /opt options
    >>

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/code49 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER code49--

% --BEGIN ENCODER channelcode--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: Channel Code
% --EXAM: 3493
% --EXOP: height=0.5 includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp channelcode 0.0 2022082100 132918 128171
%%BeginData:        262 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/channelcode {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /shortfinder false def
    /includetext false def
    /includecheck false def
    /height 1 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

    /height height cvr def

    /channelcode //loadctx exec

    % Validate the input
    barcode length 2 lt barcode length 7 gt or {
        /bwipp.channelcodeBadLength (Channel Code must be 2 to 7 digits) //raiseerror exec
    } if
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.channelcodeBadCharacter (Channel Code must contain only digits) //raiseerror exec
        } if
    } forall
    barcode cvi [ 26 292 3493 44072 576688 7742862 ] barcode length 2 sub get gt {
        /bwipp.channelcodeTooBig (The Channel Code value is too big for the number of channels) //raiseerror exec
    } if

    % Tail-call optimisation FTW!
    /loops1 { /s2max s1max 1 add s1 sub def  /b1 1 def
              s1 1 eq {nextb1} {loopb1} ifelse                             } def
    /loopb1 { /b2max b1max 1 add b1 sub def  /s2 1 def  loops2             } def
    /loops2 { /s3max s2max 1 add s2 sub def  /b2 1 def
              s1 b1 add s2 add 3 eq {nextb2} {loopb2} ifelse               } def
    /loopb2 { /b3max b2max 1 add b2 sub def  /s3 1 def  loops3             } def
    /loops3 { /s4max s3max 1 add s3 sub def  /b3 1 def
              b1 s2 add b2 add s3 add 4 eq {nextb3} {loopb3} ifelse        } def
    /loopb3 { /b4max b3max 1 add b3 sub def  /s4 1 def  loops4             } def
    /loops4 { /s5max s4max 1 add s4 sub def  /b4 1 def
              b2 s3 add b3 add s4 add 4 eq {nextb4} {loopb4} ifelse        } def
    /loopb4 { /b5max b4max 1 add b4 sub def  /s5 1 def  loops5             } def
    /loops5 { /s6max s5max 1 add s5 sub def  /b5 1 def
              b3 s4 add b4 add s5 add 4 eq {nextb5} {loopb5} ifelse        } def
    /loopb5 { /b6max b5max 1 add b5 sub def  /s6 1 def  loops6             } def
    /loops6 { /s7max s6max 1 add s6 sub def  /b6 1 def
              b4 s5 add b5 add s6 add 4 eq {nextb6} {loopb6} ifelse        } def
    /loopb6 { /b7max b6max 1 add b6 sub def  /s7 1 def  loops7             } def
    /loops7 { /s8 s7max 1 add s7 sub def     /b7 1 def
              b5 s6 add b6 add s7 add 4 eq {nextb7} {loopb7} ifelse        } def
    /loopb7 { /b8 b7max 1 add b7 sub def
              b6 s7 add b7 add s8 add b8 add 5 eq {nextb7} {chkchr} ifelse } def
    /chkchr {
        value target eq {
            [s1 b1 s2 b2 s3 b3 s4 b4 s5 b5 s6 b6 s7 b7 s8 b8] exit
        } if
        /value value 1 add def
        nextb7
    } def
    /nextb7 { /b7 b7 1 add def  b7 b7max le {loopb7} {nexts7} ifelse } def
    /nexts7 { /s7 s7 1 add def  s7 s7max le {loops7} {nextb6} ifelse } def
    /nextb6 { /b6 b6 1 add def  b6 b6max le {loopb6} {nexts6} ifelse } def
    /nexts6 { /s6 s6 1 add def  s6 s6max le {loops6} {nextb5} ifelse } def
    /nextb5 { /b5 b5 1 add def  b5 b5max le {loopb5} {nexts5} ifelse } def
    /nexts5 { /s5 s5 1 add def  s5 s5max le {loops5} {nextb4} ifelse } def
    /nextb4 { /b4 b4 1 add def  b4 b4max le {loopb4} {nexts4} ifelse } def
    /nexts4 { /s4 s4 1 add def  s4 s4max le {loops4} {nextb3} ifelse } def
    /nextb3 { /b3 b3 1 add def  b3 b3max le {loopb3} {nexts3} ifelse } def
    /nexts3 { /s3 s3 1 add def  s3 s3max le {loops3} {nextb2} ifelse } def
    /nextb2 { /b2 b2 1 add def  b2 b2max le {loopb2} {nexts2} ifelse } def
    /nexts2 { /s2 s2 1 add def  s2 s2max le {loops2} {nextb1} ifelse } def
    /nextb1 { /b1 b1 1 add def  b1 b1max le {loopb1} {nexts1} ifelse } def
    /nexts1 { /s1 s1 1 add def  s1 s1max le {loops1} if              } def

{
    /memo [  % Accelerate generation of bar patterns
        [  % CH3
            [       0  [1 1 1 1 1 2 1 2]  [1 1 1 1 1 1 1 3]  [1 1 1 1 1 3 2]  [1 1 1 1 1 3 3] ]
        ]
        [  % CH4
            [       0  [1 1 1 1 2 1 1 3]  [1 1 1 1 1 1 1 4]  [1 1 1 1 4 3 3]  [1 1 1 1 4 4 4] ]
        ]
        [  % CH5
            [       0  [1 1 1 2 1 1 2 3]  [1 1 1 1 1 1 1 5]  [1 1 1 5 4 4 4]  [1 1 1 5 5 5 5] ]
        ]
        [  % CH6
            [       0  [1 1 2 1 1 2 1 4]  [1 1 1 1 1 1 1 6]  [1 1 6 5 5 5 4]  [1 1 6 6 6 6 6] ]
        ]
        [  % CH7
            [       0  [1 2 1 1 2 1 1 5]  [1 1 1 1 1 1 1 7]  [1 7 6 6 6 5 5]  [1 7 7 7 7 7 7] ]
            [  150000  [1 3 1 1 2 4 1 1]  [1 1 3 1 2 3 2 1]  [1 7 5 5 5 4 1]  [1 7 7 5 5 4 2] ]
            [  300000  [1 1 4 2 1 1 1 3]  [1 2 4 1 1 1 2 2]  [1 7 7 4 3 3 3]  [1 7 6 3 3 3 3] ]
            [  450000  [1 1 4 1 1 4 1 1]  [1 3 2 1 2 1 2 2]  [1 7 7 4 4 4 1]  [1 7 5 4 4 3 3] ]
        ]
        [  % CH8
            [       0  [2 1 1 2 1 1 2 5]  [1 1 1 1 1 1 1 8]  [8 7 7 7 6 6 6]  [8 8 8 8 8 8 8] ]
            [  150000  [2 1 1 2 1 1 5 2]  [1 1 2 1 5 2 1 2]  [8 7 7 7 6 6 6]  [8 8 8 7 7 3 2] ]
            [  300000  [2 1 1 4 2 2 2 1]  [1 1 4 2 1 2 1 3]  [8 7 7 7 4 3 2]  [8 8 8 5 4 4 3] ]
            [  450000  [2 2 2 1 1 3 1 3]  [1 1 2 1 1 2 4 3]  [8 7 6 5 5 5 3]  [8 8 8 7 7 7 6] ]
            [  600000  [2 3 1 1 4 2 1 1]  [1 1 3 1 3 1 2 3]  [8 7 5 5 5 2 1]  [8 8 8 6 6 4 4] ]
            [  750000  [2 1 3 1 2 3 2 1]  [1 2 1 1 3 4 1 2]  [8 7 7 5 5 4 2]  [8 8 7 7 7 5 2] ]
            [  900000  [2 2 1 4 1 2 2 1]  [1 2 1 2 1 5 1 2]  [8 7 6 6 3 3 2]  [8 8 7 7 6 6 2] ]
            [ 1050000  [2 4 1 1 1 2 2 2]  [1 2 1 2 1 3 1 4]  [8 7 4 4 4 4 3]  [8 8 7 7 6 6 4] ]
            [ 1200000  [2 2 1 5 2 1 1 1]  [1 3 1 3 2 1 1 3]  [8 7 6 6 2 1 1]  [8 8 6 6 4 3 3] ]
            [ 1350000  [2 2 1 3 3 1 1 2]  [1 4 1 2 1 1 4 1]  [8 7 6 6 4 2 2]  [8 8 5 5 4 4 4] ]
            [ 1500000  [3 1 2 2 2 1 1 3]  [1 1 1 1 2 2 4 3]  [8 6 6 5 4 3 3]  [8 8 8 8 8 7 6] ]
            [ 1650000  [3 2 1 2 3 1 2 1]  [1 1 1 1 3 2 4 2]  [8 6 5 5 4 2 2]  [8 8 8 8 8 6 5] ]
            [ 1800000  [3 1 1 3 2 3 1 1]  [1 2 1 1 3 4 2 1]  [8 6 6 6 4 3 1]  [8 8 7 7 7 5 2] ]
            [ 1950000  [3 2 1 2 1 2 2 2]  [1 2 4 1 2 2 1 2]  [8 6 5 5 4 4 3]  [8 8 7 4 4 3 2] ]
            [ 2100000  [3 1 2 1 4 2 1 1]  [1 4 1 2 1 1 2 3]  [8 6 6 5 5 2 1]  [8 8 5 5 4 4 4] ]
            [ 2250000  [4 1 1 4 1 1 2 1]  [1 1 4 2 1 1 1 4]  [8 5 5 5 2 2 2]  [8 8 8 5 4 4 4] ]
            [ 2400000  [4 3 1 2 1 2 1 1]  [1 2 4 2 2 2 1 1]  [8 5 3 3 2 2 1]  [8 8 7 4 3 2 1] ]
            [ 2550000  [5 1 1 1 1 1 3 2]  [1 2 2 4 3 1 1 1]  [8 4 4 4 4 4 4]  [8 8 7 6 3 1 1] ]
            [ 2700000  [1 1 3 6 1 1 1 1]  [2 1 1 2 1 1 6 1]  [8 8 8 6 1 1 1]  [8 7 7 7 6 6 6] ]
            [ 2850000  [1 1 1 2 2 3 2 3]  [2 1 3 3 2 1 1 2]  [8 8 8 8 7 6 4]  [8 7 7 5 3 2 2] ]
            [ 3000000  [1 2 3 3 3 1 1 1]  [2 1 1 1 5 1 2 2]  [8 8 7 5 3 1 1]  [8 7 7 7 7 3 3] ]
            [ 3150000  [1 3 1 2 2 2 3 1]  [2 1 1 3 2 1 3 2]  [8 8 6 6 5 4 3]  [8 7 7 7 5 4 4] ]
            [ 3300000  [1 5 1 1 3 1 1 2]  [2 1 1 4 3 2 1 1]  [8 8 4 4 4 2 2]  [8 7 7 7 4 2 1] ]
            [ 3450000  [1 1 2 2 2 5 1 1]  [2 2 2 2 3 1 1 2]  [8 8 8 7 6 5 1]  [8 7 6 5 4 2 2] ]
            [ 3600000  [1 2 1 1 3 4 2 1]  [2 2 3 1 1 1 2 3]  [8 8 7 7 7 5 2]  [8 7 6 4 4 4 4] ]
            [ 3750000  [1 1 2 1 1 5 3 1]  [2 3 1 1 4 1 2 1]  [8 8 8 7 7 7 3]  [8 7 5 5 5 2 2] ]
            [ 3900000  [1 3 1 2 4 2 1 1]  [2 3 3 1 1 1 2 2]  [8 8 6 6 5 2 1]  [8 7 5 3 3 3 3] ]
            [ 4050000  [1 3 1 2 3 1 2 2]  [2 6 2 1 1 1 1 1]  [8 8 6 6 5 3 3]  [8 7 2 1 1 1 1] ]
            [ 4200000  [2 1 1 2 1 2 2 4]  [2 1 3 1 3 3 1 1]  [8 7 7 7 6 6 5]  [8 7 7 5 5 3 1] ]
            [ 4350000  [2 2 1 4 1 2 2 1]  [2 1 4 1 3 1 2 1]  [8 7 6 6 3 3 2]  [8 7 7 4 4 2 2] ]
            [ 4500000  [2 1 1 1 2 1 3 4]  [2 2 2 1 2 1 3 2]  [8 7 7 7 7 6 6]  [8 7 6 5 5 4 4] ]
            [ 4650000  [2 4 2 1 2 2 1 1]  [2 2 2 1 2 1 2 3]  [8 7 4 3 3 2 1]  [8 7 6 5 5 4 4] ]
            [ 4800000  [2 3 2 1 1 2 2 2]  [2 4 1 2 1 1 3 1]  [8 7 5 4 4 4 3]  [8 7 4 4 3 3 3] ]
            [ 4950000  [3 2 2 1 2 1 1 3]  [2 1 1 2 1 1 1 6]  [8 6 5 4 4 3 3]  [8 7 7 7 6 6 6] ]
            [ 5100000  [3 2 1 1 1 3 3 1]  [2 2 3 2 1 1 3 1]  [8 6 5 5 5 5 3]  [8 7 6 4 3 3 3] ]
            [ 5250000  [4 1 2 1 2 2 1 2]  [2 1 4 1 2 1 1 3]  [8 5 5 4 4 3 2]  [8 7 7 4 4 3 3] ]
            [ 5400000  [5 1 2 1 2 1 1 2]  [2 2 1 1 4 1 3 1]  [8 4 4 3 3 2 2]  [8 7 6 6 6 3 3] ]
            [ 5550000  [1 1 4 4 1 2 1 1]  [3 1 2 1 1 3 2 2]  [8 8 8 5 2 2 1]  [8 6 6 5 5 5 3] ]
            [ 5700000  [1 2 1 1 2 1 3 4]  [3 1 4 1 2 2 1 1]  [8 8 7 7 7 6 6]  [8 6 6 3 3 2 1] ]
            [ 5850000  [1 1 3 3 2 2 2 1]  [3 2 1 1 2 1 4 1]  [8 8 8 6 4 3 2]  [8 6 5 5 5 4 4] ]
            [ 6000000  [1 4 3 1 1 2 1 2]  [3 2 2 1 2 2 1 2]  [8 8 5 3 3 3 2]  [8 6 5 4 4 3 2] ]
            [ 6150000  [2 1 1 4 1 2 1 3]  [3 1 1 2 1 2 1 4]  [8 7 7 7 4 4 3]  [8 6 6 6 5 5 4] ]
            [ 6300000  [2 2 2 1 3 2 2 1]  [3 1 4 1 3 1 1 1]  [8 7 6 5 5 3 2]  [8 6 6 3 3 1 1] ]
            [ 6450000  [2 5 1 3 1 1 1 1]  [3 2 1 1 2 3 1 2]  [8 7 3 3 1 1 1]  [8 6 5 5 5 4 2] ]
            [ 6600000  [3 2 3 1 2 1 2 1]  [3 1 3 2 2 1 1 2]  [8 6 5 3 3 2 2]  [8 6 6 4 3 2 2] ]
            [ 6750000  [4 1 2 2 1 1 3 1]  [3 2 1 3 1 1 3 1]  [8 5 5 4 3 3 3]  [8 6 5 5 3 3 3] ]
            [ 6900000  [1 2 1 4 2 2 2 1]  [4 1 1 2 2 2 2 1]  [8 8 7 7 4 3 2]  [8 5 5 5 4 3 2] ]
            [ 7050000  [1 2 5 2 1 2 1 1]  [4 2 1 3 2 1 1 1]  [8 8 7 3 2 2 1]  [8 5 4 4 2 1 1] ]
            [ 7200000  [2 2 2 1 3 1 3 1]  [4 1 3 1 3 1 1 1]  [8 7 6 5 5 3 3]  [8 5 5 3 3 1 1] ]
            [ 7350000  [3 1 4 2 1 1 1 2]  [4 2 2 1 1 1 2 2]  [8 6 6 3 2 2 2]  [8 5 4 3 3 3 3] ]
            [ 7500000  [1 1 1 4 1 1 3 3]  [5 2 1 2 2 1 1 1]  [8 8 8 8 5 5 5]  [8 4 3 3 2 1 1] ]
            [ 7650000  [5 2 1 2 1 2 1 1]  [5 2 2 1 1 2 1 1]  [8 4 3 3 2 2 1]  [8 4 3 2 2 2 1] ]
        ]
    ] def
} ctxdef

    /encode {
        /chan exch def
        /target exch def

        % Lookup memoized starting value close to the target
        memo chan 3 sub get {
            /m exch def
            m 0 get target gt {exit} if
            /mv    m 0 get def
            /mb    m 1 get def
            /ms    m 2 get def
            /mbmax m 3 get def
            /msmax m 4 get def
        } forall
        /value mv def
        mb    aload pop [/b8 /b7 /b6 /b5 /b4 /b3 /b2 /b1] {exch def} forall
        ms    aload pop [/s8 /s7 /s6 /s5 /s4 /s3 /s2 /s1] {exch def} forall
        mbmax aload pop [/b7max /b6max /b5max /b4max /b3max /b2max /b1max] {exch def} forall
        msmax aload pop [/s7max /s6max /s5max /s4max /s3max /s2max /s1max] {exch def} forall

        1 {chkchr} repeat 8 chan sub 2 mul dup 16 exch sub getinterval

    } def

    /barlen barcode length def

    % Determine finder
    /finder shortfinder { [ 1 1 1 1 1 ] } { [ 1 1 1 1 1 1 1 1 1 ] } ifelse def

    % Encode the main data
    /data barcode cvi barlen 1 add encode def

    % Determine check data
{
    /mod23map [
            [] []
            [ 13 12  4  9  3  1 ]
            [  8  2 12  3 18 16  4  1 ]
            [ 11 16 17  8 20  4 10  2  5  1 ]
            [  1  4 16 18  3 12  2  8  9 13  6  1 ]
            [ 20 16 22 13 15 12  5  4 17  9 21  3  7  1 ]
            [  2  6 18  8  1  3  9  4 12 13 16  2  6 18  8  1 ]
    ] def
} ctxdef
    /check [] def
    includecheck {
        /mod23 mod23map barlen get def
        0
        0 1 data length 1 sub {
            dup data exch get 1 sub exch mod23 exch get mul add
        } for
        23 mod 3 encode /check exch def
    } if

    % Construct the symbol
    /sbs [
        finder aload pop
        data aload pop
        check aload pop
    ] def

    % Create the human readable text
    /txt barlen array def
    0 1 barlen 1 sub {
        /i exch def
        txt i [barcode i 1 getinterval 0 0 () 0] put
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /sbs sbs
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    /txt txt
    /textxalign (center)
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/channelcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER channelcode--

% --BEGIN ENCODER flattermarken--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear--
% --DESC: Flattermarken
% --EXAM: 11099
% --EXOP: inkspread=-0.25 showborder borderleft=0 borderright=0
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp flattermarken 0.0 2022082100 63195 59686
%%BeginData:        104 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/flattermarken {

    20 dict begin                 % Confine variable to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /includetext false def   % Enable/disable text
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /height 0.3 def

    % Validate the input
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.flattermarkenBadCharacter (Flattermarken must contain only digits) //raiseerror exec
        } if
    } forall

    % 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /height height cvr def

    /flattermarken //loadctx exec

    % Validate the input
    barcode {
        dup 48 lt exch 57 gt or {
            /bwipp.flattermarkenBadCharacter (Flattermarken must contain only digits) //raiseerror exec
        } if
    } forall

{
    % Create an array containing the character mappings
    /encs
    [ (0018) (0117) (0216) (0315) (0414) (0513) (0612) (0711) (0810)
      (0900)
    ] def

    % Create a string of the available characters
    /barchars (1234567890) def
} ctxdef

    /barlen barcode length def            % Length of the code

    /sbs barlen 4 mul string def
    /txt barlen array def

    0 1 barlen 1 sub {
        /i exch def
        % Lookup the encoding for the each barcode character
        barcode i 1 getinterval barchars exch search
        pop                                 % Discard true leaving pre
        length /indx exch def               % indx is the length of pre
        pop pop                             % Discard seek and post
        /enc encs indx get def              % Get the indxth encoding
        sbs i 4 mul enc putinterval         % Put encoded digit into sbs
        txt i [barcode i 1 getinterval i 9 mul textyoffset textfont textsize] put
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [sbs {48 sub} forall]
    /bhs [sbs length 1 add 2 idiv {height} repeat]
    /bbs [sbs length 1 add 2 idiv {0} repeat]
    /txt txt
    /opt options
    >>

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/flattermarken dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER flattermarken--

% --BEGIN ENCODER raw--
% --REQUIRES preamble raiseerror renlinear--
% --DESC: Custom 1D symbology
% --EXAM: 331132131313411122131311333213114131131221323
% --EXOP: height=0.5
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp raw 0.0 2022082100 49590 49483
%%BeginData:         55 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/raw {

    20 dict begin                  % Confine variables to local scope

    /options exch def        % We are given an option string
    /barcode exch def        % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /height 1 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

    /height height cvr def

    % Validate input
    barcode {
        dup 49 lt exch 57 gt or {
            /bwipp.rawBadCharacter (Raw must contain only digits 1 to 9) //raiseerror exec
        } if
    } forall

    % Return the arguments
    <<
    /ren //renlinear
    /sbs [barcode {48 sub} forall]
    /bhs [barcode length 1 add 2 idiv {height} repeat]
    /bbs [barcode length 1 add 2 idiv {0} repeat]
    /opt options
    >>

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/raw dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER raw--

% --BEGIN ENCODER daft--
% --REQUIRES preamble raiseerror renlinear--
% --DESC: Custom 4 state symbology
% --EXAM: FATDAFTDAD
% --EXOP:
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp daft 0.0 2022082100 52828 52694
%%BeginData:         79 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/daft {

    20 dict begin

    /options exch def              % We are given an option string
    /barcode exch def              % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /height 0.175 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

    /height height cvr def

    barcode {
        dup 68 ne exch dup 65 ne exch dup 70 ne exch 84 ne and and and {
            /bwipp.daftBadCharacter (DAFT must contain only characters D, A, F and T) //raiseerror exec
        } if
    } forall

    /barlen barcode length def

    /bbs barlen array def
    /bhs barlen array def
    0 1 barlen 1 sub {
        /i exch def
        /enc barcode i 1 getinterval def
        enc (D) eq {
            bbs i 0 height mul 8 div put
            bhs i 5 height mul 8 div put
        } if
        enc (A) eq {
            bbs i 3 height mul 8 div put
            bhs i 5 height mul 8 div put
        } if
        enc (F) eq {
            bbs i 0 height mul 8 div put
            bhs i 8 height mul 8 div put
        } if
        enc (T) eq {
            bbs i 3 height mul 8 div put
            bhs i 2 height mul 8 div put
        } if
    } for

    % Return the arguments
    <<
    /ren //renlinear
    /bbs bbs
    /bhs bhs
    /sbs [bhs length 1 sub {1.44 1.872} repeat 1.44]
    /opt options
    >>

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/daft dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER daft--

% --BEGIN ENCODER symbol--
% --REQUIRES preamble raiseerror renlinear--
% --DESC: Miscellaneous symbols
% --EXAM: fima
% --EXOP: backgroundcolor=DD000011
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp symbol 0.0 2022082100 53420 53349
%%BeginData:         80 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renlinear dup /uk.co.terryburton.bwipp findresource put
begin
/symbol {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw 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

    /symbols <<
        /fima {
            /sbs [2.25 2.25 2.25 11.25 2.25 11.25 2.25 2.25 2.25] def
            /bhs [.625 .625 .625 .625 .625] def
            /bbs [0 0 0 0 0] def
        } bind
        /fimb {
            /sbs [2.25 6.75 2.25 2.25 2.25 6.25 2.25 2.25 2.25 6.75 2.25] def
            /bhs [.625 .625 .625 .625 .625 .625] def
            /bbs [0 0 0 0 0 0] def
        } bind
        /fimc {
            /sbs [2.25 2.25 2.25 6.75 2.25 6.75 2.25 6.75 2.25 2.25 2.25] def
            /bhs [.625 .625 .625 .625 .625 .625] def
            /bbs [0 0 0 0 0 0] def
        } bind
        /fimd {
            /sbs [2.25 2.25 2.25 2.25 2.25 6.75 2.25 6.75 2.25 2.25 2.25 2.25 2.25] def
            /bhs [.625 .625 .625 .625 .625 .625 .625] def
            /bbs [0 0 0 0 0 0 0] def
        } bind
        /fime {
            /sbs [2.25 6.75 2.25 15.75 2.25 6.75 2.25] def
            /bhs [.625 .625 .625 .625 .625 .625 .625] def
            /bbs [0 0 0 0 0 0 0] def
        } bind
    >> def

    % Valiate input
    symbols barcode known not {
        /bwipp.symbolUnknownSymbol (Unknown symbol name provided) //raiseerror exec
    } if

    symbols barcode get exec

    % Return the arguments
    <<
    /ren //renlinear
    /sbs sbs
    /bhs bhs
    /bbs bbs
    /opt options
    >>

    dontdraw not //renlinear if

    end

}
[/barcode] {null def} forall
bind def
/symbol dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER symbol--

% --BEGIN ENCODER pdf417--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: PDF417
% --EXAM: This is PDF417
% --EXOP: columns=2
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp pdf417 0.0 2022082100 202024 204168
%%BeginData:        911 ASCII Lines
/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 /parseinput 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

    /ctx null 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
    /parsefnc 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

    /pdf417 //loadctx exec

{
    % 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

    /latchcws <<
        tl 900  bl 901  bl6 924  nl 902  bs 913
    >> def
} ctxdef

    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

    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
    } def

    encoding (byte) eq encoding (ccc) eq or {
        /barlen barcode length def
        /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 {} forall ] encb putinterval
        encoding (ccc) eq {/datcws [920 datcws aload pop] def} if
    } if

    encoding (auto) eq {

        % Parse the input
        /fncvals <<
            /parse parse
            /parsefnc parsefnc
            /eci true
            % Predates FNC non-data codewords, but supports ECI
        >> def
        /msg barcode fncvals //parseinput exec def
        /msglen msg length def

        % Determine runlengths of digits
        /numdigits [ msglen {0} repeat 0 ] def
        /numtext   [ msglen {0} repeat 0 ] def
        /numbytes  [ msglen {0} repeat 0 ] def
        /iseci     [ msglen {0} repeat 0 ] def
        msglen 1 sub -1 0 {
            /i exch def
            msg i get dup 48 ge exch 57 le and {
                numdigits i numdigits i 1 add get 1 add put
            } if
            alltext msg i get known numdigits i get 13 lt and {
                numtext i numtext i 1 add get 1 add put
            } if
            msg i get 0 ge numtext i get 5 lt and numdigits i get 13 lt and {
                numbytes i numbytes i 1 add get 1 add put
            } if
            iseci i msg i get -1000000 le put
        } for
        /numdigits numdigits 0 msglen getinterval def
        /numtext   numtext   0 msglen getinterval def
        /numbytes  numbytes  0 msglen getinterval def

        /seq [] def /seqlen 0 def /state T def /p 0 def {  % loop
            p msglen eq {exit} if
            iseci p get {
                /eci msg p get def
                /seq [
                    seq aload pop
                    [ eci ]
                ] def
                /p p 1 add def
                /seqlen seqlen eci -1810900 le {2} {eci -1000900 le {3} {2} ifelse} ifelse add def
            } {
            /n numdigits p get def
            n 13 ge {
                /seq [
                    seq aload pop
                    nl
                    [ msg 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
                    [ msg 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
                    [ msg 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
                    [ msg p b getinterval aload pop ]
                ] def
                /state B def
                /p p b add def
                /seqlen seqlen 1 add b add def
            } ifelse } ifelse } ifelse } ifelse
        } loop

        % Submode encoding functions
        /enca {charvals A get exch get} def
        /encl {charvals L get exch get} def
        /encm {charvals M get exch get} def
        /encp {charvals P get exch get} def
        /textencfuncs [ /enca /encl /encm /encp ] def

        /addtotext {
            text exch l exch put
            /l l 1 add def
        } 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

        } 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
        } def

        /ence {
            0 get neg 1000000 sub
                dup 000899 le {  % ECI 000000 - 000899
                927 exch 2 array astore
            } { dup 810899 le {  % ECI 000900 - 810899
                926 exch dup 900 idiv 1 sub exch 900 mod 3 array astore
            } { dup 811799 le {  % ECI 810900 - 811799
                925 exch 810900 sub 2 array astore
            } {
                /bwipp.pdf417badECI (PDF417 supports ECIs 000000 to 811799) //raiseerror exec
            } ifelse } ifelse } ifelse
        } def

        /encfuncs [ /enct /encn /encb ] def

        /addtocws {
            dup datcws j 3 -1 roll putinterval
            length j add /j exch def
        } 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 {
                chars 0 get -1000000 le {  % ECI
                    chars ence addtocws
                } {  % Encode data according to mode
                    chars encfuncs state get load exec addtocws
                } ifelse
            } {  % 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
    /c columns 1 ge {columns} {1} ifelse def

    % ... 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

    % Symbol cannot exceed 90 rows
    r 90 gt {
      /bwipp.pdf417insufficientCapacity (Insufficient capacity in the symbol) //raiseerror exec
    } 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
    } 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

    options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if

    % 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
             81040 106060  97680 114380 106054  97672  81028  97668  81026  97666  72792 101934
             81112  72780  97752  81100  72774  97740  81094  97734  68654  72814  81134  97774
            114256 122668 114248 122662 114244 114242  80976 106028  97488  80968 106022  97480
            114278  97476  80962  97474  72748  81004  72742  97516  80998  97510 114216 122646
            114212 114210  80936 106006  97384  80932  97380  80930  97378  72726  80950  97398
            114196 114194  80916  97332  80914  97330  66236  66206  67256  99166  67228  67214
             66142  67294  69296 100188  69272 100174  69260  69254  67164  69340  67150  69326
             73376 102232 116654  73360 102220  73352 102214  73348  73346  69208 100142  73432
            102254  73420  69190  73414  67118  69230  73454 106320 118700 106312 118694 106308
            106306  73296 102188  81616 106348 102182  81608  73284  81604  73282  81602  69164
             73324  69158  81644  73318  81638 122792 126934 122788 122786 106280 118678 114536
            106276 114532 106274 114530  73256 102166  81512  73252  98024  81508  73250  98020
             81506  98018  69142  73270  81526  98038 122772 122770 106260 114484 106258 114482
             73236  81460  73234  97908  81458  97906 122762 106250 114458  73226  81434  97850
             66396  66382  67416  99246  67404  67398  66350  67438  69456 100268  69448 100262
             69444  69442  67372  69484  67366  69478 102312 116694 102308 102306  69416 100246
             73576 102326  73572  69410  73570  67350  69430  73590 118740 118738 102292 106420
            102290 106418  69396  73524  69394  81780  73522  81778 118730 102282 106394  69386
             73498  81722  66476  66470  67496  99286  67492  67490  66454  67510 100308 100306
             67476  69556  67474  69554 116714
        ]
    ] def
} ctxdef

    % Return the 17 bits for a codeword in a given cluster
    /cwtobits {
        clusters exch get exch get /v exch def
        [ 17 {0} repeat v 2 17 string cvrs {48 sub} forall ]
        dup length 17 sub 17 getinterval
    } def

    % Populate bitmap for the image
    compact {
        /rwid 17 c mul 17 add 17 add 1 add def
    } {
        /rwid 17 c mul 17 add 17 add 17 add 18 add def
    } ifelse
    /pixs rwid r mul array def

    0 1 r 1 sub {
        /i exch def

        i 3 mod 0 eq {
            /lcw i 3 idiv 30 mul r 1 sub 3 idiv add def
            /rcw i 3 idiv 30 mul c add 1 sub def
        } if
        i 3 mod 1 eq {
            /lcw i 3 idiv 30 mul eclevel 3 mul add r 1 sub 3 mod add def
            /rcw i 3 idiv 30 mul r 1 sub 3 idiv add def
        } if
        i 3 mod 2 eq {
            /lcw i 3 idiv 30 mul c add 1 sub def
            /rcw i 3 idiv 30 mul eclevel 3 mul add r 1 sub 3 mod add def
        } if

        pixs rwid i mul [
            1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 0 0
            lcw i 3 mod cwtobits {} forall
            cws c i mul c getinterval { i 3 mod cwtobits {} forall } forall
            compact {
                1
            } {
                rcw i 3 mod cwtobits {} forall
                1 1 1 1 1 1 1 0 1 0 0 0 1 0 1 0 0 1
            } ifelse
        ] putinterval

    } for

    % Return the arguments
    <<
    /ren //renmatrix
    /pixs pixs
    /pixx rwid
    /pixy r
    /height r 72 div rowmult mul
    /width rwid 72 div
    /opt options
    >>

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/pdf417 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER pdf417--

% --BEGIN ENCODER pdf417compact--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix pdf417--
% --DESC: Compact PDF417
% --EXAM: This is compact PDF417
% --EXOP: columns=2
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp pdf417compact 0.0 2022082100 62537 62516
%%BeginData:         46 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /pdf417 dup /uk.co.terryburton.bwipp findresource put
begin
/pdf417compact {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw 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

    % Get the result of encoding with pdf417 with compact option
    options (dontdraw) true put
    options (compact) true put

    /args barcode options //pdf417 exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/pdf417compact dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER pdf417compact--

% --BEGIN ENCODER micropdf417--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: MicroPDF417
% --EXAM: MicroPDF417
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp micropdf417 0.0 2022082100 212812 214997
%%BeginData:        998 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/micropdf417 {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /version (unset) def
    /columns 0 def
    /rows 0 def
    /rowmult 2 def
    /encoding (auto) def
    /cca false def
    /ccb false def
    /raw false def
    /parse false def
    /parsefnc 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

    version (unset) ne {
        version (x) search
        pop /columns exch def
        pop /rows exch def
    } if

    /columns columns cvi def
    /rows rows cvi def
    /rowmult rowmult cvr def

    /micropdf417 //loadctx exec

{
    % 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
} ctxdef

    raw {/encoding (raw) def} if
    cca {/encoding (cca) def} if

    % Convert input into array of codewords
    encoding (raw) eq encoding (cca) eq or {
        /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

    ccb {/encoding (ccb) 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
    } def

    encoding (byte) eq encoding (ccb) eq or {
        /barlen barcode length def
        /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 {} forall ] encb putinterval
        encoding (ccb) eq {/datcws [920 datcws aload pop] def} if
    } if

    encoding (auto) eq {

        % Parse the input
        /fncvals <<
            /parse parse
            /parsefnc parsefnc
            /eci true
            % Predates FNC non-data codewords, but supports ECI
        >> def
        /msg barcode fncvals //parseinput exec def
        /msglen msg length def

        % Determine runlengths of digits
        /numdigits [ msglen {0} repeat 0 ] def
        /numtext   [ msglen {0} repeat 0 ] def
        /numbytes  [ msglen {0} repeat 0 ] def
        /iseci     [ msglen {0} repeat ] def
        msglen 1 sub -1 0 {
            /i exch def
            msg i get dup 48 ge exch 57 le and {
                numdigits i numdigits i 1 add get 1 add put
            } if
            alltext msg i get known numdigits i get 13 lt and {
                numtext i numtext i 1 add get 1 add put
            } if
            msg i get 0 ge numtext i get 5 lt and numdigits i get 13 lt and {
                numbytes i numbytes i 1 add get 1 add put
            } if
            iseci i msg i get -1000000 le put
        } for
        /numdigits numdigits 0 msglen getinterval def
        /numtext   numtext   0 msglen getinterval def
        /numbytes  numbytes  0 msglen getinterval def

        /seq [] def /seqlen 0 def /state B def /p 0 def {  % loop
            p msglen eq {exit} if
            iseci p get {
                /eci msg p get def
                /seq [
                    seq aload pop
                    [ eci ]
                ] def
                /p p 1 add def
                /seqlen seqlen eci -1810900 le {2} {eci -1000900 le {3} {2} ifelse} ifelse add def
            } {
            /n numdigits p get def
            n 13 ge {
                /seq [
                    seq aload pop
                    nl
                    [ msg 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
                    [ msg 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
                    [ msg 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
                    [ msg p b getinterval aload pop ]
                ] def
                /state B def
                /p p b add def
                /seqlen seqlen 1 add b add def
            } ifelse } 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} def
        /encl {charvals L get exch get} def
        /encm {charvals M get exch get} def
        /encp {charvals P get exch get} def
        /textencfuncs [ /enca /encl /encm /encp ] def

        /addtotext {
            text exch l exch put
            /l l 1 add def
        } 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

        } 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
        } def

        /ence {
            0 get neg 1000000 sub
                dup 000899 le {  % ECI 000000 - 000899
                927 exch 2 array astore
            } { dup 810899 le {  % ECI 000900 - 810899
                926 exch dup 900 idiv 1 sub exch 900 mod 3 array astore
            } { dup 811799 le {  % ECI 810900 - 811799
                925 exch 810900 sub 2 array astore
            } {
                /bwipp.pdf417badECI (PDF417 supports ECIs 000000 to 811799) //raiseerror exec
            } ifelse } ifelse } ifelse
        } def

        /encfuncs [ /enct /encn /encb ] def

        /addtocws {
            dup datcws j 3 -1 roll putinterval
            length j add /j exch def
        } def

        % Encode the sequence
        % No need to set state as seq will always begin with a latch, unlike for pdf417
        /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 0 get -1000000 le {  % ECI
                    chars ence addtocws
                } {  % Encode data according to mode
                    chars encfuncs state get load exec addtocws
                } ifelse
            } {  % 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

{
    % Basic metrics for the each symbol
    %     c  r ecw  rl rc rr
    /ccametrics [
        [ 2  5   4  39  0 19 ]
        [ 2  6   4   1  0 33 ]
        [ 2  7   5  32  0 12 ]
        [ 2  8   5   8  0 40 ]
        [ 2  9   6  14  0 46 ]
        [ 2 10   6  43  0 23 ]
        [ 2 12   7  20  0 52 ]
        [ 3  4   4  11 43 23 ]
        [ 3  5   5   1 33 13 ]
        [ 3  6   6   5 37 17 ]
        [ 3  7   7  15 47 27 ]
        [ 3  8   7  21  1 33 ]
        [ 4  3   4  40 20 52 ]
        [ 4  4   5  43 23  3 ]
        [ 4  5   6  46 26  6 ]
        [ 4  6   7  34 14 46 ]
        [ 4  7   8  29  9 41 ]
    ] def

    % Basic metrics for the each symbol
    %     c  r ecw  rl rc rr
    /nonccametrics [
        [ 1 11   7   1  0  9 ]
        [ 1 14   7   8  0  8 ]
        [ 1 17   7  36  0 36 ]
        [ 1 20   8  19  0 19 ]
        [ 1 24   8   9  0 17 ]
        [ 1 28   8  25  0 33 ]
        [ 2  8   8   1  0  1 ]
        [ 2 11   9   1  0  9 ]
        [ 2 14   9   8  0  8 ]
        [ 2 17  10  36  0 36 ]
        [ 2 20  11  19  0 19 ]
        [ 2 23  13   9  0 17 ]
        [ 2 26  15  27  0 35 ]
        [ 3  6  12   1  1  1 ]
        [ 3  8  14   7  7  7 ]
        [ 3 10  16  15 15 15 ]
        [ 3 12  18  25 25 25 ]
        [ 3 15  21  37 37 37 ]
        [ 3 20  26   1 17 33 ]
        [ 3 26  32   1  9 17 ]
        [ 3 32  38  21 29 37 ]
        [ 3 38  44  15 31 47 ]
        [ 3 44  50   1 25 49 ]
        [ 4  4   8  47 19 43 ]
        [ 4  6  12   1  1  1 ]
        [ 4  8  14   7  7  7 ]
        [ 4 10  16  15 15 15 ]
        [ 4 12  18  25 25 25 ]
        [ 4 15  21  37 37 37 ]
        [ 4 20  26   1 17 33 ]
        [ 4 26  32   1  9 17 ]
        [ 4 32  38  21 29 37 ]
        [ 4 38  44  15 31 47 ]
        [ 4 44  50   1 25 49 ]
    ] def
} ctxdef

    /metrics cca {ccametrics} {nonccametrics} ifelse def

    % Select metrics of an appropriate symbol
    /urows rows def
    /ucols columns def
    /i 0 def
    { % loop
        /m metrics i get def
        /c    m 0 get def        % Columns in symbol
        /r    m 1 get def        % Rows in symbol
        /k    m 2 get def        % Error correction codewords
        /rapl m 3 get def        % Left row address pattern
        /rapc m 4 get def        % Centre row address pattern
        /rapr m 5 get def        % Right row address pattern
        /ncws r c mul k sub def  % Data codewords
        /okay true def
        datcws length ncws gt     {/okay false def} if
        urows 0 ne urows r ne and {/okay false def} if
        ucols 0 ne ucols c ne and {/okay false def} if
        okay {exit} if
        /i i 1 add def
    } loop
    /m datcws length def

    % 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 datcws putinterval
    cws m [ n m 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
} ctxdef

    % 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
    } 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

    options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if

{
    % 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
             81040 106060  97680 114380 106054  97672  81028  97668  81026  97666  72792 101934
             81112  72780  97752  81100  72774  97740  81094  97734  68654  72814  81134  97774
            114256 122668 114248 122662 114244 114242  80976 106028  97488  80968 106022  97480
            114278  97476  80962  97474  72748  81004  72742  97516  80998  97510 114216 122646
            114212 114210  80936 106006  97384  80932  97380  80930  97378  72726  80950  97398
            114196 114194  80916  97332  80914  97330  66236  66206  67256  99166  67228  67214
             66142  67294  69296 100188  69272 100174  69260  69254  67164  69340  67150  69326
             73376 102232 116654  73360 102220  73352 102214  73348  73346  69208 100142  73432
            102254  73420  69190  73414  67118  69230  73454 106320 118700 106312 118694 106308
            106306  73296 102188  81616 106348 102182  81608  73284  81604  73282  81602  69164
             73324  69158  81644  73318  81638 122792 126934 122788 122786 106280 118678 114536
            106276 114532 106274 114530  73256 102166  81512  73252  98024  81508  73250  98020
             81506  98018  69142  73270  81526  98038 122772 122770 106260 114484 106258 114482
             73236  81460  73234  97908  81458  97906 122762 106250 114458  73226  81434  97850
             66396  66382  67416  99246  67404  67398  66350  67438  69456 100268  69448 100262
             69444  69442  67372  69484  67366  69478 102312 116694 102308 102306  69416 100246
             73576 102326  73572  69410  73570  67350  69430  73590 118740 118738 102292 106420
            102290 106418  69396  73524  69394  81780  73522  81778 118730 102282 106394  69386
             73498  81722  66476  66470  67496  99286  67492  67490  66454  67510 100308 100306
             67476  69556  67474  69554 116714
        ]
    ] def

    % Row address patterns
    /raps [
        [  % Left and right
            802 930 946 818 882 890 826 954 922 986 970 906 778
            794 786 914 978 982 980 916 948 932 934 942 940 936
            808 812 814 806 822 950 918 790 788 820 884 868 870
            878 876 872 840 856 860 862 846 844 836 838 834 866
        ] [  % Centre
            718 590 622 558 550 566 534 530 538 570 562 546 610
            626 634 762 754 758 630 628 612 614 582 578 706 738
            742 740 748 620 556 552 616 744 712 716 708 710 646
            654 652 668 664 696 688 656 720 592 600 604 732 734
        ]
    ] def
} ctxdef

    % Return the 17 bits for a codeword in a given cluster
    /cwtobits {
        clusters exch get exch get /v exch def
        [ 17 {0} repeat v 2 17 string cvrs {48 sub} forall ]
        dup length 17 sub 17 getinterval
    } def

    % Return the 10 bits for a row address pattern
    /raptobits {
        raps exch get exch get /v exch def
        [ 10 {0} repeat v 2 10 string cvrs {48 sub} forall ]
        dup length 10 sub 10 getinterval
    } def

    % Populate bitmap for the image
    /rwid [38 55 82 99] c 1 sub get def
    c 3 eq cca and {/rwid 72 def} if
    /pixs rwid r mul array def

    0 1 r 1 sub {
        /i exch def
        /clst i rapl add 1 sub 3 mod def
        pixs rwid i mul [
            c 1 eq {
                i rapl add 1 sub 52 mod 0 raptobits aload pop
                cws i get clst cwtobits aload pop
                i rapr add 1 sub 52 mod 0 raptobits aload pop
            } if
            c 2 eq {
                i rapl add 1 sub 52 mod 0 raptobits aload pop
                cws i 2 mul get clst cwtobits aload pop
                cws i 2 mul 1 add get clst cwtobits aload pop
                i rapr add 1 sub 52 mod 0 raptobits aload pop
            } if
            c 3 eq {
                cca not {
                    i rapl add 1 sub 52 mod 0 raptobits aload pop
                } if
                cws i 3 mul get clst cwtobits aload pop
                i rapc add 1 sub 52 mod 1 raptobits aload pop
                cws i 3 mul 1 add get clst cwtobits aload pop
                cws i 3 mul 2 add get clst cwtobits aload pop
                i rapr add 1 sub 52 mod 0 raptobits aload pop
            } if
            c 4 eq {
                i rapl add 1 sub 52 mod 0 raptobits aload pop
                cws i 4 mul get clst cwtobits aload pop
                cws i 4 mul 1 add get clst cwtobits aload pop
                i rapc add 1 sub 52 mod 1 raptobits aload pop
                cws i 4 mul 2 add get clst cwtobits aload pop
                cws i 4 mul 3 add get clst cwtobits aload pop
                i rapr add 1 sub 52 mod 0 raptobits aload pop
            } if
            1
        ] putinterval
    } for

    % Return the arguments
    <<
    /ren //renmatrix
    /pixs pixs
    /pixx rwid
    /pixy r
    /height r 72 div rowmult mul
    /width rwid 72 div
    /opt options
    >>

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/micropdf417 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER micropdf417--

% --BEGIN ENCODER datamatrix--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: Data Matrix
% --EXAM: This is Data Matrix!
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp datamatrix 0.0 2022082100 213189 215115
%%BeginData:        934 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/datamatrix {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /columns 0 def
    /rows 0 def
    /format (square) def    % square or rectangle
    /version (unset) def
    /parse false def
    /parsefnc false def
    /encoding (auto) def
    /mailmark false def
    /raw false def
    /dmre false def      % Alias for isodmre
    /dindmre false def
    /isodmre 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

    version (unset) ne {
        version (x) search
        pop /rows exch def
        pop /columns exch def
    } if

    /columns columns cvi def
    /rows rows cvi def

    /isodmre dmre def

    /datamatrix //loadctx exec

    % TODO make this "static"
    % Basic metrics for the each symbol
    %                         rows  cols  regh  regv  rscw  rsbl
    /metrics [
        % Standard square symbols
                             [  10    10     1     1     5     1 ]
                             [  12    12     1     1     7     1 ]
                             [  14    14     1     1    10     1 ]
                             [  16    16     1     1    12     1 ]
                             [  18    18     1     1    14     1 ]
                             [  20    20     1     1    18     1 ]
                             [  22    22     1     1    20     1 ]
                             [  24    24     1     1    24     1 ]
                             [  26    26     1     1    28     1 ]
                             [  32    32     2     2    36     1 ]
                             [  36    36     2     2    42     1 ]
                             [  40    40     2     2    48     1 ]
                             [  44    44     2     2    56     1 ]
                             [  48    48     2     2    68     1 ]
                             [  52    52     2     2    84     2 ]
                             [  64    64     4     4   112     2 ]
                             [  72    72     4     4   144     4 ]
                             [  80    80     4     4   192     4 ]
                             [  88    88     4     4   224     4 ]
                             [  96    96     4     4   272     4 ]
                             [ 104   104     4     4   336     6 ]
                             [ 120   120     6     6   408     6 ]
                             [ 132   132     6     6   496     8 ]
                             [ 144   144     6     6   620    10 ]
        % Optional rectangular symbols
                             [   8    18     1     1     7     1 ]
                             [   8    32     1     2    11     1 ]
        dindmre isodmre or { [   8    48     1     2    15     1 ] } if
        dindmre isodmre or { [   8    64     1     4    18     1 ] } if
                isodmre    { [   8    80     1     4    22     1 ] } if
                isodmre    { [   8    96     1     4    28     1 ] } if
                isodmre    { [   8   120     1     6    32     1 ] } if
                isodmre    { [   8   144     1     6    36     1 ] } if
                             [  12    26     1     1    14     1 ]
                             [  12    36     1     2    18     1 ]
        dindmre isodmre or { [  12    64     1     4    27     1 ] } if
                isodmre    { [  12    88     1     4    36     1 ] } if
                             [  16    36     1     2    24     1 ]
                             [  16    48     1     2    28     1 ]
        dindmre isodmre or { [  16    64     1     4    36     1 ] } if
                isodmre    { [  20    36     1     2    28     1 ] } if
                isodmre    { [  20    44     1     2    34     1 ] } if
                isodmre    { [  20    64     1     4    42     1 ] } if
                isodmre    { [  22    48     1     2    38     1 ] } if
        dindmre            { [  24    32     1     2    28     1 ] } if
        dindmre            { [  24    36     1     2    33     1 ] } if
        dindmre isodmre or { [  24    48     1     2    41     1 ] } if
        dindmre isodmre or { [  24    64     1     4    46     1 ] } if
        dindmre            { [  26    32     1     2    32     1 ] } if
        dindmre isodmre or { [  26    40     1     2    38     1 ] } if
        dindmre isodmre or { [  26    48     1     2    42     1 ] } if
        dindmre isodmre or { [  26    64     1     4    50     1 ] } if
    ] def

    % Create array of codewords remaining to make a full symbol
    /urows rows def
    /ucols columns def
    /fullcws [] def
    metrics {
        /m exch def
        /rows m 0 get def                          % Rows in symbol
        /cols m 1 get def                          % Columns in symbol
        /regh m 2 get def                          % Horizontal regions
        /regv m 3 get def                          % Vertical regions
        /rscw m 4 get def                          % Error correction codewords
        /rsbl m 5 get def                          % Error correction blocks
        /mrows rows 2 regh mul sub def             % Rows in the mapping matrix
        /mcols cols 2 regv mul sub def             % Columns in the mapping matrix
        /ncws mrows mcols mul 8 idiv rscw sub def  % Data codewords
        /okay true def
        urows 0 ne urows rows ne and {/okay false def} if
        ucols 0 ne ucols cols ne and {/okay false def} if
        format (square) eq rows cols ne and {/okay false def} if
        format (rectangle) eq rows cols eq and {/okay false def} if
        okay {/fullcws [ fullcws aload pop ncws ] def} if
    } forall
    /numremcws [ 1558 {10000} repeat ] def
    fullcws {numremcws exch 1 sub 1 put} forall
    1556 -1 0 {
        /i exch def
        numremcws i get 1 ne {
            numremcws i numremcws i 1 add get 1 add put
        } if
    } for

{
    % Special characters
    /fnc1  -1 def  /prog  -2 def  /m05   -3 def  /m06   -4 def
    /lC    -5 def  /lB    -6 def  /lX    -7 def  /lT    -8 def  /lE    -9 def  /unl -10 def
    /sapp -11 def  /usft -12 def  /sft1 -13 def  /sft2 -14 def  /sft3 -15 def  /eci -16 def  /pad -17 def
    /unlcw 254 def

    /Avals <<
        0 1 128 {dup 1 add} for
        pad 129
        0 1 99 {  % Double digits
            dup 10 2 string cvrs (00) 2 string copy dup 2 3 index length sub 4 -1 roll putinterval
            exch 130 add
        } for
        229 [ lC lB fnc1 sapp prog usft m05 m06 lX lT lE eci ] {exch 1 add dup} forall pop
    >> def
    /Avals <<
        Avals {[exch]} forall
    >> def

    /CNvals <<
        sft1 0
        sft2 1
        sft3 2
        32   3
        48 1 57 {dup 44 sub} for  % 0-9
        65 1 90 {dup 51 sub} for  % A-Z
    >> def
    /C1vals << 0 1 31 {dup} for >> def
    /C2vals <<
        33 1 47 {dup 33 sub} for
        58 1 64 {dup 43 sub} for
        91 1 95 {dup 69 sub} for
        fnc1 27
        usft 30
    >> def
    /C3vals << 96 1 127 {dup 96 sub} for >> def
    /Cvals <<
        CNvals {[exch]} forall
        C1vals {[exch CNvals sft1 get exch]} forall
        C2vals {[exch CNvals sft2 get exch]} forall
        C3vals {[exch CNvals sft3 get exch]} forall
    >> def

    /TNvals <<
        sft1 0
        sft2 1
        sft3 2
        32   3
        48 1  57 {dup 44 sub} for  % 0-9
        97 1 122 {dup 83 sub} for  % a-z
    >> def
    /T1vals << 0 1 31 {dup} for >> def
    /T2vals <<
        33 1 47 {dup 33 sub} for
        58 1 64 {dup 43 sub} for
        91 1 95 {dup 69 sub} for
        fnc1 27
        usft 30
    >> def
    /T3vals <<
         96 0
         65 1  90 {dup 64 sub} for
        123 1 127 {dup 96 sub} for
    >> def
    /Tvals <<
        TNvals {[exch]} forall
        T1vals {[exch TNvals sft1 get exch]} forall
        T2vals {[exch TNvals sft2 get exch]} forall
        T3vals {[exch TNvals sft3 get exch]} forall
    >> def

    % Extended ASCII mappings
    128 1 255 {
        /i exch def
        Avals i [ Avals usft get aload pop Avals i 128 sub get aload pop ] put
        Cvals i [ Cvals usft get aload pop Cvals i 128 sub get aload pop ] put
        Tvals i [ Tvals usft get aload pop Tvals i 128 sub get aload pop ] put
    } for

    /Xvals <<
        13 0
        42 1
        62 2
        32 3
        48 1 57 {dup 44 sub} for
        65 1 90 {dup 51 sub} for
    >> def
    /Xvals <<
        Xvals {[exch]} forall
    >> def

    /Evals <<
        64 1 94 {dup 64 sub} for
        unl 31
        32 1 63 {dup} for
    >> def
    /Evals <<
        Evals {[exch]} forall
    >> def

    /Bvals <<
        0 1 255 {dup} for
    >> def
    /Bvals <<
        Bvals {[exch]} forall
    >> def

    /encvals [ Avals Cvals Tvals Xvals Evals Bvals ] def

    /A 0 def  /C 1 def  /T 2 def  /X 3 def  /E 4 def  /B 5 def
} ctxdef

    raw {/encoding (raw) def} if

    encoding (raw) eq {
        /cws 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
            cws j cw put
            /i i 4 add def
            /j j 1 add def
        } loop
        /cws cws 0 j getinterval def
    } if  % encoding=raw

    encoding (auto) eq {

        % Parse the input
        /fncvals <<
            /parse parse
            /parsefnc parsefnc
            /eci true
            (FNC1) fnc1
            (PROG) prog
%            (MAC5) m05    Encoded automatically
%            (MAC6) m06    Encoded automatically
        >> def
        /msg barcode fncvals //parseinput exec def
        /msglen msg length def

        % Macro 05/06 compression of [)>{RS}05/06{GS}...{RS}{EOT} structured data
        msglen 9 ge {
            msg 0 7 getinterval aload pop
            29 eq exch pop exch 48 eq and exch  % [)>{RS}0*{GS}...
            30 eq and exch 62 eq and exch 41 eq and exch 91 eq and {
                msg msglen 2 sub 2 getinterval aload pop
                4 eq exch 30 eq and {           %              ...{RS}{EOT}
                    msg 5 get 53 eq {           %      ...5...
                        /msg [ m05 msg 7 msg length 9 sub getinterval aload pop ] def
                    } {
                        msg 5 get 54 eq {       %      ...6...
                            /msg [ m06 msg 7 msg length 9 sub getinterval aload pop ] def
                        } if
                    } ifelse
                } if
            } if
        } if
        /msglen msg length def

        /numD      [ msglen {0} repeat 0 ] def
        /nextXterm [ msglen {0} repeat 9999 ] def
        /nextNonX  [ msglen {0} repeat 9999 ] def
        /isECI     [ msglen {false} repeat false ] def
        msglen 1 sub -1 0 {
            /i exch def
            /barchar msg i get def
            barchar 48 ge barchar 57 le and {
                numD i numD i 1 add get 1 add put
            } if
            barchar 13 eq barchar 42 eq or barchar 62 eq or {
                nextXterm i 0 put
            } {
                nextXterm i nextXterm i 1 add get 1 add put
            } ifelse
            Xvals barchar known not {
                nextNonX i 0 put
            } {
                nextNonX i nextNonX i 1 add get 1 add put
            } ifelse
            isECI i barchar -1000000 le put
        } for
        /nextXterm [nextXterm {dup 10000 gt {pop 10000} if} forall] def
        /nextNonX  [nextNonX  {dup 10000 gt {pop 10000} if} forall] def

        /isD  {char 48 ge char 57 le and} def
        /isC  {CNvals char known} def
        /isT  {TNvals char known} def
        /isX  {Xvals char known} def
        /isE  {Evals char known} def
        /isEA {char 127 gt} def
        /isFN {char 0 lt} def
        /XtermFirst {dup nextXterm exch get exch nextNonX exch get lt} def

        /lookup {
            /ac 1 def /cc 2 def /tc 2 def /xc 2 def /ec 2 def /bc 2.25 def
            mode A eq {/ac 0 def /cc 1 def /tc 1 def /xc 1 def /ec 1 def /bc 1.25 def} if
            mode C eq {/cc 0 def} if
            mode T eq {/tc 0 def} if
            mode X eq {/xc 0 def} if
            mode E eq {/ec 0 def} if
            mode B eq {/bc 0 def} if
            1 {  % common exit
                isECI i get {A exit} if  % ECI only in ASCII
                mailmark i 45 lt and {C exit} if  % Mailmark is C40 only for 45 characters
                /k 0 def {  % loop
                    i k add msglen eq {
                        [/ac /cc /tc /xc /ec /bc] {dup load ceiling def} forall
                        true [   cc tc xc ec bc] {ac exch le and} forall {A exit} if
                        true [ac cc tc xc ec   ] {bc exch lt and} forall {B exit} if
                        true [ac cc tc xc    bc] {ec exch lt and} forall {E exit} if
                        true [ac cc    xc ec bc] {tc exch lt and} forall {T exit} if
                        true [ac cc tc    ec bc] {xc exch lt and} forall {X exit} if
                        C exit
                    } if
                    /char msg i k add get def
                    /ac ac isD {1 2 div add} {isEA {ceiling 2 add} {ceiling 1 add} ifelse} ifelse def
                    /cc cc isC {2 3 div add} {isEA { 8 3 div add } { 4 3 div add } ifelse} ifelse def
                    /tc tc isT {2 3 div add} {isEA { 8 3 div add } { 4 3 div add } ifelse} ifelse def
                    /xc xc isX {2 3 div add} {isEA {13 3 div add } {10 3 div add } ifelse} ifelse def
                    /ec ec isE {3 4 div add} {isEA {17 4 div add } {13 4 div add } ifelse} ifelse def
                    /bc bc isFN {4 add} {1 add} ifelse def
                    k 4 ge {
                        true [   cc tc xc ec bc] {ac 1 add exch le and} forall {A exit} if
                        bc 1 add ac le {B exit} if
                        true [   cc tc xc ec   ] {bc 1 add exch lt and} forall {B exit} if
                        true [ac cc tc xc    bc] {ec 1 add exch lt and} forall {E exit} if
                        true [ac cc    xc ec bc] {tc 1 add exch lt and} forall {T exit} if
                        true [ac cc tc    ec bc] {xc 1 add exch lt and} forall {X exit} if
                        true [ac    tc    ec bc] {cc 1 add exch lt and} forall {
                            cc xc lt {C exit} if
                            cc xc eq {i k add 1 add XtermFirst {X exit} {C exit} ifelse} if
                        } if
                    } if
                    /k k 1 add def
                } loop
            } repeat
        } def

        /addtocws {
            dup cws exch j exch putinterval
            /j exch length j add def
        } def

        /ECItocws {
            neg 1000000 sub
                dup 000126 le {  % ECI 000000 - 000126
                1 add
                1 array astore
            } { dup 016382 le {  % ECI 000127 - 016382
                127 sub
                dup 254 idiv 128 add exch
                    254 mod 1 add
                2 array astore
            } {                  % ECI 016383 - 999999
                16383 sub
                dup 64516 idiv         192 add exch
                dup   254 idiv 254 mod   1 add exch
                               254 mod   1 add
                3 array astore
            } ifelse } ifelse
        } def

        /encA {
            1 {  % Common exit
                isECI i get {
                    Avals eci get addtocws
                    msg i get ECItocws addtocws
                    /i i 1 add def
                    exit
                } if
                numD i get 2 ge {
                    2 string dup 0 msg i get put dup 1 msg i 1 add get put Avals exch get addtocws
                    /i i 2 add def
                    exit
                } if
                /newmode lookup def
                newmode mode ne {
                    Avals [-1 lC lT lX lE lB] newmode get get addtocws
                    /mode newmode def
                    exit
                } if
                Avals msg i get get addtocws
                /i i 1 add def
                exit
            } repeat
        } def

        /CTXvalstocws {
            /in exch def
            mark
            0 3 in length 1 sub {
                in exch 3 getinterval 0 exch {add 40 mul} forall 40 idiv 1 add
                dup 256 idiv exch 256 mod
            } for
            counttomark array astore exch pop
        } def

        /encCTX {
            /p 0 def
            /ctxvals 2500 array def
            /done false def

            % Lookup the values for each character
            {
                i msglen eq {exit} if
                encvals mode get msg i get known not {exit} if
                p 3 mod 0 eq {
                    p 0 gt {
                        /newmode lookup def
                        newmode mode ne {
                            ctxvals 0 p getinterval CTXvalstocws addtocws
                            [unlcw] addtocws
                            newmode A ne {
                                Avals [-1 lC lT lX lE lB] newmode get get addtocws
                            } if
                            /mode newmode def
                            /done true def
                            exit
                        } if
                    } if
                    msglen i sub 3 le {  % Check end of data conditions
                        /remcws numremcws j p 3 idiv 2 mul add get def
                        /remvals [
                            msg i msglen i sub getinterval {
                                dup encvals mode get exch known {
                                    encvals mode get exch get aload pop
                                } {  % Unencodable X12 characters
                                    pop -1 -1 -1 -1
                                } ifelse
                            } forall
                        ] def
                        remcws 2 eq remvals length 3 eq and {
                            % Encode and omit unlatch
                            [
                                ctxvals 0 p getinterval aload pop
                                remvals aload pop
                            ] CTXvalstocws addtocws
                            /mode A def
                            /i msglen def
                            /done true def
                            exit
                        } if
                        remcws 2 eq remvals length 2 eq and mode X ne and {
                            % Encode with sft1 as third value, omit unlatch
                            [
                                ctxvals 0 p getinterval aload pop
                                remvals aload pop
                                encvals mode get sft1 get aload pop
                            ] CTXvalstocws addtocws
                            /mode A def
                            /i msglen def
                            /done true def
                            exit
                        } if
                        remcws 2 eq remvals length 1 eq and {
                            % Unlatch to ASCII
                            ctxvals 0 p getinterval CTXvalstocws addtocws
                            [unlcw] addtocws
                            Avals msg i get get addtocws
                            /mode A def
                            /i msglen def
                            /done true def
                            exit
                        } if
                        remcws 1 eq remvals length 1 eq and {
                            % Implied unlatch to ASCII
                            ctxvals 0 p getinterval CTXvalstocws addtocws
                            Avals msg i get get addtocws
                            /mode A def
                            /i msglen def
                            /done true def
                            exit
                        } if
                    } if
                } if
                encvals mode get msg i get get
                dup ctxvals exch p exch putinterval
                /p exch length p add def
                /i i 1 add def
            } loop

            % Backtrack to a boundary and return to ASCII
            done not {
                {
                    p 3 mod 0 eq {exit} if
                    /i i 1 sub def
                    /p p encvals mode get msg i get get length sub def
                } loop
                [
                    ctxvals 0 p getinterval aload pop
                ] CTXvalstocws addtocws
                [unlcw] addtocws
                /mode A def
                % Encode something to avoid latching immediately back
                i msglen ne isECI i get not and {
                    numD i get 2 ge {
                        2 string dup 0 msg i get put dup 1 msg i 1 add get put Avals exch get addtocws
                        /i i 2 add def
                    } {
                        Avals msg i get get addtocws
                        /i i 1 add def
                    } ifelse
                } if
            } if

        } def

        /Evalstocws {
            /in exch def
            /inlen in length def
            /outlen in length 4 div 3 mul ceiling cvi def
            /in [ in aload pop 0 0 0 ] def
            mark
            0 4 inlen 1 sub {
                in exch 4 getinterval 0 exch {or 6 bitshift} forall -6 bitshift
                dup -16 bitshift 255 and exch
                dup -8 bitshift 255 and exch
                255 and
            } for
            counttomark array astore exch pop
            0 outlen getinterval
        } def

        /encE {
            /p 0 def
            /edifactvals 2100 array def

            % Lookup the values for each character
            {
                i msglen eq {exit} if
                Evals msg i get known not {exit} if
                p 4 mod 0 eq {
                    msglen i sub 2 le {  % Check end of data condition
                        /remcws numremcws j p 4 idiv 3 mul add get def
                        /remvals [
                            msg i msglen i sub getinterval {
                                Avals exch get aload pop
                            } forall
                        ] def
                        remcws 1 eq remcws 2 eq or remvals length remcws le and {
                            % Implied unlatch to ASCII
                            edifactvals 0 p getinterval Evalstocws addtocws
                            remvals addtocws
                            /mode A def
                            /i msglen def
                            exit
                        } if
                    } if
                    lookup mode ne {exit} if
                } if
                Evals msg i get get
                dup edifactvals exch p exch putinterval
                /p exch length p add def
                /i i 1 add def
            } loop

            % Unlatch and pad with zeros until boundary
            mode A ne {
                /remcws numremcws j p 4 idiv 3 mul add 1 sub get 1 sub def
                p 4 mod 0 ne i msglen ne or remcws 3 ge or {  % Unlatch unless less than 3 codewords remain
                    Evals unl get
                    dup edifactvals exch p exch putinterval
                    /p exch length p add def
                } if
                edifactvals 0 p getinterval Evalstocws addtocws
                /mode A def
                % Encode something to avoid latching immediately back
                i msglen ne isECI i get not and {
                    numD i get 2 ge {
                        2 string dup 0 msg i get put dup 1 msg i 1 add get put Avals exch get addtocws
                        /i i 2 add def
                    } {
                        Avals msg i get get addtocws
                        /i i 1 add def
                    } ifelse
                } if
            } if

        } def

        /encB {
            /p 0 def /bvals 1558 array def {
                i msglen eq {exit} if
                lookup mode ne {exit} if
                bvals p msg i get put
                /p p 1 add def
                /i i 1 add def
            } loop
            /remcws numremcws j p add get 1 sub def
            /bvals [
                remcws 0 eq i msglen eq and {  % Terminates symbol
                    0
                } {
                    p 250 lt {p} {p 250 idiv 249 add p 250 mod} ifelse
                } ifelse
                bvals 0 p getinterval aload pop
            ] def
            0 1 bvals length 1 sub {  % Pseudo-randomise based on codeword position
                /p exch def
                j p add 1 add 149 mul 255 mod 1 add bvals p get add
                dup 256 ge {256 sub} if
                bvals exch p exch put
            } for
            bvals addtocws
            /mode A def
        } def

        % Derive the codewords
        /cws 1558 array def
        /mode A def /i 0 def /j 0 def {
            i msglen ge {exit} if
            [ /encA /encCTX /encCTX /encCTX /encE /encB ] mode get load exec
        } loop
        /cws cws 0 j getinterval def

    } if  % encoding=auto

    % Extend codewords to fill symbol with pseudo-randomised pad characters
    /datlen cws length def
    /remcws numremcws j 1 sub get 1 sub def
    remcws 0 gt {
        /cws [ cws aload pop remcws {129} repeat ] def
        datlen 1 add 1 datlen remcws add 1 sub {
            /i exch def
            i 1 add 149 mul 253 mod 1 add 129 add
            dup 254 gt {254 sub} if
            cws exch i exch put
        } for
    } if

    options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if

    % Lookup symbol metrics based on number of codewords and user specification
    /i 0 def { % loop
        /m metrics i get def
        /rows m 0 get def                          % Rows in symbol
        /cols m 1 get def                          % Columns in symbol
        /regh m 2 get def                          % Horizontal regions
        /regv m 3 get def                          % Vertical regions
        /rscw m 4 get def                          % Error correction codewords
        /rsbl m 5 get def                          % Error correction blocks
        /mrows rows 2 regh mul sub def             % Rows in the mapping matrix
        /mcols cols 2 regv mul sub def             % Columns in the mapping matrix
        /rrows mrows regh idiv def                 % Rows per region
        /rcols mcols regv idiv def                 % Columns per region
        /ncws mrows mcols mul 8 idiv rscw sub def  % Data codewords
        /okay true def
        cws length ncws ne           {/okay false def} if
        urows 0 ne urows rows ne and {/okay false def} if
        ucols 0 ne ucols cols ne and {/okay false def} if
        format (square) eq rows cols ne and {/okay false def} if
        format (rectangle) eq rows cols eq and {/okay false def} if
        okay {exit} if
        /i i 1 add def
    } loop

    % De-interleave the codewords into blocks
    /cwbs rsbl array def  % Array of data codeword blocks
    /ecbs rsbl array def  % Array of error correction blocks
    0 1 rsbl 1 sub {
        /i exch def
        cws length 1558 ne {
            /cwbsize cws length rsbl idiv def
        } {
            i 7 le {/cwbsize 156 def} {/cwbsize 155 def} ifelse
        } ifelse
        /cwb cwbsize array def
        0 1 cwbsize 1 sub {
            /j exch def
            cwb j cws j rsbl mul i add get put
        } for
        cwbs i cwb put
        ecbs i [ rscw rsbl idiv {0} repeat ] put
    } for

    % Calculate the log and anti-log tables
{
    /rsalog [ 1 255 { dup 2 mul dup 256 ge {301 xor} if } repeat ] def
    /rslog 256 array def
    1 1 255 {dup rsalog exch get exch rslog 3 1 roll put} for
} ctxdef

    % 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 255 mod rsalog exch get
        } {
            pop pop 0
        } ifelse
    } def

    % Generate the coefficients
    /coeffs [ 1 rscw rsbl idiv {0} repeat ] def
    1 1 rscw rsbl idiv {
        /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 xor put
        } for
        coeffs 0 coeffs 0 get rsalog i get rsprod put
    } for
    /coeffs coeffs 0 coeffs length 1 sub getinterval def

    % Calculate the error correction codewords for each block
    0 1 cwbs length 1 sub {
        /i exch def
        /cwb cwbs i get def
        /ecb ecbs i get def
        0 1 cwb length 1 sub {
            /t exch cwb exch get ecb 0 get xor def
            ecb length 1 sub -1 0 {
                /j exch def
                /p ecb length j sub 1 sub def
                ecb p t coeffs j get rsprod put
                j 0 gt { ecb p ecb p 1 add get ecb p get xor put } if
            } for
        } for
    } for

    % Strange fixup for 144x144 symbols
    ncws 1558 eq {
        /ecbs [ ecbs 8 2 getinterval {} forall ecbs 0 8 getinterval {} forall ] def
    } if

    % Extend codewords with the interleaved error correction codes
    /cws [ cws {} forall rscw {0} repeat ] def
    0 1 rscw 1 sub {
        /i exch def
        cws ncws i add ecbs i rsbl mod get i rsbl idiv get put
    } for

    % Place the codewords into the matrix
    /module {
        % cw row col shape
        4 -1 roll
        (00000000) 8 string copy dup 3 -1 roll 2 8 string cvrs
        dup length 8 exch sub exch putinterval
        7 -1 0 {1 index exch get 48 sub exch} for pop
        11 -3 roll
        % 1 2 4 8 16 32 64 128 row col shape
        {  % Place each bit of the codeword in the shape, MSB first
            exec
            1 index 0 lt {
                exch mrows add exch
                4 mrows 4 add 8 mod sub add
            } if
            dup 0 lt {
                mcols add exch
                4 mcols 4 add 8 mod sub add exch
            } if
            1 index mrows ge {
                exch mrows sub exch
            } if
            exch mcols mul add
            mmat exch 5 -1 roll put
        } forall
    } def

    % Placement patterns
    /dmn [
        { 2 copy 2 sub exch 2 sub exch } bind  { 2 copy 1 sub exch 2 sub exch } bind
        { 2 copy 2 sub exch 1 sub exch } bind  { 2 copy 1 sub exch 1 sub exch } bind
        { 2 copy exch 1 sub exch } bind        { 2 copy 2 sub } bind
        { 2 copy 1 sub } bind                  { 2 copy } bind
    ] def

    /dmc1 [
        { mrows 1 sub 0 } bind  { mrows 1 sub 1 } bind
        { mrows 1 sub 2 } bind  { 0 mcols 2 sub } bind
        { 0 mcols 1 sub } bind  { 1 mcols 1 sub } bind
        { 2 mcols 1 sub } bind  { 3 mcols 1 sub } bind
    ] def

    /dmc2 [
        { mrows 3 sub 0 } bind  { mrows 2 sub 0 } bind
        { mrows 1 sub 0 } bind  { 0 mcols 4 sub } bind
        { 0 mcols 3 sub } bind  { 0 mcols 2 sub } bind
        { 0 mcols 1 sub } bind  { 1 mcols 1 sub } bind
    ] def

    /dmc3 [
        { mrows 3 sub 0 } bind  { mrows 2 sub 0 } bind
        { mrows 1 sub 0 } bind  { 0 mcols 2 sub } bind
        { 0 mcols 1 sub } bind  { 1 mcols 1 sub } bind
        { 2 mcols 1 sub } bind  { 3 mcols 1 sub } bind
    ] def

    /dmc4 [
        { mrows 1 sub 0 } bind  { mrows 1 sub mcols 1 sub } bind
        { 0 mcols 3 sub } bind  { 0 mcols 2 sub } bind
        { 0 mcols 1 sub } bind  { 1 mcols 3 sub } bind
        { 1 mcols 2 sub } bind  { 1 mcols 1 sub } bind
    ] def

    /mmat [ mrows mcols mul {-1} repeat ] def
    cws length 1 sub -1 0 {cws exch get} for  % Reverse cws onto stack
    4 0  % Starting row and column
    { % loop
        2 copy 0 eq exch mrows eq and {
            dmc1 module
        } if
        2 copy 0 eq exch mrows 2 sub eq and mcols 4 mod 0 ne and {
            dmc2 module
        } if
        2 copy 0 eq exch mrows 2 sub eq and mcols 8 mod 4 eq and {
            dmc3 module
        } if
        2 copy 2 eq exch mrows 4 add eq and mcols 8 mod 0 eq and {
            dmc4 module
        } if

        { % loop for sweeping upwards
            2 copy 0 ge exch mrows lt and {
                2 copy exch mcols mul add mmat exch get -1 eq {
                    dmn module
                } if
            } if
            2 add exch 2 sub exch
            2 copy mcols lt exch 0 ge and not {exit} if
        } loop
        3 add exch 1 add exch

        { % loop for sweeping downwards
            2 copy mcols lt exch 0 ge and {
                2 copy exch mcols mul add mmat exch get -1 eq {
                    dmn module
                } if
            } if
            2 sub exch 2 add exch
            2 copy 0 ge exch mrows lt and not {exit} if
        } loop
        1 add exch 3 add exch

        2 copy mcols lt exch mrows lt or not {pop pop exit} if

    } loop

    % Set checker pattern if required
    mmat mrows mcols mul 1 sub get -1 eq {
        mmat mrows mcols 1 sub mul 2 sub [1 0] putinterval
        mmat mrows mcols mul 2 sub [0 1] putinterval
    } if

    % Place the modules onto a pixel map between alignment patterns
    /pixs rows cols mul array def
    /cwpos 0 def
    0 1 rows 1 sub {
        /i exch def
        i rrows 2 add mod 0 eq { pixs i cols mul [ cols 2 idiv {1 0} repeat ] putinterval } if
        i rrows 2 add mod rrows 1 add eq { pixs i cols mul [ cols {1} repeat ] putinterval } if
        i rrows 2 add mod 0 ne i rrows 2 add mod rrows 1 add ne and {
            0 1 cols 1 sub {
                /j exch def
                j rcols 2 add mod 0 eq { pixs i cols mul j add 1 put } if
                j rcols 2 add mod rcols 1 add eq { pixs i cols mul j add i 2 mod put } if
                j rcols 2 add mod 0 ne j rcols 2 add mod rcols 1 add ne and {
                    pixs i cols mul j add mmat cwpos get put
                    /cwpos cwpos 1 add def
                } if
            } for
        } if
    } for

    % Return the arguments
    <<
    /ren //renmatrix
    /pixs pixs
    /pixx cols
    /pixy rows
    /height rows 2 mul 72 div
    /width cols 2 mul 72 div
    /opt options
    >>

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/datamatrix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER datamatrix--

% --BEGIN ENCODER datamatrixrectangular--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix datamatrix--
% --DESC: Data Matrix Rectangular
% --EXAM: 1234
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp datamatrixrectangular 0.0 2022082100 62617 62460
%%BeginData:         46 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /datamatrix dup /uk.co.terryburton.bwipp findresource put
begin
/datamatrixrectangular {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw 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

    % Get the result of encoding with datamatrix with format=rectangle
    options (dontdraw) true put
    options (format) (rectangle) put

    /args barcode options //datamatrix exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/datamatrixrectangular dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER datamatrixrectangular--

% --BEGIN ENCODER datamatrixrectangularextension--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix datamatrix--
% --DESC: Data Matrix Rectangular Extension
% --EXAM: 1234
% --EXOP: version=8x96
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp datamatrixrectangularextension 0.0 2022082100 63804 63742
%%BeginData:         56 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
20 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /datamatrix dup /uk.co.terryburton.bwipp findresource put
begin
/datamatrixrectangularextension {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def

    /dmre false def
    /dindmre 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

    % Get the result of encoding with datamatrix
    options (dontdraw) true put
    options (format) (rectangle) put

    dindmre dmre or not {  % Default is (ISO) DMRE
        options (dmre) true put
    } {  % Otherwise enable formats as given
        options (dmre) dmre put        % ISO
        options (dindmre) dindmre put  % DIN
    } ifelse

    /args barcode options //datamatrix exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/datamatrixrectangularextension dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER datamatrixrectangularextension--

% --BEGIN ENCODER mailmark--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix datamatrix--
% --DESC: Royal Mail Mailmark
% --EXAM: JGB 012100123412345678AB19XY1A 0             www.xyz.com
% --EXOP: type=29
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp mailmark 0.0 2022082100 66101 65894
%%BeginData:         81 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /datamatrix dup /uk.co.terryburton.bwipp findresource put
begin
/mailmark {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /type (unset) def  % 7, 9 or 29
    /parse false def
    /dontdraw 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

    % Parse ordinals of the form ^NNN to ASCII
    /fncvals <<
        /parse parse
        /parseonly true
        /parsefnc false
    >> def
    /barcode barcode fncvals //parseinput exec def
    /barlen barcode length def
    options (parse) undef

    % Map the given type to a format and version of Data Matrix
    <<
        (7)  (24x24)
        (9)  (32x32)
        (29) (16x48)
    >> /type load get /version exch def

    <<
        (7)  (square)
        (9)  (square)
        (29) (rectangle)
    >> /type load get /format exch def

    % Validate the input
    barcode length 45 lt {
        /bwipp.mailmarkBadLength (Royal Mail Mailmark must contain at least 45 characters of Mailmark formatted data, including any required space padding) //raiseerror exec
    } if
    barcode 0 4 getinterval (JGB ) ne {
        /bwipp.mailmarkBadIndicator (Royal Mail Mailmark must begin with JGB<space> identifier) //raiseerror exec
    } if

    % Get the result of encoding with datamatrix
    options (dontdraw) true put
    options (version) version put
    options (format) format put
    options (mailmark) true put
    /args barcode options //datamatrix exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/mailmark dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER mailmark--

% --BEGIN ENCODER qrcode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: QR Code
% --EXAM: http://goo.gl/0bis
% --EXOP: eclevel=M
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp qrcode 0.0 2022082100 320507 354887
%%BeginData:       1369 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/qrcode {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /format (unset) def    % full or micro. rMQR symbols are specified using version
    /version (unset) def   % 1-40 or M1-M4 or R7x43, etc
    /eclevel (unset) def   % full: L, M, Q, H; micro: L, M, Q; rmqr: M, H
    /parse false def
    /parsefnc false def
    /mask -1 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

    /mask mask cvi def

    /qrcode //loadctx exec

    % If version is supplied and format is not given then set format to correspond
    version (unset) ne {
        format (unset) eq {
            (full)
            version 0 1 getinterval (M) eq { pop (micro) } if
            version 0 1 getinterval (R) eq { pop (rmqr) } if
            /format exch def
        } if
    } {
        format (unset) eq { /format (full) def } if  % Default to full
    } ifelse

    % Default error correction level
    eclevel (unset) eq {/eclevel format (micro) ne {(M)} {(L)} ifelse def} if

    % Parse the input
    /fn1 -1 def
    /fncvals <<
        /parse parse
        /parsefnc parsefnc
        /eci true
        (FNC1) fn1
    >> def
    /msg barcode fncvals //parseinput exec def
    /msglen msg length def

    % If FNC1 in first position then escape % as %%
    /fnc1first false def
    msglen 0 gt {
        msg 0 get fn1 eq {
            /fnc1first true def
            /msg [ msg 1 msglen 1 sub getinterval { dup 37 eq {dup} if } forall ] def
            /msglen msg length def
        } if
    } if

{  % context

    % Enumerate vergrps
    [
        /v1to9    /v10to26  /v27to40
        /vM1      /vM2      /vM3      /vM4
        /vR7x43   /vR7x59   /vR7x77   /vR7x99   /vR7x139
        /vR9x43   /vR9x59   /vR9x77   /vR9x99   /vR9x139
        /vR11x27  /vR11x43  /vR11x59  /vR11x77  /vR11x99   /vR11x139
        /vR13x27  /vR13x43  /vR13x59  /vR13x77  /vR13x99   /vR13x139
        /vR15x43  /vR15x59  /vR15x77  /vR15x99  /vR15x139
        /vR17x43  /vR17x59  /vR17x77  /vR17x99  /vR17x139
    ] 0 exch {1 index def 1 add} forall pop

    % Convert from input into message bitstream
    %
    % Modes: (N)umeric, (A)lphanumeric, (B)yte, (K)anji, (E)CI
    %
    /N 0 def  /A 1 def  /B 2 def  /K 3 def  /E 4 def

    /Nexcl <<
       [
           16#30 1 16#39 {} for
       ] {-1} forall
    >> def

    /Aexcl <<
        [
            16#20 16#24 16#25 16#2A 16#2B 16#2D 16#2E 16#2F 16#3A
            16#41 1 16#5A {} for
            fn1
        ] {-1} forall
    >> def

    % Binary exclusives calculated from "not others"

    /Kexcl <<
        [
            16#81 1 16#9F {} for
            16#E0 1 16#EB {} for
        ] {-1} forall
    >> def

    /mids [
        %    N      A      B      K      E
        [ (0001) (0010) (0100) (1000) (0111) ]  % v1to9
        [ (0001) (0010) (0100) (1000) (0111) ]  % v10to26
        [ (0001) (0010) (0100) (1000) (0111) ]  % v27to40
        [     ()   -1     -1     -1     -1   ]  % vM1
        [    (0)    (1)   -1     -1     -1   ]  % vM2
        [   (00)   (01)   (10)   (11)   -1   ]  % vM3
        [  (000)  (001)  (010)  (011)   -1   ]  % vM4
      32 {
        [  (001)  (010)  (011)  (100)  (111) ]  % rMQR
      } repeat
    ] def

    /cclens [  % N  A  B  K
        [ 10  9  8  8 ]  % v1to9
        [ 12 11 16 10 ]  % v10to26
        [ 14 13 16 12 ]  % v27to40
        [  3 -1 -1 -1 ]  % vM1
        [  4  3 -1 -1 ]  % vM2
        [  5  4  4  3 ]  % vM3
        [  6  5  5  4 ]  % vM4
        [  4  3  3  2 ]  % vR7x43
        [  5  5  4  3 ]  % vR7x59
        [  6  5  5  4 ]  % vR7x77
        [  7  6  5  5 ]  % vR7x99
        [  7  6  6  5 ]  % vR7x139
        [  5  5  4  3 ]  % vR9x43
        [  6  5  5  4 ]  % vR9x59
        [  7  6  5  5 ]  % vR9x77
        [  7  6  6  5 ]  % vR9x99
        [  8  7  6  6 ]  % vR9x139
        [  4  4  3  2 ]  % vR11x27
        [  6  5  5  4 ]  % vR11x43
        [  7  6  5  5 ]  % vR11x59
        [  7  6  6  5 ]  % vR11x77
        [  8  7  6  6 ]  % vR11x99
        [  8  7  7  6 ]  % vR11x139
        [  5  5  4  3 ]  % vR13x27
        [  6  6  5  5 ]  % vR13x43
        [  7  6  6  5 ]  % vR13x59
        [  7  7  6  6 ]  % vR13x77
        [  8  7  7  6 ]  % vR13x99
        [  8  8  7  7 ]  % vR13x139
        [  7  6  6  5 ]  % vR15x43
        [  7  7  6  5 ]  % vR15x59
        [  8  7  7  6 ]  % vR15x77
        [  8  7  7  6 ]  % vR15x99
        [  9  8  7  7 ]  % vR15x139
        [  7  6  6  5 ]  % vR17x43
        [  8  7  6  6 ]  % vR17x59
        [  8  7  7  6 ]  % vR17x77
        [  8  8  7  6 ]  % vR17x99
        [  9  8  8  7 ]  % vR17x139
    ] def

    /termlens [
      3 {
        4  % Full
      } repeat
        3  % vM1
        5  % vM2
        7  % vM3
        9  % vM4
      32 {
        3  % rMQR
      } repeat
    ] def

    /padstrs [ (11101100) (00010001) ] def

    % Alphanumeric character to value map
    /charmap (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:) def
    /charvals 44 dict def
    0 1 44 {dup charmap exch get exch charvals 3 1 roll put} for

} ctxdef

    % Encoding functions
    /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

    /encA {
        /in exch def
        fnc1first {  % FNC1 as %
            /in [ in { dup fn1 eq {pop 37} if } forall ] def
        } if
        /out in length 11 mul 2 idiv 1 add string def
        /k 0 def /m 0 def {
            k in length eq {exit} if
            k in length 1 sub lt {
                charvals in k get get 45 mul charvals in k 1 add get get add 11 tobin
                /k k 2 add def
            } {  % Final character
                charvals in k get get 6 tobin
                /k k 1 add def
            } ifelse
            dup out exch m exch putinterval
            length m add /m exch def
        } loop
        out 0 m getinterval
    } def

    /encN {
        /in exch def
        /out in length 10 mul 3 idiv 1 add string def
        /k 0 def /m 0 def {
            k in length eq {exit} if
            k in length 2 sub lt {
                in k 3 getinterval 0 exch {exch 10 mul 48 sub add} forall 10 tobin
                /k k 3 add def
            } {
                k in length 2 sub eq {  % Two final digits
                    in k 2 getinterval 0 exch {exch 10 mul 48 sub add} forall 7 tobin
                    /k k 2 add def
                } {  % One final digit
                    in k 1 getinterval 0 exch {exch 10 mul 48 sub add} forall 4 tobin
                    /k k 1 add def
                } ifelse
            } ifelse
            dup out exch m exch putinterval
            length m add /m exch def
        } loop
        out 0 m getinterval
    } def

    /encB {
        /in exch def
        fnc1first {  % FNC1 as GS
            /in [ in { dup fn1 eq {pop 29} if } forall ] def
        } if
        /out in length 8 mul string def
        0 1 in length 1 sub {
            /k exch def
            in k get cvi 8 tobin
            out k 8 mul 3 -1 roll putinterval
        } for
        out
    } def

    /encK {
        /in exch def
        /out in length 2 idiv 13 mul string def
        /k 0 def /m 0 def {
            k in length eq {exit} if
            in k get 256 mul in k 1 add get add
            dup 16#E040 lt {16#8140} {16#C140} ifelse sub
            dup -8 bitshift 16#C0 mul exch 16#00FF and add
            13 tobin dup out exch m exch putinterval
            length m add /m exch def
            /k k 2 add def
        } loop
        out
    } def

    /encE {
        0 get neg 1000000 sub
            dup 000127 le {  % ECI 000000 - 000127
            8 tobin
        } { dup 016383 le {  % ECI 000128 - 016383
                2#1000000000000000 add 16 tobin
        } {                  % ECI 016384 - 999999
                2#110000000000000000000000 add 24 tobin
        } ifelse } ifelse
    } def

    /encfuncs [ /encN /encA /encB /encK /encE ] def

    /addtobits {
        dup bits j 3 -1 roll putinterval
        length j add /j exch def
    } def

    /numNs [ msglen {0} repeat 0 ] def
    /numAs [ msglen {0} repeat 0 ] def
    /numAorNs [ msglen {0} repeat 0 ] def
    /numBs [ msglen {0} repeat 0 ] def
    /numKs [ msglen {0} repeat 0 ] def
    /nextNs [ msglen {0} repeat 9999 ] def
    /nextBs [ msglen {0} repeat 9999 ] def
    /nextAs [ msglen {0} repeat 9999 ] def
    /nextKs [ msglen {0} repeat 9999 ] def
    /isECI msglen array def
    msglen 1 sub -1 0 {
        /i exch def
        /barchar msg i get def
        Kexcl barchar known {
            /sjis i 1 add msglen lt { barchar 256 mul msg i 1 add get add } {0} ifelse def  % Zero if last char
            sjis 16#8140 ge sjis 16#9FFC le and sjis 16#E040 ge sjis 16#EBBF le and or {
                nextKs i 0 put
                numKs i numKs i 2 add get 1 add put
            } {
                nextKs i nextKs i 1 add get 1 add put
            } ifelse
        } {
            nextKs i nextKs i 1 add get 1 add put
        } ifelse
        Nexcl barchar known {
            nextNs i 0 put
            numNs i numNs i 1 add get 1 add put
            numAorNs i numAorNs i 1 add get 1 add put
        } {
            nextNs i nextNs i 1 add get 1 add put
        } ifelse
        Aexcl barchar known {
            nextAs i 0 put
            numAs i numAs i 1 add get 1 add put
            numAorNs i numAorNs i 1 add get 1 add put
        } {
            nextAs i nextAs i 1 add get 1 add put
        } ifelse
        isECI i barchar -1000000 le put
    } for
    0 1 msglen 1 sub {  % Scan forward to set any "2nd byte 1st byte" Kanji matches to zero
        /i exch def
        numKs i get 0 gt {
            numKs i 1 add 0 put
            nextKs i 1 add nextKs i 1 add get 1 add put
        } if
    } for
    msglen 1 sub -1 0 {  % Finally scan backwards again to set numBs/nextBs from "not others"
        /i exch def
        numNs i get numAs i get numKs i get add add 0 eq isECI i get not and {
            nextBs i 0 put
            numBs i numBs i 1 add get 1 add put
        } {
            nextBs i nextBs i 1 add get 1 add put
        } ifelse
    } for

    /KbeforeB {numK exch ver get ge nextBs numK 2 mul i add get 0 eq and} def
    /KbeforeA {numK exch ver get ge nextAs numK 2 mul i add get 0 eq and} def
    /KbeforeN {numK exch ver get ge nextNs numK 2 mul i add get 0 eq and} def
    /KbeforeE {numK exch ver get ge numK 2 mul i add msglen eq and} def
    /AbeforeK {numA exch ver get ge nextKs numA i add get 0 eq and} def
    /AbeforeB {numA exch ver get ge nextBs numA i add get 0 eq and} def
    /AbeforeN {numA exch ver get ge nextNs numA i add get 0 eq and} def
    /AbeforeE {numA exch ver get ge numA i add msglen eq and} def
    /NbeforeK {numN exch ver get ge nextKs numN i add get 0 eq and} def
    /NbeforeB {numN exch ver get ge nextBs numN i add get 0 eq and} def
    /NbeforeA {numN exch ver get ge nextAs numN i add get 0 eq and} def
    /NbeforeE {numN exch ver get ge numN i add msglen eq and} def
    /AorNbeforeB {numAorN exch ver get ge nextBs numAorN i add get 0 eq and} def
    /AorNbeforeE {numAorN exch ver get ge numAorN i add msglen eq and} def

    /nextNslt { nextNs i get msglen ge { pop true } { numNs nextNs i get i add get exch ver get lt } ifelse } def

    % Elements of the encoded message have differing lengths based on the
    % resulting symbol size. The symbol sizes with different element lengths
    % are batched into vergrps. To pick the smallest symbol that holds our
    % content we encode the message according to each available vergrp, based
    % on the format of symbol.

    % Determine which groups we need to encode
{
    /versetmap <<
        % Full
         0 1  9 { 10 2 string cvrs v1to9   } for
        10 1 26 { 10 2 string cvrs v10to26 } for
        27 1 40 { 10 2 string cvrs v27to40 } for

        % Micro
        (M1) vM1  (M2) vM2  (M3) vM3  (M4) vM4

        % rMQR
                          (R7x43)  vR7x43   (R7x59)  vR7x59   (R7x77)  vR7x77   (R7x99)  vR7x99   (R7x139)  vR7x139
                          (R9x43)  vR9x43   (R9x59)  vR9x59   (R9x77)  vR9x77   (R9x99)  vR9x99   (R9x139)  vR9x139
        (R11x27) vR11x27  (R11x43) vR11x43  (R11x59) vR11x59  (R11x77) vR11x77  (R11x99) vR11x99  (R11x139) vR11x139
        (R13x27) vR13x27  (R13x43) vR13x43  (R13x59) vR13x59  (R13x77) vR13x77  (R13x99) vR13x99  (R13x139) vR13x139
                          (R15x43) vR15x43  (R15x59) vR15x59  (R15x77) vR15x77  (R15x99) vR15x99  (R15x139) vR15x139
                          (R17x43) vR17x43  (R17x59) vR17x59  (R17x77) vR17x77  (R17x99) vR17x99  (R17x139) vR17x139
    >> def
    /versetfull  [v1to9 v10to26 v27to40] def
    /versetmicro [vM1 vM2 vM3 vM4] def
} ctxdef
    version (unset) ne {
        % A specific version of symbol is given so encode in just the corresponding vergrp
        /verset versetmap version get [ exch ] def
    } {
        % Just the format is specified so encode in each vergrp for the type of symbol
        format (full)  eq { /verset versetfull  def } if
        format (micro) eq { /verset versetmicro def } if
        % rMQR symbols are accessed with an explicit version
    } ifelse

    % Encode unterminated bitstream for each compatible vergrp separately
    /msgbits [ 39 {-1} repeat ] def
    /e 10000 def

    % Number of before characters per vergrp, depending on current mode, for optimising modes
    % Generated by contrib/development/build-qr-mode-optim-arrs.php
    %                Full     Micro    R7         R9           R11             R13              R15             R17
{
    /mode0forceKB  [ 1  1  1  e e 1 1  1 1 1 1 1  1 1 1 1  1   1 1 1 1  1  1   1 1 1  1  1  1   1  1  1  1  1   1  1  1  1  1] def
    /mode0forceA   [ 1  1  1  e 1 1 1  1 1 1 1 1  1 1 1 1  1   1 1 1 1  1  1   1 1 1  1  1  1   1  1  1  1  1   1  1  1  1  1] def
    /mode0forceN   [ 1  1  1  1 1 1 1  1 1 1 1 1  1 1 1 1  1   1 1 1 1  1  1   1 1 1  1  1  1   1  1  1  1  1   1  1  1  1  1] def

    /mode0NbeforeB [ 4  4  5  e e 2 3  2 2 3 3 3  2 3 3 3  3   2 3 3 3  3  3   2 3 3  3  3  3   3  3  3  3  3   3  3  3  3  3] def

    /modeBKbeforeB [ 9 12 13  e e 4 6  4 5 6 6 6  5 6 6 6  7   4 6 6 6  7  7   5 6 6  7  7  7   6  6  7  7  7   6  7  7  7  8] def
    /modeBKbeforeA [ 8 10 11  e e 4 5  4 5 5 6 6  5 5 6 6  6   4 5 6 6  6  6   5 6 6  6  6  7   6  6  6  6  7   6  6  6  7  7] def
    /modeBKbeforeN [ 8  9 11  e e 3 5  3 4 5 5 5  4 5 5 5  6   3 5 5 5  6  6   4 5 5  6  6  6   5  5  6  6  7   5  6  6  6  7] def
    /modeBKbeforeE [ 5  5  6  e e 2 3  2 3 3 3 3  3 3 3 3  4   2 3 3 3  4  4   3 3 3  4  4  4   3  3  4  4  4   3  4  4  4  4] def

    /modeBAbeforeK [11 12 14  e e 5 7  5 6 7 8 8  6 7 8 8  8   6 7 8 8  8  8   6 8 8  8  8  9   8  8  8  8  9   8  8  8  9  9] def
    /modeBAbeforeB [11 15 16  e e 6 7  6 7 7 8 8  7 7 8 8  8   6 7 8 8  8  9   7 8 8  8  9  9   8  8  9  9  9   8  8  9  9 10] def
    /modeBAbeforeN [12 13 15  e e 6 8  6 7 8 8 8  7 8 8 8  9   6 8 8 8  9  9   7 8 8  9  9 10   8  9  9  9 10   8  9  9 10 10] def
    /modeBAbeforeE [ 6  7  8  e e 3 4  3 4 4 4 4  4 4 4 4  5   4 4 4 4  5  5   4 4 4  5  5  5   4  5  5  5  5   4  5  5  5  5] def

    /modeBNbeforeK [ 6  7  8  e e 3 4  3 4 4 5 5  4 4 5 5  5   3 4 5 5  5  5   4 4 5  5  5  5   5  5  5  5  5   5  5  5  5  5] def
    /modeBNbeforeB [ 6  8  9  e e 3 4  3 4 4 5 5  4 4 5 5  5   3 4 5 5  5  5   4 4 5  5  5  5   5  5  5  5  5   5  5  5  5  6] def
    /modeBNbeforeA [ 6  7  8  e e 3 4  3 4 4 5 5  4 4 5 5  5   4 4 5 5  5  5   4 5 5  5  5  5   5  5  5  5  6   5  5  5  5  6] def
    /modeBNbeforeE [ 3  4  4  e e 2 3  2 2 3 3 3  2 3 3 3  3   2 3 3 3  3  3   2 3 3  3  3  3   3  3  3  3  3   3  3  3  3  3] def

    /modeANbeforeA [13 15 17  e 5 7 9  7 8 9 9 9  8 9 9 9 11   7 9 9 9 11 11   8 9 9 10 11 11   9 10 11 11 11   9 11 11 11 11] def
    /modeANbeforeB [13 17 18  e e 7 9  7 8 9 9 9  8 9 9 9 10   7 9 9 9 10 11   8 9 9  9 11 11   9  9 11 11 11   9 10 11 11 11] def
    /modeANbeforeE [ 7  8  9  e 3 4 5  4 5 5 5 5  5 5 5 5  6   4 5 5 5  6  6   5 5 5  5  6  6   5  5  6  6  6   5  6  6  6  6] def
} ctxdef

    verset {
        /ver exch def

        % Derive optimal sequence
        /mode -1 def /seq [] def /i 0 def {
            i msglen ge {exit} if
            /numK numKs i get def
            /numB numBs i get def
            /numA numAs i get def
            /numN numNs i get def
            /numAorN numAorNs i get def
            /eci isECI i get def
            ver vM1 eq numA 1 ge and {/seq -1 def exit} if
            ver vM1 eq numB 1 ge and {/seq -1 def exit} if
            ver vM1 eq numK 1 ge and {/seq -1 def exit} if
            ver vM1 eq eci and       {/seq -1 def exit} if
            ver vM2 eq numB 1 ge and {/seq -1 def exit} if
            ver vM2 eq numK 1 ge and {/seq -1 def exit} if
            ver vM2 eq eci and       {/seq -1 def exit} if
            ver vM3 eq eci and       {/seq -1 def exit} if
            ver vM4 eq eci and       {/seq -1 def exit} if
            {  % common exit
                eci {
                    E exit
                } if
                mode -1 eq {  % Set initial mode (or mode after ECI)
                    mode0forceKB  KbeforeA {K exit} if
                    mode0forceKB  KbeforeN {K exit} if
                    modeBKbeforeE KbeforeB {K exit} if  % Re-using modeB KbeforeE array
                    mode0forceKB  KbeforeE {K exit} if
                    numK 1 ge {B exit} if
                    mode0NbeforeB NbeforeB {N exit} if
                    mode0forceKB  NbeforeB {B exit} if
                    modeANbeforeE NbeforeA {N exit} if  % Re-using modeA NbeforeE array
                    mode0forceN   NbeforeE {N exit} if
                    modeBAbeforeE AbeforeK {A exit} if  % Re-using modeB AbeforeE array
                    modeBAbeforeE AorNbeforeB {A exit} if  % Re-using modeB AbeforeE array
                    mode0forceA   AorNbeforeE {A exit} if
                    B exit
                } if
                mode B eq {
                    modeBKbeforeB KbeforeB {K exit} if
                    modeBKbeforeA KbeforeA {K exit} if
                    modeBKbeforeN KbeforeN {K exit} if
                    modeBKbeforeE KbeforeE {K exit} if
                    modeBAbeforeK AbeforeK {A exit} if
                    modeBAbeforeB AbeforeB {A exit} if
                    modeBAbeforeN AbeforeN {A exit} if
                    modeBAbeforeE AbeforeE {A exit} if
                    modeBNbeforeK NbeforeK {N exit} if
                    modeBNbeforeB NbeforeB {N exit} if
                    modeBNbeforeA NbeforeA {N exit} if
                    modeBNbeforeE NbeforeE {N exit} if
                    modeBAbeforeE AorNbeforeE numAorN modeBAbeforeN ver get le and {  % If A/N sequence at end and short
                        modeBNbeforeA nextNslt {A exit} if  % And next N sequence shorter than NbeforeA
                    } if
                    B exit
                } if
                mode A eq {
                    numK 1 ge {K exit} if
                    numB 1 ge {B exit} if
                    modeANbeforeA NbeforeA {N exit} if
                    modeANbeforeB NbeforeB {N exit} if
                    modeANbeforeE NbeforeE {N exit} if
                    numA 1 ge numN 1 ge or {A exit} if
                    B exit
                } if
                mode N eq {
                    numK 1 ge {K exit} if
                    numB 1 ge {B exit} if
                    numA 1 ge {A exit} if
                    numN 1 ge {N exit} if
                    B exit
                } if
                mode K eq {
                    numB 1 ge {B exit} if
                    numA 1 ge {A exit} if
                    numN 1 ge {N exit} if
                    numK 1 ge {K exit} if
                    B exit
                } if
            } loop
            dup K eq fnc1first and {pop B} if  % No kanji with fnc1first
            dup mode eq {  % Same mode encode directly
                pop
                /dat msg i mode K eq {2} {1} ifelse getinterval def
                /seq [
                    seq aload pop
                    [ exch aload pop dat aload pop ]
                ] def
            } {  % Change mode
                /mode exch def
                mode K eq {K msg i numK 2 mul getinterval} if
                mode B eq {B msg i numB getinterval} if
                mode A eq {A msg i numA getinterval} if
                mode N eq {N msg i numN getinterval} if
                mode E eq {E msg i 1 getinterval  /mode -1 def} if
                /dat exch def /sw exch def
                /seq [ seq aload pop sw dat ] def
            } ifelse
            /i i dat length add def
        } loop

        % Encode the sequence
        {  % common exit
            seq -1 eq {exit} if  % Sequence not available
            /bits 23648 string def
            /j 0 def
            fnc1first {
                ver vR7x43 lt { (0101) } { (101) } ifelse addtobits
            } if
            /abort false def
            0 2 seq length 1 sub {
                /i exch def
                /mode seq i get def
                mids ver get mode get addtobits
                /chars seq i 1 add get def
                /charslen chars length mode K eq {2 idiv} if def
                mode E ne {
                    /cclen cclens ver get mode get def
                    charslen 2 cclen exp cvi ge {  % Too many characters for cc indicator
                        /abort true def exit
                    } if
                    charslen cclen tobin addtobits
                } if
                chars encfuncs mode get load exec addtobits
            } for
            abort {exit} if
            /bits bits 0 j getinterval def
            msgbits ver bits put
            exit
        } loop
    } forall

    % Lookup the most appropriate symbol specification
{
    /metrics [
        % format   vers       vergrp  rows cols align modules    error codewords        error correction blocks
        %                                                        L    M    Q    H       L1 L2 M1 M2 Q1 Q2 H1 H2
        [ (micro)  (M1)       vM1       11  11  98 99     36  [   2   99   99   99 ]  [  1  0 -1 -1 -1 -1 -1 -1 ] ]
        [ (micro)  (M2)       vM2       13  13  98 99     80  [   5    6   99   99 ]  [  1  0  1  0 -1 -1 -1 -1 ] ]
        [ (micro)  (M3)       vM3       15  15  98 99    132  [   6    8   99   99 ]  [  1  0  1  0 -1 -1 -1 -1 ] ]
        [ (micro)  (M4)       vM4       17  17  98 99    192  [   8   10   14   99 ]  [  1  0  1  0  1  0 -1 -1 ] ]
        [ (full)   (1)        v1to9     21  21  98 99    208  [   7   10   13   17 ]  [  1  0  1  0  1  0  1  0 ] ]
        [ (full)   (2)        v1to9     25  25  18 99    359  [  10   16   22   28 ]  [  1  0  1  0  1  0  1  0 ] ]
        [ (full)   (3)        v1to9     29  29  22 99    567  [  15   26   36   44 ]  [  1  0  1  0  2  0  2  0 ] ]
        [ (full)   (4)        v1to9     33  33  26 99    807  [  20   36   52   64 ]  [  1  0  2  0  2  0  4  0 ] ]
        [ (full)   (5)        v1to9     37  37  30 99   1079  [  26   48   72   88 ]  [  1  0  2  0  2  2  2  2 ] ]
        [ (full)   (6)        v1to9     41  41  34 99   1383  [  36   64   96  112 ]  [  2  0  4  0  4  0  4  0 ] ]
        [ (full)   (7)        v1to9     45  45  22 38   1568  [  40   72  108  130 ]  [  2  0  4  0  2  4  4  1 ] ]
        [ (full)   (8)        v1to9     49  49  24 42   1936  [  48   88  132  156 ]  [  2  0  2  2  4  2  4  2 ] ]
        [ (full)   (9)        v1to9     53  53  26 46   2336  [  60  110  160  192 ]  [  2  0  3  2  4  4  4  4 ] ]
        [ (full)   (10)       v10to26   57  57  28 50   2768  [  72  130  192  224 ]  [  2  2  4  1  6  2  6  2 ] ]
        [ (full)   (11)       v10to26   61  61  30 54   3232  [  80  150  224  264 ]  [  4  0  1  4  4  4  3  8 ] ]
        [ (full)   (12)       v10to26   65  65  32 58   3728  [  96  176  260  308 ]  [  2  2  6  2  4  6  7  4 ] ]
        [ (full)   (13)       v10to26   69  69  34 62   4256  [ 104  198  288  352 ]  [  4  0  8  1  8  4 12  4 ] ]
        [ (full)   (14)       v10to26   73  73  26 46   4651  [ 120  216  320  384 ]  [  3  1  4  5 11  5 11  5 ] ]
        [ (full)   (15)       v10to26   77  77  26 48   5243  [ 132  240  360  432 ]  [  5  1  5  5  5  7 11  7 ] ]
        [ (full)   (16)       v10to26   81  81  26 50   5867  [ 144  280  408  480 ]  [  5  1  7  3 15  2  3 13 ] ]
        [ (full)   (17)       v10to26   85  85  30 54   6523  [ 168  308  448  532 ]  [  1  5 10  1  1 15  2 17 ] ]
        [ (full)   (18)       v10to26   89  89  30 56   7211  [ 180  338  504  588 ]  [  5  1  9  4 17  1  2 19 ] ]
        [ (full)   (19)       v10to26   93  93  30 58   7931  [ 196  364  546  650 ]  [  3  4  3 11 17  4  9 16 ] ]
        [ (full)   (20)       v10to26   97  97  34 62   8683  [ 224  416  600  700 ]  [  3  5  3 13 15  5 15 10 ] ]
        [ (full)   (21)       v10to26  101 101  28 50   9252  [ 224  442  644  750 ]  [  4  4 17  0 17  6 19  6 ] ]
        [ (full)   (22)       v10to26  105 105  26 50  10068  [ 252  476  690  816 ]  [  2  7 17  0  7 16 34  0 ] ]
        [ (full)   (23)       v10to26  109 109  30 54  10916  [ 270  504  750  900 ]  [  4  5  4 14 11 14 16 14 ] ]
        [ (full)   (24)       v10to26  113 113  28 54  11796  [ 300  560  810  960 ]  [  6  4  6 14 11 16 30  2 ] ]
        [ (full)   (25)       v10to26  117 117  32 58  12708  [ 312  588  870 1050 ]  [  8  4  8 13  7 22 22 13 ] ]
        [ (full)   (26)       v10to26  121 121  30 58  13652  [ 336  644  952 1110 ]  [ 10  2 19  4 28  6 33  4 ] ]
        [ (full)   (27)       v27to40  125 125  34 62  14628  [ 360  700 1020 1200 ]  [  8  4 22  3  8 26 12 28 ] ]
        [ (full)   (28)       v27to40  129 129  26 50  15371  [ 390  728 1050 1260 ]  [  3 10  3 23  4 31 11 31 ] ]
        [ (full)   (29)       v27to40  133 133  30 54  16411  [ 420  784 1140 1350 ]  [  7  7 21  7  1 37 19 26 ] ]
        [ (full)   (30)       v27to40  137 137  26 52  17483  [ 450  812 1200 1440 ]  [  5 10 19 10 15 25 23 25 ] ]
        [ (full)   (31)       v27to40  141 141  30 56  18587  [ 480  868 1290 1530 ]  [ 13  3  2 29 42  1 23 28 ] ]
        [ (full)   (32)       v27to40  145 145  34 60  19723  [ 510  924 1350 1620 ]  [ 17  0 10 23 10 35 19 35 ] ]
        [ (full)   (33)       v27to40  149 149  30 58  20891  [ 540  980 1440 1710 ]  [ 17  1 14 21 29 19 11 46 ] ]
        [ (full)   (34)       v27to40  153 153  34 62  22091  [ 570 1036 1530 1800 ]  [ 13  6 14 23 44  7 59  1 ] ]
        [ (full)   (35)       v27to40  157 157  30 54  23008  [ 570 1064 1590 1890 ]  [ 12  7 12 26 39 14 22 41 ] ]
        [ (full)   (36)       v27to40  161 161  24 50  24272  [ 600 1120 1680 1980 ]  [  6 14  6 34 46 10  2 64 ] ]
        [ (full)   (37)       v27to40  165 165  28 54  25568  [ 630 1204 1770 2100 ]  [ 17  4 29 14 49 10 24 46 ] ]
        [ (full)   (38)       v27to40  169 169  32 58  26896  [ 660 1260 1860 2220 ]  [  4 18 13 32 48 14 42 32 ] ]
        [ (full)   (39)       v27to40  173 173  26 54  28256  [ 720 1316 1950 2310 ]  [ 20  4 40  7 43 22 10 67 ] ]
        [ (full)   (40)       v27to40  177 177  30 58  29648  [ 750 1372 2040 2430 ]  [ 19  6 18 31 34 34 20 61 ] ]
        [ (rmqr)   (R7x43)    vR7x43     7  43  22 99    104  [  99    7   99   10 ]  [ -1 -1  1  0 -1 -1  1  0 ] ]
        [ (rmqr)   (R7x59)    vR7x59     7  59  20 40    171  [  99    9   99   14 ]  [ -1 -1  1  0 -1 -1  1  0 ] ]
        [ (rmqr)   (R7x77)    vR7x77     7  77  26 52    261  [  99   12   99   22 ]  [ -1 -1  1  0 -1 -1  1  0 ] ]
        [ (rmqr)   (R7x99)    vR7x99     7  99  24 50    358  [  99   16   99   30 ]  [ -1 -1  1  0 -1 -1  1  0 ] ]
        [ (rmqr)   (R7x139)   vR7x139    7 139  28 56    545  [  99   24   99   44 ]  [ -1 -1  1  0 -1 -1  2  0 ] ]
        [ (rmqr)   (R9x43)    vR9x43     9  43  22 99    170  [  99    9   99   14 ]  [ -1 -1  1  0 -1 -1  1  0 ] ]
        [ (rmqr)   (R9x59)    vR9x59     9  59  20 40    267  [  99   12   99   22 ]  [ -1 -1  1  0 -1 -1  1  0 ] ]
        [ (rmqr)   (R9x77)    vR9x77     9  77  26 52    393  [  99   18   99   32 ]  [ -1 -1  1  0 -1 -1  1  1 ] ]
        [ (rmqr)   (R9x99)    vR9x99     9  99  24 50    532  [  99   24   99   44 ]  [ -1 -1  1  0 -1 -1  2  0 ] ]
        [ (rmqr)   (R9x139)   vR9x139    9 139  28 56    797  [  99   36   99   66 ]  [ -1 -1  1  1 -1 -1  3  0 ] ]
        [ (rmqr)   (R11x27)   vR11x27   11  27  98 99    122  [  99    8   99   10 ]  [ -1 -1  1  0 -1 -1  1  0 ] ]
        [ (rmqr)   (R11x43)   vR11x43   11  43  22 99    249  [  99   12   99   20 ]  [ -1 -1  1  0 -1 -1  1  0 ] ]
        [ (rmqr)   (R11x59)   vR11x59   11  59  20 40    376  [  99   16   99   32 ]  [ -1 -1  1  0 -1 -1  1  1 ] ]
        [ (rmqr)   (R11x77)   vR11x77   11  77  26 52    538  [  99   24   99   44 ]  [ -1 -1  1  0 -1 -1  1  1 ] ]
        [ (rmqr)   (R11x99)   vR11x99   11  99  24 50    719  [  99   32   99   60 ]  [ -1 -1  1  1 -1 -1  1  1 ] ]
        [ (rmqr)   (R11x139)  vR11x139  11 139  28 56   1062  [  99   48   99   90 ]  [ -1 -1  2  0 -1 -1  3  0 ] ]
        [ (rmqr)   (R13x27)   vR13x27   13  27  98 99    172  [  99    9   99   14 ]  [ -1 -1  1  0 -1 -1  1  0 ] ]
        [ (rmqr)   (R13x43)   vR13x43   13  43  22 99    329  [  99   14   99   28 ]  [ -1 -1  1  0 -1 -1  1  0 ] ]
        [ (rmqr)   (R13x59)   vR13x59   13  59  20 40    486  [  99   22   99   40 ]  [ -1 -1  1  0 -1 -1  2  0 ] ]
        [ (rmqr)   (R13x77)   vR13x77   13  77  26 52    684  [  99   32   99   56 ]  [ -1 -1  1  1 -1 -1  1  1 ] ]
        [ (rmqr)   (R13x99)   vR13x99   13  99  24 50    907  [  99   40   99   78 ]  [ -1 -1  1  1 -1 -1  1  2 ] ]
        [ (rmqr)   (R13x139)  vR13x139  13 139  28 56   1328  [  99   60   99  112 ]  [ -1 -1  2  1 -1 -1  2  2 ] ]
        [ (rmqr)   (R15x43)   vR15x43   15  43  22 99    409  [  99   18   99   36 ]  [ -1 -1  1  0 -1 -1  1  1 ] ]
        [ (rmqr)   (R15x59)   vR15x59   15  59  20 40    596  [  99   26   99   48 ]  [ -1 -1  1  0 -1 -1  2  0 ] ]
        [ (rmqr)   (R15x77)   vR15x77   15  77  26 52    830  [  99   36   99   72 ]  [ -1 -1  1  1 -1 -1  2  1 ] ]
        [ (rmqr)   (R15x99)   vR15x99   15  99  24 50   1095  [  99   48   99   88 ]  [ -1 -1  2  0 -1 -1  4  0 ] ]
        [ (rmqr)   (R15x139)  vR15x139  15 139  28 56   1594  [  99   72   99  130 ]  [ -1 -1  2  1 -1 -1  1  4 ] ]
        [ (rmqr)   (R17x43)   vR17x43   17  43  22 99    489  [  99   22   99   40 ]  [ -1 -1  1  0 -1 -1  1  1 ] ]
        [ (rmqr)   (R17x59)   vR17x59   17  59  20 40    706  [  99   32   99   60 ]  [ -1 -1  2  0 -1 -1  2  0 ] ]
        [ (rmqr)   (R17x77)   vR17x77   17  77  26 52    976  [  99   44   99   84 ]  [ -1 -1  2  0 -1 -1  1  2 ] ]
        [ (rmqr)   (R17x99)   vR17x99   17  99  24 50   1283  [  99   60   99  104 ]  [ -1 -1  2  1 -1 -1  4  0 ] ]
        [ (rmqr)   (R17x139)  vR17x139  17 139  28 56   1860  [  99   80   99  156 ]  [ -1 -1  4  0 -1 -1  2  4 ] ]
    ] def
} ctxdef

    /eclval (LMQH) eclevel search pop length exch pop exch pop def
    0 1 metrics length 1 sub {
        /i exch def
        /m metrics i get def
        /frmt m 0 get def                             % Format of the symbol
        /vers m 1 get def                             % Version of symbol
        /vergrp m 2 get def                           % Version group
        /verind i 44 sub def                          % Version indicator for rMQR format info
        /rows m 3 get def                             % Length of side
        /cols m 4 get def                             % Length of side
        /asp2 m 5 get def                             % Position of second alignment symbol
        /asp3 m 6 get def                             % Position of third alignment symbol
        /nmod m 7 get def                             % Number of modules
        /ncws nmod 8 idiv def                         % Total number of codewords
        /rbit nmod 8 mod def                          % Number of remainder bits
        /lc4b false def                               % Last data codeword is 4 bits long
        vers (M1) eq vers (M3) eq or {                % Adjustments for M1 and M3 symbols
            /ncws ncws 1 add def
            /rbit 0 def
            /lc4b true def
        } if
        /ecws m 8 get eclval get def                  % Number of error correction codewords
        /dcws ncws ecws sub def                       % Number of data codewords
        /dmod dcws 8 mul lc4b {4} {0} ifelse sub def  % Number of data modules
        /ecb1 m 9 get eclval 2 mul get def            % First error correction blocks
        /ecb2 m 9 get eclval 2 mul 1 add get def      % Second error correction blocks
        /okay true def
        format frmt ne {/okay false def} if           % The format must match that supplied
        frmt (micro) eq fnc1first and {/okay false def} if  % FNC1 mode is only available in full and rmqr
        version (unset) ne version vers ne and {/okay false def} if  % The version must match that supplied
        ecb1 -1 eq ecb2 -1 eq or {/okay false def} if % Error correction level must be valid
        /verbits msgbits vergrp get def
        verbits -1 eq {                               % Bitstream must be available
            /okay false def
        } {
            verbits length dmod gt {/okay false def} if  % and fit into data modules
        } ifelse
        /term (000000000) 0 termlens vergrp get getinterval def
        okay {exit} if
    } for

    okay not {
        /bwipp.qrcodeNoValidSymbol (Maximum length exceeded or invalid content) //raiseerror exec
    } if

    /format frmt def
    /version vers def
    /msgbits verbits def
    /dcpb dcws ecb1 ecb2 add idiv def                 % Base data codewords per block
    /ecpb ncws ecb1 ecb2 add idiv dcpb sub def        % Error correction codewords per block

    % Complete the message bits by adding the terminator, truncated if necessary
    /term term 0 dmod msgbits length sub term length 2 copy gt {exch} if pop getinterval def
    msgbits length term length add string
    dup 0 msgbits putinterval
    dup msgbits length term putinterval
    /msgbits exch def

    % Expand the message bits by adding padding as necessary
    /pad dmod string def
    0 1 pad length 1 sub {pad exch 48 put} for
    pad 0 msgbits putinterval
    /padnum 0 def
    msgbits length 8 div ceiling 8 mul cvi 8 dmod lc4b {5} {1} ifelse sub {
        pad exch padstrs padnum get putinterval
        /padnum padnum 1 add 2 mod def
    } for

    % Evaluate the padded message into codewords
    /cws dcws array def
    0 1 cws length 1 sub {
        /c exch def
        /bpcw 8 def
        lc4b c cws length 1 sub eq and {/bpcw 4 def} if
        /cwb pad c 8 mul bpcw getinterval def
        /cw 0 def
        0 1 bpcw 1 sub {
            /i exch def
            /cw cw 2 bpcw i sub 1 sub exp cvi cwb i get 48 sub mul add def
        } for
        cws c cw put
    } for

    % Short final data byte in M1 and M3 symbols has high-order value
    lc4b {cws cws length 1 sub 2 copy get 4 bitshift put} if

    options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if

    % Calculate the log and anti-log tables
{
    /rsalog [ 1 255 { dup 2 mul dup 256 ge {285 xor} if } repeat ] def
    /rslog 256 array def
    1 1 255 {dup rsalog exch get exch rslog 3 1 roll put} for
} ctxdef

    % 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 255 mod rsalog exch get
        } {
            pop pop 0
        } ifelse
    } def

    % Generate the coefficients for the Reed-Solomon algorithm
    /coeffs [ 1 ecpb {0} repeat ] def
    0 1 ecpb 1 sub {
        /i exch def
        coeffs i 1 add coeffs i get put
        i -1 1 {
            /j exch def
            coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put
        } for
        coeffs 0 coeffs 0 get rsalog i get rsprod put
    } for
    /coeffs coeffs 0 coeffs length 1 sub getinterval def

    % Reed-Solomon algorithm to derive the error correction codewords
    /rscodes {
        /rscws exch def
        /rsnd rscws length def
        /rscws [ rscws {} forall ecpb {0} repeat ] def
        0 1 rsnd 1 sub {
            /m exch def
            /k rscws m get def
            0 1 ecpb 1 sub {
                /j exch def
                rscws m j add 1 add coeffs ecpb j sub 1 sub get k rsprod rscws m j add 1 add get xor put
            } for
        } for
        rscws rsnd ecpb getinterval
    } def

    % Divide codewords into two groups of blocks and calculate the error correction codewords
    /dcwsb ecb1 ecb2 add array def
    /ecwsb ecb1 ecb2 add array def
    0 1 ecb1 1 sub {  % First group of blocks has smaller number of data codewords
        /i exch def
        dcwsb i cws i dcpb mul dcpb getinterval put
        ecwsb i dcwsb i get rscodes put
    } for
    0 1 ecb2 1 sub {  % Second group of blocks has larger number of data codewords
        /i exch def
        dcwsb ecb1 i add cws ecb1 dcpb mul i dcpb 1 add mul add dcpb 1 add getinterval put
        ecwsb ecb1 i add dcwsb ecb1 i add get rscodes put
    } for

    % Reassemble the codewords
    /cws ncws array def
    /cw 0 def
    0 1 dcpb {  % Interleave the data codeword blocks
        /i exch def
        0 1 ecb1 ecb2 add 1 sub {
            /j exch def
            i dcwsb j get length lt {  % Ignore the end of short blocks
                cws cw dcwsb j get i get put
                /cw cw 1 add def
            } if
        } for
    } for
    0 1 ecpb 1 sub {  % Interleave the error codeword blocks
        /i exch def
        0 1 ecb1 ecb2 add 1 sub {
            /j exch def
            cws cw ecwsb j get i get put
            /cw cw 1 add def
        } for
    } for

    % Extend codewords by one if there are remainder bits
    rbit 0 gt {
        /pad cws length 1 add array def
        pad 0 cws putinterval
        pad pad length 1 sub 0 put
        /cws pad def
    } if

    % Fixups for the short final data byte in M1 and M3 symbols
    lc4b {
        cws dcws 1 sub 2 copy get -4 bitshift put
        dcws 1 sub 1 ncws 2 sub {
            /i exch def
            cws i cws i get 15 and 4 bitshift put
            cws i cws i 1 add get -4 bitshift 15 and cws i get or put
        } for
        cws ncws 1 sub cws ncws 1 sub get 15 and 4 bitshift put
    } if

    options /debugecc known { /bwipp.debugecc cws //raiseerror exec } if

    % Create the bitmap
    /pixs [ rows cols mul {-1} repeat ] def
    /qmv {cols mul add} def

    % Timing patterns
    format (full) eq {
        8 1 cols 9 sub {
            /i exch def
            pixs i 6 qmv i 1 add 2 mod put
            pixs 6 i qmv i 1 add 2 mod put
        } for
    } if
    format (micro) eq {
        8 1 cols 1 sub {
            /i exch def
            pixs i 0 qmv i 1 add 2 mod put
            pixs 0 i qmv i 1 add 2 mod put
        } for
    } if
    format (rmqr) eq {
        3 1 cols 4 sub {  % Along top and bottom
            /i exch def
            pixs i 0 qmv i 1 add 2 mod put
            pixs i rows 1 sub qmv i 1 add 2 mod put
        } for
        3 1 rows 4 sub {  % Along left and right
            /i exch def
            pixs 0 i qmv i 1 add 2 mod put
            pixs cols 1 sub i qmv i 1 add 2 mod put
        } for
        asp2 1 sub asp3 asp2 sub cols 13 sub {  % Down interior
            /i exch def
            3 1 rows 4 sub {
                /j exch def
                pixs i j qmv j 1 add 2 mod put
            } for
        } for
    } if

    % Finder patterns
{
    /fpat [
        [ 1 1 1 1 1 1 1 0 ]
        [ 1 0 0 0 0 0 1 0 ]
        [ 1 0 1 1 1 0 1 0 ]
        [ 1 0 1 1 1 0 1 0 ]
        [ 1 0 1 1 1 0 1 0 ]
        [ 1 0 0 0 0 0 1 0 ]
        [ 1 1 1 1 1 1 1 0 ]
        [ 0 0 0 0 0 0 0 0 ]
    ] def
    /fsubpat [
        [ 1 1 1 1 1 9 9 9 ]
        [ 1 0 0 0 1 9 9 9 ]
        [ 1 0 1 0 1 9 9 9 ]
        [ 1 0 0 0 1 9 9 9 ]
        [ 1 1 1 1 1 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
    ] def
    /fcorpat [
        [ 1 1 1 9 9 9 9 9 ]
        [ 1 0 9 9 9 9 9 9 ]
        [ 1 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
    ] def
    /fnullpat [
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
        [ 9 9 9 9 9 9 9 9 ]
    ] def
    /fpatmap <<
        %          TL     TR       BL       BR
        (full)  [ fpat fpat     fpat     fnullpat ]
        (micro) [ fpat fnullpat fnullpat fnullpat ]
        (rmqr)  [ fpat fcorpat  fcorpat  fsubpat  ]
    >> def
} ctxdef
    /fpats fpatmap format get def
    0 1 7 {
      /y exch def
      0 1 7 {
        /x exch def
        /fpb0 fpats 0 get y get x get def
        /fpb1 fpats 1 get y get x get def
        /fpb2 fpats 2 get y get x get def
        /fpb3 fpats 3 get y get x get def
        fpb0 9 ne y rows lt and {pixs x y qmv fpb0 put} if
        fpb1 9 ne {pixs cols x sub 1 sub y qmv fpb1 put} if
        fpb2 9 ne {pixs x rows y sub 1 sub qmv fpb2 put} if
        fpb3 9 ne {pixs cols x sub 1 sub rows y sub 1 sub qmv fpb3 put} if
      } for
    } for

    % Alignment patterns
{
    /algnpatfull [
        [ 1 1 1 1 1 ]
        [ 1 0 0 0 1 ]
        [ 1 0 1 0 1 ]
        [ 1 0 0 0 1 ]
        [ 1 1 1 1 1 ]
    ] def
    /algnpatrmqr [
        [ 1 1 1 9 9 ]
        [ 1 0 1 9 9 ]
        [ 1 1 1 9 9 ]
        [ 9 9 9 9 9 ]
        [ 9 9 9 9 9 ]
    ] def
} ctxdef

    /putalgnpat {
        /py exch def
        /px exch def
        0 1 4 {
            /pb exch def
            0 1 4 {
                /pa exch def
                /algnb algnpat pb get pa get def
                algnb 9 ne {
                    pixs px pa add py pb add qmv algnb put
                } if
            } for
        } for
    } def
    format (full) eq {
        /algnpat algnpatfull def
        asp2 2 sub asp3 asp2 sub cols 13 sub {
            /i exch def
            i 4 putalgnpat
            4 i putalgnpat
        } for
        asp2 2 sub asp3 asp2 sub cols 9 sub {
            /x exch def
            asp2 2 sub asp3 asp2 sub rows 9 sub {
                /y exch def
                x y putalgnpat
            } for
        } for
    } if
    format (rmqr) eq {
        /algnpat algnpatrmqr def
        asp2 2 sub asp3 asp2 sub cols 13 sub {
            /i exch def
            i 0 putalgnpat
            i rows 3 sub putalgnpat
        } for
    } if

    % Format information modules
{
    /formatmapmicro [
            [ [ 1 8 ] ]  [ [ 2 8 ] ]  [ [ 3 8 ] ]  [ [ 4 8 ] ]  [ [ 5 8 ] ]
            [ [ 6 8 ] ]  [ [ 7 8 ] ]  [ [ 8 8 ] ]  [ [ 8 7 ] ]  [ [ 8 6 ] ]
            [ [ 8 5 ] ]  [ [ 8 4 ] ]  [ [ 8 3 ] ]  [ [ 8 2 ] ]  [ [ 8 1 ] ]
    ] def
} ctxdef
    /formatmap <<
        (full) [
            [ [ 0 8 ] [ 8 cols 1 sub ] ]  [ [ 1 8 ] [ 8 cols 2 sub ] ]  [ [ 2 8 ] [ 8 cols 3 sub ] ]
            [ [ 3 8 ] [ 8 cols 4 sub ] ]  [ [ 4 8 ] [ 8 cols 5 sub ] ]  [ [ 5 8 ] [ 8 cols 6 sub ] ]
            [ [ 7 8 ] [ 8 cols 7 sub ] ]  [ [ 8 8 ] [ cols 8 sub 8 ] ]  [ [ 8 7 ] [ cols 7 sub 8 ] ]
            [ [ 8 5 ] [ cols 6 sub 8 ] ]  [ [ 8 4 ] [ cols 5 sub 8 ] ]  [ [ 8 3 ] [ cols 4 sub 8 ] ]
            [ [ 8 2 ] [ cols 3 sub 8 ] ]  [ [ 8 1 ] [ cols 2 sub 8 ] ]  [ [ 8 0 ] [ cols 1 sub 8 ] ]
        ]
        (micro) formatmapmicro
        (rmqr) [
            [ [ 11 3 ] [ cols 3 sub rows 6 sub ] ]  [ [ 11 2 ] [ cols 4 sub rows 6 sub ] ]  [ [ 11 1 ] [ cols 5 sub rows 6 sub ] ]
            [ [ 10 5 ] [ cols 6 sub rows 2 sub ] ]  [ [ 10 4 ] [ cols 6 sub rows 3 sub ] ]  [ [ 10 3 ] [ cols 6 sub rows 4 sub ] ]
            [ [ 10 2 ] [ cols 6 sub rows 5 sub ] ]  [ [ 10 1 ] [ cols 6 sub rows 6 sub ] ]  [ [  9 5 ] [ cols 7 sub rows 2 sub ] ]
            [ [  9 4 ] [ cols 7 sub rows 3 sub ] ]  [ [  9 3 ] [ cols 7 sub rows 4 sub ] ]  [ [  9 2 ] [ cols 7 sub rows 5 sub ] ]
            [ [  9 1 ] [ cols 7 sub rows 6 sub ] ]  [ [  8 5 ] [ cols 8 sub rows 2 sub ] ]  [ [  8 4 ] [ cols 8 sub rows 3 sub ] ]
            [ [  8 3 ] [ cols 8 sub rows 4 sub ] ]  [ [  8 2 ] [ cols 8 sub rows 5 sub ] ]  [ [  8 1 ] [ cols 8 sub rows 6 sub ] ]
        ]
    >> format get def
    formatmap {
        { {} forall qmv pixs exch 1 put } forall
    } forall

    % Version information modules
    format (full) eq cols 45 ge and {
        /versionmap [
            [ [ cols  9 sub 5 ] [ 5 cols  9 sub ] ]  [ [ cols 10 sub 5 ] [ 5 cols 10 sub ] ]
            [ [ cols 11 sub 5 ] [ 5 cols 11 sub ] ]  [ [ cols  9 sub 4 ] [ 4 cols  9 sub ] ]
            [ [ cols 10 sub 4 ] [ 4 cols 10 sub ] ]  [ [ cols 11 sub 4 ] [ 4 cols 11 sub ] ]
            [ [ cols  9 sub 3 ] [ 3 cols  9 sub ] ]  [ [ cols 10 sub 3 ] [ 3 cols 10 sub ] ]
            [ [ cols 11 sub 3 ] [ 3 cols 11 sub ] ]  [ [ cols  9 sub 2 ] [ 2 cols  9 sub ] ]
            [ [ cols 10 sub 2 ] [ 2 cols 10 sub ] ]  [ [ cols 11 sub 2 ] [ 2 cols 11 sub ] ]
            [ [ cols  9 sub 1 ] [ 1 cols  9 sub ] ]  [ [ cols 10 sub 1 ] [ 1 cols 10 sub ] ]
            [ [ cols 11 sub 1 ] [ 1 cols 11 sub ] ]  [ [ cols  9 sub 0 ] [ 0 cols  9 sub ] ]
            [ [ cols 10 sub 0 ] [ 0 cols 10 sub ] ]  [ [ cols 11 sub 0 ] [ 0 cols 11 sub ] ]
        ] def
    } {
        /versionmap [] def
    } ifelse
    versionmap {
        { {} forall qmv pixs exch 0 put } forall
    } forall

    % Reserve the solitary dark module in full symbols
    format (full) eq {
        pixs 8 rows 8 sub qmv 0 put
    } if

    % Calculate the mask patterns
    /maskfuncs <<
        (full) [
            {add 2 mod}
            {exch pop 2 mod}
            {pop 3 mod}
            {add 3 mod}
            {2 idiv exch 3 idiv add 2 mod}
            {mul dup 2 mod exch 3 mod add}
            {mul dup 2 mod exch 3 mod add 2 mod}
            {2 copy mul 3 mod 3 1 roll add 2 mod add 2 mod}
        ]
        (micro) [
            {exch pop 2 mod}
            {2 idiv exch 3 idiv add 2 mod}
            {mul dup 2 mod exch 3 mod add 2 mod}
            {2 copy mul 3 mod 3 1 roll add 2 mod add 2 mod}
        ]
        (rmqr) [
            {2 idiv exch 3 idiv add 2 mod}
        ]
    >> format get def
    mask -1 ne {  % User specifies a mask
        /maskfuncs [maskfuncs mask 1 sub get] def
        /bestmaskval mask 1 sub def
    } if
    /masks maskfuncs length array def
    0 1 masks length 1 sub {
        /m exch def
        /mask rows cols mul array def
        0 1 rows 1 sub {
            /j exch def
            0 1 cols 1 sub {
                /i exch def
                i j maskfuncs m get exec 0 eq
                pixs i j qmv get -1 eq and {1} {0} ifelse
                mask i j qmv 3 -1 roll put
            } for
        } for
        masks m mask put
    } for

    % Walk the symbol placing the bitstream
    /posx cols format (rmqr) ne {1} {2} ifelse sub def
    /posy rows 1 sub def
    /dir -1 def  % -1 is upwards, 1 is downwards
    /col 1 def   % 0 is left bit, 1 is right bit
    /num 0 def
    { % loop
        posx 0 lt {exit} if
        pixs posx posy qmv get -1 eq {
            cws num 8 idiv get 7 num 8 mod sub neg bitshift 1 and
            pixs posx posy qmv 3 -1 roll put
            /num num 1 add def
        } if
        col 1 eq {
            /col 0 def
            /posx posx 1 sub def
        } {
            /col 1 def
            /posx posx 1 add def
            /posy posy dir add def
            posy 0 lt posy rows ge or {  % Turn around at top and bottom
                /dir dir -1 mul def
                /posy posy dir add def
                /posx posx 2 sub def
                % Hop over the timing pattern in full size symbols
                format (full) eq posx 6 eq and {/posx posx 1 sub def} if
            } if
        } ifelse
    } loop

    % Evaluate runlength encoded rows or columns in full symbols
    /evalfulln1n3 {
        /scrle exch def
        % Detect runs of 5 or more like modules
        /scr1 0 scrle { dup 5 ge {add 2 sub dup} if pop } forall def
        % Detect 1:1:3:1:1 ratio next to 4 modules of whitespace
        /scr3 0 def
        3 2 scrle length 3 sub {  % Scan odd (dark) runs within bounds
            /j exch def
            scrle j get 3 mod 0 eq {  % Multiple of 3 black modules
                /fact scrle j get 3 idiv def
                scrle j 2 sub 5 getinterval {fact eq} forall and exch pop and and {
                    j 3 eq j 4 add scrle length ge or {  % At either extent of run
                        /scr3 scr3 40 add def
                    } {  % Bounded by dark modules
                        scrle j 3 sub get 4 ge scrle j 3 add get 4 ge or {
                            /scr3 scr3 40 add def
                        } if
                    } ifelse
                } if
            } if
        } for
        scr1 scr3
    } def

    % Evaluation algorithm for full symbols
    /evalfull {
        /sym exch def

        /n1 0 def /n2 0 def /n3 0 def
        /rle cols 1 add array def
        /lastpairs cols array def
        /thispairs cols array def
        /colsadd1 cols 1 add def
        0 1 cols 1 sub {
            /i exch def

            % Runlength encode (light, dark, light, ...) and evaluate each column
            mark 0 0
            i cols dup dup mul 1 sub {
                sym exch get exch 1 index eq {exch 1 add exch} {1 exch} ifelse
            } for
            pop
            rle 0 counttomark 2 sub getinterval astore
            evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def
            pop

            % Runlength encode (light, dark, light, ...) and evaluate each row
            /symrow sym i cols mul cols getinterval def
            mark 0 0
            symrow {
                exch 1 index eq {exch 1 add exch} {1 exch} ifelse
            } forall
            pop
            rle 0 counttomark 2 sub getinterval astore
            evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def
            pop

            % Count and score same coloured blocks
            /lastpairs thispairs /thispairs lastpairs def def
            symrow 0 get 1 eq {0} {1} ifelse
            symrow {exch 1 index add exch} forall
            pop
            thispairs astore pop
            i 0 gt {
                mark
                lastpairs aload pop thispairs aload pop
                n2 cols { exch colsadd1 index add 3 and 0 eq {3 add} if } repeat
                /n2 exch def
                cleartomark
            } if

        } for

        % Score dark/light imbalance
        /dark 0 sym {add} forall def
        /n4 dark 100 mul cols dup mul div 50 sub abs 5 div cvi 10 mul def

        n1 n2 add n3 add n4 add
    } def

    % Evaluation algorithm for micro symbols
    /evalmicro {
        /sym exch def
        /dkrhs 0 def /dkbot 0 def
        1 1 cols 1 sub {
            /i exch def
            /dkrhs dkrhs sym cols 1 sub i qmv get add def
            /dkbot dkbot sym i cols 1 sub qmv get add def
        } for
        dkrhs dkbot le {
            dkrhs 16 mul dkbot add neg
        } {
            dkbot 16 mul dkrhs add neg
        } ifelse
    } def

    % Evaluate the masked symbols to find the most suitable
    /bestscore 999999999 def
    0 1 masks length 1 sub {
        /m exch def
        /masksym rows cols mul array def
        0 1 rows cols mul 1 sub {
            /i exch def
            masksym i pixs i get masks m get i get xor put
        } for
        masks length 1 ne {  % Not rMQR nor user-specified mask
            format (full) eq {
                masksym evalfull /score exch def
            } {
                masksym evalmicro /score exch def
            } ifelse
            score bestscore lt {
                /bestsym masksym def
                /bestmaskval m def
                /bestscore score def
            } if
        } {
            /bestsym masksym def
        } ifelse
    } for
    /pixs bestsym def

    % Set the solitary dark module in full symbols
    format (full) eq {
        pixs 8 cols 8 sub qmv 1 put
    } if

    % Add the format information
{
    /fmtvalsfull [
        16#5412 16#5125 16#5e7c 16#5b4b 16#45f9 16#40ce 16#4f97 16#4aa0
        16#77c4 16#72f3 16#7daa 16#789d 16#662f 16#6318 16#6c41 16#6976
        16#1689 16#13be 16#1ce7 16#19d0 16#0762 16#0255 16#0d0c 16#083b
        16#355f 16#3068 16#3f31 16#3a06 16#24b4 16#2183 16#2eda 16#2bed
    ] def
    /fmtvalsmicro [
        16#4445 16#4172 16#4e2b 16#4b1c 16#55ae 16#5099 16#5fc0 16#5af7
        16#6793 16#62a4 16#6dfd 16#68ca 16#7678 16#734f 16#7c16 16#7921
        16#06de 16#03e9 16#0cb0 16#0987 16#1735 16#1202 16#1d5b 16#186c
        16#2508 16#203f 16#2f66 16#2a51 16#34e3 16#31d4 16#3e8d 16#3bba
    ] def
    /fmtvalsrmqr1 [
        16#1fab2 16#1e597 16#1dbdd 16#1c4f8 16#1b86c 16#1a749 16#19903 16#18626
        16#17f0e 16#1602b 16#15e61 16#14144 16#13dd0 16#122f5 16#11cbf 16#1039a
        16#0f1ca 16#0eeef 16#0d0a5 16#0cf80 16#0b314 16#0ac31 16#0927b 16#08d5e
        16#07476 16#06b53 16#05519 16#04a3c 16#036a8 16#0298d 16#017c7 16#008e2
        16#3f367 16#3ec42 16#3d208 16#3cd2d 16#3b1b9 16#3ae9c 16#390d6 16#38ff3
        16#376db 16#369fe 16#357b4 16#34891 16#33405 16#32b20 16#3156a 16#30a4f
        16#2f81f 16#2e73a 16#2d970 16#2c655 16#2bac1 16#2a5e4 16#29bae 16#2848b
        16#27da3 16#26286 16#25ccc 16#243e9 16#23f7d 16#22058 16#21e12 16#20137
    ] def
    /fmtvalsrmqr2 [
        16#20a7b 16#2155e 16#22b14 16#23431 16#248a5 16#25780 16#269ca 16#276ef
        16#28fc7 16#290e2 16#2aea8 16#2b18d 16#2cd19 16#2d23c 16#2ec76 16#2f353
        16#30103 16#31e26 16#3206c 16#33f49 16#343dd 16#35cf8 16#362b2 16#37d97
        16#384bf 16#39b9a 16#3a5d0 16#3baf5 16#3c661 16#3d944 16#3e70e 16#3f82b
        16#003ae 16#01c8b 16#022c1 16#03de4 16#04170 16#05e55 16#0601f 16#07f3a
        16#08612 16#09937 16#0a77d 16#0b858 16#0c4cc 16#0dbe9 16#0e5a3 16#0fa86
        16#108d6 16#117f3 16#129b9 16#1369c 16#14a08 16#1552d 16#16b67 16#17442
        16#18d6a 16#1924f 16#1ac05 16#1b320 16#1cfb4 16#1d091 16#1eedb 16#1f1fe
    ] def
} ctxdef
    format (full) eq {
        /ecid (MLHQ) eclevel search pop length exch pop exch pop def
        /fmtval fmtvalsfull ecid 3 bitshift bestmaskval add get def
        0 1 formatmap length 1 sub {
            /i exch def
            formatmap i get {
                pixs exch aload pop qmv fmtval 14 i sub neg bitshift 1 and put
            } forall
        } for
    } if
    format (micro) eq {
        /symid [ [0] [1 2] [3 4] [5 6 7] ] cols 11 sub 2 idiv get eclval get def
        /fmtval fmtvalsmicro symid 2 bitshift bestmaskval add get def
        0 1 formatmap length 1 sub {
            /i exch def
            pixs formatmap i get 0 get aload pop qmv fmtval 14 i sub neg bitshift 1 and put
        } for
    } if
    format (rmqr) eq {
        /fmtvalu (MH) eclevel search pop length exch pop exch pop 5 bitshift verind add def
        /fmtval1 fmtvalsrmqr1 fmtvalu get def
        /fmtval2 fmtvalsrmqr2 fmtvalu get def
        0 1 formatmap length 1 sub {
            /i exch def
            pixs formatmap i get 0 get aload pop qmv fmtval1 17 i sub neg bitshift 1 and put
            pixs formatmap i get 1 get aload pop qmv fmtval2 17 i sub neg bitshift 1 and put
        } for
    } if

    % Add the version information
{
    /vervals [
        16#07c94 16#085bc 16#09a99 16#0a4d3 16#0bbf6 16#0c762 16#0d847
        16#0e60d 16#0f928 16#10b78 16#1145d 16#12a17 16#13532 16#149a6
        16#15683 16#168c9 16#177ec 16#18ec4 16#191e1 16#1afab 16#1b08e
        16#1cc1a 16#1d33f 16#1ed75 16#1f250 16#209d5 16#216fd 16#228ba
        16#2379f 16#24b0b 16#2542e 16#26a64 16#27541 16#28c69
    ] def
} ctxdef
    format (full) eq cols 45 ge and {
        /verval vervals cols 17 sub 4 idiv 7 sub get def
        0 1 versionmap length 1 sub {
            /i exch def
            versionmap i get {
                pixs exch {} forall qmv verval 17 i sub neg bitshift 1 and put
            } forall
        } for
    } if

    % Return the arguments
    <<
    /ren //renmatrix
    /pixs pixs
    /pixx cols
    /pixy rows
    /height rows 2 mul 72 div
    /width cols 2 mul 72 div
    /opt options
    >>

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/qrcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER qrcode--

% --BEGIN ENCODER swissqrcode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix qrcode--
% --DESC: Swiss QR Code
% --EXAM:
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp swissqrcode 0.0 2022082100 68213 68020
%%BeginData:        128 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /qrcode dup /uk.co.terryburton.bwipp findresource put
begin
/swissqrcode {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw 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

    % Parse ordinals of the form ^NNN to ASCII
    /fncvals <<
        /parse parse
        /parseonly true
        /parsefnc false
    >> def
    /barcode barcode fncvals //parseinput exec def
    /barlen barcode length def
    options (parse) undef

    % Validate the input length
    barcode length 997 gt {
        /bwipp.swissqrcodeBadLength (Swiss QR Code input must not exceed 997 digits) //raiseerror exec
    } if

    % Get the result of encoding with qrcode
    options (dontdraw) true put
    /args barcode options //qrcode exec def

    args (opt) options put
    args

    % The 7mm-wide Swiss Cross is defined by the specification as being an
    % overlaid image, i.e. not made out of "modules", so very likely a
    % different pitch. It cannot therefore be represented by our standard image
    % dictionary and would be a nightmare to gridfit. The application assumes a
    % sufficient high-resolution print process that such issues do not matter.
    %
    % So for now we simply do as we're told and paint over the top of the
    % barcode image that has been scaled to 46mm, user be damned!
    %
    dontdraw not {

        gsave
        currentpoint translate
        72 25.4 div dup scale  % pt to mm

        % Clipping path with 7mm hole for the Swiss Cross
        gsave
        newpath
         0  0 moveto
        46  0 lineto
        46 46 lineto
         0 46 lineto
        closepath
        19.5 19.5 moveto
        19.5 26.5 lineto
        26.5 26.5 lineto
        26.5 19.5 lineto
        closepath
        clip

        % Scale the QR Code to fit within 46mm
        gsave
        0 0 moveto
        46 args (pixx) get div 2 div dup scale
        //renmatrix exec
        grestore

        grestore  % Clipping

        % Draw Swiss Cross
        19.5 dup translate
        7 83 div dup scale

        newpath
         6  6 moveto
         6 77 lineto
        77 77 lineto
        77  6 lineto
        closepath
        49 18 moveto
        49 34 lineto
        65 34 lineto
        65 49 lineto
        49 49 lineto
        49 65 lineto
        34 65 lineto
        34 49 lineto
        18 49 lineto
        18 34 lineto
        34 34 lineto
        34 18 lineto
        closepath
        0 0 0 setrgbcolor fill

        grestore

    } if

    end

}
[/barcode] {null def} forall
bind def
/swissqrcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER swissqrcode--

% --BEGIN ENCODER microqrcode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix qrcode--
% --DESC: Micro QR Code
% --EXAM: 1234
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp microqrcode 0.0 2022082100 62905 62760
%%BeginData:         46 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /qrcode dup /uk.co.terryburton.bwipp findresource put
begin
/microqrcode {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw 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

    % Get the result of encoding with qrcode with format=micro
    options (dontdraw) true put
    options (format) (micro) put

    /args barcode options //qrcode exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/microqrcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER microqrcode--

% --BEGIN ENCODER rectangularmicroqrcode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix qrcode--
% --DESC: Rectangular Micro QR Code
% --EXAM: 1234
% --EXOP: version=R17x139
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp rectangularmicroqrcode 0.0 2022082100 62948 62792
%%BeginData:         46 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /qrcode dup /uk.co.terryburton.bwipp findresource put
begin
/rectangularmicroqrcode {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw 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

    % Get the result of encoding with qrcode with format=micro
    options (dontdraw) true put
    options (format) (rmqr) put

    /args barcode options //qrcode exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/rectangularmicroqrcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER rectangularmicroqrcode--

% --BEGIN ENCODER maxicode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmaximatrix--
% --DESC: MaxiCode
% --EXAM: [)>^03001^02996152382802^029840^029001^0291Z00004951^029UPSN^02906X610^029159^0291234567^0291/1^029^029Y^029634 ALPHA DR^029PITTSBURGH^029PA^029^004
% --EXOP: mode=2 parse
% --RNDR: renmaximatrix
%%BeginResource: uk.co.terryburton.bwipp maxicode 0.0 2022082100 132737 135002
%%BeginData:        607 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmaximatrix dup /uk.co.terryburton.bwipp findresource put
begin
/maxicode {

    20 dict begin

    /options exch def        % We are given an option string
    /barcode exch def        % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /mode -1 def
    /sam -1 def
    /parse false def
    /parsefnc 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

    /mode mode cvi def
    /sam sam cvi def

    /maxicode //loadctx exec

    % Parse the input
    /fncvals <<
        /parse parse
        /parsefnc parsefnc
        /eci true
        % ECIs only
    >> def
    /msg barcode fncvals //parseinput exec def
    /msglen msg length def

    % Special message handling for modes 2 and 3
    mode 2 eq mode 3 eq or {

        % Convert to a string for extracting the structured data
        /barcode msglen string def
        0 1 msglen 1 sub {
            /i exch def
            msg i get 0 gt {
                barcode i msg i get put
            } if
        } for
        /barlen barcode length def

        % Normalise messages that begin with a field identifier [)>{RS}01{GS}yy
        barcode 0 7 getinterval <5b293e1e30311d> eq {
            /fid barcode 0 9 getinterval def
            /barcode barcode 9 barlen 9 sub getinterval def
        } {
            /fid () def
        } ifelse

        % Read the postcode, country code and service code fields separated by GS
        barcode <1d> search pop /pcode exch def
        pop <1d> search pop /ccode exch def
        pop <1d> search pop /scode exch def
        pop /barcode exch def

        % Prepend the field identifier
        barcode length fid length add string dup
        0 fid putinterval dup
        fid length barcode putinterval
        /barcode exch def
        /barlen barcode length def

        /msg [ barcode {} forall ] def
        /msglen msg length def

    } if

{
    % Special function characters
    /eci -1 def  /pad -2 def  /ns -3 def
    /la  -4 def  /lb  -5 def
    /sa  -6 def  /sb  -7 def  /sc -8 def  /sd -9 def  /se -10 def
    /sa2 -11 def /sa3 -12 def
    /lkc -13 def /lkd -14 def /lke -15 def
    /pd2 -16 def /pd3 -17 def

    % Character maps for each state
    /charmaps [
        %  A    B    C    D    E
        [  13  (`)  192  224    0 ]  % 0
        [ (A)  (a)  193  225    1 ]  % 1
        [ (B)  (b)  194  226    2 ]  % 2
        [ (C)  (c)  195  227    3 ]  % 3
        [ (D)  (d)  196  228    4 ]  % 4
        [ (E)  (e)  197  229    5 ]  % 5
        [ (F)  (f)  198  230    6 ]  % 6
        [ (G)  (g)  199  231    7 ]  % 7
        [ (H)  (h)  200  232    8 ]  % 8
        [ (I)  (i)  201  233    9 ]  % 9
        [ (J)  (j)  202  234   10 ]  % 10
        [ (K)  (k)  203  235   11 ]  % 11
        [ (L)  (l)  204  236   12 ]  % 12
        [ (M)  (m)  205  237   13 ]  % 13
        [ (N)  (n)  206  238   14 ]  % 14
        [ (O)  (o)  207  239   15 ]  % 15
        [ (P)  (p)  208  240   16 ]  % 16
        [ (Q)  (q)  209  241   17 ]  % 17
        [ (R)  (r)  210  242   18 ]  % 18
        [ (S)  (s)  211  243   19 ]  % 19
        [ (T)  (t)  212  244   20 ]  % 20
        [ (U)  (u)  213  245   21 ]  % 21
        [ (V)  (v)  214  246   22 ]  % 22
        [ (W)  (w)  215  247   23 ]  % 23
        [ (X)  (x)  216  248   24 ]  % 24
        [ (Y)  (y)  217  249   25 ]  % 25
        [ (Z)  (z)  218  250   26 ]  % 26
        [ eci  eci  eci  eci  eci ]  % 27
        [  28   28   28   28  pad ]  % 28
        [  29   29   29   29  pad ]  % 29
        [  30   30   30   30   27 ]  % 30
        [  ns   ns   ns   ns   ns ]  % 31
        [ ( )  ({)  219  251   28 ]  % 32
        [ pad  pad  220  252   29 ]  % 33
        [ (")  (})  221  253   30 ]  % 34
        [ (#)  (~)  222  254   31 ]  % 35
        [ ($)  127  223  255  159 ]  % 36
        [ (%)  (;)  170  161  160 ]  % 37
        [ (&)  (<)  172  168  162 ]  % 38
        [ (')  (=)  177  171  163 ]  % 39
        [  40  (>)  178  175  164 ]  % 40
        [  41  (?)  179  176  165 ]  % 41
        [ (*)  ([)  181  180  166 ]  % 42
        [ (+)   92  185  183  167 ]  % 43
        [ (,)  (])  186  184  169 ]  % 44
        [ (-)  (^)  188  187  173 ]  % 45
        [ (.)  (_)  189  191  174 ]  % 46
        [ (/)  ( )  190  138  182 ]  % 47
        [ (0)  (,)  128  139  149 ]  % 48
        [ (1)  (.)  129  140  150 ]  % 49
        [ (2)  (/)  130  141  151 ]  % 50
        [ (3)  (:)  131  142  152 ]  % 51
        [ (4)  (@)  132  143  153 ]  % 52
        [ (5)  (!)  133  144  154 ]  % 53
        [ (6)  (|)  134  145  155 ]  % 54
        [ (7)  pd2  135  146  156 ]  % 55
        [ (8)  sa2  136  147  157 ]  % 56
        [ (9)  sa3  137  148  158 ]  % 57
        [ (:)  pd3   la   la   la ]  % 58
        [  sb   sa  ( )  ( )  ( ) ]  % 59
        [  sc   sc  lkc   sc   sc ]  % 60
        [  sd   sd   sd  lkd   sd ]  % 61
        [  se   se   se   se  lke ]  % 62
        [  lb   la   lb   lb   lb ]  % 63
    ] def

    % Invert charmaps to give character to value maps for each state
    /charvals [ 64 dict 64 dict 64 dict 64 dict 64 dict ] def
    0 1 charmaps length 1 sub {
        /i exch def
        /encs charmaps i get def
        0 1 4 {
            /j exch def
            encs j get dup type /stringtype eq {0 get} if  % convert string to ASCII if required
            charvals j get exch i put
        } for
    } for
    /seta charvals 0 get def
    /setb charvals 1 get def
    /setc charvals 2 get def
    /setd charvals 3 get def
    /sete charvals 4 get def
} ctxdef

    % Compute numeric runlengths
    /nseq [ msglen 1 add {0} repeat ] def
    msglen 1 sub -1 0 {
        /i exch def
        msg i get dup 48 ge exch 57 le and {
            nseq i nseq i 1 add get 1 add put
        } {
            nseq i 0 put
        } ifelse
    } for
    /nseq nseq 0 msglen getinterval def

    % Encode the message from ASCII to codewords
    /prefixinset {
        0 {
            2 copy exch length ge {exit} if
            2 copy get 3 index exch known {1 add} {exit} ifelse
        } loop
        exch pop exch pop
    } def

    /enc {
        exch get out exch j exch put
        /j j 1 add def
    } def

    /out 144 array def
    /i 0 def /j 0 def /cset (seta) def
    { % loop
        % Exit when no characters remain latching back to A if necessary
        i msglen eq {
            cset (seta) ne cset (setb) ne and {
                la cset load enc
                /cset (seta) def
            } if
            exit
        } if
        { % not a loop but common exit point
            % Immediately encode an ECI
            msg i get -1000000 le {
                eci cset load enc
                msg i get neg 1000000 sub
                    dup 000031 le {  % ECI 000000 - 000031
                                         63 and
                        1 array astore
                } { dup 001023 le {  % ECI 000032 - 001023
                        dup  -6 bitshift 31 and 32 or exch
                                         63 and
                        2 array astore
                } { dup 032767 le {  % ECI 001024 - 032767
                        dup -12 bitshift 47 and 48 or exch
                        dup  -6 bitshift 63 and       exch
                                         63 and
                        3 array astore
                } {                  % ECI 032768 - 999999
                        dup -18 bitshift 55 and 56 or exch
                        dup -12 bitshift 63 and       exch
                        dup  -6 bitshift 63 and       exch
                                         63 and
                        4 array astore
                } ifelse } ifelse } ifelse
                dup out exch j exch putinterval
                length j add /j exch def
                /i i 1 add def
                exit
            } if

            % If 9 numerals available then use NS
            nseq i get 9 ge {
                msg i 9 getinterval 0 exch {48 sub add 10 mul} forall 10 idiv
                4 { dup 63 and exch -6 bitshift } repeat cset load ns get
                0 2 10 {index} for 6 array astore 7 1 roll 6 {pop} repeat
                out exch j exch putinterval
                /i i 9 add def
                /j j 6 add def
                exit
            } if

            % Read next three characters
            /char1 msg i get def
            /char2 i 1 add msglen lt {msg i 1 add get} {-99} ifelse def
            /char3 i 2 add msglen lt {msg i 2 add get} {-99} ifelse def

            % If current mode is sufficient then directly encode
            cset load char1 known {
                char1 cset load enc
                /i i 1 add def
                exit
            } if

            % For switching from A to B
            cset (seta) eq setb char1 known and {
                setb char2 known {
                    lb seta enc
                    /cset (setb) def
                } {
                    sb seta enc
                    char1 setb enc
                    /i i 1 add def
                } ifelse
                exit
            } if

            % For switching from B to A encode according to length of prefix
            cset (setb) eq seta char1 known and {
                /p seta msg i 4 msglen i sub 2 copy gt {exch} if pop getinterval prefixinset def
                p 1 eq {
                    sa setb enc
                    char1 seta enc
                    /i i 1 add def
                } if
                p 2 eq {
                    sa2 setb enc
                    char1 seta enc
                    char2 seta enc
                    /i i 2 add def
                } if
                p 3 eq {
                    sa3 setb enc
                    char1 seta enc
                    char2 seta enc
                    char3 seta enc
                    /i i 3 add def
                } if
                p 4 ge {
                    la setb enc
                    /cset (seta) def
                } if
                exit
            } if

            % If character is in A or B then directly latch
            seta char1 known {
                la cset load enc
                /cset (seta) def
                exit
            } if
            setb char1 known {
                lb cset load enc
                /cset (setb) def
                exit
            } if

            % Determine which one of sets C, D or E the character is in
            setc char1 known {/setx (setc) def /sx sc def /lkx lkc def} if
            setd char1 known {/setx (setd) def /sx sd def /lkx lkd def} if
            sete char1 known {/setx (sete) def /sx se def /lkx lke def} if

            % Encode according to the length of the prefix
            /p setx load msg i 4 msglen i sub 2 copy gt {exch} if pop getinterval prefixinset def
            p 1 eq {
                sx cset load enc
                char1 setx load enc
                /i i 1 add def
            } if
            p 2 eq {
                sx cset load enc
                char1 setx load enc
                sx cset load enc
                char2 setx load enc
                /i i 2 add def
            } if
            p 3 eq {
                sx cset load enc
                char1 setx load enc
                sx cset load enc
                char2 setx load enc
                sx cset load enc
                char3 setx load enc
                /i i 3 add def
            } if
            p 4 ge {
                sx cset load enc
                lkx setx load enc
                /cset setx def
            } if

            exit
        } loop  % out
    } loop
    /encmsg out 0 j getinterval def
    /padval cset load pad get def

    % Prefix the encoded message with the structured append insert
    /sami [] def
    sam -1 ne {
        /sami 2 array def
        sami 0 seta pad get put
        sami 1 sam 10 idiv 1 sub 8 mul sam 10 mod 1 sub add put
    } if
    /encmsg [ sami aload pop encmsg aload pop ] def

    % Derive the primary and secondary codewords for modes 2 and 3
    mode 2 eq mode 3 eq or {

        % Calculate the fixed-width binary values for the mode, postcode, country code and service
        /mdb (0000) 4 string copy dup mode cvi 2 4 string cvrs dup length 4 exch sub exch putinterval def
        /ccb (0000000000) 10 string copy dup ccode cvi 2 10 string cvrs dup length 10 exch sub exch putinterval def
        /scb (0000000000) 10 string copy dup scode cvi 2 10 string cvrs dup length 10 exch sub exch putinterval def
        /pcb (000000000000000000000000000000000000) 36 string copy def
        mode 2 eq {
            % For numeric postcode, first six bits represent length and remaining 30 bits the value
            pcb pcode length 2 6 string cvrs dup length 6 exch sub exch putinterval
            pcb pcode cvi 2 30 string cvrs dup length 36 exch sub exch putinterval
        } {  % mode=3
            % For alphanumeric postcode, trim or pad with spaces to 6 chars and encode to binary
            /pccw [
                (      ) 6 string copy dup 0 pcode length 6 gt {pcode 0 6 getinterval} {pcode} ifelse putinterval
                {seta exch get} forall
            ] def
            0 1 5 {
                /i exch def
                pcb pccw i get 2 6 string cvrs dup length 6 i mul 6 add exch sub exch putinterval
            } for
        } ifelse

        % Convolute the binary values into the structured carrier message
        /scm 60 string def
        scm 2  mdb putinterval
        scm 38 pcb 0  4 getinterval putinterval
        scm 30 pcb 4  6 getinterval putinterval
        scm 24 pcb 10 6 getinterval putinterval
        scm 18 pcb 16 6 getinterval putinterval
        scm 12 pcb 22 6 getinterval putinterval
        scm 6  pcb 28 6 getinterval putinterval
        scm 0  pcb 34 2 getinterval putinterval
        scm 52 ccb 0  2 getinterval putinterval
        scm 42 ccb 2  6 getinterval putinterval
        scm 36 ccb 8  2 getinterval putinterval
        scm 54 scb 0  6 getinterval putinterval
        scm 48 scb 6  4 getinterval putinterval

        % Evaluate the structured carrier message as codewords
        /pri [ 0 0 0 0 0 0 0 0 0 0 ] def
        0 1 59 {
            /i exch def
            /ps i 6 idiv def
            /ep 2 5 i 6 mod sub exp cvi scm i get 48 sub mul def
            pri ps pri ps get ep add put
        } for

        % Pad the encoded message into the secondary component
        /sec [ 84 {padval} repeat ] def
        sec 0 encmsg putinterval

    } if

    % Derive the primary and secondary codewords for modes 4, 5 and 6
    mode 4 eq mode 5 eq or mode 6 eq or mode -1 eq or {

        % If mode isn't specified then use EEC if message fits, otherwise SEC
        mode -1 eq {
            /mode encmsg length 77 le {5} {4} ifelse def
        } if

        % First symbol is the mode and the remainder are the padded message
        /cws [ mode 5 eq {78} {94} ifelse {padval} repeat ] def
        cws 0 mode put
        cws 1 encmsg putinterval

        % Fit the message into the primary and secondary components
        /pri cws 0 10 getinterval def
        /sec cws 10 cws length 10 sub getinterval def

    } if

    % Calculate the log and anti-log tables
    /rsalog [ 1 63 { dup 2 mul dup 64 ge {67 xor} if } repeat ] def
    /rslog 64 array def
    1 1 63 {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 63 mod rsalog exch get
        } {
            pop pop 0
        } ifelse
    } def

    % Generate error correction codewords
    /rscodes {

        /rsnum exch def
        /cwb exch def

        % Generate the coefficients
        /coeffs [ 1 rsnum {0} repeat ] def
        1 1 rsnum {
            /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 xor put
            } for
            coeffs 0 coeffs 0 get rsalog i get rsprod put
        } for
        /coeffs coeffs 0 coeffs length 1 sub getinterval def

        % Calculate the error correction codewords
        /ecb [ rsnum {0} repeat ] def
        0 1 cwb length 1 sub {
            /t exch cwb exch get ecb 0 get xor def
            ecb length 1 sub -1 0 {
                /i exch def
                /p ecb length i sub 1 sub def
                ecb p t coeffs i get rsprod put
                i 0 gt { ecb p ecb p 1 add get ecb p get xor put } if
            } for
        } for

        ecb

    } def

    % Split secondary codeword into odd and even elements
    /seco [ 0 2 sec length 1 sub { sec exch get } for ] def
    /sece [ 1 2 sec length 1 sub { sec exch get } for ] def

    % Calculate the parity codewords for secondary codeword parts based on mode
    /scodes sec length 84 eq {20} {28} ifelse def  % SEC/EEC mode
    /secochk seco scodes rscodes def
    /secechk sece scodes rscodes def

    % Recompose the secondary parity codewords
    /secchk [ 0 1 scodes 1 sub { dup secochk exch get exch secechk exch get } for ] def

    % Concatenate the data into final codewords
    /codewords [
        pri aload pop
        pri 10 rscodes aload pop
        sec aload pop
        secchk aload pop
    ] def

    % Convert the codewords into module bits
    /mods [ 864 {0} repeat ] def
    0 1 143 {
        /i exch def
        /cw [ codewords i get 2 6 string cvrs {48 sub} forall ] def
        mods 6 i mul 6 cw length sub add cw putinterval
    } for

    % Maps modules to pixels in the grid
{
    /modmap [
        469 529 286 316 347 346 673 672 703 702 647 676 283 282 313 312 370 610 618 379
        378 409 408 439 705 704 559 589 588 619 458 518 640 701 675 674 285 284 315 314
        310 340 531 289 288 319 349 348 456 486 517 516 471 470 369 368 399 398 429 428
        549 548 579 578 609 608 649 648 679 678 709 708 639 638 669 668 699 698 279 278
        309 308 339 338 381 380 411 410 441 440 561 560 591 590 621 620 547 546 577 576
        607 606 367 366 397 396 427 426 291 290 321 320 351 350 651 650 681 680 711 710
        1   0   31  30  61  60  3   2   33  32  63  62  5   4   35  34  65  64  7   6
        37  36  67  66  9   8   39  38  69  68  11  10  41  40  71  70  13  12  43  42
        73  72  15  14  45  44  75  74  17  16  47  46  77  76  19  18  49  48  79  78
        21  20  51  50  81  80  23  22  53  52  83  82  25  24  55  54  85  84  27  26
        57  56  87  86  117 116 147 146 177 176 115 114 145 144 175 174 113 112 143 142
        173 172 111 110 141 140 171 170 109 108 139 138 169 168 107 106 137 136 167 166
        105 104 135 134 165 164 103 102 133 132 163 162 101 100 131 130 161 160 99  98
        129 128 159 158 97  96  127 126 157 156 95  94  125 124 155 154 93  92  123 122
        153 152 91  90  121 120 151 150 181 180 211 210 241 240 183 182 213 212 243 242
        185 184 215 214 245 244 187 186 217 216 247 246 189 188 219 218 249 248 191 190
        221 220 251 250 193 192 223 222 253 252 195 194 225 224 255 254 197 196 227 226
        257 256 199 198 229 228 259 258 201 200 231 230 261 260 203 202 233 232 263 262
        205 204 235 234 265 264 207 206 237 236 267 266 297 296 327 326 357 356 295 294
        325 324 355 354 293 292 323 322 353 352 277 276 307 306 337 336 275 274 305 304
        335 334 273 272 303 302 333 332 271 270 301 300 331 330 361 360 391 390 421 420
        363 362 393 392 423 422 365 364 395 394 425 424 383 382 413 412 443 442 385 384
        415 414 445 444 387 386 417 416 447 446 477 476 507 506 537 536 475 474 505 504
        535 534 473 472 503 502 533 532 455 454 485 484 515 514 453 452 483 482 513 512
        451 450 481 480 511 510 541 540 571 570 601 600 543 542 573 572 603 602 545 544
        575 574 605 604 563 562 593 592 623 622 565 564 595 594 625 624 567 566 597 596
        627 626 657 656 687 686 717 716 655 654 685 684 715 714 653 652 683 682 713 712
        637 636 667 666 697 696 635 634 665 664 695 694 633 632 663 662 693 692 631 630
        661 660 691 690 721 720 751 750 781 780 723 722 753 752 783 782 725 724 755 754
        785 784 727 726 757 756 787 786 729 728 759 758 789 788 731 730 761 760 791 790
        733 732 763 762 793 792 735 734 765 764 795 794 737 736 767 766 797 796 739 738
        769 768 799 798 741 740 771 770 801 800 743 742 773 772 803 802 745 744 775 774
        805 804 747 746 777 776 807 806 837 836 867 866 897 896 835 834 865 864 895 894
        833 832 863 862 893 892 831 830 861 860 891 890 829 828 859 858 889 888 827 826
        857 856 887 886 825 824 855 854 885 884 823 822 853 852 883 882 821 820 851 850
        881 880 819 818 849 848 879 878 817 816 847 846 877 876 815 814 845 844 875 874
        813 812 843 842 873 872 811 810 841 840 871 870 901 900 931 930 961 960 903 902
        933 932 963 962 905 904 935 934 965 964 907 906 937 936 967 966 909 908 939 938
        969 968 911 910 941 940 971 970 913 912 943 942 973 972 915 914 945 944 975 974
        917 916 947 946 977 976 919 918 949 948 979 978 921 920 951 950 981 980 923 922
        953 952 983 982 925 924 955 954 985 984 927 926 957 956 987 986 58  89  88  118
        149 148 178 209 208 238 269 268 298 329 328 358 389 388 418 449 448 478 509 508
        538 569 568 598 629 628 658 689 688 718 749 748 778 809 808 838 869 868 898 929
        928 958 989 988
    ] def
} ctxdef

    % Lookup pixels for enabled modules from modmap
    /pixs 864 array def
    /j 0 def
    0 1 mods length 1 sub {
        /i exch def
        mods i get 1 eq {
            pixs j modmap i get put
            /j j 1 add def
        } if
    } for
    /pixs [ pixs 0 j getinterval {} forall 28 29 280 281 311 457 488 500 530 670 700 677 707 ] def

    % Return the arguments
    <<
    /ren //renmaximatrix
    /pixs pixs
    /opt options
    >>

    dontdraw not //renmaximatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/maxicode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER maxicode--

% --BEGIN ENCODER azteccode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: Aztec Code
% --EXAM: This is Aztec Code
% --EXOP: format=full
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp azteccode 0.0 2022082100 189159 191319
%%BeginData:        794 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/azteccode {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /format (unset) def    % full, compact or rune
    /readerinit false def
    /layers -1 def
    /eclevel 23 def
    /ecaddchars 3 def
    /raw false def
    /parse false def
    /parsefnc 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

    /layers layers cvi def
    /eclevel eclevel cvr def
    /ecaddchars ecaddchars cvi def

    /azteccode //loadctx exec

    format (rune) eq {
        barcode length 0 eq {
            /bwipp.aztecRuneNotNumeric (Aztec runes must be numeric) //raiseerror exec
        } if
        barcode {
            dup 48 lt exch 57 gt or {
                /bwipp.aztecRuneNotNumeric (Aztec runes must be numeric) //raiseerror exec
            } if
        } forall
        barcode cvi dup 0 lt exch 255 gt or {
            /bwipp.aztecRuneInvalid (Aztec runes must be 0 to 255) //raiseerror exec
        } if
    } if

    % Parse the input
    /fn1 -1 def
    /fncvals <<
        /parse parse
        /parsefnc parsefnc
        /eci true
        (FNC1) fn1
    >> def
    /msg barcode fncvals //parseinput exec def
    /msglen msg length def

{
    % State key: "U"pper, "L"ower, "M"ixed, "P"unctuation, "D"igit, "B"inary
    /U 0 def  /L 1 def  /M 2 def  /P 3 def  /D 4 def  /B 5 def

    % Special function characters
    /lu -2 def  /ll -3 def  /lm -4 def
    /lp -5 def  /ld -6 def  /su -7 def
    /sp -8 def  /sb -9 def  /fl -10 def
    /p2 -11 def /p3 -12 def /p4 -13 def /p5 -14 def

    % Character maps for each state
    /charmaps [
        %  U    L    M    P    D
        [  sp   sp   sp   fl   sp ]  % 0
        [  32   32   32   13   32 ]  % 1
        [ (A)  (a)    1   p2  (0) ]  % 2     p2 = CR LF
        [ (B)  (b)    2   p3  (1) ]  % 3     p3 = ". "
        [ (C)  (c)    3   p4  (2) ]  % 4     p4 = ", "
        [ (D)  (d)    4   p5  (3) ]  % 5     p5 = ": "
        [ (E)  (e)    5  (!)  (4) ]  % 6
        [ (F)  (f)    6  (")  (5) ]  % 7
        [ (G)  (g)    7  (#)  (6) ]  % 8
        [ (H)  (h)    8  ($)  (7) ]  % 9
        [ (I)  (i)    9  (%)  (8) ]  % 10
        [ (J)  (j)   10  (&)  (9) ]  % 11
        [ (K)  (k)   11  (')  (,) ]  % 12
        [ (L)  (l)   12   40  (.) ]  % 13
        [ (M)  (m)   13   41   lu ]  % 14
        [ (N)  (n)   27  (*)   su ]  % 15
        [ (O)  (o)   28  (+)  -99 ]  % 16
        [ (P)  (p)   29  (,)  -99 ]  % 17
        [ (Q)  (q)   30  (-)  -99 ]  % 18
        [ (R)  (r)   31  (.)  -99 ]  % 19
        [ (S)  (s)  (@)  (/)  -99 ]  % 20
        [ (T)  (t)   92  (:)  -99 ]  % 21
        [ (U)  (u)  (^)  (;)  -99 ]  % 22
        [ (V)  (v)  (_)  (<)  -99 ]  % 23
        [ (W)  (w)  (`)  (=)  -99 ]  % 24
        [ (X)  (x)  (|)  (>)  -99 ]  % 25
        [ (Y)  (y)  (~)  (?)  -99 ]  % 26
        [ (Z)  (z)  127  ([)  -99 ]  % 27
        [  ll   su   ll  (])  -99 ]  % 28
        [  lm   lm   lu  ({)  -99 ]  % 29
        [  ld   ld   lp  (})  -99 ]  % 30
        [  sb   sb   sb   lu  -99 ]  % 31
    ] def

    % Invert charmaps to give character to value maps for each state
    /charvals [ 32 dict 32 dict 32 dict 32 dict 16 dict ] def
    0 1 charmaps length 1 sub {
        /i exch def
        /encs charmaps i get def
        0 1 4 {
            /j exch def
            encs j get dup type /stringtype eq {0 get} if  % convert string to ASCII if required
            charvals j get exch i put
        } for
    } for

    % Punctuation compression
    /pcomp <<
        <0d0a> p2   % CR LF
        (. )   p3
        (, )   p4
        (: )   p5
    >> def

    /e 10000 def  % "Empty"

    /latlen [  % Bit length of latch between states
    % To:  U  L  M  P  D  B      From
        [  0  5  5 10  5 10 ]  % U
        [  9  0  5 10  5 10 ]  % L
        [  5  5  0  5 10 10 ]  % M
        [  5 10 10  0 10 15 ]  % P
        [  4  9  9 14  0 14 ]  % D
        [  0  0  0  0  0  0 ]  % B
    ] def

    /latseq [  % Latch sequences between states
    % To: U       L       M       P          D       B          From
        [ []      [ll]    [lm]    [lm lp]    [ld]    [sb]    ]  % U
        [ [ld lu] []      [lm]    [lm lp]    [ld]    [sb]    ]  % L
        [ [lu]    [ll]    []      [lp]       [lu ld] [sb]    ]  % M
        [ [lu]    [lu ll] [lu lm] []         [lu ld] [lu sb] ]  % P
        [ [lu]    [lu ll] [lu lm] [lu lm lp] []      [lu sb] ]  % D
        [ [lu]    [ll]    [lm]    []         []      []      ]  % B
    ] def

    /shftlen [  % Bit length of shift to state
    % To:  U  L  M  P  D      From
        [  e  e  e  5  e ]  % U
        [  5  e  e  5  e ]  % L
        [  e  e  e  5  e ]  % M
        [  e  e  e  e  e ]  % P
        [  4  e  e  4  e ]  % D
    ] def

} ctxdef

    % Convert from input into message bitstream
    /msgbits () def
    format (rune) ne raw and {/msgbits barcode def} if
    format (rune) ne raw not and {

        /charsize {
            dup 0 ge {
                %      U   L   M   P   D   B
                pop [  5   5   5   5   4   8 ] exch get
            } {  % FNC or ECI in P
                exch pop
                dup fn1 eq {  % FNC1: PS{Flg(0)} + 3
                    pop 8
                } {  % ECI: PS{Flg(n)} + 3 + 4n
                    neg 1000000 sub dup 0 eq {pop 1} if
                    ln 10 ln div cvi 1 add 4 mul 8 add
                } ifelse
            } ifelse
        } def

        %          U  L  M  P  D  B
        /curlen [  0  e  e  e  e  e ] def
        /curseq [ [] [] [] [] [] [] ] def

        /backto U def  % U
        /lastchar () def

        % Derive the optimal sequences ending in each state
        msg {

            /char exch def

            % Check for optimisations in the current sequences by latching from x to y
            {  % loop
                /imp false def
                [ U L M P D B ] {
                    /x exch def
                    [ U L M P D B ] {
                        /y exch def
                        x B ne y backto eq or {  % Only B -> backto
                            /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
                                y B eq {  % Set backto to previous state
                                    /backto x P eq x D eq or {U} {x} ifelse def
                                } if
                                /imp true def
                            } if
                        } 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 e e ] def
            /nxtseq 6 array def

            [ U L M P D B ] {
                /x exch def

                { % loop for common exit

                    % Skip states that cannot encode character
                    char 0 ge {
                        x B ne {charvals x get char known not {exit} if} if
                    } {
                        x P ne {exit} if  % Only P can encode FNC1 and ECI
                    } ifelse

                    % Extend directly
                    /cost curlen x get x char charsize 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
                    x B eq {exit} if  % B is treated as a latch
                    [ U L M P D ] {
                        /y exch def
                        x y ne {
                            /cost curlen y get shftlen y get x get add x char charsize add def
                            cost nxtlen y get lt {
                                nxtlen y cost put
                                nxtseq y [
                                    curseq y get aload pop
                                    x U eq {su} {sp} ifelse
                                    char
                                ] put
                            } if
                        } if
                    } forall

                    exit
                } loop

            } forall

            % Optimise using P compression
            lastchar () ne char 0 ge and {
                /pchars 2 string dup 0 lastchar put dup 1 char put def
                pcomp pchars known {
                    [ U L M P D ] {
                        /i exch def
                        /inP true def  % U and L can't encode CR, comma, dot or colon
                        i M eq {  % M can encode CR
                            lastchar 13 eq { /inP false def } if
                        } {
                            i D eq {  % D can encode comma and dot
                                lastchar 44 eq lastchar 46 eq or { /inP false def } if
                            } if
                        } ifelse
                        inP curlen i get nxtlen i get lt and {
                            /curseqi curseq i get def
                            /lastld false def
                            /lastsp false def
                            /lastidx -1 def
                            curseqi length 1 sub -1 0 {  % Search backwards for lastchar
                                /idx exch def
                                /ch curseqi idx get def
                                lastidx -1 eq {
                                    ch lastchar eq {
                                        /lastidx idx def
                                        idx 0 gt {
                                            curseqi idx 1 sub get sp eq { /lastsp true def } if  % Preceded by P/S
                                        } if
                                    } if
                                } {  % Found lastchar, check latch
                                    ch 0 lt ch ld ge and {  % If have latch
                                        i P eq {
                                            ch ld eq { /lastld true def } if  % Set flag if D/L for adjustment below
                                        } {
                                            ch lp ne { /inP lastsp def } if  % If not P/L only in P if have P/S
                                        } ifelse
                                        exit
                                    } if
                                } ifelse
                            } for
                            inP lastidx 0 ge and {
                                nxtlen i curlen i get put
                                lastidx curseqi length 1 sub lt {  % If lastchar not at end of sequence
                                    i P eq {
                                        lastld { nxtlen i nxtlen i get 1 add put } if  % Adjust count if D/L
                                        % Move lastchar to end and replace
                                        nxtseq i [ curseqi aload pop curseqi length lastidx sub -1 roll pop pcomp pchars get ] put
                                    } {
                                        % Replace lastchar in situ
                                        nxtseq i [ curseqi aload pop ] put
                                        nxtseq i get lastidx pcomp pchars get put
                                    } ifelse
                                } {
                                    nxtseq i [ curseqi aload pop pop pcomp pchars get ] put
                                } ifelse
                            } if
                        } if
                    } forall
                } if
            } if

            % Account for binary extension for 32 or more bytes
            nxtseq B get null ne {
                /numbytes 0 def
                nxtseq B get {
                    sb eq {0} {numbytes 1 add} ifelse /numbytes exch def
                } forall
                numbytes 32 eq {nxtlen B nxtlen B get 11 add put} if
            } if

            /curlen nxtlen def
            /curseq nxtseq def
            /lastchar char 0 ge {char} {()} ifelse def

        } forall

        % Select the optimal sequence
        /minseq e def
        [ U L M P D B ] {
            /i exch def
            curlen i get minseq lt {
                /minseq curlen i get def
                /seq curseq i get def
            } if
        } forall

        % Encoding functions
        /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

        /encu {charvals U get exch get 5 tobin} def
        /encl {charvals L get exch get 5 tobin} def
        /encm {charvals M get exch get 5 tobin} def
        /encd {charvals D get exch get 4 tobin} def

        /encp {
            dup fn1 eq {  % FNC1: Flg(0)
                pop (00000000)
            } {
            dup -1000000 le {  % ECI: Flg(n) + n-Digits
                neg 1000000 sub dup dup 0 eq {pop 1} if
                ln 10 ln div cvi
                dup 1 add 4 mul 8 add string
                dup 0 (00000) putinterval  % Flg(n)
                dup 2 index 1 add 3 tobin 5 exch putinterval  % len
                3 1 roll -1 0 {  % ECI digits in "Digit" encoding
                    4 mul 8 add exch
                    dup 10 idiv 3 index 4 2 roll
                    10 mod 2 add 4 tobin putinterval
                } for
                pop
            } {
                charvals P get exch get 5 tobin
            } ifelse } ifelse
        } def

        /encfuncs [ /encu /encl /encm /encp /encd ] def

        /addtomsgbits {
            /v exch def
            msgbits j v putinterval
            /j j v length add def
        } def

        % Encode the sequence
        /state U def
        /msgbits minseq string def
        /i 0 def /j 0 def {
            i seq length ge {exit} if

            state B ne {

                /char seq i get def

                % Encode character
                char encfuncs state get load exec addtomsgbits
                /i i 1 add def

                % Encode shifted next character
                char su eq char sp eq or {
                    seq i get char su eq {encu} {encp} ifelse addtomsgbits
                    /i i 1 add def
                } if

                % Latches to new state
                char lu eq {/state U def} if
                char ll eq {/state L def} if
                char lm eq {/state M def} if
                char lp eq {/state P def} if
                char ld eq {/state D def} if
                char sb eq {/state B def} if

            } {  % Binary

                % Find number of bytes before latch or end
                /numbytes 0 def {
                    i numbytes add seq length ge {exit} if
                    seq i numbytes add get 0 lt {exit} if
                    /numbytes numbytes 1 add def
                } loop

                % Encode length
                numbytes 31 le {
                    numbytes 5 tobin addtomsgbits
                } {
                    0 5 tobin addtomsgbits
                    numbytes 31 sub 11 tobin addtomsgbits
                } ifelse

                % Encode bytes
                numbytes {
                    seq i get 8 tobin addtomsgbits
                    /i i 1 add def
                } repeat

                % Return to previous state as indicated
                i seq length lt {
                    /char seq i get def
                    /i i 1 add def
                    char lu eq {/state U def} if
                    char ll eq {/state L def} if
                    char lm eq {/state M def} if
                } if

            } ifelse

        } loop

    } if

    % Lookup the most appropriate symbol specification
{
    /metrics [
        [ (rune)     0 0    0  6 ]  % Special metric for rune symbols
        [ (compact)  1 1   17  6 ] [ (full)     1 1   21  6 ] [ (compact)  2 0   40  6 ]
        [ (full)     2 1   48  6 ] [ (compact)  3 0   51  8 ] [ (full)     3 1   60  8 ]
        [ (compact)  4 0   76  8 ] [ (full)     4 1   88  8 ] [ (full)     5 1  120  8 ]
        [ (full)     6 1  156  8 ] [ (full)     7 1  196  8 ] [ (full)     8 1  240  8 ]
        [ (full)     9 1  230 10 ] [ (full)    10 1  272 10 ] [ (full)    11 1  316 10 ]
        [ (full)    12 1  364 10 ] [ (full)    13 1  416 10 ] [ (full)    14 1  470 10 ]
        [ (full)    15 1  528 10 ] [ (full)    16 1  588 10 ] [ (full)    17 1  652 10 ]
        [ (full)    18 1  720 10 ] [ (full)    19 1  790 10 ] [ (full)    20 1  864 10 ]
        [ (full)    21 1  940 10 ] [ (full)    22 1 1020 10 ] [ (full)    23 0  920 12 ]
        [ (full)    24 0  992 12 ] [ (full)    25 0 1066 12 ] [ (full)    26 0 1144 12 ]
        [ (full)    27 0 1224 12 ] [ (full)    28 0 1306 12 ] [ (full)    29 0 1392 12 ]
        [ (full)    30 0 1480 12 ] [ (full)    31 0 1570 12 ] [ (full)    32 0 1664 12 ]
    ] def
} ctxdef

    /i 0 def
    { % loop
        /m metrics i get def
        /frmt m 0 get def                          % Format of the symbol
        /mlyr m 1 get def                          % Data layers
        /icap m 2 get def                          % Reader initialisation capable
        /ncws m 3 get def                          % Total of codewords
        /bpcw m 4 get def                          % Bits per codeword
        /numecw ncws eclevel mul 100 div ecaddchars add ceiling cvi def
        msgbits length 0 eq {/numecw 0 def} if     % Error correction codewords
        /numdcw ncws numecw sub def                % Data codewords
        /okay true def
        format (unset) ne format frmt ne and {/okay false def} if
        readerinit icap 1 ne and {/okay false def} if
        layers -1 ne layers mlyr ne and {/okay false def} if
        msgbits length bpcw div ceiling cvi numdcw gt {/okay false def} if
        okay {exit} if
        /i i 1 add def
    } loop
    /layers mlyr def
    /format frmt def

    % Expand message bits into codewords avoiding codewords with all zeros or all ones
    /allzero {dup length (000000000000) 0 3 -1 roll getinterval eq} def
    /allones {dup length (111111111111) 0 3 -1 roll getinterval eq} def
    /cws ncws array def
    /m 0 def /c 0 def
    {
        msgbits length m le {exit} if
        msgbits length m sub bpcw ge {
            /cwb msgbits m bpcw 1 sub getinterval def        % All but last bit
            /cwf msgbits m bpcw add 1 sub 1 getinterval def  % Last bit
            cwb allzero {/cwf (1) def /m m 1 sub def} if     % Flip last bit to avoid zeros
            cwb allones {/cwf (0) def /m m 1 sub def} if     % Flip last bit to avoid ones
            % Concatenate the bits
            12 string dup 0 cwb putinterval
            dup bpcw 1 sub cwf putinterval
            0 bpcw getinterval
            /cwb exch def
        } {  %  Final codeword
            /cwb msgbits m msgbits length m sub getinterval def
            /cwb (111111111111) 12 string copy dup 0 cwb putinterval 0 bpcw getinterval def
            cwb allones {cwb cwb length 1 sub (0) putinterval} if  % Prevent all ones
        } ifelse
        % Conversion of binary data into byte array
        /cw 0 def
        0 1 bpcw 1 sub {
            /i exch def
            /cw cw 2 bpcw i sub 1 sub exp cvi cwb i get 48 sub mul add def
        } for
        cws c cw put
        /m m bpcw add def
        /c c 1 add def
    } loop
    /cws cws 0 c getinterval def

    options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if

    % Reed-Solomon algorithm
    /rscodes {

        /rspm exch def
        /rsgf exch def
        /rsnc exch def
        /rscws exch def

        % Calculate the log and anti-log tables
        /rsalog [ 1 rsgf 1 sub { dup 2 mul dup rsgf ge {rspm xor} if } repeat ] def
        /rslog rsgf array def
        1 1 rsgf 1 sub {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 rsgf 1 sub mod rsalog exch get
            } {
                pop pop 0
            } ifelse
        } def

        % Generate the coefficients
        /coeffs [ 1 rsnc {0} repeat ] def
        1 1 rsnc {
            /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 xor put
            } for
            coeffs 0 coeffs 0 get rsalog i get rsprod put
        } for

        % Extend the input with the error correction values
        /nd rscws length def
        /rscws [ rscws {} forall rsnc {0} repeat 0 ] def
        0 1 nd 1 sub {
            /k exch rscws exch get rscws nd get xor def
            0 1 rsnc 1 sub {
                /j exch def
                rscws nd j add rscws nd j add 1 add get k coeffs rsnc j sub 1 sub get rsprod xor put
            } for
        } for

        % Return all but the last codeword
        rscws 0 rscws length 1 sub getinterval

    } def

    % Create the codewords and bit string for the mode
    format (full) eq {
        /mode layers 1 sub 11 bitshift cws length 1 sub add def
        readerinit {/mode mode 2#0000010000000000 or def} if
        /mode [
            mode 2#1111000000000000 and -12 bitshift
            mode 2#0000111100000000 and -8 bitshift
            mode 2#0000000011110000 and -4 bitshift
            mode 2#0000000000001111 and
        ] def
        /mode mode 6 16 19 rscodes def
    } if
    format (compact) eq {
        /mode layers 1 sub 6 bitshift cws length 1 sub add def
        readerinit {/mode mode 2#00100000 or def} if
        /mode [
            mode 2#11110000 and -4 bitshift
            mode 2#00001111 and
        ] def
        /mode mode 5 16 19 rscodes def
    } if
    format (rune) eq {
        /mode barcode cvi def
        /mode [
            mode 2#11110000 and -4 bitshift
            mode 2#00001111 and
        ] def
        /mode mode 5 16 19 rscodes def
        /mode [mode {2#1010 xor} forall] def  % Invert alternate bits
    } if
    /modebits mode length 4 mul string def
    0 1 modebits length 1 sub {modebits exch (0) putinterval} for
    0 1 mode length 1 sub {
        /i exch def
        modebits mode i get 2 4 string cvrs dup length 4 exch sub 4 i mul add exch putinterval
    } for

    % Extend the data codewords with error correction codewords to create the bit string for the data
{
    /rsparams [
        [] [] [] [] [] []
        [ 64 67 ]      % 6-bit codewords
        []
        [ 256 301 ]    % 8-bit codewords
        []
        [ 1024 1033 ]  % 10-bit codewords
        []
        [ 4096 4201 ]  % 12-bit codewords
    ] def
} ctxdef
    /cws cws ncws cws length sub rsparams bpcw get {} forall rscodes def
    format (full) eq {
        /databits layers layers mul 16 mul layers 112 mul add string def
    } {
        /databits layers layers mul 16 mul layers 88 mul add string def
    } ifelse
    0 1 databits length 1 sub {databits exch (0) putinterval} for
    0 1 ncws 1 sub {
        /i exch def
        databits cws i get 2 bpcw string cvrs
        dup length bpcw exch sub bpcw i mul add databits length ncws bpcw mul sub add
        exch putinterval
    } for

    % Move to a point in the cartesian plane centered on the bullseye
    /cmv {size mul sub mid add} def

    % Move to a bit position within a layer
    /lmv {
        /lbit exch def
        /llyr exch def
        /lwid fw llyr 4 mul add def
        /ldir lbit 2 idiv lwid idiv def
        ldir 0 eq {  % Top
            lwid 1 sub 2 idiv neg 1 add lbit 2 idiv lwid mod add
            fw 1 sub 2 idiv llyr 2 mul add lbit 2 mod add
            cmv
        } if
        ldir 1 eq {  % Right
            fw 2 idiv llyr 2 mul add lbit 2 mod add
            lwid 1 sub 2 idiv 1 sub lbit 2 idiv lwid mod sub
            cmv
        } if
        ldir 2 eq {  % Bottom
            lwid 2 idiv neg 1 add lbit 2 idiv lwid mod add neg
            fw 2 idiv llyr 2 mul add lbit 2 mod add neg
            cmv
        } if
        ldir 3 eq {  % Left
            fw 1 sub 2 idiv llyr 2 mul add lbit 2 mod add neg
            lwid 2 idiv 1 sub lbit 2 idiv lwid mod sub neg
            cmv
        } if
    } def

    % Create the pixel map
    % For full symbols we disregard the reference grid at this stage
    format (full) eq {/fw 12 def} {/fw 9 def} ifelse
    /size fw layers 4 mul add 2 add def
    /pixs [size size mul {-1} repeat] def
    /mid size 1 sub 2 idiv size mul size 1 sub 2 idiv add def

    % Data layers
    /i 0 def
    1 1 layers {
        /layer exch def
        0 1 fw layer 4 mul add 8 mul 1 sub {
            /pos exch def
            pixs layer pos lmv databits databits length i sub 1 sub get 48 sub put
            /i i 1 add def
        } for
    } for

    % For full symbols expand the pixel map by inserting the reference grid
    format (full) eq {
        /fw 13 def
        /size fw layers 4 mul add 2 add layers 10.5 add 7.5 div 1 sub cvi 2 mul add def
        /mid size size mul 2 idiv def
        /npixs [size size mul {-2} repeat] def
        0 16 size 2 idiv {
            /i exch def
            0 1 size 1 sub {
                /j exch def
                npixs size 2 idiv neg j add i cmv     [size 2 idiv j add i add 1 add 2 mod] putinterval
                npixs size 2 idiv neg j add i neg cmv [size 2 idiv j add i add 1 add 2 mod] putinterval
                npixs i size 2 idiv neg j add cmv     [size 2 idiv j add i add 1 add 2 mod] putinterval
                npixs i neg size 2 idiv neg j add cmv [size 2 idiv j add i add 1 add 2 mod] putinterval
            } for
        } for
        /j 0 def
        0 1 npixs length 1 sub {
            /i exch def
            npixs i get -2 eq {
                npixs i pixs j get put
                /j j 1 add def
            } if
        } for
        /pixs npixs def
    } if

    % Finder pattern
    /fw fw 2 idiv def
    fw neg 1 fw {
        /i exch def
        fw neg 1 fw {
            /j exch def
            pixs i j cmv
            i abs j abs gt {i abs} {j abs} ifelse 1 add 2 mod
            put
        } for
    } for

    % Orientation bits
    [ [ fw 1 add neg   fw             1 ] [ fw 1 add neg   fw 1 add       1 ]
      [ fw neg         fw 1 add       1 ] [ fw 1 add       fw 1 add       1 ]
      [ fw 1 add       fw             1 ] [ fw 1 add       fw neg         1 ]
      [ fw             fw 1 add       0 ] [ fw 1 add       fw 1 add neg   0 ]
      [ fw             fw 1 add neg   0 ] [ fw neg         fw 1 add neg   0 ]
      [ fw 1 add neg   fw 1 add neg   0 ] [ fw 1 add neg   fw neg         0 ]
    ] {pixs exch {} forall 3 1 roll cmv exch put} forall

    % Mode ring
{
    /modemapfull [
        [-5  7] [-4  7] [-3  7] [-2  7] [-1  7] [ 1  7] [ 2  7] [ 3  7] [ 4  7] [ 5  7]
        [ 7  5] [ 7  4] [ 7  3] [ 7  2] [ 7  1] [ 7 -1] [ 7 -2] [ 7 -3] [ 7 -4] [ 7 -5]
        [ 5 -7] [ 4 -7] [ 3 -7] [ 2 -7] [ 1 -7] [-1 -7] [-2 -7] [-3 -7] [-4 -7] [-5 -7]
        [-7 -5] [-7 -4] [-7 -3] [-7 -2] [-7 -1] [-7  1] [-7  2] [-7  3] [-7  4] [-7  5]
    ] def
    /modemapcompact [
        [-3  5] [-2  5] [-1  5] [ 0  5] [ 1  5] [ 2  5] [ 3  5]
        [ 5  3] [ 5  2] [ 5  1] [ 5  0] [ 5 -1] [ 5 -2] [ 5 -3]
        [ 3 -5] [ 2 -5] [ 1 -5] [ 0 -5] [-1 -5] [-2 -5] [-3 -5]
        [-5 -3] [-5 -2] [-5 -1] [-5  0] [-5  1] [-5  2] [-5  3]
    ] def
} ctxdef
    /modemap format (full) eq {modemapfull} {modemapcompact} ifelse def
    0 1 modemap length 1 sub {
        /i exch def
        pixs modemap i get {} forall cmv modebits i get 48 sub put
    } for

    <<
    /ren //renmatrix
    /pixs pixs
    /pixx size
    /pixy size
    /height size 2 mul 72 div
    /width size 2 mul 72 div
    /opt options
    >>

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/azteccode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER azteccode--

% --BEGIN ENCODER azteccodecompact--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix azteccode--
% --DESC: Compact Aztec Code
% --EXAM: 1234
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp azteccodecompact 0.0 2022082100 62569 62441
%%BeginData:         46 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /azteccode dup /uk.co.terryburton.bwipp findresource put
begin
/azteccodecompact {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw 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

    % Get the result of encoding with azteccode with format=compact
    options (dontdraw) true put
    options (format) (compact) put

    /args barcode options //azteccode exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/azteccodecompact dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER azteccodecompact--

% --BEGIN ENCODER aztecrune--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix azteccode--
% --DESC: Aztec Runes
% --EXAM: 1
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp aztecrune 0.0 2022082100 62538 62417
%%BeginData:         46 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /azteccode dup /uk.co.terryburton.bwipp findresource put
begin
/aztecrune {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw 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

    % Get the result of encoding with azteccode with format=rune
    options (dontdraw) true put
    options (format) (rune) put

    /args barcode options //azteccode exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/aztecrune dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER aztecrune--

% --BEGIN ENCODER codeone--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: Code One
% --EXAM: Code One
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp codeone 0.0 2022082100 201282 203168
%%BeginData:        903 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/codeone {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /version (unset) def
    /parse false def
    /parsefnc 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

    /codeone //loadctx exec

    /stype version 0 1 getinterval (S) eq def

{
    /stypevals [
        (1)
        (1010)
        (1100100)
        (1111101000)
        (10011100010000)
        (11000011010100000)
        (11110100001001000000)
        (100110001001011010000000)
        (101111101011110000100000000)
        (111011100110101100101000000000)
        (1001010100000010111110010000000000)
        (1011101001000011101101110100000000000)
        (1110100011010100101001010001000000000000)
        (10010001100001001110011100101010000000000000)
        (10110101111001100010000011110100100000000000000)
        (11100011010111111010100100110001101000000000000000)
        (100011100001101111001001101111110000010000000000000000)
        (101100011010001010111100001011101100010100000000000000000)
    ] def

    % Basic metrics for the each symbol
    %     ver    row col dcol dcws rscw rsbl  ro ri rl
    /stypemetrics [
        [ (S-10)   8  11   10    4    4    1  99 99 99 ]
        [ (S-20)   8  21   20    8    8    1  99 99 99 ]
        [ (S-30)   8  31   30   12   12    1  99 99 99 ]
    ] def

    % Basic metrics for the each symbol
    %     ver    row col dcol dcws rscw rsbl  ro ri rl
    /nonstypemetrics [
        [ (A)     16  18   16   10   10    1   4 99  6 ]
        [ (B)     22  22   20   19   16    1   4 99  8 ]
        [ (C)     28  32   28   44   26    1   4 22 11 ]
        [ (D)     40  42   36   91   44    1   4 16 16 ]
        [ (E)     52  54   48  182   70    1   4 22 22 ]
        [ (F)     70  76   68  370  140    2   4 22 31 ]
        [ (G)    104  98   88  732  280    4   6 21 47 ]
        [ (H)    148 134  120 1480  560    8   6 20 69 ]
        [ (T-16)  16  17   16   10   10    1  99 99 99 ]
        [ (T-32)  16  33   32   24   16    1  99 99 99 ]
        [ (T-48)  16  49   48   38   22    1  99 99 99 ]
    ] def

    % Special characters
    /fnc1 -1 def  /fnc3 -2 def
    /lC    -5 def  /lB    -6 def  /lX    -7 def  /lT    -8 def  /lD    -9 def  /unl -10 def
    /fnc2 -11 def  /fnc4 -12 def  /sft1 -13 def  /sft2 -14 def  /sft3 -15 def  /eci -16 def  /pad -17 def  /fnc1lD -18 def
    /unlcw 255 def

    /Avals <<
        0 1 128 {dup 1 add} for
        pad 129
        0 1 99 {  % Double digits
            dup 10 2 string cvrs (00) 2 string copy dup 2 3 index length sub 4 -1 roll putinterval
            exch 130 add
        } for
        229 [ lC lB fnc1 fnc2 fnc3 fnc4 fnc1lD ] {exch 1 add dup} forall pop
        lX 238
        lT 239
        % 240-255 lD + 4 bits
    >> def
    /Avals <<
        Avals {[exch]} forall
    >> def

    /CNvals <<
        sft1 0
        sft2 1
        sft3 2
        32   3
        48 1 57 {dup 44 sub} for  % 0-9
        65 1 90 {dup 51 sub} for  % A-Z
    >> def
    /C1vals << 0 1 31 {dup} for >> def
    /C2vals <<
        33 1 47 {dup 33 sub} for
        58 1 64 {dup 43 sub} for
        91 1 95 {dup 69 sub} for
        fnc1 27
        fnc2 28
        fnc3 29
        fnc4 30
        pad  31
    >> def
    /C3vals << 96 1 127 {dup 96 sub} for >> def
    /Cvals <<
        CNvals {[exch]} forall
        C1vals {[exch CNvals sft1 get exch]} forall
        C2vals {[exch CNvals sft2 get exch]} forall
        C3vals {[exch CNvals sft3 get exch]} forall
    >> def

    /TNvals <<
        sft1 0
        sft2 1
        sft3 2
        32   3
        48 1  57 {dup 44 sub} for  % 0-9
        97 1 122 {dup 83 sub} for  % a-z
    >> def
    /T1vals << 0 1 31 {dup} for >> def
    /T2vals <<
        33 1 47 {dup 33 sub} for
        58 1 64 {dup 43 sub} for
        91 1 95 {dup 69 sub} for
        fnc1 27
        fnc2 28
        fnc3 29
        fnc4 30
        pad  31
    >> def
    /T3vals <<
         96 0
         65 1  90 {dup 64 sub} for
        123 1 127 {dup 96 sub} for
    >> def
    /Tvals <<
        TNvals {[exch]} forall
        T1vals {[exch TNvals sft1 get exch]} forall
        T2vals {[exch TNvals sft2 get exch]} forall
        T3vals {[exch TNvals sft3 get exch]} forall
    >> def

    % Extended ASCII mappings
    128 1 255 {
        /i exch def
        Avals i [ Avals fnc4 get aload pop Avals i 128 sub get aload pop ] put
        Cvals i [ Cvals fnc4 get aload pop Cvals i 128 sub get aload pop ] put
        Tvals i [ Tvals fnc4 get aload pop Tvals i 128 sub get aload pop ] put
    } for

    /Xvals <<
        13 0
        42 1
        62 2
        32 3
        48 1 57 {dup 44 sub} for
        65 1 90 {dup 51 sub} for
    >> def
    /Xvals <<
        Xvals {[exch]} forall
    >> def

    /Bvals <<
        0 1 255 {dup} for
    >> def
    /Bvals <<
        Bvals {[exch]} forall
    >> def

    /encvals [ Avals Cvals Tvals Xvals -1 Bvals ] def

    /A 0 def  /C 1 def  /T 2 def  /X 3 def  /D 4 def  /B 5 def
} ctxdef

    stype {

        /normalize {
            /base exch def
            /num exch def
            num length 1 sub -1 1 {
                /i exch def
                num i 1 sub 2 copy get num i get base idiv add put
                num i num i get base mod put
            } for
            { %loop - extend input as necessary
                num 0 get base lt {exit} if
                /num [0 num {} forall] def
                num 0 num 0 get num 1 get base idiv add put
                num 1 num 1 get base mod put
            } loop
            % Trim leading zeros
            /num [/i true def num {dup 0 eq i and {pop} {/i false def} ifelse} forall] def
            num length 0 eq {/num [0] def} if
            num
        } def

        /bigadd {
            2 copy length exch length
            2 copy sub abs /offset exch def
            lt {exch} if
            /a exch def /b exch def
            0 1 b length 1 sub {
                dup a exch offset add 2 copy get b 5 -1 roll get add put
            } for
            a
        } def

        /barlen barcode length def

        % Convert value plus one to binary
        /v [ 1 ] def
        0 1 barlen 1 sub {
            /i exch def
            [ stypevals i get {48 sub barcode barlen i sub 1 sub get 48 sub mul} forall ]
            v bigadd /v exch def
        } for
        /v v 2 normalize def

        % Split into 5-bit codewords
        /v [ 5 v length 5 mod sub 5 mod {0} repeat v aload pop ] def
        /cws v length 5 idiv array def
        0 1 cws length 1 sub {
            /i exch def
            v i 5 mul 5 getinterval
            0 exch {add 2 mul} forall 2 idiv
            cws exch i exch put
        } for

        /metrics stypemetrics def

    } {  % Standard and type-T

        % Convert input into bytes accounting for FNC characters
        /fncvals <<
            /parse parse
            /parsefnc parsefnc
            /eci true
            (FNC1) fnc1
            (FNC3) fnc3
        >> def
        /msg barcode fncvals //parseinput exec def
        /msglen msg length def

        % Code One stores ECIs in data
        /eciesc 16#5c def  % We choose \ as a typical default
        /numecis 0 msg { -1000000 le {1 add} if } forall def
        numecis 0 gt {
            /msgtmp msg length 2 mul numecis 6 mul add 2 add array def
            msgtmp 0 pad put
            msgtmp 1 eciesc put
            /j 2 def
            0 1 msg length 1 sub {
                msg exch get
                dup -1000000 le {
                    neg 10 7 string cvrs 1 6 getinterval {} forall 6 array astore
                    msgtmp exch j 1 add exch putinterval
                    msgtmp j eciesc put
                    /j j 7 add def
                } {
                    dup eciesc ne {
                        msgtmp exch j exch put
                        /j j 1 add def
                    } {
                        pop
                        msgtmp j eciesc put
                        msgtmp j 1 add eciesc put
                        /j j 2 add def
                    } ifelse
                } ifelse
            } for
            /msg msgtmp 0 j getinterval def
            /msglen msg length def
        } if

        /metrics nonstypemetrics def

        % Select metrics of an appropriate symbol
        /fullcws [] def
        metrics {
            /m exch def
            /vers m 0 get def           % Version of symbol
            /dcws m 4 get def           % Data codewords in symbol
            /okay true def
            version (unset) eq {
                vers length 1 ne {/okay false def} if
            } {
                version vers ne {/okay false def} if
            } ifelse
            okay {/fullcws [ fullcws aload pop dcws ] def} if
        } forall
        /numremcws [ 1480 {10000} repeat ] def
        fullcws {numremcws exch 1 sub 1 put} forall
        1478 -1 0 {
            /i exch def
            numremcws i get 1 ne {
                numremcws i numremcws i 1 add get 1 add put
            } if
        } for

        /numD [ msglen {0} repeat 0 ] def
        /nextXterm [ msglen {0} repeat 9999 ] def
        /nextNonX  [ msglen {0} repeat 9999 ] def
        msglen 1 sub -1 0 {
            /i exch def
            /barchar msg i get def
            barchar 48 ge barchar 57 le and {
                numD i numD i 1 add get 1 add put
            } if
            barchar 13 eq barchar 42 eq or barchar 62 eq or {
                nextXterm i 0 put
            } {
                nextXterm i nextXterm i 1 add get 1 add put
            } ifelse
            Xvals barchar known not {
                nextNonX i 0 put
            } {
                nextNonX i nextNonX i 1 add get 1 add put
            } ifelse
        } for
        /nextXterm [nextXterm {dup 10000 gt {pop 10000} if} forall] def
        /nextNonX  [nextNonX  {dup 10000 gt {pop 10000} if} forall] def

        /isD  {char 48 ge char 57 le and} def
        /isC  {CNvals char known} def
        /isT  {TNvals char known} def
        /isX  {Xvals char known} def
        /isEA {char 127 gt} def
        /isFN {char 0 lt} def
        /XtermFirst {dup nextXterm exch get exch nextNonX exch get lt} def

        /lookup {
            /ac 1 def /cc 2 def /tc 2 def /xc 2 def /bc 3 def
            mode A eq {/ac 0 def /cc 1 def /tc 1 def /xc 1 def /bc 2 def} if
            mode C eq {/cc 0 def} if
            mode T eq {/tc 0 def} if
            mode X eq {/xc 0 def} if  % Assume mistake in spec
            mode B eq {/bc 0 def} if
            1 {  % common exit
                /k 0 def {  % loop
                    i k add msglen eq {
                        true [ac cc tc xc   ] {bc         exch ceiling le and} forall {B exit} if
                        true [   cc tc xc bc] {ac         exch ceiling le and} forall {A exit} if
                        true [      tc xc   ] {cc ceiling exch ceiling le and} forall {C exit} if
                        true [         xc   ] {tc ceiling exch ceiling le and} forall {T exit} if
                        X exit
                    } if
                    /char msg i k add get def
                    /ac ac isD {1 2 div add} {isEA {ceiling 2 add} {ceiling 1 add} ifelse} ifelse def
                    /cc cc isC {2 3 div add} {isEA { 8 3 div add } { 4 3 div add } ifelse} ifelse def
                    /tc tc isT {2 3 div add} {isEA { 8 3 div add } { 4 3 div add } ifelse} ifelse def
                    /xc xc isX {2 3 div add} {isEA {13 3 div add } {10 3 div add } ifelse} ifelse def
                    /bc bc isFN {3 add} {1 add} ifelse def
                    k 3 ge {  % Checking after at least 4 characters (cf. Data Matrix), not 3 as in spec Step Q
                        true [ac cc tc xc   ] {bc 1 add exch ceiling le and} forall {B exit} if
                        true [   cc tc xc bc] {ac 1 add exch ceiling le and} forall {A exit} if
                        true [ac cc    xc bc] {tc ceiling 1 add exch ceiling le and} forall {T exit} if
                        true [ac    tc      ] {cc ceiling 1 add exch ceiling le and} forall {
                            cc ceiling xc ceiling lt {C exit} if
                            cc xc eq {i k add 1 add XtermFirst {X exit} {C exit} ifelse} if
                        } if
                        true [ac cc tc    bc] {xc ceiling 1 add exch ceiling le and} forall {X exit} if
                    } if
                    /k k 1 add def
                } loop
            } repeat
        } def

        /addtocws {
            dup cws exch j exch putinterval
            /j exch length j add def
        } 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
            [ exch {48 sub} forall ]
        } def

        /encA {
            1 {  % Common exit
                numD i get 21 ge {
                    /Dbits [ 1 1 1 1 ] def
                    /mode D def
                    exit
                } if
                numD i get dup 13 ge exch i add msglen eq and {
                    /Dbits [ 1 1 1 1 ] def
                    /mode D def
                    exit
                } if
                numD i get 2 ge {
                    2 string dup 0 msg i get put dup 1 msg i 1 add get put Avals exch get addtocws
                    /i i 2 add def
                    exit
                } if
                msg i get fnc1 eq {
                    numD i 1 add get 15 ge {
                        Avals fnc1lD get addtocws
                        /i i 1 add def
                        /Dbits [] def
                        /mode D def
                        exit
                    } if
                    numD i 1 add get dup 7 ge exch i add 1 add msglen eq and {
                        Avals fnc1lD get addtocws
                        /i i 1 add def
                        /Dbits [] def
                        /mode D def
                        exit
                    } if
                } if
                /newmode lookup def
                newmode mode ne {
                    Avals [-1 lC lT lX lD lB] newmode get get addtocws
                    /mode newmode def
                    exit
                } if
                Avals msg i get get addtocws
                /i i 1 add def
                exit
            } repeat
        } def

        /CTXvalstocws {
            /in exch def
            mark
            0 3 in length 1 sub {
                in exch 3 getinterval 0 exch {add 40 mul} forall 40 idiv 1 add
                dup 256 idiv exch 256 mod
            } for
            counttomark array astore exch pop
        } def

        /encCTX {
            /p 0 def
            /ctxvals 2220 array def

            % Lookup the values for each character
            {
                i msglen eq {exit} if
                p 3 mod 0 eq {
                    numD i get 12 ge {
                        ctxvals 0 p getinterval CTXvalstocws addtocws
                        [unlcw] addtocws
                        /mode A def
                        exit
                    } if
                    numD i get dup 8 ge exch i add msglen eq and {
                        ctxvals 0 p getinterval CTXvalstocws addtocws
                        [unlcw] addtocws
                        /mode A def
                        exit
                    } if
                    mode X eq {  % Steps E1c, E2
                        Xvals msg i get known not {
                            ctxvals 0 p getinterval CTXvalstocws addtocws
                            % Unlatch to ASCII unless one codeword left and single ASCII to encode
                            numremcws j get 1 ne msg i get 127 gt or {
                                [unlcw] addtocws
                            } if
                            /mode A def
                            exit
                        } if
                        i 1 add msglen lt {
                            Xvals msg i 1 add get known not {exit} if
                            i 2 add msglen lt {
                                Xvals msg i 2 add get known not {exit} if
                            } if
                        } if
                    } {
                        lookup mode ne {
                            ctxvals 0 p getinterval CTXvalstocws addtocws
                            [unlcw] addtocws
                            /mode A def
                            exit
                        } if
                    } ifelse
                    msglen i sub 3 le {  % Check end of data conditions
                        /remcws numremcws j p 3 idiv 2 mul add get def
                        /remvals [
                            msg i msglen i sub getinterval {
                                dup encvals mode get exch known {
                                    encvals mode get exch get aload pop
                                } {  % Unencodable X12 characters
                                    pop -1 -1 -1 -1
                                } ifelse
                            } forall
                        ] def
                        remcws 2 eq remvals length 3 eq and {
                            % Encode and omit unlatch
                            [
                                ctxvals 0 p getinterval aload pop
                                remvals aload pop
                            ] CTXvalstocws addtocws
                            /mode A def
                            /i msglen def
                            exit
                        } if
                        remcws 2 eq remvals length 2 eq and mode X ne and {
                            % Encode with sft1 as third value, omit unlatch
                            [
                                ctxvals 0 p getinterval aload pop
                                remvals aload pop
                                encvals mode get sft1 get aload pop
                            ] CTXvalstocws addtocws
                            /mode A def
                            /i msglen def
                            exit
                        } if
                        remcws 2 eq remvals length 1 eq and {
                            % Unlatch to ASCII
                            ctxvals 0 p getinterval CTXvalstocws addtocws
                            [unlcw] addtocws
                            Avals msg i get get addtocws
                            /mode A def
                            /i msglen def
                            exit
                        } if
                        remcws 1 eq remvals length 1 eq and {
                            % Implied unlatch to ASCII
                            ctxvals 0 p getinterval CTXvalstocws addtocws
                            Avals msg i get get addtocws
                            /mode A def
                            /i msglen def
                            exit
                        } if
                    } if
                } if
                encvals mode get msg i get get
                dup ctxvals exch p exch putinterval
                /p exch length p add def
                /i i 1 add def
            } loop

            % Backtrack to a boundary and return to ASCII
            mode A ne {
                {
                    p 3 mod 0 eq {exit} if
                    /i i 1 sub def
                    /p p encvals mode get msg i get get length sub def
                } loop
                [
                    ctxvals 0 p getinterval aload pop
                ] CTXvalstocws addtocws
                [unlcw] addtocws
                /mode A def
                % Encode something to avoid latching immediately back
                i msglen ne {
                    numD i get 2 ge {
                        2 string dup 0 msg i get put dup 1 msg i 1 add get put Avals exch get addtocws
                        /i i 2 add def
                    } {
                        Avals msg i get get addtocws
                        /i i 1 add def
                    } ifelse
                } if
            } if

        } def

        /encD {

            {  % loop

                numD i get 3 lt {

                    /Drem 8 Dbits length 8 mod sub 8 mod def
                    /remcws numremcws j Dbits length 8 idiv add get def

                    % Final codeword with no data
                    numremcws j Dbits length 8 idiv add 1 sub get 1 sub 0 eq Drem 0 eq and  % No remaining codewords and no bits
                    remcws 1 eq Drem 0 ne and or  % Or 1 remaining codeword and some bits
                    i msglen eq and {
                        Drem 4 eq Drem 6 eq or { /Dbits [ Dbits aload pop 1 1 1 1 ] def } if
                        Drem 2 eq Drem 6 eq or { /Dbits [ Dbits aload pop 0 1 ] def } if
                        exit
                    } if

                    % Final digit or double-digit into final codeword as ASCII
                    i msglen 1 sub eq numD i get 1 eq and
                    i msglen 2 sub eq numD i get 2 eq and or
                    remcws 1 eq and Drem 0 eq and {exit} if

                    % Latch to ASCII unless 4 or 6 bits remain in final codeword
                    i msglen 1 sub eq numD i get 1 eq and
                    remcws 1 eq and Drem 4 eq Drem 6 eq or and not {
                      /Dbits [ Dbits aload pop 1 1 1 1 1 1 ] def
                      /Drem 8 Dbits length 8 mod sub 8 mod def
                    } if

                    % Try to encode a digit in remaining bits
                    Drem 4 eq Drem 6 eq or {
                        numD i get 1 ge {
                            /Dbits [ Dbits aload pop msg i get 48 sub 1 add 4 tobin aload pop ] def
                            /i i 1 add def
                        } {
                            /Dbits [ Dbits aload pop 1 1 1 1 ] def
                        } ifelse
                        /Drem Drem 4 sub def
                    } if
                    Drem 2 eq {
                        /Dbits [ Dbits aload pop 0 1 ] def
                        /Drem 0 def
                    } if

                    exit

                } if

                % Three digit value plus one to ten bits
                /Dbits [
                    Dbits aload pop
                    0 msg i 3 getinterval {48 sub add 10 mul} forall 10 idiv
                    1 add 10 tobin aload pop
                ] def
                /i i 3 add def

            } loop

            mark
            0 8 Dbits length 1 sub {
                Dbits exch 8 getinterval 0 exch {add 2 mul} forall 2 idiv
            } for
            counttomark array astore exch pop addtocws
            /mode A def

        } def

        /encB {
            /p 0 def /bvals 1480 array def {
                i msglen eq {exit} if
                msg i get 0 lt {exit} if  % Function character
                lookup mode ne {exit} if
                bvals p msg i get put
                /p p 1 add def
                /i i 1 add def
            } loop
            /remcws numremcws j p add get 1 sub def
            /bvals [
                remcws 0 eq i msglen eq and {  % Terminates symbol
                    0
                } {
                    p 250 lt {p} {p 250 idiv 249 add p 250 mod} ifelse
                } ifelse
                bvals 0 p getinterval aload pop
            ] def
            bvals addtocws
            /mode A def
        } def

        % Derive the codewords
        /cws 1480 array def
        /mode A def /i 0 def /j 0 def {
            i msglen ge {exit} if
            [ /encA /encCTX /encCTX /encCTX /encD /encB ] mode get load exec
        } loop
        /cws cws 0 j getinterval def

    } ifelse

    % Select metrics of an appropriate symbol
    /i 0 def
    { % loop
        /m metrics i get def
        /vers m 0 get def           % Version of symbol
        /rows m 1 get def           % Rows in symbol
        /cols m 2 get def           % Columns in symbol
        /dcol m 3 get def           % Data columns in symbol
        /dcws m 4 get def           % Data codewords in symbol
        /rscw m 5 get def           % Error correction codewords
        /rsbl m 6 get def           % Error correction blocks
        /riso m 7 get def           % Riser offset
        /risi m 8 get def           % Riser interval
        /risl m 9 get def           % Riser length
        /dcpb dcws rsbl idiv def    % Data codewords per block
        /ecpb rscw rsbl idiv def    % Error codewords per block
        /okay true def
        version (unset) ne version vers ne and {/okay false def} if  % The version must match that supplied
        cws length dcws gt {/okay false def} if
        okay {exit} if
        /i i 1 add def
    } loop

    % Extend cws to ncws codewords by addition of pad characters
    stype not {
        /cws [ cws aload pop dcws cws length sub {129} repeat ] def
    } {
        /cws [ dcws cws length sub {0} repeat cws aload pop ] def
    } ifelse

    options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if

    % De-interleave the codewords into blocks
    /cwbs rsbl array def  % Array of data codeword blocks
    /ecbs rsbl array def  % Array of error correction blocks
    0 1 rsbl 1 sub {
        /i exch def
        /cwb dcpb array def
        0 1 dcpb 1 sub {
            /j exch def
            cwb j cws j rsbl mul i add get put
        } for
        cwbs i cwb put
    } for

    % Log and anti-log tables and function to calculate product in the field
    /gf stype {32} {256} ifelse def
    /gf-1 gf 1 sub def
    /pm stype {37} {301} ifelse def
    /rsalog [ 1 gf-1 { dup 2 mul dup gf ge {pm xor} if } repeat ] def
    /rslog gf array def
    1 1 gf-1 {dup rsalog exch get exch rslog 3 1 roll put} for
    /rsprod {
        2 copy 0 ne exch 0 ne and {
            rslog exch get exch rslog exch get add gf-1 mod rsalog exch get
        } {
            pop pop 0
        } ifelse
    } def

    % Generate the coefficients for the Reed-Solomon algorithm
    /coeffs [ 1 ecpb {0} repeat ] def
    0 1 ecpb 1 sub {
        /i exch def
        coeffs i 1 add coeffs i get put
        i -1 1 {
            /j exch def
            coeffs j coeffs j 1 sub get coeffs j get rsalog i get rsprod xor put
        } for
        coeffs 0 coeffs 0 get rsalog i get rsprod put
    } for
    /coeffs coeffs 0 coeffs length 1 sub getinterval def

    % Reed-Solomon algorithm to derive the error correction codewords
    0 1 cwbs length 1 sub {
        /i exch def
        /rscws [ cwbs i get aload pop ecpb {0} repeat ] def
        0 1 dcpb 1 sub {
            /m exch def
            /k rscws m get def
            0 1 ecpb 1 sub {
                /j exch def
                rscws m j add 1 add coeffs ecpb j sub 1 sub get k rsprod rscws m j add 1 add get xor put
            } for
        } for
        ecbs i rscws dcpb ecpb getinterval put
    } for

    % Extend codewords with the interleaved error correction codes
    /cws [ cws aload pop rscw {0} repeat ] def
    0 1 rscw 1 sub {
        /i exch def
        cws dcws i add ecbs i rsbl mod get i rsbl idiv get put
    } for

    % Module matrix for layout of the codewords
    /mmat dcws rscw add stype {5} {8} ifelse mul array def
    /r 0 def /c 0 def
    0 stype {2} {1} ifelse cws length 1 sub {
        /i exch def
        stype not {
            (00000000) 8 string copy dup cws i get 2 8 string cvrs
            dup length 8 exch sub exch putinterval [ exch {48 sub} forall ]
            dup 0 4 getinterval /top exch def
            4 4 getinterval /bot exch def
        } {
            (00000) 5 string copy dup cws i get 2 5 string cvrs
            dup length 5 exch sub exch putinterval [ exch {48 sub} forall ]
            /c1 exch def
            (00000) 5 string copy dup cws i 1 add get 2 5 string cvrs
            dup length 5 exch sub exch putinterval [ exch {48 sub} forall ]
            /c2 exch def
            /top [ c1 0 3 getinterval aload pop c2 0 2 getinterval aload pop ] def
            /bot [ c1 3 2 getinterval aload pop c2 2 3 getinterval aload pop ] def
        } ifelse
        mmat r dcol mul c add top putinterval
        mmat r 1 add dcol mul c add bot putinterval
        /c c top length add def
        c dcol eq {/c 0 def /r r 2 add def} if
    } for

    % Create bitmap and add finder patterns
    /mmv {cols mul add} def
    /pixs [ rows cols mul {-1} repeat ] def

    % Centre pattern
    /artifact [
        {cols {0} repeat} bind
        {cols {1} repeat} bind
        {0   cols 2 sub {1} repeat   0} bind
        {0 1 cols 4 sub {0} repeat 1 0} bind
        {cols 1 sub 2 idiv {-1} repeat 1 cols 1 sub 2 idiv {-1} repeat} bind
        {cols 1 sub 2 idiv {-1} repeat 0 cols 1 sub 2 idiv {-1} repeat} bind
        {1   cols 2 sub {0} repeat   1} bind
        {1 0 cols 4 sub {1} repeat 0 1} bind
    ] def
{
    /cpatmap <<
        /A (121343)
        /B (12134343)
        /C (12121343)
        /D (1213434343)
        /E (1212134343)
        /F (1212121343)
        /G (121213434343)
        /H (121212134343)
        /S (56661278)
        /T (5666666666127878)
    >> def
} ctxdef
    /cpat cpatmap vers 0 1 getinterval get def
    pixs 0 rows cpat length sub 2 idiv mmv
    [ cpat {artifact exch 49 sub get exec} forall ] putinterval

    % Risers
    0 1 risl 1 sub {
        /i exch def
        riso risi cols 1 sub {
            /j exch def
            [ 1 i 12 mod 0 eq {1} {0} ifelse ] dup
            pixs j i mmv
            3 -1 roll putinterval
            i risl 1 sub ne {
                pixs cols j sub 2 sub rows i sub 1 sub mmv
                3 -1 roll putinterval
            } {pop} ifelse
        } for
    } for

    % Black dots
{
    /blackdotmap <<
        /A [ [12 5] ]
        /B [ [16 7] ]
        /C [ [26 12] ]
        /D []
        /E [ [26 23] ]
        /F [ [26 32] [70 32] [26 34] [70 34] ]
        /G [ [27 48] [69 48] ]
        /H [ [26 70] [66 70] [106 70] [26 72] [66 72] [106 72] ]
        /S-10 []
        /S-20 [ [10 4] ]
        /S-30 [ [15 4] [15 6] ]
        /T-16 [ [8 10] ]
        /T-32 [ [16 10] [16 12] ]
        /T-48 [ [24 10] [24 12] [24 14] ]
    >> def
} ctxdef
    blackdotmap vers get {pixs exch aload pop mmv 1 put} forall

    % Place the modules onto a pixel map between alignment patterns
    /j 0 def
    0 1 pixs length 1 sub {
        /i exch def
        pixs i get -1 eq {
            pixs i mmat j get put
            /j j 1 add def
        } if
    } for

    % Return the arguments
    <<
    /ren //renmatrix
    /pixs pixs
    /pixx cols
    /pixy rows
    /height rows 72 div 2 mul
    /width cols 72 div 2 mul
    /opt options
    >>

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/codeone dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER codeone--

% --BEGIN ENCODER hanxin--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: Han Xin Code
% --EXAM: This is Han Xin
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp hanxin 0.0 2022082100 304477 334267
%%BeginData:        863 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/hanxin {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /version (unset) def   % 1-84
    /eclevel (unset) def   % L1, L2, L3 or L4
    /parse false def
    /parsefnc false def
    /mask -1 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

    /mask mask cvi def

    /hanxin //loadctx exec

    % Parse the input
    /fncvals <<
        /parse parse
        /parsefnc parsefnc
        % No FNC characters defined
    >> def
    /msg barcode fncvals //parseinput exec def
    /msglen msg length def

    % Default error correction level
    eclevel (unset) eq {/eclevel (L2) def} if

    /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

    % Encode the data using byte mode encoding
    /bits 4 13 add msglen 8 mul add string def
    bits 0 (0011) putinterval
    bits 4 msglen 13 tobin putinterval
    0 1 msglen 1 sub {
        /i exch def
        bits 17 i 8 mul add msg i get 8 tobin putinterval
    } for

    % Lookup the most appropriate symbol specification
{
    /metrics [
        % vers size  align  modules            error correction blocks
        [ (1)    23  -1  0    205  [  1  21   4 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  17   8 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  13  12 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1   9  16 ] [  0  -1  -1 ] [  0  -1  -1 ] ]
        [ (2)    25  -1  0    301  [  1  31   6 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  25  12 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  19  18 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  15  22 ] [  0  -1  -1 ] [  0  -1  -1 ] ]
        [ (3)    27  -1  0    405  [  1  42   8 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  34  16 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  26  24 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  20  30 ] [  0  -1  -1 ] [  0  -1  -1 ] ]
        [ (4)    29  14  1    439  [  1  46   8 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  38  16 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  30  24 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  22  32 ] [  0  -1  -1 ] [  0  -1  -1 ] ]
        [ (5)    31  16  1    555  [  1  57  12 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  49  20 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  37  32 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  14  20 ] [  1  13  22 ] [  0  -1  -1 ] ]
        [ (6)    33  16  1    675  [  1  70  14 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  58  26 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  24  20 ] [  1  22  18 ] [  0  -1  -1 ]
                                   [  1  16  24 ] [  1  18  26 ] [  0  -1  -1 ] ]
        [ (7)    35  17  1    805  [  1  84  16 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  70  30 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  26  22 ] [  1  28  24 ] [  0  -1  -1 ]
                                   [  2  14  20 ] [  1  12  20 ] [  0  -1  -1 ] ]
        [ (8)    37  18  1    943  [  1  99  18 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  40  18 ] [  1  41  18 ] [  0  -1  -1 ]
                                   [  1  31  26 ] [  1  32  28 ] [  0  -1  -1 ]
                                   [  2  16  24 ] [  1  15  22 ] [  0  -1  -1 ] ]
        [ (9)    39  19  1   1089  [  1 114  22 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  2  48  20 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  2  24  20 ] [  1  26  22 ] [  0  -1  -1 ]
                                   [  2  18  28 ] [  1  18  26 ] [  0  -1  -1 ] ]
        [ (10)   41  20  1   1243  [  1 131  24 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  52  22 ] [  1  57  24 ] [  0  -1  -1 ]
                                   [  2  27  24 ] [  1  29  24 ] [  0  -1  -1 ]
                                   [  2  21  32 ] [  1  19  30 ] [  0  -1  -1 ] ]
        [ (11)   43  14  2   1289  [  1 135  26 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  56  24 ] [  1  57  24 ] [  0  -1  -1 ]
                                   [  2  28  24 ] [  1  31  26 ] [  0  -1  -1 ]
                                   [  2  22  32 ] [  1  21  32 ] [  0  -1  -1 ] ]
        [ (12)   45  15  2   1455  [  1 153  28 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  1  62  26 ] [  1  65  28 ] [  0  -1  -1 ]
                                   [  2  32  28 ] [  1  33  28 ] [  0  -1  -1 ]
                                   [  3  17  26 ] [  1  22  30 ] [  0  -1  -1 ] ]
        [ (13)   47  16  2   1629  [  1  86  16 ] [  1  85  16 ] [  0  -1  -1 ]
                                   [  1  71  30 ] [  1  72  30 ] [  0  -1  -1 ]
                                   [  2  37  32 ] [  1  35  30 ] [  0  -1  -1 ]
                                   [  3  20  30 ] [  1  21  32 ] [  0  -1  -1 ] ]
        [ (14)   49  16  2   1805  [  1  94  18 ] [  1  95  18 ] [  0  -1  -1 ]
                                   [  2  51  22 ] [  1  55  24 ] [  0  -1  -1 ]
                                   [  3  30  26 ] [  1  31  26 ] [  0  -1  -1 ]
                                   [  4  18  28 ] [  1  17  24 ] [  0  -1  -1 ] ]
        [ (15)   51  17  2   1995  [  1 104  20 ] [  1 105  20 ] [  0  -1  -1 ]
                                   [  2  57  24 ] [  1  61  26 ] [  0  -1  -1 ]
                                   [  3  33  28 ] [  1  36  30 ] [  0  -1  -1 ]
                                   [  4  20  30 ] [  1  19  30 ] [  0  -1  -1 ] ]
        [ (16)   53  17  2   2187  [  1 115  22 ] [  1 114  22 ] [  0  -1  -1 ]
                                   [  2  65  28 ] [  1  61  26 ] [  0  -1  -1 ]
                                   [  3  38  32 ] [  1  33  30 ] [  0  -1  -1 ]
                                   [  5  19  28 ] [  1  14  24 ] [  0  -1  -1 ] ]
        [ (17)   55  18  2   2393  [  1 126  24 ] [  1 125  24 ] [  0  -1  -1 ]
                                   [  2  70  30 ] [  1  69  30 ] [  0  -1  -1 ]
                                   [  4  33  28 ] [  1  29  26 ] [  0  -1  -1 ]
                                   [  5  20  30 ] [  1  19  30 ] [  0  -1  -1 ] ]
        [ (18)   57  19  2   2607  [  1 136  26 ] [  1 137  26 ] [  0  -1  -1 ]
                                   [  3  56  24 ] [  1  59  26 ] [  0  -1  -1 ]
                                   [  5  35  30 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  6  18  28 ] [  1  21  28 ] [  0  -1  -1 ] ]
        [ (19)   59  20  2   2829  [  1 148  28 ] [  1 149  28 ] [  0  -1  -1 ]
                                   [  3  61  26 ] [  1  64  28 ] [  0  -1  -1 ]
                                   [  7  24  20 ] [  1  23  22 ] [  0  -1  -1 ]
                                   [  6  20  30 ] [  1  21  32 ] [  0  -1  -1 ] ]
        [ (20)   61  20  2   3053  [  3 107  20 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  3  65  28 ] [  1  72  30 ] [  0  -1  -1 ]
                                   [  7  26  22 ] [  1  23  22 ] [  0  -1  -1 ]
                                   [  7  19  28 ] [  1  20  32 ] [  0  -1  -1 ] ]
        [ (21)   63  21  2   3291  [  3 115  22 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  4  56  24 ] [  1  63  28 ] [  0  -1  -1 ]
                                   [  7  28  24 ] [  1  25  22 ] [  0  -1  -1 ]
                                   [  8  18  28 ] [  1  21  22 ] [  0  -1  -1 ] ]
        [ (22)   65  16  3   3383  [  2 116  22 ] [  1 122  24 ] [  0  -1  -1 ]
                                   [  4  56  24 ] [  1  72  30 ] [  0  -1  -1 ]
                                   [  7  28  24 ] [  1  32  26 ] [  0  -1  -1 ]
                                   [  8  18  28 ] [  1  24  30 ] [  0  -1  -1 ] ]
        [ (23)   67  17  3   3631  [  3 127  24 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  5  51  22 ] [  1  62  26 ] [  0  -1  -1 ]
                                   [  7  30  26 ] [  1  35  26 ] [  0  -1  -1 ]
                                   [  8  20  30 ] [  1  21  32 ] [  0  -1  -1 ] ]
        [ (24)   69  17  3   3887  [  2 135  26 ] [  1 137  26 ] [  0  -1  -1 ]
                                   [  5  56  24 ] [  1  59  26 ] [  0  -1  -1 ]
                                   [  7  33  28 ] [  1  30  28 ] [  0  -1  -1 ]
                                   [ 11  16  24 ] [  1  19  26 ] [  0  -1  -1 ] ]
        [ (25)   71  18  3   4151  [  3 105  20 ] [  1 121  22 ] [  0  -1  -1 ]
                                   [  5  61  26 ] [  1  57  26 ] [  0  -1  -1 ]
                                   [  9  28  24 ] [  1  28  22 ] [  0  -1  -1 ]
                                   [ 10  19  28 ] [  1  18  30 ] [  0  -1  -1 ] ]
        [ (26)   73  18  3   4423  [  2 157  30 ] [  1 150  28 ] [  0  -1  -1 ]
                                   [  5  65  28 ] [  1  61  26 ] [  0  -1  -1 ]
                                   [  8  33  28 ] [  1  34  30 ] [  0  -1  -1 ]
                                   [ 10  19  28 ] [  2  15  26 ] [  0  -1  -1 ] ]
        [ (27)   75  19  3   4703  [  3 126  24 ] [  1 115  22 ] [  0  -1  -1 ]
                                   [  7  51  22 ] [  1  54  22 ] [  0  -1  -1 ]
                                   [  8  35  30 ] [  1  37  30 ] [  0  -1  -1 ]
                                   [ 15  15  22 ] [  1  10  22 ] [  0  -1  -1 ] ]
        [ (28)   77  19  3   4991  [  4 105  20 ] [  1 103  20 ] [  0  -1  -1 ]
                                   [  7  56  24 ] [  1  45  18 ] [  0  -1  -1 ]
                                   [ 10  31  26 ] [  1  27  26 ] [  0  -1  -1 ]
                                   [ 10  17  26 ] [  3  20  28 ] [  1  21  28 ] ]
        [ (29)   79  20  3   5287  [  3 139  26 ] [  1 137  28 ] [  0  -1  -1 ]
                                   [  6  66  28 ] [  1  66  30 ] [  0  -1  -1 ]
                                   [  9  36  30 ] [  1  34  32 ] [  0  -1  -1 ]
                                   [ 13  19  28 ] [  1  17  32 ] [  0  -1  -1 ] ]
        [ (30)   81  20  3   5591  [  6  84  16 ] [  1  82  16 ] [  0  -1  -1 ]
                                   [  6  70  30 ] [  1  68  30 ] [  0  -1  -1 ]
                                   [  7  35  30 ] [  3  33  28 ] [  1  32  28 ]
                                   [ 13  20  30 ] [  1  20  28 ] [  0  -1  -1 ] ]
        [ (31)   83  21  3   5903  [  5 105  20 ] [  1  94  18 ] [  0  -1  -1 ]
                                   [  6  74  32 ] [  1  71  30 ] [  0  -1  -1 ]
                                   [ 11  33  28 ] [  1  34  32 ] [  0  -1  -1 ]
                                   [ 13  19  28 ] [  3  16  26 ] [  0  -1  -1 ] ]
        [ (32)   85  17  4   6033  [  4 127  24 ] [  1 126  24 ] [  0  -1  -1 ]
                                   [  7  66  28 ] [  1  66  30 ] [  0  -1  -1 ]
                                   [ 12  30  24 ] [  1  24  28 ] [  1  24  30 ]
                                   [ 15  19  28 ] [  1  17  32 ] [  0  -1  -1 ] ]
        [ (33)   87  17  4   6353  [  7  84  16 ] [  1  78  16 ] [  0  -1  -1 ]
                                   [  7  70  30 ] [  1  66  28 ] [  0  -1  -1 ]
                                   [ 12  33  28 ] [  1  32  30 ] [  0  -1  -1 ]
                                   [ 14  21  32 ] [  1  24  28 ] [  0  -1  -1 ] ]
        [ (34)   89  18  4   6689  [  5 117  22 ] [  1 117  24 ] [  0  -1  -1 ]
                                   [  8  66  28 ] [  1  58  26 ] [  0  -1  -1 ]
                                   [ 11  38  32 ] [  1  34  32 ] [  0  -1  -1 ]
                                   [ 15  20  30 ] [  2  17  26 ] [  0  -1  -1 ] ]
        [ (35)   91  18  4   7025  [  4 148  28 ] [  1 146  28 ] [  0  -1  -1 ]
                                   [  8  68  30 ] [  1  70  24 ] [  0  -1  -1 ]
                                   [ 10  36  32 ] [  3  38  28 ] [  0  -1  -1 ]
                                   [ 16  19  28 ] [  3  16  26 ] [  0  -1  -1 ] ]
        [ (36)   93  19  4   7377  [  4 126  24 ] [  2 135  26 ] [  0  -1  -1 ]
                                   [  8  70  28 ] [  2  43  26 ] [  0  -1  -1 ]
                                   [ 13  32  28 ] [  2  41  30 ] [  0  -1  -1 ]
                                   [ 17  19  28 ] [  3  15  26 ] [  0  -1  -1 ] ]
        [ (37)   95  19  4   7729  [  5 136  26 ] [  1 132  24 ] [  0  -1  -1 ]
                                   [  5  67  30 ] [  4  68  28 ] [  1  69  28 ]
                                   [ 14  35  30 ] [  1  32  24 ] [  0  -1  -1 ]
                                   [ 18  18  26 ] [  3  16  28 ] [  1  14  28 ] ]
        [ (38)   97  19  4   8089  [  3 142  26 ] [  3 141  28 ] [  0  -1  -1 ]
                                   [  8  70  30 ] [  1  73  32 ] [  1  74  32 ]
                                   [ 12  34  30 ] [  3  34  26 ] [  1  35  28 ]
                                   [ 18  21  32 ] [  1  27  30 ] [  0  -1  -1 ] ]
        [ (39)   99  20  4   8465  [  5 116  22 ] [  2 103  20 ] [  1 102  20 ]
                                   [  9  74  32 ] [  1  74  30 ] [  0  -1  -1 ]
                                   [ 14  34  28 ] [  2  32  32 ] [  1  32  30 ]
                                   [ 19  21  32 ] [  1  25  26 ] [  0  -1  -1 ] ]
        [ (40)  101  20  4   8841  [  7 116  22 ] [  1 117  22 ] [  0  -1  -1 ]
                                   [ 11  65  28 ] [  1  58  24 ] [  0  -1  -1 ]
                                   [ 15  38  32 ] [  1  27  28 ] [  0  -1  -1 ]
                                   [ 20  20  30 ] [  1  20  32 ] [  1  21  32 ] ]
        [ (41)  103  17  5   9009  [  6 136  26 ] [  1 130  24 ] [  0  -1  -1 ]
                                   [ 11  66  28 ] [  1  62  30 ] [  0  -1  -1 ]
                                   [ 14  34  28 ] [  3  34  32 ] [  1  30  30 ]
                                   [ 18  20  30 ] [  3  20  28 ] [  2  15  26 ] ]
        [ (42)  105  17  5   9401  [  5 105  20 ] [  2 115  22 ] [  2 116  22 ]
                                   [ 10  75  32 ] [  1  73  32 ] [  0  -1  -1 ]
                                   [ 16  38  32 ] [  1  27  28 ] [  0  -1  -1 ]
                                   [ 22  19  28 ] [  2  16  30 ] [  1  19  30 ] ]
        [ (43)  107  18  5   9799  [  6 147  28 ] [  1 146  28 ] [  0  -1  -1 ]
                                   [ 11  66  28 ] [  2  65  30 ] [  0  -1  -1 ]
                                   [ 18  33  28 ] [  2  33  30 ] [  0  -1  -1 ]
                                   [ 22  21  32 ] [  1  28  30 ] [  0  -1  -1 ] ]
        [ (44)  109  18  5  10207  [  6 116  22 ] [  3 125  24 ] [  0  -1  -1 ]
                                   [ 11  75  32 ] [  1  68  30 ] [  0  -1  -1 ]
                                   [ 13  35  28 ] [  6  34  32 ] [  1  30  30 ]
                                   [ 23  21  32 ] [  1  26  30 ] [  0  -1  -1 ] ]
        [ (45)  111  18  5  10623  [  7 105  20 ] [  4  95  18 ] [  0  -1  -1 ]
                                   [ 12  67  28 ] [  1  63  30 ] [  1  62  32 ]
                                   [ 21  31  26 ] [  2  33  32 ] [  0  -1  -1 ]
                                   [ 23  21  32 ] [  2  24  30 ] [  0  -1  -1 ] ]
        [ (46)  113  19  5  11045  [ 10 116  22 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [ 12  74  32 ] [  1  78  30 ] [  0  -1  -1 ]
                                   [ 18  37  32 ] [  1  39  30 ] [  1  41  28 ]
                                   [ 25  21  32 ] [  1  27  28 ] [  0  -1  -1 ] ]
        [ (47)  115  19  5  11477  [  5 126  24 ] [  4 115  22 ] [  1 114  22 ]
                                   [ 12  67  28 ] [  2  66  32 ] [  1  68  30 ]
                                   [ 21  35  30 ] [  1  39  30 ] [  0  -1  -1 ]
                                   [ 26  21  32 ] [  1  28  28 ] [  0  -1  -1 ] ]
        [ (48)  117  19  5  11917  [  9 126  24 ] [  1 117  22 ] [  0  -1  -1 ]
                                   [ 13  75  32 ] [  1  68  30 ] [  0  -1  -1 ]
                                   [ 20  35  30 ] [  3  35  28 ] [  0  -1  -1 ]
                                   [ 27  21  32 ] [  1  28  30 ] [  0  -1  -1 ] ]
        [ (49)  119  17  6  12111  [  9 126  24 ] [  1 137  26 ] [  0  -1  -1 ]
                                   [ 13  71  30 ] [  2  68  32 ] [  0  -1  -1 ]
                                   [ 20  37  32 ] [  1  39  28 ] [  1  38  28 ]
                                   [ 24  20  32 ] [  5  25  28 ] [  0  -1  -1 ] ]
        [ (50)  121  17  6  12559  [  8 147  28 ] [  1 141  28 ] [  0  -1  -1 ]
                                   [ 10  73  32 ] [  4  74  30 ] [  1  73  30 ]
                                   [ 16  36  32 ] [  6  39  30 ] [  1  37  30 ]
                                   [ 27  21  32 ] [  3  20  26 ] [  0  -1  -1 ] ]
        [ (51)  123  18  6  13025  [  9 137  26 ] [  1 135  26 ] [  0  -1  -1 ]
                                   [ 12  70  30 ] [  4  75  32 ] [  0  -1  -1 ]
                                   [ 24  35  30 ] [  1  40  28 ] [  0  -1  -1 ]
                                   [ 23  20  32 ] [  8  24  30 ] [  0  -1  -1 ] ]
        [ (52)  125  18  6  13489  [ 14  95  18 ] [  1  86  18 ] [  0  -1  -1 ]
                                   [ 13  73  32 ] [  3  77  30 ] [  0  -1  -1 ]
                                   [ 24  35  30 ] [  2  35  28 ] [  0  -1  -1 ]
                                   [ 26  21  32 ] [  5  21  30 ] [  1  23  30 ] ]
        [ (53)  127  18  6  13961  [  9 147  28 ] [  1 142  28 ] [  0  -1  -1 ]
                                   [ 10  73  30 ] [  6  70  32 ] [  1  71  32 ]
                                   [ 25  35  30 ] [  2  34  26 ] [  0  -1  -1 ]
                                   [ 29  21  32 ] [  4  22  30 ] [  0  -1  -1 ] ]
        [ (54)  129  18  6  14441  [ 11 126  24 ] [  1 131  24 ] [  0  -1  -1 ]
                                   [ 16  74  32 ] [  1  79  30 ] [  0  -1  -1 ]
                                   [ 25  38  32 ] [  1  25  30 ] [  0  -1  -1 ]
                                   [ 33  21  32 ] [  1  28  28 ] [  0  -1  -1 ] ]
        [ (55)  131  19  6  14939  [ 14 105  20 ] [  1  99  18 ] [  0  -1  -1 ]
                                   [ 19  65  28 ] [  1  72  28 ] [  0  -1  -1 ]
                                   [ 24  37  32 ] [  2  40  30 ] [  1  41  30 ]
                                   [ 31  21  32 ] [  4  24  32 ] [  0  -1  -1 ] ]
        [ (56)  133  19  6  15435  [ 10 147  28 ] [  1 151  28 ] [  0  -1  -1 ]
                                   [ 15  71  30 ] [  3  71  32 ] [  1  73  32 ]
                                   [ 24  37  32 ] [  3  38  30 ] [  1  39  30 ]
                                   [ 36  19  30 ] [  3  29  26 ] [  0  -1  -1 ] ]
        [ (57)  135  19  6  15939  [ 15 105  20 ] [  1  99  18 ] [  0  -1  -1 ]
                                   [ 19  70  30 ] [  1  64  28 ] [  0  -1  -1 ]
                                   [ 27  38  32 ] [  2  25  26 ] [  0  -1  -1 ]
                                   [ 38  20  30 ] [  2  18  28 ] [  0  -1  -1 ] ]
        [ (58)  137  17  7  16171  [ 14 105  20 ] [  1 113  22 ] [  1 114  22 ]
                                   [ 17  67  30 ] [  3  92  32 ] [  0  -1  -1 ]
                                   [ 30  35  30 ] [  1  41  30 ] [  0  -1  -1 ]
                                   [ 36  21  32 ] [  1  26  30 ] [  1  27  30 ] ]
        [ (59)  139  17  7  16691  [ 11 146  28 ] [  1 146  26 ] [  0  -1  -1 ]
                                   [ 20  70  30 ] [  1  60  26 ] [  0  -1  -1 ]
                                   [ 29  38  32 ] [  1  24  32 ] [  0  -1  -1 ]
                                   [ 40  20  30 ] [  2  17  26 ] [  0  -1  -1 ] ]
        [ (60)  141  18  7  17215  [  3 137  26 ] [  1 136  26 ] [ 10 126  24 ]
                                   [ 22  65  28 ] [  1  75  30 ] [  0  -1  -1 ]
                                   [ 30  37  32 ] [  1  51  30 ] [  0  -1  -1 ]
                                   [ 42  20  30 ] [  1  21  30 ] [  0  -1  -1 ] ]
        [ (61)  143  18  7  17751  [ 12 126  24 ] [  2 118  22 ] [  1 116  22 ]
                                   [ 19  74  32 ] [  1  74  30 ] [  1  72  28 ]
                                   [ 30  38  32 ] [  2  29  30 ] [  0  -1  -1 ]
                                   [ 39  20  32 ] [  2  37  26 ] [  1  38  26 ] ]
        [ (62)  145  18  7  18295  [ 12 126  24 ] [  3 136  26 ] [  0  -1  -1 ]
                                   [ 21  70  30 ] [  2  65  28 ] [  0  -1  -1 ]
                                   [ 34  35  30 ] [  1  44  32 ] [  0  -1  -1 ]
                                   [ 42  20  30 ] [  2  19  28 ] [  2  18  28 ] ]
        [ (63)  147  18  7  18847  [ 12 126  24 ] [  3 117  22 ] [  1 116  22 ]
                                   [ 25  61  26 ] [  2  62  28 ] [  0  -1  -1 ]
                                   [ 34  35  30 ] [  1  40  32 ] [  1  41  32 ]
                                   [ 45  20  30 ] [  1  20  32 ] [  1  21  32 ] ]
        [ (64)  149  19  7  19403  [ 15 105  20 ] [  2 115  22 ] [  2 116  22 ]
                                   [ 25  65  28 ] [  1  72  28 ] [  0  -1  -1 ]
                                   [ 18  35  30 ] [ 17  37  32 ] [  1  50  32 ]
                                   [ 42  20  30 ] [  6  19  28 ] [  1  15  28 ] ]
        [ (65)  151  19  7  19971  [ 19 105  20 ] [  1 101  20 ] [  0  -1  -1 ]
                                   [ 33  51  22 ] [  1  65  22 ] [  0  -1  -1 ]
                                   [ 40  33  28 ] [  1  28  28 ] [  0  -1  -1 ]
                                   [ 49  20  30 ] [  1  18  28 ] [  0  -1  -1 ] ]
        [ (66)  153  17  8  20229  [ 18 105  20 ] [  2 117  22 ] [  0  -1  -1 ]
                                   [ 26  65  28 ] [  1  80  30 ] [  0  -1  -1 ]
                                   [ 35  35  30 ] [  3  35  28 ] [  1  36  28 ]
                                   [ 52  18  28 ] [  2  38  30 ] [  0  -1  -1 ] ]
        [ (67)  155  17  8  20805  [ 26  84  16 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [ 26  70  30 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [ 45  31  26 ] [  1   9  26 ] [  0  -1  -1 ]
                                   [ 52  20  30 ] [  0  -1  -1 ] [  0  -1  -1 ] ]
        [ (68)  157  17  8  21389  [ 16 126  24 ] [  1 114  22 ] [  1 115  22 ]
                                   [ 23  70  30 ] [  3  65  28 ] [  1  66  28 ]
                                   [ 40  35  30 ] [  1  43  30 ] [  0  -1  -1 ]
                                   [ 46  20  30 ] [  7  19  28 ] [  1  16  28 ] ]
        [ (69)  159  18  8  21993  [ 19 116  22 ] [  1 105  22 ] [  0  -1  -1 ]
                                   [ 20  70  30 ] [  7  66  28 ] [  1  63  28 ]
                                   [ 40  35  30 ] [  1  42  32 ] [  1  43  32 ]
                                   [ 54  20  30 ] [  1  19  30 ] [  0  -1  -1 ] ]
        [ (70)  161  18  8  22593  [ 17 126  24 ] [  2 115  22 ] [  0  -1  -1 ]
                                   [ 24  70  30 ] [  4  74  32 ] [  0  -1  -1 ]
                                   [ 48  31  26 ] [  2  18  26 ] [  0  -1  -1 ]
                                   [ 54  19  28 ] [  6  15  26 ] [  1  14  26 ] ]
        [ (71)  163  18  8  23201  [ 29  84  16 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [ 29  70  30 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [  6  34  30 ] [  3  36  30 ] [ 38  33  28 ]
                                   [ 58  20  30 ] [  0  -1  -1 ] [  0  -1  -1 ] ]
        [ (72)  165  18  8  23817  [ 16 147  28 ] [  1 149  28 ] [  0  -1  -1 ]
                                   [ 31  66  28 ] [  1  37  26 ] [  0  -1  -1 ]
                                   [ 48  33  28 ] [  1  23  26 ] [  0  -1  -1 ]
                                   [ 53  20  30 ] [  6  19  28 ] [  1  17  28 ] ]
        [ (73)  167  19  8  24453  [ 20 115  22 ] [  2 134  24 ] [  0  -1  -1 ]
                                   [ 29  66  28 ] [  2  56  26 ] [  2  57  26 ]
                                   [ 45  36  30 ] [  2  15  28 ] [  0  -1  -1 ]
                                   [ 59  20  30 ] [  2  21  32 ] [  0  -1  -1 ] ]
        [ (74)  169  19  8  25085  [ 17 147  28 ] [  1 134  26 ] [  0  -1  -1 ]
                                   [ 26  70  30 ] [  5  75  32 ] [  0  -1  -1 ]
                                   [ 47  35  30 ] [  1  48  32 ] [  0  -1  -1 ]
                                   [ 64  18  28 ] [  2  33  30 ] [  1  35  30 ] ]
        [ (75)  171  17  9  25373  [ 22 115  22 ] [  1 133  24 ] [  0  -1  -1 ]
                                   [ 33  65  28 ] [  1  74  28 ] [  0  -1  -1 ]
                                   [ 43  36  30 ] [  5  27  28 ] [  1  30  28 ]
                                   [ 57  20  30 ] [  5  21  32 ] [  1  24  32 ] ]
        [ (76)  173  17  9  26021  [ 18 136  26 ] [  2 142  26 ] [  0  -1  -1 ]
                                   [ 33  66  28 ] [  2  49  26 ] [  0  -1  -1 ]
                                   [ 48  35  30 ] [  2  38  28 ] [  0  -1  -1 ]
                                   [ 64  20  30 ] [  1  20  32 ] [  0  -1  -1 ] ]
        [ (77)  175  17  9  26677  [ 19 126  24 ] [  2 135  26 ] [  1 136  26 ]
                                   [ 32  66  28 ] [  2  55  26 ] [  2  56  26 ]
                                   [ 49  36  30 ] [  2  18  32 ] [  0  -1  -1 ]
                                   [ 65  18  28 ] [  5  27  30 ] [  1  29  30 ] ]
        [ (78)  177  18  9  27335  [ 20 137  26 ] [  1 130  26 ] [  0  -1  -1 ]
                                   [ 30  75  32 ] [  2  71  32 ] [  0  -1  -1 ]
                                   [ 46  35  30 ] [  6  39  32 ] [  0  -1  -1 ]
                                   [  3  12  30 ] [ 70  19  28 ] [  0  -1  -1 ] ]
        [ (79)  179  18  9  28007  [ 20 147  28 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [ 35  70  30 ] [  0  -1  -1 ] [  0  -1  -1 ]
                                   [ 49  35  30 ] [  5  35  28 ] [  0  -1  -1 ]
                                   [ 70  20  30 ] [  0  -1  -1 ] [  0  -1  -1 ] ]
        [ (80)  181  18  9  28687  [ 21 136  26 ] [  1 155  28 ] [  0  -1  -1 ]
                                   [ 34  70  30 ] [  1  64  28 ] [  1  65  28 ]
                                   [ 54  35  30 ] [  1  45  30 ] [  0  -1  -1 ]
                                   [ 68  20  30 ] [  3  18  28 ] [  1  19  28 ] ]
        [ (81)  183  18  9  29375  [ 19 126  24 ] [  5 115  22 ] [  1 114  22 ]
                                   [ 33  70  30 ] [  3  65  28 ] [  1  64  28 ]
                                   [ 52  35  30 ] [  3  41  32 ] [  1  40  32 ]
                                   [ 67  20  30 ] [  5  21  32 ] [  1  24  32 ] ]
        [ (82)  185  18  9  30071  [  2 150  28 ] [ 21 136  26 ] [  0  -1  -1 ]
                                   [ 32  70  30 ] [  6  65  28 ] [  0  -1  -1 ]
                                   [ 52  38  32 ] [  2  27  32 ] [  0  -1  -1 ]
                                   [ 73  20  30 ] [  2  22  32 ] [  0  -1  -1 ] ]
        [ (83)  187  17 10  30387  [ 21 126  24 ] [  4 136  26 ] [  0  -1  -1 ]
                                   [ 30  74  32 ] [  6  73  30 ] [  0  -1  -1 ]
                                   [ 54  35  30 ] [  4  40  32 ] [  0  -1  -1 ]
                                   [ 75  20  30 ] [  1  20  28 ] [  0  -1  -1 ] ]
        [ (84)  189  17 10  31091  [ 30 105  20 ] [  1 114  22 ] [  0  -1  -1 ]
                                   [  3  45  22 ] [ 55  47  20 ] [  0  -1  -1 ]
                                   [  2  26  26 ] [ 62  33  28 ] [  0  -1  -1 ]
                                   [ 79  18  28 ] [  4  33  30 ] [  0  -1  -1 ] ]
    ] def
} ctxdef

    /eclval eclevel 1 get 49 sub def
    0 1 83 {
        /i exch def
        /m metrics i get def
        /vers m 0 get def                             % Version of symbol
        /size m 1 get def                             % Length of side
        /alnk m 2 get def                             % Regular alignment pattern length
        /alnn m 3 get def                             % Number of alignment patterns
        /alnr size alnk alnn mul sub def              % Remainder alignment pattern length
        /nmod m 4 get def                             % Number of modules
        /ncws nmod 8 idiv def                         % Total number of codewords
        /rbit nmod 8 mod def                          % Number of remainder bits
        /ecbs m 5 eclval 3 mul add 3 getinterval def  % Error correction blocks
        /ecws 0 ecbs {dup 0 get exch 2 get mul add} forall def  % Number of error correction codewords
        /dcws ncws ecws sub def                       % Number of data codewords
        /dmod dcws 8 mul def                          % Number of data modules
        /okay true def
        version (unset) ne version vers ne and {/okay false def} if  % The version must match that supplied
        bits length dmod gt {/okay false def} if      % Bitstream must fit into data modules
        okay {exit} if
    } for

    okay not {
        /bwipp.hanxinNoValidSymbol (Maximum length exceeded or invalid content) //raiseerror exec
    } if

    /version vers def
    /msgbits bits def
    /e1nb   ecbs 0 get 0 get def  /e2nb   ecbs 1 get 0 get def  /e3nb   ecbs 2 get 0 get def
    /e1dcws ecbs 0 get 1 get def  /e2dcws ecbs 1 get 1 get def  /e3dcws ecbs 2 get 1 get def
    /e1ecws ecbs 0 get 2 get def  /e2ecws ecbs 1 get 2 get def  /e3ecws ecbs 2 get 2 get def

    % Expand the message bits by adding padding as necessary
    /pad dmod string def
    0 1 pad length 1 sub {pad exch 48 put} for
    pad 0 msgbits putinterval

    % Evaluate the padded message into codewords
    /cws dcws array def
    0 1 cws length 1 sub {
        /c exch def
        /cwb pad c 8 mul 8 getinterval def
        /cw 0 def
        0 1 7 {
            /i exch def
            /cw cw 2 8 i sub 1 sub exp cvi cwb i get 48 sub mul add def
        } for
        cws c cw put
    } for

    /rscodes {

        /rspm exch def
        /rsgf exch def
        /rsnc exch def
        /rscws exch def

        % Calculate the log and anti-log tables
        /rsalog [ 1 rsgf 1 sub { dup 2 mul dup rsgf ge {rspm xor} if } repeat ] def
        /rslog rsgf array def
        1 1 rsgf 1 sub {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 rsgf 1 sub mod rsalog exch get
            } {
                pop pop 0
            } ifelse
        } def

        % Generate the coefficients
        /coeffs [ 1 rsnc {0} repeat ] def
        1 1 rsnc {
            /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 xor put
            } for
            coeffs 0 coeffs 0 get rsalog i get rsprod put
        } for

        % Extend the input with the error correction values
        /nd rscws length def
        /rscws [ rscws {} forall rsnc {0} repeat 0 ] def
        0 1 nd 1 sub {
            /k exch rscws exch get rscws nd get xor def
            0 1 rsnc 1 sub {
                /j exch def
                rscws nd j add rscws nd j add 1 add get k coeffs rsnc j sub 1 sub get rsprod xor put
            } for
        } for

        % Return all but the last codeword
        rscws 0 rscws length 1 sub getinterval

    } def

    % Divide codewords into two groups of blocks and calculate the error correction codewords
    /dcwsb e1nb e2nb add e3nb add array def
    /ecwsb dcwsb length array def
    /in 0 def  /out 0 def
    e1nb {
        cws in e1dcws getinterval e1ecws 256 355 rscodes
        dup 0 e1dcws getinterval dcwsb exch out exch put
        e1dcws e1ecws getinterval ecwsb exch out exch put
        /in in e1dcws add def  /out out 1 add def
    } repeat
    e2nb {
        cws in e2dcws getinterval e2ecws 256 355 rscodes
        dup 0 e2dcws getinterval dcwsb exch out exch put
        e2dcws e2ecws getinterval ecwsb exch out exch put
        /in in e2dcws add def  /out out 1 add def
    } repeat
    e3nb {
        cws in e3dcws getinterval e3ecws 256 355 rscodes
        dup 0 e3dcws getinterval dcwsb exch out exch put
        e3dcws e3ecws getinterval ecwsb exch out exch put
        /in in e3dcws add def  /out out 1 add def
    } repeat

    % Reassemble the codewords
    /cws ncws array def
    /cw 0 def
    0 1 dcwsb length 1 sub {
        /i exch def
        dcwsb i get dup cws exch cw exch putinterval length cw add /cw exch def
        ecwsb i get dup cws exch cw exch putinterval length cw add /cw exch def
    } for

    % Split codewords into groups of 13 and concatenate
    /cws [
        0 1 ncws 1 sub 12 2 copy gt {exch} if pop {
            13 ncws 1 sub { dup ncws lt {cws exch get} {pop} ifelse } for
        } for
    ] def

    % Extend codewords by one if there are remainder bits
    rbit 0 gt {
        /pad cws length 1 add array def
        pad 0 cws putinterval
        pad pad length 1 sub 0 put
        /cws pad def
    } if

    % Create the bitmap
    /pixs [ size size mul {-1} repeat ] def
    /qmv {size mul add} def

    % Alignment patterns
    alnn 0 ne {
        /trmv {size mul size add 1 sub exch sub} def
        /aplot {
            3 1 roll 3 copy exch trmv pixs exch 3 -1 roll put
            trmv pixs exch 3 -1 roll put
        } def
        /i 0 def /stag 0 def {
            i size ge {exit} if
            0 1 size 1 sub {
                /j exch def
                j alnr add size lt {
                    j alnk idiv stag add 2 mod 0 eq   % Staggered groups of k modules
                    i 0 eq j alnk lt and not and      % Keep clear at top right
                    j alnk mod 0 eq or                % Complete regular-spaced grid
                } {
                    alnn stag add 2 mod 0 eq          % Bottom right remainder
                } ifelse
                {
                    j i 1 aplot
                    j 1 add i 1 add 2 copy size lt exch size lt and {0 aplot} {pop pop} ifelse
                } if
            } for
            i alnr add size eq {
                /i i alnr add 1 sub def
            } {
                /i i alnk add def
            } ifelse
            /stag 1 stag sub def
        } loop
        alnk alnk size 2 sub {
            /i exch def
            i alnk idiv 2 mod 0 ne {
                pixs 0 i 1 sub trmv 0 put
                pixs 0 i 1 add trmv 0 put
                pixs 1 i 1 sub trmv 0 put
                pixs 1 i trmv 0 put
                pixs 1 i 1 add trmv 0 put
                pixs i 1 sub 0 trmv 0 put
                pixs i 1 add 0 trmv 0 put
                pixs i 1 sub 1 trmv 0 put
                pixs i 1 trmv 0 put
                pixs i 1 add 1 trmv 0 put
            } if
            pixs size 1 sub i 1 sub trmv get 1 ne {
                pixs size 1 sub i 1 sub trmv 0 put
                pixs size 2 sub i 1 sub trmv 0 put
                pixs size 2 sub i trmv 0 put
                pixs size 2 sub i 1 add trmv 0 put
                pixs size 1 sub i 1 add trmv 0 put
                pixs i 1 sub size 1 sub trmv 0 put
                pixs i 1 sub size 2 sub trmv 0 put
                pixs i size 2 sub trmv 0 put
                pixs i 1 add size 2 sub trmv 0 put
                pixs i 1 add size 1 sub trmv 0 put
            } if
        } for
    } if

    % Finder patterns
{
    /fpat [
        [ 1 1 1 1 1 1 1 0 ]
        [ 1 0 0 0 0 0 0 0 ]
        [ 1 0 1 1 1 1 1 0 ]
        [ 1 0 1 0 0 0 0 0 ]
        [ 1 0 1 0 1 1 1 0 ]
        [ 1 0 1 0 1 1 1 0 ]
        [ 1 0 1 0 1 1 1 0 ]
        [ 0 0 0 0 0 0 0 0 ]
    ] def
    /fpat2 [
        [ 1 1 1 0 1 0 1 0 ]
        [ 1 1 1 0 1 0 1 0 ]
        [ 1 1 1 0 1 0 1 0 ]
        [ 0 0 0 0 1 0 1 0 ]
        [ 1 1 1 1 1 0 1 0 ]
        [ 0 0 0 0 0 0 1 0 ]
        [ 1 1 1 1 1 1 1 0 ]
        [ 0 0 0 0 0 0 0 0 ]
    ] def
} ctxdef
    0 1 fpat length 1 sub {
        /y exch def
        0 1 fpat 0 get length 1 sub {
            /x exch def
            /fpb fpat y get x get def
            /fpb2 fpat2 y get x get def
            pixs x y qmv fpb put
            pixs size x sub 1 sub y qmv fpb put
            pixs size x sub 1 sub size y sub 1 sub qmv fpb put
            pixs x size y sub 1 sub qmv fpb2 put
        } for
    } for

    % Format information modules
    /functionmap [
        [ [ 0 8 ] [ size 1 sub size 9 sub ] ]  [ [ 1 8 ] [ size 2 sub size 9 sub ] ]
        [ [ 2 8 ] [ size 3 sub size 9 sub ] ]  [ [ 3 8 ] [ size 4 sub size 9 sub ] ]
        [ [ 4 8 ] [ size 5 sub size 9 sub ] ]  [ [ 5 8 ] [ size 6 sub size 9 sub ] ]
        [ [ 6 8 ] [ size 7 sub size 9 sub ] ]  [ [ 7 8 ] [ size 8 sub size 9 sub ] ]
        [ [ 8 8 ] [ size 9 sub size 9 sub ] ]
        [ [ 8 7 ] [ size 9 sub size 8 sub ] ]  [ [ 8 6 ] [ size 9 sub size 7 sub ] ]
        [ [ 8 5 ] [ size 9 sub size 6 sub ] ]  [ [ 8 4 ] [ size 9 sub size 5 sub ] ]
        [ [ 8 3 ] [ size 9 sub size 4 sub ] ]  [ [ 8 2 ] [ size 9 sub size 3 sub ] ]
        [ [ 8 1 ] [ size 9 sub size 2 sub ] ]  [ [ 8 0 ] [ size 9 sub size 1 sub ] ]
        [ [ size 9 sub 0 ] [ 8 size 1 sub ] ]  [ [ size 9 sub 1 ] [ 8 size 2 sub ] ]
        [ [ size 9 sub 2 ] [ 8 size 3 sub ] ]  [ [ size 9 sub 3 ] [ 8 size 4 sub ] ]
        [ [ size 9 sub 4 ] [ 8 size 5 sub ] ]  [ [ size 9 sub 5 ] [ 8 size 6 sub ] ]
        [ [ size 9 sub 6 ] [ 8 size 7 sub ] ]  [ [ size 9 sub 7 ] [ 8 size 8 sub ] ]
        [ [ size 9 sub 8 ] [ 8 size 9 sub ] ]
        [ [ size 8 sub 8 ] [ 7 size 9 sub ] ]  [ [ size 7 sub 8 ] [ 6 size 9 sub ] ]
        [ [ size 6 sub 8 ] [ 5 size 9 sub ] ]  [ [ size 5 sub 8 ] [ 4 size 9 sub ] ]
        [ [ size 4 sub 8 ] [ 3 size 9 sub ] ]  [ [ size 3 sub 8 ] [ 2 size 9 sub ] ]
        [ [ size 2 sub 8 ] [ 1 size 9 sub ] ]  [ [ size 1 sub 8 ] [ 0 size 9 sub ] ]
    ] def
    functionmap {
        { {} forall qmv pixs exch 0 put } forall
    } forall

    /maskfuncs [
        {pop pop 1} bind
        {add 2 mod} bind
        {1 index add 3 mod exch 3 mod add 2 mod} bind
        {2 copy mod 3 1 roll 2 copy exch mod 3 1 roll 3 mod exch 3 mod
         add add add 2 mod} bind
    ] def
    mask -1 ne {  % User specifies a mask
        /maskfuncs [maskfuncs mask 1 sub get] def
        /bestmaskval mask 1 sub def
    } if
    /masks maskfuncs length array def
    0 1 masks length 1 sub {
        /m exch def
        /mask size size mul array def
        0 1 size 1 sub {
            /j exch def
            0 1 size 1 sub {
                /i exch def
                i 1 add j 1 add maskfuncs m get exec 0 eq
                pixs i j qmv get -1 eq and {1} {0} ifelse
                mask i j qmv 3 -1 roll put
            } for
        } for
        masks m mask put
    } for

    % Walk the symbol placing the bitstream
    /posx 0 def
    /posy 0 def
    /num 0 def
    { % loop
        posy size eq {exit} if
        pixs posx posy qmv get -1 eq {
            cws num 8 idiv get 7 num 8 mod sub neg bitshift 1 and
            pixs posx posy qmv 3 -1 roll put
            /num num 1 add def
        } if
        /posx posx 1 add def
        posx size eq {/posx 0 def /posy posy 1 add def} if
    } loop

    % Evaluate runlength encoded rows or columns in full symbols
    /evalfulln1n3 {
        /scrle exch def
        % Detect runs of 3 or more like modules
        /scr1 0 scrle { dup 3 ge {4 mul add dup} if pop } forall def
        /scr3 0 def
        % Detect 1:1:1:1:3 ratio next to 3 modules of whitespace
        5 2 scrle length 1 sub {  % Scan odd (dark) runs within bounds
            /j exch def
            scrle j get 3 mod 0 eq {  % Multiple of 3 black modules
                /fact scrle j get 3 idiv def
                scrle j 4 sub 4 getinterval {fact eq} forall and and and {
                    j 5 eq j 2 add scrle length ge or {  % At either extent of run
                        /scr3 scr3 50 add def
                    } {  % Bounded by dark modules
                        scrle j 5 sub get 3 ge scrle j 1 add get 3 ge or {
                            /scr3 scr3 50 add def
                        } if
                    } ifelse
                } if
            } if
        } for
        % Detect 3:1:1:1:1 ratio next to 3 modules of whitespace
        1 2 scrle length 5 sub {  % Scan odd (dark) runs within bounds
            /j exch def
            scrle j get 3 mod 0 eq {  % Multiple of 3 black modules
                /fact scrle j get 3 idiv def
                scrle j 1 add 4 getinterval {fact eq} forall and and and {
                    j 1 eq j 6 add scrle length ge or {  % At either extent of run
                        /scr3 scr3 50 add def
                    } {  % Bounded by dark modules
                        scrle j 1 sub get 3 ge scrle j 5 add get 3 ge or {
                            /scr3 scr3 50 add def
                        } if
                    } ifelse
                } if
            } if
        } for
        scr1 scr3
    } def

    % Evaluation algorithm
    /evalfull {
        /sym exch def

        /n1 0 def /n3 0 def
        /rle size 1 add array def
        /lastpairs size array def
        /thispairs size array def
        /sizeadd1 size 1 add def
        0 1 size 1 sub {
            /i exch def

            % Runlength encode (light, dark, light, ...) and evaluate each column
            mark 0 0
            i size dup dup mul 1 sub {
                sym exch get exch 1 index eq {exch 1 add exch} {1 exch} ifelse
            } for
            pop
            rle 0 counttomark 2 sub getinterval astore
            evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def
            pop

            % Runlength encode (light, dark, light, ...) and evaluate each row
            /symrow sym i size mul size getinterval def
            mark 0 0
            symrow {
                exch 1 index eq {exch 1 add exch} {1 exch} ifelse
            } forall
            pop
            rle 0 counttomark 2 sub getinterval astore
            evalfulln1n3 n3 add /n3 exch def n1 add /n1 exch def
            pop

        } for

        n1 n3 add
    } def

    % Evaluate the masked symbols to find the most suitable
    /bestscore 999999999 def
    0 1 masks length 1 sub {
        /m exch def
        /masksym size size mul array def
        0 1 size size mul 1 sub {
            /i exch def
            masksym i pixs i get masks m get i get xor put
        } for
        masks length 1 ne {
            masksym evalfull /score exch def
            score bestscore lt {
                /bestsym masksym def
                /bestmaskval m def
                /bestscore score def
            } if
        } {
            /bestsym masksym def
        } ifelse
    } for
    /pixs bestsym def

    % Add the function information
    /funval size 21 sub 2 idiv 20 add 4 mul eclval add 4 mul bestmaskval add def
    [ funval 16#0F00 and -8 bitshift
      funval 16#00F0 and -4 bitshift
      funval 16#000F and ]
    4 16 19 rscodes /funvals exch def
    /funbits [
        funvals {
            4 tobin {48 sub} forall
        } forall
        0 1 0 1 0 1
    ] def
    0 1 functionmap length 1 sub {
        /i exch def
        functionmap i get {
            pixs exch aload pop qmv funbits i get put
        } forall
    } for

    % Return the arguments
    <<
    /ren //renmatrix
    /pixs pixs
    /pixx size
    /pixy size
    /height size 2 mul 72 div
    /width size 2 mul 72 div
    /opt options
    >>

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/hanxin dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER hanxin--

% --BEGIN ENCODER dotcode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: DotCode
% --EXAM: This is DotCode
% --EXOP: inkspread=0.16
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp dotcode 0.0 2022082100 238866 247484
%%BeginData:       1067 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/dotcode {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /rows -1 def
    /columns -1 def
    /ratio -1 def
    /parse false def
    /parsefnc false def
    /raw false def
    /fast false def
    /mask -1 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

    /rows rows cvi def
    /columns columns cvi def
    /ratio ratio cvr def
    /mask mask cvi def

    /dotcode //loadctx exec

    % Set the ratio to 3:2 if no size is specified
    ratio -1 eq rows -1 eq and columns -1 eq and {
        /ratio 3 2 div def
    } if

    % Convert input into bytes accounting for FNC characters
{
    /laa  -1 def  /lab  -2 def  /lac  -3 def  /bin  -4 def
    /sfa  -5 def  /sfb  -6 def  /sb2  -7 def  /sb3  -8 def
    /sb4  -9 def  /sb5 -10 def  /sb6 -11 def  /sfc -12 def
    /sc2 -13 def  /sc3 -14 def  /sc4 -15 def  /sc5 -16 def
    /sc6 -17 def  /sc7 -18 def  /bsa -19 def  /bsb -20 def
    /tma -21 def  /tmb -22 def  /tmc -23 def  /tms -24 def
    /fn1 -25 def  /fn2 -26 def  /fn3 -27 def  /crl -28 def
    /aim -29 def  /m05 -30 def  /m06 -31 def  /m12 -32 def
    /mac -33 def
} ctxdef

    % Parse the input
    /fncvals <<
        /parse parse
        /parsefnc parsefnc
        /eci true
        (FNC1) fn1
        % (FNC2) fn2  %  Use ^ECInnnnnn for ECI; Structured append not supported
        (FNC3) fn3
    >> def
    /msg barcode fncvals //parseinput exec def
    /msglen msg length def

    % Special FNC2 semantics: Expand ECI characters into ^FNC2nnnnnn
    /numecis 0 msg { -1000000 le {1 add} if } forall def
    /msgtmp msg length numecis 6 mul add array def
    /j 0 def
    0 1 msg length 1 sub {
        msg exch get dup -1000000 le {
            neg 10 7 string cvrs 1 6 getinterval {} forall 6 array astore
            msgtmp exch j 1 add exch putinterval
            msgtmp j fn2 put
            /j j 7 add def
        } {
            msgtmp exch j exch put
            /j j 1 add def
        } ifelse
    } for
    /msg msgtmp def
    /msglen msg length def

    % Character maps for each state
{
   /charmaps [
      %  A    B    C         A    B    C         A    B    C
      [  32   32  (00) ]  [ (!)  (!)  (01) ]  [ (")  (")  (02) ]  % 0-2
      [ (#)  (#)  (03) ]  [ ($)  ($)  (04) ]  [ (%)  (%)  (05) ]  % 3-5
      [ (&)  (&)  (06) ]  [ (')  (')  (07) ]  [  40   40  (08) ]  % 6-8
      [  41   41  (09) ]  [ (*)  (*)  (10) ]  [ (+)  (+)  (11) ]  % 9-11
      [ (,)  (,)  (12) ]  [ (-)  (-)  (13) ]  [ (.)  (.)  (14) ]  % 12-14
      [ (/)  (/)  (15) ]  [ (0)  (0)  (16) ]  [ (1)  (1)  (17) ]  % 15-17
      [ (2)  (2)  (18) ]  [ (3)  (3)  (19) ]  [ (4)  (4)  (20) ]  % 18-20
      [ (5)  (5)  (21) ]  [ (6)  (6)  (22) ]  [ (7)  (7)  (23) ]  % 21-23
      [ (8)  (8)  (24) ]  [ (9)  (9)  (25) ]  [ (:)  (:)  (26) ]  % 24-26
      [ (;)  (;)  (27) ]  [ (<)  (<)  (28) ]  [ (=)  (=)  (29) ]  % 27-29
      [ (>)  (>)  (30) ]  [ (?)  (?)  (31) ]  [ (@)  (@)  (32) ]  % 30-32
      [ (A)  (A)  (33) ]  [ (B)  (B)  (34) ]  [ (C)  (C)  (35) ]  % 33-35
      [ (D)  (D)  (36) ]  [ (E)  (E)  (37) ]  [ (F)  (F)  (38) ]  % 36-38
      [ (G)  (G)  (39) ]  [ (H)  (H)  (40) ]  [ (I)  (I)  (41) ]  % 39-41
      [ (J)  (J)  (42) ]  [ (K)  (K)  (43) ]  [ (L)  (L)  (44) ]  % 42-44
      [ (M)  (M)  (45) ]  [ (N)  (N)  (46) ]  [ (O)  (O)  (47) ]  % 45-47
      [ (P)  (P)  (48) ]  [ (Q)  (Q)  (49) ]  [ (R)  (R)  (50) ]  % 48-50
      [ (S)  (S)  (51) ]  [ (T)  (T)  (52) ]  [ (U)  (U)  (53) ]  % 51-53
      [ (V)  (V)  (54) ]  [ (W)  (W)  (55) ]  [ (X)  (X)  (56) ]  % 54-56
      [ (Y)  (Y)  (57) ]  [ (Z)  (Z)  (58) ]  [ ([)  ([)  (59) ]  % 57-59
      [  92   92  (60) ]  [ (])  (])  (61) ]  [ (^)  (^)  (62) ]  % 60-62
      [ (_)  (_)  (63) ]  [   0  (`)  (64) ]  [   1  (a)  (65) ]  % 63-65
      [   2  (b)  (66) ]  [   3  (c)  (67) ]  [   4  (d)  (68) ]  % 66-68
      [   5  (e)  (69) ]  [   6  (f)  (70) ]  [   7  (g)  (71) ]  % 69-71
      [   8  (h)  (72) ]  [   9  (i)  (73) ]  [  10  (j)  (74) ]  % 72-74
      [  11  (k)  (75) ]  [  12  (l)  (76) ]  [  13  (m)  (77) ]  % 75-77
      [  14  (n)  (78) ]  [  15  (o)  (79) ]  [  16  (p)  (80) ]  % 78-80
      [  17  (q)  (81) ]  [  18  (r)  (82) ]  [  19  (s)  (83) ]  % 81-83
      [  20  (t)  (84) ]  [  21  (u)  (85) ]  [  22  (v)  (86) ]  % 84-86
      [  23  (w)  (87) ]  [  24  (x)  (88) ]  [  25  (y)  (89) ]  % 87-89
      [  26  (z)  (90) ]  [  27  ({)  (91) ]  [  28  (|)  (92) ]  % 90-92
      [  29  (})  (93) ]  [  30  (~)  (94) ]  [  31  127  (95) ]  % 93-95
      [ sfb  crl  (96) ]  [ sb2    9  (97) ]  [ sb3   28  (98) ]  % 96-98
      [ sb4   29  (99) ]  [ sb5   30  aim  ]  [ sb6  sfa  laa  ]  % 99-101
      [ lab  laa  sfb  ]  [ sc2  sc2  sb2  ]  [ sc3  sc3  sb3  ]  % 102-104
      [ sc4  sc4  sb4  ]  [ lac  lac  lab  ]  [ fn1  fn1  fn1  ]  % 105-107
      [ fn2  fn2  fn2  ]  [ fn3  fn3  fn3  ]  [ bsa  bsa  bsa  ]  % 108-110
      [ bsb  bsb  bsb  ]  [ bin  bin  bin  ]                      % 111-112
    ] def

    % Invert charmaps to give character to value maps for each state
    /charvals [ 113 dict 117 dict 113 dict ] def
    0 1 charmaps length 1 sub {
        /i exch def
        /encs charmaps i get def
        0 1 2 {
            /j exch def
            encs j get dup type /stringtype eq {0 get} if  % convert string to ASCII if required
            charvals j get exch i put
        } for
    } for
    /Avals charvals 0 get def
    /Bvals charvals 1 get def
    Bvals m05  97 put
    Bvals m06  98 put
    Bvals m12  99 put
    Bvals mac 100 put
    /Cvals charvals 2 get def
    /BINvals <<
        102 [ sc2 sc3 sc4 sc5 sc6 sc7 tma tmb tmc tms ] {exch 1 add dup} forall pop
    >> def

    /A 0 def  /B 1 def  /C 2 def  /BIN 3 def
} ctxdef

    % Pre-compute properties of the input at each point
    /nDigits      [ msglen 1 add {0} repeat     ] def
    /SeventeenTen [ msglen 1 add {false} repeat ] def
    /ECI          [ msglen 1 add {false} repeat ] def
    /DatumA       [ msglen 1 add {false} repeat ] def
    /DatumB       [ msglen 1 add {false} repeat ] def
    /DatumC       [ msglen 1 add {false} repeat ] def
    /Binary       [ msglen 8 add {false} repeat ] def
    /AheadC       [ msglen 1 add {0} repeat     ] def
    /TryC         [ msglen 1 add {0} repeat     ] def
    /AheadA       [ msglen 1 add {0} repeat     ] def
    /AheadB       [ msglen 1 add {0} repeat     ] def
    /UntilEndSeg  [ msglen 1 add {0} repeat     ] def
    msglen 1 sub -1 0 {
        /i exch def
        /barchar msg i get def
        barchar 48 ge barchar 57 le and {
            nDigits i nDigits i 1 add get 1 add put
        } if
        Avals barchar known {DatumA i true put} if
        Bvals barchar known {DatumB i true put} if
        /CRLF false def
        barchar 13 eq i msglen 1 sub lt and {
            msg i 1 add get 10 eq {/CRLF true def} if
        } if
        CRLF {DatumB i true put} if
        nDigits i get 2 ge  {DatumC i true put} if
        barchar 0 lt        {DatumC i true put} if  % FNCx
        barchar 128 ge      {Binary i true put} if
        nDigits i get 10 ge {  % 17xxxxxx10
            mark
            msg i 10 getinterval aload pop
            1 {  % common exit
                48 ne {false exit} if
                49 ne {false exit} if
                pop pop pop pop pop pop
                55 ne {false exit} if
                49 ne {false exit} if
                true
            } repeat
            SeventeenTen i 3 -1 roll put
            cleartomark
        } if
        nDigits i 1 add get 6 ge msg i get fn2 eq and {  % ^FNC2xxxxxx
            ECI i true put
        } if
        barchar 0 lt barchar fn3 ne and {  % FNCx, except FNC3
            AheadC i AheadC i 1 add get 1 add put
        } {
            nDigits i get 1 le {
                AheadC i 0 put
            } {
                AheadC i AheadC i 2 add get 1 add put
            } ifelse
        } ifelse
        nDigits i get 0 gt AheadC i get AheadC i 1 add get gt and {
            TryC i AheadC i get put
        } if
        DatumA i get TryC i get 2 lt and barchar fn3 ne and {
            AheadA i AheadA i 1 add get 1 add put
        } if
        DatumB i get TryC i get 2 lt and barchar fn3 ne and {
            AheadB i AheadB i 1 add CRLF {1 add} if get 1 add put
        } if
        barchar fn3 ne {
            UntilEndSeg i UntilEndSeg i 1 add get 1 add put
        } if
    } for

    /addtocws {
        dup cws exch j exch putinterval
        /j exch length j add def
    } def

    % Base 259 to one more in base 103
    /base259to103 {
        /in exch def
        /inlen in length def
        /in [ 5 inlen sub {0} repeat in aload pop ] def
        /out 6 array def
        /msbs [ in 0 2 getinterval aload pop ] def
        /mscs [
            msbs aload pop exch 259 mul add
            2 {dup 103 mod exch 103 idiv} repeat
        ] def
        /lsbs [ in 2 3 getinterval aload pop ] def
        /lscs [
            lsbs aload pop exch 259 mul add exch 67081 mul add
            3 {dup 103 mod exch 103 idiv} repeat
        ] def
        lscs 0 get mscs 0 get 42 mul add
        out 5 2 index 103 mod put
        103 idiv lscs 1 get add mscs 0 get 68 mul add mscs 1 get 42 mul add
        out 4 2 index 103 mod put
        103 idiv lscs 2 get add mscs 0 get 92 mul add mscs 1 get 68 mul add mscs 2 get 42 mul add
        out 3 2 index 103 mod put
        103 idiv lscs 3 get add mscs 0 get 15 mul add mscs 1 get 92 mul add mscs 2 get 68 mul add
        out 2 2 index 103 mod put
        103 idiv mscs 1 get 15 mul add mscs 2 get 92 mul add
        out 1 2 index 103 mod put
        103 idiv mscs 2 get 15 mul add
        out 0 3 -1 roll 103 mod put
        out 6 inlen sub 1 sub inlen 1 add getinterval
    } def

    /finaliseBIN {
        bpos 0 ne {
            bvals 0 bpos getinterval base259to103 aload pop
            /bpos 0 def
        } if
    } def

    /addtobin {
        bvals exch bpos exch put
        /bpos bpos 1 add def
        bpos 5 eq { finaliseBIN } if
    } def

    /ECIabc {  % ECI encoding for modes A, B and C
        msg i 1 add 6 getinterval 0 exch {48 sub add 10 mul} forall 10 idiv
        dup 40 ge {
            40 sub
            dup 12769 idiv 40 add exch 12769 mod
            dup   113 idiv        exch   113 mod
        } if
    } def

    /ECIbin {  % ECI encoding for binary mode
        [
            msg i 1 add 6 getinterval 0 exch {48 sub add 10 mul} forall 10 idiv
            dup 65536 ge {
                258 exch dup 65536 idiv exch 65536 mod dup 256 idiv exch 256 mod
            } {
                dup 256 ge {
                    257 exch dup 256 idiv exch 256 mod
                } {
                    256 exch
                } ifelse
            } ifelse
        ] {
            addtobin
        } forall
    } def

    /encC {
        1 {  % Common exit
            i segstart eq {  % Structured data macros
                1 {  % common exit
                    i segend 7 sub gt {0 exit} if
                    msg segstart       get 91 ne {0 exit} if                    % [
                    msg segstart 1 add get 41 ne {0 exit} if                    % )
                    msg segstart 2 add get 62 ne {0 exit} if                    % >
                    msg segstart 3 add get 30 ne {0 exit} if                    % {RS}
                    msg segstart 4 add get dup 48 lt exch 57 gt or {0 exit} if  % digit
                    msg segstart 5 add get dup 48 lt exch 57 gt or {0 exit} if  % digit
                    msg segend   1 sub get  4 ne {0 exit} if                    % End: {EOT}
                    msg segstart 4 add get 48 sub 10 mul msg segstart 5 add get 48 sub add
                    dup dup 05 ne exch dup 06 ne exch 12 ne and and {pop mac exit} if
                    msg segstart 6 add get 29 ne {pop 0 exit} if                % {GS}
                    msg segend   2 sub get 30 ne {pop 0 exit} if                % End: {RS}
                    dup 05 eq {pop m05 exit} if
                        06 eq {    m06 exit} if
                                   m12 exit
                } repeat
                /inmac exch def
                inmac 0 ne {
                    [ Cvals lab get ] addtocws
                    /mode B def
                    [ Bvals inmac get ] addtocws
                    inmac mac eq {
                        [ Bvals msg segstart 4 add get get ] addtocws
                        [ Bvals msg segstart 5 add get get ] addtocws
                        /i i 6 add def
                    } {
                        /i i 7 add def
                    } ifelse
                    exit
                } if
            } if
            % Special treatment of FNC1 in First for Dotcode
            i segstart eq {
                % Encode an FNC1 if two digits start a segment
                nDigits i get 2 ge {
                    [ Cvals fn1 get ] addtocws
                } if
                % Skip an FNC1 if followed by two digits at start of segment
                msg i get fn1 eq nDigits i 1 add get 2 ge and {
                    /i i 1 add def
                } if
            } if
            SeventeenTen i get {
                [  % 17xxxxxx10 macro
                    Cvals aim get
                    msg i 2 add get 48 sub 10 mul msg i 3 add get 48 sub add
                    msg i 4 add get 48 sub 10 mul msg i 5 add get 48 sub add
                    msg i 6 add get 48 sub 10 mul msg i 7 add get 48 sub add
                ] addtocws
                /i i 10 add def
                exit
            } if
            DatumC i get {
                msg i get dup fn1 eq exch dup fn2 eq exch fn3 eq or or {  % FNCx
                    [ Cvals msg i get get ] addtocws
                    ECI i get {  % FNC2 then 6 digits
                        [ ECIabc ] addtocws
                        /i i 7 add def
                        exit
                    } if
                    msg i get fn3 eq segstart i ne and {  % FNC3
                        /i i 1 add def
                        /inmac 0 def
                        /segstart i def
                        /segend i UntilEndSeg i get add def
                        exit
                    } if
                    /i i 1 add def
                    exit
                } if
                [ msg i get 48 sub 10 mul msg i 1 add get 48 sub add ] addtocws
                /i i 2 add def
                exit
            } if
            Binary i get {  % Binary
                nDigits i 1 add get 0 gt {
                    msg i get 160 lt {
                        [ Cvals bsa get Avals msg i get 128 sub get ] addtocws
                    } {
                        [ Cvals bsb get Bvals msg i get 128 sub get ] addtocws
                    } ifelse
                    /i i 1 add def
                    exit
                } if
                [ Cvals bin get ] addtocws
                /mode BIN def
                exit
            } if
            /m AheadA i get def  /n AheadB i get def
            m n gt {
                [ Cvals laa get ] addtocws
                /mode A def
                exit
            } if
            i segstart eq {
                msg i get dup 9 eq exch dup 28 eq exch dup 29 eq exch 30 eq or or or {
                    [ Cvals laa get ] addtocws
                    /mode A def
                    exit
                } if
            } if
            n 4 gt {
                [ Cvals lab get ] addtocws
                /mode B def
                exit
            } if
            [ Cvals [ sfb sb2 sb3 sb4 ] n 1 sub get get ] addtocws
            n {
                msg i get 13 eq {
                    [ Bvals crl get ] addtocws
                    /i i 2 add def
                } {
                    [ Bvals msg i get get ] addtocws
                    /i i 1 add def
                } ifelse
            } repeat
            exit
        } repeat
    } def  % encC

    /encB {
        1 {  % Common exit
            /n TryC i get def
            n 2 ge {
                n 4 gt {
                    [ Bvals lac get ] addtocws
                    /mode C def
                    exit
                } if
                [ Bvals [ sfc sc2 sc3 sc4 ] n 1 sub get get ] addtocws
                n {
                    msg i get 0 lt {
                        [ Cvals msg i get get ] addtocws
                        /i i 1 add def
                    } {
                        [ msg i get 48 sub 10 mul msg i 1 add get 48 sub add ] addtocws
                        /i i 2 add def
                    } ifelse
                } repeat
                exit
            } if
            DatumB i get {
                msg i get dup fn1 eq exch dup fn2 eq exch fn3 eq or or {  % FNCx
                    [ Bvals msg i get get ] addtocws
                    ECI i get {  % FNC2 then 6 digits
                        [ ECIabc ] addtocws
                        /i i 7 add def
                        exit
                    } if
                    msg i get fn3 eq i segstart ne and {  % FNC3
                        /i i 1 add def
                        /mode C def
                        /inmac 0 def
                        /segstart i def
                        /segend i UntilEndSeg i get add def
                        exit
                    } if
                    /i i 1 add def
                    exit
                } if
                msg i get 13 eq i msglen 1 sub lt and {
                    msg i 1 add get 10 eq {  % CRLF
                        [ Bvals crl get ] addtocws
                        /i i 2 add def
                        exit
                    } if
                } if
                [ Bvals msg i get get ] addtocws
                /i i 1 add def
                exit
            } if
            Binary i get {  % Binary
                DatumB i 1 add get {
                    msg i get 160 lt {
                        [ Bvals bsa get Avals msg i get 128 sub get ] addtocws
                    } {
                        [ Bvals bsb get Bvals msg i get 128 sub get ] addtocws
                    } ifelse
                    /i i 1 add def
                    exit
                } if
                [ Bvals bin get ] addtocws
                /mode BIN def
                exit
            } if
            AheadA i get 1 eq {
                [ Bvals sfa get Avals msg i get get ] addtocws
                /i i 1 add def
                exit
            } if
            [ Bvals laa get ] addtocws
            /mode A def
            exit
        } repeat
    } def

    /encA {
        1 {  % Common exit
            /n TryC i get def
            n 2 ge {
                n 4 gt {
                    [ Avals lac get ] addtocws
                    /mode C def
                    exit
                } if
                [ Avals [ sfc sc2 sc3 sc4 ] n 1 sub get get ] addtocws
                n {
                    msg i get 0 lt {
                        [ Cvals msg i get get ] addtocws
                        /i i 1 add def
                    } {
                        [ msg i get 48 sub 10 mul msg i 1 add get 48 sub add ] addtocws
                        /i i 2 add def
                    } ifelse
                } repeat
                exit
            } if
            DatumA i get {
                msg i get dup fn1 eq exch dup fn2 eq exch fn3 eq or or {  % FNCx
                    [ Avals msg i get get ] addtocws
                    ECI i get {  % FNC2 then 6 digits
                        [ ECIabc ] addtocws
                        /i i 7 add def
                        exit
                    } if
                    msg i get fn3 eq i segstart ne and {  % FNC3
                        /i i 1 add def
                        /mode C def
                        /inmac 0 def
                        /segstart i def
                        /segend i UntilEndSeg i get add def
                        exit
                    } if
                    /i i 1 add def
                    exit
                } if
                [ Avals msg i get get ] addtocws
                /i i 1 add def
                exit
            } if
            Binary i get {  % Binary
                DatumA i 1 add get {
                    msg i get 160 lt {
                        [ Avals bsa get Avals msg i get 128 sub get ] addtocws
                    } {
                        [ Avals bsb get Bvals msg i get 128 sub get ] addtocws
                    } ifelse
                    /i i 1 add def
                    exit
                } if
                [ Avals bin get ] addtocws
                /mode BIN def
                exit
            } if
            /n AheadB i get def
            n 6 gt {
                [ Avals lab get ] addtocws
                /mode B def
                exit
            } if
            [ Avals [ sfb sb2 sb3 sb4 sb5 sb6 ] n 1 sub get get ] addtocws
            n {
                msg i get 13 eq {
                    [ Bvals crl get ] addtocws
                    /i i 2 add def
                } {
                    [ Bvals msg i get get ] addtocws
                    /i i 1 add def
                } ifelse
            } repeat
            exit
        } repeat
    } def

    /encBIN {
        1 {  % Common exit
            /n TryC i get def
            n 2 ge {
                [ finaliseBIN ] addtocws
                n 7 gt {  % Terminate to C
                    [ BINvals tmc get ] addtocws
                    /mode C def
                    exit
                } if
                [ BINvals [ sc2 sc3 sc4 sc5 sc6 sc7 ] n 2 sub get get ] addtocws
                n {
                    msg i get 0 lt {
                        [ Cvals msg i get get ] addtocws
                        /i i 1 add def
                    } {
                        [ msg i get 48 sub 10 mul msg i 1 add get 48 sub add ] addtocws
                        /i i 2 add def
                    } ifelse
                } repeat
                exit
            } if
            ECI i get Binary i 7 add get and {  % ECI then binary
                [ ECIbin ] addtocws
                /i i 7 add def
                i msglen eq { [ finaliseBIN ] addtocws } if
                exit
            } if
            msg i get 0 ge {  % Not FNCx
                Binary i       get    Binary i 1 add get or
                Binary i 2 add get or Binary i 3 add get or
                ECI i 1 add get       Binary i 8 add get and or {
                    [ msg i get addtobin ] addtocws
                    /i i 1 add def
                    i msglen eq { [ finaliseBIN ] addtocws } if
                    exit
                } if
            } if
            [ finaliseBIN ] addtocws
            i msglen 1 sub ne {  % Not last character
                msg i get fn3 eq i segstart ne and {  % FNC3
                    [ BINvals tms get ] addtocws
                    /i i 1 add def
                    /mode C def
                    /inmac 0 def
                    /segstart i def
                    /segend i UntilEndSeg i get add def
                    exit
                } if
                AheadA i get AheadB i get gt {
                    [ BINvals tma get ] addtocws
                    /mode A def
                } {
                    [ BINvals tmb get ] addtocws
                    /mode B def
                } ifelse
                exit
            } if
            exit
        } repeat
    } def

    /cws msglen 2 mul 1 add array def
    /mode C def
    /bvals 5 array def  /bpos 0 def
    /inmac 0 def  /segstart 0 def  /segend UntilEndSeg 0 get def
    /i 0 def  /j 0 def  {
        i msglen ge {exit} if
        inmac 0 ne {  % Jump over macro trailers
            inmac mac ne i segend 2 sub eq and {  % {RS}{EOT}
                /i i 2 add def
                i msglen ge {exit} if
            } if
            inmac mac eq i segend 1 sub eq and {  % {EOT}
                /i i 1 add def
                i msglen ge {exit} if
            } if
        } if
        [ /encA /encB /encC /encBIN ] mode get load exec
    } loop
    /cws cws 0 j getinterval def

    % Determine the symbol size
    /nd cws length def
    /minarea nd 3 add nd 2 idiv add 9 mul 2 add 2 mul def
    ratio -1 ne {        % Fixed ratio
        /hgt minarea ratio div sqrt def
        /wid minarea ratio mul sqrt def
        /h hgt cvi def  /w wid cvi def
        h w add 2 mod 1 eq {
            h w mul minarea lt {/h h 1 add def  /w w 1 add def} if
        } {
            hgt w mul wid h mul lt {
                /w w 1 add def
                h w mul minarea lt {
                    /w w 1 sub def  /h h 1 add def
                    h w mul minarea lt {/w w 2 add def} if
                } if
            } {
                /h h 1 add def
                h w mul minarea lt {
                    /h h 1 sub def  /w w 1 add def
                    h w mul minarea lt {/h h 2 add def} if
                } if
            } ifelse
        } ifelse
        /rows h def  /columns w def
    } {
        columns -1 eq {  % Fixed height
            /columns minarea rows add 1 sub rows idiv dup rows add 2 mod 0 eq {1 add} if def
        } if
        rows -1 eq {     % Fixed width
            /rows minarea columns add 1 sub columns idiv dup columns add 2 mod 0 eq {1 add} if def
        } if
    } ifelse

    % Extend the codewords with padding
    /ndots rows columns mul 2 idiv def
    {
        nd 1 add dup 2 idiv 3 add add 9 mul 2 add ndots gt {exit} if
        /nd nd 1 add def
    } loop
    /nc nd 2 idiv 3 add def
    /nw nd nc add def
    /rembits ndots nw 9 mul 2 add sub def
    nd cws length gt {
        /cws [
            cws aload pop
            mode BIN eq {109} {106} ifelse
            nd cws length sub 1 sub {106} repeat
        ] def
    } if

    options /debugcws known { /bwipp.debugcws cws //raiseerror exec } if

    % Create an array containing the character mappings
{
    /encs [
        (101010101) (010101011) (010101101) (010110101) (011010101)
        (101010110) (101011010) (101101010) (110101010) (010101110)
        (010110110) (010111010) (011010110) (011011010) (011101010)
        (100101011) (100101101) (100110101) (101001011) (101001101)
        (101010011) (101011001) (101100101) (101101001) (110010101)
        (110100101) (110101001) (001010111) (001011011) (001011101)
        (001101011) (001101101) (001110101) (010010111) (010011011)
        (010011101) (010100111) (010110011) (010111001) (011001011)
        (011001101) (011010011) (011011001) (011100101) (011101001)
        (100101110) (100110110) (100111010) (101001110) (101011100)
        (101100110) (101101100) (101110010) (101110100) (110010110)
        (110011010) (110100110) (110101100) (110110010) (110110100)
        (111001010) (111010010) (111010100) (001011110) (001101110)
        (001110110) (001111010) (010011110) (010111100) (011001110)
        (011011100) (011100110) (011101100) (011110010) (011110100)
        (100010111) (100011011) (100011101) (100100111) (100110011)
        (100111001) (101000111) (101100011) (101110001) (110001011)
        (110001101) (110010011) (110011001) (110100011) (110110001)
        (111000101) (111001001) (111010001) (000101111) (000110111)
        (000111011) (000111101) (001001111) (001100111) (001110011)
        (001111001) (010001111) (011000111) (011100011) (011110001)
        (100011110) (100111100) (101111000) (110001110) (110011100)
        (110111000) (111000110) (111001100)
    ] def
} ctxdef

    % Final six dots arranged at edges
    rows 2 mod 0 eq {
        /sixedges [
            [ columns 1 sub  rows 2 sub ]
            [ 0              rows 2 sub ]
            [ columns 2 sub  rows 1 sub ]
            [ 1              rows 1 sub ]
            [ columns 1 sub  0          ]
            [ 0              0          ]
        ] def
    } {
        /sixedges [
            [ columns 2 sub  0          ]
            [ columns 2 sub  rows 1 sub ]
            [ columns 1 sub  1          ]
            [ columns 1 sub  rows 2 sub ]
            [ 0              0          ]
            [ 0              rows 1 sub ]
        ] def
    } ifelse

    /dmv {columns mul add} def

    % Construct the template
    /outline rows columns mul array def
    0 1 rows 1 sub {
        /y exch def
        0 1 columns 1 sub {
            /x exch def
            outline x y dmv x y add 2 mod 1 sub put
        } for
    } for
    sixedges {
        outline exch aload pop dmv 1 put
    } forall

    /clearcol {
        /x exch def
        true
        x 1 and 2 rows 1 sub {
            x exch dmv sym exch get 1 eq {pop false exit} if
        } for
    } def

    /clearrow {
        /y exch def
        true
        y 1 and 2 columns 1 sub {
            y dmv sym exch get 1 eq {pop false exit} if
        } for
    } def

    % Evaluate the symbol
    /evalsymbol {
        /sym exch def

        % Identify the worst side
        /worst 9999999 def
        [ [ /x 0 ] [ /x 1 ] [ /y 0 ] [ /y 1 ] ] {  % Top Bottom Left Right
            aload pop  /fl exch def  /dir exch def
            /sum 0 def  /first -1 def  /last -1 def
            0 1 dir /x eq {columns} {rows} ifelse 1 sub {
                dir exch def
                sym
                dir load
                dir /x eq {rows} {columns} ifelse 1 sub fl mul
                dir /y eq {exch} if
                dmv get 1 eq {
                    first -1 eq {/first dir load def} if
                    /last dir load def
                    /sum sum 1 add def
                } if
            } for
            sum last add first sub
            dir /x eq {rows} {columns} ifelse mul
            dup worst lt {/worst exch def} {pop} ifelse
        } forall

        /pen 0 def

        % Check for groups of blank columns unless data is encoded vertically
        % in a symbol of sufficient height to overcome up to six consecutive 0s
        % in two neighbouring 5 of 9 dot patterns
        rows 2 mod 1 eq rows 12 le or {
            /sum 0 def  /p 0 def
            1 1 columns 2 sub {
                clearcol {
                    /sum sum 1 add def
                    /p sum 1 eq {rows} {p rows mul} ifelse def
                } {
                    /sum 0 def
                    /pen pen p add def
                    /p 0 def
                } ifelse
            } for
            /pen pen p add def
        } if

        % Check for groups of blank rows unless data is encoded horizontally
        % in a symbol of sufficient width to overcome up to six consecutive 0s
        % in two neighbouring 5 of 9 dot patterns
        rows 2 mod 0 eq columns 12 le or {
            /sum 0 def  /p 0 def
            1 1 rows 2 sub {
                clearrow {
                    /sum sum 1 add def
                    /p sum 1 eq {columns} {p columns mul} ifelse def
                } {
                    /sum 0 def
                    /pen pen p add def
                    /p 0 def
                } ifelse
            } for
            /pen pen p add def
        } if

        % Pad twice on all sides
        /symp [
            columns 4 add 2 mul {0} repeat
            0 columns sym length 1 sub {
                0 exch 0 exch
                sym exch columns getinterval aload pop
                0 0
            } for
            columns 4 add 2 mul {0} repeat
        ] def

        % Count voids and isolated dots
        /columns columns 4 add def
        /rows    rows    4 add def
        /sum 0 def
        2 1 rows 3 sub {
            /y exch def
            y 1 and 2 add 2 columns 3 sub {
                /x exch def
                1 {  % Common exit
                    symp x 1 sub y 1 sub dmv get 1 eq {exit} if
                    symp x 1 add y 1 sub dmv get 1 eq {exit} if
                    symp x 1 sub y 1 add dmv get 1 eq {exit} if
                    symp x 1 add y 1 add dmv get 1 eq {exit} if
                    symp x y dmv get 0 eq {/sum sum 1 add def exit} if
                    symp x 2 sub y       dmv get 1 eq {exit} if
                    symp x       y 2 sub dmv get 1 eq {exit} if
                    symp x 2 add y       dmv get 1 eq {exit} if
                    symp x       y 2 add dmv get 1 eq {exit} if
                    /sum sum 1 add def
                } repeat
            } for
        } for
        /columns columns 4 sub def
        /rows    rows    4 sub def

        worst 0 eq {  % Fixed penalty to disqualify a symbol with an unlit edge
            -99999
        } {
            worst sum sum mul sub pen sub
        } ifelse

    } def

    % Reed Solomon antilog table
    /rsalog [ 1 112 { dup 3 mul 113 mod } repeat ] def
    /step nw 112 idiv 1 add def
    /offset {step mul start add} def

    % Evaluate the symbols in the following order:
    % fast mode: m3 -> m3' -> m2 -> m2' -> m1 -> m1' -> m0 -> m0'
    % dflt mode: (m0 m1 m2 m3) -> (m0' m1' m2' m3')
    % -> : Test if we have met the HxW/2 threshold
    % m' : Symbols with six edge dots forcibly lit
    % () : Best of
    /bestscore -99999999 def
    /masks mask -1 ne {
        [ mask ]
    } {
        fast { [ 2#11 2#10 2#01 2#00 ] } { [ 2#00 2#01 2#10 2#11 ] } ifelse
    } ifelse def
    /litmasks 4 array def
    masks {  % For each mask pattern

        /mask exch def

        % Calculate the error correction codewords for each block
        /rscws [
             mask
             [ 0 3 7 17 ] mask get 0 cws {1 index add 113 mod exch 2 index add exch 3 1 roll} forall pop pop
             nc {0} repeat
        ] def
        0 1 step 1 sub {
            /start exch def
            /ND nd 1 add start sub step add 1 sub step idiv def
            /NW nw 1 add start sub step add 1 sub step idiv def
            /NC NW ND sub def
            /coeffs [ 1 NC {0} repeat ] def
            1 1 NC {
                /i exch def
                NC -1 1 {
                    /j exch def
                    coeffs j coeffs j get 113 add rsalog i get coeffs j 1 sub get mul 113 mod sub 113 mod put
                } for
            } for
            0 1 ND 1 sub {
                /t exch rscws exch offset get rscws ND offset get add 113 mod def
                0 1 NC 2 sub {
                    /j exch def
                    rscws ND j add offset rscws ND j add 1 add offset get 113 add t coeffs j 1 add get mul 113 mod sub 113 mod put
                } for
                rscws ND NC add 1 sub offset 113 t coeffs NC get mul 113 mod sub 113 mod put
            } for
            ND 1 NW 1 sub { dup rscws exch offset 113 rscws 5 -1 roll offset get sub 113 mod put } for
        } for

        % Create the bitstream
        /bits ndots string def
        bits 0 [ (00) (01) (10) (11) ] mask get putinterval
        1 1 nw {
            /i exch def
            bits i 1 sub 9 mul 2 add encs rscws i get get putinterval
        } for
        rembits 0 gt {
            bits nw 9 mul 2 add (11111111111111111) 0 rembits getinterval putinterval
        } if

        % Walk the symbol placing the bitstream
        /pixs outline dup length array copy def
        /posx 0 def
        /posy rows 2 mod 0 eq {0} {rows 1 sub} ifelse def
        bits 0 bits length 6 sub getinterval {
            {  % Move to next vacant position
                pixs posx posy dmv get -1 eq {exit} if
                rows 2 mod 0 eq {
                    /posy posy 1 add def
                    posy rows eq {
                        /posy 0 def
                        /posx posx 1 add def
                    } if
                } {
                    /posx posx 1 add def
                    posx columns eq {
                        /posx 0 def
                        /posy posy 1 sub def
                    } if
                } ifelse
            } loop
            pixs posx posy dmv 3 -1 roll 48 sub put
        } forall
        0 1 5 {  % Last six edge dots
            /i exch def
            pixs sixedges i get aload pop dmv
            bits bits length 6 sub i add get 48 sub put
        } for

        % Evaluate the symbol to find the most suitable mask
        /score pixs evalsymbol def
        score bestscore gt {
            /bestsym pixs def
            /bestscore score def
            fast bestscore rows columns mul 2 idiv gt and {exit} if
        } if

        % Make a copy with lit edges for possible later evaluation
        /litmask pixs dup length array copy def
        0 1 5 {  % Light last six edge dots
            /i exch def
            litmask sixedges i get aload pop dmv
            1 put
        } for
        litmasks mask litmask put

        % In fast mode immediately score the lit symbol
        fast {
            /score litmask evalsymbol def
            score bestscore gt {
                /bestsym litmask def
                /bestscore score def
                bestscore rows columns mul 2 idiv gt {exit} if
            } if
        } if

    } forall
    /pixs bestsym def

    % For default mode, if best mask fails threshold then recalculate with lit corners and pick best
    fast not bestscore rows columns mul 2 idiv le and {
        /bestscore -99999999 def
        masks {
            litmasks exch get /litmask exch def
            /score litmask evalsymbol def
            score bestscore gt {
                /bestsym litmask def
                /bestscore score def
            } if
        } forall
        /pixs bestsym def
    } if

    % Return the arguments
    <<
    /ren //renmatrix
    /dotty true
    /pixs pixs
    /pixx columns
    /pixy rows
    /height rows 2 mul 72 div
    /width columns 2 mul 72 div
    /opt options
    >>

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/dotcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER dotcode--

% --BEGIN ENCODER ultracode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: Ultracode
% --EXAM: Awesome colours!
% --EXOP: eclevel=EC2
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp ultracode 0.0 2022082100 96235 99035
%%BeginData:        361 ASCII Lines
/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 /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/ultracode {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /eclevel (EC2) def     % EC0-EC5
    /encoding (auto) def
    /parse false def
    /parsefnc false def
    /start 257 def         % 8-bit ISO-8859-1, until we write high-level encoders
    /link1 0 def
    /raw false def
    /rev 1 def             % Ultracode specification revision

    % 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

    /start start cvi def
    /link1 link1 cvi def
    /rev rev cvi def

    rev dup 1 ne exch 2 ne and {
        /bwipp.ultracodeInvalidRevision (Valid revisions are 1 and 2) //raiseerror exec
    } if

    /ultracode //loadctx exec

    raw {/encoding (raw) def} if

    encoding (raw) eq {
        /dcws 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
            dcws j cw put
            /i i 4 add def
            /j j 1 add def
        } loop
        /dcws dcws 0 j getinterval def
    } if

    % Basic high level encoding
    encoding (auto) eq {

        % Parse the input
        /fn1 -1 def  /fn3 -2 def
        /fncvals <<
            /parse parse
            /parsefnc parsefnc
            (FNC1) fn1
            (FNC3) fn3
        >> def
        /msg barcode fncvals //parseinput exec def
        /msglen msg length def

        /scr [] def     % Empty symbol control region
        /scp [] def     % Empty start sequence parameters
        /dcws [
            scr aload pop
            scp aload pop
            msg {
                dup fn1 eq {pop 268} if
                dup fn3 eq {pop 269} if
            } forall
        ] def

    } if

    options /debugcws known { /bwipp.debugcws dcws //raiseerror exec } if

    /mcc dcws length 3 add def  % Message codewords: start mcc acc [dcws ...]

    /eclval eclevel 2 get 48 sub def
    eclval 0 ne {
        /qcc [0 1 2 4 6 8] eclval get mcc 25 idiv mcc 25 mod 0 ne {1 add} if mul 5 add def
    } {
        /qcc 3 def
    } ifelse
    /acc qcc 3 sub 78 link1 mul add def
    /tcc mcc qcc add def

    % Lookup the most appropriate symbol specification
{
    /metrics [
        % rows  minc  maxc  mcol
        [   2     7    37     5  ]
        [   3    36    84    13  ]
        [   4    85   161    22  ]
        [   5   142   282    29  ]
    ] def
} ctxdef

    0 1 3 {
        /i exch def
        /m metrics i get def
        /rows m 0 get def
        /minc m 1 get def  % Minimum permissible codewords
        /maxc m 2 get def  % Maximum permissible codewords
        /mcol m 3 get def  % Minimum tile columns
        /okay true def
        tcc minc lt tcc maxc gt or {/okay false def} if
        okay {exit} if
    } for

    okay not {
        /bwipp.ultracodeNoValidSymbol (Maximum length exceeded or invalid content) //raiseerror exec
    } if

    % Determine required number of columns and pads
    mcol 1 61 {
        /columns exch def
        columns
        columns 15 ge {1 sub} if
        columns 31 ge {1 sub} if
        columns 47 ge {1 sub} if
        rows mul 3 sub tcc sub dup 0 ge {
            /pads exch def
            exit
        } if
        pop
    } for
    /dcc columns mcol sub def

    % Reed-Solomon error correction
    /rsseq [
        start
        mcc
        acc
        dcws aload pop
        qcc {0} repeat
        0  % Working space
    ] def

    % Calculate the log and anti-log tables
    /rsalog [ 1 282 {dup 3 mul 283 mod} repeat ] def
    /rslog 283 array def
    1 1 282 {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 282 mod rsalog exch get
        } {
            pop pop 0
        } ifelse
    } def

    % Generate the coefficients
    /n mcc def  /k qcc def
    /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 283 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 283 exch sub put} for

    % Derive the error codewords
    0 1 n 1 sub {
        /t exch rsseq exch get rsseq n get add 283 mod def
        0 1 k 1 sub {
            /j exch def
            rsseq n j add rsseq n j add 1 add get 283 t coeffs k j sub 1 sub get mul 283 mod sub add 283 mod put
        } for
    } for
    n 1 n k add { dup rsseq exch 283 rsseq 5 -1 roll get sub 283 mod put } for
    /ecws rsseq n k getinterval def

    options /debugecc known { /bwipp.debugecc ecws //raiseerror exec } if

{
    /tiles [
        13135  13136  13153  13156  13163  13165  13513  13515  13516  13531  %   0-9
        13535  13536  13561  13563  13565  13613  13615  13616  13631  13635  %  10-19
        13636  13651  13653  13656  15135  15136  15153  15163  15165  15313  %  20-29
        15315  15316  15351  15353  15356  15361  15363  15365  15613  15615  %  30-39
        15616  15631  15635  15636  15651  15653  15656  16135  16136  16153  %  40-49
        16156  16165  16313  16315  16316  16351  16353  16356  16361  16363  %  50-59
        16365  16513  16515  16516  16531  16535  16536  16561  16563  16565  %  60-69
        31315  31316  31351  31356  31361  31365  31513  31515  31516  31531  %  70-79
        31535  31536  31561  31563  31565  31613  31615  31631  31635  31636  %  80-89
        31651  31653  31656  35131  35135  35136  35151  35153  35156  35161  %  90-99
        35163  35165  35315  35316  35351  35356  35361  35365  35613  35615  % 100-109
        35616  35631  35635  35636  35651  35653  35656  36131  36135  36136  % 110-119
        36151  36153  36156  36163  36165  36315  36316  36351  36356  36361  % 120-129
        36365  36513  36515  36516  36531  36535  36536  36561  36563  36565  % 130-139
        51313  51315  51316  51351  51353  51356  51361  51363  51365  51513  % 140-149
        51516  51531  51536  51561  51563  51613  51615  51616  51631  51635  % 150-159
        51636  51651  51653  51656  53131  53135  53136  53151  53153  53156  % 160-169
        53161  53163  53165  53513  53516  53531  53536  53561  53563  53613  % 170-179
        53615  53616  53631  53635  53636  53651  53653  53656  56131  56135  % 180-189
        56136  56151  56153  56156  56161  56163  56165  56313  56315  56316  % 190-199
        56351  56353  56356  56361  56363  56365  56513  56516  56531  56536  % 200-209
        56561  56563  61313  61315  61316  61351  61353  61356  61361  61363  % 210-219
        61365  61513  61515  61516  61531  61535  61536  61561  61563  61565  % 220-229
        61615  61631  61635  61651  61653  63131  63135  63136  63151  63153  % 230-239
        63156  63161  63163  63165  63513  63515  63516  63531  63535  63536  % 240-249
        63561  63563  63565  63613  63615  63631  63635  63651  63653  65131  % 250-259
        65135  65136  65151  65153  65156  65161  65163  65165  65313  65315  % 260-269
        65316  65351  65353  65356  65361  65363  65365  65613  65615  65631  % 270-279
        65635  65651  65653  56565  51515                                     % 280-284
    ] def

    /dccurev1 [
        51363  51563  51653  53153  53163  53513  53563  53613  %  0-7
        53653  56153  56163  56313  56353  56363  56513  56563  %  8-15
        51316  51356  51536  51616  53156  53516  53536  53616  % 16-23
        53636  53656  56136  56156  56316  56356  56516  56536  % 24-31
    ] def
    /dcclrev1 [
        61351  61361  61531  61561  61631  61651  63131  63151  %  0-7
        63161  63531  63561  63631  65131  65161  65351  65631  %  8-15
        31351  31361  31531  31561  31631  31651  35131  35151  % 16-23
        35161  35361  35631  35651  36131  36151  36351  36531  % 24-31
    ] def
    /dccurev2 [
        15316  16316  13516  16516  13616  15616  13136  15136  %  0-7
        16136  13536  16536  13636  13156  16156  15356  13656  %  8-15
        15313  16313  13513  16513  13613  15613  13153  15153  % 16-23
        16153  16353  13653  15653  13163  15163  15363  13563  % 24-31
    ] def
    /dcclrev2 [
        36315  36515  35615  35135  36135  31535  36535  31635  %  0-7
        35635  35165  36165  31365  35365  36365  31565  36565  %  8-15
        61315  65315  63515  61615  65135  61535  63535  61635  % 16-23
        63635  65635  63165  65165  61365  65365  61565  63565  % 24-31
    ] def
} ctxdef

    /dccu rev 1 eq {dccurev1} {dccurev2} ifelse def
    /dccl rev 1 eq {dcclrev1} {dcclrev2} ifelse def

    % Create the bitmap
    /rows rows 6 mul 1 add def
    /columns columns 6 add def
    /pixs [ rows columns mul {-1} repeat ] def
    /qmv {columns mul add} def
    0 1 columns 1 sub {
        /i exch def
        0 6 rows 1 sub {
            /j exch def
            i 5 ge {pixs i j qmv i 2 mod 9 mul put} if
        } for
        pixs i 0 qmv 9 put
        pixs i rows 1 sub qmv 9 put
    } for
    1 1 rows 2 sub {
        /i exch def
        3 16 columns 1 sub {
            /j exch def
            pixs j i qmv 1 i 2 mod sub 9 mul put
        } for
        pixs 0 i qmv 9 put
        pixs 1 i qmv 1 i 2 mod sub 9 mul put
        pixs 2 i qmv 0 put
        pixs 3 i qmv 9 put
        pixs 4 i qmv 0 put
        pixs columns 1 sub i qmv 9 put
    } for

    % DCCU and DCCL tiles
    /i rows 2 idiv 5 sub def
    [
        dccu dcc get 10 5 string cvrs {48 sub} forall
        0
        dccl dcc get 10 5 string cvrs {48 sub} forall
    ] {
        pixs 2 i qmv 3 -1 roll put
        /i i 1 add def
    } forall

    % Data tiles
    /tileseq [
        start
        mcc
        ecws aload pop
        tcc
        283  % SEP
        acc
        dcws aload pop
        pads {284} repeat
        qcc
    ] def

    /x 5 def /y 1 def
    tileseq {
         tiles exch get 10 5 string cvrs {
              pixs x y qmv 3 -1 roll 48 sub put
              /y y 1 add def
         } forall
         y rows 1 sub ne {
              /y y 1 add def      % Jump horizontal timing pattern
         } {
              /x x 1 add def  /y 1 def
              pixs x y qmv get -1 ne {
                  /x x 1 add def  % Jump vertical timing pattern
              } if
         } ifelse
    } forall

{
    /colormap <<
        0 (FFFFFF)  % W
        9 (000000)  % K
        1 (00FFFF)  % C
        3 (FF00FF)  % M
        5 (FFFF00)  % Y
        6 (00FF00)  % G
    >> def
} ctxdef

    % Return the arguments
    <<
    /ren //renmatrix
    /pixs pixs
    /pixx columns
    /pixy rows
    /height rows 72 div 2 mul
    /width columns 72 div 2 mul
    /colormap colormap
    /opt options
    >>

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/ultracode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER ultracode--

% --BEGIN ENCODER jabcode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix--
% --DESC: JAB Code (Beta)
% --EXAM: This is JAB Code
% --EXOP: eclevel=6
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp jabcode 0.0 2022082100 244344 255738
%%BeginData:       1133 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/jabcode {

    20 dict begin

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /rows -1 def
    /columns -1 def
    /slave false def
    /colors 16 def
    /eclevel 6 def  % 0-10
    /raw false def
    /parse false def
    /parsefnc false def
    /mask -1 def    % 0-7

    % 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

    /rows rows cvi def
    /columns columns cvi def
    /colors colors cvi def
    /eclevel eclevel cvi def
    /mask mask cvi def

    /databpm colors ln 2 ln div round cvi def
    /metabpm colors dup 8 gt {pop 8} if ln 2 ln div round cvi def

     % Parse the input
    /fn1 -1 def
    /fncvals <<
        /parse parse
        /parsefnc parsefnc
        (FNC1) fn1
    >> def
    /msg barcode fncvals //parseinput exec def
    /msglen msg length def

    % Wide array support, as needed
    {65536 array} stopped {
        pop
        /arrayw {
            dup 65535 idiv 1 add dup array exch 0 exch 1 sub {2 copy 65535 array put 1 add} repeat
            1 index 4 1 roll 3 -1 roll 65535 mod array put
        } def
        /getw  {exch 1 index 65535 idiv get exch 65535 mod get} def
        /putw  {3 1 roll exch 1 index 65535 idiv get exch 65535 mod 3 -1 roll put} def
        /copyw {exch 0 exch {dup length array copy 3 copy put pop 1 add} forall pop} def
    } {
        pop
        /arrayw {array} def
        /getw   {get}   def
        /putw   {put}   def
        /copyw  {copy}  def
    } ifelse

    /addtobits {
        dup bits j 3 -1 roll putinterval
        length j add /j exch def
    } def

    /tofixedbits {  % Zero padded base 2 string
        (0000000000000) 13 string copy dup 4 -1 roll 2 13 string cvrs
        dup length 4 index exch sub exch putinterval
        0 3 -1 roll getinterval
    } def

    % Encode the data using byte mode encoding and terminate with EOM
    /bits 7 msglen 15 le {4} {17} ifelse add msglen 8 mul add 12 add string def
    /j 0 def
    31 5 tofixedbits addtobits  % MS
    (00) addtobits              % S/B
    msglen 15 le {
        msglen 4 tofixedbits addtobits
    } {
        (0000) addtobits
        msglen 16 sub 13 tofixedbits addtobits
    } ifelse
    0 1 msglen 1 sub {
        msg exch get 8 tofixedbits addtobits
    } for
    28 5 tofixedbits addtobits  % L/L
    31 5 tofixedbits addtobits  % MS
    (11) addtobits              % EOM

    % TODO Cascade
    /diffside 21 def
    /sameshape false def
    /sameecc false def
    /hasslaves false def

    % Determine the metrics for a symbol of a given size
    /metrics {
        /mc exch def  /mr exch def
        mc mr mul                                      % All modules
        mc 25 sub 16 idiv 2 add mr 25 sub 16 idiv 2 add
        mul 4 sub 7 mul                                % Alignment modules
        64 colors 2 copy gt {exch} if pop 2 mul        % Palette modules
        slave {7} {17} ifelse 4 mul                    % Finder modules

        % Metadata bits and modules
        slave not {  % Master
            /metass mr mc eq {0} {1} ifelse def
            mr mc 2 copy lt {exch} if pop
            21 sub 16 idiv [ 0 1 2 2 3 3 3 3 ] exch get  /metavf exch def
            /metavlen metass 0 eq {[2 2 3 4]} {[4 6 8 10]} ifelse metavf get def
            /metaelen metavf 2 mul 10 add def
            7                                          % II:  SS VF MSK SF
            metavlen add metaelen add                  % III: V E
            hasslaves {4 add} if                       % III: S
            2 mul                                      % LDPC
            metabpm div ceiling cvi
            dup metabpm mul 6 add /nummetabits exch def
            6 add                                      % I:   Nc into 6 modules
        } {  % Slave
            3                                          % I:   SS SE SF
            sameshape not {5 add} if                   % II:  V
            hasslaves     {3 add} if                   % II:  S
            sameecc not {
                mr mc 2 copy lt {exch} if pop
                21 sub 16 idiv [ 10 12 14 14 16 16 16 16 ] exch get
                add                                    % III: E
            } if
            2 mul                                      % LDPC
            metabpm div ceiling cvi
            dup metabpm mul /nummetabits exch def
        } ifelse

        dup              /nummetamodules exch def
        add add add sub  /numdatamodules exch def
        /numdatabits numdatamodules databpm mul def
    } def

    % Select a symbol size sufficient to carry the message
    /coderate [ 0.67 0.63 0.57 0.55 0.50 0.43 0.34 0.25 0.20 0.17 0.14 ] eclevel get def
    /grosslen bits length coderate div ceiling cvi def
    /snapsize {ceiling cvi 18 sub dup 0 lt {pop 0} if 4 idiv 4 mul 21 add} def

    rows -1 eq columns -1 eq and {        % Square if neither rows or columns fixed
        /size grosslen sqrt snapsize def
        {
            size size metrics
            grosslen numdatabits le {exit} if
            /size size 4 add def
        } loop
        /rows size def
        /columns size def
    } {
        columns -1 eq rows -1 ne and {     % Fixed height
            /columns grosslen rows div snapsize def
            {
                rows columns metrics
                grosslen numdatabits le {exit} if
                /columns columns 4 add def
            } loop
        } if
        rows -1 eq columns -1 ne and {     % Fixed width
            /rows grosslen columns div snapsize def
            {
                rows columns metrics
                grosslen numdatabits le {exit} if
                /rows rows 4 add def
            } loop
        } if
        rows -1 ne columns -1 ne and {     % Fixed height and width
            rows columns metrics
        } if
    } ifelse
    /C numdatabits def
    /cols columns def

    % TODO Reject all invalid sizes
    rows 145 gt cols 145 gt or {
        /bwipp.jabcodeNoValidSymbol (Maximum length exceeded or invalid content) //raiseerror exec
    } if

    % Pick ECC params to maximally fill symbol
    /min C def
    3 1 8 {
        /i exch def
        i 1 add 1 9 {
            /j exch def
            /dist C j idiv j mul C j idiv i mul sub bits length sub def
            dist min lt dist 0 ge and {
                /datawc i def
                /datawr j def
                /min dist def
            } if
        } for
    } for

    % Extend the encoded data to fill the required data length
    /tmpbits C datawr idiv datawr mul C datawr idiv datawc mul sub string def
    tmpbits 0 bits putinterval
    bits length 1 tmpbits length 1 sub {
        dup 1 sub tmpbits exch get dup 2 mod 0 eq {1 add} {1 sub} ifelse
        tmpbits 3 1 roll put
    } for
    /bits tmpbits def

    % Avoid 15-bit overflow when multiplying the digits by stealing from the second digit
    % m = 6364136223846793005 = 0x 5851 f42d 4c95 7f2d
    /m0 16#5851 16#1 add def  /m1 16#f42d 16#10000 sub def  /m2 16#4c95 def  /m3 16#7f2d def

    /lcg64_temper {

        % Multiply seed by 6364136223846793005 then add 1

        /p00 m0 s0 mul def  /p01 m0 s1 mul def  /p02 m0 s2 mul def  /p03 m0 s3 mul def
        /p10 m1 s0 mul def  /p11 m1 s1 mul def  /p12 m1 s2 mul def  /p13 m1 s3 mul def
        /p20 m2 s0 mul def  /p21 m2 s1 mul def  /p22 m2 s2 mul def  /p23 m2 s3 mul def
        /p30 m3 s0 mul def  /p31 m3 s1 mul def  /p32 m3 s2 mul def  /p33 m3 s3 mul def

        /s3 p33 16#10000 mod                     1 add def  % 1 added here
        /s2 p32 16#10000 mod p33 16#10000 idiv add
            p23 16#10000 mod                       add def
        /s1 p31 16#10000 mod p32 16#10000 idiv add
            p22 16#10000 mod p23 16#10000 idiv add add
            p13 16#10000 mod                       add def
        /s0 p30 16#10000 mod p31 16#10000 idiv add
            p21 16#10000 mod p22 16#10000 idiv add add
            p12 16#10000 mod p13 16#10000 idiv add add
            p03 16#10000 mod                       add def

        % Simplify carry by making each digit positive by borrowing from more significant digit
        /s3 s3 16#10000 add def
        /s2 s2 16#ffff  add def
        /s1 s1 16#ffff  add def
        /s0 s0 16#ffff  add def

        % Carry
        /s2 s3 16#10000 idiv s2 add def  /s3 s3 16#10000 mod def
        /s1 s2 16#10000 idiv s1 add def  /s2 s2 16#10000 mod def
        /s0 s1 16#10000 idiv s0 add def  /s1 s1 16#10000 mod def
                                         /s0 s0 16#10000 mod def

        % Temper most significant 32 bits
        s0 16#8000 sub 16#10000 mul s1 add 16#80000000 xor
        16#ffffffff and
        dup -11 bitshift xor
        dup   7 bitshift 16#62d3a980 neg and xor  % 0x9D2C5680 - 0x100000000
        dup  15 bitshift 16#103a0000 neg and xor  % 0xEFC60000 - 0x100000000
        16#ffffffff and
        dup -18 bitshift xor

    } def

    /createMatrixA {

        /nb_pcb wr 4 lt {Pg_sub_block 2 idiv} {Pg_sub_block wr idiv wc mul} ifelse def
        /offset Pg_sub_block 32 div ceiling cvi def
        /effwidth offset 32 mul def
        /matrixA offset nb_pcb mul arrayw def
        0 1 offset nb_pcb mul 1 sub {matrixA exch 0 putw} for
        /permutation Pg_sub_block array def
        0 1 Pg_sub_block 1 sub {permutation exch dup put} for

        0 1 Pg_sub_block wr idiv 1 sub {
            /i exch def
            0 1 wr 1 sub {
                /j exch def
                matrixA i effwidth wr add mul j add 32 idiv
                2 copy getw 1 31 i effwidth wr add mul j add 32 mod sub bitshift or putw
            } for
        } for

        % Pseudorandom permutation
        /s0 16#0000 def  /s1 16#0000 def  /s2 16#000B def  /s3 16#FC39 def  % s=785465
        1 1 wc 1 sub {
            /i exch def
            /off_index Pg_sub_block wr idiv i mul def
            0 1 Pg_sub_block 1 sub {
                /j exch def
                lcg64_temper
                dup 0 lt {16#80000000 xor 2147483648.0 add} if
                4294967296.0 div Pg_sub_block j sub mul cvi  % (float)UINT32_MAX = 65536.0 * 65536
                /pos exch def
                0 1 Pg_sub_block wr idiv 1 sub {
                    /k exch def
                    matrixA off_index k add offset mul j 32 idiv add
                    2 copy getw
                        matrixA permutation pos get 32 idiv k offset mul add getw
                        31      permutation pos get 32 mod  sub neg bitshift 1 and
                        31 j                        32 mod  sub bitshift
                    or putw
                } for
                permutation pos permutation Pg_sub_block 1 sub j sub 2 copy get permutation pos get
                exch 4 1 roll   % p b p a p[a] p[b] -> p b p[a] p a p[b]
                put put
            } for
        } for

    } def

    /createMetadataMatrixA {

        /nb_pcb Pg_sub_block 2 idiv def
        /offset Pg_sub_block 32 div ceiling cvi def
        /matrixA offset nb_pcb mul arrayw def
        0 1 offset nb_pcb mul 1 sub {matrixA exch 0 putw} for
        /permutation Pg_sub_block array def
        0 1 Pg_sub_block 1 sub {permutation exch dup put} for

        % Pseudorandom permutation
        /s0 16#0000 def  /s1 16#0000 def  /s2 16#0000 def  /s3 16#9691 def  % s=38545
        /nb_once nb_pcb wc div Pg_sub_block mul 3 add cvi nb_pcb idiv def
        0 1 nb_pcb 1 sub {
            /i exch def
            0 1 nb_once 1 sub {
                /j exch def
                lcg64_temper
                dup 0 lt {16#80000000 xor 2147483648.0 add} if
                4294967296.0 div Pg_sub_block j sub mul cvi  % (float)UINT32_MAX = 65536.0 * 65536
                /pos exch def
                matrixA i offset mul permutation pos get 32 idiv add
                2 copy getw 1 31 permutation pos get 32 mod sub bitshift or putw
                permutation pos permutation Pg_sub_block 1 sub j sub 2 copy get permutation pos get
                exch 4 1 roll   % p b p a p[a] p[b] -> p b p[a] p a p[b]
                put put
            } for
        } for

    } def

    /GaussJordan {

        /nb_pcb wr 4 lt {Pg_sub_block 2 idiv} {Pg_sub_block wr idiv wc mul} ifelse def
        /offset Pg_sub_block 32 div ceiling cvi def
        /matrixH matrixA dup length array copyw def
        /column_arrangement [ Pg_sub_block       {0}     repeat ] def
        /processed_column   [ Pg_sub_block       {false} repeat ] def
        /zero_lines_nb      [ nb_pcb             {0}     repeat ] def
        /swap_col           [ Pg_sub_block 2 mul {0}     repeat ] def
        /zero_lines 0 def

        /loop0 0 def
        0 1 nb_pcb 1 sub {
            /i exch def
            /pivot_column Pg_sub_block 1 add def
            0 1 Pg_sub_block 1 sub {
                /j exch def
                matrixH offset 32 mul i mul j add 32 idiv getw
                31 offset 32 mul i mul j add 32 mod sub neg bitshift 1 and 1 eq {
                    /pivot_column j def
                    exit
                } if
            } for
            pivot_column Pg_sub_block lt {
                processed_column   pivot_column true put
                column_arrangement pivot_column i put
                pivot_column nb_pcb ge {
                    swap_col loop0 2 mul pivot_column put
                    /loop0 loop0 1 add def
                } if
                /off_index  pivot_column 32 idiv def
                /off_index1 pivot_column 32 mod def
                0 1 nb_pcb 1 sub {
                    /j exch def
                    i j ne {
                        matrixH off_index j offset mul add getw
                        31 off_index1 sub neg bitshift 1 and 1 eq {
                            0 1 offset 1 sub {
                                /k exch def
                                matrixH offset j mul k add
                                2 copy getw matrixH offset i mul k add getw xor putw
                            } for
                        } if
                    } if
                } for
            } {
                zero_lines_nb zero_lines i put
                /zero_lines zero_lines 1 add def
            } ifelse
        } for

        /matrix_rank nb_pcb zero_lines sub def
        /loop2 0 def
        matrix_rank 1 nb_pcb 1 sub {
            /i exch def
            column_arrangement i get 0 gt {
                0 1 nb_pcb 1 sub {
                    /j exch def
                    processed_column j get not {
                        column_arrangement j column_arrangement i get put
                        column_arrangement i 0 put
                        processed_column   j true put
                        processed_column   i false put
                        swap_col loop0 2 mul       i put
                        swap_col loop0 2 mul 1 add j put
                        column_arrangement i j put
                        /loop0 loop0 1 add def
                        /loop2 loop2 1 add def
                        exit
                    } if
                } for
            } if
        } for

        /loop1 0 def
        0 1 nb_pcb 1 sub {
            /kl exch def
            processed_column kl get not loop1 loop0 loop2 sub lt and {
                column_arrangement kl column_arrangement swap_col loop1 2 mul get get put
                processed_column kl true put
                swap_col loop1 2 mul 1 add kl put
                /loop1 loop1 1 add def
            } if
        } for

        /loop1 0 def
        0 1 nb_pcb 1 sub {
            /kl exch def
            processed_column kl get not {
                column_arrangement kl zero_lines_nb loop1 get put
                /loop1 loop1 1 add def
            } if
        } for

        0 1 nb_pcb 1 sub {
            /i exch def
            0 1 offset 1 sub {
                /j exch def
                matrixH column_arrangement i get offset mul j add getw
                matrixA exch i offset mul j add exch putw
            } for
        } for

        /tmp 0 def
        0 1 loop0 1 sub {
            /i exch def
            0 1 nb_pcb 1 sub {
                /j exch def
                matrixA swap_col i 2 mul get 32 idiv j offset mul add getw
                31 swap_col i 2 mul get 32 mod sub neg bitshift 1 and neg tmp xor 1 and
                tmp xor /tmp exch def
                matrixA     swap_col i 2 mul       get 32 idiv j offset mul add
                2 copy getw
                    matrixA swap_col i 2 mul 1 add get 32 idiv j offset mul add getw
                    31      swap_col i 2 mul 1 add get 32 mod  sub neg bitshift 1 and neg
                    matrixA swap_col i 2 mul       get 32 idiv j offset mul add getw xor
                    1 31    swap_col i 2 mul       get 32 mod  sub     bitshift and
                xor putw
                matrixA swap_col i 2 mul 1 add get 32 idiv j offset mul add
                2 copy getw
                    tmp 1 and neg
                    matrixA swap_col i 2 mul 1 add get 32 idiv j offset mul add getw xor
                    1 31    swap_col i 2 mul 1 add get 32 mod  sub     bitshift and
                xor putw
            } for
        } for

    } def

    /createGeneratorMatrix {

        /pn Pg_sub_block matrix_rank sub def
        /offset pn 32 div ceiling cvi def
        /effwidth offset 32 mul def
        /offset_cap Pg_sub_block 32 div ceiling cvi def
        /G offset Pg_sub_block mul arrayw def
        0 1 offset Pg_sub_block mul 1 sub {
            G exch 0 putw
        } for
        0 1 pn 1 sub {
            /i exch def
            G Pg_sub_block pn sub i add offset mul i 32 idiv add
            2 copy getw 1 31 i 32 mod sub bitshift or putw
        } for
        /matrix_index Pg_sub_block pn sub def
        /loop0 0 def
        0 1 Pg_sub_block pn sub effwidth mul 1 sub {
            /i exch def
            matrix_index Pg_sub_block ge {
                /loop0 loop0 1 add def
                /matrix_index Pg_sub_block pn sub def
            } if
            i effwidth mod pn lt {
                G i 32 idiv
                2 copy getw
                    matrixA matrix_index 32 idiv offset_cap loop0 mul add getw
                    31      matrix_index 32 mod sub neg bitshift 1 and neg
                    G       i            32 idiv getw xor
                    1 31    i            32 mod sub     bitshift and
                xor putw
                /matrix_index matrix_index 1 add def
            } if
        } for

    } def

    /ldpc {

        /wr exch def
        /wc exch def
        [ exch {48 sub} forall ] /data exch def

        /Pn data length def
        wr -1 ne {  % Message data
            /Pg Pn wr mul wr wc sub div ceiling wr div ceiling wr mul cvi def
            /nb_sub_blocks Pg 2700 idiv 1 add def
            /Pg_sub_block  Pg nb_sub_blocks idiv wr idiv wr mul def
            /Pn_sub_block  Pg_sub_block wr wc sub mul wr idiv def
            /nb_sub_blocks Pg Pg_sub_block idiv def
            /encoding_iterations Pg Pg_sub_block idiv Pn_sub_block nb_sub_blocks mul Pn lt {1 sub} if def
            createMatrixA
        } {         % Metadata
            /Pg Pn 2 mul def
            /nb_sub_blocks 1 def
            /Pg_sub_block  Pg def
            /Pn_sub_block  Pn def
            /encoding_iterations 1 def
            createMetadataMatrixA
        } ifelse
        GaussJordan
        createGeneratorMatrix

        /ecc_encoded_data Pg array def

        /offset Pg_sub_block matrix_rank sub 32 div ceiling cvi def
        0 1 encoding_iterations 1 sub {
            /iter exch def
            0 1 Pg_sub_block 1 sub {
                /i exch def
                /temp 0 def
                /loop0 0 def
                /offset_index offset i mul def
                iter Pn_sub_block mul 1 iter 1 add Pn_sub_block mul 1 sub {
                    data exch get
                    G offset_index loop0 32 idiv add getw 31 loop0 32 mod sub neg bitshift 1 and and
                    /temp exch temp xor def
                    /loop0 loop0 1 add def
                } for
                ecc_encoded_data i iter Pg_sub_block mul add temp put
            } for
        } for

        encoding_iterations nb_sub_blocks ne {
            /start      encoding_iterations Pn_sub_block mul def
            /last_index encoding_iterations Pg_sub_block mul def
            /Pg_sub_block Pg encoding_iterations Pg_sub_block mul sub def
            /Pn_sub_block Pg_sub_block wr wc sub mul wr idiv def
            createMatrixA
            GaussJordan
            createGeneratorMatrix
            /offset Pg_sub_block matrix_rank sub 32 div ceiling cvi def
            0 1 Pg_sub_block 1 sub {
                /i exch def
                /temp 0 def
                /loop0 0 def
                /offset_index offset i mul def
                start 1 Pn 1 sub {
                    data exch get
                    G offset_index loop0 32 idiv add getw 31 loop0 32 mod sub neg bitshift 1 and and
                    /temp exch temp xor def
                    /loop0 loop0 1 add def
                } for
                ecc_encoded_data i last_index add temp put
            } for
        } if

        /out Pg string def
        0 1 Pg 1 sub {
            dup ecc_encoded_data exch get
            out 3 1 roll 48 add put
        } for
        out

    } def

    % Replace data bitstream with LDPC error correction stream
    /bits bits datawc datawr ldpc def

    % Interleave via pseudorandom permutation
    /s0 16#0000 def  /s1 16#0000 def  /s2 16#0003 def  /s3 16#75C7 def  % s=226759
    bits length 1 sub -1 1 {
        /l exch def
        lcg64_temper
        dup 0 lt {16#80000000 xor 2147483648.0 add} if
        4294967296.0 div l 1 add mul cvi  % (float)UINT32_MAX = 65536.0 * 65536
        /r exch def
        bits l get bits r get
        bits exch l exch put
        bits exch r exch put
    } for

    % Append padding bits to the interleaved, ECC encoded data up to capacity
    /tmpbits C string def
    tmpbits 0 bits putinterval
    /j bits length def
    C j sub 1 add 2 idiv {
        tmpbits j 48 put
        j 1 add C lt {tmpbits j 1 add 49 put} if
        /j j 2 add def
    } repeat
    /bits tmpbits def

    % Define the color palette
    colors 4 eq {
        /bi 0 def  /gi 1 def  /mi 2 def  /yi 3 def
        /ki 4 def  /wi 5 def  % Extended
        /palette <<
            bi (0000FF)  gi (00FF00)  mi (FF00FF)  yi (FFFF00)
            ki (000000)  wi (FFFFFF)
        >> def
        /metacolorindex [bi gi mi yi] def
        /palettelayout  [bi gi mi yi] def
    } {
        /rgbres <<
              % r g b   Graduations
           8  [ 2 2 2 ]
          16  [ 4 2 2 ]
          32  [ 4 4 2 ]
          64  [ 4 4 4 ]
         128  [ 8 4 4 ]
         256  [ 8 8 4 ]
        >> colors get def

        /rvals rgbres 0 get [ exch 1 sub dup 0 exch 1 exch {255 2 index div mul round cvi exch} for pop ] def
        /gvals rgbres 1 get [ exch 1 sub dup 0 exch 1 exch {255 2 index div mul round cvi exch} for pop ] def
        /bvals rgbres 2 get [ exch 1 sub dup 0 exch 1 exch {255 2 index div mul round cvi exch} for pop ] def

        /palette colors dict def
        /palettelayout 64 colors 2 copy gt {exch} if pop array def
        /i 0 def  /j 8 def
        rvals {
            /r exch def
            gvals {
                /g exch def
                bvals {
                    /b exch def
                    r 16 bitshift g 8 bitshift or b or
                    (000000) 6 string copy dup 3 -1 roll 16 6 string cvrs dup length 6 exch sub exch putinterval
                    false
                    1 index (000000) eq {/ki i def  pop true} if
                    1 index (0000FF) eq {/bi i def  pop true} if
                    1 index (00FF00) eq {/gi i def  pop true} if
                    1 index (00FFFF) eq {/ci i def  pop true} if
                    1 index (FF0000) eq {/ri i def  pop true} if
                    1 index (FF00FF) eq {/mi i def  pop true} if
                    1 index (FFFF00) eq {/yi i def  pop true} if
                    1 index (FFFFFF) eq {/wi i def  pop true} if
                    not {
                        colors 64 le
                        colors 128 eq
                            r 0 eq r 73 eq or r 182 eq or r 255 eq or and
                        colors 256 eq
                            r 0 eq r 73 eq or r 182 eq or r 255 eq or and
                            g 0 eq g 73 eq or g 182 eq or g 255 eq or and
                        or or {  % RGB space is sampled into 64 slots
                            palettelayout j i put
                            /j j 1 add def
                        } if
                    } if
                    palette exch i exch put
                    /i i 1 add def
                } forall
            } forall
        } forall
        palettelayout 0 [ki bi gi ci ri mi yi wi] putinterval
        /metacolorindex [ki bi gi ci ri mi yi wi] def
    } ifelse

    % Create the pixel map
    /pixs [rows cols mul {-1} repeat] def
    /jmv {cols mul add} def

    % Finder patterns
    slave not {  % Master alignment pattern
        /fpat [
            [ 1 1 1 0 0 ]
            [ 1 2 2 0 0 ]
            [ 1 2 1 2 1 ]
            [ 0 0 2 2 1 ]
            [ 0 0 1 1 1 ]
        ] def
        /fmap [
            [ -1 bi yi ]  % UL
            [ -1 yi bi ]  % LL
            [ -1 gi mi ]  % UR
            [ -1 mi gi ]  % LR
        ] def
    } {  % Slave alignment pattern
        /fpat [
            [ 0 0 0 0 0 ]
            [ 0 2 2 0 0 ]
            [ 0 2 1 2 0 ]
            [ 0 0 2 2 0 ]
            [ 0 0 0 0 0 ]
        ] def
        /fmap [
            [ -1 ki wi ]  % UL
            [ -1 ki wi ]  % LL
            [ -1 ki wi ]  % UR
            [ -1 ki wi ]  % LR
        ] def
    } ifelse
    0 1 4 {
      /y exch def
      0 1 4 {
        /x exch def
        /fpb fpat y get x get def
        pixs x 1 add y 1 add                     jmv fmap 0 get fpb get put
        pixs x 1 add           rows y sub 2 sub  jmv fmap 1 get fpb get put
        pixs x cols add 6 sub  y 1 add           jmv fmap 2 get fpb get put
        pixs x cols add 6 sub  rows y sub 2 sub  jmv fmap 3 get fpb get put
      } for
    } for

    % Alignment patterns
    /algnpat0 [
        [ ki ki -1 ]
        [ ki wi ki ]
        [ -1 ki ki ]
    ] def
    /algnpat1 [
        [ -1 ki ki ]
        [ ki wi ki ]
        [ ki ki -1 ]
    ] def
    /num cols 16 div round cvi 1 sub def
    /algnrpos [ 3 17 ] def
    num 0 gt {
        /algnrpos [ 0 1 num {cols 7 sub num div mul cvi 3 add} for ] def
    } if
    /num rows 16 div round cvi 1 sub def
    /algncpos [ 3 17 ] def
    num 0 gt {
        /algncpos [ 0 1 num {rows 7 sub num div mul cvi 3 add} for ] def
    } if
    /putalgnpat {
        /pp exch def
        /py exch def
        /px exch def
        0 1 2 {
            /pb exch def
            0 1 2 {
                /pa exch def
                pixs px pa add py pb add jmv pp pb get pa get put
            } for
        } for
    } def
    0 1 algncpos length 1 sub {
        /j exch def
        /y algncpos j get def
        0 1 algnrpos length 1 sub {
            /i exch def
            /x algnrpos i get def
            pixs x y jmv get -1 eq {
                x 1 sub y 1 sub i j add 2 mod 0 eq {algnpat0} {algnpat1} ifelse putalgnpat
            } if
        } for
    } for

    slave not {

        [  % Expanded to [ x y ] [ x -y ] [ -x -y ] [ x -y ]
            % Metadata and palette
            [ 6 1 ] [ 6 2 ] [ 6 3 ] [ 6 4 ] [ 6 5 ] [ 6 6 ] [ 5 6 ] [ 4 6 ] [ 3 6 ] [ 2 6 ]  %  0-39
            [ 1 6 ] [ 7 1 ] [ 7 2 ] [ 7 3 ] [ 7 4 ] [ 7 5 ] [ 7 6 ] [ 7 7 ] [ 6 7 ] [ 5 7 ]  % 40-79
            % Palette only
            [  4  7 ] [  3  7 ] [  2  7 ] [  1  7 ] [  8  1 ] [  8  2 ] [  8  3 ] [  8  4 ]  % 16-31
            [  8  5 ] [  8  6 ] [  8  7 ] [  8  8 ] [  7  8 ] [  6  8 ] [  5  8 ] [  4  8 ]  % 32-47
            [  3  8 ] [  2  8 ] [  1  8 ] [  9  1 ] [  9  2 ] [  9  3 ] [  9  4 ] [  9  5 ]  % 48-63
        ] {
            aload pop /y exch def /x exch def
            [ x y ] [ x neg y ] [ x neg y neg ] [ x y neg ]
        } forall
        176 array astore /metadatamap exch def

        /palettemap1 [
            [  4  1 ] [  4  2 ] [  5  1 ] [  5  2 ] [  2  4 ] [  2  5 ] [  1  4 ] [  1  5 ]  %  0-7
            [ -2  1 ] [ -2  2 ] [ -1  1 ] [ -1  2 ] [ -4  4 ] [ -4  5 ] [ -5  4 ] [ -5  5 ]  %  8-15
        ] def

        /palettemap2 [
            [ -4 -5 ] [ -4 -4 ] [ -5 -5 ] [ -5 -4 ] [ -2 -2 ] [ -2 -1 ] [ -1 -2 ] [ -1 -1 ]  %  0-7
            [  2 -5 ] [  2 -4 ] [  1 -5 ] [  1 -4 ] [  4 -2 ] [  4 -1 ] [  5 -2 ] [  5 -1 ]  %  8-15
        ] def

    } {  % Slave

        % TODO Cascade

        /metadatamap [
            1 1 19 {
                /i exch def
                [ 0 i ] [ 1 i ]
            } for
            5 1 12 {
                /i exch def
                [ 2 i ] [ 3 i ]
            } for
        ] def

        /palettemap1 [
             5  1 12 { [ exch 4 exch ] } for
            12 -1  5 { [ exch 5 exch ] } for
             5  1 12 { [ exch 6 exch ] } for
            12 -1  5 { [ exch 7 exch ] } for
        ] def

        /palettemap2 [
            palettemap1 {[ exch aload pop neg exch neg exch]} forall
        ] def

    } ifelse

    % Normalise wrapping
    metadatamap {
        dup 0 get dup 0 lt {cols add 1 sub 1 index 0 3 -1 roll put} {pop} ifelse
        dup 1 get dup 0 lt {rows add 1 sub 1 index 1 3 -1 roll put} {pop} ifelse
        pop
    } forall
    palettemap1 {
        dup 0 get dup 0 lt {cols add 1 sub 1 index 0 3 -1 roll put} {pop} ifelse
        dup 1 get dup 0 lt {rows add 1 sub 1 index 1 3 -1 roll put} {pop} ifelse
        pop
    } forall
    palettemap2 {
        dup 0 get dup 0 lt {cols add 1 sub 1 index 0 3 -1 roll put} {pop} ifelse
        dup 1 get dup 0 lt {rows add 1 sub 1 index 1 3 -1 roll put} {pop} ifelse
        pop
    } forall

    % Reserve the metadata modules to be placed once mask is determined
    0 1 nummetamodules 1 sub {
        pixs exch metadatamap exch get aload pop jmv 0 put
    } for

    % Place the color palette
    slave not {
        % Up to first 16 colors into finder slots
        0 1 16 colors 2 copy gt {exch} if pop 1 sub {
            /i exch def
            palettelayout i get dup
            pixs exch palettemap1 i get aload pop jmv exch put
            pixs exch palettemap2 i get aload pop jmv exch put
        } for
        /i 16 def
    } {
        /i 0 def
    } ifelse

    % Continue palette placement after end of metadata modules
    /j nummetamodules def
    i 2 palettelayout length 1 sub {
        /i exch def
        palettelayout i get dup
        pixs exch metadatamap j       get aload pop jmv exch put
        pixs exch metadatamap j 2 add get aload pop jmv exch put
        palettelayout i 1 add get dup
        pixs exch metadatamap j 1 add get aload pop jmv exch put
        pixs exch metadatamap j 3 add get aload pop jmv exch put
        /j j 4 add def
    } for

    % Calculate the mask patterns applied to data modules
    /maskfuncs [
        {add colors mod} bind
        {pop colors mod} bind
        {exch pop colors mod} bind
        {3 idiv exch 2 idiv add colors mod} bind
        {2 idiv exch 3 idiv add colors mod} bind
        {add dup 2 idiv exch 3 idiv add colors mod} bind
        {2 copy exch dup mul mul 7 mod 3 1 roll exch dup mul add 2 mul 19 mod add colors mod} bind
        {2 copy dup mul mul 5 mod 3 1 roll dup mul exch 2 mul add 13 mod add colors mod} bind
    ] def
    mask -1 ne {  % User specifies a mask
        /maskfuncs [maskfuncs mask get] def
        /bestmaskval mask def
    } if
    /masks maskfuncs length array def
    0 1 masks length 1 sub {
        /m exch def
        /mask rows cols mul array def
        0 1 rows 1 sub {
            /j exch def
            0 1 cols 1 sub {
                /i exch def
                pixs i j jmv get -1 eq {i j maskfuncs m get exec} {0} ifelse
                mask i j jmv 3 -1 roll put
            } for
        } for
        masks m mask put
    } for

    % Walk the symbol placing the data bitstream
    /posx 0 def  /posy 0 def
    /i 0 def
    { % loop
        posx cols eq {exit} if
        pixs posx posy jmv get -1 eq {
            bits i databpm getinterval 0 exch {48 sub add 2 mul} forall 2 idiv
            pixs posx posy jmv 3 -1 roll put
            /i i databpm add def
        } if
        /posy posy 1 add def
        posy rows eq {/posy 0 def /posx posx 1 add def} if
    } loop

    % Evaluate runlength encoded rows or columns in full symbols
    /evalrle {
        /scrle exch def
        /scr1 0 def  /scr3 0 def
        0 2 scrle length 2 sub {
            /j exch def
            scrle j 1 add get -1 ne {  % Skip over voids
                % Detect runs of 5 or more like modules, except in voids
                scrle j get dup 5 ge {2 sub /scr1 exch scr1 add def} {pop} ifelse
                % Detect finder pattern
                j 4 ge j scrle length 5 sub le and {
                    scrle j 4 sub 10 getinterval                     % n1 c1 ... n5 c5
                    dup {1 eq} forall pop 4 {exch pop and} repeat {  % n{1-5}=1
                        mark exch aload pop
                        8 index dup 6 index eq exch 2 index eq and   % c1=c3=c5
                        7 index 4 index eq and {                     % c2=c4
                            2 index  /c4 exch def  /c5 exch def
                            c4 bi eq c5 yi eq and  c4 yi eq c5 bi eq and
                            c4 gi eq c5 mi eq and  c4 mi eq c5 gi eq and
                            or or or {/scr3 scr3 100 add def} if
                        } if
                        cleartomark
                    } {pop} ifelse
                } if
            } if
        } for
        scr1 scr3
    } def

    /evalmask {
        /sym exch def

        /n1 0 def /n2 0 def /n3 0 def
        /rle rows cols 2 copy lt {exch} if pop 2 mul 2 add array def
        /lastpairs cols array def
        /thispairs cols array def

        % Runlength encode and evaluate each column
        0 1 cols 1 sub {
            /i exch def
            mark 0 -1
            i cols rows cols mul 1 sub {
                sym exch get 2 copy eq {pop exch 1 add exch} {1 exch} ifelse
            } for
            rle 0 counttomark 2 sub getinterval astore
            evalrle n3 add /n3 exch def n1 add /n1 exch def
            pop
        } for

        0 1 rows 1 sub {
            /i exch def

            % Runlength encode and evaluate each row
            /symrow sym i cols mul cols getinterval def
            mark 0 -1
            symrow {
                2 copy eq {pop exch 1 add exch} {1 exch} ifelse
            } forall
            rle 0 counttomark 2 sub getinterval astore
            evalrle n3 add /n3 exch def n1 add /n1 exch def
            pop

            % Count and score same coloured blocks
            /lastpairs thispairs /thispairs lastpairs def def
            -1 symrow {exch 2 copy ne {pop -1 exch} if} forall
            pop
            thispairs astore pop
            i 0 gt {
                mark
                lastpairs aload pop thispairs aload pop
                n2 cols { exch dup -1 ne { cols 1 add index eq {3 add} if } {pop} ifelse } repeat
                /n2 exch def
                cleartomark
            } if
        } for

        n1 n2 add n3 add
    } def

    % Evaluate the masked symbols to find the most suitable
    /bestscore 999999999 def
    0 1 masks length 1 sub {
        /m exch def
        /masksym rows cols mul array def
        0 1 rows cols mul 1 sub {
            /i exch def
            masksym i pixs i get masks m get i get xor put
        } for
        masks length 1 ne {
            masksym evalmask /score exch def
            score bestscore lt {
                /bestsym masksym def
                /bestmaskval m def
                /bestscore score def
            } if
        } {
            /bestsym masksym def
        } ifelse
    } for
    /pixs bestsym def
    /metamask bestmaskval def

    % Derive the metadata bitstream
    /addtometapart {
        dup metapart p 3 -1 roll putinterval
        length p add /p exch def
    } def

    /addtometabits {
        dup metabits q 3 -1 roll putinterval
        length q add /q exch def
    } def

    /metapart 40 string def
    /metabits nummetabits string def
    /p 0 def  /q 0 def
    slave not {

        % Part I
        colors ln 2 ln div round cvi 1 sub
        3 tofixedbits addtometapart                                 % Nc
        metapart 0 p getinterval 2 -1 ldpc addtometabits  /p 0 def

        % Part II
        metass   1 tofixedbits addtometapart                        % SS
        metavf   2 tofixedbits addtometapart                        % VF
        metamask 3 tofixedbits addtometapart                        % MSK
        hasslaves {(1)} {(0)} ifelse addtometapart                  % SF
        metapart 0 p getinterval 2 -1 ldpc addtometabits  /p 0 def

        % Part III
        metass 0 eq {  % Square
            cols 17 sub 4 idiv [ 0 4 8 16 ] metavf get sub 1 sub
            metavlen tofixedbits addtometapart                      % V
        } {  % Rectangular
            cols 17 sub 4 idiv 1 sub
            metavlen 2 idiv tofixedbits addtometapart               % V1
            rows 17 sub 4 idiv 1 sub
            metavlen 2 idiv tofixedbits addtometapart               % V2
        } ifelse
        datawc 3 sub metaelen 2 idiv tofixedbits addtometapart      % E1
        datawr 4 sub metaelen 2 idiv tofixedbits addtometapart      % E2
        hasslaves {  % TODO Cascading
            0 4 tofixedbits addtometapart                           % S
        } if
        metapart 0 p getinterval 2 -1 ldpc addtometabits  /p 0 def

    } {  % slave

        % Part I
        sameshape {0} {1} ifelse 1 tofixedbits addtometapart        % SS
        sameecc   {0} {1} ifelse 1 tofixedbits addtometapart        % SE
        hasslaves {1} {0} ifelse 1 tofixedbits addtometapart        % SF
        metapart 0 p getinterval 2 -1 ldpc addtometabits  /p 0 def

        % Part II
        sameshape not {
            diffside 17 sub 4 idiv 1 sub
            5 tofixedbits addtometapart                             % V
        } if
        hasslaves {  % TODO Cascading
            0 3 tofixedbits addtometapart                           % S
        } if
        metapart 0 p getinterval 2 -1 ldpc addtometabits  /p 0 def

        % Part III
        sameecc not {
            datawc 3 sub metaelen 2 idiv tofixedbits addtometapart  % E1
            datawr 4 sub metaelen 2 idiv tofixedbits addtometapart  % E2
        } if
        metapart 0 p getinterval 2 -1 ldpc addtometabits  /p 0 def

    } ifelse
    q 1 nummetabits 1 sub {  % Pad with 0s
        metabits exch 48 put
    } for

    % Place the metadata
    /i 0 def  /j 0 def
    slave not {  % Two-color encoding of Part I (Nc) in master symbols
        metabits i 6 getinterval {
            colors 4 eq {[bi yi]} {[ki wi]} ifelse exch 48 sub get
            pixs metadatamap j get aload pop jmv 3 -1 roll put
            /j j 1 add def
        } forall
        /i i 6 add def
    } if
    nummetabits i sub metabpm idiv {
        metabits i metabpm getinterval 0 exch {48 sub add 2 mul} forall 2 idiv
        metacolorindex exch get
        pixs metadatamap j get aload pop jmv 3 -1 roll put
        /i i metabpm add def
        /j j 1 add def
    } repeat

    <<
    /ren //renmatrix
    /pixs pixs
    /pixx cols
    /pixy rows
    /colormap palette
    /height rows 2 mul 72 div
    /width  cols 2 mul 72 div
    /opt options
    >>

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/jabcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER jabcode--

% --BEGIN ENCODER gs1-cc--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renmatrix micropdf417 pdf417--
% --DESC: GS1 Composite 2D Component
% --EXAM: (01)95012345678903(3103)000123
% --EXOP: ccversion=b cccolumns=4
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp gs1-cc 0.0 2022082100 222469 205288
%%BeginData:        639 ASCII Lines
/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 /gs1process dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /pdf417 dup /uk.co.terryburton.bwipp findresource put
dup /micropdf417 dup /uk.co.terryburton.bwipp findresource put
begin
/gs1-cc {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /parse false def
    /dontlint false def
    /lintreqs false def
    /dontdraw false def
    /ccversion (a) def
    /cccolumns -1 def
    /lintype () def
    /linwidth -1 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

    /cccolumns cccolumns cvi def
    /linwidth linwidth cvi def

    /gs1-cc //loadctx exec

    % Select columns based on linear type
    cccolumns -1 eq {
        <<
            /ean13                  4
            /upca                   4
            /ean8                   3
            /upce                   2
            /gs1-128
                ccversion (c) ne {4} {linwidth 52 sub 17 idiv} ifelse
            /databaromni            4
            /databarstacked         2
            /databarstackedomni     2
            /databartruncated       4
            /databarlimited         3
            /databarexpanded        4
            /databarexpandedstacked 4
        >> lintype get /cccolumns exch def
    } if

    barcode /ai //gs1process exec
    /fncs exch def
    /vals exch def
    /ais exch def

    % Method selection
    /isupper {dup 65 ge exch 90 le and} def  % A-Z
    /isnum0  {dup 48 ge exch 57 le and} def  % 0-9
    /isnum1  {dup 49 ge exch 57 le and} def  % 1-9
    {  % common exit

        % (10/11/17)...
        ais length 1 ge {
            ais 0 get (10) eq ais 0 get (11) eq or ais 0 get (17) eq or {
                -1 (10) exit
            } if
        } if

        % (90){0-3 digits not starting 0}{upper alpha}...
        ais length 1 ge {
            ais 0 get (90) eq {
                /v vals 0 get def
                v length 1 ge {
                   v 0 get isupper {
                       0 (11) exit
                   } if
                } if
                v length 2 ge {
                   v 0 get isnum1
                   v 1 get isupper and {
                       1 (11) exit
                   } if
                } if
                v length 3 ge {
                    v 0 get isnum1
                    v 1 get isnum0 and
                    v 2 get isupper and {
                        2 (11) exit
                    } if
                } if
                v length 4 ge {
                    v 0 get isnum1
                    v 1 get isnum0 and
                    v 2 get isnum0 and
                    v 3 get isupper and {
                        3 (11) exit
                    } if
                } if
            } if
        } if

        % Freeform
        -1 (0) exit

    } loop
    /method exch def
    /npre exch 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

    /alpha <<
        65 1 90 {dup 65 sub 5 tobin} for
        48 1 57 {dup 4 add 6 tobin} for
        fnc1 (11111)
    >> def

    /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

    method (10) eq {  % TODO: fixme
        ais 0 get (11) eq ais 0 get (17) eq or {
            vals 0 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
            (0000000000000000) 16 string copy dup 3 -1 roll 2 16 string cvrs
            dup length 16 exch sub exch putinterval
            [ 1 0
              4 -1 roll {48 sub} forall
              ais 0 get (11) eq {0} {1} ifelse
            ] /cdf exch 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
        } {
            /cdf [ 1 0  1 1 ] def
        } ifelse
        ais length 0 ne {
            ais 0 get (10) eq {
                /gpf [ vals 0 get {} forall ] def
                ais length 1 gt {/gpf [ gpf aload pop fnc1 ] def} if  % TODO: check
                /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
            } {
                /gpf [fnc1] def  % TODO: check
            } ifelse
        } {
            /cdf [ cdf aload pop 0 0 0 0 0 1 1 1 1 ] def
            /gpf [] def
        } ifelse
        /mode (numeric) def
    } if

    method (11) eq {
        /cdf [ 1 1 ] def
        /ai90 vals 0 get def
        npre 1 add ai90 length ne {
            ai90 npre 1 add ai90 length npre sub 1 sub getinterval
        } {
            ()
        } ifelse
        /ai90rem exch def
        /nalpha 0 ai90rem {dup 65 ge exch 90 le and {1 add} if} forall def
        /nnums  0 ai90rem {dup 48 ge exch 57 le and {1 add} if} forall def
        /mode nalpha nnums gt {(alpha)} { nalpha 0 eq {(numeric)} {(alphanumeric)} ifelse } ifelse def
        nalpha nnums add ai90rem length ne {/mode (alphanumeric) def} if
        /cdf [
            cdf aload pop
            mode (alphanumeric) eq {0} if
            mode (numeric) eq {1 0} if
            mode (alpha) eq {1 1} if
        ] def
        /ais1  ais  length 1 gt {ais  1 get} {-1} ifelse def
        /vals1 vals length 1 gt {vals 1 get} {-1} ifelse def
        ais1 (21) eq ais1 (8004) eq or {
            /cdf [ cdf aload pop ais1 (21) eq {1 0} {1 1} ifelse ] def
        } {
            /cdf [ cdf aload pop 0 ] def
        } ifelse
        /nval npre 0 ne {ai90 0 npre getinterval cvi} {0} ifelse def
        (BDHIJKLNPQRSTVXZ) ai90 npre 1 getinterval search {
            length exch pop exch pop
            /aval exch def
        } {
            pop /aval -1 def
        } ifelse
        nval 31 lt aval -1 ne and {
            (00000) 5 string copy dup nval 2 5 string cvrs
            dup length 5 exch sub exch putinterval
            [ exch {48 sub} forall ] /nbits exch def
            (0000) 4 string copy dup aval 2 4 string cvrs
            dup length 4 exch sub exch putinterval
            [ exch {48 sub} forall ] /abits exch def
            /cdf [
                cdf aload pop
                nbits aload pop
                abits aload pop
            ] def
        } {
            (0000000000) 10 string copy dup nval 2 10 string cvrs
            dup length 10 exch sub exch putinterval
            [ exch {48 sub} forall ] /nbits exch def
            (00000) 5 string copy dup ai90 npre get 65 sub 2 5 string cvrs
            dup length 5 exch sub exch putinterval
            [ exch {48 sub} forall ] /abits exch def
            /cdf [
                cdf aload pop
                1 1 1 1 1
                nbits aload pop
                abits aload pop
            ] def
        } ifelse
        mode (alpha) ne {
            /gpf [ ai90rem {} forall ais length 1 gt {fnc1} if ] def
        } {
            /in [ ai90rem {} forall ais length 1 gt {fnc1} if ] def
            /out in length 6 mul array def
            /j 0 def
            0 1 in length 1 sub {
                in exch get alpha exch get
                dup [ exch {48 sub} forall ] out exch j exch putinterval
                length j add /j exch def
            } for
            /cdf [
                cdf aload pop
                out 0 j getinterval aload pop
            ] def
            /gpf [] def
            ais length 1 gt {/mode (numeric) def} if
        } ifelse
        /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
        ais length 0 ne {
            ais1 (21) eq ais1 (8004) eq or {
                /gpf [
                    gpf aload pop
                    vals1 {} forall
                ] 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
                ais length 0 ne {/gpf [gpf aload pop fnc1] def} if
            } if
        } if
    } if

    method (0) eq {
        /cdf [ 0 ] def
        /gpf [] def
        /mode (numeric) def
    } if

    % 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
{
    /bitcapsmaps <<
        /a [
            [167 138 118 108 88 78 59]
            [167 138 118  98 78]
            [197 167 138 108 78]
        ]
        /b [
            [ 336  296 256 208 160 104  56]
            [ 768  648 536 416 304 208 152 112  72 32]
            [1184 1016 840 672 496 352 264 208 152 96 56]
        ]
    >> def
} ctxdef

    /rembits {
        /used exch def
        ccversion (c) ne {  % cc-a or cc-b
            /bitcaps bitcapsmaps ccversion get cccolumns 2 sub get def
            -1 bitcaps {dup used ge {exch} if pop} forall
            dup -1 ne {used sub} if
        } {
            << /c -1 >> ccversion get pop  % Assert cc-c
            /m used 8 div ceiling cvi dup 6 idiv 5 mul exch 6 mod add def
            m   40 le               {8 } if
            m   41 ge m  160 le and {16} if
            m  161 ge m  320 le and {32} if
            m  321 ge m  833 le and {64} if  % 833 = 900 - 3 - 64, where 900 = 30 rows x 30 cols limit
            m  834 ge               {32} if  % Reduce to meet advertised "up to 2361 digits" (allows max 2372) within 900 limit
            /eccws exch def
            /m m eccws add 3 add def
            cccolumns 30 gt { /cccolumns 30 def } if
            {  % Loop until rows <= 30 or columns >= 30 (GS1 General Specifications 5.11.2.3)
                m cccolumns div ceiling cvi 30 le cccolumns 30 ge or {exit} if
                /cccolumns cccolumns 1 add def
            } loop
            /r m cccolumns div ceiling cvi def
            r 3 lt { /r 3 def } if  % GS1 General Specifications 5.11.2.3 "3 to 30 rows"
            /tgt cccolumns r mul eccws sub 3 sub dup 5 idiv 6 mul exch 5 mod add 8 mul def
            used 8304 le {tgt used sub} {-1} ifelse
        } ifelse
        dup -1 eq {  % Upgrade CC-A to CC-B or CC-B to CC-C to fit
            pop
            ccversion (a) eq {
                /ccversion (b) def
            } {
                ccversion (b) eq lintype (gs1-128) eq and {
                    /ccversion (c) def
                    /cccolumns linwidth 52 sub 17 idiv def
                } {
                    /ccversion -1 def
                } ifelse
            } ifelse
            used rembits
        } if
    } def

    /encode {
        dup /raw ne {exch get} {pop} ifelse
        [ 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 8304 array def  % 8304 = (865 / 5) * 6 * 8, where 865 = 900 - 3 - 32
    /i 0 def /j 0 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 cdf length 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

    % Create pad
    /pad cdf length gpf length add rembits array def
    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
        mode (alpha) eq {  % Prefix FNC1 + shift from numeric to ASCII
            /pad [ 1 1 1 1 1 0 0 0 0 pad aload pop ] 0 pad length getinterval def
        } if
    } if

    % Concatenate fields
    /bits [
        cdf aload pop
        gpf aload pop
        pad aload pop
    ] def

{
    /pwr928 [
        [ 0 0 0 0 0 0 1 ]
        68 {7 array} repeat
    ] def
    1 1 68 {
        /j exch def
        /v 0 def
        6 -1 1 {
            /i exch def
            /v pwr928 j 1 sub get i get 2 mul v 928 idiv add def
            pwr928 j get i v 928 mod put
        } for
        pwr928 j get 0 pwr928 j 1 sub get 0 get 2 mul v 928 idiv add put
    } for
} ctxdef

    ccversion (a) eq {
        /cws [ 28 {0} repeat ] def
        /b 0 def /c 0 def
        {  % loop
            b bits length eq {exit} if
            /bs bits b 69 bits length b sub 2 copy gt {exch} if pop getinterval def
            /bsl bs length def
            /cs cws c bsl 10 idiv 1 add getinterval def
            /csl cs length def
            0 1 bsl 1 sub {
                /i exch def
                0 1 csl 1 sub {
                    /j exch def
                    cs j 2 copy get
                    pwr928 i get j 7 add csl sub get
                    bs bsl i sub 1 sub get
                    mul add put
                } for
            } for
            csl 1 sub -1 1 {
                /i exch def
                cs i 1 sub 2 copy get cs i get 928 idiv add put
                cs i 2 copy get 928 mod put
            } for
            /b b bsl add def
            /c c csl add def
        } loop
        /cws cws 0 c getinterval def
        /barcode cws length 4 mul string def
        0 1 cws length 1 sub {
            /i exch def
            (^   ) 4 string copy dup cws i get 10 4 string cvrs
            dup length 4 exch sub exch putinterval
            barcode i 4 mul 3 -1 roll putinterval
        } for
        options (parse) undef
        options (dontdraw) true put
        options (cca) true put
        options (columns) cccolumns put
        /args barcode options //micropdf417 exec def
    } if

    ccversion (b) eq {
        /barcode bits length 8 idiv string def
        0 1 barcode length 1 sub {
            /i exch def
            bits i 8 mul 8 getinterval 0 exch {add 2 mul} forall 2 idiv
            barcode exch i exch put
        } for
        options (parse) undef
        options (dontdraw) true put
        options (ccb) true put
        options (columns) cccolumns put
        /args barcode options //micropdf417 exec def
    } if

    ccversion (c) eq {
        /barcode bits length 8 idiv string def
        0 1 barcode length 1 sub {
            /i exch def
            bits i 8 mul 8 getinterval 0 exch {add 2 mul} forall 2 idiv
            barcode exch i exch put
        } for
        options (parse) undef
        options (dontdraw) true put
        options (ccc) true put
        options (columns) cccolumns put
        options (eclevel) eccws ln 2 ln div cvi 1 sub put
        /args barcode options //pdf417 exec def
    } if

    args
    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/gs1-cc dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER gs1-cc--

% --BEGIN ENCODER ean13composite--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix ean5 ean2 ean13 micropdf417 pdf417 gs1-cc--
% --DESC: EAN-13 Composite
% --EXAM: 2112345678900|(99)1234-abcd
% --EXOP: includetext
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp ean13composite 0.0 2022082100 105183 107941
%%BeginData:        159 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /ean13 dup /uk.co.terryburton.bwipp findresource put
dup /gs1-cc 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
/ean13composite {

    20 dict begin            % Confine variables to local scope

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /usematrix false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    dontdraw { /usematrix true def } if

    % Split the linear and composite parts
    barcode (|) search {
        /linear exch def
        pop
        /comp exch def
    } {
        pop
    } ifelse

    options (lintype) (ean13) put
    options (inkspread) (0) put
    options (dontdraw) true put
    options (dontlint) true put

    % Lint with a fake AI (01)
    comp length 18 add string
    dup 0 ((01)00000000000000) putinterval
    dup 18 comp putinterval
    /ai //gs1process exec pop pop pop

    % Plot the linear part
    linear options //ean13 exec
    usematrix not {
        gsave

        //renlinear exec

        % Plot the separator
        -1 72 rmoveto <<
            /ren //renmatrix
            /pixs [
                0 1  93 {0} repeat  1 0
                1 0  93 {0} repeat  0 1
                0 1  93 {0} repeat  1 0
            ]
            /pixx 97
            /pixy 3
            /height 6 72 div
            /width 97 72 div
            /opt options
        >> //renmatrix exec

        % Plot the 2D part
        -2 6 rmoveto comp options //gs1-cc exec //renmatrix exec

        grestore
    } {
        /linsym exch def
        /sbs linsym /sbs get def
        /bhs linsym /bhs get def
        /bbs linsym /bbs get def
        /linwidth 0 sbs {cvi add} forall def

        /compsym comp options //gs1-cc exec def
        /ccpixs compsym /pixs get def
        /ccpixx compsym /pixx get def

        /linpad [ ccpixx 97 sub {0} repeat ] def

        /diff linwidth linpad length add 2 add ccpixx sub def  % An add-on can make linear wider than composite
        diff 0 gt {  % Left align composite
            /ccrpad [ diff {0} repeat ] def
            /pixx ccpixx diff add def
        } {
            /ccrpad 0 array def
            /pixx ccpixx def
        } ifelse

        /pixs [
            0 ccpixx ccpixs length 1 sub {
                /i exch def
                2 { ccpixs i ccpixx getinterval aload pop ccrpad aload pop } repeat
            } for
            2 { linpad aload pop 0 1  93 {0} repeat  1 0 ccrpad aload pop } repeat
            2 { linpad aload pop 1 0  93 {0} repeat  0 1 ccrpad aload pop } repeat
            2 { linpad aload pop 0 1  93 {0} repeat  1 0 ccrpad aload pop } repeat
            71 -1 0 {
                /y exch def
                linpad aload pop
                0
                0 1 sbs length 1 sub {
                    /i exch def
                    i 2 mod 0 eq {
                        % Don't print when bbs > y || (bbs + bhs) < y (i.e. add-on or includetext offsets)
                        bbs i 2 idiv get 72 mul dup y gt exch bhs i 2 idiv get 72 mul add y lt or {
                            sbs i get cvi {0} repeat
                        } {
                            sbs i get cvi {1} repeat
                        } ifelse
                    } {
                        sbs i get cvi {0} repeat
                    } ifelse
                } for
                0
            } for
        ] def

        /pixy pixs length pixx idiv def
        <<
        /ren //renmatrix
        /pixs pixs
        /pixx pixx
        /pixy pixy
        /height pixy 72 div
        /width pixx 72 div
        /opt options
        >>

        dontdraw not {
            gsave
            //renmatrix exec
            grestore
        } if
    } ifelse

    end

}
[/barcode] {null def} forall
bind def
/ean13composite dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER ean13composite--

% --BEGIN ENCODER ean8composite--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix ean5 ean2 ean8 micropdf417 pdf417 gs1-cc--
% --DESC: EAN-8 Composite
% --EXAM: 02345673|(21)A12345678
% --EXOP: includetext
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp ean8composite 0.0 2022082100 109084 108283
%%BeginData:        162 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /ean8 dup /uk.co.terryburton.bwipp findresource put
dup /gs1-cc 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
/ean8composite {

    20 dict begin            % Confine variables to local scope

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /usematrix false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    dontdraw { /usematrix true def } if

    % Split the linear and composite parts
    barcode (|) search {
        /linear exch def
        pop
        /comp exch def
    } {
        pop
    } ifelse

    % Get the result of encoding with ean8 and gs1-cc
    options (lintype) (ean8) put
    options (inkspread) (0) put
    options (dontdraw) true put
    options (dontlint) true put

    % Lint with a fake AI (01)
    comp length 18 add string
    dup 0 ((01)00000000000000) putinterval
    dup 18 comp putinterval
    /ai //gs1process exec pop pop pop

    % Plot the linear part
    linear options //ean8 exec
    usematrix not {
        gsave

        //renlinear exec

        % Plot the separator
        -1 72 rmoveto <<
            /ren //renmatrix
            /pixs [
                0 1  65 {0} repeat  1 0
                1 0  65 {0} repeat  0 1
                0 1  65 {0} repeat  1 0
            ]
            /pixx 69
            /pixy 3
            /height 6 72 div
            /width 69 72 div
            /opt options
        >> //renmatrix exec

        % Plot the 2D part
        comp options //gs1-cc exec
        dup (pixx) get 69 exch sub 6 rmoveto
        //renmatrix exec

        grestore
    } {
        /linsym exch def
        /sbs linsym /sbs get def
        /bhs linsym /bhs get def
        /bbs linsym /bbs get def
        /linwidth 0 sbs {cvi add} forall def

        /compsym comp options //gs1-cc exec def
        /ccpixs compsym /pixs get def
        /ccpixx compsym /pixx get def

        /linpad [ ccpixx 69 sub {0} repeat ] def

        /diff linwidth linpad length add 2 add ccpixx sub def  % An add-on can make linear wider than composite
        diff 0 gt {  % Left align composite
            /ccrpad [ diff {0} repeat ] def
            /pixx ccpixx diff add def
        } {
            /ccrpad 0 array def
            /pixx ccpixx def
        } ifelse

        /pixs [
            0 ccpixx ccpixs length 1 sub {
                /i exch def
                2 { ccpixs i ccpixx getinterval aload pop ccrpad aload pop } repeat
            } for
            2 { linpad aload pop 0 1  65 {0} repeat  1 0 ccrpad aload pop } repeat
            2 { linpad aload pop 1 0  65 {0} repeat  0 1 ccrpad aload pop } repeat
            2 { linpad aload pop 0 1  65 {0} repeat  1 0 ccrpad aload pop } repeat
            71 -1 0 {
                /y exch def
                linpad aload pop
                0
                0 1 sbs length 1 sub {
                    /i exch def
                    i 2 mod 0 eq {
                        % Don't print when bbs > y || (bbs + bhs) < y (i.e. add-on or includetext offsets)
                        bbs i 2 idiv get 72 mul dup y gt exch bhs i 2 idiv get 72 mul add y lt or {
                            sbs i get cvi {0} repeat
                        } {
                            sbs i get cvi {1} repeat
                        } ifelse
                    } {
                        sbs i get cvi {0} repeat
                    } ifelse
                } for
                0
            } for
        ] def

        /pixy pixs length pixx idiv def
        <<
        /ren //renmatrix
        /pixs pixs
        /pixx pixx
        /pixy pixy
        /height pixy 72 div
        /width pixx 72 div
        /opt options
        >>

        dontdraw not {
            gsave
            //renmatrix exec
            grestore
        } if
    } ifelse

    end

}
[/barcode] {null def} forall
bind def
/ean8composite dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER ean8composite--

% --BEGIN ENCODER upcacomposite--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix ean5 ean2 upca micropdf417 pdf417 gs1-cc--
% --DESC: UPC-A Composite
% --EXAM: 416000336108|(99)1234-abcd
% --EXOP: includetext
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp upcacomposite 0.0 2022082100 105177 107936
%%BeginData:        159 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /upca dup /uk.co.terryburton.bwipp findresource put
dup /gs1-cc 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
/upcacomposite {

    20 dict begin            % Confine variables to local scope

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /usematrix false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    dontdraw { /usematrix true def } if

    % Split the linear and composite parts
    barcode (|) search {
        /linear exch def
        pop
        /comp exch def
    } {
        pop
    } ifelse

    options (lintype) (ean13) put
    options (inkspread) (0) put
    options (dontdraw) true put
    options (dontlint) true put

    % Lint with a fake AI (01)
    comp length 18 add string
    dup 0 ((01)00000000000000) putinterval
    dup 18 comp putinterval
    /ai //gs1process exec pop pop pop

    % Plot the linear part
    linear options //upca exec
    usematrix not {
        gsave

        //renlinear exec

        % Plot the separator
        -1 72 rmoveto <<
            /ren //renmatrix
            /pixs [
                0 1  93 {0} repeat  1 0
                1 0  93 {0} repeat  0 1
                0 1  93 {0} repeat  1 0
            ]
            /pixx 97
            /pixy 3
            /height 6 72 div
            /width 97 72 div
            /opt options
        >> //renmatrix exec

        % Plot the 2D part
        -2 6 rmoveto comp options //gs1-cc exec //renmatrix exec

        grestore
    } {
        /linsym exch def
        /sbs linsym /sbs get def
        /bhs linsym /bhs get def
        /bbs linsym /bbs get def
        /linwidth 0 sbs {cvi add} forall def

        /compsym comp options //gs1-cc exec def
        /ccpixs compsym /pixs get def
        /ccpixx compsym /pixx get def

        /linpad [ ccpixx 97 sub {0} repeat ] def

        /diff linwidth linpad length add 2 add ccpixx sub def  % An add-on can make linear wider than composite
        diff 0 gt {  % Left align composite
            /ccrpad [ diff {0} repeat ] def
            /pixx ccpixx diff add def
        } {
            /ccrpad 0 array def
            /pixx ccpixx def
        } ifelse

        /pixs [
            0 ccpixx ccpixs length 1 sub {
                /i exch def
                2 { ccpixs i ccpixx getinterval aload pop ccrpad aload pop } repeat
            } for
            2 { linpad aload pop 0 1  93 {0} repeat  1 0 ccrpad aload pop } repeat
            2 { linpad aload pop 1 0  93 {0} repeat  0 1 ccrpad aload pop } repeat
            2 { linpad aload pop 0 1  93 {0} repeat  1 0 ccrpad aload pop } repeat
            71 -1 0 {
                /y exch def
                linpad aload pop
                0
                0 1 sbs length 1 sub {
                    /i exch def
                    i 2 mod 0 eq {
                        % Don't print when bbs > y || (bbs + bhs) < y (i.e. add-on or includetext offsets)
                        bbs i 2 idiv get 72 mul dup y gt exch bhs i 2 idiv get 72 mul add y lt or {
                            sbs i get cvi {0} repeat
                        } {
                            sbs i get cvi {1} repeat
                        } ifelse
                    } {
                        sbs i get cvi {0} repeat
                    } ifelse
                } for
                0
            } for
        ] def

        /pixy pixs length pixx idiv def
        <<
        /ren //renmatrix
        /pixs pixs
        /pixx pixx
        /pixy pixy
        /height pixy 72 div
        /width pixx 72 div
        /opt options
        >>

        dontdraw not {
            gsave
            //renmatrix exec
            grestore
        } if
    } ifelse

    end

}
[/barcode] {null def} forall
bind def
/upcacomposite dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER upcacomposite--

% --BEGIN ENCODER upcecomposite--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix ean5 ean2 upce micropdf417 pdf417 gs1-cc--
% --DESC: UPC-E Composite
% --EXAM: 00123457|(15)021231
% --EXOP: includetext
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp upcecomposite 0.0 2022082100 108608 104503
%%BeginData:        159 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /upce dup /uk.co.terryburton.bwipp findresource put
dup /gs1-cc 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
/upcecomposite {

    20 dict begin            % Confine variables to local scope

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /usematrix false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    dontdraw { /usematrix true def } if

    % Split the linear and composite parts
    barcode (|) search {
        /linear exch def
        pop
        /comp exch def
    } {
        pop
    } ifelse

    options (lintype) (upce) put
    options (inkspread) (0) put
    options (dontdraw) true put
    options (dontlint) true put

    % Lint with a fake AI (01)
    comp length 18 add string
    dup 0 ((01)00000000000000) putinterval
    dup 18 comp putinterval
    /ai //gs1process exec pop pop pop

    % Plot the linear part
    linear options //upce exec
    usematrix not {
        gsave

        //renlinear exec

        % Plot the separator
        -1 72 rmoveto <<
            /ren //renmatrix
            /pixs [
                0 1  49 {0} repeat  1 0
                1 0  49 {0} repeat  0 1
                0 1  49 {0} repeat  1 0
            ]
            /pixx 53
            /pixy 3
            /height 6 72 div
            /width 53 72 div
            /opt options
        >> //renmatrix exec

        % Plot the 2D part
        -2 6 rmoveto comp options //gs1-cc exec //renmatrix exec

        grestore
    } {
        /linsym exch def
        /sbs linsym /sbs get def
        /bhs linsym /bhs get def
        /bbs linsym /bbs get def
        /linwidth 0 sbs {cvi add} forall def

        /compsym comp options //gs1-cc exec def
        /ccpixs compsym /pixs get def
        /ccpixx compsym /pixx get def

        /linpad [ ccpixx 53 sub {0} repeat ] def

        /diff linwidth linpad length add 2 add ccpixx sub def  % An add-on can make linear wider than composite
        diff 0 gt {  % Left align composite
            /ccrpad [ diff {0} repeat ] def
            /pixx ccpixx diff add def
        } {
            /ccrpad 0 array def
            /pixx ccpixx def
        } ifelse

        /pixs [
            0 ccpixx ccpixs length 1 sub {
                /i exch def
                2 { ccpixs i ccpixx getinterval aload pop ccrpad aload pop } repeat
            } for
            2 { linpad aload pop 0 1  49 {0} repeat  1 0 ccrpad aload pop } repeat
            2 { linpad aload pop 1 0  49 {0} repeat  0 1 ccrpad aload pop } repeat
            2 { linpad aload pop 0 1  49 {0} repeat  1 0 ccrpad aload pop } repeat
            71 -1 0 {
                /y exch def
                linpad aload pop
                0
                0 1 sbs length 1 sub {
                    /i exch def
                    i 2 mod 0 eq {
                        % Don't print when bbs > y || (bbs + bhs) < y (i.e. add-on or includetext offsets)
                        bbs i 2 idiv get 72 mul dup y gt exch bhs i 2 idiv get 72 mul add y lt or {
                            sbs i get cvi {0} repeat
                        } {
                            sbs i get cvi {1} repeat
                        } ifelse
                    } {
                        sbs i get cvi {0} repeat
                    } ifelse
                } for
                0
            } for
        ] def

        /pixy pixs length pixx idiv def
        <<
        /ren //renmatrix
        /pixs pixs
        /pixx pixx
        /pixy pixy
        /height pixy 72 div
        /width pixx 72 div
        /opt options
        >>

        dontdraw not {
            gsave
            //renmatrix exec
            grestore
        } if
    } ifelse

    end

}
[/barcode] {null def} forall
bind def
/upcecomposite dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER upcecomposite--

% --BEGIN ENCODER databaromnicomposite--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix databaromni micropdf417 pdf417 gs1-cc--
% --DESC: GS1 DataBar Omnidirectional Composite
% --EXAM: (01)03612345678904|(11)990102
% --EXOP:
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databaromnicomposite 0.0 2022082100 94570 94434
%%BeginData:        114 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /databaromni dup /uk.co.terryburton.bwipp findresource put
dup /gs1-cc 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
/databaromnicomposite {

    20 dict begin            % Confine variables to local scope

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    % Split the linear and composite parts
    barcode (|) search {
        /linear exch def
        pop
        /comp exch def
    } {
        pop
    } ifelse

    gsave

    options (lintype) (databaromni) put
    options (linkage) true put
    options (inkspread) (0) put
    options (dontdraw) true put
    options (dontlint) true put

    % Lint the combined AI element strings
    linear length comp length add string
    dup 0 linear putinterval
    dup linear length comp putinterval
    /ai //gs1process exec pop pop pop

    % Plot the linear part
    linear options //databaromni exec
    dup (sbs) get /linsbs exch def
    dup (bhs) get 0 get 72 mul /linheight exch def
    //renlinear exec

    % Plot the separator
    /sepfinder {
        /fp exch def
        fp 1 fp 12 add {
            /i exch def
            bot i get 0 eq {
                bot 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
        /f3 [1 1 1 1 1 1 1 1 1 0 1 1 1] def
        true 0 1 12 {dup bot exch fp add get exch f3 exch get eq and} for {
            % Right shifted module for value 3 finder
            sep fp [ 0 0 0 0 0 0 0 0 0 0 1 0 0 ] putinterval
        } if
    } def
    mark
    0 linsbs {1 index 1 eq {{0}} {{1}} ifelse repeat} forall
    counttomark 1 sub array astore /bot exch def pop pop
    /sep [ bot {1 exch sub} forall ] def
    sep 0 [0 0 0] putinterval
    sep sep length 4 sub [0 0 0 0] putinterval
    18 sepfinder 64 sepfinder
    0 linheight rmoveto <<
        /ren //renmatrix
        /pixs sep
        /pixx sep length
        /pixy 1
        /height 1 72 div
        /width sep length 72 div
        /opt options
    >> //renmatrix exec

    % Plot the 2D part
    -5 1 rmoveto comp options //gs1-cc exec //renmatrix exec

    grestore

    end

}
[/barcode] {null def} forall
bind def
/databaromnicomposite dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databaromnicomposite--

% --BEGIN ENCODER databarstackedcomposite--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix databaromni databarstacked micropdf417 pdf417 gs1-cc--
% --DESC: GS1 DataBar Stacked Composite
% --EXAM: (01)03412345678900|(17)010200
% --EXOP:
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databarstackedcomposite 0.0 2022082100 96302 96201
%%BeginData:        110 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /databarstacked dup /uk.co.terryburton.bwipp findresource put
dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put
dup /gs1process dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/databarstackedcomposite {

    20 dict begin            % Confine variables to local scope

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    % Split the linear and composite parts
    barcode (|) search {
        /linear exch def
        pop
        /comp exch def
    } {
        pop
    } ifelse

    gsave

    options (lintype) (databarstacked) put
    options (linkage) true put
    options (inkspread) (0) put
    options (dontdraw) true put
    options (dontlint) true put

    % Lint the combined AI element strings
    linear length comp length add string
    dup 0 linear putinterval
    dup linear length comp putinterval
    /ai //gs1process exec pop pop pop

    % Plot the linear part
    linear options //databarstacked exec
    dup (pixs) get 0 2 index (pixx) get getinterval /bot exch def
    dup (pixy) get /linheight exch def
    //renmatrix exec

    % Plot the separator
    /sepfinder {
        /fp exch def
        fp 1 fp 12 add {
            /i exch def
            bot i get 0 eq {
                bot 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
        /f3 [1 1 1 1 1 1 1 1 1 0 1 1 1] def
        true 0 1 12 {dup bot exch fp add get exch f3 exch get eq and} for {
            % Right shifted module for value 3 finder
            sep fp [ 0 0 0 0 0 0 0 0 0 0 1 0 0 ] putinterval
        } if
    } def
    /sep [ bot {1 exch sub} forall ] def
    sep 0 [ 0 0 0 0 ] putinterval
    sep sep length 4 sub [ 0 0 0 0 ] putinterval
    18 sepfinder
    0 linheight rmoveto <<
        /ren //renmatrix
        /pixs sep
        /pixx sep length
        /pixy 1
        /height 1 72 div
        /width sep length 72 div
        /opt options
    >> //renmatrix exec

    % Plot the 2D part
    1 1 rmoveto comp options //gs1-cc exec //renmatrix exec

    grestore

    end

}
[/barcode] {null def} forall
bind def
/databarstackedcomposite dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databarstackedcomposite--

% --BEGIN ENCODER databarstackedomnicomposite--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix databaromni databarstackedomni micropdf417 pdf417 gs1-cc--
% --DESC: GS1 DataBar Stacked Omnidirectional Composite
% --EXAM: (01)03612345678904|(11)990102
% --EXOP:
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databarstackedomnicomposite 0.0 2022082100 96354 96225
%%BeginData:        110 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /databarstackedomni dup /uk.co.terryburton.bwipp findresource put
dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put
dup /gs1process dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/databarstackedomnicomposite {

    20 dict begin            % Confine variables to local scope

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    % Split the linear and composite parts
    barcode (|) search {
        /linear exch def
        pop
        /comp exch def
    } {
        pop
    } ifelse

    gsave

    options (lintype) (databarstackedomni) put
    options (linkage) true put
    options (inkspread) (0) put
    options (dontdraw) true put
    options (dontlint) true put

    % Lint the combined AI element strings
    linear length comp length add string
    dup 0 linear putinterval
    dup linear length comp putinterval
    /ai //gs1process exec pop pop pop

    % Plot the linear part
    linear options //databarstackedomni exec
    dup (pixs) get 0 2 index (pixx) get getinterval /bot exch def
    dup (pixy) get /linheight exch def
    //renmatrix exec

    % Plot the separator
    /sepfinder {
        /fp exch def
        fp 1 fp 12 add {
            /i exch def
            bot i get 0 eq {
                bot 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
        /f3 [1 1 1 1 1 1 1 1 1 0 1 1 1] def
        true 0 1 12 {dup bot exch fp add get exch f3 exch get eq and} for {
            % Right shifted module for value 3 finder
            sep fp [ 0 0 0 0 0 0 0 0 0 0 1 0 0 ] putinterval
        } if
    } def
    /sep [ bot {1 exch sub} forall ] def
    sep 0 [ 0 0 0 0 ] putinterval
    sep sep length 4 sub [ 0 0 0 0 ] putinterval
    18 sepfinder
    0 linheight rmoveto <<
        /ren //renmatrix
        /pixs sep
        /pixx sep length
        /pixy 1
        /height 1 72 div
        /width sep length 72 div
        /opt options
    >> //renmatrix exec

    % Plot the 2D part
    1 1 rmoveto comp options //gs1-cc exec //renmatrix exec

    grestore

    end

}
[/barcode] {null def} forall
bind def
/databarstackedomnicomposite dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databarstackedomnicomposite--

% --BEGIN ENCODER databartruncatedcomposite--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix databaromni databartruncated micropdf417 pdf417 gs1-cc--
% --DESC: GS1 DataBar Truncated Composite
% --EXAM: (01)03612345678904|(11)990102
% --EXOP:
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databartruncatedcomposite 0.0 2022082100 97436 97319
%%BeginData:        114 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /databartruncated dup /uk.co.terryburton.bwipp findresource put
dup /gs1-cc 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
/databartruncatedcomposite {

    20 dict begin            % Confine variables to local scope

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    % Split the linear and composite parts
    barcode (|) search {
        /linear exch def
        pop
        /comp exch def
    } {
        pop
    } ifelse

    gsave

    options (lintype) (databartruncated) put
    options (linkage) true put
    options (inkspread) (0) put
    options (dontdraw) true put
    options (dontlint) true put

    % Lint the combined AI element strings
    linear length comp length add string
    dup 0 linear putinterval
    dup linear length comp putinterval
    /ai //gs1process exec pop pop pop

    % Plot the linear part
    linear options //databartruncated exec
    dup (sbs) get /linsbs exch def
    dup (bhs) get 0 get 72 mul /linheight exch def
    //renlinear exec

    % Plot the separator
    /sepfinder {
        /fp exch def
        fp 1 fp 12 add {
            /i exch def
            bot i get 0 eq {
                bot 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
        /f3 [1 1 1 1 1 1 1 1 1 0 1 1 1] def
        true 0 1 12 {dup bot exch fp add get exch f3 exch get eq and} for {
            % Right shifted module for value 3 finder
            sep fp [ 0 0 0 0 0 0 0 0 0 0 1 0 0 ] putinterval
        } if
    } def
    mark
    0 linsbs {1 index 1 eq {{0}} {{1}} ifelse repeat} forall
    counttomark 1 sub array astore /bot exch def pop pop
    /sep [ bot {1 exch sub} forall ] def
    sep 0 [0 0 0] putinterval
    sep sep length 4 sub [0 0 0 0] putinterval
    18 sepfinder 64 sepfinder
    0 linheight rmoveto <<
        /ren //renmatrix
        /pixs sep
        /pixx sep length
        /pixy 1
        /height 1 72 div
        /width sep length 72 div
        /opt options
    >> //renmatrix exec

    % Plot the 2D part
    -5 1 rmoveto comp options //gs1-cc exec //renmatrix exec

    grestore

    end

}
[/barcode] {null def} forall
bind def
/databartruncatedcomposite dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databartruncatedcomposite--

% --BEGIN ENCODER databarlimitedcomposite--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix databarlimited micropdf417 pdf417 gs1-cc--
% --DESC: GS1 DataBar Limited Composite
% --EXAM: (01)03512345678907|(21)abcdefghijklmnopqrst
% --EXOP:
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databarlimitedcomposite 0.0 2022082100 87443 90776
%%BeginData:         93 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /databarlimited dup /uk.co.terryburton.bwipp findresource put
dup /gs1-cc 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
/databarlimitedcomposite {

    20 dict begin            % Confine variables to local scope

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    % Split the linear and composite parts
    barcode (|) search {
        /linear exch def
        pop
        /comp exch def
    } {
        pop
    } ifelse

    gsave

    options (lintype) (databarlimited) put
    options (linkage) true put
    options (inkspread) (0) put
    options (dontdraw) true put
    options (dontlint) true put

    % Lint the combined AI element strings
    linear length comp length add string
    dup 0 linear putinterval
    dup linear length comp putinterval
    /ai //gs1process exec pop pop pop

    % Plot the linear part
    linear options //databarlimited exec
    dup (sbs) get /linsbs exch def
    dup (bhs) get 0 get 72 mul /linheight exch def
    //renlinear exec

    % Plot the separator
    mark
    1 linsbs {1 index 0 eq {{1}} {{0}} ifelse repeat} forall
    counttomark 1 sub array astore /sep exch def pop pop
    sep 0 [0 0 0] putinterval
    sep sep length 9 sub [0 0 0 0 0 0 0 0 0] putinterval % 4 + 5 right guard spaces
    0 linheight rmoveto <<
        /ren //renmatrix
        /pixs sep
        /pixx sep length
        /pixy 1
        /height 1 72 div
        /width sep length 72 div
        /opt options
    >> //renmatrix exec

    % Plot the 2D part
    comp options //gs1-cc exec
    dup (pixx) get 72 exch sub 1 rmoveto
    //renmatrix exec

    grestore

    end

}
[/barcode] {null def} forall
bind def
/databarlimitedcomposite dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databarlimitedcomposite--

% --BEGIN ENCODER databarexpandedcomposite--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix databarexpanded micropdf417 pdf417 gs1-cc--
% --DESC: GS1 DataBar Expanded Composite
% --EXAM: (01)93712345678904(3103)001234|(91)1A2B3C4D5E
% --EXOP:
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp databarexpandedcomposite 0.0 2022082100 93873 93874
%%BeginData:        112 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /databarexpanded dup /uk.co.terryburton.bwipp findresource put
dup /gs1-cc 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
/databarexpandedcomposite {

    20 dict begin            % Confine variables to local scope

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    % Split the linear and composite parts
    barcode (|) search {
        /linear exch def
        pop
        /comp exch def
    } {
        pop
    } ifelse

    gsave

    options (lintype) (databarexpanded) put
    options (linkage) true put
    options (inkspread) (0) put
    options (dontdraw) true put
    options (dontlint) true put

    % Lint the combined AI element strings
    linear length comp length add string
    dup 0 linear putinterval
    dup linear length comp putinterval
    /ai //gs1process exec pop pop pop

    % Plot the linear part
    linear options //databarexpanded exec
    dup (sbs) get /linsbs exch def
    dup (bhs) get 0 get 72 mul /linheight exch def
    //renlinear exec

    % Plot the separator
    /sepfinder {
        /fp exch def
        fp 1 fp 12 add {
            /i exch def
            bot i get 0 eq {
                bot 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
    } def
    mark
    0 linsbs {1 index 1 eq {{0}} {{1}} ifelse repeat} forall
    counttomark 1 sub array astore /bot exch def pop pop
    /sep [ bot {1 exch sub} forall ] def
    sep 0 [0 0 0] putinterval
    sep sep length 4 sub [0 0 0 0] putinterval
    [  % Finder pattern module positions
        18 98 bot length 13 sub {} for
        69 98 bot length 13 sub {} for
    ] {sepfinder} forall
    0 linheight rmoveto <<
        /ren //renmatrix
        /pixs sep
        /pixx sep length
        /pixy 1
        /height 1 72 div
        /width sep length 72 div
        /opt options
    >> //renmatrix exec

    % Plot the 2D part
    1 1 rmoveto comp options //gs1-cc exec //renmatrix exec

    grestore

    end

}
[/barcode] {null def} forall
bind def
/databarexpandedcomposite dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databarexpandedcomposite--

% --BEGIN ENCODER databarexpandedstackedcomposite--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix databarexpanded databarexpandedstacked micropdf417 pdf417 gs1-cc--
% --DESC: GS1 DataBar Expanded Stacked Composite
% --EXAM: (01)00012345678905(10)ABCDEF|(21)12345678
% --EXOP: segments=4
% --RNDR: renmatrix renlinear
%%BeginResource: uk.co.terryburton.bwipp databarexpandedstackedcomposite 0.0 2022082100 96049 95929
%%BeginData:        109 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /databarexpandedstacked dup /uk.co.terryburton.bwipp findresource put
dup /gs1-cc dup /uk.co.terryburton.bwipp findresource put
dup /gs1process dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
begin
/databarexpandedstackedcomposite {

    20 dict begin            % Confine variables to local scope

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    % Split the linear and composite parts
    barcode (|) search {
        /linear exch def
        pop
        /comp exch def
    } {
        pop
    } ifelse

    gsave

    options (lintype) (databarexpandedstacked) put
    options (linkage) true put
    options (inkspread) (0) put
    options (dontdraw) true put
    options (dontlint) true put

    % Lint the combined AI element strings
    linear length comp length add string
    dup 0 linear putinterval
    dup linear length comp putinterval
    /ai //gs1process exec pop pop pop

    % Plot the linear part
    linear options //databarexpandedstacked exec
    dup (pixs) get 0 2 index (pixx) get getinterval /bot exch def
    dup (pixy) get /linheight exch def
    //renmatrix exec

    % Plot the separator
    /sepfinder {
        /fp exch def
        fp 1 fp 12 add {
            /i exch def
            bot i get 0 eq {
                bot 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
    } def
    /sep [ bot {1 exch sub} forall ] def
    sep 0 [ 0 0 0 0 ] putinterval
    sep sep length 4 sub [ 0 0 0 0 ] putinterval
    [  % Finder pattern module positions
        19 98 bot length 13 sub {} for
        70 98 bot length 13 sub {} for
    ] {sepfinder} forall
    0 linheight rmoveto <<
        /ren //renmatrix
        /pixs sep
        /pixx sep length
        /pixy 1
        /height 1 72 div
        /width sep length 72 div
        /opt options
    >> //renmatrix exec

    % Plot the 2D part
    bot 0 get 0 eq {2} {0} ifelse 1 rmoveto
    comp options //gs1-cc exec //renmatrix exec

    grestore

    end

}
[/barcode] {null def} forall
bind def
/databarexpandedstackedcomposite dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER databarexpandedstackedcomposite--

% --BEGIN ENCODER gs1-128composite--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renlinear renmatrix code128 gs1-128 micropdf417 pdf417 gs1-cc--
% --DESC: GS1-128 Composite
% --EXAM: (00)030123456789012340|(02)13012345678909(37)24(10)1234567ABCDEFG
% --EXOP: ccversion=c
% --RNDR: renlinear renmatrix
%%BeginResource: uk.co.terryburton.bwipp gs1-128composite 0.0 2022082100 97016 93461
%%BeginData:        114 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /gs1-128 dup /uk.co.terryburton.bwipp findresource put
dup /gs1-cc 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
/gs1-128composite {

    20 dict begin            % Confine variables to local scope

    /options exch def
    /barcode exch def

    /ctx null def
    /dontdraw false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    % Split the linear and composite parts
    barcode (|) search {
        /linear exch def
        pop
        /comp exch def
    } {
        pop
    } ifelse

    gsave

    options (inkspread) (0) put
    options (dontdraw) true put
    options (dontlint) true put

    % Lint the combined AI element strings
    linear length comp length add string
    dup 0 linear putinterval
    dup linear length comp putinterval
    /ai //gs1process exec pop pop pop

    % Dummy plot of linear part with CC-A to get width
    options (linkagea) true put
    linear << options {} forall >> //gs1-128 exec
    (sbs) get 0 exch {add} forall /linwidth exch def

    % Create 2D part and determine type
    options (lintype) (gs1-128) put
    options (linwidth) linwidth put
    comp options //gs1-cc exec /compsym exch def
    compsym (pixx) get 99 eq {(a)} {(c)} ifelse /linktype exch def

    % Plot linear part
    linktype (a) eq {
        options (linkagea) true put
        options (linkagec) false put
    } {
        options (linkagea) false put
        options (linkagec) true put
    } ifelse
    linear << options {} forall >> //gs1-128 exec
    dup (sbs) get /linsbs exch def
    dup (bhs) get 0 get 72 mul /linheight exch def
    //renlinear exec

    % Plot the separator
    mark
    1 linsbs {1 index 0 eq {{1}} {{0}} ifelse repeat} forall
    counttomark 1 sub array astore /sep exch def pop pop
    0 linheight rmoveto <<
        /ren //renmatrix
        /pixs sep
        /pixx sep length
        /pixy 1
        /height 1 72 div
        /width sep length 72 div
        /opt options
    >> //renmatrix exec

    % Plot the 2D part
    linktype (a) eq {
        /s linwidth 2 sub 11 idiv def
        /p s 9 sub 2 idiv def
        /x s p sub 1 sub 11 mul 10 add p 0 eq {2 add} if 99 sub def
        x 1 rmoveto
    } {
        -7 1 rmoveto
    } ifelse

    compsym //renmatrix exec

    grestore

    end

}
[/barcode] {null def} forall
bind def
/gs1-128composite dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER gs1-128composite--

% --BEGIN ENCODER gs1datamatrix--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renmatrix datamatrix--
% --DESC: GS1 Data Matrix
% --EXAM: (01)03453120000011(17)120508(10)ABCD1234(410)9501101020917
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp gs1datamatrix 0.0 2022082100 77432 73954
%%BeginData:         91 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /gs1process dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /datamatrix dup /uk.co.terryburton.bwipp findresource put
begin
/gs1datamatrix {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /parse false def
    /dontlint false def
    /lintreqs true def
    /gssep 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

    barcode /ai //gs1process exec
    /fncs exch def
    /vals exch def
    /ais exch def

    % Create the datamatrix data
    /fnc1 -1 def
    /dmtx [ fnc1 ] def
    0 1 ais length 1 sub {
        /i exch def
        /ai ais i get def
        /val vals i get def
        dmtx length ai length add val length add array
        dup 0 dmtx putinterval
        dup dmtx length ai [ exch {} forall ] putinterval
        dup dmtx length ai length add val [ exch {} forall ] putinterval
        /dmtx exch def
        i ais length 1 sub ne fncs i get and {  % Append FNC1
            dmtx length 1 add array
            dup 0 dmtx putinterval
            dup dmtx length gssep {29} {fnc1} ifelse put
            /dmtx exch def
        } if
    } for

    % Compose input to datamatrix
    /barcode dmtx length 1 add 5 mul string def
    /i 0 def /j 0 def {
        i dmtx length eq {exit} if
        dmtx i get dup fnc1 eq {
            pop barcode j (^FNC1) putinterval
            /j j 4 add def
        } {
            barcode exch j exch put
        } ifelse
        /i i 1 add def
        /j j 1 add def
    } loop
    /barcode barcode 0 j getinterval def

    % Get the result of encoding with datamatrix
    options (parse) undef
    options (dontdraw) true put
    options (parsefnc) true put
    /args barcode options //datamatrix exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/gs1datamatrix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER gs1datamatrix--

% --BEGIN ENCODER gs1datamatrixrectangular--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renmatrix datamatrix--
% --DESC: GS1 Data Matrix Rectangular
% --EXAM: (01)03453120000011(17)120508(10)ABCD1234(410)9501101020917
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp gs1datamatrixrectangular 0.0 2022082100 77747 74258
%%BeginData:         92 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /gs1process dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /datamatrix dup /uk.co.terryburton.bwipp findresource put
begin
/gs1datamatrixrectangular {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /parse false def
    /dontlint false def
    /lintreqs true def
    /dontdraw false def
    /gssep 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

    barcode /ai //gs1process exec
    /fncs exch def
    /vals exch def
    /ais exch def

    % Create the datamatrix data
    /fnc1 -1 def
    /dmtx [ fnc1 ] def
    0 1 ais length 1 sub {
        /i exch def
        /ai ais i get def
        /val vals i get def
        dmtx length ai length add val length add array
        dup 0 dmtx putinterval
        dup dmtx length ai [ exch {} forall ] putinterval
        dup dmtx length ai length add val [ exch {} forall ] putinterval
        /dmtx exch def
        i ais length 1 sub ne fncs i get and {  % Append FNC1
            dmtx length 1 add array
            dup 0 dmtx putinterval
            dup dmtx length gssep {29} {fnc1} ifelse put
            /dmtx exch def
        } if
    } for

    % Compose input to datamatrix
    /barcode dmtx length 1 add 5 mul string def
    /i 0 def /j 0 def {
        i dmtx length eq {exit} if
        dmtx i get dup fnc1 eq {
            pop barcode j (^FNC1) putinterval
            /j j 4 add def
        } {
            barcode exch j exch put
        } ifelse
        /i i 1 add def
        /j j 1 add def
    } loop
    /barcode barcode 0 j getinterval def

    % Get the result of encoding with datamatrix
    options (parse) undef
    options (dontdraw) true put
    options (parsefnc) true put
    options (format) (rectangle) put
    /args barcode options //datamatrix exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/gs1datamatrixrectangular dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER gs1datamatrixrectangular--

% --BEGIN ENCODER gs1dldatamatrix--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renmatrix datamatrix--
% --DESC: GS1 Digital Link Data Matrix
% --EXAM: https://id.gs1.org/01/12312312312333/22/ABC%2d123?99=XYZ%2f987#test
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp gs1dldatamatrix 0.0 2022082100 70572 63571
%%BeginData:         59 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /gs1process dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /datamatrix dup /uk.co.terryburton.bwipp findresource put
begin
/gs1dldatamatrix {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /parse false def
    /dontlint false def
    /lintreqs true def
    /dontdraw 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

    % Parse the input
    /fncvals <<
        /parse parse
        /parseonly true
        /parsefnc false
    >> def
    /barcode barcode fncvals //parseinput exec def

    barcode /dl //gs1process exec pop pop pop

    % Get the result of encoding with datamatrix
    options (parse) undef
    options (dontdraw) true put
    /args barcode options //datamatrix exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/gs1dldatamatrix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER gs1dldatamatrix--

% --BEGIN ENCODER gs1qrcode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renmatrix qrcode--
% --DESC: GS1 QR Code
% --EXAM: (01)03453120000011(8200)http://www.abc.net(10)ABCD1234(410)9501101020917
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp gs1qrcode 0.0 2022082100 77214 73742
%%BeginData:         89 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /gs1process dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /qrcode dup /uk.co.terryburton.bwipp findresource put
begin
/gs1qrcode {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /parse false def
    /dontlint false def
    /lintreqs true def
    /dontdraw 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

    barcode /ai //gs1process exec
    /fncs exch def
    /vals exch def
    /ais exch def

    % Create the qrcode data
    /fnc1 -1 def
    /qrc [ fnc1 ] def
    0 1 ais length 1 sub {
        /i exch def
        /ai ais i get def
        /val vals i get def
        qrc length ai length add val length add array
        dup 0 qrc putinterval
        dup qrc length ai [ exch {} forall ] putinterval
        dup qrc length ai length add val [ exch {} forall ] putinterval
        /qrc exch def
        i ais length 1 sub ne fncs i get and {  % Append FNC1
            qrc length 1 add array
            dup 0 qrc putinterval
            dup qrc length fnc1 put
            /qrc exch def
        } if
    } for

    % Compose input to qrcode
    /barcode qrc length 1 add 5 mul string def
    /i 0 def /j 0 def {
        i qrc length eq {exit} if
        qrc i get dup fnc1 eq {
            pop barcode j (^FNC1) putinterval
            /j j 4 add def
        } {
            barcode exch j exch put
        } ifelse
        /i i 1 add def
        /j j 1 add def
    } loop
    /barcode barcode 0 j getinterval def

    % Get the result of encoding with qrcode
    options (parse) undef
    options (dontdraw) true put
    options (parsefnc) true put
    /args barcode options //qrcode exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/gs1qrcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER gs1qrcode--

% --BEGIN ENCODER gs1dlqrcode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renmatrix qrcode--
% --DESC: GS1 Digital Link QR Code
% --EXAM: https://id.gs1.org/01/12312312312333/22/ABC%2d123?99=XYZ%2f987#test
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp gs1dlqrcode 0.0 2022082100 67116 67111
%%BeginData:         59 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /parseinput dup /uk.co.terryburton.bwipp findresource put
dup /gs1process dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /qrcode dup /uk.co.terryburton.bwipp findresource put
begin
/gs1dlqrcode {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /parse false def
    /dontlint false def
    /lintreqs true def
    /dontdraw 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

    % Parse the input
    /fncvals <<
        /parse parse
        /parseonly true
        /parsefnc false
    >> def
    /barcode barcode fncvals //parseinput exec def

    barcode /dl //gs1process exec pop pop pop

    % Get the result of encoding with qrcode
    options (parse) undef
    options (dontdraw) true put
    /args barcode options //qrcode exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/gs1dlqrcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER gs1dlqrcode--

% --BEGIN ENCODER gs1dotcode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput gs1process renmatrix dotcode--
% --DESC: GS1 DotCode
% --EXAM: (235)5vBZIF%!<B;?oa%(01)01234567890128(8008)19052001
% --EXOP: rows=16
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp gs1dotcode 0.0 2022082100 77157 73683
%%BeginData:         90 ASCII Lines
/setpacking where {pop currentpacking true setpacking} if
10 dict
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
dup /gs1process dup /uk.co.terryburton.bwipp findresource put
dup /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /dotcode dup /uk.co.terryburton.bwipp findresource put
begin
/gs1dotcode {

    20 dict begin            % Confine variables to local scope

    /options exch def  % We are given an option string
    /barcode exch def  % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /parse false def
    /dontlint false def
    /lintreqs true 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

    barcode /ai //gs1process exec
    /fncs exch def
    /vals exch def
    /ais exch def

    % Create the dotcode data
    /fnc1 -1 def
    /dmtx [ fnc1 ] def
    0 1 ais length 1 sub {
        /i exch def
        /ai ais i get def
        /val vals i get def
        dmtx length ai length add val length add array
        dup 0 dmtx putinterval
        dup dmtx length ai [ exch {} forall ] putinterval
        dup dmtx length ai length add val [ exch {} forall ] putinterval
        /dmtx exch def
        i ais length 1 sub ne fncs i get and {  % Append FNC1
            dmtx length 1 add array
            dup 0 dmtx putinterval
            dup dmtx length fnc1 put
            /dmtx exch def
        } if
    } for

    % Compose input to dotcode
    /barcode dmtx length 1 add 5 mul string def
    /i 0 def /j 0 def {
        i dmtx length eq {exit} if
        dmtx i get dup fnc1 eq {
            pop barcode j (^FNC1) putinterval
            /j j 4 add def
        } {
            barcode exch j exch put
        } ifelse
        /i i 1 add def
        /j j 1 add def
    } loop
    /barcode barcode 0 j getinterval def

    % Get the result of encoding with dotcode
    options (parse) undef
    options (dontdraw) true put
    options (parsefnc) true put
    /args barcode options //dotcode exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    end

}
[/barcode] {null def} forall
bind def
/gs1dotcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER gs1dotcode--

% --BEGIN ENCODER hibccode39--
% --REQUIRES preamble loadctx unloadctx raiseerror renlinear code39--
% --DESC: HIBC Code 39
% --EXAM: A123BJC5D6E71
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp hibccode39 0.0 2022082100 63587 67110
%%BeginData:        103 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code39 dup /uk.co.terryburton.bwipp findresource put
begin
/hibccode39 {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /textxoffset 0 def
    /validatecheck 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /textxoffset textxoffset cvr def

    /hibccode39 //loadctx exec

    % Create a string of the available characters
{
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
    /charvals 43 dict def
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.hibccode39badCharacter (HIBC Code 39 must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {1 sub} if def

    /checksum 41 def
    0 1 barlen 1 sub {
        barcode exch 1 getinterval charvals exch get
        checksum add /checksum exch def
    } for
    /checksum checksum 43 mod def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.hibccode39badCheckDigit (Incorrect HIBC Code 39 check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /barcode barlen 2 add string dup 1 barcode putinterval def
    barcode 0 43 put
    barcode barlen 1 add barchars checksum get put

    /text barlen 4 add string def
    text 0 42 put
    text 1 barcode putinterval
    text barlen 2 add barcode barlen 1 add get dup 32 eq {pop 95} if put
    text barlen 3 add 42 put

    % Get the result of encoding with code39
    options (dontdraw) true put
    options (includecheck) false put
    options (validatecheck) false put
    /args barcode options //code39 exec def

    args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
    args (textxalign) (center) put
    args (opt) options put
    args

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/hibccode39 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER hibccode39--

% --BEGIN ENCODER hibccode128--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renlinear code128--
% --DESC: HIBC Code 128
% --EXAM: A123BJC5D6E71
% --EXOP: includetext
% --RNDR: renlinear
%%BeginResource: uk.co.terryburton.bwipp hibccode128 0.0 2022082100 69879 69846
%%BeginData:        102 ASCII Lines
/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 /renlinear dup /uk.co.terryburton.bwipp findresource put
dup /code128 dup /uk.co.terryburton.bwipp findresource put
begin
/hibccode128 {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /textfont /Courier def
    /textsize 10 def
    /textyoffset -7 def
    /textxoffset 0 def
    /validatecheck 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

    /textfont textfont cvlit def
    /textsize textsize cvr def
    /textyoffset textyoffset cvr def
    /textxoffset textxoffset cvr def

    /hibccode128 //loadctx exec

    % Create a string of the available characters
{
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
    /charvals 43 dict def
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.hibccode128badCharacter (HIBC Code 128 must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {1 sub} if def

    /checksum 41 def
    0 1 barlen 1 sub {
        barcode exch 1 getinterval charvals exch get
        checksum add /checksum exch def
    } for
    /checksum checksum 43 mod def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.hibccode128badCheckDigit (Incorrect HIBC Code 128 check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /barcode barlen 2 add string dup 1 barcode putinterval def
    barcode 0 43 put
    barcode barlen 1 add barchars checksum get put

    /text barlen 4 add string def
    text 0 42 put
    text 1 barcode putinterval
    text barlen 2 add barcode barlen 1 add get dup 32 eq {pop 95} if put
    text barlen 3 add 42 put

    % Get the result of encoding with code128
    options (dontdraw) true put
    options (validatecheck) false put
    /args barcode options //code128 exec def

    args (txt) [ [text textxoffset textyoffset textfont textsize] ] put
    args (textxalign) (center) put
    args (opt) options put
    args

    dontdraw not //renlinear if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/hibccode128 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER hibccode128--

% --BEGIN ENCODER hibcdatamatrix--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix datamatrix--
% --DESC: HIBC Data Matrix
% --EXAM: A123BJC5D6E71
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp hibcdatamatrix 0.0 2022082100 67458 67144
%%BeginData:         85 ASCII Lines
/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 /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /datamatrix dup /uk.co.terryburton.bwipp findresource put
begin
/hibcdatamatrix {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /validatecheck 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

    /hibcdatamatrix //loadctx exec

    % Create a string of the available characters
{
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
    /charvals 43 dict def
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.hibcdatamatrixBadCharacter (HIBC Data Matrix must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {1 sub} if def

    /checksum 41 def
    0 1 barlen 1 sub {
        barcode exch 1 getinterval charvals exch get
        checksum add /checksum exch def
    } for
    /checksum checksum 43 mod def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.hibcdatamatrixBadCheckDigit (Incorrect HIBC Data Matrix check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /barcode barlen 2 add string dup 1 barcode putinterval def
    barcode 0 43 put
    barcode barlen 1 add barchars checksum get put

    % Get the result of encoding with datamatrix
    options (dontdraw) true put
    options (validatecheck) false put
    /args barcode options //datamatrix exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/hibcdatamatrix dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER hibcdatamatrix--

% --BEGIN ENCODER hibcdatamatrixrectangular--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix datamatrix--
% --DESC: HIBC Data Matrix Rectangular
% --EXAM: A123BJC5D6E71
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp hibcdatamatrixrectangular 0.0 2022082100 67707 67360
%%BeginData:         86 ASCII Lines
/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 /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /datamatrix dup /uk.co.terryburton.bwipp findresource put
begin
/hibcdatamatrixrectangular {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /validatecheck 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

    /hibcdatamatrixrectangular //loadctx exec

    % Create a string of the available characters
{
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
    /charvals 43 dict def
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.hibcdatamatrixrectangularBadCharacter (HIBC Data Matrix Rectangular must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {1 sub} if def

    /checksum 41 def
    0 1 barlen 1 sub {
        barcode exch 1 getinterval charvals exch get
        checksum add /checksum exch def
    } for
    /checksum checksum 43 mod def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.hibcdatamatrixrectangularBadCheckDigit (Incorrect HIBC Data Matrix Rectangular check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /barcode barlen 2 add string dup 1 barcode putinterval def
    barcode 0 43 put
    barcode barlen 1 add barchars checksum get put

    % Get the result of encoding with datamatrix
    options (dontdraw) true put
    options (validatecheck) false put
    options (format) (rectangle) put
    /args barcode options //datamatrix exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/hibcdatamatrixrectangular dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER hibcdatamatrixrectangular--

% --BEGIN ENCODER hibcpdf417--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix pdf417--
% --DESC: HIBC PDF417
% --EXAM: A123BJC5D6E71
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp hibcpdf417 0.0 2022082100 67713 67465
%%BeginData:         89 ASCII Lines
/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 /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /pdf417 dup /uk.co.terryburton.bwipp findresource put
begin
/hibcpdf417 {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /columns 2 def
    /validatecheck 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

    /columns columns cvi def

    /hibcpdf417 //loadctx exec

    % Create a string of the available characters
{
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
    /charvals 43 dict def
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.hibcpdf417BadCharacter (HIBC PDF417 must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {1 sub} if def

    /checksum 41 def
    0 1 barlen 1 sub {
        barcode exch 1 getinterval charvals exch get
        checksum add /checksum exch def
    } for
    /checksum checksum 43 mod def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.hibcpdf417BadCheckDigit (Incorrect HIBC PDF417 check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /barcode barlen 2 add string dup 1 barcode putinterval def
    barcode 0 43 put
    barcode barlen 1 add barchars checksum get put

    % Get the result of encoding with pdf417
    options (dontdraw) true put
    options (columns) columns put
    options (validatecheck) false put
    /args barcode options //pdf417 exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/hibcpdf417 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER hibcpdf417--

% --BEGIN ENCODER hibcmicropdf417--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix micropdf417--
% --DESC: HIBC MicroPDF417
% --EXAM: A123BJC5D6E71
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp hibcmicropdf417 0.0 2022082100 67787 67500
%%BeginData:         89 ASCII Lines
/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 /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /micropdf417 dup /uk.co.terryburton.bwipp findresource put
begin
/hibcmicropdf417 {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /columns 2 def
    /validatecheck 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

    /columns columns cvi def

    /hibcmicropdf417 //loadctx exec

    % Create a string of the available characters
{
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
    /charvals 43 dict def
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.hibcmicropdf417BadCharacter (HIBC MicroPDF417 must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {1 sub} if def

    /checksum 41 def
    0 1 barlen 1 sub {
        barcode exch 1 getinterval charvals exch get
        checksum add /checksum exch def
    } for
    /checksum checksum 43 mod def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.hibcmicropdf417BadCheckDigit (Incorrect HIBC MicroPDF417 check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /barcode barlen 2 add string dup 1 barcode putinterval def
    barcode 0 43 put
    barcode barlen 1 add barchars checksum get put

    % Get the result of encoding with micropdf417
    options (dontdraw) true put
    options (columns) columns put
    options (validatecheck) false put
    /args barcode options //micropdf417 exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/hibcmicropdf417 dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER hibcmicropdf417--

% --BEGIN ENCODER hibcqrcode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix qrcode--
% --DESC: HIBC QR Code
% --EXAM: A123BJC5D6E71
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp hibcqrcode 0.0 2022082100 68350 68090
%%BeginData:         85 ASCII Lines
/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 /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /qrcode dup /uk.co.terryburton.bwipp findresource put
begin
/hibcqrcode {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /validatecheck 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

    /hibcqrcode //loadctx exec

    % Create a string of the available characters
{
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
    /charvals 43 dict def
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.hibcqrcodeBadCharacter (HIBC QR Code must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {1 sub} if def

    /checksum 41 def
    0 1 barlen 1 sub {
        barcode exch 1 getinterval charvals exch get
        checksum add /checksum exch def
    } for
    /checksum checksum 43 mod def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.hibcqrcodeBadCheckDigit (Incorrect HIBC QR Code check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /barcode barlen 2 add string dup 1 barcode putinterval def
    barcode 0 43 put
    barcode barlen 1 add barchars checksum get put

    % Get the result of encoding with qrcode
    options (dontdraw) true put
    options (validatecheck) false put
    /args barcode options //qrcode exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/hibcqrcode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER hibcqrcode--

% --BEGIN ENCODER hibccodablockf--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix codablockf--
% --DESC: HIBC Codablock F
% --EXAM: A123BJC5D6E71
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp hibccodablockf 0.0 2022082100 67542 67272
%%BeginData:         85 ASCII Lines
/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 /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /codablockf dup /uk.co.terryburton.bwipp findresource put
begin
/hibccodablockf {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /validatecheck 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

    /hibccodablockf //loadctx exec

    % Create a string of the available characters
{
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
    /charvals 43 dict def
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.codablockfBadCharacter (HIBC Codablock F must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {1 sub} if def

    /checksum 41 def
    0 1 barlen 1 sub {
        barcode exch 1 getinterval charvals exch get
        checksum add /checksum exch def
    } for
    /checksum checksum 43 mod def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.hibccodablockfBadCheckDigit (Incorrect HIBC Codablock F check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /barcode barlen 2 add string dup 1 barcode putinterval def
    barcode 0 43 put
    barcode barlen 1 add barchars checksum get put

    % Get the result of encoding with codablockf
    options (dontdraw) true put
    options (validatecheck) false put
    /args barcode options //codablockf exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/hibccodablockf dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER hibccodablockf--

% --BEGIN ENCODER hibcazteccode--
% --REQUIRES preamble loadctx unloadctx raiseerror parseinput renmatrix azteccode--
% --DESC: HIBC Aztec Code
% --EXAM: A123BJC5D6E71
% --EXOP:
% --RNDR: renmatrix
%%BeginResource: uk.co.terryburton.bwipp hibcazteccode 0.0 2022082100 67408 67137
%%BeginData:         85 ASCII Lines
/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 /renmatrix dup /uk.co.terryburton.bwipp findresource put
dup /azteccode dup /uk.co.terryburton.bwipp findresource put
begin
/hibcazteccode {

    20 dict begin                 % Confine variables to local scope

    /options exch def       % We are given an option string
    /barcode exch def       % We are given a barcode string

    /ctx null def
    /dontdraw false def
    /validatecheck 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

    /hibcazteccode //loadctx exec

    % Create a string of the available characters
{
    /barchars (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%) def
    /charvals 43 dict def
    0 1 42 {charvals exch dup barchars exch 1 getinterval exch put} for
} ctxdef

    % Validate the input
    0 1 barcode length 1 sub {
        barcode exch 1 getinterval charvals exch known not {
            /bwipp.hibcazteccodeBadCharacter (HIBC Aztec Code must contain only digits, capital letters, spaces and the symbols -.$/+%) //raiseerror exec
        } if
    } for

    /barlen barcode length validatecheck {1 sub} if def

    /checksum 41 def
    0 1 barlen 1 sub {
        barcode exch 1 getinterval charvals exch get
        checksum add /checksum exch def
    } for
    /checksum checksum 43 mod def
    validatecheck {
        barcode barlen get barchars checksum get ne {
            /bwipp.hibcazteccodeBadCheckDigit (Incorrect HIBC Aztec Code check digit provided) //raiseerror exec
        } if
        /barcode barcode 0 barlen getinterval def
    } if

    /barcode barlen 2 add string dup 1 barcode putinterval def
    barcode 0 43 put
    barcode barlen 1 add barchars checksum get put

    % Get the result of encoding with azteccode
    options (dontdraw) true put
    options (validatecheck) false put
    /args barcode options //azteccode exec def

    args (opt) options put
    args

    dontdraw not //renmatrix if

    //unloadctx exec

    end

}
[/barcode] {null def} forall
bind def
/hibcazteccode dup load /uk.co.terryburton.bwipp defineresource pop
end
/setpacking where {pop setpacking} if
%%EndData
%%EndResource
% --END ENCODER hibcazteccode--

% --END TEMPLATE--