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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>The interface between Ghostscript and device drivers</title>
<!-- $Id$ -->
<!-- Originally: drivers.txt -->
<link rel="stylesheet" type="text/css" href="gs.css" title="Ghostscript Style">
</head>
<body>
<!-- [1.0 begin visible header] ============================================ -->
<!-- [1.1 begin headline] ================================================== -->
<h1>The interface between Ghostscript and device drivers</h1>
<!-- [1.1 end headline] ==================================================== -->
<!-- [1.2 begin table of contents] ========================================= -->
<h2>Table of contents</h2>
<blockquote><ul>
<li><a href="#Adding_drivers">Adding a driver</a>
<li><a href="#KISS">Keeping things simple</a>
<li><a href="#Structure">Driver structure</a>
<ul>
<li><a href="#Structure_definition">Structure definition</a>
<li><a href="#Sophisticated">For sophisticated developers only</a>
</ul>
<li><a href="#coordinates_and_types">Coordinates and types</a>
<ul>
<li><a href="#Coordinate_system">Coordinate system</a>
<li><a href="#Color_definition">Color definition</a>
<ul>
<li><a href="#sep_and_linear_fields">Separable and linear fields</a>
<li><a href="#Changing_color_info_data">Changing color_info data</a>
</ul>
<li><a href="#Types">Types</a>
</ul>
<li><a href="#Coding_conventions">Coding conventions</a>
<ul>
<li><a href="#Allocating_storage">Allocating storage</a>
<li><a href="#Driver_instance_allocation">Driver instance allocation</a>
</ul>
<li><a href="#Printer_drivers">Printer drivers</a>
<li><a href="#Driver_procedures">Driver procedures</a>
<ul>
<li><a href="#Life_cycle">Life cycle</a>
<li><a href="#Open_close">Open, close, sync, copy</a>
<li><a href="#Color_mapping">Color and alpha mapping</a>
<li><a href="#Pixel_level_drawing">Pixel-level drawing</a>
<ul>
<li><a href="#Bitmap_imaging">Bitmap imaging</a>
<li><a href="#Pixmap_imaging">Pixmap imaging</a>
<li><a href="#Compositing">Compositing</a>
[<a href="#S_spec">S</a>, <a href="#T_spec">T</a>, <a href="#F_spec">f</a>,
<a href="#Compositing_notes">Notes</a>]
</ul>
<li><a href="#Polygon_level_drawing">Polygon-level drawing</a>
<li><a href="#Linear_color_drawing">Linear color drawing</a>
<li><a href="#High_level_drawing">High-level drawing</a>
<ul>
<li><a href="#Paths">Paths</a>
<li><a href="#Images">Images</a> [<a href="#Images_notes">Notes</a>]
<li><a href="#Text">Text</a> [<a href="#Text_notes">Notes</a>]
<li><a href="#Unicode">Unicode support for high level devices</a>
</ul>
<li><a href="#Reading_bits_back">Reading bits back</a>
<li><a href="#Parameters">Parameters</a>
<ul>
<li><a href="#Default_CRD_parameters">Default color rendering dictionary (CRD) parameters</a>
</ul>
<li><a href="#External_fonts">External fonts</a>
<li><a href="#Page_devices">Page devices</a>
<li><a href="#Miscellaneous">Miscellaneous</a>
</ul>
<li><a href="#Tray">Tray selection</a>
<ul>
<li><a href="#LeadingEdge">Tray rotation and the LeadingEdge parameter</a>
<li><a href="#LeadingPage">Interaction between LeadingEdge and PageSize</a>
</ul>
</ul></blockquote>
<!-- [1.2 end table of contents] =========================================== -->
<!-- [1.3 begin hint] ====================================================== -->
<p>For other information, see the <a href="Readme.htm">Ghostscript
overview</a> and the documentation on <a href="Make.htm">how to build
Ghostscript</a>.
<!-- [1.3 end hint] ======================================================== -->
<hr>
<!-- [1.0 end visible header] ============================================== -->
<!-- [2.0 begin contents] ================================================== -->
<h2><a name="Adding_drivers"></a>Adding a driver</h2>
<p>
To add a driver to Ghostscript, first pick a name for your device, say
"<code>smurf</code>". (Device names must be 1 to 8 characters, begin
with a letter, and consist only of letters, digits, and underscores. Case
is significant: all current device names are lower case.) Then all you
need do is edit <code>contrib.mak</code> in two places.
<ol>
<li>The list of devices, in the section headed "Catalog". Add
<code>smurf</code> to the list.
<li>The section headed "Device drivers".
<p>
Suppose the files containing the smurf driver are called
"<code>joe</code>" and "<b><tt>fred</tt></b>". Then you should add the
following lines:
<blockquote>
<pre># ------ The SMURF device ------ #
smurf_=$(GLOBJ)joe.$(OBJ) $(GLOBJ)fred.$(OBJ)
$(DD)smurf.dev: $(smurf_)
$(SETDEV) $(DD)smurf $(smurf_)
$(GLOBJ)joe.$(OBJ) : $(GLSRC)joe.c
$(GLCC) $(GLO_)joe.$(OBJ) $(C_) $(GLSRC)joe.c
$(GLOBJ)fred.$(OBJ) : $(GLSRC)fred.c
$(GLCC) $(GLO_)fred.$(OBJ) $(C_) $(GLSRC)fred.c</pre>
</blockquote>
<p>
and whatever <code>joe.c</code> and <b><tt>fred.c</tt></b> depend on.
If the smurf driver also needs special libraries, for instance a library
named "<code>gorf</code>", then the entry should look like this:
<blockquote>
<pre>$(DD)smurf.dev : $(smurf_)
$(SETDEV) $(DD)smurf $(smurf_)
$(ADDMOD) $(DD)smurf -lib gorf</pre>
</blockquote>
<p>
If, as will usually be the case, your driver is a printer driver (as
<a href="#Printer_drivers">discussed below</a>), the device entry should
look like this:
<blockquote>
<pre>$(DD)smurf.dev : $(smurf_) $(GLD)page.dev
$(SETPDEV) $(DD)smurf $(smurf_)</pre>
</blockquote>
<p>
or
<blockquote>
<pre>$(DD)smurf.dev : $(smurf_) $(GLD)page.dev
$(SETPDEV) $(DD)smurf $(smurf_)
$(ADDMOD) $(DD)smurf -lib gorf</pre>
</blockquote>
<p>
Note that the space before the :, and the explicit compilation rules for the
.c files, are required for portability,
</ol>
<hr>
<h2><a name="KISS"></a>Keeping things simple</h2>
<p>
If you want to add a simple device (specifically, a monochrome printer), you
probably don't need to read the rest of this document; just use the code in
an existing driver as a guide. The Epson and Canon BubbleJet drivers <a
href="../base/gdevepsn.c">gdevepsn.c</a> and <a
href="../base/gdevbj10.c">gdevbj10.c</a> are good models for dot-matrix
printers, which require presenting the data for many scan lines at once; the
DeskJet/LaserJet drivers in <a href="../base/gdevdjet.c">gdevdjet.c</a> are
good models for laser printers, which take a single scan line at a time but
support data compression. For color printers, there are unfortunately no
good models: the two major color inkjet printer drivers, <a
href="../base/gdevcdj.c">gdevcdj.c</a> and <a
href="../base/gdevstc.c">gdevstc.c</a>, are far too complex to read.
<p>
On the other hand, if you're writing a driver for some more esoteric
device, you probably do need at least some of the information in the rest
of this document. It might be a good idea for you to read it in
conjunction with one of the existing drivers.
<p>
Duplication of code, and sheer volume of code, is a serious maintenance and
distribution problem for Ghostscript. If your device is similar to an
existing one, try to implement your driver by adding some parameterization
to an existing driver rather than by copying code to create an entirely new
source module. <a href="../base/gdevepsn.c">gdevepsn.c</a> and <a
href="../base/gdevdjet.c">gdevdjet.c</a> are good examples of this approach.
<hr>
<h2><a name="Structure"></a>Driver structure</h2>
<p>
A device is represented by a structure divided into three parts:
<ul>
<li>procedures that are (normally) shared by all instances of each device;
<li>parameters that are present in all devices but may be different for
each device or instance; and
<li>device-specific parameters that may be different for each instance.
</ul>
<p>
Normally the procedure structure is defined and initialized at compile
time. A prototype of the parameter structure (including both generic and
device-specific parameters) is defined and initialized at compile time, but
is copied and filled in when an instance of the device is created. Both of
these structures should be declared as <code>const</code>, but for backward
compatibility reasons the latter is not.
<p>
The <code>gx_device_common</code> macro defines the common structure
elements, with the intent that devices define and export a structure along
the following lines. Do not fill in the individual generic parameter values
in the usual way for C structures: use the macros defined for this purpose
in <a href="../base/gxdevice.h">gxdevice.h</a> or, if applicable, <a
href="../base/gdevprn.h">gdevprn.h</a>.
<blockquote>
<pre>typedef struct smurf_device_s {
gx_device_common;
<b><em>... device-specific parameters ...</em></b>
} smurf_device;
smurf_device gs_smurf_device = {
<b><em>... macro for generic parameter values ...,</em></b>
{ <b><em>... procedures ...</em></b> }, /* std_procs */
<b><em>... device-specific parameter values if any ...</em></b>
};</pre>
</blockquote>
<p>
The device structure instance <b>must</b> have the name
<code>gs_smurf_device</code>, where <b><tt>smurf</tt></b> is the device
name used in <code>contrib.mak</code>. <b><tt>gx_device_common</tt></b>
is a macro consisting only of the element definitions.
<p>
All the device procedures are called with the device as the first argument.
Since each device type is actually a different structure type, the device
procedures must be declared as taking a <code>gx_device *</code> as
their first argument, and must cast it to
<code>smurf_device *</code> internally. For example, in the code
for the "memory" device, the first argument to all routines is called
<code>dev</code>, but the routines actually use <b><tt>mdev</tt></b> to
refer to elements of the full structure, using the following standard
initialization statement at the beginning of each procedure:
<blockquote>
<pre>gx_memory_device *const mdev = (gx_device_memory *)dev;</pre>
</blockquote>
<p>
(This is a cheap version of "object-oriented" programming: in C++, for
example, the cast would be unnecessary, and in fact the procedure table
would be constructed by the compiler.)
<h3><a name="Structure_definition"></a>Structure definition</h3>
<p>
You should consult the definition of struct <code>gx_device_s</code> in
<a href="../base/gxdevice.h">gxdevice.h</a> for the complete details of the
generic device structure. Some of the most important members of this
structure for ordinary drivers are:
<blockquote><table cellpadding=0 cellspacing=0>
<tr valign=top> <td><code>const char *dname;</code>
<td>
<td>The device name
<tr valign=top> <td><code>bool is_open;</code>
<td>
<td>True if device has been opened
<tr valign=top> <td><code>gx_device_color_info color_info;</code>
<td>
<td>Color information
<tr valign=top> <td><code>int width;</code>
<td>
<td>Width in pixels
<tr valign=top> <td><code>int height;</code>
<td>
<td>Height in pixels
</table></blockquote>
<p>
The name in the structure (<code>dname</code>) should be the same as the
name in <a href="../base/contrib.mak">contrib.mak</a>.
<h3><a name="Sophisticated"></a>For sophisticated developers only</h3>
<p>
If for any reason you need to change the definition of the basic device
structure, or to add procedures, you must change the following places:
<blockquote><ul>
<li>This document and the <a href="News.htm">news document</a> (if you want
to keep the documentation up to date).
<li>The definition of <code>gx_device_common</code> and the procedures
in <a href="../base/gxdevcli.h">gxdevcli.h</a>.
<li>Possibly, the default forwarding procedures declared in
<a href="../base/gxdevice.h">gxdevice.h</a> and implemented in
<a href="../base/gdevnfwd.c">gdevnfwd.c</a>.
<li>The device procedure record completion routines in
<a href="../base/gdevdflt.c">gdevdflt.c</a>.
<li>Possibly, the default device implementation in
<a href="../base/gdevdflt.c">gdevdflt.c</a>,
<a href="../base/gdevddrw.c">gdevddrw.c</a>, and
<a href="../base/gxcmap.c">gxcmap.c</a>.
<li>The bounding box device in <a href="../base/gdevbbox.c">gdevbbox.c</a>
(probably just adding <code>NULL</code> procedure entries if the
new procedures don't produce output).
<li>These devices that must have complete (non-defaulted) procedure vectors:
<ul>
<li>The null device in <a href="../base/gdevnfwd.c">gdevnfwd.c</a>.
<li>The command list "device" in <a href="../base/gxclist.c">gxclist.c</a>.
This is not an actual device; it only defines procedures.
<li>The "memory" devices in <a href="../base/gdevmem.h">gdevmem.h</a> and
<code>gdevm*.c</code>.
</ul>
<li>The clip list accumulation "device" in
<a href="../base/gxacpath.c">gxacpath.c</a>.
<li>The clipping "devices" <a href="../base/gxclip.c">gxclip.c</a>,
<a href="../base/gxclip2.c">gxclip2.c</a>,
and <a href="../base/gxclipm.c">gxclipm.c</a>.
<li>The pattern accumulation "device" in
<a href="../base/gxpcmap.c">gxpcmap.c</a>.
<li>The hit detection "device" in <a href="../base/gdevhit.c">gdevhit.c</a>.
<li>The generic printer device macros in
<a href="../base/gdevprn.h">gdevprn.h</a>.
<li>The generic printer device code in
<a href="../base/gdevprn.c">gdevprn.c</a>.
<li>The RasterOp source device in
<a href="../base/gdevrops.c">gdevrops.c</a>.
</ul></blockquote>
<p>
You may also have to change the code for
<code>gx_default_get_params</code> or
<code>gx_default_put_params</code> in <a
href="../base/gsdparam.c">gsdparam.c</a>.
<p>
You should not have to change any of the real devices in the standard
Ghostscript distribution (listed in <a href="../base/devs.mak">devs.mak</a>
and <a href="../base/contrib.mak">contrib.mak</a>) or any of your own
devices, because all of them are supposed to use the macros in <a
href="../base/gxdevice.h">gxdevice.h</a> or <a
href="../base/gdevprn.h">gdevprn.h</a> to define and initialize their state.
<hr>
<h2><a name="coordinates_and_types"></a>Coordinates and types</h2>
<h3><a name="Coordinate_system"></a>Coordinate system</h3>
<p>
Since each driver specifies the initial transformation from user
coordinates to device coordinates, the driver can use any coordinate system
it wants, as long as a device coordinate will fit in an
<code>int</code>. (This is only an issue on DOS systems, where ints are
only 16 bits. User coordinates are represented as floats.) Most current
drivers use a coordinate system with (0,0) in the upper left corner, with
<b><em>X</em></b> increasing to the right and <b><em>Y</em></b> increasing
toward the bottom. However, there is supposed to be nothing in the rest of
Ghostscript that assumes this, and indeed some drivers use a coordinate
system with (0,0) in the lower left corner.
<p>
Drivers must check (and, if necessary, clip) the coordinate parameters given
to them: they should not assume the coordinates will be in bounds. The
<code>fit_fill</code> and <b><tt>fit_copy</tt></b> macros in <a
href="../base/gxdevice.h">gxdevice.h</a> are very helpful in doing this.
<h3><a name="Color_definition"></a>Color definition</h3>
<p>
Between the Ghostscript graphics library and the device, colors are
represented in three forms. Color components in a color space (Gray, RGB,
DeviceN, etc.) represented as <code>frac</code> values. Device colorants
are represented as <code>gx_color_value</code> values. For many
procedures, colors are represented in a type called
<code>gx_color_index</code>.
All three types are described in more detail in <a href="#Types">Types</a>
<p>
The <code>color_info</code> member of the device structure defines the
color and gray-scale capabilities of the device. Its type is defined as
follows:
<blockquote>
<pre>
/*
* The enlarged color model information structure: Some of the
* information that was implicit in the component number in
* the earlier conventions (component names, polarity, mapping
* functions) are now explicitly provided.
*
* Also included is some information regarding the encoding of
* color information into gx_color_index. Some of this information
* was previously gathered indirectly from the mapping
* functions in the existing code, specifically to speed up the
* halftoned color rendering operator (see
* gx_dc_ht_colored_fill_rectangle in gxcht.c). The information
* is now provided explicitly because such optimizations are
* more critical when the number of color components is large.
*
* Note: no pointers have been added to this structure, so there
* is no requirement for a structure descriptor.
*/
typedef struct gx_device_color_info_s {
/*
* max_components is the maximum number of components for all
* color models supported by this device. This does not include
* any alpha components.
*/
int max_components;
/*
* The number of color components. This does not include any
* alpha-channel information, which may be integrated into
* the gx_color_index but is otherwise passed as a separate
* component.
*/
int num_components;
/*
* Polarity of the components of the color space, either
* additive or subtractive. This is used to interpret transfer
* functions and halftone threshold arrays. Possible values
* are GX_CM_POLARITY_ADDITIVE or GX_CM_POLARITY_SUBTRACTIVE
*/
gx_color_polarity_t polarity;
/*
* The number of bits of gx_color_index actually used.
* This must be <= sizeof(gx_color_index), which is usually 64.
*/
byte depth;
/*
* Index of the gray color component, if any. The max_gray and
* dither_gray values apply to this component only; all other
* components use the max_color and dither_color values.
*
* This will be GX_CINFO_COMP_NO_INDEX if there is no gray
* component.
*/
byte gray_index;
/*
* max_gray and max_color are the number of distinct native
* intensity levels, less 1, for the gray and all other color
* components, respectively. For nearly all current devices
* that support both gray and non-gray components, the two
* parameters have the same value.
*
* dither_grays and dither_colors are the number of intensity
* levels between which halftoning can occur, for the gray and
* all other color components, respectively. This is
* essentially redundant information: in all reasonable cases,
* dither_grays = max_gray + 1 and dither_colors = max_color + 1.
* These parameters are, however, extensively used in the
* current code, and thus have been retained.
*
* Note that the non-gray values may now be relevant even if
* num_components == 1. This simplifies the handling of devices
* with configurable color models which may be set for a single
* non-gray color model.
*/
gx_color_value max_gray; /* # of distinct color levels -1 */
gx_color_value max_color;
gx_color_value dither_grays;
gx_color_value dither_colors;
/*
* Information to control super-sampling of objects to support
* anti-aliasing.
*/
gx_device_anti_alias_info anti_alias;
/*
* Flag to indicate if gx_color_index for this device may be divided
* into individual fields for each component. This is almost always
* the case for printers, and is the case for most modern displays
* as well. When this is the case, halftoning may be performed
* separately for each component, which greatly simplifies processing
* when the number of color components is large.
*
* If the gx_color_index is separable in this manner, the comp_shift
* array provides the location of the low-order bit for each
* component. This may be filled in by the client, but need not be.
* If it is not provided, it will be calculated based on the values
* in the max_gray and max_color fields as follows:
*
* comp_shift[num_components - 1] = 0,
* comp_shift[i] = comp_shift[i + 1]
* + ( i == gray_index ? ceil(log2(max_gray + 1))
* : ceil(log2(max_color + 1)) )
*
* The comp_mask and comp_bits fields should be left empty by the client.
* They will be filled in during initialization using the following
* mechanism:
*
* comp_bits[i] = ( i == gray_index ? ceil(log2(max_gray + 1))
* : ceil(log2(max_color + 1)) )
*
* comp_mask[i] = (((gx_color_index)1 << comp_bits[i]) - 1)
* << comp_shift[i]
*
* (For current devices, it is almost always the case that
* max_gray == max_color, if the color model contains both gray and
* non-gray components.)
*
* If separable_and_linear is not set, the data in the other fields
* is unpredictable and should be ignored.
*/
gx_color_enc_sep_lin_t separable_and_linear;
byte comp_shift[GX_DEVICE_COLOR_MAX_COMPONENTS];
byte comp_bits[GX_DEVICE_COLOR_MAX_COMPONENTS];
gx_color_index comp_mask[GX_DEVICE_COLOR_MAX_COMPONENTS];
/*
* Pointer to name for the process color model.
*/
const char * cm_name;
} gx_device_color_info;
</pre>
</blockquote>
<p>
Note: See <a href="#Changing_color_info_data">Changing color_info data</a> before changing
any information in the <code>color_info structure</code> for a device.
<p>
It is recommended that the values for this structure be defined using one
of the standard macros provided for this purpose. This allows for future
changes to be made to the structure without changes being required in the
actual device code.
<p>
The following macros (in <a href="../base/gxdevcli.h">gxdevcli.h</a>) provide
convenient shorthands for initializing this structure for ordinary
black-and-white or color devices:
<blockquote>
<code>#define dci_black_and_white</code> ...<br>
<code>#define dci_color(depth,maxv,dither)</code> ...
</blockquote>
<p>
The <code>#define dci_black_and_white</code> macro defines a
single bit monochrome device (For example: a typical monochrome printer device.)
<p>
The <code>#define dci_color(depth,maxv,dither)</code> macro can be used
to define a 24 bit RGB device or a 4 or 32 bit CMYK device.
<p>
The <code>#define dci_extended_alpha_values</code> macro (in
<a href="../base/gxdevcli.h">gxdevcli.h</a>)
specifies most of the current fields in the structure. However this macro allows
only the default setting for the comp_shift, comp_bits, and comp_mask fields
to be set. Any device which requires a non-default setting for these fields
has to correctly these fields during the device open procedure.
See
<a href="#sep_and_linear_fields">Separable and linear fields></a> and
<a href="#Changing_color_info_data">Changing color_info data</a>.
<p>
The idea is that a device has a certain number of gray levels
(<code>max_gray</code>+1) and a certain number of colors
(<code>max_rgb</code>+1) that it can produce directly. When Ghostscript
wants to render a given color space color value as a device color, it first tests
whether the color is a gray level and if so:
<blockquote>
If <code>max_gray</code> is large (>= 31), Ghostscript asks the
device to approximate the gray level directly. If the device returns a
valid <code>gx_color_index</code>, Ghostscript uses it. Otherwise,
Ghostscript assumes that the device can represent
<code>dither_gray</code> distinct gray levels, equally spaced along the
diagonal of the color cube, and uses the two nearest ones to the desired
color for halftoning.
</blockquote>
<p>
If the color is not a gray level:
<blockquote>
If <code>max_rgb</code> is large (>= 31), Ghostscript asks the device
to approximate the color directly. If the device returns a valid
<code>gx_color_index</code>, Ghostscript uses it. Otherwise,
Ghostscript assumes that the device can represent
<blockquote>
<code>dither_rgb</code> × <b><tt>dither_rgb</tt></b> × <b><tt>dither_rgb</tt></b>
</blockquote>
<p>
distinct colors, equally spaced throughout the color cube, and uses two of
the nearest ones to the desired color for halftoning.
</blockquote>
<h4><a name="sep_and_linear_fields"></a>Separable and linear fields</h4>
<p>
The three fields <code>comp_shift</code>, <b><tt>comp_bits</tt></b>, and
<code>comp_mask</code> are only used if the <b><tt>separable_and_linear</tt></b>
field is set to <code>GX_CINFO_SEP_LIN</code>. In this situation a <b><tt>gx_color_index</tt></b>
value must represent a combination created by or'ing bits for each of the devices's
output colorants. The <code>comp_shift</code> array defines the location
(shift count) of each colorants bits in the output gx_color_index value. The
<code>comp_bits</code> array defines the number of bits for each colorant.
The <code>comp_mask</code> array contains a mask which can be used to isolate
the bits for each colorant. These fields must be set if the device supports
more than four colorants.
<h4><a name="Changing_color_info_data"></a>Changing color_info data</h4>
<p> For most devices, the information in the device's <code>color_info</code>
structure is defined by the various device definition macros and the data remains
constant during the entire existence of the device. In general the Ghostscript
graphics assumes that the information is constant. However some devices want
to modify the data in this structure.
<p>
The device's <code>put_params</code> procedure may change
<code>color_info</code> field values.
After the data has been modified then the
device should be closed (via a call to <code>gs_closedevice</code>). Closing
the device will erase the current page so these changes should only be made
before anything has been drawn on a page.
<p> The device's <code>open_device</code> procedure may change
<code>color_info</code> field values. These changes should be done before
any other procedures are called.
<p>
The Ghostscript graphics library
uses some of the data in <code>color_info</code> to set the default
procedures for the
<code>get_color_mapping_procs</code>,
<code>get_color_comp_index</code>,
<code>encode_color</code>, and
<code>decode_color</code> procedures.
These default procedures are set when the
device is originally created. If any changes are made to the
<code>color_info</code> fields then the device's <code>open_device</code>
procedure
has responsibility for insuring that the correct procedures are contained
in the device structure. (For an example, see the display device open procedure
<code>display_open</code> and its subroutine
<code>display_set_color_format</code>
(in <a href="../base/gdevdisp.c">gdevdisp</a>).
<h3><a name="Types"></a>Types</h3>
<p>
Here is a brief explanation of the various types that appear as parameters
or results of the drivers.
<dl>
<dt><code>frac</code> (defined in <a href="../base/gxfrac.h">gxfrac.h</a>)
<dd>This is the type used to represent color values for the input to the
color model mapping procedures. It is currently defined as a short. It has a
range of <code>frac_0</code> to <b><tt>frac_1</tt></b>.
</dl>
<dl>
<dt><code>gx_color_value</code> (defined in
<a href="../base/gxdevice.h">gxdevice.h</a>)
<dd>This is the type used to represent RGB or CMYK color values. It is
currently equivalent to unsigned short. However, Ghostscript may use less
than the full range of the type to represent color values:
<code>gx_color_value_bits</code> is the number of bits actually used,
and <code>gx_max_color_value</code> is the maximum value, equal to
(2^<small><sup><code>gx_max_color_value_bits</code></sup></small>)-1.
</dl>
<dl>
<dt><code>gx_device</code> (defined in
<a href="../base/gxdevice.h">gxdevice.h</a>)
<dd>This is the device structure, as explained above.
</dl>
<dl>
<dt><code>gs_matrix</code> (defined in
<a href="../base/gsmatrix.h">gsmatrix.h</a>)
<dd>This is a 2-D homogeneous coordinate transformation matrix, used by
many Ghostscript operators.
</dl>
<dl>
<dt><code>gx_color_index</code> (defined in
<a href="../base/gxcindex.h">gxcindex.h</a>)
<dd>This is meant to be whatever the driver uses to represent a device
color. For example, it might be an index in a color map, or it might be R,
G, and B values packed into a single integer. The Ghostscript graphics library
gets <code>gx_color_index</code> values from the device's
<code>encode_color</code> and hands them back as arguments to several other
procedures. If the <code>separable_and_linear</code> field in the device's
<code>color_info</code> structure is not set to
<code>GX_CINFO_SEP_LIN</code> then Ghostscript does not do
any computations with <code>gx_color_index</code> values.
<p>
The special
value <code>gx_no_color_index</code> (defined as
<code>(~(gx_color_index)(0))</code> ) means "transparent" for some of
the procedures.
<p>
The size of <code>gx_color_index</code> can be either 32 or 64 bits. The
choice depends upon the architecture of the CPU and the compiler. The default
type definition is simply:
<blockquote><code>
typedef unsigned long gx_color_index;
</code></blockquote>
However if <code>GX_COLOR_INDEX_TYPE</code> is defined, then it is used
as the type for <code>gx_color_index</code>.
<blockquote><code>
typedef GX_COLOR_INDEX_TYPE gx_color_index;
</code></blockquote>
The smaller size (32 bits) may produce more efficient or faster executing
code. The larger size (64 bits) is needed for representing either more
bits per component or more components. An example of the later case is
a device that supports 8 bit contone colorants using a DeviceCMYK process
color model with its four colorants and also supports additional spot
colorants.
<p>
Currently autoconf attempts to find a 64 bit type definition for the
compiler being used, and if a 64 bit type is found then
<code>GX_COLOR_INDEX_TYPE</code> is set to the type.
<p>
For Microsoft and the MSVC compiler, <code>GX_COLOR_INDEX_TYPE</code> will
be set to <code>unsigned _int64</code> if <b><tt>USE_LARGE_COLOR_INDEX</tt></b>
is set to 1 either on the make command line or by editing the definition
in <a href="../psi/msvc32.mak">msvc32.mak</a>
</dl>
<dl>
<dt><code>gs_param_list</code> (defined in <a
href="../base/gsparam.h">gsparam.h</a>)
<dd>This is a parameter list, which is used to read and set attributes in a
device. See the comments in <a href="../base/gsparam.h">gsparam.h</a>, and
the <a href="#Parameters">description of the <code>get_params</code> and
<code>put_params</code> procedures</a> below, for more detail.
</dl>
<dl>
<dt><code>gx_tile_bitmap</code> (defined in
<a href="../base/gxbitmap.h">gxbitmap.h</a>)
<br><code>gx_strip_bitmap</code> (defined in
<a href="../base/gxbitmap.h">gxbitmap.h</a>)
<dd>These structure types represent bitmaps to be used as a tile for
filling a region (rectangle). <code>gx_tile_bitmap</code> is an
older, deprecated type lacking <code>shift</code> and
<code>rep_shift</code>;
<code>gx_strip_bitmap</code> has superseded it, and should be
used in new code. Here is a copy of the relevant part of the file:
<blockquote>
<pre>
/*
* Structure for describing stored bitmaps.
* Bitmaps are stored bit-big-endian (i.e., the 2^7 bit of the first
* byte corresponds to x=0), as a sequence of bytes (i.e., you can't
* do word-oriented operations on them if you're on a little-endian
* platform like the Intel 80x86 or VAX). Each scan line must start on
* a (32-bit) word boundary, and hence is padded to a word boundary,
* although this should rarely be of concern, since the raster and width
* are specified individually. The first scan line corresponds to y=0
* in whatever coordinate system is relevant.
*
* For bitmaps used as halftone tiles, we may replicate the tile in
* X and/or Y, but it is still valuable to know the true tile dimensions
* (i.e., the dimensions prior to replication). Requirements:
* width % rep_width = 0
* height % rep_height = 0
*
* For halftones at arbitrary angles, we provide for storing the halftone
* data as a strip that must be shifted in X for different values of Y.
* For an ordinary (non-shifted) halftone that has a repetition width of
* W and a repetition height of H, the pixel at coordinate (X,Y)
* corresponds to halftone pixel (X mod W, Y mod H), ignoring phase;
* for a shifted halftone with shift S, the pixel at (X,Y) corresponds
* to halftone pixel ((X + S * floor(Y/H)) mod W, Y mod H). Requirements:
* strip_shift < rep_width
* strip_height % rep_height = 0
* shift = (strip_shift * (size.y / strip_height)) % rep_width
*/
typedef struct gx_strip_bitmap_s {
byte *data;
int raster; /* bytes per scan line */
gs_int_point size; /* width, height */
gx_bitmap_id id;
ushort rep_width, rep_height; /* true size of tile */
ushort strip_height;
ushort strip_shift;
ushort shift;
} gx_strip_bitmap;</pre>
</blockquote>
</dl>
<hr>
<h2><a name="Coding_conventions"></a>Coding conventions</h2>
<p>
All the driver procedures defined below that return <code>int</code>
results return 0 on success, or an appropriate negative error code in the
case of error conditions. The error codes are defined in <a
href="../base/gserrors.h">gserrors.h</a>; they correspond directly to the
errors defined in the PostScript language reference manuals. The most
common ones for drivers are:
<blockquote><dl>
<dt><code>gs_error_invalidfileaccess</code>
<dd>An attempt to open a file failed.
<dt><code>gs_error_ioerror</code>
<dd>An error occurred in reading or writing a file.
<dt><code>gs_error_limitcheck</code>
<dd>An otherwise valid parameter value was too large for the
implementation.
<dt><code>gs_error_rangecheck</code>
<dd>A parameter was outside the valid range.
<dt><code>gs_error_VMerror</code>
<dd>An attempt to allocate memory failed. (If this happens, the procedure
should release all memory it allocated before it returns.)
</dl></blockquote>
<p>
If a driver does return an error, rather than a simple return statement it
should use the <code>return_error</code> macro defined in <a
href="../base/gx.h">gx.h</a>, which is automatically included by <a
href="../base/gdevprn.h">gdevprn.h</a> but not by <a
href="../base/gserrors.h">gserrors.h</a>. For example
<blockquote>
<code> return_error(gs_error_VMerror);
</code></blockquote>
<h3><a name="Allocating_storage"></a>Allocating storage</h3>
<p>
While most drivers (especially printer drivers) follow a very similar
template, there is one important coding convention that is not obvious from
reading the code for existing drivers: driver procedures must not use
<code>malloc</code> to allocate any storage that stays around after the
procedure returns. Instead, they must use <code>gs_malloc</code> and
<code>gs_free</code>, which have slightly different calling conventions.
(The prototypes for these are in <a href="../base/gsmemory.h">gsmemory.h</a>,
which is included in <a href="../base/gx.h">gx.h</a>, which is included in <a
href="../base/gdevprn.h">gdevprn.h</a>.) This is necessary so that
Ghostscript can clean up all allocated memory before exiting, which is
essential in environments that provide only single-address-space
multi-tasking (some versions of Microsoft Windows).
<blockquote>
<pre>char *gs_malloc(uint num_elements, uint element_size,
const char *client_name);</pre>
</blockquote>
<p>
Like <code>calloc</code>, but unlike <b><tt>malloc</tt></b>,
<code>gs_malloc</code> takes an element count and an element size. For
structures, <code>num_elements</code> is 1 andi
<code>element_size</code> is <b><tt>sizeof</tt></b> the structure; for
byte arrays, <code>num_elements</code> is the number of bytes and
<code>element_size</code> is 1. Unlike <b><tt>calloc</tt></b>,
<code>gs_malloc</code> does <b>not</b> clear the block of storage.
<p>
The <code>client_name</code> is used for tracing and debugging. It must
be a real string, not <code>NULL</code>. Normally it is the name of the
procedure in which the call occurs.
<blockquote>
<pre>void gs_free(char *data, uint num_elements, uint element_size,
const char *client_name);</pre>
</blockquote>
<p>
Unlike <code>free</code>, <b><tt>gs_free</tt></b> demands that
<code>num_elements</code> and element_size be supplied. It also
requires a client name, like <code>gs_malloc</code>.
<h3><a name="Driver_instance_allocation"></a>Driver instance allocation</h3>
<p>
All driver instances allocated by Ghostscript's standard allocator must
point to a "structure descriptor" that tells the garbage collector how to
trace pointers in the structure. For drivers registered in the normal way
(using the makefile approach described above), no special care is needed as
long as instances are created only by calling the
<code>gs_copydevice</code> procedure defined in <a
href="../base/gsdevice.h">gsdevice.h</a>. If you have a need to define
devices that are not registered in this way, you must fill in the stype
member in any dynamically allocated instances with a pointer to the same
structure descriptor used to allocate the instance. For more information
about structure descriptors, see <a href="../base/gsmemory.h">gsmemory.h</a>
and <a href="../base/gsstruct.h">gsstruct.h</a>.
<hr>
<h2><a name="Printer_drivers"></a>Printer drivers</h2>
<p>
Printer drivers (which include drivers that write some kind of raster file)
are especially simple to implement.
The printer driver must implement a <code>print_page</code> or
<code>print_page_copies</code> procedure. There are macros in <a
href="../base/gdevprn.h">gdevprn.h</a> that generate the device structure for
such devices, of which the simplest is <code>prn_device</code>; for an
example, see <a href="../base/gdevbj10.c">gdevbj10.c</a>. If you are writing
a printer driver, we suggest you start by reading <a
href="../base/gdevprn.h">gdevprn.h</a> and the <a
href="#Color_mapping">subsection on "Color mapping"</a> below; you may be
able to ignore all the rest of the driver procedures.
<p>
The <code>print_page</code> procedures are defined as follows:
<blockquote>
<pre>int (*print_page)(gx_device_printer *, FILE *)
int (*print_page_copies)(gx_device_printer *, FILE *, int)</pre>
</blockquote>
<p>
This procedure must read out the rendered image from the device and write
whatever is appropriate to the file. To read back one or more scan lines
of the image, the <code>print_page</code> procedure must call one of the
following procedures:
<blockquote>
<pre>int gdev_prn_copy_scan_lines(gx_device_printer *pdev, int y, byte *str,
uint size)</pre>
</blockquote>
<p>
For this procedure, <code>str</code> is where the data should be copied to, and <b><tt>size</tt></b> is
the size of the buffer starting at <code>str</code>. This procedure returns the number
of scan lines copied, or <0 for an error. <code>str</code> need not be aligned.
<blockquote>
<pre>int gdev_prn_get_bits(gx_device_printer *pdev, int y, byte *str,
byte **actual_data)</pre>
</blockquote>
<p>
This procedure reads out exactly one scan line. If the scan line is
available in the correct format already, <code>*actual_data</code> is
set to point to it; otherwise, the scan line is copied to the buffer
starting at <code>str</code>, and <b><tt>*actual_data</tt></b> is set to
<code>str</code>. This saves a copying step most of the time.
<code>str</code> need not be aligned; however, if
<code>*actual_data</code> is set to point to an existing scan line, it
will be aligned. (See the description of the <code>get_bits</code>
procedure below for more details.)
<p>
In either case, each row of the image is stored in the form described in
the comment under <code>gx_tile_bitmap</code> above; each pixel takes
the number of bits specified as <code>color_info.depth</code> in the
device structure, and holds values returned by the device's
<code>encode_color</code> procedure.
<p>
The <code>print_page</code> procedure can determine the number of bytes
required to hold a scan line by calling:
<blockquote>
<pre>uint gdev_prn_raster(gx_device_printer *)</pre>
</blockquote>
<p>
For a very simple concrete example, we suggest reading the code in
<code>bit_print_page</code> in <a href="../base/gdevbit.c">gdevbit.c</a>.
<p>
If the device provides <code>print_page</code>, Ghostscript will call
<code>print_page</code> the requisite number of times to print the
desired number of copies; if the device provides
<code>print_page_copies</code>, Ghostscript will call
<code>print_page_copies</code> once per page, passing it the desired
number of copies.
<hr>
<h2><a name="Driver_procedures"></a>Driver procedures</h2>
<p>
Most of the procedures that a driver may implement are optional. If a
device doesn't supply an optional procedure <code>WXYZ</code>, the entry
in the procedure structure may be either <code>gx_default_WXYZ</code>,
for instance <code>gx_default_tile_rectangle</code>, or
<code>NULL</code> or 0. (The device procedure must also call the
<code>gx_default_</code> procedure if it doesn't implement the function
for particular values of the arguments.) Since C compilers supply 0 as the
value for omitted structure elements, this convention means that statically
initialized procedure structures continue to work even if new (optional)
members are added.
<h3><a name="Life_cycle"></a>Life cycle</h3>
<p>
A device instance begins life in a closed state. In this state, no output
operations will occur. Only the following procedures may be called:
<blockquote><code>
open_device<br>
finish_copydevice<br>
get_initial_matrix<br>
get_params<br>
put_params<br>
get_hardware_params
</code></blockquote>
<p>
When <code>setdevice</code> installs a device instance in the graphics
state, it checks whether the instance is closed or open. If the instance
is closed, <code>setdevice</code> calls the open routine, and then sets
the state to open.
<p>
There is no user-accessible operation to close a device instance. This is
not an oversight -- it is required in order to enforce the following
invariant:
<blockquote>
If a device instance is the current device in <em>any</em> graphics state,
it must be open (have <code>is_open</code> set to true).
</blockquote>
<p>
Device instances are only closed when they are about to
be freed, which occurs in three situations:
<ul>
<li>When a <code>restore</code> occurs, if the instance was created since
the corresponding <code>save</code> and is in a VM being restored. I.e.,
if the instance was created in local VM since a <code>save</code>, it
will always be closed and freed by the corresponding
<code>restore</code>; if it was created in global VM, it will only be
closed by the outermost <code>restore</code>, regardless of the save
level at the time the instance was created.
<li>By the garbage collector, if the instance is no longer accessible.
<li>When Ghostscript exits (terminates).
</ul>
<h3><a name="Open_close"></a>Open, close, sync, copy</h3>
<dl>
<dt><code>int (*open_device)(gx_device *)</code> <b><em>[OPTIONAL]</em></b>
<dd>Open the device: do any initialization associated with making the device
instance valid. This must be done before any output to the device. The
default implementation does nothing. <b>NOTE</b>: Clients should never call
a device's <code>open_device</code> procedure directly: they should
always call <code>gs_opendevice</code> instead.
</dl>
<dl>
<dt><code>int (*finish_copydevice)(gx_device *dev, const gx_device
*from_dev)</code> <b><em>[OPTIONAL]</em></b> <dd>Perform any cleanup
required after <code>copydevice</code> has created a new device instance
by copying <code>from_dev</code>. If the copy operation should not be
allowed, this procedure should return an error; the copy will be freed. The
default implementation allows copying the device prototype, but does not
allow copying device instances, because instances may contain internal
pointers that should not be shared between copies, and there is no way to
determine this from outside the device. <b>NOTE</b>: Clients should never
call a device's <code>finish_copydevice</code> procedure: this procedure
is only intended for use by <code>gs_copydevice[2]</code>.
</dl>
<dl>
<dt><code>void (*get_initial_matrix)(gx_device *, gs_matrix *)</code> <b><em>[OPTIONAL]</em></b>
<dd>Construct the initial transformation matrix mapping user coordinates
(nominally 1/72 inch per unit) to device coordinates. The default
procedure computes this from width, height, and
[<code>xy</code>]<b><tt>_pixels_per_inch</tt></b> on the assumption that
the origin is in the upper left corner, that is
<blockquote>
<code>xx</code> = <b><tt>x_pixels_per_inch</tt></b>/72, <b><tt>xy</tt></b> = 0,<br>
<code>yx = 0, yy = -y_pixels_per_inch</code>/72,<br>
<code>tx = 0, ty = height</code>.
</blockquote>
</dl>
<dl>
<dt><code>int (*sync_output)(gx_device *)</code> <b><em>[OPTIONAL]</em></b>
<dd>Synchronize the device. If any output to the device has been
buffered, send or write it now. Note that this may be called several times
in the process of constructing a page, so printer drivers should <b>not</b>
implement this by printing the page. The default implementation does
nothing.
</dl>
<dl>
<dt><code>int (*output_page)(gx_device *, int num_copies, int flush)</code> <b><em>[OPTIONAL]</em></b>
<dd>Output a fully composed page to the device. The
<code>num_copies</code> argument is the number of copies that should be
produced for a hardcopy device. (This may be ignored if the driver has
some other way to specify the number of copies.) The <code>flush</code>
argument is true for <code>showpage</code>, false for
<code>copypage</code>. The default definition just calls
<code>sync_output</code>. Printer drivers should implement this by
printing and ejecting the page.
</dl>
<dl>
<dt><code>int (*close_device)(gx_device *)</code> <b><em>[OPTIONAL]</em></b>
<dd>Close the device: release any associated resources. After this, output
to the device is no longer allowed. The default implementation does
nothing. <b>NOTE</b>: Clients should never call a device's
<code>close_device</code> procedure directly: they should always call
<code>gs_closedevice</code> instead.
</dl>
<h3><a name="Color_mapping"></a>Color and alpha mapping</h3>
<p>
Note that code in the Ghostscript library may cache the results of calling
one or more of the color mapping procedures. If the result returned by any
of these procedures would change (other than as a result of a change made by
the driver's <code>put_params</code> procedure), the driver must call
<code>gx_device_decache_colors(dev)</code>.
<p>
The <code>map_rgb_color</code>, <b><tt>map_color_rgb</tt></b>, and
<code>map_cmyk_color</code> are obsolete. They have been left
in the device procedure list for backward compatibility. See the
<code>encode_color</code> and <b><tt>decode_color</tt></b> procedures
below. To insure that older device drivers are changed to use the new
<code>encode_color</code> and <b><tt>decode_color</tt></b>
procedures,
the parameters for the older procedures have been changed to
match the new procedures. To minimize changes in devices that have
already been written, the map_rgb_color and map_cmyk_color routines
are used as the default value for the encode_color routine. The
map_cmyk_color routine is used if the number of components is four.
The map_rgb_color routine is used if the number of components is one
or three. This works okay for RGB and CMYK process color model devices.
However this does not work properly for gray devices. The encode_color
routine for a gray device is only passed one component. Thus the
map_rgb_color routine must be modified to only use a single input (instead
of three). (See the encode_color and decode_color routines below.)
<p>
Colors can be specified to the Ghostscript graphics library in a variety
of forms. For example, there are a wide variety of color spaces that can
be used such as Gray, RGB, CMYK, DeviceN, Separation, Indexed, CIEbasedABC,
etc. The graphics library converts the various input color space
values into four base color spaces: Gray, RGB, CMYK, and DeviceN. The
DeviceN color space allows for specifying values for individual device
colorants or spot colors.
<p>
Colors are converted by the device in a two step process. The first step
is to convert a color in one of the base color spaces (Gray, RGB, CMYK,
or DeviceN) into values for each device colorant. This transformation is
done via a set of procedures provided by the device. These procedures are
provided by the <code>get_color_mapping_procs</code> device procedure.
<p>
Between the first and second steps, the graphics library applies transfer
functions to the device colorants. Where needed, the output of the results
after the transfer functions is used by the graphics library for halftoning.
<p>
In the second step, the device procedure <code>encode_color</code> is
used to convert the transfer function results into a
<code>gx_color_index</code> value.
The <code>gx_color_index</code> values are passed to specify colors
to various routines.
The choice of the encoding for a <code>gx_color_index</code> is
up to the device. Common choices are indexes into a color palette or
several integers packed together into a single value. The manner of this
encoding is usually opaque to the graphics library. The only exception to this
statement occurs when halftoning 5 or more colorants. In this case the
graphics library assumes that if a colorant values is zero then the
bits associated with the colorant in the <code>gx_color_index</code>
value are zero.
<dl>
<dt><code>int get_color_comp_index(const gx_device * dev, const char * pname,
int name_size, int src_index)</code> <b><em>[OPTIONAL]</em></b>
<dd>This procedure returns the device colorant number of the given name.
The possible return values are -1, 0 to
<code>GX_DEVICE_COLOR_MAX_COMPONENTS - 1</code>, or
<code>GX_DEVICE_COLOR_MAX_COMPONENTS</code>. A value of -1 indicates that
the specified name is not a colorant for the device. A value of 0 to
<code>GX_DEVICE_COLOR_MAX_COMPONENTS - 1</code> indicates the colorant number
of the given name. A value of <code>GX_DEVICE_COLOR_MAX_COMPONENTS</code>
indicates that the given name is a valid colorant name for the device but the
colorant is not currently being used. This is used for implementing names
which are in SeparationColorNames but not in SeparationOrder.
<p>
The default procedure returns results based upon process color model
of DeviceGray, DeviceRGB, or DeviceCMYK selected by
<code>color_info.num_components</code>. This procedure must be
defined if another process color model is used by the device or spot colors are
supported by the device.
</dd>
</dl>
<dl>
<dt><code>const gx_cm_color_map_procs * get_color_mapping_procs(const
gx_device * dev)</code> <b><em>[OPTIONAL]</em></b>
<dd>This procedure returns a list of three procedures. These procedures
are used to translate values in either Gray, RGB, or CMYK color spaces
into device colorant values. A separate procedure is not required for the
DeviceN and Separation color spaces since these already represent
device colorants.
<p>
The default procedure returns a list of procedures based upon
<code>color_info.num_components</code>. These procedures are appropriate
for DeviceGray, DeviceRGB, or DeviceCMYK process color model devices. A
procedure must be defined if another process color model is used by the
device or spot colors are to be supported.
</dd>
</dl>
<dl>
<dt><code>gx_color_index (*encode_color)(gx_device * dev,
gx_color_value * cv)</code> <b><em>[OPTIONAL]</em></b>
<dd>Map a set of device color values into a <code>gx_color_index</code>
value. The range of legal values of the
arguments is 0 to <code>gx_max_color_value</code>. The default procedure
packs bits into a <code>gx_color_index</code> value based upon the
values in <code>color_info.depth</code> and
<code>color_info.num_components</code>.
<p>
Note that the <code>encode_color</code> procedure
must not return <code>gx_no_color_index</code> (all 1s).
</dl>
<dl>
<dt><code>int (*decode_color)(gx_device *, gx_color_index color,
gx_color_value * CV)</code> <b><em>[OPTIONAL]</em></b>
<dd>This is the inverse of the <code>encode_color</code> procedure.
Map a <code>gx_color_index</code> value to color values. The default
procedure unpacks bits from the <code>gx_color_index</code> value based upon
the values in <code>color_info.depth</code> and
<code>color_info.num_components</code>.
</dl>
<dl>
<dt><code>gx_color_index (*map_rgb_alpha_color)(gx_device *,
gx_color_value red, gx_color_value green,
gx_color_value blue, gx_color_value alpha)</code> <b><em>[OPTIONAL]</em></b>
<dd>Map a RGB color and an opacity value to a device color. The range of
legal values of the RGB and alpha arguments is 0 to
<code>gx_max_color_value</code>; <b><tt>alpha</tt></b> = 0 means
transparent, <code>alpha</code> = <b><tt>gx_max_color_value</tt></b>
means fully opaque. The default is to use the
<code>encode_color</code> procedure and ignore alpha.
<p>
Note that if a driver implements <code>map_rgb_alpha_color</code>, it
must also implement <code>encode_color</code>, and must implement them
in such a way that
<code>map_rgb_alpha_color(dev, r, g, b, gx_max_color_value)</code>
returns the same value as
<code>encode_color(dev, CV)</code>.
</dl>
<dl>
<dt><code>int (*map_color_rgb_alpha)(gx_device *,
gx_color_index color, gx_color_value rgba[4])</code>
<b><em>[OPTIONAL]</em></b>
<dd>Map a device color code to RGB and alpha values. The default
implementation calls <code>map_color_rgb</code> and fills in
<code>gx_max_color_value</code> for alpha.
<p>
Note that if a driver implements <code>map_color_rgb_alpha</code>, it
must also implement <code>decode_color</code>, and must implement them
in such a way that the first 3 values returned by
<code>map_color_rgb_alpha</code> are the same as the values returned by
<code>decode_color</code>.
<p>
Note that only RGB devices currently support variable opacity; alpha is ignored
on other devices. The PDF 1.4 transparency features are supported on all devices.
</dl>
<dl>
<dt><code>typedef enum { go_text,
go_graphics } graphic_object_type; int
(*get_alpha_bits)(gx_device *dev,
graphic_object_type type)</code> <b><em>[OPTIONAL] [OBSOLETE]</em></b>
<dd>This procedure is no longer used: it is replaced by the
color_info.anti_alias member of the driver structure. However, it still
appears in the driver procedure vector for backward compatibility. It
should never be called, and drivers should not implement it.
</dl>
<dl>
<dt><code>void (*update_spot_equivalent_colors)(gx_device *,
const gs_state *)</code>
<b><em>[OPTIONAL]</em></b>
<dd>This routine provides a method for the device to gather an equivalent
color for spot colorants. This routine is called when a Separation or DeviceN
color space is installed. See comments at the start of
<a href="../base/gsequivc.c">gsequivc.c</a>. Note: This procedure is only needed
for devices that support spot colorants and also need to have an equivalent
color for simulating the appearance of the spot colorants.
</dl>
<h3><a name="Pixel_level_drawing"></a>Pixel-level drawing</h3>
<p>
This group of drawing operations specifies data at the pixel level. All
drawing operations use device coordinates and device color values.
<dl>
<dt><code>int (*fill_rectangle)(gx_device *, int x,
int y, int width, int height,
gx_color_index color)</code>
<dd>Fill a rectangle with a color. The set of pixels filled is {(px,py) |
x <= px < x + width and y <= py < y + height}. In other words,
the point <em>(x,y)</em> is included in the rectangle, as are
<em>(x+w-1,y)</em>, <em>(x,y+h-1)</em>, and <em>(x+w-1,y+h-1)</em>, but
<b><em>not</em></b> <em>(x+w,y)</em>, <em>(x,y+h)</em>, or
<em>(x+w,y+h)</em>. If <code>width</code> <= 0 or
height <= 0, <code>fill_rectangle</code> should return 0
without drawing anything.
<p>
Note that <code>fill_rectangle</code> is the only non-optional procedure
in the driver interface.
</dl>
<h4><a name="Bitmap_imaging"></a>Bitmap imaging</h4>
<p>
Bitmap (or pixmap) images are stored in memory in a nearly standard way.
The first byte corresponds to <em>(0,0)</em> in the image coordinate
system: bits (or polybit color values) are packed into it left to right.
There may be padding at the end of each scan line: the distance from one
scan line to the next is always passed as an explicit argument.
<dl>
<dt><code>int (*copy_mono)(gx_device *,
const unsigned char *data, int data_x, int raster,
gx_bitmap_id id, int x, int y, int width,
int height, gx_color_index color0,
gx_color_index color1)</code> <b><em>[OPTIONAL]</em></b>
<dd>Copy a monochrome image (similar to the PostScript image operator).
Each scan line is raster bytes wide. Copying begins at
(<code>data_x</code>,0) and transfers a rectangle of the given width and
height to the device at device coordinate <em>(x,y)</em>. (If the transfer
should start at some non-zero y value in the data, the caller can adjust
the data address by the appropriate multiple of the raster.) The copying
operation writes device color <code>color0</code> at each 0-bit, and
<code>color1</code> at each 1-bit: if <b><tt>color0</tt></b> or
<code>color1</code> is <b><tt>gx_no_color_index</tt></b>, the device
pixel is unaffected if the image bit is 0 or 1 respectively. If
<code>id</code> is different from <b><tt>gx_no_bitmap_id</tt></b>, it
identifies the bitmap contents unambiguously; a call with the same
<code>id</code> will always have the same <b><tt>data</tt></b>,
<code>raster</code>, and data contents.
<p>
This operation, with
<code>color0</code> = <b><tt>gx_no_color_index</tt></b>, is
the workhorse for text display in Ghostscript, so implementing it
efficiently is very important.
</dl>
<dl>
<dt><code>int (*tile_rectangle)(gx_device *,
const gx_tile_bitmap *tile, int x, int y,
int width, int height, gx_color_index color0,
gx_color_index color1, int phase_x, int phase_y)</code>
<b><em>[OPTIONAL] [OBSOLETE]</em></b>
<dd>This procedure is still supported, but has been superseded by
<code>strip_tile_rectangle</code>. New drivers should implement
<code>strip_tile_rectangle</code>; if they cannot cope with non-zero
shift values, they should test for this explicitly and call the default
implementation (<code>gx_default_strip_tile_rectangle</code>) if
shift != 0. Clients should call
<code>strip_tile_rectangle</code>, not <b><tt>tile_rectangle</tt></b>.
</dl>
<dl>
<dt><code>int (*strip_tile_rectangle)(gx_device *,
const gx_strip_bitmap *tile, int x, int y,
int width, int height, gx_color_index color0,
gx_color_index color1, int phase_x, int phase_y)</code>
<b><em>[OPTIONAL]</em></b>
<dd>Tile a rectangle. Tiling consists of doing multiple
<code>copy_mono</code> operations to fill the rectangle with copies of
the tile. The tiles are aligned with the device coordinate system, to
avoid "seams". Specifically, the (<code>phase_x</code>,
<code>phase_y</code>) point of the tile is aligned with the origin of
the device coordinate system. (Note that this is backwards from the
PostScript definition of halftone phase.) <code>phase_x</code> and
<code>phase_y</code> are guaranteed to be in the range
<em>[0..</em><code>tile->width</code><em>)</em> and
<em>[0..</em><code>tile->height</code><em>)</em> respectively.
<p>
If <code>color0</code> and <b><tt>color1</tt></b> are both
<code>gx_no_color_index</code>, then the tile is a color pixmap, not a
bitmap: see the next section.
<p>
This operation is the workhorse for halftone filling in Ghostscript, so
implementing it efficiently for solid tiles (that is, where either
<code>color0</code> and <b><tt>color1</tt></b> are both
<code>gx_no_color_index</code>, for colored halftones, or neither one is
<code>gx_no_color_index</code>, for monochrome halftones) is very
important.
</dl>
<h4><a name="Pixmap_imaging"></a>Pixmap imaging</h4>
<p>
Pixmaps are just like bitmaps, except that each pixel occupies more than
one bit. All the bits for each pixel are grouped together (this is
sometimes called "chunky" or "Z" format). For <code>copy_color</code>,
the number of bits per pixel is given by the
<code>color_info.depth</code> parameter in the device structure: the
legal values are 1, 2, 4, 8, 16, 24, 32, 40, 48, 56, or 64. The pixel
values are device color codes (that is, whatever it is that
<code>encode_color</code> returns).
<dl>
<dt><code>int (*copy_color)(gx_device *,
const unsigned char *data, int data_x, int raster,
gx_bitmap_id id, int x, int y, int width,
int height)</code> <b><em>[OPTIONAL]</em></b>
<dd>Copy a color image with multiple bits per pixel. The raster is in
bytes, but <code>x</code> and <b><tt>width</tt></b> are in pixels, not
bits. If <code>id</code> is different from
<code>gx_no_bitmap_id</code>, it identifies the bitmap contents
unambiguously; a call with the same <code>id</code> will always have the
same <code>data</code>, <b><tt>raster</tt></b>, and data contents.
<p>
We do not provide a separate procedure for tiling with a pixmap; instead,
<code>tile_rectangle</code> can also take colored tiles. This is
indicated by the <code>color0</code> and <b><tt>color1</tt></b>
arguments' both being <code>gx_no_color_index</code>. In this case, as
for <code>copy_color</code>, the <b><tt>raster</tt></b> and
<code>height</code> in the "bitmap" are interpreted as for real bitmaps,
but the <code>x</code> and <b><tt>width</tt></b> are in pixels, not
bits.
</dl>
<h4><a name="Compositing"></a>Compositing</h4>
<p>
In addition to direct writing of opaque pixels, devices must also support
compositing. Currently two kinds of compositing are defined
(<code>RasterOp</code> and alpha-based), but more may be added in the
future.
<blockquote>
<b><em>THIS AREA OF THE INTERFACE IS SOMEWHAT UNSTABLE: USE AT YOUR OWN
RISK.</em></b>
</blockquote>
<dl>
<dt><code>int (*copy_alpha)(gx_device *dev,
const unsigned char *data, int data_x, int raster,
gx_bitmap_id id, int x, int y, int width,
int height, gx_color_index color, int depth)</code>
<b><em>[OPTIONAL]</em></b>
<dd>This procedure is somewhat misnamed: it was added to the interface
before we really understood alpha channel and compositing.
<p>
Fill a given region with a given color modified by an individual alpha
value for each pixel. For each pixel, this is equivalent to
alpha-compositing with a source pixel whose alpha value is obtained from
the pixmap (<code>data</code>, <b><tt>data_x</tt></b>, and
<code>raster</code>) and whose color is the given color (which has
<b><em>not</em></b> been premultiplied by the alpha value), using the Sover
rule. <code>depth</code>, the number of bits per alpha value, is either
2 or 4, and in any case is always a value returned by a previous call on
the <code>get_alpha_bits</code> procedure. Note that if
<code>get_alpha_bits</code> always returns 1, this procedure will never
be called.
</dl>
<dl>
<dt><code>int (*create_compositor)(dev_t *dev,
gx_device_t **pcdev, const gs_composite_t *pcte,
const gs_imager_state *pis, gs_memory_t *memory)</code>
<b><em>[OPTIONAL]</em></b>
<dd>Create a new device (called a "compositing device" or "compositor")
that will composite data written to it with the device's existing data,
according to the compositing function defined by <code>*pcte</code>.
Devices will normally implement this in one of the following standard ways:
<ul>
<li>Devices that don't do any imaging and don't forward any imaging
operations (for example, the null device, the hit detection device, and the
clipping list accumulation device) simply return themselves, which
effectively ignores the compositing function.
<li>"Leaf" devices that do imaging and have no special optimizations for
compositing (for example, some memory devices) ask the
<code>gs_composite_t</code> to create a default compositor.
<li>Leaf devices that can implement some kinds of compositing operation
efficiently (for example, monobit memory devices and RasterOp) inspect the
type and values of <code>*pcte</code> to determine whether it specifies
such an operation: if so, they create a specialized compositor, and if not,
they ask the <code>gs_composite_t</code> to create a default compositor.
</ul>
<p>
Other kinds of forwarding devices, which don't fall into any of these
categories, require special treatment. In principle, what they do is ask
their target to create a compositor, and then create and return a copy of
themselves with the target's new compositor as the target of the copy.
There is a possible default implementation of this approach: if the
original device was <b>D</b> with target <b>T</b>, and <b>T</b> creates a
compositor <b>C</b>, then the default implementation creates a device
<b>F</b> that for each operation temporarily changes <b>D</b>'s target to
<b>C</b>, forwards the operation to <b>D</b>, and then changes <b>D</b>'s
target back to <b>T</b>. However, the Ghostscript library currently only
creates a compositor with an imaging forwarding device as target in a few
specialized situations (banding, and bounding box computation), and these
are handled as special cases.
<p>
Note that the compositor may have a different color space, color
representation, or bit depth from the device to which it is compositing.
For example, alpha-compositing devices use standard-format chunky color
even if the underlying device doesn't.
<p>
Closing a compositor frees all of its storage, including the compositor
itself. However, since the <code>create_compositor</code> call may
return the same device, clients must check for this case, and only call the
close procedure if a separate device was created.
</dl>
<p>
<font size="+1">
<b><em>[strip_]copy_rop WILL BE SUPERSEDED BY COMPOSITORS</em></b>
</font>
<dl>
<dt><code>int (*copy_rop)(gx_device *dev,
const byte *sdata, int sourcex, uint sraster,
gx_bitmap_id id, const gx_color_index *scolors,
const gx_tile_bitmap *texture,
const gx_color_index *tcolors, int x, int y,
int width, int height, int phase_x, int phase_y,
int command)</code> <b><em>[OPTIONAL]</em></b>
<dd>This procedure is still supported, but has been superseded by
<code>strip_copy_rop</code>. New drivers should implement
<code>strip_copy_rop</code>; if they cannot cope with non-zero shift
values in the texture, they should test for this explicitly and call the
default implementation (<code>gx_default_strip_copy_rop</code>) if
shift != 0. Clients should call <code>strip_copy_rop</code>,
not <code>copy_rop</code>.
</dl>
<dl>
<dt><code>int (*strip_copy_rop)(gx_device *dev,
const byte *sdata, int sourcex, uint sraster,
gx_bitmap_id id, const gx_color_index *scolors,
const gx_strip_bitmap *texture,
const gx_color_index *tcolors, int x, int y,
int width, int height, int phase_x, int phase_y,
int command)</code> <b><em>[OPTIONAL]</em></b>
<dd>Combine an optional source image <b>S</b> (as for
<code>copy_mono</code> or <b><tt>copy_color</tt></b>) and an optional
texture <b>T</b> (a tile, as for <code>tile_rectangle</code>) with the
existing bitmap or pixmap <b>D</b> held by the driver, pixel by pixel,
using any 3-input Boolean operation as modified by "transparency" flags:
schematically, set <b>D = f(D,S,T)</b>, computing <b>f</b> in RGB
space rather than using actual device pixel values. <b>S</b> and <b>T</b>
may each (independently) be a solid color, a bitmap with "foreground" and
"background" colors, or a pixmap. This is a complex (and currently rather
slow) operation. The arguments are as follows:
<blockquote><table cellpadding=0 cellspacing=0>
<tr valign=top> <td><code>dev</code>
<td>
<td>the device, as for all driver procedures
<tr valign=top> <td><code>sdata</code>, <b><tt>sourcex</tt></b>, <b><tt>sraster</tt></b>, <b><tt>id</tt></b>, <b><tt>scolors</tt></b>
<td>
<td>specify <b>S</b>, <a href="#S_spec">see below</a>
<tr valign=top> <td><code>texture</code>, <b><tt>tcolors</tt></b>
<td>
<td>specify <b>T</b>, <a href="#T_spec">see below</a>
<tr valign=top> <td><code>x</code>, <b><tt>y</tt></b>, <b><tt>width</tt></b>, <b><tt>height</tt></b>
<td>
<td>as for the other copy and fill procedures
<tr valign=top> <td><code>phase_x</code>, <b><tt>phase_y</tt></b>
<td>
<td>part of <b>T</b> specification, <a href="#T_spec">see below</a>
<tr valign=top> <td><code>command</code>
<td>
<td><a href="#F_spec">see below</a>
</table></blockquote>
</dl>
<h5><a name="S_spec"></a>The source specification S</h5>
<p>
As noted above, the source <b>S</b> may be a solid color, a bitmap, or a
pixmap. If <b>S</b> is a solid color:
<ul>
<li><code>sdata</code>, <b><tt>sourcex</tt></b>,
<code>sraster</code>, and <b><tt>id</tt></b> are irrelevant.
<li><code>scolors</code> points to two <b><tt>gx_color_index</tt></b>
values; <code>scolors[0]</code> = <b><tt>scolors[1]</tt></b> = the
color.
</ul>
<p>
If <b>S</b> is a bitmap:
<ul>
<li><code>sdata</code>, <b><tt>sourcex</tt></b>,
<code>sraster</code>, and <b><tt>id</tt></b> arguments are as for
<code>copy_mono</code> or <b><tt>copy_color</tt></b>
(<code>data</code>, <b><tt>data_x</tt></b>, <b><tt>raster</tt></b>,
<code>id</code>), and specify a source bitmap.
<li><code>scolors</code> points to two <b><tt>gx_color_index</tt></b>
values; <code>scolors[0]</code> is the background color (the color
corresponding to 0-bits in the bitmap), <code>scolors[1]</code> is the
foreground color (the color corresponding to 1-bits in the bitmap).
</ul>
<p>
If <b>S</b> is a pixmap:
<ul>
<li><code>sdata</code>, <b><tt>sourcex</tt></b>,
<code>sraster</code>, and <b><tt>id</tt></b> arguments are as for
<code>copy_mono</code> or <b><tt>copy_color</tt></b>
(<code>data</code>, <b><tt>data_x</tt></b>, <b><tt>raster</tt></b>,
<code>id</code>), and specify a source pixmap whose depth is the same as
the depth of the destination.
<li><code>scolors</code> is <b><tt>NULL</tt></b>.
</ul>
<p>
Note that if the source is a bitmap with background=0 and foreground=1, and
the destination is 1 bit deep, then the source can be treated as a pixmap
(scolors=<code>NULL</code>).
<h5><a name="T_spec"></a>The texture specification T</h5>
<p>
Similar to the source, the texture <b>T</b> may be a solid color, a bitmap,
or a pixmap. If <b>T</b> is a solid color:
<ul>
<li>The texture pointer is irrelevant.
<li><code>tcolors</code> points to two <b><tt>gx_color_index</tt></b>
values; <code>tcolors[0]</code> = <b><tt>tcolors[1]</tt></b> = the
color.
</ul>
<p>
If <b>T</b> is a bitmap:
<ul>
<li>The texture argument points to a <code>gx_tile_bitmap</code>, as for
the <code>tile_rectangle</code> procedure. Similarly,
<code>phase_x</code> and <b><tt>phase_y</tt></b> specify the offset of
the texture relative to the device coordinate system origin, again as for
<code>tile_rectangle</code>. The tile is a bitmap (1 bit per pixel).
<li><code>tcolors</code> points to two <b><tt>gx_color_index</tt></b>
values; <code>tcolors[0]</code> is the background color (the color
corresponding to 0-bits in the bitmap), <code>tcolors[1]</code> is the
foreground color (the color corresponding to 1-bits in the bitmap).
</ul>
<p>
If <b>T</b> is a pixmap:
<ul>
<li>The texture argument points to a <code>gx_tile_bitmap</code> whose
depth is the same as the depth of the destination.
<li>tcolors is <code>NULL</code>.
</ul>
<p>
Again, if the texture is a bitmap with background=0 and foreground=1, and
the destination depth is 1, the texture bitmap can be treated as a pixmap
(tcolors=<code>NULL</code>).
<p>
Note that while a source bitmap or pixmap has the same width and height as
the destination, a texture bitmap or pixmap has its own width and height
specified in the <code>gx_tile_bitmap</code> structure, and is
replicated or clipped as needed.
<h5><a name="F_spec"></a>The function specification f</h5>
<p>
"Command" indicates the raster operation and transparency as follows:
<blockquote><table cellpadding=0 cellspacing=0>
<tr valign=bottom>
<th>Bits
<td>
<td>
<tr valign=top> <td>7-0
<td>
<td>raster op
<tr valign=top> <td>8
<td>
<td>0 if source opaque, 1 if source transparent
<tr valign=top> <td>9
<td>
<td>0 if texture opaque, 1 if texture transparent
<tr valign=top> <td>?-10
<td>
<td>unused, must be 0
</table></blockquote>
<p>
The raster operation follows the Microsoft and H-P specification. It is an
8-element truth table that specifies the output value for each of the
possible 2×2×2 input values as follows:
<blockquote><table cellpadding=0 cellspacing=0>
<tr valign=bottom>
<th>Bit
<td>
<th>Texture
<td>
<th>Source
<td>
<th>Destination
<tr> <td colspan=7><hr>
<tr valign=top> <td align=center>7
<td>
<td align=center>1
<td>
<td align=center>1
<td>
<td align=center>1
<tr valign=top> <td align=center>6
<td>
<td align=center>1
<td>
<td align=center>1
<td>
<td align=center>0
<tr valign=top> <td align=center>5
<td>
<td align=center>1
<td>
<td align=center>0
<td>
<td align=center>1
<tr valign=top> <td align=center>4
<td>
<td align=center>1
<td>
<td align=center>0
<td>
<td align=center>0
<tr valign=top> <td align=center>3
<td>
<td align=center>0
<td>
<td align=center>1
<td>
<td align=center>1
<tr valign=top> <td align=center>2
<td>
<td align=center>0
<td>
<td align=center>1
<td>
<td align=center>0
<tr valign=top> <td align=center>1
<td>
<td align=center>0
<td>
<td align=center>0
<td>
<td align=center>1
<tr valign=top> <td align=center>0
<td>
<td align=center>0
<td>
<td align=center>0
<td>
<td align=center>0
</table></blockquote>
<p>
Transparency affects the output in the following way. A source or texture
pixel is considered transparent if its value is all 1s (for instance, 1 for
bitmaps, <tt>0xffffff</tt> for 24-bit RGB pixmaps) <b><em>and</em></b> the
corresponding transparency bit is set in the command. For each pixel, the
result of the Boolean operation is written into the destination iff neither
the source nor the texture pixel is transparent. (Note that the HP
RasterOp specification, on which this is based, specifies that if the
source and texture are both all 1s and the command specifies transparent
source and opaque texture, the result <b><em>should</em></b> be written in
the output. We think this is an error in the documentation.)
<h5><a name="Compositing_notes"></a>Notes</h5>
<p>
<code>copy_rop</code> is defined to operate on pixels in RGB space,
again following the HP and Microsoft specification. For devices that
don't use RGB (or gray-scale with black = 0, white = all 1s) as their
native color representation, the implementation of <code>copy_rop</code>
must convert to RGB or gray space, do the operation, and convert back (or
do the equivalent of this). Here are the <code>copy_rop</code>
equivalents of the most important previous imaging calls. We assume the
declaration:
<blockquote><code>
static const gx_color_index white2[2] = { 1, 1 };
</code></blockquote>
<p>
Note that <code>rop3_S</code> may be replaced by any other Boolean operation.
For monobit devices, we assume that black = 1.
<blockquote>
<pre>/* For all devices: */
(*fill_rectangle)(dev, x, y, w, h, color) ==>
{ gx_color_index colors[2];
colors[0] = colors[1] = color;
(*dev_proc(dev, copy_rop))(dev, NULL, 0, 0, gx_no_bitmap_id, colors,
NULL, colors /*irrelevant*/,
x, y, w, h, 0, 0, rop3_S);
}
/* For black-and-white devices only: */
(*copy_mono)(dev, base, sourcex, sraster, id,
x, y, w, h, (gx_color_index)0, (gx_color_index)1) ==>
(*dev_proc(dev, copy_rop))(dev, base, sourcex, sraster, id, NULL,
NULL, white2 /*irrelevant*/,
x, y, w, h, 0, 0, rop3_S);
/* For color devices, where neither color0 nor color1 is gx_no_color_index: */
(*copy_mono)(dev, base, sourcex, sraster, id,
x, y, w, h, color0, color1) ==>
{ gx_color_index colors[2];
colors[0] = color0, colors[1] = color1;
(*dev_proc(dev, copy_rop))(dev, base, sourcex, sraster, id, colors,
NULL, white2 /*irrelevant*/,
x, y, w, h, 0, 0, rop3_S);
}
/* For black-and-white devices only: */
(*copy_mono)(dev, base, sourcex, sraster, id,
x, y, w, h, gx_no_color_index, (gx_color_index)1) ==>
(*dev_proc(dev, copy_rop))(dev, base, sourcex, sraster, id, NULL,
NULL, white2 /*irrelevant*/,
x, y, w, h, 0, 0,
rop3_S | lop_S_transparent);
/* For all devices: */
(*copy_color)(dev, base, sourcex, sraster, id,
x, y, w, h) ==> [same as first copy_mono above]
/* For black-and-white devices only: */
(*tile_rectangle)(dev, tile, x, y, w, h,
(gx_color_index)0, (gx_color_index)1, px, py) ==>
(*dev_proc(dev, copy_rop))(dev, NULL, 0, 0, gx_no_bitmap_id,
white2 /*irrelevant*/,
tile, NULL,
x, y, w, h, px, py, rop3_T)
</pre></blockquote>
<h3><a name="Polygon_level_drawing"></a>Polygon-level drawing</h3>
<p>
In addition to the pixel-level drawing operations that take integer device
coordinates and pure device colors, the driver interface includes
higher-level operations that draw polygons using fixed-point coordinates,
possibly halftoned colors, and possibly a non-default logical operation.
<p>
The <code>fill_</code>* drawing operations all use the center-of-pixel
rule: a pixel is colored iff its center falls within the polygonal region
being filled. If a pixel center <em>(X+0.5,Y+0.5)</em> falls exactly on
the boundary, the pixel is filled iff the boundary is horizontal and the
filled region is above it, or the boundary is not horizontal and the filled
region is to the right of it.
<dl>
<dt><code>int (*fill_trapezoid)(gx_device *dev, const
gs_fixed_edge *left, const gs_fixed_edge *right,
fixed ybot, fixed ytop, bool swap_axes,
const gx_drawing_color *pdcolor,
gs_logical_operation_t lop)</code> <b><em>[OPTIONAL]</em></b>
<dd>Fill a trapezoid. The bottom and top edges are parallel to the x
axis, and are defined by <code>ybot</code> and <b><tt>ytop</tt></b>,
respectively. The left and right edges are defined by <code>left</code>
and <code>right</code>. Both of these represent lines (<b><tt>gs_fixed_edge</tt></b>
is defined in <a href="../base/gxdevcli.h">gxdevcli.h</a> and consists
of <code>gs_fixed_point</code> <b><tt>start</tt></b> and <b><tt>end</tt></b> points).
The y coordinates of these lines need not have any specific relation to
<code>ybot</code> and <b><tt>ytop</tt></b>. The routine is defined this way so
that the filling algorithm can subdivide edges and still guarantee
that the exact same pixels will be filled. If
<code>swap_axes</code> is set, the meanings of X and Y are
interchanged.
</dd>
<dt><code>int (*fill_parallelogram)(gx_device *dev,
fixed px, fixed py, fixed ax, fixed ay, fixed bx,
fixed by, const gx_drawing_color *pdcolor,
gs_logical_operation_t lop)</code> <b><em>[OPTIONAL]</em></b>
<dd>Fill a parallelogram whose corners are <em>(px,py)</em>,
<em>(px+ax,py+ay)</em>, <em>(px+bx,py+by)</em>, and
<em>(px+ax+bx,py+ay+by)</em>. There are no constraints on the values of
any of the parameters, so the parallelogram may have any orientation
relative to the coordinate axes.
<dt><code>int (*fill_triangle)(gx_device *dev, fixed px,
fixed py, fixed ax, fixed ay, fixed bx, fixed by,
const gx_drawing_color *pdcolor,
gs_logical_operation_t lop)</code> <b><em>[OPTIONAL]</em></b>
<dd>Fill a triangle whose corners are <em>(px,py)</em>,
<em>(px+ax,py+ay)</em>, and <em>(px+bx,py+by)</em>.
<dt><code>int (*draw_thin_line)(gx_device *dev,
fixed fx0, fixed fy0, fixed fx1, fixed fy1,
const gx_drawing_color *pdcolor,
gs_logical_operation_t lop)</code> <b><em>[OPTIONAL]</em></b>
<dd>Draw a one-pixel-wide line from <em>(fx0,fy0)</em> to
<em>(fx1,fy1)</em>.
<dt><code>int (*draw_line)(gx_device *dev, int x0, int y0,
int x1, int y1, gx_color_index color)</code>
<b><em>[OPTIONAL] [OBSOLETE]</em></b>
<dd>This procedure is no longer used: it is replaced by the draw_thin_line
procedure. However, still appears in the driver procedure vector for
backward compatibility. It should never be called, and drivers should not
implement it.
</dl>
<h3><a name="Linear_color_drawing"></a>Linear color drawing</h3>
<p>
Linear color functions allow fast high quality rendering of
shadings on continuous tone devices. They implement filling simple areas
with a lineary varying color. These functions are not called if the device applies halftones,
or uses a non-separable or a non-linear color model.
<dl>
<dt><code> int (*fill_linear_color_triangle)
(dev_t *dev, const gs_fill_attributes *fa,
const gs_fixed_point *p0, const gs_fixed_point *p1,
const gs_fixed_point *p2,
const frac31 *c0, const frac31 *c1, const frac31 *c2)
</code>
<b><em>[OPTIONAL]</em></b>
<dd>This function is the highest level one within the linear color function group.
It fills a triangle with a linearly varying color.
Arguments specify 3 points in the device space - vertices of a triangle, and their colors.
The colors are represented as vectors of positive fractional numbers, each of which
represents a color component value in the interval <code>[0,1]</code>.
The number of components in a vector in the number of color
components in the device (process) color model.
<dd>
The implementation fills entire triangle.
The filling rule is same as for <a href="#Polygon_level_drawing">Polygon-level drawing</a>.
A color for each pixel within the triangle to be computed as a linear interpolation
of vertex colors.
<dd>
The implementation may reject the request if the area or the color appears too complex
for filling in a single action. For doing that the implementation returns 0 and must not
paint any pixel. In this case the graphics library will perform a subdivision of the area
into smaller triangles and call the function again with smaller areas.
<dd>
<b><em>Important note :</em></b> Do not try to decompose the area within
the implementation of <code> fill_linear_color_triangle</code>, because
it can break the plane coverage contiguity and cause a dropout.
Instead request that graphics library to perform the decomposition.
The graphics libary is smart enough to do that properly.
<dd>
<b><em>Important note :</em></b>
The implementation must handle a special case, when only 2 colors are specified.
It happens if <code>p3</code> one is <b><tt>NULL</tt></b>.
This means that the color does not depend on the X coordinate,
i.e. it forms a linear gradient along the Y axis.
The implementation must not reject (return 0) such cases.
<dd>
<b><em>Important note :</em></b>The device color component
value 1 may be represented with several hexadecimal values :
<code>0x7FFF0000</code>, <b><tt>0x7FFFF000</tt></b>, <b><tt>0x7FFFFF00</tt></b>, etc.,
because the precision here exceeds the color precision of the device.
To convert a <code>frac31</code> value into a device color component value,
fist drop (ignore) the sign bit, then drop least significant bits -
so many ones as you need to fit the device color precision.
<dd>
<b><em>Important note :</em></b> The <code>fa</code> argument may contain
the <code>swap_axes</code> bit set. In this case the implementation must swap (transpoze)
<code>X</code> and <b><tt>Y</tt></b> axes.
<dd>
<b><em>Important note :</em></b> The implementation must not paint outside the
clipping rectangle specified in the <code>fa</code> argument.
If <code>fa->swap_axes</code> is true, the clipping rectangle is transposed.
<dd>
See <code> gx_default_fill_linear_color_triangle </code>
in <code>gdevddrw.c</code> as a sample code.
</dl>
<dl>
<dt><code> int (*fill_linear_color_trapezoid)
(dev_t *dev, const gs_fill_attributes *fa,
const gs_fixed_point *p0, const gs_fixed_point *p1,
const gs_fixed_point *p2, const gs_fixed_point *p3,
const frac31 *c0, const frac31 *c1,
const frac31 *c2, const frac31 *c2)
</code>
<b><em>[OPTIONAL]</em></b>
<dd>This function is a lower level one within the linear color function group.
The default implementation of <code> fill_linear_color_triangle </code>
calls this function 1-2 times per triangle. Besides that,
this function may be called by the graphics library for other special cases,
when a decomposition into triangles appears undiserable.
<dd>
Rather the prototype can specify a bilinear color,
we assume that the implementation handles linear colors only.
This means that the implementation can ignore any of <code> c0, c1, c2, c3 </code>.
The graphics library takes a special care of the color linearity
when calling this function. The reason for passing all 4 color arguments
is to avoid color precision problems.
<dd>
Similarly to <code> fill_linear_color_triangle </code>,
this function may be called with only 2 colors, and may reject too comple areas.
All those important notes are applicable here.
<dd>
A sample code may be found in in <code>gxdtfill.h</code>, rather it's a kind of complicated.
A linear color function is generated from it as <code> gx_fill_trapezoid_ns_lc </code>
with the following template parametres :
<pre>
#define LINEAR_COLOR 1
#define EDGE_TYPE gs_linear_color_edge
#define FILL_ATTRS const gs_fill_attributes *
#define CONTIGUOUS_FILL 0
#define SWAP_AXES 0
#define FILL_DIRECT 1
</pre>
See the helplers <code>init_gradient</code>,
<code>step_gradient</code> (defined in in <b><tt>gdevddrw.c</tt></b>), how to manage colors.
See <code>check_gradient_overflow</code>
(defined in in <code>gdevddrw.c</code>), as an example of an area
that can't be painted in a single action due to 64-bits fixed overflows.
</dl>
<dl>
<dt><code> int (*fill_linear_color_scanline)
(dev_t *dev, const gs_fill_attributes *fa,
int i, int j, int w,
const frac31 *c0,
const int32_t *c0_f,
const int32_t *cg_num,
int32_t cg_den)
</code>
<b><em>[OPTIONAL]</em></b>
<dd>This function is the lowest level one within the linear color function group.
It implements filling a scanline with a linearly varying color.
The default implementation for <code> fill_linear_color_trapezoid </code>
calls this function, and there are no other calls to it from the graphics libary.
Thus if the device implements <code> fill_linear_color_triangle </code> and
<code> fill_linear_color_trapezoid </code> by own means,
this function may be left unimplemented.
<dd>
<code>i</code> and <b><tt>j</tt></b> specify device coordinates (indices)
of the starting pixel of the scanline, <code>w</code> specifies the
width of the scanline, i.e. the number of pixels to be painted to the right from
the starting pixel, including the starting pixel.
<dd>
<code>c0</code> specifies the color for the starting pixel
as a vector of fraction values, each of which represents
a color value in the interval <code>[0,1]</code>.
<dd>
<code>c0_f</code> specify a fraction part of the color for the starting pixel.
See the formula below about using it.
<dd>
<code>cg_num</code> specify a numerator for the color gradient -
a vector of values in <code>[-1,1]</code>, each of which correspond to a color component.
<dd>
<code>cg_den</code> specify the denominator for the color gradient -
a value in <code>[-1,1]</code>.
<dd><p>
The color for the pixel <code>[i + k, j]</code> to be computed like this :
<pre><code>
(double)(c0[n] + (c0_f[n] + cg_num[n] * k) / cg_den) / (1 ^ 31 - 1)
</code></pre>
<dd>where <code>0 <= k <= w </code>, and <b><tt>n</tt></b> is a device color component index.
<dd>
<b><em>Important note :</em></b> The <code>fa</code> argument may contain
the <code>swap_axes</code> bit set. In this case the implementation must swap (transpose)
<code>X</code> and <b><tt>Y</tt></b> axes.
<dd>
<b><em>Important note :</em></b> The implementation must not paint outside the
clipping rectangle specified in the <code>fa</code> argument.
If <code>fa->swap_axes</code> is true, the clipping rectangle is transposed.
<dd>
See <code> gx_default_fill_linear_color_scanline</code>
in <code>gdevdsha.c</code> as a sample code.
</dl>
<h3><a name="High_level_drawing"></a>High-level drawing</h3>
<p>
In addition to the lower-level drawing operations described above, the
driver interface provides a set of high-level operations. Normally these
will have their default implementation, which converts the high-level
operation to the low-level ones just described; however, drivers that
generate high-level output formats such as CGM, or communicate with devices
that have firmware for higher-level operations such as polygon fills, may
implement these high-level operations directly. For more details, please
consult the source code, specifically:
<blockquote><table cellpadding=0 cellspacing=0>
<tr valign=top> <th align=left>Header
<td>
<th align=left>Defines
<tr valign=top> <td><a href="../base/gxpaint.h">gxpaint.h</a>
<td>
<td><code>gx_fill_params</code>, <b><tt>gx_stroke_params</tt></b>
<tr valign=top> <td><a href="../base/gxfixed.h">gxfixed.h</a>
<td>
<td><code>fixed</code>, <b><tt>gs_fixed_point</tt></b> (used by
<code>gx_*_params</code>)
<tr valign=top> <td><a href="../base/gxistate.h">gxistate.h</a>
<td>
<td><code>gs_imager_state</code> (used by <b><tt>gx_*_params</tt></b>)
<tr valign=top> <td><a href="../base/gxline.h">gxline.h</a>
<td>
<td><code>gx_line_params</code> (used by <b><tt>gs_imager_state</tt></b>)
<tr valign=top> <td><a href="../base/gslparam.h">gslparam.h</a>
<td>
<td>line cap/join values (used by <code>gx_line_params</code>)
<tr valign=top> <td><a href="../base/gxmatrix.h">gxmatrix.h</a>
<td>
<td><code>gs_matrix_fixed</code> (used by <b><tt>gs_imager_state</tt></b>)
<tr valign=top> <td><a href="../base/gspath.h">gspath.h</a>, <a href="../base/gxpath.h">gxpath.h</a>, <a href="../base/gzpath.h">gzpath.h</a>
<td>
<td><code>gx_path</code>
<tr valign=top> <td><a href="../base/gxcpath.h">gxcpath.h</a>, <a href="../base/gzcpath.h">gzcpath.h</a>
<td>
<td><code>gx_clip_path</code>
</table></blockquote>
<p>
For a minimal example of how to implement the high-level drawing operations,
see <a href="../base/gdevtrac.c">gdevtrac.c</a>.
<h4><a name="Paths"></a>Paths</h4>
<dl>
<dt><code>int (*fill_path)(gx_device *dev,
const gs_imager_state *pis, gx_path *ppath,
const gx_fill_params *params,
const gx_drawing_color *pdcolor,
const gx_clip_path *pcpath)</code> <b><em>[OPTIONAL]</em></b>
<dd>Fill the given path, clipped by the given clip path, according to the
given parameters, with the given color. The clip path pointer may be
<code>NULL</code>, meaning do not clip.
<dd>
The implementation must paint the path with the specified device color,
which may be either a pure color, or a pattern. If the device can't
handle non-pure colors, it should check the color type and
call the default implementation gx_default_fill_path for cases
which it can't handle. The default implementation will perform
a subdivision of the area to be painted, and will
call other device virtual functions (such as fill_linear_color_triangle)
with simpler areas.
</dl>
<dl>
<dt><code>int (*stroke_path)(gx_device *dev,
const gs_imager_state *pis, gx_path *ppath,
const gx_stroke_params *params,
const gx_drawing_color *pdcolor,
const gx_clip_path *pcpath)</code> <b><em>[OPTIONAL]</em></b>
<dd>Stroke the given path, clipped by the given clip path, according to the
given parameters, with the given color. The clip path pointer may be
<code>NULL</code>, meaning not to clip.
</dl>
<dl>
<dt><code>int (*fill_mask)(gx_device *dev,
const byte *data, int data_x, int raster,
gx_bitmap_id id, int x, int y, int width,
int height, const gx_drawing_color *pdcolor, int depth,
int command, const gx_clip_path *pcpath)</code>
<b><em>[OPTIONAL]</em></b>
<dd>Color the 1-bits in the given mask (or according to the alpha values,
if <code>depth</code> > 1), clipped by the given clip path,
with the given color and logical operation. The clip path pointer may be
<code>NULL</code>, meaning do not clip. The parameters
<code>data</code>, ..., <b><tt>height</tt></b> are as for
<code>copy_mono</code>; depth is as for <b><tt>copy_alpha</tt></b>;
command is as for <code>copy_rop</code>.
</dl>
<h4><a name="Images"></a>Images</h4>
<p>
Similar to the high-level interface for fill and stroke graphics, a high-level
interface exists for bitmap images. The procedures in this part of the
interface are optional.
<p>
Bitmap images come in a variety of types, corresponding closely (but not
precisely) to the PostScript ImageTypes. The generic or common part of all
bitmap images is defined by:
<blockquote>
<pre>typedef struct {
const gx_image_type_t *type;
gs_matrix ImageMatrix;
} gs_image_common_t;</pre>
</blockquote>
<p>
Bitmap images that supply data (all image types except
<code>image_type_from_device</code> (2)) are defined by:
<blockquote>
<pre>#define gs_image_max_components 5
typedef struct {
<< gs_image_common_t >>
int Width;
int Height;
int BitsPerComponent;
float Decode[gs_image_max_components * 2];
bool Interpolate;
} gs_data_image_t;</pre>
</blockquote>
<p>
Images that supply pixel (as opposed to mask) data are defined by:
<blockquote>
<pre>typedef enum {
/* Single plane, chunky pixels. */
gs_image_format_chunky = 0,
/* num_components planes, chunky components. */
gs_image_format_component_planar = 1,
/* BitsPerComponent * num_components planes, 1 bit per plane */
gs_image_format_bit_planar = 2
} gs_image_format_t;
typedef struct {
<< gs_data_image_t >>
const gs_color_space *ColorSpace;
bool CombineWithColor;
} gs_pixel_image_t;</pre>
</blockquote>
<p>
Ordinary PostScript Level 1 or Level 2 (<code>ImageType</code> 1) images
are defined by:
<blockquote>
<pre>typedef enum {
/* No alpha. */
gs_image_alpha_none = 0,
/* Alpha precedes color components. */
gs_image_alpha_first,
/* Alpha follows color components. */
gs_image_alpha_last
} gs_image_alpha_t;
typedef struct {
<< gs_pixel_image_t >>
bool ImageMask;
bool adjust;
gs_image_alpha_t Alpha;
} gs_image1_t;
typedef gs_image1_t gs_image_t;</pre>
</blockquote>
<p>
Of course, standard PostScript images don't have an alpha component. For
more details, consult the source code in <a
href="../base/gsiparam.h">gsiparam.h</a> and <code>gsiparm*.h</code>,
which define parameters for an image.
<p>
The <code>begin[_typed_]image</code> driver procedures create image
enumeration structures. The common part of these structures consists of:
<blockquote>
<pre>typedef struct gx_image_enum_common_s {
const gx_image_type_t *image_type;
const gx_image_enum_procs_t *procs;
gx_device *dev;
gs_id id;
int num_planes;
int plane_depths[gs_image_max_planes]; /* [num_planes] */
int plane_widths[gs_image_max_planes] /* [num_planes] */
} gx_image_enum_common_t;</pre>
</blockquote>
<p>
where <code>procs</code> consists of:
<blockquote>
<pre>typedef struct gx_image_enum_procs_s {
/*
* Pass the next batch of data for processing.
*/
#define image_enum_proc_plane_data(proc)\
int proc(gx_device *dev,\
gx_image_enum_common_t *info, const gx_image_plane_t *planes,\
int height)
image_enum_proc_plane_data((*plane_data));
/*
* End processing an image, freeing the enumerator.
*/
#define image_enum_proc_end_image(proc)\
int proc(gx_device *dev,\
gx_image_enum_common_t *info, bool draw_last)
image_enum_proc_end_image((*end_image));
/*
* Flush any intermediate buffers to the target device.
* We need this for situations where two images interact
* (currently, only the mask and the data of ImageType 3).
* This procedure is optional (may be 0).
*/
#define image_enum_proc_flush(proc)\
int proc(gx_image_enum_common_t *info)
image_enum_proc_flush((*flush));
} gx_image_enum_procs_t;</pre>
</blockquote>
<p> In other words, <code>begin[_typed]_image</code> sets up an
enumeration structure that contains the procedures that will process the
image data, together with all variables needed to maintain the state of the
process. Since this is somewhat tricky to get right, if you plan to create
one of your own you should probably read an existing implementation of
<code>begin[_typed]_image</code>, such as the one in <a
href="../base/gdevbbox.c">gdevbbox.c</a> or <a
href="../base/gdevps.c">gdevps.c</a>.
<p>
The data passed at each call of <code>image_plane_data</code> consists of
one or more planes, as appropriate for the type of image.
<code>begin[_typed]_image</code> must initialize the
<code>plane_depths</code> array in the enumeration structure with the
depths (bits per element) of the planes. The array of
<code>gx_image_plane_t</code> structures passed to each call of
<code>image_plane_data</code> then defines where the data are stored, as
follows:
<blockquote>
<pre>typedef struct gx_image_plane_s {
const byte *data;
int data_x;
uint raster;
} gx_image_plane_t;</pre>
</blockquote>
<dl>
<dt><code>int (*begin_image)(gx_device *dev,
const gs_imager_state *pis, const gs_image_t *pim,
gs_image_format_t format, gs_int_rect *prect,
const gx_drawing_color *pdcolor,
const gx_clip_path *pcpath, gs_memory_t *memory,
gx_image_enum_common_t **pinfo)</code> <b><em>[OPTIONAL]</em></b>
<dd>Begin the transmission of an image. Zero or more calls of
<code>image_plane_data</code> will follow, and then a call of
<code>end_image</code>. The parameters of <b><tt>begin_image</tt></b>
are as follows:
<blockquote><table cellpadding=0 cellspacing=0>
<tr valign=top> <td><code>pis</code>
<td>
<td>pointer to an imager state. The only relevant elements of the
imager state are the CTM (coordinate transformation matrix),
the logical operation (<code>RasterOp</code> or
transparency), and the color rendering information.
<tr valign=top> <td><code>pim</code>
<td>
<td>pointer to the <code>gs_image_t</code> structure that
defines the image parameters
<tr valign=top> <td><code>format</code>
<td>
<td>defines how pixels are represented for
<code>image_plane_data</code>. See the description of
<code>image_plane_data</code> below
<tr valign=top> <td><code>prect</code>
<td>
<td>if not <code>NULL</code>, defines a subrectangle of the
image; only the data for this subrectangle will be passed to
<code>image_plane_data</code>, and only this subrectangle should
be drawn
<tr valign=top> <td><code>pdcolor</code>
<td>
<td>defines a drawing color, only needed for masks or if
<code>CombineWithColor</code> is true
<tr valign=top> <td><code>pcpath</code>
<td>
<td>if not <code>NULL</code>, defines an optional clipping path
<tr valign=top> <td><code>memory</code>
<td>
<td>defines the allocator to be used for allocating bookkeeping
information
<tr valign=top> <td><code>pinfo</code>
<td>
<td>the implementation should return a pointer to its state
structure here
</table></blockquote>
<p>
<code>begin_image</code> is expected to allocate a structure for its
bookkeeping needs, using the allocator defined by the memory parameter, and
return it in <code>*pinfo</code>. <b><tt>begin_image</tt></b> should not assume that
the structures in <code>*pim</code>, <b><tt>*prect</tt></b>, or
<code>*pdcolor</code> will survive the call on
<code>begin_image</code> (except for the color space in
<code>*pim->ColorSpace</code>): it should copy any necessary parts of
them into its own bookkeeping structure. It may, however, assume that
<code>*pis</code>, <b><tt>*pcpath</tt></b>, and of course
<code>*memory</code> will live at least until <b><tt>end_image</tt></b>
is called.
<p>
<code>begin_image</code> returns 0 normally, or 1 if the image does not
need any data. In the latter case, <code>begin_image</code> does not
allocate an enumeration structure.
</dl>
<dl>
<dt><code>int (*begin_typed_image)(gx_device *dev,
const gs_imager_state *pis, const gs_matrix *pmat,
const gs_image_common_t *pim, gs_int_rect *prect,
const gx_drawing_color *pdcolor,
const gx_clip_path *pcpath, gs_memory_t *memory,
gx_image_enum_common_t **pinfo)</code> <b><em>[OPTIONAL]</em></b>
<dd>This has the same function as <code>begin_image</code>, except
<ul>
<li>The image may be of any <code>ImageType</code>, not only
<code>image_type_simple</code> (1);
<li>The image format is included in the image structure, not supplied as a
separate argument;
<li>The optional <code>pmat</code> argument provides a matrix that
substitutes for the one in the imager state;
<li>For mask images, if <code>pmat</code> is not <b><tt>NULL</tt></b>
and the color is pure, <code>pis</code> may be <b><tt>NULL</tt></b>.
</ul>
</dl>
<p>
The actual transmission of data uses the procedures in the enumeration
structure, not driver procedures, since the handling of the data usually
depends on the image type and parameters rather than the device. These
procedures are specified as follows.
<dl>
<dt><code>int (*image_plane_data)(gx_device *dev,
gx_image_enum_common_t *info,
const gx_image_plane_t *planes, int height)</code>
<dd>This call provides more of the image source data: specifically,
<code>height</code> rows, with <b><tt>Width</tt></b> pixels supplied for
each row.
<p>
The data for each row are packed big-endian within each byte, as for
<code>copy_color</code>. The <b><tt>data_x</tt></b> (starting X position
within the row) and <code>raster</code> (number of bytes per row) are
specified separately for each plane, and may include some padding at the
beginning or end of each row. Note that for non-mask images, the input data
may be in any color space and may have any number of bits per component (1,
2, 4, 8, 12); currently mask images always have 1 bit per component, but in
the future, they might allow multiple bits of alpha. Note also that each
call of <code>image_plane_data</code> passes complete pixels: for example, for
a chunky image with 24 bits per pixel, each call of
<code>image_plane_data</code> passes 3N bytes of data (specifically,
3 × Width × height).
<p>
The interpretation of planes depends on the <code>format</code> member of
the <code>gs_image[_common]_t</code> structure:
<ul>
<li>If the format is <code>gs_image_format_chunky</code>,
<code>planes[0].data</code> points to data in "chunky" format, in which
the components follow each other (for instance, RGBRGBRGB....)
<li>If the format is <code>gs_image_format_component_planar</code>,
<code>planes[0 .. N-1].data</code> point to data for the
<b><em>N</em></b> components (for example, <b><em>N</em></b>=3 for RGB
data); each plane contains samples for a single component, for instance,
RR..., GG..., BB.... Note that the planes are divided by component, not by
bit: for example, for 24-bit RGB data, <b><em>N</em></b>=3, with 8-bit
values in each plane of data.
<li>If the format is <code>gs_image_format_bit_planar</code>,
<code>planes[0 .. N*B-1].data</code> point to data for the
<b><em>N</em></b> components of <b><em>B</em></b> bits each (for example,
<b><em>N</em></b>=3 and <b><em>B</em></b>=4 for RGB data with 4 bits per
component); each plane contains samples for a single bit, for instance, R0
R1 R2 R3 G0 G1 G2 G3 B0 B1 B2 B3. Note that the most significant bit of
each plane comes first.
</ul>
<p>
If, as a result of this call, <code>image_plane_data</code> has been called with all
the data for the (sub-)image, it returns 1; otherwise, it returns 0 or an
error code as usual.
<p>
<code>image_plane_data</code>, unlike most other procedures that take bitmaps as
arguments, does not require the data to be aligned in any way.
<p>
Note that for some image types, different planes may have different
numbers of bits per pixel, as defined in the <code>plane_depths</code> array.
</dl>
<dl>
<dt><code>int (*end_image)(gx_device *dev, void *info,
bool draw_last)</code>
<dd>Finish processing an image, either because all data have been supplied
or because the caller has decided to abandon this image.
<code>end_image</code> may be called at any time after
<code>begin_image</code>. It should free the info structure and any
subsidiary structures. If <code>draw_last</code> is true, it should
finish drawing any buffered lines of the image.
</dl>
<h5><a name="Images_notes"></a>Notes</h5>
<p>
While there will almost never be more than one image enumeration in
progress -- that is, after a <code>begin_image</code>,
<code>end_image</code> will almost always be called before the next
<code>begin_image</code> -- driver code should not rely on this
property; in particular, it should store all information regarding the
image in the info structure, not in the driver structure.
<p>
Note that if <code>begin_[typed_]image</code> saves its parameters in
the info structure, it can decide on each call whether to use its own
algorithms or to use the default implementation. (It may need to call
<code>gx_default_begin</code>/<b><tt>end_image</tt></b> partway
through.) [A later revision of this document may include an example here.]
<h4><a name="Text"></a>Text</h4>
<p>
The third high-level interface handles text. As for images, the interface
is based on creating an enumerator which then may execute the operation in
multiple steps. As for the other high-level interfaces, the procedures are
optional.
<dl>
<dt><code>int (*text_begin)(gx_device *dev,
gs_imager_state *pis, const gs_text_params_t *text,
gs_font *font, gx_path *path,
const gx_device_color *pdcolor,
const gx_clip_path *pcpath, gs_memory_t *memory,
gs_text_enum_t **ppte)</code> <b><em>[OPTIONAL]</em></b>
<dd>
Begin processing text, by creating a state structure and storing it in
<code>*ppte</code>. The parameters of <b><tt>text_begin</tt></b> are as
follows:
</dl>
<blockquote><table cellpadding=0 cellspacing=0>
<tr valign=top> <td><code>dev</code>
<td>
<td>The usual pointer to the device.
<tr valign=top> <td><code>pis</code>
<td>
<td>A pointer to an imager state. All elements may be relevant,
depending on how the text is rendered.
<tr valign=top> <td><code>text</code>
<td>
<td>A pointer to the structure that defines the text operation
and parameters. See <a href="../base/gstext.h">gstext.h</a> for details.
<tr valign=top> <td><code>font</code>
<td>
<td>Defines the font for drawing.
<tr valign=top> <td><code>path</code>
<td>
<td>Defines the path where the character outline will be appended
(if the text operation includes <code>TEXT_DO_...PATH</code>),
and whose current point indicates where drawing should occur
and will be updated by the string width (unless the text
operation includes <code>TEXT_DO_NONE</code>).
<tr valign=top> <td><code>pdcolor</code>
<td>
<td>Defines the drawing color for the text. Only relevant if
the text operation includes <code>TEXT_DO_DRAW</code>.
<tr valign=top> <td><code>pcpath</code>
<td>
<td>If not <code>NULL</code>, defines an optional clipping path.
Only relevant if the text operation includes
<code>TEXT_DO_DRAW</code>.
<tr valign=top> <td><code>memory</code>
<td>
<td>Defines the allocator to be used for allocating bookkeeping
information.
<tr valign=top> <td><code>ppte</code>
<td>
<td>The implementation should return a pointer to its state
structure here.
</table></blockquote>
<p>
<code>text_begin</code> must allocate a structure for its bookkeeping
needs, using the allocator defined by the <code>memory</code> parameter,
and return it in <code>*ppte</code>. <b><tt>text_begin</tt></b> may
assume that the structures passed as parameters will survive until text
processing is complete.
<p>
Clients should not call the driver <code>text_begin</code> procedure
directly. Instead, they should call <code>gx_device_text_begin</code>,
which takes the same parameters and also initializes certain common elements
of the text enumeration structure, or <code>gs_text_begin</code>, which
takes many of the parameters from a graphics state structure. For details,
see <a href="../base/gstext.h">gstext.h</a>.
<p>
The actual processing of text uses the procedures in the enumeration
structure, not driver procedures, since the handling of the text may depend
on the font and parameters rather than the device. Text processing may also
require the client to take action between characters, either because the
client requested it (<code>TEXT_INTERVENE</code> in the operation) or
because rendering a character requires suspending text processing to call an
external package such as the PostScript interpreter. (It is a deliberate
design decision to handle this by returning to the client, rather than
calling out of the text renderer, in order to avoid potentially unknown
stack requirements.) Specifically, the client must call the following
procedures, which in turn call the procedures in the text enumerator.
<dl>
<dt><code>int gs_text_process(gs_text_enum_t *pte)</code>
<dd>Continue processing text. This procedure may return 0 or a negative
error code as usual, or one of the following values (see
<a href="../base/gstext.h">gstext.h</a> for details).
<blockquote><table cellpadding=0 cellspacing=0>
<tr valign=top> <td><code>TEXT_PROCESS_RENDER</code>
<td>The client must cause the current character to be rendered.
This currently only is used for PostScript Type 0-4 fonts
and their CID-keyed relatives.
<tr valign=top> <td><code>TEXT_PROCESS_INTERVENE</code>
<td>The client has asked to intervene between characters.
This is used for <code>cshow</code> and <b><tt>kshow</tt></b>.
</table></blockquote>
</dl>
<dl>
<dt><code>int gs_text_release(gs_text_enum_t *pte,
client_name_t cname)</code> <dd>Finish processing text and release
all associated structures. Clients must call this procedure after
<code>gs_text_process</code> returns 0 or an error, and may call it at
any time.
</dl>
<p>
There are numerous other procedures that clients may call during text
processing. See <a href="../base/gstext.h">gstext.h</a> for details.
<h5><a name="Text_notes"></a>Notes</h5>
<p>
Note that unlike many other optional procedures, the default implementation
of <code>text_begin</code> cannot simply return: like the default
implementation of <code>begin[_typed]_image</code>, it must create and
return an enumerator. Furthermore, the implementation of the
<code>process</code> procedure (in the enumerator structure, called by
<code>gs_text_process</code>) cannot simply return without doing
anything, even if it doesn't want to draw anything on the output. See the
comments in <a href="../base/gxtext.h">gxtext.h</a> for details.
<h4><a name="Unicode"></a>Unicode support for high level devices</h4>
<p>
<p>Implementing a new high level device, one may need to translate <code>Postscript</code>
character codes into <code>Unicode</code>. This can be done pretty simply.
<p>For translating a <code>Postscript</code> text you need to inplement the device
virtual function <code>text_begin</code>. It should create a new instance of
<code>gs_text_enum_t</code> in the heap (let its pointer be <b><tt>pte</tt></b>),
and assign a special function to <code>gs_text_enum_t::procs.process</code>.
The function will receive <code>pte</code>. It should take the top level font from
<code>pte->orig_font</code>,
and iterate with <code>font->procs.next_char_glyph(pte, ..., &glyph)</code>.
The last argument receives a <code>gs_glyph</code> value, which encodes a
<code>Postscript</code> character name or CID (and also stores it into
<code>pte->returned.current_glyph</code>).
Then obtain the current subfont with <code>gs_text_current_font(pte)</code>
(it can differ from the font)
and call <code>subfont->procs.decode_glyph(subfont, glyph)</code>.
The return value will be an <code>Unicode</code> code, or <b><tt>GS_NO_CHAR</tt></b>
if the glyph can't be translated to Unicode.
<h3><a name="Reading_bits_back"></a>Reading bits back</h3>
<dl>
<dt><code>int (*get_bits_rectangle)(gx_device *dev,
const gs_int_rect *prect, gs_get_bits_params_t *params,
gs_int_rect **unread)</code> <b><em>[OPTIONAL]</em></b>
<dd>
Read a rectangle of bits back from the device. The <code>params</code>
structure consists of:
<table cellpadding=0 cellspacing=0>
<tr valign=top> <td><code>options</code>
<td>
<td>the allowable formats for returning the data
<tr valign=top> <td><code>data[32]</code>
<td>
<td>pointers to the returned data
<tr valign=top> <td><code>x_offset</code>
<td>
<td>the X offset of the first returned pixel in data
<tr valign=top> <td><code>raster</code>
<td>
<td>the distance between scan lines in the returned data
</table>
<p>
<code>options</code> is a bit mask specifying what formats the client is
willing to accept. (If the client has more flexibility, the implementation
may be able to return the data more efficiently, by avoiding representation
conversions.) The options are divided into groups.
<blockquote><dl>
<dt><b><em>alignment</em></b>
<dd>Specifies whether the returned data must be aligned in the normal
manner for bitmaps, or whether unaligned data are acceptable.
<dt><b><em>pointer or copy</em></b>
<dd>Specifies whether the data may be copied into storage provided by the
client and/or returned as pointers to existing storage. (Note that if
copying is not allowed, it is much more likely that the implementation will
return an error, since this requires that the client accept the data in the
implementation's internal format.)
<dt><b><em>X offset</em></b>
<dd>Specifies whether the returned data must have a specific X offset
(usually zero, but possibly other values to avoid skew at some later stage
of processing) or whether it may have any X offset (which may avoid skew in
the <code>get_bits_rectangle</code> operation itself).
<dt><b><em>raster</em></b>
<dd>Specifies whether the raster (distance between returned scan lines)
must have its standard value, must have some other specific value, or may
have any value. The standard value for the raster is the device width
padded out to the alignment modulus when using pointers, or the minimum
raster to accommodate the X offset + width when copying (padded out to the
alignment modulus if standard alignment is required).
<dt><b><em>format</em></b>
<dd>Specifies whether the data are returned in chunky (all components of a
single pixel together), component-planar (each component has its own scan
lines), or bit-planar (each bit has its own scan lines) format.
<dt><b><em>color space</em></b>
<dd>Specifies whether the data are returned as native device pixels, or in
a standard color space. Currently the only supported standard space is
RGB.
<dt><b><em>standard component depth</em></b>
<dd>Specifies the number of bits per component if the data are returned in
the standard color space. (Native device pixels use
<code>dev</code>-><b><tt>color_info.depth</tt></b> bits per pixel.)
<dt><b><em>alpha</em></b>
<dd>Specifies whether alpha channel information should be returned as the
first component, the last component, or not at all. Note that for devices
that have no alpha capability, the returned alpha values will be all 1s.
</dl></blockquote>
<p>
The client may set more than one option in each of the above groups; the
implementation will choose one of the selected options in each group to
determine the actual form of the returned data, and will update
<code>params[].options</code> to indicate the form. The returned
<code>params[].options</code> will normally have only one option set per
group.
<p>
For further details on <code>params</code>, see <a
href="../base/gxgetbit.h">gxgetbit.h</a>. For further details on
<code>options</code>, see <a href="../base/gxbitfmt.h">gxbitfmt.h</a>.
<p>
Define w = <code>prect</code>->q.x - <b><tt>prect</tt></b>->p.x, h
= <code>prect</code>->q.y - <b><tt>prect</tt></b>->p.y. If the
bits cannot be read back (for example, from a printer), return
<code>gs_error_unknownerror</code>; if raster bytes is not enough space
to hold <code>offset_x</code> + w pixels, or if the source rectangle
goes outside the device dimensions (p.x < 0 || p.y < 0 || q.x >
<code>dev</code>->width || q.y > <b><tt>dev</tt></b>->height),
return <code>gs_error_rangecheck</code>; if any regions could not be
read, return <code>gs_error_ioerror</code> if unpainted is
<code>NULL</code>, otherwise the number of rectangles (see below);
otherwise return 0.
<p>
The caller supplies a buffer of <code>raster</code> × h
bytes starting at <code>data[0]</code> for the returned data in chunky
format, or <b><em>N</em></b> buffers of
<code>raster</code> × h bytes starting at
<code>data[0]</code> through
<code>data[</code><b><em>N-1</em></b><b><tt>]</tt></b> in planar format
where <b><em>N</em></b> is the number of components or bits. The contents
of the bits beyond the last valid bit in each scan line (as defined by w)
are unpredictable. data need not be aligned in any way. If
<code>x_offset</code> is non-zero, the bits before the first valid bit
in each scan line are undefined. If the implementation returns pointers to
the data, it stores them into <code>data[0]</code> or
<code>data[</code><b><em>0..N-1</em></b><b><tt>]</tt></b>.
<p>
If not all the source data are available (for example, because the source
was a partially obscured window and backing store was not available or not
used), or if the rectangle does not fall completely within the device's
coordinate system, any unread bits are undefined, and the value returned
depends on whether unread is <code>NULL</code>. If unread is
<code>NULL</code>, return <b><tt>gs_error_ioerror</tt></b>; in this case,
some bits may or may not have been read. If unread is not
<code>NULL</code>, allocate (using <b><tt>dev</tt></b>->memory) and
fill in a list of rectangles that could not be read, store the pointer to
the list in <code>*unread</code>, and return the number of rectangles; in
this case, all bits not listed in the rectangle list have been read back
properly. The list is not sorted in any particular order, but the
rectangles do not overlap. Note that the rectangle list may cover a
superset of the region actually obscured: for example, a lazy implementation
could return a single rectangle that was the bounding box of the region.
</dl>
<dl>
<dt><code>int (*get_bits)(gx_device *dev, int y,
byte *data, byte **actual_data)</code>
<b><em>[OPTIONAL]</em></b>
<dd>Read scan line <code>y</code> of bits back from the device into the
area starting at data. This call is functionally equivalent to
<blockquote>
<pre>(*get_bits_rectangle)
(dev, {0, y, dev->width, y+1},
{(GB_ALIGN_ANY | (GB_RETURN_COPY | GB_RETURN_POINTER) | GB_OFFSET_0 |
GB_RASTER_STANDARD | GB_FORMAT_CHUNKY | GB_COLORS_NATIVE |
GB_ALPHA_NONE),
{data}})</pre></blockquote>
<p>
with the returned value of
<code>params</code>-><b><tt>data[0]</tt></b> stored in
<code>*actual_data</code>, and will in fact be implemented this way if
the device defines a <code>get_bits_rectangle</code> procedure and does
not define one for <code>get_bits</code>. (If
<code>actual_data</code> is <b><tt>NULL</tt></b>,
<code>GB_RETURN_POINTER</code> is omitted from the options.)
</dl>
<h3><a name="Parameters"></a>Parameters</h3>
<p>
Devices may have an open-ended set of parameters, which are simply pairs
consisting of a name and a value. The value may be of various types:
integer (int or long), boolean, float, string, name, <code>NULL</code>,
array of integer, array of float, or arrays or dictionaries of mixed types.
For example, the <code>Name</code> of a device is a string; the
<code>Margins</code> of a device is an array of two floats. See
<a href="../base/gsparam.h">gsparam.h</a> for more details.
<p>
If a device has parameters other than the ones applicable to all devices
(or, in the case of printer devices, all printer devices), it must provide
<code>get_params</code> and <b><tt>put_params</tt></b> procedures. If
your device has parameters beyond those of a straightforward display or
printer, we strongly advise using the <code>_get_params</code> and
<code>_put_params</code> procedures in an existing device (for example,
<a href="../base/gdevcdj.c">gdevcdj.c</a> or <a
href="../base/gdevbit.c">gdevbit.c</a>) as a model for your own code.
<dl>
<dt><code>int (*get_params)(gx_device *dev,
gs_param_list *plist)</code> <b><em>[OPTIONAL]</em></b>
<dd>Read the parameters of the device into the parameter list at
<code>plist</code>, using the <b><tt>param_write_*</tt></b>
macros or procedures defined in <a href="../base/gsparam.h">gsparam.h</a>.
</dl>
<dl>
<dt><code>int (*get_hardware_params)(gx_device *dev,
gs_param_list *plist)</code> <b><em>[OPTIONAL]</em></b>
<dd>Read the hardware-related parameters of the device into the parameter
list at plist. These are any parameters whose values are under control of
external forces rather than the program -- for example, front panel
switches, paper jam or tray empty sensors, etc. If a parameter involves
significant delay or hardware action, the driver should only determine the
value of the parameter if it is "requested" by the
<code>gs_param_list</code> [<b><tt>param_requested</tt></b>(plist,
<code>key_name</code>)]. This function may cause the asynchronous
rendering pipeline (if enabled) to be drained, so it should be used
sparingly.
</dl>
<dl>
<dt><code>int (*put_params)(gx_device *dev,
gs_param_list *plist)</code> <b><em>[OPTIONAL]</em></b>
<dd>Set the parameters of the device from the parameter list at
<code>plist</code>, using the <b><tt>param_read_</tt></b>*
macros/procedures defined in <a href="../base/gsparam.h">gsparam.h</a>. All
<code>put_params</code> procedures must use a "two-phase commit"
algorithm; see <a href="../base/gsparam.h">gsparam.h</a> for details.
</dl>
<h4><a name="Default_CRD_parameters"></a>Default color rendering
dictionary (CRD) parameters</h4>
<p>
Drivers that want to provide one or more default CIE color rendering
dictionaries (CRDs) can do so through <code>get_params</code>. To do
this, they create the CRD in the usual way (normally using the
<code>gs_cie_render1_build</code> and <b><tt>_initialize</tt></b>
procedures defined in <a href="../base/gscrd.h">gscrd.h</a>), and then write
it as a parameter using <code>param_write_cie_render1</code> defined in
<a href="../base/gscrdp.h">gscrdp.h</a>. However, the TransformPQR procedure
requires special handling. If the CRD uses a TransformPQR procedure
different from the default (identity), the driver must do the following:
<ul>
<li>The TransformPQR element of the CRD must include a
<code>proc_name</code>, and optionally <b><tt>proc_data</tt></b>. The
<code>proc_name</code> is an arbitrary name chosen by the driver to
designate the particular TransformPQR function. It must not be the same as
any device parameter name; we strongly suggest it include the device name,
for instance, "<code>bitTPQRDefault</code>".
<li>For each such named TransformPQR procedure, the driver's
<code>get_param</code> procedure must provide a parameter of the same
name. The parameter value must be a string whose bytes are the actual
procedure address.
</ul>
<p>
For a complete example, see the <code>bit_get_params</code> procedure in
<a href="../base/gdevbit.c">gdevbit.c</a>. Note that it is essential that
the driver return the CRD or the procedure address only if specifically
requested (<code>param_requested(...)</code> > 0); otherwise, errors
will occur.
<h3><a name="External_fonts"></a>External fonts</h3>
<p>
Drivers may include the ability to display text. More precisely, they may
supply a set of procedures that in turn implement some font and text
handling capabilities, described in <a href="Xfonts.htm">a separate
document</a>. The link between the two is the driver procedure that
supplies the font and text procedures:
<dl>
<dt><code>xfont_procs *(*get_xfont_procs)(gx_device *dev)</code> <b><em>[OPTIONAL]</em></b>
<dd>Return a structure of procedures for handling external fonts and text
display. A <code>NULL</code> value means that this driver doesn't
provide this capability.
</dl>
<p>
For technical reasons, a second procedure is also needed:
<dl>
<dt><code>gx_device *(*get_xfont_device)(gx_device *dev)</code> <b><em>[OPTIONAL]</em></b>
<dd>Return the device that implements <code>get_xfont_procs</code> in a
non-default way for this device, if any. Except for certain special
internal devices, this is always the device argument.
</dl>
<h3><a name="Page_devices"></a>Page devices</h3>
<dl>
<dt><code>gx_device *(*get_page_device)(gx_device *dev)</code>
<b><em>[OPTIONAL]</em></b>
<dd>According to the Adobe specifications, some devices are "page devices"
and some are not. This procedure returns <code>NULL</code> if the
device is not a page device, or the device itself if it is a page device.
In the case of forwarding devices, <code>get_page_device</code> returns
the underlying page device (or <code>NULL</code> if the underlying
device is not a page device).
</dl>
<h3><a name="Miscellaneous"></a>Miscellaneous</h3>
<dl>
<dt><code>int (*get_band)(gx_device *dev, int y,
int *band_start)</code> <b><em>[OPTIONAL]</em></b>
<dd>If the device is a band device, this procedure stores in
<code>*band_start</code> the scan line (device Y coordinate) of the band
that includes the given Y coordinate, and returns the number of scan lines
in the band. If the device is not a band device, this procedure returns 0.
The latter is the default implementation.
</dl>
<dl>
<dt><code>void (*get_clipping_box)(gx_device *dev,
gs_fixed_rect *pbox))</code> <b><em>[OPTIONAL]</em></b>
<dd>Stores in <code>*pbox</code> a rectangle that defines the device's
clipping region. For all but a few specialized devices, this is
<em>((0,0),(width,height))</em>.
</dl>
<hr>
<h2><a name="Tray"></a>Tray selection</h2>
<!-- Note for documentation maintainers: tray selection overlaps -->
<!-- significantly across the device interface and the PostScript -->
<!-- language implementation of setpagedevice, while the rest of -->
<!-- Drivers.htm focusses on lanugage-independent interfaces. Likely -->
<!-- the documentation should be refactored a bit so that this section -->
<!-- has a comfortable home. -->
<p>The logic for selecting input trays, and modifying other parameters
based on tray selection, can be complex and subtle, largely thanks to
the requirement to be compatible with the PostScript language
setpagedevice mechanism. This section will describe recipes for
several common scenarios for tray selection, with special attention to
the how the overall task factors into configuration options, generic
logic provided by the PostScript language (or not, if the device is
used with other PDL's), and implementation of the put_param /
get_param device functions within the device.
<p>In general, tray selection is determined primarily through the
setpagedevice operator, which is part of the PostScript runtime.
Ghostscript attempts to be as compatible as is reasonable with the
PostScript standard, so for more details, see the description in the
<a
href="http://partners.adobe.com/public/developer/ps/index_specs.html">PostScript
language specifications</a>, including the "supplements", which tend
to have more detail about setpagedevice behavior than the PLRM book itself.
<p>The first step is to set up an /InputAttributes dictionary matching
the trays and so on available in the device. The standard Ghostscript
initialization files set up a large InputAttributes dictionary with
many "known" page sizes (the full list is in
<code>gs_statd.ps</code>, under .setpagesize). It's possible to
edit this list in the Ghostscript source, of course, but most of the
time it is better to execute a snippet of PostScript code after the
default initialization but before sending any actual jobs.
<p>Simply setting a new /InputAttributes dictionary with setpagedevice
will not work, because the the language specification for
setpagedevice demands a "merging" behavior - paper tray keys present
in the old dictionary will be preserved even if the key is not present
in the new /InputAttributes dictionary. Here is a sample invocation
that clears out all existing keys, and installs three new ones: a US letter
page size for trays 0 and 1, and 11x17 for tray 1. Note that you must add at
least one valid entry into the /InputAttributes dictionary; if all are
<code>null</code>, then the setpagedevice will fail with a
/configurationerror.
<blockquote><code>
<< /InputAttributes<br />
currentpagedevice /InputAttributes get<br />
dup { pop 1 index exch null put } forall<br />
<br />
dup 0 << /PageSize [612 792] >> put<br />
dup 1 << /PageSize [612 792] >> put<br />
dup 2 << /PageSize [792 1224] >> put<br />
>> setpagedevice<br />
</code></blockquote>
<p>After this code runs, then requesting a letter page size (612x792
points) from setpagedevice will select tray 0, and requesting an 11x17
size will select tray 2. To explicitly request tray 1, run:
<blockquote><code>
<< /PageSize [612 792] /MediaPosition 1 >> setpagedevice
</code></blockquote>
<p>At this point, the chosen tray is sent to the device as the
(nonstandard) %MediaSource device parameter. Devices with switchable
trays should implement this device parameter in the
<code>put_params</code> procedure. Unlike the usual protocol for
device parameters, it is not necessary for devices to also implement
<code>get_params</code> querying of this paramter; it is
effectively a write-only communication from the language to the
device. Currently, among the devices that ship with Ghostscript, only
PCL (gdevdjet.c) and PCL/XL (gdevpx.c) implement this parameter, but
that list may well grow over time.
If the device has dynamic configuration of trays, etc., then the
easiest way to get that information into the tray selection logic is
to send a setpagedevice request (if using the standard API, then using
gsapi_run_string_continue) to update the /InputAttributes dictionary
immediately before beginning a job.
<h3><a name="LeadingEdge"></a>Tray rotation and the LeadingEdge parameter</h3>
<p>Large, sophisticated printers often have multiple trays supporting
both short-edge and long-edge feed. For example, if the paper path is
11 inches wide, then 11x17 pages must always print short-edge, but
letter size pages print with higher throughput if fed from long-edge
trays. Generally, the device will expect the rasterized bitmap image
to be rotated with respect to the page, so that it's always the same
orientation with respect to the paper feed direction.
<p>The simplest way to achieve this behavior is to call
<code>gx_device_request_leadingedge</code> to request a LeadingEdge
value
<code>LeadingEdge</code> field in the device structure based on the
%MediaSource tray selection index and knowledge of the device's
trays. The default put_params implementation will then handle this
request (it's done this way to preserve the transactional semantics of
put_params; it needs the new value, but the changes can't actually be
made until all params succeed). For example, if tray 0 is long-edge,
while trays 1 and 2 are short-edge, the following code outline should
select the appropriate rotation:
<blockquote><code>
my_put_params(gx_device *pdev, gs_param_list *plist) {<br />
my_device *dev = (my_device *)pdev;<br />
int MediaSource = dev->myMediaSource;<br />
<br />
code = param_read_int(plist, "%MediaSource", &MediaSource);<br />
<br />
switch (MediaSource) {<br />
case 0:<br />
gx_device_req_leadingedge(dev, 1);<br />
break;<br />
case 1:<br />
case 2:<br />
gx_device_req_leadingedge(dev, 0);<br />
break;<br />
}<br />
...call default put_params, which makes the change...<br />
<br />
dev->myMediaSource = MediaSource;<br />
return 0;<br />
}
</code></blockquote>
<p>Ghostscript also supports explicit rotation of the page through
setting the /LeadingEdge parameter with setpagedevice. The above code
snippet will simply override this request. To give manual setting
through setpagedevice priority, don't change the LeadingEdge field in
the device if its LEADINGEDGE_SET_MASK bit is set. In other words,
simply enclose the above <tt>switch</tt> statement inside an <code>if
(!(dev->LeadingEdge & LEADINGEDGE_SET_MASK) { ... }</code> statement.
<!-- Note for doc maintainers: the following is much more of a -->
<!-- discussion of the PS language than a device interface issue, but -->
<!-- it is essential info for people implementing this stuff. -->
<h3><a name="LeadingPage"></a>Interaction between LeadingEdge and PageSize</h3>
<p>As of LanguageLevel 3, PostScript now has two mechanisms for rotating
the imaging of the page: the LeadingEdge parameter described in detail
above, and the automatic rotation as enabled by the /PageSize page
device parameter (described in detail in Table 6.2 of the PLRM3).
Briefly, the PageSize autorotation handles the case where the page
size requested in setpagedevice matches the <i>swapped</i> size of the
paper source (as set in the InputAttributesDictionary). This mechanism
can be, and has been, used to implement long-edge feed, but has
several disadvantages. Among other things, it's overly tied to the PostScript
language, while the device code above will work with other
languages. Also, it only specifies one direction of rotation (90
degrees counterclockwise). Thus, given the choice, LeadingEdge is to
be preferred.
<p>If PageSize is used, the following things are different:
<ul>
<li>The PageSize array in InputAttributes is swapped, so it is [long
short].
<li>The .MediaSize device parameter is similarly swapped.
<li>The initial matrix established by the device through the
<code>get_initial_matrix</code> procedure is the same as for the
non-rotated case.
<li>The CTM rotation is done in the setpagedevice implementation.
</ul>
<!-- Why oh why does it all have to be so complicated? -->
<!-- [2.0 end contents] ==================================================== -->
<!-- [3.0 begin visible trailer] =========================================== -->
<hr>
<p>
<small>Copyright © 2000-2007 Artifex Software, Inc. All rights reserved.</small>
<p>
This software is provided AS-IS with no warranty, either express or
implied.
This software is distributed under license and may not be copied, modified
or distributed except as expressly authorized under the terms of that
license. Refer to licensing information at http://www.artifex.com/
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
<p>
<small>Ghostscript version 9.01, 7 February 2011
<!-- [3.0 end visible trailer] ============================================= -->
</small></body>
</html>
|