summaryrefslogtreecommitdiff
path: root/src/main/print-pcl.c
blob: 5f0d1fad32448e16bb60085e5215ec15668c7ae9 (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
/*
 * "$Id: print-pcl.c,v 1.165 2015/09/09 23:57:32 speachy Exp $"
 *
 *   Print plug-in HP PCL driver for the GIMP.
 *
 *   Copyright 1997-2000 Michael Sweet (mike@easysw.com),
 *	Robert Krawitz (rlk@alum.mit.edu) and
 *      Dave Hill (dave@minnie.demon.co.uk)
 *
 *   This program is free software; you can redistribute it and/or modify it
 *   under the terms of the GNU General Public License as published by the Free
 *   Software Foundation; either version 2 of the License, or (at your option)
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful, but
 *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 *   for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/*
 * This file must include only standard C header files.  The core code must
 * compile on generic platforms that don't support glib, gimp, gtk, etc.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gutenprint/gutenprint.h>
#include <gutenprint/gutenprint-intl-internal.h>
#include "gutenprint-internal.h"
#include <stdio.h>
#include <string.h>

/* #define DEBUG */
/* #define PCL_DEBUG_DISABLE_BLANKLINE_REMOVAL */

/*
 * Local functions...
 */
static void	pcl_mode0(stp_vars_t *, unsigned char *, int, int);
static void	pcl_mode2(stp_vars_t *, unsigned char *, int, int);

#ifndef MAX
#  define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif /* !MAX */

typedef struct
{
  int do_blank;
  int blank_lines;
  unsigned char *comp_buf;
  void (*writefunc)(stp_vars_t *, unsigned char *, int, int);	/* PCL output function */
  int do_cret;
  int do_cretb;
  int do_6color;
  int height;
  int duplex;
  int tumble;
  int use_crd;
  int orientation;
  int label_separator;
} pcl_privdata_t;

/*
 * Generic define for a name/value set
 */

typedef struct
{
  const char	*pcl_name;
  const char	*pcl_text;
  int		pcl_code;
  int		p0;
  int		p1;
} pcl_t;

static const stp_dotsize_t single_dotsize[] =
{
  { 0x1, 1.0 }
};

static const stp_shade_t photo_dither_shades[] =
{
  { 1.0000, 1, single_dotsize },
  { 0.3333, 1, single_dotsize },
};

/*
 * Media size to PCL media size code table
 *
 * Note, you can force the list of papersizes given in the GUI to be only those
 * supported by defining PCL_NO_CUSTOM_PAPERSIZES
 */

/* #define PCL_NO_CUSTOM_PAPERSIZES */

#define PCL_PAPERSIZE_EXECUTIVE		1
#define PCL_PAPERSIZE_LETTER		2
#define PCL_PAPERSIZE_LEGAL		3
#define PCL_PAPERSIZE_TABLOID		6	/* "Ledger" */
#define PCL_PAPERSIZE_STATEMENT		15	/* Called "Manual" in print-util */
#define PCL_PAPERSIZE_SUPER_B		16	/* Called "13x19" in print-util */
#define PCL_PAPERSIZE_A5		25
#define PCL_PAPERSIZE_A4		26
#define PCL_PAPERSIZE_A3		27
#define PCL_PAPERSIZE_JIS_B5		45
#define PCL_PAPERSIZE_JIS_B4		46
#define PCL_PAPERSIZE_HAGAKI_CARD	71
#define PCL_PAPERSIZE_OUFUKU_CARD	72
#define PCL_PAPERSIZE_A6_CARD		73
#define PCL_PAPERSIZE_4x6		74
#define PCL_PAPERSIZE_5x8		75
#define PCL_PAPERSIZE_3x5		78
#define PCL_PAPERSIZE_MONARCH_ENV	80
#define PCL_PAPERSIZE_COMMERCIAL10_ENV	81
#define PCL_PAPERSIZE_DL_ENV		90
#define PCL_PAPERSIZE_C5_ENV		91
#define PCL_PAPERSIZE_C6_ENV		92
#define PCL_PAPERSIZE_CUSTOM		101	/* Custom size */
#define PCL_PAPERSIZE_INVITATION_ENV	109
#define PCL_PAPERSIZE_JAPANESE_3_ENV	110
#define PCL_PAPERSIZE_JAPANESE_4_ENV	111
#define PCL_PAPERSIZE_KAKU_ENV		113
#define PCL_PAPERSIZE_HP_CARD		114	/* HP Greeting card!?? */

/*
 * This data comes from the HP documentation "Deskjet 1220C and 1120C
 * PCL reference guide 2.0, Nov 1999". NOTE: The first name *must* match
 * those in print-util.c for the lookups to work properly!
 * The long names are not used so they have been removed, the ones in
 * print-util.c are used in the interface.
 */

static const pcl_t pcl_media_sizes[] =
{
    { "Executive", "notused", PCL_PAPERSIZE_EXECUTIVE},			/* US Exec (7.25 x 10.5 in) */
    { "Letter", "notused", PCL_PAPERSIZE_LETTER},			/* US Letter (8.5 x 11 in) */
    { "Legal", "notused", PCL_PAPERSIZE_LEGAL},				/* US Legal (8.5 x 14 in) */
    { "Tabloid", "notused", PCL_PAPERSIZE_TABLOID},			/* US Tabloid (11 x 17 in) */
    { "Statement", "notused", PCL_PAPERSIZE_STATEMENT},			/* US Manual/Statement (5.5 x 8.5 in) */
    { "SuperB", "notused", PCL_PAPERSIZE_SUPER_B},			/* US 13x19/Super B (13 x 19 in) */
    { "A5", "notused", PCL_PAPERSIZE_A5},				/* ISO/JIS A5 (148 x 210 mm) */
    { "A4", "notused", PCL_PAPERSIZE_A4},				/* ISO/JIS A4 (210 x 297 mm) */
    { "A3", "notused", PCL_PAPERSIZE_A3},				/* ISO/JIS A3 (297 x 420 mm) */
    { "B5", "notused", PCL_PAPERSIZE_JIS_B5},				/* JIS B5 (182 x 257 mm). */
    { "B4", "notused", PCL_PAPERSIZE_JIS_B4},				/* JIS B4 (257 x 364 mm). */
    { "w283h420", "notused", PCL_PAPERSIZE_HAGAKI_CARD},		/* Japanese Hagaki Card (100 x 148 mm) */
    { "w420h567", "notused", PCL_PAPERSIZE_OUFUKU_CARD},		/* Japanese Oufuku Card (148 x 200 mm) */
    { "A6", "notused", PCL_PAPERSIZE_A6_CARD},				/* ISO/JIS A6 card */
    { "w288h432", "notused", PCL_PAPERSIZE_4x6},			/* US Index card (4 x 6 in) */
    { "w360h576", "notused", PCL_PAPERSIZE_5x8},			/* US Index card (5 x 8 in) */
    { "w216h360", "notused", PCL_PAPERSIZE_3x5},			/* US Index card (3 x 5 in) */
    { "Monarch", "notused", PCL_PAPERSIZE_MONARCH_ENV},			/* Monarch Envelope (3 7/8 x 7 1/2 in) */
    { "COM10", "notused", PCL_PAPERSIZE_COMMERCIAL10_ENV},		/* US Commercial 10 Envelope (4.125 x 9.5 in) Portrait */
    { "DL", "notused", PCL_PAPERSIZE_DL_ENV},				/* DL envelope (110 x 220 mm) Portrait */
    { "C5", "notused", PCL_PAPERSIZE_C5_ENV},				/* C5 envelope (162 x 229 mm) */
    { "C6", "notused", PCL_PAPERSIZE_C6_ENV},				/* C6 envelope (114 x 162 mm) */
    { "w315h414", "notused", PCL_PAPERSIZE_INVITATION_ENV},		/* US A2 Invitation envelope (4 3/8 x 5 3/4 in) */
    { "w340h666", "notused", PCL_PAPERSIZE_JAPANESE_3_ENV},		/* Japanese Long Envelope #3 (120 x 235 mm) */
    { "w255h581", "notused", PCL_PAPERSIZE_JAPANESE_4_ENV},		/* Japanese Long Envelope #4 (90 x 205 mm) */
    { "w680h941", "notused", PCL_PAPERSIZE_KAKU_ENV},			/* Japanese Kaku Envelope (240 x 332.1 mm) */
/**** MRS: this size not supported by print-util funcs! ****/
    { "w612h792", "notused", PCL_PAPERSIZE_HP_CARD}, 			/* Hp greeting card */
};
#define NUM_PRINTER_PAPER_SIZES	(sizeof(pcl_media_sizes) / sizeof(pcl_t))

/*
 * Media type to code table
 */

#define PCL_PAPERTYPE_PLAIN	0
#define PCL_PAPERTYPE_BOND	1
#define PCL_PAPERTYPE_PREMIUM	2
#define PCL_PAPERTYPE_GLOSSY	3	/* or photo */
#define PCL_PAPERTYPE_TRANS	4
#define PCL_PAPERTYPE_QPHOTO	5	/* Quick dry photo (2000 only) */
#define PCL_PAPERTYPE_QTRANS	6	/* Quick dry transparency (2000 only) */

static const pcl_t pcl_media_types[] =
{
    { "Plain", N_ ("Plain"), PCL_PAPERTYPE_PLAIN},
    { "Bond", N_ ("Bond"), PCL_PAPERTYPE_BOND},
    { "Premium", N_ ("Premium"), PCL_PAPERTYPE_PREMIUM},
    { "Glossy", N_ ("Glossy Photo"), PCL_PAPERTYPE_GLOSSY},
    { "Transparency", N_ ("Transparency"), PCL_PAPERTYPE_TRANS},
    { "GlossyQD", N_ ("Quick-dry Photo"), PCL_PAPERTYPE_QPHOTO},
    { "TransparencyQD", N_ ("Quick-dry Transparency"), PCL_PAPERTYPE_QTRANS},
};
#define NUM_PRINTER_PAPER_TYPES	(sizeof(pcl_media_types) / sizeof(pcl_t))

/*
 * Media feed to code table. There are different names for the same code,
 * so we encode them by adding "lumps" of "PAPERSOURCE_MOD".
 * This is removed later to get back to the main codes.
 */

#define PAPERSOURCE_MOD			16
#define PAPERSOURCE_340_MOD		(PAPERSOURCE_MOD)
#define PAPERSOURCE_DJ_MOD		(PAPERSOURCE_MOD << 1)
#define PAPERSOURCE_ADJ_GUIDE		(PAPERSOURCE_MOD << 2)

#define PCL_PAPERSOURCE_STANDARD	0	/* Don't output code */
#define PCL_PAPERSOURCE_MANUAL		2
#define PCL_PAPERSOURCE_MANUAL_ADJ	(PCL_PAPERSOURCE_MANUAL + PAPERSOURCE_ADJ_GUIDE)
#define PCL_PAPERSOURCE_ENVELOPE	3	/* Not used */

/* LaserJet types */
#define PCL_PAPERSOURCE_LJ_TRAY2	1
#define PCL_PAPERSOURCE_LJ_TRAY3	4
#define PCL_PAPERSOURCE_LJ_TRAY4	5
#define PCL_PAPERSOURCE_LJ_TRAY1	8
#define PCL_PAPERSOURCE_LJ_TRAY1_ADJ	(PCL_PAPERSOURCE_LJ_TRAY1 + PAPERSOURCE_ADJ_GUIDE)
#define PCL_PAPERSOURCE_LJ_TRAY2_ADJ	(PCL_PAPERSOURCE_LJ_TRAY2 + PAPERSOURCE_ADJ_GUIDE)
#define PCL_PAPERSOURCE_LJ_TRAY3_ADJ	(PCL_PAPERSOURCE_LJ_TRAY3 + PAPERSOURCE_ADJ_GUIDE)
#define PCL_PAPERSOURCE_LJ_TRAY4_ADJ	(PCL_PAPERSOURCE_LJ_TRAY4 + PAPERSOURCE_ADJ_GUIDE)

/* Deskjet 340 types */
#define PCL_PAPERSOURCE_340_PCSF	(1 + PAPERSOURCE_340_MOD)
						/* Portable sheet feeder for 340 */
#define PCL_PAPERSOURCE_340_DCSF	(4 + PAPERSOURCE_340_MOD)
						/* Desktop sheet feeder for 340 */

/* Other Deskjet types */
#define PCL_PAPERSOURCE_DJ_TRAY		(1 + PAPERSOURCE_DJ_MOD)
#define PCL_PAPERSOURCE_DJ_TRAY2	(4 + PAPERSOURCE_DJ_MOD)
						/* Tray 2 for 2500 */
#define PCL_PAPERSOURCE_DJ_OPTIONAL	(5 + PAPERSOURCE_DJ_MOD)
						/* Optional source for 2500 */
#define PCL_PAPERSOURCE_DJ_AUTO		(7 + PAPERSOURCE_DJ_MOD)
						/* Autoselect for 2500 */

static const pcl_t pcl_media_sources[] =
{
    { "Standard", N_ ("Standard"), PCL_PAPERSOURCE_STANDARD},
    { "Manual", N_ ("Manual"), PCL_PAPERSOURCE_MANUAL},
    { "ManualAdj", N_ ("Manual - Movable Guides"), PCL_PAPERSOURCE_MANUAL_ADJ},
/*  {"Envelope", PCL_PAPERSOURCE_ENVELOPE}, */
    { "MultiPurposeAdj", N_ ("Tray 1 - Movable Guides"), PCL_PAPERSOURCE_LJ_TRAY1_ADJ},
    { "MultiPurpose", N_ ("Tray 1"), PCL_PAPERSOURCE_LJ_TRAY1},
    { "UpperAdj", N_ ("Tray 2 - Movable Guides"), PCL_PAPERSOURCE_LJ_TRAY2_ADJ},
    { "Upper", N_ ("Tray 2"), PCL_PAPERSOURCE_LJ_TRAY2},
    { "LowerAdj", N_ ("Tray 3 - Movable Guides"), PCL_PAPERSOURCE_LJ_TRAY3_ADJ},
    { "Lower", N_ ("Tray 3"), PCL_PAPERSOURCE_LJ_TRAY3},
    { "LargeCapacityAdj", N_ ("Tray 4 - Movable Guides"), PCL_PAPERSOURCE_LJ_TRAY4_ADJ},
    { "LargeCapacity", N_ ("Tray 4"), PCL_PAPERSOURCE_LJ_TRAY4},
    { "Portable", N_ ("Portable Sheet Feeder"), PCL_PAPERSOURCE_340_PCSF},
    { "Desktop", N_ ("Desktop Sheet Feeder"), PCL_PAPERSOURCE_340_DCSF},
    { "Tray", N_ ("Tray"), PCL_PAPERSOURCE_DJ_TRAY},
    { "Tray2", N_ ("Tray 2"), PCL_PAPERSOURCE_DJ_TRAY2},
    { "Optional", N_ ("Optional Source"), PCL_PAPERSOURCE_DJ_OPTIONAL},
    { "Auto", N_ ("Autoselect"), PCL_PAPERSOURCE_DJ_AUTO},
};
#define NUM_PRINTER_PAPER_SOURCES	(sizeof(pcl_media_sources) / sizeof(pcl_t))

#define PCL_RES_150_150		1
#define PCL_RES_300_300		2
#define PCL_RES_600_300		4	/* DJ 600 series */
#define PCL_RES_600_600_MONO	8	/* DJ 600/800/1100/2000 b/w only */
#define PCL_RES_600_600		16	/* DJ 9xx/1220C/PhotoSmart */
#define PCL_RES_1200_600	32	/* DJ 9xx/1220C/PhotoSmart */
#define PCL_RES_2400_600	64	/* DJ 9xx/1220C/PhotoSmart */

static const pcl_t pcl_resolutions[] =
{
    { "150dpi", N_("150x150 DPI"), PCL_RES_150_150, 150, 150},
    { "300dpi", N_("300x300 DPI"), PCL_RES_300_300, 300, 300},
    { "600x300dpi", N_("600x300 DPI"), PCL_RES_600_300, 600, 300},
    { "600mono", N_("600x600 DPI monochrome"), PCL_RES_600_600_MONO, 600, 600},
    { "600dpi", N_("600x600 DPI"), PCL_RES_600_600, 600, 600},
    { "1200x600dpi", N_("1200x600 DPI"), PCL_RES_1200_600, 1200, 600},
    { "2400x600dpi", N_("2400x600 DPI"), PCL_RES_2400_600, 2400, 600},
};
#define NUM_RESOLUTIONS		(sizeof(pcl_resolutions) / sizeof (pcl_t))

static const pcl_t pcl_qualities[] =
{
    { "Draft", N_("Draft"), PCL_RES_150_150, 150, 150},
    { "Standard", N_("Standard"), PCL_RES_300_300, 300, 300},
    { "High", N_("High"), PCL_RES_600_600, 600, 600},
    { "High", N_("Standard"), PCL_RES_600_300, 600, 300},
    { "Photo", N_("Photo"), PCL_RES_1200_600, 1200, 600},
    { "Photo", N_("Photo"), PCL_RES_2400_600, 2400, 600},
};
#define NUM_QUALITIES		(sizeof(pcl_qualities) / sizeof (pcl_t))

typedef struct {
  int top_margin;
  int bottom_margin;
  int left_margin;
  int right_margin;
} margins_t;

/*
 * Printer capability data
 */

typedef struct {
  int model;
  int custom_max_width;
  int custom_max_height;
  int custom_min_width;
  int custom_min_height;
  int resolutions;
  margins_t normal_margins;
  margins_t a4_margins;
  int color_type;		/* 2 print head or one, 2 level or 4 */
  int stp_printer_type;		/* Deskjet/Laserjet and quirks */
/* The paper size, paper type and paper source codes cannot be combined */
  const short *paper_sizes;	/* Paper sizes */
  const short *paper_types;	/* Paper types */
  const short *paper_sources;	/* Paper sources */
  } pcl_cap_t;

#define PCL_COLOR_NONE		0
#define PCL_COLOR_CMY		1	/* One print head */
#define PCL_COLOR_CMYK		2	/* Two print heads */
#define PCL_COLOR_CMYK4		4	/* CRet printing */
#define PCL_COLOR_CMYKcm	8	/* CMY + Photo Cart */
#define PCL_COLOR_CMYK4b	16	/* CRet for HP840c */

#define PCL_PRINTER_LJ		1
#define PCL_PRINTER_DJ		2
#define PCL_PRINTER_NEW_ERG	4	/* use "\033*rC" to end raster graphics,
					   instead of "\033*rB" */
#define PCL_PRINTER_TIFF	8	/* Use TIFF compression */
#define PCL_PRINTER_MEDIATYPE	16	/* Use media type & print quality */
#define PCL_PRINTER_CUSTOM_SIZE	32	/* Custom sizes supported */
#define PCL_PRINTER_BLANKLINE	64	/* Blank line removal supported */
#define PCL_PRINTER_DUPLEX	128	/* Printer can have duplexer */
#define PCL_PRINTER_LABEL       256     /* Datamax-O'Neil PCL Label Printer */

/*
 * FIXME - the 520 shouldn't be lumped in with the 500 as it supports
 * more paper sizes.
 *
 * The following models use depletion, raster quality and shingling:-
 * 500, 500c, 510, 520, 550c, 560c.
 * The rest use Media Type and Print Quality.
 *
 * This data comes from the HP documentation "Deskjet 1220C and 1120C
 * PCL reference guide 2.0, Nov 1999".
 */

static const short emptylist[] =
{
  -1
};

static const short custom_papersizes[] =
{
  PCL_PAPERSIZE_CUSTOM,
  -1,
};

static const short standard_papersizes[] =
{
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_STATEMENT,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_A4,
  -1,
};

static const short letter_only_papersizes[] =
{
  PCL_PAPERSIZE_LETTER,
  -1
};

static const short letter_a4_papersizes[] =
{
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_LETTER,
  -1
};

static const short dj340_papersizes[] =
{
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_A4,
  -1,
};

static const short dj400_papersizes[] =
{
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_JIS_B5,
  -1,
};

static const short dj500_papersizes[] =
{
/*    PCL_PAPERSIZE_EXECUTIVE, The 500 doesn't support this, the 520 does */
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_COMMERCIAL10_ENV,
/*    PCL_PAPERSIZE_DL_ENV,    The 500 doesn't support this, the 520 does */
  -1,
};

static const short dj540_papersizes[] =
{
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_A5,
  PCL_PAPERSIZE_JIS_B5,
  PCL_PAPERSIZE_HAGAKI_CARD,
  PCL_PAPERSIZE_A6_CARD,
  PCL_PAPERSIZE_4x6,
  PCL_PAPERSIZE_5x8,
  PCL_PAPERSIZE_COMMERCIAL10_ENV,
  PCL_PAPERSIZE_DL_ENV,
  PCL_PAPERSIZE_C6_ENV,
  -1,
};

static const short dj600_papersizes[] =
{
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_A5,
  PCL_PAPERSIZE_HAGAKI_CARD,
  PCL_PAPERSIZE_A6_CARD,
  PCL_PAPERSIZE_4x6,
  PCL_PAPERSIZE_5x8,
  PCL_PAPERSIZE_COMMERCIAL10_ENV,
  PCL_PAPERSIZE_DL_ENV,
  PCL_PAPERSIZE_C6_ENV,
  PCL_PAPERSIZE_INVITATION_ENV,
  -1,
};

static const short dj1220_papersizes[] =
{
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_TABLOID,
  PCL_PAPERSIZE_STATEMENT,
  PCL_PAPERSIZE_SUPER_B,
  PCL_PAPERSIZE_A5,
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_A3,
  PCL_PAPERSIZE_JIS_B5,
  PCL_PAPERSIZE_JIS_B4,
  PCL_PAPERSIZE_HAGAKI_CARD,
  PCL_PAPERSIZE_OUFUKU_CARD,
  PCL_PAPERSIZE_A6_CARD,
  PCL_PAPERSIZE_4x6,
  PCL_PAPERSIZE_5x8,
  PCL_PAPERSIZE_3x5,
  PCL_PAPERSIZE_HP_CARD,
  PCL_PAPERSIZE_MONARCH_ENV,
  PCL_PAPERSIZE_COMMERCIAL10_ENV,
  PCL_PAPERSIZE_DL_ENV,
  PCL_PAPERSIZE_C5_ENV,
  PCL_PAPERSIZE_C6_ENV,
  PCL_PAPERSIZE_INVITATION_ENV,
  PCL_PAPERSIZE_JAPANESE_3_ENV,
  PCL_PAPERSIZE_JAPANESE_4_ENV,
  PCL_PAPERSIZE_KAKU_ENV,
  -1,
};

static const short dj1100_papersizes[] =
{
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_TABLOID,
  PCL_PAPERSIZE_STATEMENT,
  PCL_PAPERSIZE_SUPER_B,
  PCL_PAPERSIZE_A5,
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_A3,
  PCL_PAPERSIZE_JIS_B5,
  PCL_PAPERSIZE_JIS_B4,
  PCL_PAPERSIZE_HAGAKI_CARD,
  PCL_PAPERSIZE_A6_CARD,
  PCL_PAPERSIZE_4x6,
  PCL_PAPERSIZE_5x8,
  PCL_PAPERSIZE_COMMERCIAL10_ENV,
  PCL_PAPERSIZE_DL_ENV,
  PCL_PAPERSIZE_C6_ENV,
  PCL_PAPERSIZE_INVITATION_ENV,
  PCL_PAPERSIZE_JAPANESE_3_ENV,
  PCL_PAPERSIZE_JAPANESE_4_ENV,
  PCL_PAPERSIZE_KAKU_ENV,
  -1,
};

static const short dj1200_papersizes[] =
{
  /* This printer is not mentioned in the Comparison tables,
     so I'll just pick some likely sizes... */
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_A5,
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_4x6,
  PCL_PAPERSIZE_5x8,
  -1,
};

static const short dj2000_papersizes[] =
{
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_A5,
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_HAGAKI_CARD,
  PCL_PAPERSIZE_A6_CARD,
  PCL_PAPERSIZE_4x6,
  PCL_PAPERSIZE_5x8,
  PCL_PAPERSIZE_3x5,
  PCL_PAPERSIZE_COMMERCIAL10_ENV,
  PCL_PAPERSIZE_DL_ENV,
  PCL_PAPERSIZE_C6_ENV,
  PCL_PAPERSIZE_INVITATION_ENV,
  -1,
};

static const short dj2500_papersizes[] =
{
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_TABLOID,
  PCL_PAPERSIZE_STATEMENT,
  PCL_PAPERSIZE_A5,
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_A3,
  PCL_PAPERSIZE_JIS_B5,
  PCL_PAPERSIZE_JIS_B4,
  PCL_PAPERSIZE_HAGAKI_CARD,
  PCL_PAPERSIZE_A6_CARD,
  PCL_PAPERSIZE_4x6,
  PCL_PAPERSIZE_5x8,
  PCL_PAPERSIZE_COMMERCIAL10_ENV,
  PCL_PAPERSIZE_DL_ENV,
  -1,
};

static const short ljsmall_papersizes[] =
{
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_STATEMENT,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_MONARCH_ENV,
  PCL_PAPERSIZE_COMMERCIAL10_ENV,
  PCL_PAPERSIZE_DL_ENV,
  PCL_PAPERSIZE_C5_ENV,
  PCL_PAPERSIZE_C6_ENV,
  -1,
};

static const short ljbig_papersizes[] =
{
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_STATEMENT,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_TABLOID,
  PCL_PAPERSIZE_SUPER_B,
  PCL_PAPERSIZE_A5,
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_A3,
  PCL_PAPERSIZE_JIS_B5,
  PCL_PAPERSIZE_JIS_B4,                /* Guess */
  PCL_PAPERSIZE_4x6,
  PCL_PAPERSIZE_5x8,
  PCL_PAPERSIZE_MONARCH_ENV,
  PCL_PAPERSIZE_COMMERCIAL10_ENV,
  PCL_PAPERSIZE_DL_ENV,
  PCL_PAPERSIZE_C5_ENV,
  PCL_PAPERSIZE_C6_ENV,
  -1,
};

static const short ljtabloid_papersizes[] =
{
  PCL_PAPERSIZE_EXECUTIVE,
  PCL_PAPERSIZE_STATEMENT,
  PCL_PAPERSIZE_LETTER,
  PCL_PAPERSIZE_LEGAL,
  PCL_PAPERSIZE_TABLOID,
  PCL_PAPERSIZE_A5,
  PCL_PAPERSIZE_A4,
  PCL_PAPERSIZE_A3,
  PCL_PAPERSIZE_JIS_B5,
  PCL_PAPERSIZE_JIS_B4,                /* Guess */
  PCL_PAPERSIZE_4x6,
  PCL_PAPERSIZE_5x8,
  PCL_PAPERSIZE_MONARCH_ENV,
  PCL_PAPERSIZE_COMMERCIAL10_ENV,
  PCL_PAPERSIZE_DL_ENV,
  PCL_PAPERSIZE_C5_ENV,
  PCL_PAPERSIZE_C6_ENV,
  -1,
};

static const short basic_papertypes[] =
{
  PCL_PAPERTYPE_PLAIN,
  PCL_PAPERTYPE_BOND,
  PCL_PAPERTYPE_PREMIUM,
  PCL_PAPERTYPE_GLOSSY,
  PCL_PAPERTYPE_TRANS,
  -1,
};

static const short new_papertypes[] =
{
  PCL_PAPERTYPE_PLAIN,
  PCL_PAPERTYPE_BOND,
  PCL_PAPERTYPE_PREMIUM,
  PCL_PAPERTYPE_GLOSSY,
  PCL_PAPERTYPE_TRANS,
  PCL_PAPERTYPE_QPHOTO,
  PCL_PAPERTYPE_QTRANS,
  -1,
};

static const short laserjet_papersources[] =
{
  PCL_PAPERSOURCE_STANDARD,
  PCL_PAPERSOURCE_MANUAL_ADJ,
  PCL_PAPERSOURCE_MANUAL,
  PCL_PAPERSOURCE_LJ_TRAY1_ADJ,
  PCL_PAPERSOURCE_LJ_TRAY1,
  PCL_PAPERSOURCE_LJ_TRAY2_ADJ,
  PCL_PAPERSOURCE_LJ_TRAY2,
  PCL_PAPERSOURCE_LJ_TRAY3_ADJ,
  PCL_PAPERSOURCE_LJ_TRAY3,
  PCL_PAPERSOURCE_LJ_TRAY4_ADJ,
  PCL_PAPERSOURCE_LJ_TRAY4,
  -1,
};

static const short dj340_papersources[] =
{
  PCL_PAPERSOURCE_STANDARD,
  PCL_PAPERSOURCE_MANUAL,
  PCL_PAPERSOURCE_340_PCSF,
  PCL_PAPERSOURCE_340_DCSF,
  -1,
};

static const short dj_papersources[] =
{
  PCL_PAPERSOURCE_STANDARD,
  PCL_PAPERSOURCE_MANUAL,
  PCL_PAPERSOURCE_DJ_TRAY,
  -1,
};

static const short dj2500_papersources[] =
{
  PCL_PAPERSOURCE_STANDARD,
  PCL_PAPERSOURCE_MANUAL,
  PCL_PAPERSOURCE_DJ_AUTO,
  PCL_PAPERSOURCE_DJ_TRAY,
  PCL_PAPERSOURCE_DJ_TRAY2,
  PCL_PAPERSOURCE_DJ_OPTIONAL,
  -1,
};

static const short standard_papersources[] =
{
  PCL_PAPERSOURCE_STANDARD,
  -1
};

static const pcl_cap_t pcl_model_capabilities[] =
{
  /* Default/unknown printer - assume laserjet */
  { 0,
    17 * 72 / 2, 14 * 72,		/* Max paper size */
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,	/* Resolutions */
    {12, 12, 18, 18},			/* non-A4 Margins */
    {12, 12, 10, 10},			/* A4 Margins */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ,
    standard_papersizes,
    emptylist,
    emptylist,
  },
/* Datamax-O'Neil Thermal PCL printers */
  { 10010,                             /* p1115 */
    4 * 72, 99 * 72,                  /* Max paper size */
    1, 1,                             /* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,	/* Resolutions */
    {0, 0, 0, 0},                     /* non-A4 Margins */
    {0, 0, 0, 0},                     /* A4 Margins */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_LABEL |
      PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE,
    custom_papersizes,
    emptylist,
    emptylist,
  },
/* Datamax-O'Neil Thermal PCL printers */
  { 10011,                             /* p1115s */
    4 * 72, 99 * 72,                  /* Max paper size */
    1, 1,                             /* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600,        /* Resolutions */
    {0, 0, 0, 0},                     /* non-A4 Margins */
    {0, 0, 0, 0},                     /* A4 Margins */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_LABEL |
      PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE,
    custom_papersizes,
    emptylist,
    emptylist,
  },
/* Datamax-O'Neil Thermal PCL printers */
  { 10012,                             /* p1120n */
    4 * 72, 99 * 72,                  /* Max paper size */
    1, 1,                             /* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,	/* Resolutions */
    {0, 0, 0, 0},                     /* non-A4 Margins */
    {0, 0, 0, 0},                     /* A4 Margins */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_LABEL |
      PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE,
    custom_papersizes,
    emptylist,
    emptylist,
  },
/* Datamax-O'Neil Thermal PCL printers */
  { 10013,                             /* p1125 */
    4 * 72, 99 * 72,                  /* Max paper size */
    1, 1,                             /* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,	/* Resolutions */
    {0, 0, 0, 0},                     /* non-A4 Margins */
    {0, 0, 0, 0},                     /* A4 Margins */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_LABEL |
      PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE,
    custom_papersizes,
    emptylist,
    emptylist,
  },
/* Datamax-O'Neil Thermal PCL printers */
  { 10014,                             /* p1725 */
    6 * 72, 99 * 72,                  /* Max paper size */
    1, 1,                             /* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,	/* Resolutions */
    {0, 0, 0, 0},                     /* non-A4 Margins */
    {0, 0, 0, 0},                     /* A4 Margins */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_LABEL |
      PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE,
    custom_papersizes,
    emptylist,
    emptylist,
  },
/* Datamax-O'Neil Thermal PCL printers */
  { 10015,                             /* w1110 */
    4 * 72, 99 * 72,                  /* Max paper size */
    1, 1,                             /* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,	/* Resolutions */
    {0, 0, 0, 0},                     /* non-A4 Margins */
    {0, 0, 0, 0},                     /* A4 Margins */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_LABEL |
      PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE,
    custom_papersizes,
    emptylist,
    emptylist,
  },
/* Datamax-O'Neil Thermal PCL printers */
  { 10016,                             /* H8308p */
    17 * 72 / 2, 99 * 72,             /* Max paper size */
    1, 1,                             /* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,	/* Resolutions */
    {0, 0, 0, 0},                     /* non-A4 Margins */
    {0, 0, 0, 0},                     /* A4 Margins */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_LABEL |
      PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE,
    custom_papersizes,
    emptylist,
    emptylist,
  },
  /* DesignJet 230/430 (monochrome ) */
  { 10230,
    36 * 72, 150 * 12 * 72,		/* 150ft in roll mode, 64" in sheet */
    826 * 72 / 100, 583 * 72 / 100,	/* 8.3" wide min in sheet mode */
    PCL_RES_300_300 | PCL_RES_600_600,
    {49, 49, 15, 15},
    {49, 49, 15, 15},
    PCL_COLOR_NONE,
    PCL_PRINTER_DJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_NEW_ERG,
    letter_a4_papersizes,
    basic_papertypes,
    standard_papersources,
  },
  /* DesignJet 250C/450C/455CA/488CA */
  /* The "CA" versions have a "software RIP" but are the same hardware */
  { 10250,
    36 * 72, 150 * 12 * 72,		/* 150ft in roll mode, 64" in sheet */
    826 * 72 / 100, 583 * 72 / 100,	/* 8.3" wide min in sheet mode */
    PCL_RES_300_300 | PCL_RES_600_600_MONO,
    {49, 49, 15, 15},
    {49, 49, 15, 15},
    PCL_COLOR_CMYK,
    PCL_PRINTER_DJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_NEW_ERG,
    letter_a4_papersizes,
    basic_papertypes,
    standard_papersources,
  },
  /* DesignJet 700 (monochrome) */
  { 10700,
    36 * 72, 150 * 12 * 72,		/* 150ft in roll mode, 64" in sheet */
    826 * 72 / 100, 583 * 72 / 100,	/* 8.3" wide min in sheet mode */
    PCL_RES_300_300 | PCL_RES_600_600,
    {30, 30, 15, 15},		/* These margins are for sheet mode FIX */
    {30, 30, 15, 15},
    PCL_COLOR_NONE,
    PCL_PRINTER_DJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_NEW_ERG,
    letter_a4_papersizes,
    basic_papertypes,
    standard_papersources,
  },
  /* DesignJet 750C */
  { 10750,
    36 * 72, 150 * 12 * 72,		/* 150ft in roll mode, 64" in sheet */
    826 * 72 / 100, 583 * 72 / 100,	/* 8.3" wide min in sheet mode */
    PCL_RES_300_300 | PCL_RES_600_600_MONO,
    {30, 30, 15, 15},	/* These margins are for roll mode FIX */
    {30, 30, 15, 15},
    PCL_COLOR_CMYK,
    PCL_PRINTER_DJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_NEW_ERG,
    letter_a4_papersizes,
    basic_papertypes,
    standard_papersources,
  },
  /* DesignJet 2000C/2500C (36" wide) */
  { 12500,	/* Deskjet 2500 already has "2500" */
    36 * 72, 150 * 12 * 72,		/* 150ft in roll mode, 64" in sheet */
    826 * 72 / 100, 583 * 72 / 100,	/* 8.3" wide min in sheet mode */
    PCL_RES_300_300 | PCL_RES_600_600_MONO,
    {49, 49, 15, 15},		/* Check/Fix */
    {49, 49, 15, 15},
    PCL_COLOR_CMYK,
    PCL_PRINTER_DJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_NEW_ERG,
    letter_a4_papersizes,
    basic_papertypes,
    standard_papersources,
  },
  /* DesignJet 3000C/3500C (54" wide) */
  { 13500,	/* Deskjet 2500 already has "2500" */
    54 * 72, 150 * 12 * 72,		/* 150ft in roll mode, 64" in sheet */
    826 * 72 / 100, 583 * 72 / 100,	/* 8.3" wide min in sheet mode */
    PCL_RES_300_300 | PCL_RES_600_600_MONO,
    {49, 49, 15, 15},		/* Check/Fix */
    {49, 49, 15, 15},
    PCL_COLOR_CMYK,
    PCL_PRINTER_DJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE | PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_NEW_ERG,
    letter_a4_papersizes,
    basic_papertypes,
    standard_papersources,
  },
  /* Deskjet 340 */
  { 340,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {6, 48, 18, 18},	/* from bpd07933.pdf */
    {6, 48, 10, 11},	/* from bpd07933.pdf */
    PCL_COLOR_CMY,
    PCL_PRINTER_DJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
    dj340_papersizes,
    basic_papertypes,
    dj340_papersources,
  },
  /* Deskjet 400 */
  { 400,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {7, 41, 18, 18},
    {7, 41, 10, 10},	/* Check/Fix */
    PCL_COLOR_CMY,
    PCL_PRINTER_DJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
    dj400_papersizes,
    basic_papertypes,
    emptylist,
  },
  /* Deskjet 500, 520. Lexmark 4076 */
  { 500,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {7, 41, 18, 18},
    {7, 41, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_DJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
    dj500_papersizes,
    basic_papertypes,
    dj_papersources,
  },
  /* Deskjet 500C */
  { 501,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {7, 33, 18, 18},
    {7, 33, 10, 10},	/* Check/Fix */
    PCL_COLOR_CMY,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
    dj500_papersizes,
    basic_papertypes,
    dj_papersources,
  },
  /* Deskjet 540C */
  { 540,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {7, 33, 18, 18},
    {7, 33, 10, 10},	/* Check/Fix */
    PCL_COLOR_CMY,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE,
    dj540_papersizes,
    basic_papertypes,
    dj_papersources,
  },
  /* Deskjet 550C, 560C */
  { 550,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {3, 33, 18, 18},
    {5, 33, 10, 10},
    PCL_COLOR_CMYK,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
/* The 550/560 support COM10 and DL envelope, but the control codes
   are negative, indicating landscape mode. This needs thinking about! */
    dj340_papersizes,
    basic_papertypes,
    dj_papersources,
  },
  /* Deskjet 600/600C */
  { 600,
    17 * 72 / 2, 14 * 72,
    5 * 72, 583 * 72 / 100,		/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_300 | PCL_RES_600_600_MONO,
    {0, 33, 18, 18},
    {0, 33, 10, 10},	/* Check/Fix */
    PCL_COLOR_CMY,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE,
    dj600_papersizes,
    basic_papertypes,
    emptylist,
  },
  /* Deskjet 6xx series */
  { 601,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_300 | PCL_RES_600_600_MONO,
    {0, 33, 18, 18},
    {0, 33, 10, 10},	/* Check/Fix */
    PCL_COLOR_CMYK,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE,
    dj600_papersizes,
    basic_papertypes,
    emptylist,
  },
  /* Deskjet 69x series (Photo Capable) */
  { 690,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_300 | PCL_RES_600_600,
    {0, 33, 18, 18},
    {0, 33, 10, 10},	/* Check/Fix */
    PCL_COLOR_CMYK | PCL_COLOR_CMYKcm,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE,
    dj600_papersizes,
    basic_papertypes,
    emptylist,
  },
  /* Deskjet 850/855/870/890 (C-RET) */
  { 800,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600_MONO,
    {3, 33, 18, 18},
    {5, 33, 10, 10},
    PCL_COLOR_CMYK | PCL_COLOR_CMYK4,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE,
    dj600_papersizes,
    basic_papertypes,
    emptylist,
  },
  /* Deskjet 810C, 812C, 840C, 842C, 845C, 895C (C-RET) */
  { 840,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_300 | PCL_RES_600_600,
    {0, 33, 18, 18},
    {0, 33, 10, 10},	/* Check/Fix */
    PCL_COLOR_CMYK | PCL_COLOR_CMYK4b,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE,
    dj600_papersizes,
    basic_papertypes,
    emptylist,
  },
  /* Deskjet 900 series, 1220C, PhotoSmart P1000/P1100 */
  { 900,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600 /* | PCL_RES_1200_600 | PCL_RES_2400_600 */,
    {3, 33, 18, 18},
    {5, 33, 10, 10},	/* Oliver Vecernik */
    PCL_COLOR_CMYK,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE | PCL_PRINTER_DUPLEX,
    dj600_papersizes,
    basic_papertypes,
    emptylist,
  },
  /* Deskjet 1220C (or other large format 900) */
  { 901,
    13 * 72, 19 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600 /* | PCL_RES_1200_600 | PCL_RES_2400_600 */,
    {3, 33, 18, 18},
    {5, 33, 10, 10},
    PCL_COLOR_CMYK,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE,
    dj1220_papersizes,
    basic_papertypes,
    emptylist,
  },
  /* Deskjet 1100C, 1120C */
  { 1100,
    13 * 72, 19 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600_MONO,
    {3, 33, 18, 18},
    {5, 33, 10, 10},
    PCL_COLOR_CMYK | PCL_COLOR_CMYK4,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE,
    dj1100_papersizes,
    basic_papertypes,
    dj_papersources,
  },
  /* Deskjet 1200C */
  { 1200,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_CMY,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE,
    dj1200_papersizes,
    basic_papertypes,
    dj_papersources,
  },
  /* Deskjet 1600C */
  { 1600,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_CMYK,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE,
    dj1200_papersizes,
    basic_papertypes,
    dj_papersources,
  },
  /* Deskjet 2000 */
  { 2000,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600,
    {0, 35, 18, 18},			/* Michel Goraczko */
    {0, 35, 10, 10},	/* Check/Fix */
    PCL_COLOR_CMYK,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE,
    dj2000_papersizes,
    new_papertypes,
    dj_papersources,
  },
  /* Deskjet 2500 */
  { 2500,
    13 * 72, 19 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_CMYK,
    PCL_PRINTER_DJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_MEDIATYPE |
      PCL_PRINTER_CUSTOM_SIZE | PCL_PRINTER_BLANKLINE,
    dj2500_papersizes,
    new_papertypes,
    dj2500_papersources,
  },
  /* LaserJet II series */
  { 2,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ,
    ljsmall_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* LaserJet IIP (TIFF but no blankline) */
  { 21,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF,
    ljsmall_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* Some laser printers don't have expanded A4 margins */
  { 22,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 18, 18},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ,
    ljsmall_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* PCL-4 with large paper */
  { 23,
    13 * 72, 19 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ,
    ljbig_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* PCL-4 with large paper, no expanded A4 margins */
  { 24,
    13 * 72, 19 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 18, 18},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ,
    ljbig_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* LaserJet III series */
  { 3,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
    ljsmall_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* LaserJet III series */
  { 31,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
    ljsmall_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* Some laser printers don't have expanded A4 margins */
  { 32,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 18, 18},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
    ljsmall_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* PCL-5 with large paper */
  { 33,
    13 * 72, 19 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
    ljbig_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* PCL-5 with large paper, no expanded margins */
  { 34,
    13 * 72, 19 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 18, 18},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
    ljbig_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* PCL-5 with tabloid paper, no expanded margins */
  { 35,
    118 * 72 / 10, 17 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 18, 18},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
    ljtabloid_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* LaserJet 4L */
  { 4,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
    ljsmall_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* LaserJet 4V */
  { 5,
    13 * 72, 19 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE,
    ljbig_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* LaserJet 4Si */
  { 51,
    13 * 72, 19 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE |
      PCL_PRINTER_DUPLEX,
    ljbig_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* LaserJet 4 series (except as above), 5 series, 6 series */
  { 6,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE |
      PCL_PRINTER_DUPLEX,
    ljsmall_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* PCL-5c/5e/6/XL with large paper */
  { 61,
    13 * 72, 19 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE |
      PCL_PRINTER_DUPLEX,
    ljbig_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* Some laser printers don't have expanded A4 margins */
  { 62,
    17 * 72 / 2, 14 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600,
    {12, 12, 18, 18},
    {12, 12, 18, 18},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE |
      PCL_PRINTER_DUPLEX,
    ljsmall_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* PCL-5c/5e/6/XL with large paper, no expanded A4 margins */
  { 63,
    13 * 72, 19 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600,
    {12, 12, 18, 18},
    {12, 12, 18, 18},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE |
      PCL_PRINTER_DUPLEX,
    ljbig_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* PCL-5c/5e/6/XL with tabloid paper, no expanded A4 margins */
  { 64,
    118 * 72 / 10, 17 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600,
    {12, 12, 18, 18},
    {12, 12, 18, 18},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE |
      PCL_PRINTER_DUPLEX,
    ljtabloid_papersizes,
    emptylist,
    laserjet_papersources,
  },
  /* LaserJet 5Si */
  { 7,
    13 * 72, 19 * 72,
    1, 1,				/* Min paper size */
    PCL_RES_150_150 | PCL_RES_300_300 | PCL_RES_600_600,
    {12, 12, 18, 18},
    {12, 12, 10, 10},	/* Check/Fix */
    PCL_COLOR_NONE,
    PCL_PRINTER_LJ | PCL_PRINTER_NEW_ERG | PCL_PRINTER_TIFF | PCL_PRINTER_BLANKLINE |
      PCL_PRINTER_DUPLEX,
    ljbig_papersizes,
    emptylist,
    laserjet_papersources,
  },
};


static const char standard_sat_adjustment[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<gutenprint>\n"
"<curve wrap=\"wrap\" type=\"linear\" gamma=\"0\">\n"
"<sequence count=\"48\" lower-bound=\"0\" upper-bound=\"4\">\n"
/* C */  "1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 "  /* B */
/* B */  "1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 "  /* M */
/* M */  "1.00 0.95 0.90 0.90 0.90 0.90 0.90 0.90 "  /* R */
/* R */  "0.90 0.95 0.95 1.00 1.00 1.00 1.00 1.00 "  /* Y */
/* Y */  "1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 "  /* G */
/* G */  "1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 "  /* C */
"</sequence>\n"
"</curve>\n"
"</gutenprint>\n";

static const char standard_lum_adjustment[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<gutenprint>\n"
"<curve wrap=\"wrap\" type=\"linear\" gamma=\"0\">\n"
"<sequence count=\"48\" lower-bound=\"0\" upper-bound=\"4\">\n"
/* C */  "0.65 0.67 0.70 0.72 0.77 0.80 0.82 0.85 "  /* B */
/* B */  "0.87 0.86 0.82 0.79 0.79 0.82 0.85 0.88 "  /* M */
/* M */  "0.92 0.95 0.96 0.97 0.97 0.97 0.96 0.96 "  /* R */
/* R */  "0.96 0.97 0.97 0.98 0.99 1.00 1.00 1.00 "  /* Y */
/* Y */  "1.00 0.97 0.95 0.94 0.93 0.92 0.90 0.86 "  /* G */
/* G */  "0.79 0.76 0.71 0.68 0.68 0.68 0.68 0.66 "  /* C */
"</sequence>\n"
"</curve>\n"
"</gutenprint>\n";

static const char standard_hue_adjustment[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<gutenprint>\n"
"<curve wrap=\"wrap\" type=\"linear\" gamma=\"0\">\n"
"<sequence count=\"48\" lower-bound=\"-6\" upper-bound=\"6\">\n"
/* C */  "0.00 0.06 0.10 0.10 0.06 -.01 -.09 -.17 "  /* B */
/* B */  "-.25 -.33 -.38 -.38 -.36 -.34 -.34 -.34 "  /* M */
/* M */  "-.34 -.34 -.36 -.40 -.50 -.40 -.30 -.20 "  /* R */
/* R */  "-.12 -.07 -.04 -.02 0.00 0.00 0.00 0.00 "  /* Y */
/* Y */  "0.00 0.00 0.00 -.05 -.10 -.15 -.22 -.24 "  /* G */
/* G */  "-.26 -.30 -.33 -.28 -.25 -.20 -.13 -.06 "  /* C */
"</sequence>\n"
"</curve>\n"
"</gutenprint>\n";

static const stp_parameter_t the_parameters[] =
{
  {
    "PageSize", N_("Page Size"), "Color=No,Category=Basic Printer Setup",
    N_("Size of the paper being printed to"),
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_CORE,
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
  },
  {
    "MediaType", N_("Media Type"), "Color=Yes,Category=Basic Printer Setup",
    N_("Type of media (plain paper, photo paper, etc.)"),
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
  },
  {
    "InputSlot", N_("Media Source"), "Color=No,Category=Basic Printer Setup",
    N_("Source (input slot) of the media"),
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
  },
  {
    "Quality", N_("Print Quality"), "Color=Yes,Category=Basic Output Adjustment",
    N_("Print Quality"),
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 0, 0
  },
  {
    "Resolution", N_("Resolution"), "Color=Yes,Category=Basic Printer Setup",
    N_("Resolution of the print"),
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
  },
  {
    "InkType", N_("Ink Type"), "Color=Yes,Category=Advanced Printer Setup",
    N_("Type of ink in the printer"),
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
  },
  {
    "InkChannels", N_("Ink Channels"), "Color=Yes,Category=Advanced Printer Functionality",
    N_("Ink Channels"),
    STP_PARAMETER_TYPE_INT, STP_PARAMETER_CLASS_FEATURE,
    STP_PARAMETER_LEVEL_INTERNAL, 0, 0, STP_CHANNEL_NONE, 0, 0
  },
  {
    "PrintingMode", N_("Printing Mode"), "Color=Yes,Category=Core Parameter",
    N_("Printing Output Mode"),
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_CORE,
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
  },
  {
    "Duplex", N_("Double-Sided Printing"), "Color=No,Category=Basic Printer Setup",
    N_("Duplex/Tumble Setting"),
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0
  },
 {
    "Orientation", N_("Orientation"), "Color=No,Category=Basic Printer Setup",
    N_("Orientation, Portrait, Landscape, Upside Down, Seascape"),
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0,
  },
 {
    "LabelSeparator", N_("Paper Sensor Type"),
    "Color=No,Category=Basic Printer Setup",
    N_("Gap, Mark on Top, Mark on Bottom, Notch, Continuous"),
    STP_PARAMETER_TYPE_STRING_LIST, STP_PARAMETER_CLASS_FEATURE,
    STP_PARAMETER_LEVEL_BASIC, 1, 1, STP_CHANNEL_NONE, 1, 0,
  },
};

static const int the_parameter_count =
sizeof(the_parameters) / sizeof(const stp_parameter_t);

typedef struct
{
  const stp_parameter_t param;
  double min;
  double max;
  double defval;
  int color_only;
} float_param_t;

static const float_param_t float_parameters[] =
{
  {
    {
      "CyanDensity", N_("Cyan Density"), "Color=Yes,Category=Output Level Adjustment",
      N_("Adjust the cyan density"),
      STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
      STP_PARAMETER_LEVEL_ADVANCED, 0, 1, 1, 1, 0
    }, 0.0, 2.0, 1.0, 1
  },
  {
    {
      "MagentaDensity", N_("Magenta Density"), "Color=Yes,Category=Output Level Adjustment",
      N_("Adjust the magenta density"),
      STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
      STP_PARAMETER_LEVEL_ADVANCED, 0, 1, 2, 1, 0
    }, 0.0, 2.0, 1.0, 1
  },
  {
    {
      "YellowDensity", N_("Yellow Density"), "Color=Yes,Category=Output Level Adjustment",
      N_("Adjust the yellow density"),
      STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
      STP_PARAMETER_LEVEL_ADVANCED, 0, 1, 3, 1, 0
    }, 0.0, 2.0, 1.0, 1
  },
  {
    {
      "BlackDensity", N_("Black Density"), "Color=Yes,Category=Output Level Adjustment",
      N_("Adjust the black density"),
      STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
      STP_PARAMETER_LEVEL_ADVANCED, 0, 1, 0, 1, 0
    }, 0.0, 2.0, 1.0, 1
  },
  {
    {
      "LightCyanTrans", N_("Light Cyan Transition"), "Color=Yes,Category=Advanced Ink Adjustment",
      N_("Light Cyan Transition"),
      STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
      STP_PARAMETER_LEVEL_ADVANCED4, 0, 1, STP_CHANNEL_NONE, 1, 0
    }, 0.0, 5.0, 1.0, 1
  },
  {
    {
      "LightMagentaTrans", N_("Light Magenta Transition"), "Color=Yes,Category=Advanced Ink Adjustment",
      N_("Light Magenta Transition"),
      STP_PARAMETER_TYPE_DOUBLE, STP_PARAMETER_CLASS_OUTPUT,
      STP_PARAMETER_LEVEL_ADVANCED4, 0, 1, STP_CHANNEL_NONE, 1, 0
    }, 0.0, 5.0, 1.0, 1
  },
};

static const int float_parameter_count =
sizeof(float_parameters) / sizeof(const float_param_t);

/*
 * Convert a name into it's option value
 */

static int pcl_string_to_val(const char *string,		/* I: String */
                           const pcl_t *options,	/* I: Options */
			   int num_options)		/* I: Num options */
{

  int i;
  int code = -1;

 /*
  * Look up the string in the table and convert to the code.
  */

  for (i=0; i<num_options; i++) {
    if (!strcmp(string, options[i].pcl_name)) {
       code=options[i].pcl_code;
       break;
       }
  }

  stp_deprintf(STP_DBG_PCL, "String: %s, Code: %d\n", string, code);

  return(code);
}

/*
 * Convert a value into it's option name
 */

static const char * pcl_val_to_string(int code,			/* I: Code */
                           const pcl_t *options,	/* I: Options */
			   int num_options)		/* I: Num options */
{

  int i;
  const char *string = NULL;

 /*
  * Look up the code in the table and convert to the string.
  */

  for (i=0; i<num_options; i++) {
    if (code == options[i].pcl_code) {
       string=options[i].pcl_name;
       break;
       }
  }

  stp_deprintf(STP_DBG_PCL, "Code: %d, String: %s\n", code, string);

  return(string);
}

static const char * pcl_val_to_text(int code,			/* I: Code */
                           const pcl_t *options,	/* I: Options */
			   int num_options)		/* I: Num options */
{

  int i;
  const char *string = NULL;

 /*
  * Look up the code in the table and convert to the string.
  */

  for (i=0; i<num_options; i++) {
    if (code == options[i].pcl_code) {
       string=gettext(options[i].pcl_text);
       break;
       }
  }

  stp_deprintf(STP_DBG_PCL, "Code: %d, String: %s\n", code, string);

  return(string);
}

static const double dot_sizes[] = { 0.5, 0.832, 1.0 };
static const double dot_sizes_cret[] = { 1.0, 1.0, 1.0 };

static const stp_dotsize_t variable_dotsizes[] =
{
  { 0x1, 0.5 },
  { 0x2, 0.67 },
  { 0x3, 1.0 }
};

static const stp_shade_t variable_shades[] =
{
  { 0.38, 3, variable_dotsizes },
  { 1.0, 3, variable_dotsizes }
};

/*
 * pcl_get_model_capabilities() - Return struct of model capabilities
 */

static const pcl_cap_t *				/* O: Capabilities */
pcl_get_model_capabilities(int model)	/* I: Model */
{
  int i;
  int models= sizeof(pcl_model_capabilities) / sizeof(pcl_cap_t);
  for (i=0; i<models; i++) {
    if (pcl_model_capabilities[i].model == model) {
      return &(pcl_model_capabilities[i]);
    }
  }
  stp_erprintf("pcl: model %d not found in capabilities list.\n",model);
  return &(pcl_model_capabilities[0]);
}

/*
 * Determine the current resolution based on quality and resolution settings
 */

static void
pcl_describe_resolution(const stp_vars_t *v, int *x, int *y)
{
  int i;
  int model = stp_get_model_id(v);
  const char *resolution = stp_get_string_parameter(v, "Resolution");
  const char *quality;
  const pcl_cap_t *caps = NULL;
  if (resolution)
    {
      for (i = 0; i < NUM_RESOLUTIONS; i++)
	{
	  if (!strcmp(resolution, pcl_resolutions[i].pcl_name))
	    {
	      *x = pcl_resolutions[i].p0;
	      *y = pcl_resolutions[i].p1;
	      return;
	    }
	}
    }
  quality = stp_get_string_parameter(v, "Quality");
  caps = pcl_get_model_capabilities(model);
  if (quality && strcmp(quality, "None") == 0)
    quality = "Standard";
  if (quality)
    {
      for (i = 0; i < NUM_QUALITIES; i++)
	{
	  if ((caps->resolutions & pcl_qualities[i].pcl_code) &&
	      !strcmp(quality, pcl_qualities[i].pcl_name))
	    {
	      *x = pcl_qualities[i].p0;
	      *y = pcl_qualities[i].p1;
	      return;
	    }
	}
    }
  *x = -1;
  *y = -1;
}

/*
 * Convert Media size name into PCL media code for printer
 */

static int pcl_convert_media_size(const char *media_size,	/* I: Media size string */
				  int  model)		/* I: model number */
{

  int i;
  int media_code = 0;
  const pcl_cap_t *caps;

 /*
  * First look up the media size in the table and convert to the code.
  */

  media_code = pcl_string_to_val(media_size, pcl_media_sizes,
                                 NUM_PRINTER_PAPER_SIZES);

  stp_deprintf(STP_DBG_PCL, "Media Size: %s, Code: %d\n", media_size, media_code);

 /*
  * Now see if the printer supports the code found.
  */

  if (media_code != -1) {
    caps = pcl_get_model_capabilities(model);

    for (i=0; (i<NUM_PRINTER_PAPER_SIZES) && (caps->paper_sizes[i] != -1); i++) {
      if (media_code == (int) caps->paper_sizes[i])
        return(media_code);		/* Is supported */
    }

    stp_deprintf(STP_DBG_PCL, "Media Code %d not supported by printer model %d.\n",
      media_code, model);
    return(-1);				/* Not supported */
  }
  else
    return(-1);				/* Not supported */
}


static const stp_param_string_t ink_types[] =
{
  { "CMYK",	N_ ("Color + Black Cartridges") },
  { "Photo",	N_ ("Color + Photo Cartridges") }
};

/*
 * Duplex support - modes available
 * Note that the internal names MUST match those in cups/genppd.c else the
 * PPD files will not be generated correctly
 */

static const stp_param_string_t duplex_types[] =
{
  { "None",		N_ ("Off") },
  { "DuplexNoTumble",	N_ ("Long Edge (Standard)") },
  { "DuplexTumble",	N_ ("Short Edge (Flip)") }
};
#define NUM_DUPLEX (sizeof (duplex_types) / sizeof (stp_param_string_t))

/*
 * Orientation support - modes available
 * Note that the internal names MUST match those in cups/genppd.c else the
 * PPD files will not be generated correctly
 */

static const stp_param_string_t orientation_types[] =
{
  { "Portrait",         N_ ("Portrait") },
  { "Landscape",        N_ ("Landscape") },
  { "UpsideDown",       N_ ("Reverse Portrait") },
  { "Seascape",         N_ ("Reverse Landscape") },
};
#define NUM_ORIENTATION (sizeof (orientation_types) / sizeof (stp_param_string_t))

/*
 * Label Separator Support for D-O printers, modes available
 */

static const stp_param_string_t label_separator_types[] =
{
  { "IGNORE",		N_ ("Keep Previous") },
  { "GAP",		N_ ("Gap") },
  { "TOP",		N_ ("Mark on Top") },
  { "BOTTOM",		N_ ("Mark on Bottom") },
  { "NOTCH",		N_ ("Notch") },
  { "NONE",		N_ ("Continuous") },
};
#define NUM_LABEL_SEPARATOR (sizeof (label_separator_types) / sizeof (stp_param_string_t))


/*
 * 'pcl_papersize_valid()' - Is the paper size valid for this printer.
 */

static int
pcl_papersize_valid(const stp_papersize_t *pt,
		    int model)
{

  const pcl_cap_t *caps = pcl_get_model_capabilities(model);

#ifdef PCL_NO_CUSTOM_PAPERSIZES
  int use_custom = 0;
#else
  int use_custom = ((caps->stp_printer_type & PCL_PRINTER_CUSTOM_SIZE)
                     == PCL_PRINTER_CUSTOM_SIZE);
#endif

  unsigned int pwidth = pt->width;
  unsigned int pheight = pt->height;

/*
 * This function decides whether a paper size is allowed for the
 * current printer. The DeskJet feed mechanisms set a minimum and
 * maximum size for the paper, BUT some of the directly supported
 * media sizes are less than this minimum (eg card and envelopes)
 * So, we allow supported sizes though, but clamp custom sizes
 * to the min and max sizes.
 */

/*
 * Is it a valid name?
 */

  if (strlen(pt->name) <= 0)
    return(0);

/*
 * Is it a valid type?
 */  
  if (pt->paper_size_type != PAPERSIZE_TYPE_STANDARD &&
      pt->paper_size_type != PAPERSIZE_TYPE_ENVELOPE)
    return(0);
  
/*
 * Is it a recognized supported name?
 */

  if (pcl_convert_media_size(pt->name, model) != -1)
    return(1);

/*
 * If we are not allowed to use custom paper sizes, we are done
 */

  if (use_custom == 0)
    return(0);

/*
 * We are allowed custom paper sizes. Check that the name contains
 * d-o if this is the Datamax O'Neil label printer and not custom paper
 */

  if (caps->stp_printer_type & PCL_PRINTER_LABEL) {
    if (strcmp(pt->name, "Custom")) {
      if (NULL != strstr(pt->name, "d-o")) {
        return(1);
      } else {
        return(0);
      }
    }
  }


/*
 * We are allowed custom paper sizes. Check that the size is within
 * limits.
 */

  if (pwidth <= caps->custom_max_width &&
     pheight <= caps->custom_max_height &&
     (pheight >=  caps->custom_min_height || pheight == 0) &&
     (pwidth >= caps->custom_min_width || pwidth == 0))
    return(1);

  return(0);
}

/*
 * 'pcl_parameters()' - Return the parameter values for the given parameter.
 */

static stp_parameter_list_t
pcl_list_parameters(const stp_vars_t *v)
{
  stp_parameter_list_t *ret = stp_parameter_list_create();
  stp_parameter_list_t *tmp_list;

  int i;

  /* Set up dithering */
  tmp_list = stp_dither_list_parameters(v);
  stp_parameter_list_append(ret, tmp_list);
  stp_parameter_list_destroy(tmp_list);
  
  for (i = 0; i < the_parameter_count; i++)
    stp_parameter_list_add_param(ret, &(the_parameters[i]));
  for (i = 0; i < float_parameter_count; i++)
    stp_parameter_list_add_param(ret, &(float_parameters[i].param));
  return ret;
}

static void
pcl_parameters(const stp_vars_t *v, const char *name,
	       stp_parameter_t *description)
{
  int		model = stp_get_model_id(v);
  int		i;
  const pcl_cap_t *caps;
  description->p_type = STP_PARAMETER_TYPE_INVALID;

  if (name == NULL)
    return;

  stp_deprintf(STP_DBG_PCL, "pcl_parameters(): Name = %s\n", name);

  caps = pcl_get_model_capabilities(model);

  stp_deprintf(STP_DBG_PCL, "Printer model = %d\n", model);
  stp_deprintf(STP_DBG_PCL, "PageWidth = %d, PageHeight = %d\n", caps->custom_max_width, caps->custom_max_height);
  stp_deprintf(STP_DBG_PCL, "MinPageWidth = %d, MinPageHeight = %d\n", caps->custom_min_width, caps->custom_min_height);
  stp_deprintf(STP_DBG_PCL, "Normal Margins: top = %d, bottom = %d, left = %d, right = %d\n",
    caps->normal_margins.top_margin, caps->normal_margins.bottom_margin,
    caps->normal_margins.left_margin, caps->normal_margins.right_margin);
  stp_deprintf(STP_DBG_PCL, "A4 Margins: top = %d, bottom = %d, left = %d, right = %d\n",
    caps->a4_margins.top_margin, caps->a4_margins.bottom_margin,
    caps->a4_margins.left_margin, caps->a4_margins.right_margin);
  stp_deprintf(STP_DBG_PCL, "Resolutions: %d\n", caps->resolutions);
  stp_deprintf(STP_DBG_PCL, "ColorType = %d, PrinterType = %d\n", caps->color_type, caps->stp_printer_type);

  for (i = 0; i < the_parameter_count; i++)
    if (strcmp(name, the_parameters[i].name) == 0)
      {
	stp_fill_parameter_settings(description, &(the_parameters[i]));
	break;
      }
  description->deflt.str = NULL;

  for (i = 0; i < float_parameter_count; i++)
    if (strcmp(name, float_parameters[i].param.name) == 0)
      {
	stp_fill_parameter_settings(description,
				    &(float_parameters[i].param));
	description->deflt.dbl = float_parameters[i].defval;
	description->bounds.dbl.upper = float_parameters[i].max;
	description->bounds.dbl.lower = float_parameters[i].min;
	break;
      }

  if (strcmp(name, "PageSize") == 0)
    {
      int papersizes = stp_known_papersizes();
      description->bounds.str = stp_string_list_create();
      for (i = 0; i < papersizes; i++)
	{
	  const stp_papersize_t *pt = stp_get_papersize_by_index(i);
	  if (strlen(pt->name) > 0 && pcl_papersize_valid(pt, model))
	    stp_string_list_add_string(description->bounds.str,
				       pt->name, gettext(pt->text));
	}
      description->deflt.str =
	stp_string_list_param(description->bounds.str, 0)->name;
    }
  else if (strcmp(name, "MediaType") == 0)
  {
    description->bounds.str = stp_string_list_create();
    if (caps->paper_types[0] != -1)
      {
	for (i=0; (i < NUM_PRINTER_PAPER_TYPES) && (caps->paper_types[i] != -1); i++)
	  stp_string_list_add_string(description->bounds.str,
				    pcl_val_to_string(caps->paper_types[i],
						      pcl_media_types,
						      NUM_PRINTER_PAPER_TYPES),
				    pcl_val_to_text(caps->paper_types[i],
						    pcl_media_types,
						    NUM_PRINTER_PAPER_TYPES));
	description->deflt.str =
	  stp_string_list_param(description->bounds.str, 0)->name;
      }
    else
      description->is_active = 0;
  }
  else if (strcmp(name, "InputSlot") == 0)
  {
    description->bounds.str = stp_string_list_create();
    if (caps->paper_sources[0] != -1)
      {
	for (i=0; (i < NUM_PRINTER_PAPER_SOURCES) && (caps->paper_sources[i] != -1); i++)
	  stp_string_list_add_string(description->bounds.str,
				    pcl_val_to_string(caps->paper_sources[i],
						      pcl_media_sources,
						      NUM_PRINTER_PAPER_SOURCES),
				    pcl_val_to_text(caps->paper_sources[i],
						    pcl_media_sources,
						    NUM_PRINTER_PAPER_SOURCES));
	description->deflt.str =
	  stp_string_list_param(description->bounds.str, 0)->name;
      }
    else
      description->is_active = 0;
  }
  else if (strcmp(name, "Resolution") == 0)
  {
    description->bounds.str = stp_string_list_create();
    stp_string_list_add_string(description->bounds.str, "None", _("Default"));
    description->deflt.str = "None";
    for (i = 0; i < NUM_RESOLUTIONS; i++)
      if (caps->resolutions & pcl_resolutions[i].pcl_code)
	{
	  stp_string_list_add_string
	    (description->bounds.str,
	     pcl_val_to_string(pcl_resolutions[i].pcl_code,
			       pcl_resolutions, NUM_RESOLUTIONS),
	     pcl_val_to_text(pcl_resolutions[i].pcl_code,
			     pcl_resolutions, NUM_RESOLUTIONS));
	}
  }
  else if (strcmp(name, "Quality") == 0)
  {
    int has_standard_quality = 0;
    description->bounds.str = stp_string_list_create();
    stp_string_list_add_string(description->bounds.str, "None",
			       _("Manual Control"));
    for (i = 0; i < NUM_QUALITIES; i++)
      if (caps->resolutions & pcl_qualities[i].pcl_code)
	{
	  const char *qual =
	    pcl_val_to_string(pcl_qualities[i].pcl_code,
			      pcl_qualities, NUM_QUALITIES);
	  if (! stp_string_list_is_present(description->bounds.str, qual))
	    stp_string_list_add_string
	      (description->bounds.str, qual,
	       pcl_val_to_text(pcl_qualities[i].pcl_code,
			       pcl_qualities, NUM_QUALITIES));
	  if (strcmp(qual, "Standard") == 0)
	    has_standard_quality = 1;
	}
    if (has_standard_quality)
      description->deflt.str = "Standard";
    else
      description->deflt.str = "None";
  }
  else if (strcmp(name, "InkType") == 0)
  {
    description->bounds.str = stp_string_list_create();
    if (caps->color_type & PCL_COLOR_CMYKcm)
    {
      description->deflt.str = ink_types[0].name;
      stp_string_list_add_string(description->bounds.str,
			       ink_types[0].name,gettext(ink_types[0].text));
      stp_string_list_add_string(description->bounds.str,
			       ink_types[1].name,gettext(ink_types[1].text));
    }
    else
      description->is_active = 0;
  }
  else if (strcmp(name, "Duplex") == 0)
  {
    int offer_duplex=0;

    description->bounds.str = stp_string_list_create();

/*
 * Don't offer the Duplex/Tumble options if the JobMode parameter is
 * set to "Page" Mode.
 * "Page" mode is set by the Gimp Plugin, which only outputs one page at a
 * time, so Duplex/Tumble is meaningless.
 */

    if (stp_get_string_parameter(v, "JobMode"))
        offer_duplex = strcmp(stp_get_string_parameter(v, "JobMode"), "Page");
    else
     offer_duplex=1;

    if (offer_duplex)
    {
      if (caps->stp_printer_type & PCL_PRINTER_DUPLEX)
      {
        description->deflt.str = duplex_types[0].name;
        for (i=0; i < NUM_DUPLEX; i++)
        {
          stp_string_list_add_string(description->bounds.str,
			       duplex_types[i].name,gettext(duplex_types[i].text));
        }
      }
      else
        description->is_active = 0;	/* Not supported by printer */
    }
    else
      description->is_active = 0;	/* Not in "Job" mode */
  }
  else if (strcmp(name, "Orientation") == 0)
  {
    if (caps->stp_printer_type & PCL_PRINTER_LABEL)
    {
      description->bounds.str = stp_string_list_create();
      description->deflt.str = orientation_types[0].name;
      for (i=0; i < NUM_ORIENTATION; i++)
      {
        stp_string_list_add_string(description->bounds.str,
            orientation_types[i].name,gettext(orientation_types[i].text));
      }
    }
    else
    {
      description->is_active = 0;
    }
  }
  else if (strcmp(name, "LabelSeparator") == 0)
  {
    if (caps->stp_printer_type & PCL_PRINTER_LABEL)
    {
      description->bounds.str = stp_string_list_create();
      description->deflt.str = label_separator_types[0].name;
      for (i=0; i < NUM_LABEL_SEPARATOR; i++)
      {
        stp_string_list_add_string(description->bounds.str,
            label_separator_types[i].name, gettext(label_separator_types[i].text));
      }
    }
    else
    {
      description->is_active = 0;
    }
  }
  else if (strcmp(name, "CyanDensity") == 0 ||
	   strcmp(name, "MagentaDensity") == 0 ||
	   strcmp(name, "YellowDensity") == 0 ||
	   strcmp(name, "BlackDensity") == 0)
    {
      if (caps->color_type != PCL_COLOR_NONE &&
	  stp_check_string_parameter(v, "PrintingMode", STP_PARAMETER_DEFAULTED) &&
	  strcmp(stp_get_string_parameter(v, "PrintingMode"), "Color") == 0)
	description->is_active = 1;
      else
	description->is_active = 0;
    }
  else if (strcmp(name, "LightCyanTrans") == 0 ||
	   strcmp(name, "LightMagentaTrans") == 0)
    {
      if (caps->color_type & PCL_COLOR_CMYKcm &&
	  stp_check_string_parameter(v, "PrintingMode", STP_PARAMETER_DEFAULTED) &&
	  strcmp(stp_get_string_parameter(v, "PrintingMode"), "Color") == 0)
	description->is_active = 1;
      else
	description->is_active = 0;
    }
  else if (strcmp(name, "InkChannels") == 0)
    {
      if (caps->color_type & PCL_COLOR_CMYKcm)
	description->deflt.integer = 6;
      else if (caps->color_type == PCL_COLOR_NONE)
	description->deflt.integer = 1;
      else
	description->deflt.integer = 4;
      description->bounds.integer.lower = -1;
      description->bounds.integer.upper = -1;
    }
  else if (strcmp(name, "PrintingMode") == 0)
    {
      description->bounds.str = stp_string_list_create();
      if (caps->color_type != PCL_COLOR_NONE)
	stp_string_list_add_string
	  (description->bounds.str, "Color", _("Color"));
      stp_string_list_add_string
	(description->bounds.str, "BW", _("Black and White"));
      description->deflt.str =
	stp_string_list_param(description->bounds.str, 0)->name;
    }
}


/*
 * 'pcl_imageable_area()' - Return the imageable area of the page.
 */
static void
internal_imageable_area(const stp_vars_t *v,     /* I */
			int  use_paper_margins,
			int  *left,	/* O - Left position in points */
			int  *right,	/* O - Right position in points */
			int  *bottom,	/* O - Bottom position in points */
			int  *top)	/* O - Top position in points */
{
  int	width, height;			/* Size of page */
  const pcl_cap_t *caps;		/* Printer caps */
  int	pcl_media_size;			/* Converted media size */
  const char *media_size = stp_get_string_parameter(v, "PageSize");
  const stp_papersize_t *pp = NULL;
  int left_margin = 0;
  int right_margin = 0;
  int bottom_margin = 0;
  int top_margin = 0;

  caps = pcl_get_model_capabilities(stp_get_model_id(v));

  stp_default_media_size(v, &width, &height);

/* If we are using A4 paper, then the margins are different than any
 * other paper size. This is because HP wanted to have the same printable
 * width for A4 as for letter. Go figure.
 */

  if (!media_size)
    media_size = "";
  if (strlen(media_size) == 0 &&
      ((pp = stp_get_papersize_by_size(stp_get_page_height(v),
				       stp_get_page_width(v))) != NULL))
    media_size = pp->name;

  stp_deprintf(STP_DBG_PCL, "pcl_imageable_area(): media_size: '%s'\n",
	       media_size);

  pcl_media_size = pcl_convert_media_size(media_size, stp_get_model_id(v));
  if (media_size)
    pp = stp_get_papersize_by_name(media_size);
  if (pp && use_paper_margins)
    {
      left_margin = pp->left;
      right_margin = pp->right;
      bottom_margin = pp->bottom;
      top_margin = pp->top;
    }

  if (pcl_media_size == PCL_PAPERSIZE_A4)
  {
    left_margin = MAX(left_margin, caps->a4_margins.left_margin);
    right_margin = MAX(right_margin, caps->a4_margins.right_margin);
    top_margin = MAX(top_margin, caps->a4_margins.top_margin);
    bottom_margin = MAX(bottom_margin, caps->a4_margins.bottom_margin);
  }
  else
  {
    left_margin = MAX(left_margin, caps->normal_margins.left_margin);
    right_margin = MAX(right_margin, caps->normal_margins.right_margin);
    top_margin = MAX(top_margin, caps->normal_margins.top_margin);
    bottom_margin = MAX(bottom_margin, caps->normal_margins.bottom_margin);
  }
  *left =	left_margin;
  *right =	width - right_margin;
  *top =	top_margin;
  *bottom =	height - bottom_margin;
}

static void
pcl_imageable_area(const stp_vars_t *v,     /* I */
                   int  *left,		/* O - Left position in points */
                   int  *right,		/* O - Right position in points */
                   int  *bottom,	/* O - Bottom position in points */
                   int  *top)		/* O - Top position in points */
{
  internal_imageable_area(v, 1, left, right, bottom, top);
}

static void
pcl_limit(const stp_vars_t *v,  		/* I */
	  int *width,
	  int *height,
	  int *min_width,
	  int *min_height)
{
  const pcl_cap_t *caps= pcl_get_model_capabilities(stp_get_model_id(v));
  *width =	caps->custom_max_width;
  *height =	caps->custom_max_height;
  *min_width =	caps->custom_min_width;
  *min_height =	caps->custom_min_height;
}

static const char *
pcl_describe_output(const stp_vars_t *v)
{
  int printing_color = 0;
  int model = stp_get_model_id(v);
  const pcl_cap_t *caps = pcl_get_model_capabilities(model);
  const char *print_mode = stp_get_string_parameter(v, "PrintingMode");
  int xdpi, ydpi;

  pcl_describe_resolution(v, &xdpi, &ydpi);
  if (!print_mode || strcmp(print_mode, "Color") == 0)
    printing_color = 1;
  if (((caps->resolutions & PCL_RES_600_600_MONO) == PCL_RES_600_600_MONO) &&
      printing_color && xdpi == 600 && ydpi == 600)
    printing_color = 0;
  if (printing_color)
    {
      if ((caps->color_type & PCL_COLOR_CMY) == PCL_COLOR_CMY)
	return "CMY";
      else
	return "CMYK";
    }
  else
    return "Grayscale";
}

/*
 * 'pcl_print()' - Print an image to an HP printer.
 */

static void
pcl_printfunc(stp_vars_t *v)
{
  pcl_privdata_t *pd = (pcl_privdata_t *) stp_get_component_data(v, "Driver");
  int do_blank = pd->do_blank;
  unsigned char *black = stp_dither_get_channel(v, STP_ECOLOR_K, 0);
  unsigned char *cyan = stp_dither_get_channel(v, STP_ECOLOR_C, 0);
  unsigned char *lcyan = stp_dither_get_channel(v, STP_ECOLOR_C, 1);
  unsigned char *magenta = stp_dither_get_channel(v, STP_ECOLOR_M, 0);
  unsigned char *lmagenta = stp_dither_get_channel(v, STP_ECOLOR_M, 1);
  unsigned char *yellow = stp_dither_get_channel(v, STP_ECOLOR_Y, 0);
  int len_c = stp_dither_get_last_position(v, STP_ECOLOR_C, 0);
  int len_lc = stp_dither_get_last_position(v, STP_ECOLOR_C, 1);
  int len_m = stp_dither_get_last_position(v, STP_ECOLOR_M, 0);
  int len_lm = stp_dither_get_last_position(v, STP_ECOLOR_M, 1);
  int len_y = stp_dither_get_last_position(v, STP_ECOLOR_Y, 0);
  int len_k = stp_dither_get_last_position(v, STP_ECOLOR_K, 0);
  int is_blank = (do_blank && (len_c == -1) && (len_lc == -1) &&
		  (len_m == -1) && (len_lm == -1) && (len_y == -1) &&
		  (len_k == -1));
  int height = pd->height;
  const char    *print_mode = stp_get_string_parameter(v, "PrintingMode");

  if (is_blank && (pd->blank_lines != 0))	/* repeated blank line */
    {
      pd->blank_lines++;
    }
  else				/* Not blank, or is first one */
    {
      if (! is_blank)
	{
	  if (pd->blank_lines > 1)		/* Output accumulated lines */
	    {
	      pd->blank_lines--;		/* correct for one already output */
	      stp_deprintf(STP_DBG_PCL, "Blank Lines = %d\n", pd->blank_lines);
	      stp_zprintf(v, "\033*b%dY", pd->blank_lines);
	      pd->blank_lines=0;
	    }
	  else;
	}
      else
	{
	  pd->blank_lines++;
	}

      if (pd->do_cret)
	{
	  /*
	   * 4-level (CRet) dithers...
	   */
	  if (strcmp(print_mode, "BW") == 0)
	    {
	      (*(pd->writefunc))(v, black + height / 2, height / 2, 0);
	      (*(pd->writefunc))(v, black, height / 2, 1);
	    }
	  else
	    {
	      if(pd->do_cretb)
		{
		  /*	    (*(pd->writefunc))(v, black + height / 2, 0, 0); */
		  (*(pd->writefunc))(v, black, height/2, 0);
		}
	      else
		{
		  (*(pd->writefunc))(v, black + height / 2, height / 2, 0);
		  (*(pd->writefunc))(v, black, height / 2, 0);
		}
	      (*(pd->writefunc))(v, cyan + height / 2, height / 2, 0);
	      (*(pd->writefunc))(v, cyan, height / 2, 0);
	      (*(pd->writefunc))(v, magenta + height / 2, height / 2, 0);
	      (*(pd->writefunc))(v, magenta, height / 2, 0);
	      (*(pd->writefunc))(v, yellow + height / 2, height / 2, 0);
	      if (pd->do_6color)
		{
		  (*(pd->writefunc))(v, yellow, height / 2, 0);
		  (*(pd->writefunc))(v, lcyan + height / 2, height / 2, 0);
		  (*(pd->writefunc))(v, lcyan, height / 2, 0);
		  (*(pd->writefunc))(v, lmagenta + height / 2, height / 2, 0);
		  (*(pd->writefunc))(v, lmagenta, height / 2, 1);		/* Last plane set on light magenta */
		}
	      else
		(*(pd->writefunc))(v, yellow, height / 2, 1);		/* Last plane set on yellow */
	    }
	}
      else
	{
	  /*
	   * Standard 2-level dithers...
	   */

	  if (strcmp(print_mode, "BW") == 0)
	    {
	      (*(pd->writefunc))(v, black, height, 1);
	    }
	  else
	    {
	      if (black != NULL)
		(*(pd->writefunc))(v, black, height, 0);
	      (*(pd->writefunc))(v, cyan, height, 0);
	      (*(pd->writefunc))(v, magenta, height, 0);
	      if (pd->do_6color)
		{
		  (*(pd->writefunc))(v, yellow, height, 0);
		  (*(pd->writefunc))(v, lcyan, height, 0);
		  (*(pd->writefunc))(v, lmagenta, height, 1);		/* Last plane set on light magenta */
		}
	      else
		(*(pd->writefunc))(v, yellow, height, 1);		/* Last plane set on yellow */
	    }
	}
    }
}

static double
get_double_param(stp_vars_t *v, const char *param)
{
  if (param && stp_check_float_parameter(v, param, STP_PARAMETER_ACTIVE))
    return stp_get_float_parameter(v, param);
  else
    return 1.0;
}

static int
pcl_do_print(stp_vars_t *v, stp_image_t *image)
{
  pcl_privdata_t privdata;
  int		status = 1;
  int		model = stp_get_model_id(v);
  const char	*media_size = stp_get_string_parameter(v, "PageSize");
  const char	*media_type = stp_get_string_parameter(v, "MediaType");
  const char	*media_source = stp_get_string_parameter(v, "InputSlot");
  const char	*ink_type = stp_get_string_parameter(v, "InkType");
  const char	*print_mode = stp_get_string_parameter(v, "PrintingMode");
  const char	*duplex_mode = stp_get_string_parameter(v, "Duplex");
  const char    *orientation_mode = stp_get_string_parameter(v, "Orientation");
  const char	*label_separator_mode = stp_get_string_parameter(v, "LabelSeparator");
  int		page_number = stp_get_int_parameter(v, "PageNumber");
  int		printing_color = 0;
  int		top = stp_get_top(v);
  int		left = stp_get_left(v);
  int		y;		/* Looping vars */
  int		xdpi, ydpi;	/* Resolution */
  unsigned char *black,		/* Black bitmap data */
		*cyan,		/* Cyan bitmap data */
		*magenta,	/* Magenta bitmap data */
		*yellow,	/* Yellow bitmap data */
		*lcyan,		/* Light Cyan bitmap data */
		*lmagenta;	/* Light Magenta bitmap data */
  int		page_left,
		page_top,
		page_right,
		page_bottom,
		out_width,	/* Width of image on page */
		out_height,	/* Height of image on page */
		errdiv,		/* Error dividend */
		errmod,		/* Error modulus */
		errval,		/* Current error value */
		errline,	/* Current raster line */
		errlast;	/* Last raster line loaded */
  unsigned	zero_mask;
  int           image_height;
  const pcl_cap_t *caps;		/* Printer capabilities */
  int		planes = 3;	/* # of output planes */
  int		pcl_media_size; /* PCL media size code */
  const double *dot_sizes_use;
  const stp_papersize_t *pp;
  int		the_top_margin,	/* Corrected top margin */
		the_left_margin;	/* Corrected left margin */
  int		manual_feed_left_adjust = 0;
  int		extra_left_margin = 0;
  stp_curve_t   *lum_adjustment;
  stp_curve_t   *hue_adjustment;
  double        density;
  int           label = 0;

  if (!stp_verify(v))
    {
      stp_eprintf(v, "Print options not verified; cannot print.\n");
      return 0;
    }
  if (strcmp(print_mode, "Color") == 0)
    printing_color = 1;

  caps = pcl_get_model_capabilities(model);

 /*
  * Setup a read-only pixel region for the entire image...
  */

  stp_image_init(image);
  image_height = stp_image_height(image);

 /*
  * Figure out the output resolution...
  */

  pcl_describe_resolution(v, &xdpi, &ydpi);

  stp_deprintf(STP_DBG_PCL,"pcl: resolution=%dx%d\n",xdpi,ydpi);
  if (xdpi <= 0 || ydpi <= 0)
    {
      stp_eprintf(v, "No resolution found; cannot print.\n");
      return 0;
    }

 /*
  * Choose the correct color conversion function...
  */
  if (((caps->resolutions & PCL_RES_600_600_MONO) == PCL_RES_600_600_MONO) &&
      printing_color && xdpi == 600 && ydpi == 600)
    {
      stp_eprintf(v, "600x600 resolution only available in MONO\n");
      stp_set_string_parameter(v, "PrintingMode", "BW");
      printing_color = 0;
    }

  privdata.do_cret = (xdpi >= 300 &&
	     ((caps->color_type & PCL_COLOR_CMYK4) == PCL_COLOR_CMYK4));
  privdata.do_cretb = (xdpi >= 600 && ydpi >= 600 &&
	      ((caps->color_type & PCL_COLOR_CMYK4b) == PCL_COLOR_CMYK4b) &&
	      printing_color);
  if (privdata.do_cretb){
    privdata.do_cret = 1;
    dot_sizes_use=dot_sizes_cret;
  }else{
    dot_sizes_use=dot_sizes;
  }

  stp_deprintf(STP_DBG_PCL, "privdata.do_cret = %d\n", privdata.do_cret);
  stp_deprintf(STP_DBG_PCL, "privdata.do_cretb = %d\n", privdata.do_cretb);

  if (ink_type && printing_color)
    privdata.do_6color = (strcmp(ink_type, "Photo") == 0);
  else
    privdata.do_6color = 0;

  stp_deprintf(STP_DBG_PCL, "privdata.do_6color = %d\n", privdata.do_6color);

 /*
  * Compute the output size...
  */

  out_width = stp_get_width(v);
  out_height = stp_get_height(v);

  internal_imageable_area(v, 0, &page_left, &page_right,
			  &page_bottom, &page_top);
  left -= page_left;
  top -= page_top;

  image_height = stp_image_height(image);

 /*
  * Set media size here because it is needed by the margin calculation code.
  */

  if (!media_size)
    media_size = "";
  if (strlen(media_size) == 0 &&
      ((pp = stp_get_papersize_by_size(stp_get_page_height(v),
				       stp_get_page_width(v))) != NULL))
    media_size = pp->name;

  pcl_media_size = pcl_convert_media_size(media_size, model);

  stp_deprintf(STP_DBG_PCL,"pcl_media_size = %d, media_size = %s\n", pcl_media_size, media_size);

 /*
  * If the media size requested is unknown, try it as a custom size.
  *
  * Warning: The margins may need to be fixed for this!
  */

  if (pcl_media_size == -1) {
    stp_deprintf(STP_DBG_PCL, "Paper size %s is not directly supported by printer.\n",
      media_size);
    stp_deprintf(STP_DBG_PCL, "Trying as custom pagesize (watch the margins!)\n");
    pcl_media_size = PCL_PAPERSIZE_CUSTOM;			/* Custom */
  }

  stp_deprintf(STP_DBG_PCL, "Duplex: %s, Page_Number: %d\n", duplex_mode, page_number);
  privdata.duplex=0;
  privdata.tumble=0;

 /*
  * Duplex
  */

  if (duplex_mode)
    {
      if (caps->stp_printer_type & PCL_PRINTER_DUPLEX)
        {
          if ((strcmp(duplex_mode, "DuplexTumble") == 0) || (strcmp(duplex_mode, "DuplexNoTumble") == 0))
            privdata.duplex=1;
          if ((strcmp(duplex_mode, "DuplexTumble") == 0))
            privdata.tumble=1;
        }
    }

 /*
  * Label (PJL) settings and Orientation
  */

  if ((caps->stp_printer_type & PCL_PRINTER_LABEL)) {
    label = 1;
    privdata.orientation = 0;
    if ((strncmp(orientation_mode, "Landscape", 9) == 0))
      privdata.orientation = 1;
    else if ((strncmp(orientation_mode, "UpsideDown", 10) == 0))
      privdata.orientation = 2;
    else if ((strncmp(orientation_mode, "Seascape", 8) == 0))
      privdata.orientation = 3;

  /*
   * Label Separator mode
   */
    privdata.label_separator = 0;
    if ((strncmp(label_separator_mode, "GAP", 3) == 0))
      privdata.label_separator = 1;
    if ((strncmp(label_separator_mode, "TOP", 3) == 0))
      privdata.label_separator = 2;
    if ((strncmp(label_separator_mode, "BOTTOM", 6) == 0))
      privdata.label_separator = 3;
    if ((strncmp(label_separator_mode, "NOTCH", 5) == 0))
      privdata.label_separator = 4;
    if ((strncmp(label_separator_mode, "NONE", 10) == 0))
      privdata.label_separator = 5;
  }


 /*
  * Send PCL initialization commands...
  */

  if ((privdata.duplex == 0) || ((page_number & 1) == 0))
    {
      int pcl_media_type,	/* PCL media type code */
          pcl_media_source;	/* PCL media source code */

      stp_deprintf(STP_DBG_PCL, "Normal init\n");

      if (label)
      {
        if (privdata.do_cretb)
          stp_puts("\033*rbC", v);        /* End raster graphics */
        stp_puts("\033E", v);             /* PCL reset */
        if (privdata.do_cretb)
          stp_zprintf(v, "\033%%-12345X@PJL ENTER LANGUAGE=PCL3GUI\n");

        stp_zprintf(v, "\033%%-12345X@PJL SET RESOLUTION=%d\n"
                       "@PJL SET PAPERWIDTH=%d\n"
                       "@PJL SET PAPERLENGTH=%d\n"
                       "@PJL ENTER LANGUAGE=PCL\n", xdpi, out_width*10,
                       out_height*10);

	if ( privdata.label_separator != 0) {
            stp_zprintf(v, "\033%%-12345X@PJL JOB SETUP = \"ON\" "
                       "NAME = \"JOB_MEDIACONFIG\"\n"
                       "@PJL DEFAULT PAPERSENSORTYPE=%s\n"
                       "@PJL RESET\n@PJL EOJ\n", label_separator_mode);
	}

        stp_zprintf(v, "\033&l%dA", pcl_media_size);      /* Set media size we calculated above */

        stp_zprintf(v, "\033&l%dO", privdata.orientation);
        stp_puts("\033*r0F",v);                   /* Presentation mode */
        stp_puts("\033&l6D\033&k12H",v);          /* 6 lines per inch, 10 chars per inch */
      }
      else
      {
        if (privdata.do_cretb)
          stp_puts("\033*rbC", v);	/* End raster graphics */
        stp_puts("\033E", v); 				/* PCL reset */
        if (privdata.do_cretb)
          stp_zprintf(v, "\033%%-12345X@PJL ENTER LANGUAGE=PCL3GUI\n");

        stp_puts("\033&l6D\033&k12H",v);		/* 6 lines per inch, 10 chars per inch */
        stp_puts("\033&l0O",v);			/* Portrait */

        stp_zprintf(v, "\033&l%dA", pcl_media_size);	/* Set media size we calculated above */
      }

      stp_zprintf(v, "\033&l%dP", stp_get_page_height(v) / 12);
						/* Length of "forms" in "lines" */
      stp_puts("\033&l0L", v);			/* Turn off perforation skip */
      stp_puts("\033&l0E", v);			/* Reset top margin to 0 */

 /*
  * Convert media source string to the code, if specified.
  */

      if (media_source && strlen(media_source) != 0) {
        pcl_media_source = pcl_string_to_val(media_source, pcl_media_sources,
                             sizeof(pcl_media_sources) / sizeof(pcl_t));

        stp_deprintf(STP_DBG_PCL,"pcl_media_source = %d, media_source = %s\n", pcl_media_source,
               media_source);

        if (pcl_media_source == -1)
          stp_deprintf(STP_DBG_PCL, "Unknown media source %s, ignored.\n", media_source);
        else if (pcl_media_source != PCL_PAPERSOURCE_STANDARD) {

/* Correct the value by taking the modulus */

	  if ((pcl_media_source & PAPERSOURCE_ADJ_GUIDE) ==
	      PAPERSOURCE_ADJ_GUIDE)
	    {
	      manual_feed_left_adjust = 1;
	      stp_deprintf(STP_DBG_PCL, "Adjusting left margin for manual feed.\n");
	    }
          pcl_media_source = pcl_media_source % PAPERSOURCE_MOD;
          stp_zprintf(v, "\033&l%dH", pcl_media_source);
        }
      }

 /*
  * Convert media type string to the code, if specified.
  */

      if (media_type && strlen(media_type) != 0) {
        pcl_media_type = pcl_string_to_val(media_type, pcl_media_types,
                           sizeof(pcl_media_types) / sizeof(pcl_t));

        stp_deprintf(STP_DBG_PCL,"pcl_media_type = %d, media_type = %s\n", pcl_media_type,
               media_type);

        if (pcl_media_type == -1) {
          stp_deprintf(STP_DBG_PCL, "Unknown media type %s, set to PLAIN.\n", media_type);
          pcl_media_type = PCL_PAPERTYPE_PLAIN;
        }

/*
 * The HP812C doesn't like glossy paper being selected when using 600x600
 * C-RET (PhotoRET II). So we use Premium paper instead.
 *
 */

        if (privdata.do_cretb && pcl_media_type == PCL_PAPERTYPE_GLOSSY) {
          stp_deprintf(STP_DBG_PCL, "Media type GLOSSY, set to PREMIUM for PhotoRET II.\n");
          pcl_media_type = PCL_PAPERTYPE_PREMIUM;
        }
      }
      else
        pcl_media_type = PCL_PAPERTYPE_PLAIN;

 /*
  * Set DJ print quality to "best" if resolution >= 300
  */

      if ((xdpi >= 300) && ((caps->stp_printer_type & PCL_PRINTER_DJ) == PCL_PRINTER_DJ))
      {
        if ((caps->stp_printer_type & PCL_PRINTER_MEDIATYPE) == PCL_PRINTER_MEDIATYPE)
        {
          stp_puts("\033*o1M", v);			/* Quality = presentation */
          stp_zprintf(v, "\033&l%dM", pcl_media_type);
        }
        else
        {
          stp_puts("\033*r2Q", v);			/* Quality (high) */
          stp_puts("\033*o2Q", v);			/* Shingling (4 passes) */

 /* Depletion depends on media type and cart type. */

          if ((pcl_media_type == PCL_PAPERTYPE_PLAIN)
           || (pcl_media_type == PCL_PAPERTYPE_BOND)) {
            if ((caps->color_type & PCL_COLOR_CMY) == PCL_COLOR_CMY)
              stp_puts("\033*o2D", v);			/* Depletion 25% */
            else
              stp_puts("\033*o5D", v);			/* Depletion 50% with gamma correction */
            }

          else if ((pcl_media_type == PCL_PAPERTYPE_PREMIUM)
                 || (pcl_media_type == PCL_PAPERTYPE_GLOSSY)
                 || (pcl_media_type == PCL_PAPERTYPE_TRANS))
            stp_puts("\033*o1D", v);			/* Depletion none */
        }
      }

/*
 * Duplex
 */

      if (privdata.duplex)
          stp_zprintf(v,"\033&l%dS", privdata.duplex + privdata.tumble);
      }
    else
      {
        stp_deprintf(STP_DBG_PCL, "Back face init\n");
        stp_puts("\033&a2G", v);
      }

/*
 * See if we need to use the CRD (Configure Raster Data) command, because we're
 * doing something interesting on a DeskJet.
 * (I hate long complicated if statements, the compiler will sort it out!).
 */

  privdata.use_crd = 0;
  if ((caps->stp_printer_type & PCL_PRINTER_DJ) == PCL_PRINTER_DJ)
    {
    if (xdpi != ydpi)				/* Different X and Y Resolutions */
      privdata.use_crd = 1;
    if (privdata.do_cret)			/* Resolution Enhancement */
      privdata.use_crd = 1;
    if (privdata.do_6color)			/* Photo Ink printing */
      privdata.use_crd = 1;
    if (privdata.duplex)			/* Duplexing */
      privdata.use_crd = 1;
    }

  if (privdata.use_crd)
						/* Set resolution using CRD */
  {

/*
 * If duplexing on a CRD printer, we need to use the (re)load media command.
 */

    if (privdata.duplex)
      stp_puts("\033&l-2H",v);			/* Load media */

   /*
    * Send configure image data command with horizontal and
    * vertical resolutions as well as a color count...
    */

    if (printing_color)
      if ((caps->color_type & PCL_COLOR_CMY) == PCL_COLOR_CMY)
        planes = 3;
      else
        if (privdata.do_6color)
          planes = 6;
        else
          planes = 4;
    else
      planes = 1;

    stp_zprintf(v, "\033*g%dW", 2 + (planes * 6));
    stp_putc(2, v);				/* Format 2 (Complex Direct Planar) */
    stp_putc(planes, v);				/* # output planes */

    if (planes != 3) {		/* Black resolution */
      stp_send_command(v, "", "HHH", xdpi, ydpi, (privdata.do_cretb || !privdata.do_cret) ? 2 : 4);
    }

    if (planes != 1) {		/* Cyan, magenta, yellow resolutions */
      stp_send_command(v, "", "HHH", xdpi, ydpi, privdata.do_cret ? 4 : 2);
      stp_send_command(v, "", "HHH", xdpi, ydpi, privdata.do_cret ? 4 : 2);
      stp_send_command(v, "", "HHH", xdpi, ydpi, privdata.do_cret ? 4 : 2);
    }
    if (planes == 6)		/* LC, LM resolutions */
    {
      stp_send_command(v, "", "HHH", xdpi, ydpi, privdata.do_cret ? 4 : 2);
      stp_send_command(v, "", "HHH", xdpi, ydpi, privdata.do_cret ? 4 : 2);
    }
  }
  else
  {
    stp_zprintf(v, "\033*t%dR", xdpi);		/* Simple resolution */
    if (printing_color)
    {
      if ((caps->color_type & PCL_COLOR_CMY) == PCL_COLOR_CMY)
        stp_puts("\033*r-3U", v);		/* Simple CMY color */
      else
        stp_puts("\033*r-4U", v);		/* Simple KCMY color */
    }
  }

  if ((caps->stp_printer_type & PCL_PRINTER_TIFF) == PCL_PRINTER_TIFF &&
      !(stp_get_debug_level() & STP_DBG_NO_COMPRESSION))
  {
    stp_puts("\033*b2M", v);			/* Mode 2 (TIFF) */
  }
  else
  {
    stp_puts("\033*b0M", v);			/* Mode 0 (no compression) */
  }

 /*
  * Convert image size to printer resolution and setup the page for printing...
  */

  out_width  = xdpi * out_width / 72;
  out_height = ydpi * out_height / 72;

  if (pcl_media_size == PCL_PAPERSIZE_A4)
  {
    the_left_margin = caps->a4_margins.left_margin;
    the_top_margin = caps->a4_margins.top_margin;
  }
  else
  {
    the_left_margin = caps->normal_margins.left_margin;
    the_top_margin = caps->normal_margins.top_margin;
  }

  stp_deprintf(STP_DBG_PCL, "left %d margin %d top %d margin %d width %d height %d\n",
	  left, the_left_margin, top, the_top_margin, out_width, out_height);

  if (manual_feed_left_adjust)
    {
      unsigned wdelta = caps->custom_max_width - stp_get_page_width(v);
      if (wdelta > 0)
	{
	  /*
	   * Why 3?  I would expect it would be 2 here, but it appears
	   * that at least one printer (LJ 1022) actually partially
	   * adjusts the margin itself.  Adjusting the left margin by 1/3
	   * of the difference between the maximum width and the actual
	   * width experimentally yields correct results -- rlk 20081014
	   */
	  stp_deprintf(STP_DBG_PCL,
		       "  Adjusting manual feed left margin by %d\n", wdelta / 3);
	  extra_left_margin += wdelta / 3;
	}
    }

  if (!privdata.do_cretb) {
    stp_zprintf(v, "\033&a%dH", 10 * (left + extra_left_margin));		/* Set left raster position */
    stp_zprintf(v, "\033&a%dV", 10 * (top + the_top_margin));
				/* Set top raster position */
  }
  stp_zprintf(v, "\033*r%dS", out_width);		/* Set raster width */
  stp_zprintf(v, "\033*r%dT", out_height);	/* Set raster height */

  if (privdata.do_cretb)
    {
      /* Move to top left of printed area */
      stp_zprintf(v, "\033*p%dY", (top + the_top_margin)*4); /* Measured in dots. */
      stp_zprintf(v, "\033*p%dX", (left + extra_left_margin)*4);
    }
  stp_puts("\033*r1A", v); 			/* Start GFX */

 /*
  * Allocate memory for the raster data...
  */

  privdata.height = (out_width + 7) / 8;
  if (privdata.do_cret)
    privdata.height *= 2;

  if (!printing_color)
  {
    black   = stp_malloc(privdata.height);
    cyan    = NULL;
    magenta = NULL;
    yellow  = NULL;
    lcyan    = NULL;
    lmagenta = NULL;
  }
  else
  {
    cyan    = stp_malloc(privdata.height);
    magenta = stp_malloc(privdata.height);
    yellow  = stp_malloc(privdata.height);

    if ((caps->color_type & PCL_COLOR_CMY) == PCL_COLOR_CMY)
      black = NULL;
    else
      black = stp_malloc(privdata.height);
    if (privdata.do_6color)
    {
      lcyan    = stp_malloc(privdata.height);
      lmagenta = stp_malloc(privdata.height);
    }
    else
    {
      lcyan    = NULL;
      lmagenta = NULL;
    }
  }

  if (black)
    {
      if (cyan)
	stp_set_string_parameter(v, "STPIOutputType", "KCMY");
      else
	stp_set_string_parameter(v, "STPIOutputType", "Grayscale");
    }
  else
    stp_set_string_parameter(v, "STPIOutputType", "CMY");

/* Allocate buffer for pcl_mode2 tiff compression */

  if ((caps->stp_printer_type & PCL_PRINTER_TIFF) == PCL_PRINTER_TIFF &&
      !(stp_get_debug_level() & STP_DBG_NO_COMPRESSION))
  {
    privdata.comp_buf = stp_malloc((privdata.height + 128 + 7) * 129 / 128);
    privdata.writefunc = pcl_mode2;
  }
  else
  {
    privdata.comp_buf = NULL;
    privdata.writefunc = pcl_mode0;
  }

/* Set up dithering for special printers. */

#if 1		/* Leave alone for now */
  if (!stp_check_float_parameter(v, "GCRLower", STP_PARAMETER_ACTIVE))
    stp_set_default_float_parameter(v, "GCRLower", .3);
  if (!stp_check_float_parameter(v, "GCRUpper", STP_PARAMETER_ACTIVE))
    stp_set_default_float_parameter(v, "GCRUpper", .999);
#endif
  stp_dither_init(v, image, out_width, xdpi, ydpi);

  if (black)
    {
      stp_dither_add_channel(v, black, STP_ECOLOR_K, 0);
      stp_channel_set_black_channel(v, STP_ECOLOR_K);
    }
  if (cyan)
    stp_dither_add_channel(v, cyan, STP_ECOLOR_C, 0);
  if (lcyan)
    stp_dither_add_channel(v, lcyan, STP_ECOLOR_C, 1);
  if (magenta)
    stp_dither_add_channel(v, magenta, STP_ECOLOR_M, 0);
  if (lmagenta)
    stp_dither_add_channel(v, lmagenta, STP_ECOLOR_M, 1);
  if (yellow)
    stp_dither_add_channel(v, yellow, STP_ECOLOR_Y, 0);

/* Ensure that density does not exceed 1.0 */

  if (!stp_check_float_parameter(v, "Density", STP_PARAMETER_DEFAULTED))
    {
      stp_set_float_parameter_active(v, "Density", STP_PARAMETER_ACTIVE);
      stp_set_float_parameter(v, "Density", 1.0);
    }

  stp_deprintf(STP_DBG_PCL, "Density: %f\n", stp_get_float_parameter(v, "Density"));
  if (stp_get_float_parameter(v, "Density") > 1.0)
    stp_set_float_parameter(v, "Density", 1.0);
  density = stp_get_float_parameter(v, "Density");

  if (privdata.do_cret)			/* 4-level printing for 800/1120 */
    {
      if (yellow)
	stp_dither_set_inks_simple(v, STP_ECOLOR_Y, 3, dot_sizes_use, 1.0, 0.08);
      if (black && !privdata.do_cretb)
        stp_dither_set_inks_simple(v, STP_ECOLOR_K, 3, dot_sizes_use, 1.0, 1.0);

      /* Note: no printer I know of does both CRet (4-level) and 6 color, but
	 what the heck. variable_dither_ranges copied from print-escp2.c */

      if (privdata.do_6color)			/* Photo for 69x */
	{
	  stp_dither_set_inks_full(v, STP_ECOLOR_C, 6, variable_shades, 1.0,
				    0.31 / .5);
	  stp_dither_set_inks_full(v, STP_ECOLOR_M, 6, variable_shades, 1.0,
				    0.61 / .97);
	}
      else
	{
	  if (cyan)
	    stp_dither_set_inks_simple(v, STP_ECOLOR_C, 3, dot_sizes_use, 1.0,
				       0.31 / .5);
	  if (magenta)
	    stp_dither_set_inks_simple(v, STP_ECOLOR_M, 3, dot_sizes_use, 1.0,
				       0.61 / .7);
	}
    }
  else if (privdata.do_6color)
    {
      /* Set light inks for 6 color printers.
	 Numbers copied from print-escp2.c */
      stp_dither_set_inks_full(v, STP_ECOLOR_C, 2, photo_dither_shades, 1.0,
				0.31 / .5);
      stp_dither_set_inks_full(v, STP_ECOLOR_M, 2, photo_dither_shades, 1.0,
				0.61 / .7);
    }
  if (black)
    stp_channel_set_density_adjustment(v, STP_ECOLOR_K, 0,
				       get_double_param(v, "BlackDensity") *
				       density);
  if (cyan)
    stp_channel_set_density_adjustment(v, STP_ECOLOR_C, 0,
				       get_double_param(v, "CyanDensity") *
				       density);
  if (magenta)
    stp_channel_set_density_adjustment(v, STP_ECOLOR_M, 0,
				       get_double_param(v, "MagentaDensity") *
				       density);
  if (yellow)
    stp_channel_set_density_adjustment(v, STP_ECOLOR_Y, 0,
					get_double_param(v, "YellowDensity") *
					density);
  if (lcyan)
    stp_channel_set_density_adjustment
      (v, STP_ECOLOR_C, 1, (get_double_param(v, "CyanDensity") *
			get_double_param(v, "LightCyanTrans") *
			density));
  if (lmagenta)
    stp_channel_set_density_adjustment
      (v, STP_ECOLOR_M, 1, (get_double_param(v, "MagentaDensity") *
			get_double_param(v, "LightMagentaTrans") *
			density));


  if (!stp_check_curve_parameter(v, "HueMap", STP_PARAMETER_ACTIVE))
    {
      hue_adjustment = stp_curve_create_from_string(standard_hue_adjustment);
      stp_set_curve_parameter(v, "HueMap", hue_adjustment);
      stp_curve_destroy(hue_adjustment);
    }
  if (!stp_check_curve_parameter(v, "LumMap", STP_PARAMETER_ACTIVE))
    {
      lum_adjustment = stp_curve_create_from_string(standard_lum_adjustment);
      stp_curve_destroy(lum_adjustment);
    }

  (void) stp_color_init(v, image, 65536);

  errdiv  = image_height / out_height;
  errmod  = image_height % out_height;
  errval  = 0;
  errlast = -1;
  errline  = 0;
  privdata.blank_lines = 0;
#ifndef PCL_DEBUG_DISABLE_BLANKLINE_REMOVAL
  privdata.do_blank = ((caps->stp_printer_type & PCL_PRINTER_BLANKLINE) ==
		       PCL_PRINTER_BLANKLINE);
#else
  privdata.do_blank = 0;
#endif
  stp_allocate_component_data(v, "Driver", NULL, NULL, &privdata);

  for (y = 0; y < out_height; y ++)
  {
    int duplicate_line = 1;
    if (errline != errlast)
    {
      errlast = errline;
      duplicate_line = 0;
      if (stp_color_get_row(v, image, errline, &zero_mask))
	{
	  status = 2;
	  break;
	}
    }
    stp_dither(v, y, duplicate_line, zero_mask, NULL);
    pcl_printfunc(v);
    stp_deprintf(STP_DBG_PCL,"pcl_print: y = %d, line = %d, val = %d, mod = %d, height = %d\n",
		  y, errline, errval, errmod, out_height);
    errval += errmod;
    errline += errdiv;
    if (errval >= out_height)
    {
      errval -= out_height;
      errline ++;
    }
  }

/* Output trailing blank lines (may not be required?) */

  if (privdata.blank_lines > 1)
  {
    privdata.blank_lines--;		/* correct for one already output */
    stp_deprintf(STP_DBG_PCL, "Blank Lines = %d\n", privdata.blank_lines);
    stp_zprintf(v, "\033*b%dY", privdata.blank_lines);
    privdata.blank_lines=0;
  }

  stp_image_conclude(image);

 /*
  * Cleanup...
  */

  if (black != NULL)
    stp_free(black);
  if (cyan != NULL)
  {
    stp_free(cyan);
    stp_free(magenta);
    stp_free(yellow);
  }
  if (lcyan != NULL)
  {
    stp_free(lcyan);
    stp_free(lmagenta);
  }

  if (privdata.comp_buf != NULL)
    stp_free(privdata.comp_buf);

  if ((caps->stp_printer_type & PCL_PRINTER_NEW_ERG) == PCL_PRINTER_NEW_ERG)
    stp_puts("\033*rC", v);
  else
    stp_puts("\033*rB", v);

  if ((privdata.duplex == 1) && ((page_number & 1) == 0))
      stp_puts("\014", v);		/* Form feed */
  else
    {
      stp_puts("\033&l0H", v);		/* Eject page */
      if (privdata.do_cretb)
        stp_zprintf(v, "\033%%-12345X\n");
      stp_puts("\033E", v); 		/* PCL reset */
    }
  return status;
}

static int
pcl_print(const stp_vars_t *v, stp_image_t *image)
{
  int status;
  stp_vars_t *nv = stp_vars_create_copy(v);
  stp_prune_inactive_options(nv);
  status = pcl_do_print(nv, image);
  stp_vars_destroy(nv);
  return status;
}

static const stp_printfuncs_t print_pcl_printfuncs =
{
  pcl_list_parameters,
  pcl_parameters,
  stp_default_media_size,
  pcl_imageable_area,
  pcl_imageable_area,
  pcl_limit,
  pcl_print,
  pcl_describe_resolution,
  pcl_describe_output,
  stp_verify_printer_params,
  NULL,
  NULL,
  NULL
};


/*
 * 'pcl_mode0()' - Send PCL graphics using mode 0 (no) compression.
 */

static void
pcl_mode0(stp_vars_t *v,		/* I - Print file or command */
          unsigned char *line,		/* I - Output bitmap data */
          int           height,		/* I - Height of bitmap data */
          int           last_plane)	/* I - True if this is the last plane */
{
  stp_zprintf(v, "\033*b%d%c", height, last_plane ? 'W' : 'V');
  stp_zfwrite((const char *) line, height, 1, v);
}


/*
 * 'pcl_mode2()' - Send PCL graphics using mode 2 (TIFF) compression.
 */

static void
pcl_mode2(stp_vars_t *v,		/* I - Print file or command */
          unsigned char *line,		/* I - Output bitmap data */
          int           height,		/* I - Height of bitmap data */
          int           last_plane)	/* I - True if this is the last plane */
{
  pcl_privdata_t *privdata =
    (pcl_privdata_t *) stp_get_component_data(v, "Driver");
  unsigned char *comp_buf = privdata->comp_buf;
  unsigned char	*comp_ptr;		/* Current slot in buffer */

  stp_pack_tiff(v, line, height, comp_buf, &comp_ptr, NULL, NULL);

 /*
  * Send a line of raster graphics...
  */

  stp_zprintf(v, "\033*b%d%c", (int)(comp_ptr - comp_buf), last_plane ? 'W' : 'V');
  stp_zfwrite((const char *)comp_buf, comp_ptr - comp_buf, 1, v);
}


static stp_family_t print_pcl_module_data =
  {
    &print_pcl_printfuncs,
    NULL
  };


static int
print_pcl_module_init(void)
{
  return stp_family_register(print_pcl_module_data.printer_list);
}


static int
print_pcl_module_exit(void)
{
  return stp_family_unregister(print_pcl_module_data.printer_list);
}


/* Module header */
#define stp_module_version print_pcl_LTX_stp_module_version
#define stp_module_data print_pcl_LTX_stp_module_data

stp_module_version_t stp_module_version = {0, 0};

stp_module_t stp_module_data =
  {
    "pcl",
    VERSION,
    "PCL family driver",
    STP_MODULE_CLASS_FAMILY,
    NULL,
    print_pcl_module_init,
    print_pcl_module_exit,
    (void *) &print_pcl_module_data
  };