Commit d89489210a9a410fd93288b11813313374fe1502

David Turner 2000-05-02T13:29:29

ftrast.c

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
diff --git a/demos/src/ftrast.c b/demos/src/ftrast.c
new file mode 100644
index 0000000..4f5c895
--- /dev/null
+++ b/demos/src/ftrast.c
@@ -0,0 +1,2905 @@
+/*******************************************************************
+ *
+ *  ftraster.c                                                  1.5
+ *
+ *  The FreeType glyph rasterizer (body).
+ *
+ *  Copyright 1996-2000 by
+ *  David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ *  This file is part of the FreeType project, and may only be used
+ *  modified and distributed under the terms of the FreeType project
+ *  license, LICENSE.TXT. By continuing to use, modify, or distribute
+ *  this file you indicate that you have read the license and
+ *  understand and accept it fully.
+ *
+ *
+ *  This is a rewrite of the FreeType 1.x scan-line converter
+ *
+ *
+ *
+ ******************************************************************/
+
+#include "frast.h"
+#include <ftcalc.h>      /* for FT_MulDiv only */
+
+  /****************************************************************/
+  /****************************************************************/
+  /**                                                            **/
+  /**  CONFIGURATION MACROS                                      **/
+  /**                                                            **/
+  /****************************************************************/
+  /****************************************************************/
+
+/* define DEBUG_RASTER if you want to compile a debugging version */
+#define xxxDEBUG_RASTER
+
+/* required by the tracing mode */
+#undef  FT_COMPONENT
+#define FT_COMPONENT      trace_raster
+
+#include <ftdebug.h>
+
+
+/* The default render pool size */
+#define  RASTER_RENDER_POOL   8192
+
+/* The size of the two-lines intermediate bitmap used */
+/* for anti-aliasing                                  */
+#define  RASTER_GRAY_LINES    1024
+
+#define Raster_Err_None              TT_Err_Ok
+#define Raster_Err_Not_Ini           TT_Err_Raster_Not_Initialized
+#define Raster_Err_Overflow          TT_Err_Raster_Pool_Overflow
+#define Raster_Err_Neg_Height        TT_Err_Raster_Negative_Height
+#define Raster_Err_Invalid           TT_Err_Raster_Invalid_Value
+#define Raster_Err_Gray_Unsupported  TT_Err_Raster_Gray_Unsupported
+
+
+/* FMulDiv means "Fast MulDiv", it is uses in case where 'b' is typically */
+/* a small value and the result of (a*b) is known to fit in 32 bits.      */
+#define FMulDiv( a, b, c )  ( (a) * (b) / (c) )
+
+/* On the other hand, SMulDiv is for "Slow MulDiv", and is used typically */
+/* for clipping computations.  It simply uses the TT_MulDiv() function    */
+/* defined in "ttcalc.h"                                                  */
+/*                                                                        */
+/* So, the following definition fits the bill nicely, and we don't need   */
+/* to use the one in 'ttcalc' anymore, even for 16-bit systems...         */
+#define SMulDiv   FT_MulDiv
+
+
+
+/* The rasterizer is a very general purpose component, please leave */
+/* the following redefinitions there (you never know your target    */
+/* environment).                                                    */
+
+#ifndef TRUE
+#define TRUE   1
+#endif
+
+#ifndef FALSE
+#define FALSE  0
+#endif
+
+#ifndef NULL
+#define NULL  (void*)0
+#endif
+
+
+
+
+#define MaxBezier  32   /* The maximum number of stacked Bezier curves. */
+                        /* Setting this constant to more than 32 is a   */
+                        /* pure waste of space.                         */
+
+#define Pixel_Bits  6   /* fractional bits of *input* coordinates */
+
+  /****************************************************************/
+  /****************************************************************/
+  /**                                                            **/
+  /**  SIMPLE TYPE DECLARATIONS                                  **/
+  /**                                                            **/
+  /****************************************************************/
+  /****************************************************************/
+  
+  typedef int            Int;
+  typedef unsigned int   UInt;
+  typedef short          Short;
+  typedef unsigned short UShort, *PUShort;
+  typedef long           Long, *PLong;
+  typedef unsigned long  ULong;
+  
+  typedef unsigned char  Byte, *PByte;
+  typedef char           Bool;
+
+  typedef struct TPoint_
+  {
+    Long  x;
+    Long  y;
+    
+  } TPoint;
+
+
+  typedef enum TFlow_
+  {
+    Flow_None = 0,
+    Flow_Up,
+    Flow_Down
+  
+  } TFlow;
+
+
+  /* States of each line, arc and profile */
+  typedef enum  TStates_
+  {
+    Unknown,
+    Ascending,
+    Descending,
+    Flat
+    
+  } TStates;
+
+
+  typedef struct TProfile_  TProfile;
+  typedef TProfile*         PProfile;
+
+  struct  TProfile_
+  {
+    FT_F26Dot6  X;           /* current coordinate during sweep          */
+    PProfile    link;        /* link to next profile - various purpose   */
+    PStorage    offset;      /* start of profile's data in render pool   */
+    Int         flow;        /* Profile orientation: Asc/Descending      */
+    Long        height;      /* profile's height in scanlines            */
+    Long        start;       /* profile's starting scanline              */
+
+    UShort      countL;      /* number of lines to step before this      */
+                             /* profile becomes drawable                 */
+
+    PProfile    next;        /* next profile in same contour, used       */
+                             /* during drop-out control                  */
+  };
+
+  typedef PProfile   TProfileList;
+  typedef PProfile*  PProfileList;
+
+
+  /* Simple record used to implement a stack of bands, required */
+  /* by the sub-banding mechanism                               */
+  typedef struct  TBand_
+  {
+    Short  y_min;   /* band's minimum */
+    Short  y_max;   /* band's maximum */
+    
+  } TBand;
+
+
+
+#define AlignProfileSize \
+          (( sizeof(TProfile)+sizeof(long)-1 ) / sizeof(long))
+
+
+  /* Left fill bitmask */
+  static const Byte  LMask[8] =
+    { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01 };
+
+  /* Right fill bitmask */
+  static const Byte  RMask[8] =
+    { 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF };
+
+  /* We provide two different builds of the scan-line converter  */
+  /* The static build uses global variables and isn't            */
+  /* re-entrant.                                                 */
+  /* The indirect build is re-entrant but accesses all variables */
+  /* indirectly.                                                 */
+  /*                                                             */
+  /* As a consequence, the indirect build is about 10% slower    */
+  /* than the static one on a _Pentium_ (this could get worse    */
+  /* on older processors), but the code size is reduced by       */
+  /* more than 30% !                                             */
+  /*                                                             */
+  /* The indirect build is now the default, defined in           */
+  /* ttconfig.h.  Be careful if you experiment with this.        */
+
+  /* Note also that, though its code can be re-entrant, the      */
+  /* component is always used in thread-safe mode.  This is      */
+  /* simply due to the fact that we want to use a single         */
+  /* render pool (of 64 Kb), and not to waste memory.            */
+
+#ifdef TT_STATIC_RASTER
+
+#define  RAS_ARGS  /* void */
+#define  RAS_ARG   /* void */
+
+#define  RAS_VARS  /* void */
+#define  RAS_VAR   /* void */
+
+#else
+
+#define  RAS_ARGS  TRaster_Instance*  raster,
+#define  RAS_ARG   TRaster_Instance*  raster
+
+#define  RAS_VARS  raster,
+#define  RAS_VAR   raster
+
+#endif
+
+
+  typedef struct TRaster_Instance_  TRaster_Instance;
+
+
+  /* prototypes used for sweep function dispatch */
+  typedef void  Function_Sweep_Init( RAS_ARGS Short*  min,
+                                              Short*  max );
+
+  typedef void  Function_Sweep_Span( RAS_ARGS Short       y,
+                                              FT_F26Dot6  x1,
+                                              FT_F26Dot6  x2,
+                                              PProfile    left,
+                                              PProfile    right );
+
+  typedef void  Function_Sweep_Step( RAS_ARG );
+
+
+/* NOTE: These operations are only valid on 2's complement processors */
+
+#define FLOOR( x )    ( (x) & -ras.precision )
+#define CEILING( x )  ( ((x) + ras.precision - 1) & -ras.precision )
+#define TRUNC( x )    ( (signed long)(x) >> ras.precision_bits )
+#define FRAC( x )     ( (x) & (ras.precision - 1) )
+#define SCALED( x )   ( ((x) << ras.scale_shift) - ras.precision_half )
+
+  /* Note that I have moved the location of some fields in the */
+  /* structure to ensure that the most used variables are used */
+  /* at the top.  Thus, their offset can be coded with less    */
+  /* opcodes, and it results in a smaller executable.          */
+
+  struct  TRaster_Instance_
+  {
+    Int       precision_bits;       /* precision related variables */
+    Int       precision;
+    Int       precision_half;
+    Long      precision_mask;
+    Int       precision_shift;
+    Int       precision_step;
+    Int       precision_jitter;
+
+    Int       scale_shift;        /* == precision_shift   for bitmaps */
+                                  /* == precision_shift+1 for pixmaps */
+
+    PLong     buff;                 /* The profiles buffer          */
+    PLong     sizeBuff;             /* Render pool size             */
+    PLong     maxBuff;              /* Profiles buffer size         */
+    PLong     top;                  /* Current cursor in buffer     */
+
+    FT_Error  error;
+
+    PByte     flags;                /* current flags table    */
+    PUShort   outs;                 /* current outlines table */
+
+    UShort    nPoints;              /* number of points in current glyph   */
+    Short     nContours;            /* number of contours in current glyph */
+    Int       numTurns;             /* number of Y-turns in outline        */
+
+    TPoint*   arc;                  /* current Bezier arc pointer */
+
+    UShort    bWidth;               /* target bitmap width  */
+    PByte     bTarget;              /* target bitmap buffer */
+    PByte     gTarget;              /* target pixmap buffer */
+
+    Long      lastX, lastY, minY, maxY;
+
+    UShort    num_Profs;            /* current number of profiles */
+
+    Bool      fresh;                /* signals a fresh new profile which */
+                                    /* 'start' field must be completed   */
+    Bool      joint;                /* signals that the last arc ended   */
+                                    /* exactly on a scanline.  Allows    */
+                                    /* removal of doublets               */
+    PProfile  cProfile;             /* current profile                   */
+    PProfile  fProfile;             /* head of linked list of profiles   */
+    PProfile  gProfile;             /* contour's first profile in case   */
+                                    /* of impact                         */
+    TStates   state;                /* rendering state */
+
+    FT_Bitmap target;          /* description of target bit/pixmap */
+
+    Long      traceOfs;             /* current offset in target bitmap */
+    Long      traceG;               /* current offset in target pixmap */
+
+    Short     traceIncr;            /* sweep's increment in target bitmap */
+
+    Short     gray_min_x;           /* current min x during gray rendering */
+    Short     gray_max_x;           /* current max x during gray rendering */
+
+    /* dispatch variables */
+
+    Function_Sweep_Init*  Proc_Sweep_Init;
+    Function_Sweep_Span*  Proc_Sweep_Span;
+    Function_Sweep_Span*  Proc_Sweep_Drop;
+    Function_Sweep_Step*  Proc_Sweep_Step;
+
+    FT_Vector*  coords;
+
+    Byte      dropOutControl;       /* current drop_out control method */
+
+    Byte      grays[5];         /* Palette of gray levels used for render */
+
+    Byte*     gray_lines;       /* Intermediate table used to render the   */
+                                /* graylevels pixmaps.                     */
+                                /* gray_lines is a buffer holding two      */
+                                /* monochrome scanlines                    */
+    Short     gray_width;       /* width in bytes of one monochrome        */
+                                /* intermediate scanline of gray_lines.    */
+                                /* Each gray pixel takes 2 bits long there */
+
+                        /* The gray_lines must hold 2 lines, thus with size */
+                        /* in bytes of at least 'gray_width*2'              */
+
+    Bool      second_pass;      /* indicates wether a horizontal pass      */
+                                /* should be performed to control drop-out */
+                                /* accurately when calling Render_Glyph.   */
+                                /* Note that there is no horizontal pass   */
+                                /* during gray rendering.                  */
+    TPoint    arcs[2 * MaxBezier + 1];      /* The Bezier stack */
+
+    TBand     band_stack[16];       /* band stack used for sub-banding */
+    Int       band_top;             /* band stack top                  */
+
+    Int       count_table[256];     /* Look-up table used to quickly count */
+                                    /* set bits in a gray 2x2 cell         */
+  };
+
+
+#ifdef FT_CONFIG_OPTION_STATIC_RASTER
+
+  static TRaster_Instance  cur_ras;
+  #define ras  cur_ras
+  
+#else
+
+  #define ras  (*raster)
+
+#endif /* FT_STATIC_RASTER */
+
+  /****************************************************************/
+  /****************************************************************/
+  /**                                                            **/
+  /**  PROFILES COMPUTATION                                      **/
+  /**                                                            **/
+  /****************************************************************/
+  /****************************************************************/
+  
+
+/************************************************************************/
+/*                                                                      */
+/* Function:    Set_High_Precision                                      */
+/*                                                                      */
+/* Description: Sets precision variables according to param flag.       */
+/*                                                                      */
+/* Input:       High     set to True for high precision (typically for  */
+/*                       ppem < 18), false otherwise.                   */
+/*                                                                      */
+/************************************************************************/
+
+  static void  Set_High_Precision( RAS_ARGS Bool  High )
+  {
+    if ( High )
+    {
+      ras.precision_bits   = 10;
+      ras.precision_step   = 128;
+      ras.precision_jitter = 24;
+    }
+    else
+    {
+      ras.precision_bits   = 6;
+      ras.precision_step   = 32;
+      ras.precision_jitter = 2;
+    }
+
+    FT_TRACE7(( "Set_High_Precision(%s)\n", High ? "true" : "false" ));
+
+    ras.precision       = 1L << ras.precision_bits;
+    ras.precision_half  = ras.precision / 2;
+    ras.precision_shift = ras.precision_bits - Pixel_Bits;
+    ras.precision_mask  = -ras.precision;
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    New_Profile                                                 */
+/*                                                                          */
+/* Description: Creates a new Profile in the render pool.                   */
+/*                                                                          */
+/* Input:       aState   state/orientation of the new Profile               */
+/*                                                                          */
+/* Returns:     SUCCESS on success.                                         */
+/*              FAILURE in case of overflow or of incoherent Profile.       */
+/*                                                                          */
+/****************************************************************************/
+
+  static Bool  New_Profile( RAS_ARGS TStates  aState )
+  {
+    if ( !ras.fProfile )
+    {
+      ras.cProfile  = (PProfile)ras.top;
+      ras.fProfile  = ras.cProfile;
+      ras.top      += AlignProfileSize;
+    }
+
+    if ( ras.top >= ras.maxBuff )
+    {
+      ras.error = Raster_Err_Overflow;
+      return FAILURE;
+    }
+
+    switch ( aState )
+    {
+    case Ascending:
+      ras.cProfile->flow = FT_Flow_Up;
+      FT_TRACE7(( "New ascending profile = %lx\n", (long)ras.cProfile ));
+      break;
+
+    case Descending:
+      ras.cProfile->flow = FT_Flow_Down;
+      FT_TRACE7(( "New descending profile = %lx\n", (long)ras.cProfile ));
+      break;
+
+    default:
+      FT_ERROR(( "Invalid profile direction in Raster:New_Profile !!\n" ));
+      ras.error = Raster_Err_Invalid;
+      return FAILURE;
+    }
+
+    ras.cProfile->start  = 0;
+    ras.cProfile->height = 0;
+    ras.cProfile->offset = ras.top;
+    ras.cProfile->link   = (PProfile)0;
+    ras.cProfile->next   = (PProfile)0;
+
+    if ( !ras.gProfile )
+      ras.gProfile = ras.cProfile;
+
+    ras.state = aState;
+    ras.fresh = TRUE;
+    ras.joint = FALSE;
+
+    return SUCCESS;
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    End_Profile                                                 */
+/*                                                                          */
+/* Description: Finalizes the current Profile.                              */
+/*                                                                          */
+/* Input:       None                                                        */
+/*                                                                          */
+/* Returns:     SUCCESS on success.                                         */
+/*              FAILURE in case of overflow or incoherency.                 */
+/*                                                                          */
+/****************************************************************************/
+
+  static Bool  End_Profile( RAS_ARG )
+  {
+    Long      h;
+    PProfile  oldProfile;
+
+
+    h = ras.top - ras.cProfile->offset;
+
+    if ( h < 0 )
+    {
+      FT_ERROR(( "Negative height encountered in End_Profile!\n" ));
+      ras.error = Raster_Err_Neg_Height;
+      return FAILURE;
+    }
+
+    if ( h > 0 )
+    {
+      FT_TRACE1(( "Ending profile %lx, start = %ld, height = %ld\n",
+                (long)ras.cProfile, ras.cProfile->start, h ));
+
+      oldProfile           = ras.cProfile;
+      ras.cProfile->height = h;
+      ras.cProfile         = (PProfile)ras.top;
+
+      ras.top             += AlignProfileSize;
+
+      ras.cProfile->height = 0;
+      ras.cProfile->offset = ras.top;
+      oldProfile->next     = ras.cProfile;
+      ras.num_Profs++;
+    }
+
+    if ( ras.top >= ras.maxBuff )
+    {
+      FT_TRACE1(( "overflow in End_Profile\n" ));
+      ras.error = Raster_Err_Overflow;
+      return FAILURE;
+    }
+
+    ras.joint = FALSE;
+
+    return SUCCESS;
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Insert_Y_Turn                                               */
+/*                                                                          */
+/* Description: Insert a salient into the sorted list placed on top         */
+/*              of the render pool                                          */
+/*                                                                          */
+/* Input:       New y scanline position                                     */
+/*                                                                          */
+/****************************************************************************/
+
+  static
+  Bool Insert_Y_Turn( RAS_ARGS  Int  y )
+  {
+    PStorage  y_turns;
+    Int       y2, n;
+
+    n       = ras.numTurns-1;
+    y_turns = ras.sizeBuff - ras.numTurns;
+
+    /* look for first y value that is <= */
+    while ( n >= 0 && y < y_turns[n] )
+      n--;
+
+    /* if it is <, simply insert it, ignore if == */
+    if ( n >= 0 && y > y_turns[n] )
+      while ( n >= 0 )
+      {
+        y2 = y_turns[n];
+        y_turns[n] = y;
+        y = y2;
+        n--;
+      }
+
+    if ( n < 0 )
+    {
+      if (ras.maxBuff <= ras.top)
+      {
+        ras.error = Raster_Err_Overflow;
+        return FAILURE;
+      }
+      ras.maxBuff--;
+      ras.numTurns++;
+      ras.sizeBuff[-ras.numTurns] = y;
+    }
+
+    return SUCCESS;
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Finalize_Profile_Table                                      */
+/*                                                                          */
+/* Description: Adjusts all links in the Profiles list.                     */
+/*                                                                          */
+/* Input:       None                                                        */
+/*                                                                          */
+/* Returns:     None.                                                       */
+/*                                                                          */
+/****************************************************************************/
+
+  static
+  Bool Finalize_Profile_Table( RAS_ARG )
+  {
+    Int       bottom, top;
+    UShort    n;
+    PProfile  p;
+
+
+    n = ras.num_Profs;
+
+    if ( n > 1 )
+    {
+      p = ras.fProfile;
+      while ( n > 0 )
+      {
+        if ( n > 1 )
+          p->link = (PProfile)( p->offset + p->height );
+        else
+          p->link = NULL;
+
+        switch ( p->flow )
+        {
+        case FT_Flow_Down:
+          bottom     = p->start - p->height+1;
+          top        = p->start;
+          p->start   = bottom;
+          p->offset += p->height-1;
+          break;
+
+        case FT_Flow_Up:
+        default:
+          bottom = p->start;
+          top    = p->start + p->height-1;
+        }
+
+        if ( Insert_Y_Turn( RAS_VARS  bottom ) ||
+             Insert_Y_Turn( RAS_VARS  top+1 )  )
+          return FAILURE;
+
+        p = p->link;
+        n--;
+      }
+    }
+    else
+      ras.fProfile = NULL;
+
+    return SUCCESS;
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Split_Conic                                                 */
+/*                                                                          */
+/* Description: Subdivides one conic bezier into two joint                  */
+/*              sub-arcs in the Bezier stack.                               */
+/*                                                                          */
+/* Input:       None (subdivided bezier is taken from the top of the        */
+/*              stack).                                                     */
+/*                                                                          */
+/* Returns:     None.                                                       */
+/*                                                                          */
+/*                                                                          */
+/* Note:  This routine is the 'beef' of this component. It is  _the_        */
+/*        inner loop that should be optimized to hell to get the            */
+/*        best performance.                                                 */
+/*                                                                          */
+/****************************************************************************/
+
+  static void  Split_Conic( TPoint*  base )
+  {
+    Long     a, b;
+
+
+    base[4].x = base[2].x;
+    b = base[1].x;
+    a = base[3].x = ( base[2].x + b ) / 2;
+    b = base[1].x = ( base[0].x + b ) / 2;
+    base[2].x = ( a + b ) / 2;
+
+    base[4].y = base[2].y;
+    b = base[1].y;
+    a = base[3].y = ( base[2].y + b ) / 2;
+    b = base[1].y = ( base[0].y + b ) / 2;
+    base[2].y = ( a + b ) / 2;
+
+    /* hand optimized.  gcc doesn't seem too good at common expression */
+    /* substitution and instruction scheduling ;-)                     */
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>   Split_Cubic                                              */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*     Subdivides a third-order Bezier arc into two joint sub-arcs in    */
+  /*     the Bezier stack.                                                 */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    This routine is the `beef' of the component.  It is one of _the_   */
+  /*    inner loops that should be optimized like hell to get the best     */
+  /*    performance.                                                       */
+  /*                                                                       */
+  static
+  void  Split_Cubic( TPoint*  base )
+  {
+    Long  a, b, c, d;
+
+    base[6].x = base[3].x;
+    c = base[1].x;
+    d = base[2].x;
+    base[1].x = a = ( base[0].x + c + 1 ) >> 1;
+    base[5].x = b = ( base[3].x + d + 1 ) >> 1;
+    c = ( c + d + 1 ) >> 1;
+    base[2].x = a = ( a + c + 1 ) >> 1;
+    base[4].x = b = ( b + c + 1 ) >> 1;
+    base[3].x = ( a + b + 1 ) >> 1;
+
+    base[6].y = base[3].y;
+    c = base[1].y;
+    d = base[2].y;
+    base[1].y = a = ( base[0].y + c + 1 ) >> 1;
+    base[5].y = b = ( base[3].y + d + 1 ) >> 1;
+    c = ( c + d + 1 ) >> 1;
+    base[2].y = a = ( a + c + 1 ) >> 1;
+    base[4].y = b = ( b + c + 1 ) >> 1;
+    base[3].y = ( a + b + 1 ) >> 1;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    Push_Cubic                                                         */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Clears the Bezier stack and pushes a new third-order Bezier arc on */
+  /*    top of it.                                                         */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    p2 :: A pointer to the second (control) point.                     */
+  /*    p3 :: A pointer to the third (control) point.                      */
+  /*    p4 :: A pointer to the fourth (end) point.                         */
+  /*                                                                       */
+  /* <Note>                                                                */
+  /*    The first point is taken as `raster->last', so it doesn't appear   */
+  /*    in the signature.                                                  */
+  /*                                                                       */
+  /*    This is the same as Push_Conic(), except that it deals with        */
+  /*    third-order Beziers.                                               */
+  /*                                                                       */
+  static
+  static void  Push_Cubic( RAS_ARGS Long  x1, Long  y1,
+                                    Long  x2, Long  y2,
+                                    Long  x3, Long  y3,
+                                    Long  x4, Long  y4 )
+  {
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Line_Up                                                     */
+/*                                                                          */
+/* Description: Computes the x-coordinates of an ascending line segment     */
+/*              and stores them in the render pool.                         */
+/*                                                                          */
+/* Input:       x1,y1,x2,y2  Segment start (x1,y1) and end (x2,y2) points   */
+/*                                                                          */
+/* Returns:     SUCCESS on success.                                         */
+/*              FAILURE on Render Pool overflow.                            */
+/*                                                                          */
+/****************************************************************************/
+
+  static Bool  Line_Up( RAS_ARGS Long  x1, Long  y1,
+                                 Long  x2, Long  y2,
+                                 Long  miny, Long  maxy )
+  {
+    Long  Dx, Dy;
+    Int   e1, e2, f1, f2, size;     /* XXX: is `Short' sufficient? */
+    Long  Ix, Rx, Ax;
+
+    PStorage  top;
+
+
+    Dx = x2 - x1;
+    Dy = y2 - y1;
+
+    if ( Dy <= 0 || y2 < miny || y1 > maxy )
+      return SUCCESS;
+
+    if ( y1 < miny )
+    {
+      /* Take care : miny-y1 can be a very large value, we use     */
+      /*             a slow MulDiv function to avoid clipping bugs */
+      x1 += SMulDiv( Dx, miny - y1, Dy );
+      e1  = TRUNC( miny );
+      f1  = 0;
+    }
+    else
+    {
+      e1 = TRUNC( y1 );
+      f1 = FRAC( y1 );
+    }
+
+    if ( y2 > maxy )
+    {
+      /* x2 += FMulDiv( Dx, maxy - y2, Dy );  UNNECESSARY */
+      e2  = TRUNC( maxy );
+      f2  = 0;
+    }
+    else
+    {
+      e2 = TRUNC( y2 );
+      f2 = FRAC( y2 );
+    }
+
+    if ( f1 > 0 )
+    {
+      if ( e1 == e2 ) return SUCCESS;
+      else
+      {
+        x1 += FMulDiv( Dx, ras.precision - f1, Dy );
+        e1 += 1;
+      }
+    }
+    else
+      if ( ras.joint )
+      {
+        ras.top--;
+        ras.joint = FALSE;
+      }
+
+    ras.joint = ( f2 == 0 );
+
+    if ( ras.fresh )
+    {
+      ras.cProfile->start = e1;
+      ras.fresh           = FALSE;
+    }
+
+    size = e2 - e1 + 1;
+    if ( ras.top + size >= ras.maxBuff )
+    {
+      ras.error = Raster_Err_Overflow;
+      return FAILURE;
+    }
+
+    if ( Dx > 0 )
+    {
+      Ix = (ras.precision*Dx) / Dy;
+      Rx = (ras.precision*Dx) % Dy;
+      Dx = 1;
+    }
+    else
+    {
+      Ix = -( (ras.precision*-Dx) / Dy );
+      Rx =    (ras.precision*-Dx) % Dy;
+      Dx = -1;
+    }
+
+    Ax  = -Dy;
+    top = ras.top;
+
+    while ( size > 0 )
+    {
+      *top++ = x1;
+
+      x1 += Ix;
+      Ax += Rx;
+      if ( Ax >= 0 )
+      {
+        Ax -= Dy;
+        x1 += Dx;
+      }
+      size--;
+    }
+
+    ras.top = top;
+    return SUCCESS;
+  }
+
+
+  static Bool  Line_Down( RAS_ARGS Long  x1, Long  y1,
+                                   Long  x2, Long  y2,
+                                   Long  miny, Long  maxy )
+  {
+    Bool result, fresh;
+
+
+    fresh  = ras.fresh;
+
+    result = Line_Up( RAS_VARS x1, -y1, x2, -y2, -maxy, -miny );
+
+    if ( fresh && !ras.fresh )
+      ras.cProfile->start = -ras.cProfile->start;
+
+    return result;
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Bezier_Up                                                   */
+/*                                                                          */
+/* Description: Computes thes x-coordinates of an ascending bezier arc      */
+/*              and stores them in the render pool.                         */
+/*                                                                          */
+
+ /* A function type describing the functions used to split bezier arcs */
+  typedef  void  (*TSplitter)( TPoint*  base );
+
+  static Bool  Bezier_Up( RAS_ARGS Int        degree,
+                                   TSplitter  splitter,
+                                   Long       miny,
+                                   Long       maxy )
+  {
+    Long   y1, y2, e, e2, e0;
+    Short  f1;
+
+    TPoint*  arc;
+    TPoint*  start_arc;
+
+    PStorage top;
+
+
+    arc = ras.arc;
+    y1  = arc[degree].y;
+    y2  = arc[0].y;
+    top = ras.top;
+
+    if ( y2 < miny || y1 > maxy )
+      goto Fin;
+
+    e2 = FLOOR( y2 );
+
+    if ( e2 > maxy )
+      e2 = maxy;
+
+    e0 = miny;
+
+    if ( y1 < miny )
+      e = miny;
+    else
+    {
+      e  = CEILING( y1 );
+      f1 = FRAC( y1 );
+      e0 = e;
+
+      if ( f1 == 0 )
+      {
+        if ( ras.joint )
+        {
+          top--;
+          ras.joint = FALSE;
+        }
+
+        *top++ = arc[degree].x;
+
+        e += ras.precision;
+      }
+    }
+
+    if ( ras.fresh )
+    {
+      ras.cProfile->start = TRUNC( e0 );
+      ras.fresh = FALSE;
+    }
+
+    if ( e2 < e )
+      goto Fin;
+
+    if ( ( top + TRUNC( e2 - e ) + 1 ) >= ras.maxBuff )
+    {
+      ras.top   = top;
+      ras.error = Raster_Err_Overflow;
+      return FAILURE;
+    }
+
+    start_arc = arc;
+
+    while ( arc >= start_arc && e <= e2 )
+    {
+      ras.joint = FALSE;
+
+      y2 = arc[0].y;
+
+      if ( y2 > e )
+      {
+        y1 = arc[degree].y;
+        if ( y2 - y1 >= ras.precision_step )
+        {
+          splitter( arc );
+          arc += degree;
+        }
+        else
+        {
+          *top++ = arc[degree].x + FMulDiv( arc[0].x-arc[degree].x,
+                                            e - y1, y2 - y1 );
+          arc -= degree;
+          e   += ras.precision;
+        }
+      }
+      else
+      {
+        if ( y2 == e )
+        {
+          ras.joint  = TRUE;
+          *top++     = arc[0].x;
+
+          e += ras.precision;
+        }
+        arc -= degree;
+      }
+    }
+
+  Fin:
+    ras.top  = top;
+    ras.arc -= degree;
+    return SUCCESS;
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Bezier_Down                                                 */
+/*                                                                          */
+/* Description: Computes the x-coordinates of a descending bezier arc       */
+/*              and stores them in the render pool.                         */
+/*                                                                          */
+
+  static Bool  Bezier_Down( RAS_ARGS Int        degree,
+                                     TSplitter  splitter,
+                                     Long       miny,
+                                     Long       maxy )
+  {
+    TPoint*  arc = ras.arc;
+    Bool     result, fresh;
+
+
+    arc[0].y = -arc[0].y;
+    arc[1].y = -arc[1].y;
+    arc[2].y = -arc[2].y;
+    if (degree > 2)
+      arc[3].y = -arc[3].y;
+
+    fresh = ras.fresh;
+
+    result = Bezier_Up( RAS_VARS degree, splitter, -maxy, -miny );
+
+    if ( fresh && !ras.fresh )
+      ras.cProfile->start = -ras.cProfile->start;
+
+    arc[0].y = -arc[0].y;
+    return result;
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Line_To                                                     */
+/*                                                                          */
+/* Description: Injects a new line segment and adjusts Profiles list.       */
+/*                                                                          */
+/* Input:       x, y : segment endpoint (start point in LastX,LastY)        */
+/*                                                                          */
+/* Returns:     SUCCESS on success.                                         */
+/*              FAILURE on Render Pool overflow or Incorrect Profile.       */
+/*                                                                          */
+/****************************************************************************/
+
+  static Bool  Line_To( RAS_ARGS Long  x, Long  y )
+  {
+    /* First, detect a change of direction */
+
+    switch ( ras.state )
+    {
+    case Unknown:
+      if ( y > ras.lastY )
+      {
+        if ( New_Profile( RAS_VARS  Ascending ) ) return FAILURE;
+      }
+      else
+      {
+        if ( y < ras.lastY )
+          if ( New_Profile( RAS_VARS  Descending ) ) return FAILURE;
+      }
+      break;
+
+    case Ascending:
+      if ( y < ras.lastY )
+      {
+        if ( End_Profile( RAS_VAR ) ||
+             New_Profile( RAS_VARS  Descending ) ) return FAILURE;
+      }
+      break;
+
+    case Descending:
+      if ( y > ras.lastY )
+      {
+        if ( End_Profile( RAS_VAR ) ||
+             New_Profile( RAS_VARS  Ascending ) ) return FAILURE;
+      }
+      break;
+
+    default:
+      ;
+    }
+
+    /* Then compute the lines */
+
+    switch ( ras.state )
+    {
+    case Ascending:
+      if ( Line_Up ( RAS_VARS  ras.lastX, ras.lastY,
+                     x, y, ras.minY, ras.maxY ) )
+        return FAILURE;
+      break;
+
+    case Descending:
+      if ( Line_Down( RAS_VARS ras.lastX, ras.lastY,
+                      x, y, ras.minY, ras.maxY ) )
+        return FAILURE;
+      break;
+
+    default:
+      ;
+    }
+
+    ras.lastX = x;
+    ras.lastY = y;
+
+    return SUCCESS;
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Conic_To                                                    */
+/*                                                                          */
+/* Description: Injects a new conic arc and adjusts the profile list.       */
+/*                                                                          */
+
+  static Bool  Conic_To( RAS_ARGS Long  x,
+                                  Long  y,
+                                  Long  cx,
+                                  Long  cy )
+  {
+    Long     y1, y2, y3, x3;
+    TStates  state_bez;
+
+
+    ras.arc      = ras.arcs;
+    ras.arc[2].x = ras.lastX;
+    ras.arc[2].y = ras.lastY;
+    ras.arc[1].x = cx; ras.arc[1].y = cy;
+    ras.arc[0].x = x;  ras.arc[0].y = y;
+
+    do
+    {
+      y1 = ras.arc[2].y;
+      y2 = ras.arc[1].y;
+      y3 = ras.arc[0].y;
+      x3 = ras.arc[0].x;
+
+      /* first, categorize the Bezier arc */
+
+      if ( y1 <= y3 )
+      {
+        ymin = y1;
+        ymax = y3;
+      }
+      else
+      {
+        ymin = y3;
+        ymax = y1;
+      }
+
+      if ( y2 < ymin || y2 > ymax )
+      {
+        /* this arc has no given direction, split it !! */
+        Split_Conic( ras.arc );
+        ras.arc += 2;
+      }
+      else if ( y1 == y3 )
+      {
+        /* this arc is flat, ignore it and pop it from the bezier stack */
+        ras.arc -= 2;
+      }
+      else
+      {
+        /* the arc is y-monotonous, either ascending or descending */
+        /* detect a change of direction                            */
+        state_bez =  y1 < y3 ? Ascending : Descending;
+        if ( ras.state != state_bez )
+        {
+          /* finalize current profile if any */
+          if ( ras.state != Unknown   &&
+               End_Profile( RAS_VAR ) )
+            goto Fail;
+
+          /* create a new profile */
+          if ( New_Profile( RAS_VAR_ state_bez ) )
+            goto Fail;
+        }
+
+        /* now call the appropriate routine */
+        if ( state_bez == Ascending )
+        {
+          if ( Bezier_Up( RAS_VAR_  2, Split_Conic, ras.minY, ras.maxY ) )
+            goto Fail;
+        }
+        else
+          if ( Bezier_Down( RAS_VAR_  2, Split_Conic, ras.minY, ras.maxY ) )
+            goto Fail;
+      }
+
+    } while ( ras.arc >= ras.arcs );
+
+    ras.lastX = x3;
+    ras.lastY = y3;
+
+    return SUCCESS;
+  }
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Cubic_To                                                    */
+/*                                                                          */
+/* Description: Injects a new cubic arc and adjusts the profile list.       */
+/*                                                                          */
+
+  static Bool  Cubic_To( RAS_ARGS Long  x,
+                                  Long  y,
+                                  Long  cx1,
+                                  Long  cy1,
+                                  Lonc  cx2,
+                                  Long  cy2 )
+  {
+    TPos     y1, y2, y3, y4, x4, ymin1, ymax1, ymin2, ymax2;
+    Long     y0, y1, y2, y3, x3;
+    TStates  state_bez;
+
+
+    ras.arc      = ras.arcs;
+    ras.arc[3].x = ras.lastX;
+    ras.arc[3].y = ras.lastY;
+    ras.arc[2].x = cx1; ras.arc[2].y = cy1;
+    ras.arc[1].x = cx2; ras.arc[1].y = cy2;
+    ras.arc[0].x = x;   ras.arc[0].y = y;
+
+    do
+    {
+      y1 = ras.arc[3].y;
+      y2 = ras.arc[2].y;
+      y3 = ras.arc[1].y;
+      y4 = ras.arc[0].y;
+      x4 = ras.arc[0].x;
+
+      /* first, categorize the Bezier arc */
+
+      if ( y1 <= y4 )
+      {
+        ymin1 = y1;
+        ymax1 = y4;
+      }
+      else
+      {
+        ymin1 = y4;
+        ymax1 = y1;
+      }
+
+      if ( y2 <= y3 )
+      {
+        ymin2 = y2;
+        ymax2 = y3;
+      }
+      else
+      {
+        ymin2 = y3;
+        ymax2 = y2;
+      }
+
+      if ( ymin2 < ymin1 || ymax2 > ymax1 )
+      {
+        /* this arc has no given direction, split it! */
+        Split_Cubic( ras.arc );
+        ras.arc += 3;
+      }
+      else if ( y1 == y4 )
+      {
+        /* this arc is flat, ignore it and pop it from the bezier stack */
+        ras.arc -= 3;
+      }
+      else
+      {
+        state_bez = ( y1 <= y4 ) ? Ascending : Descending;
+
+        /* detect a change of direction */
+        if ( ras.state != state_bez )
+        {
+          if ( ras.state != Unknown   &&
+               End_Profile( RAS_VAR ) )
+            goto Fail;
+
+          if ( New_Profile( RAS_VAR_ state_bez ) )
+            goto Fail;
+        }
+
+        /* compute intersections */
+        if ( state_bez == Ascending )
+        {
+          if ( Bezier_Up ( RAS_VAR_ 3, Split_Cubic, ras.minY, ras.maxY ) )
+            goto Fail;
+        }
+        else
+          if ( Bezier_Down ( RAS_VAR_ 3, Split_Cubic, ras.minY, ras.maxY ) )
+            goto Fail;
+      }
+
+    } while ( ras.arc >= ras.arcs );
+
+    ras.lastX = x4
+    ras.lastY = y4
+
+    return SUCCESS;
+  Fail:
+    return FAILURE;
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Decompose_Curve                                             */
+/*                                                                          */
+/* Description: Scans the outline arays in order to emit individual         */
+/*              segments and beziers by calling Line_To() and Bezier_To().  */
+/*              It handles all weird cases, like when the first point       */
+/*              is off the curve, or when there are simply no 'on'          */
+/*              points in the contour!                                      */
+/*                                                                          */
+/* Input:       first, last    : indexes of first and last point in         */
+/*                               contour.                                   */
+/*                                                                          */
+/* Returns:     SUCCESS on success.                                         */
+/*              FAILURE on error.                                           */
+/*                                                                          */
+/****************************************************************************/
+
+#undef  SWAP_
+#define SWAP_(x,y)  { Long swap = x; x = y; y = swap; }
+
+
+  static Bool  Decompose_Curve( RAS_ARGS UShort  first,
+                                         UShort  last,
+                                         Bool    flipped )
+  {
+    FT_Vector  v_last;
+    FT_Vector  v_control;
+    FT_Vector  v_start;
+
+    FT_Vector* points;
+    FT_Vector* point;
+    FT_Vector* limit;
+    char*      tags;
+
+    int    n;         /* index of contour in outline     */
+    int    first;     /* index of first point in contour */
+    int    error;
+    char   tag;       /* current point's state           */
+
+    points = ras.outline.points;
+    limit  = points + last;
+
+    v_start.x = SCALED(points[first].x);
+    v_start.y = SCALED(points[first].y);
+    v_last.x  = SCALED(points[last].x);
+    v_last.y  = SCALED(points[last].y);
+    if (flipped)
+    {
+      SWAP_(v_start.x,v_start.y);
+      SWAP_(v_last.x,v_last.y);
+    }
+    
+    v_control = v_start;
+
+    point = points + first;
+    tags  = ras.outline->tags  + first;
+    tag   = FT_CURVE_TAG( tags[0] );
+
+    /* A contour cannot start with a cubic control point! */
+    if ( tag == FT_Curve_Tag_Cubic )
+      goto Invalid_Outline;
+
+    /* check first point to determine origin */
+    if ( tag == FT_Curve_Tag_Conic )
+    {
+      /* first point is conic control.  Yes, this happens. */
+      if ( FT_CURVE_TAG( ras.outline->tags[last] ) == FT_Curve_Tag_On )
+      {
+        /* start at last point if it is on the curve */
+        v_start = v_last;
+        limit--;
+      }
+      else
+      {
+        /* if both first and last points are conic,         */
+        /* start at their middle and record its position    */
+        /* for closure                                      */
+        v_start.x = ( v_start.x + v_last.x ) / 2;
+        v_start.y = ( v_start.y + v_last.y ) / 2;
+
+        v_last = v_start;
+      }
+      point--;
+      tags--;
+    }
+
+    while (point < limit)
+    {
+      point++;
+      tags++;
+  
+      tag = FT_CURVE_TAG( tags[0] );
+      switch (tag)
+      {
+        case FT_Curve_Tag_On:  /* emit a single line_to */
+          {
+            Long  x, y;
+            
+            x = SCALED(point->x);
+            y = SCALED(point->y);
+            if (flipped) SWAP_(x,y);
+
+            if (Line_To( RAS_VARS x, y )) goto Fail;
+            continue;
+          }
+
+          
+        case FT_Curve_Tag_Conic:  /* consume conic arcs */
+          {
+            v_control.x = SCALED(point[0].x);
+            v_control.y = SCALED(point[0].y);
+            if (flipped) SWAP_(v_control.x,v_control.y);
+              
+          Do_Conic:
+            if (point < limit)
+            {
+              FT_Vector  v_middle;
+              Long       x, y;
+              
+              point++;
+              tags++;
+              tag = FT_CURVE_TAG( tags[0] );
+              
+              x = SCALED(point[0].x);
+              y = SCALED(point[0].y);
+              if (flipped) SWAP_(x,y);
+                
+              if (tag == FT_Curve_Tag_On)
+              {
+                if (Conic_To( RAS_VARS v_control.x, v_control.y, x, y ))
+                  goto Fail;
+                continue;
+              }
+                
+              if (tag != FT_Curve_Tag_Conic)
+                goto Invalid_Outline;
+
+              v_middle.x = (v_control.x + x)/2;
+              v_middle.y = (v_control.y + y)/2;
+
+              if (Conic_To( RAS_VARS v_control.x, v_control.y, 
+                                     v_middle.x,  v_middle.y )) goto Fail;
+                
+              v_control.x = x;
+              v_control.y = y;
+              goto Do_Conic;
+            }
+          
+            if (Conic_To( RAS_VARS v_control.x, v_control.y,
+                                   v_start.x,   v_start.y )) goto Fail;
+            goto Close;
+          }
+          
+        default:  /* FT_Curve_Tag_Cubic */
+          {
+            Long  x1, y1, x2, y2, x3, y3;
+            
+            if ( point+1 > limit         ||
+                 FT_CURVE_TAG( tags[1] ) != FT_Curve_Tag_Cubic )
+              goto Invalid_Outline;
+                
+            point += 2;
+            tags  += 2;
+            
+            x1 = SCALED(point[-2].x);
+            y1 = SCALED(point[-2].y);
+            x2 = SCALED(point[-1].x);
+            y2 = SCALED(point[-1].y);
+            x3 = SCALED(point[ 0].x);
+            y3 = SCALED(point[ 0].y);
+            if (flipped)
+            {
+              SWAP_(x1,y1);
+              SWAP_(x2,y2);
+              SWAP_(x3,y3);
+            }
+            if (point <= limit)
+            {
+              if (Cubic_To( RAS_VARS x1, y1, x2, y2, x3, y3 ))
+                goto Fail;
+              continue;
+            }
+            
+            if (Cubic_To( RAS_VARS x1, y1, x2, y2, v_start.x, v_start.y ))
+              goto Fail;
+            goto Close;
+          }
+      }
+    }
+
+    /* close the contour with a line segment */
+    if (Line_To( RAS_VARS v_start.x, v_start.y ))
+      goto Fail;
+  }
+
+Close:
+  return SUCCESS;
+  
+Invalid_Outline:
+  ras.error = Raster_Err_Invalid;
+
+Fail:
+  return FAILURE;
+}
+  
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Convert_Glyph                                               */
+/*                                                                          */
+/* Description: Converts a glyph into a series of segments and arcs         */
+/*              and makes a Profiles list with them.                        */
+/*                                                                          */
+/* Input:       _xCoord, _yCoord : coordinates tables.                      */
+/*                                                                          */
+/*              Uses the 'Flag' table too.                                  */
+/*                                                                          */
+/* Returns:     SUCCESS on success.                                         */
+/*              FAILURE if any error was encountered during rendering.      */
+/*                                                                          */
+/****************************************************************************/
+
+  static Bool  Convert_Glyph( RAS_ARGS int  flipped )
+  {
+    Short     i;
+    UShort    start;
+
+    PProfile  lastProfile;
+
+
+    ras.fProfile = NULL;
+    ras.joint    = FALSE;
+    ras.fresh    = FALSE;
+
+    ras.maxBuff  = ras.sizeBuff - AlignProfileSize;
+
+    ras.numTurns = 0;
+
+    ras.cProfile         = (PProfile)ras.top;
+    ras.cProfile->offset = ras.top;
+    ras.num_Profs        = 0;
+
+    start = 0;
+
+    for ( i = 0; i < ras.nContours; i++ )
+    {
+      ras.state    = Unknown;
+      ras.gProfile = NULL;
+
+      if ( Decompose_Curve( RAS_VARS  start, ras.outs[i], flipped ) )
+        return FAILURE;
+
+      start = ras.outs[i] + 1;
+
+      /* We must now see if the extreme arcs join or not */
+      if ( ( FRAC( ras.lastY ) == 0 &&
+             ras.lastY >= ras.minY      &&
+             ras.lastY <= ras.maxY ) )
+        if ( ras.gProfile && ras.gProfile->flow == ras.cProfile->flow )
+          ras.top--;
+        /* Note that ras.gProfile can be nil if the contour was too small */
+        /* to be drawn.                                                   */
+
+      lastProfile = ras.cProfile;
+      if ( End_Profile( RAS_VAR ) ) return FAILURE;
+
+      /* close the 'next profile in contour' linked list */
+      if ( ras.gProfile )
+        lastProfile->next = ras.gProfile;
+    }
+
+    if (Finalize_Profile_Table( RAS_VAR ))
+      return FAILURE;
+
+    return (ras.top < ras.maxBuff ? SUCCESS : FAILURE );
+  }
+
+
+  /****************************************************************/
+  /****************************************************************/
+  /**                                                            **/
+  /**  SCAN-LINE SWEEPS AND DRAWING                              **/
+  /**                                                            **/
+  /****************************************************************/
+  /****************************************************************/
+  
+
+/************************************************/
+/*                                              */
+/*  Init_Linked                                 */
+/*                                              */
+/*    Inits an empty linked list.               */
+/*                                              */
+/************************************************/
+
+  static void  Init_Linked( TProfileList*  l )
+  {
+    *l = NULL;
+  }
+
+
+/************************************************/
+/*                                              */
+/*  InsNew :                                    */
+/*                                              */
+/*    Inserts a new Profile in a linked list.   */
+/*                                              */
+/************************************************/
+
+  static void  InsNew( PProfileList  list,
+                       PProfile      profile )
+  {
+    PProfile  *old, current;
+    Long       x;
+
+
+    old     = list;
+    current = *old;
+    x       = profile->X;
+
+    while ( current )
+    {
+      if ( x < current->X )
+        break;
+      old     = &current->link;
+      current = *old;
+    }
+
+    profile->link = current;
+    *old          = profile;
+  }
+
+
+/*************************************************/
+/*                                               */
+/*  DelOld :                                     */
+/*                                               */
+/*    Removes an old Profile from a linked list. */
+/*                                               */
+/*************************************************/
+
+  static void  DelOld( PProfileList  list,
+                       PProfile      profile )
+  {
+    PProfile  *old, current;
+
+
+    old     = list;
+    current = *old;
+
+    while ( current )
+    {
+      if ( current == profile )
+      {
+        *old = current->link;
+        return;
+      }
+
+      old     = &current->link;
+      current = *old;
+    }
+
+    /* we should never get there, unless the Profile was not part of */
+    /* the list.                                                     */
+  }
+
+
+/************************************************/
+/*                                              */
+/*  Update :                                    */
+/*                                              */
+/*    Update all X offsets of a drawing list    */
+/*                                              */
+/************************************************/
+
+  static void  Update( PProfile  first )
+  {
+    PProfile  current = first;
+
+
+    while ( current )
+    {
+      current->X       = *current->offset;
+      current->offset += current->flow;
+      current->height--;
+      current = current->link;
+    }
+  }
+
+
+/************************************************/
+/*                                              */
+/*  Sort :                                      */
+/*                                              */
+/*    Sorts a trace list.  In 95%, the list     */
+/*    is already sorted.  We need an algorithm  */
+/*    which is fast in this case.  Bubble sort  */
+/*    is enough and simple.                     */
+/*                                              */
+/************************************************/
+
+  static void  Sort( PProfileList  list )
+  {
+    PProfile  *old, current, next;
+
+
+    /* First, set the new X coordinate of each profile */
+    Update( *list );
+
+    /* Then sort them */
+    old     = list;
+    current = *old;
+
+    if ( !current )
+      return;
+
+    next = current->link;
+
+    while ( next )
+    {
+      if ( current->X <= next->X )
+      {
+        old     = &current->link;
+        current = *old;
+
+        if ( !current )
+          return;
+      }
+      else
+      {
+        *old          = next;
+        current->link = next->link;
+        next->link    = current;
+
+        old     = list;
+        current = *old;
+      }
+
+      next = current->link;
+    }
+  }
+
+
+/***********************************************************************/
+/*                                                                     */
+/*  Vertical Sweep Procedure Set :                                     */
+/*                                                                     */
+/*  These three routines are used during the vertical black/white      */
+/*  sweep phase by the generic Draw_Sweep() function.                  */
+/*                                                                     */
+/***********************************************************************/
+
+  static void  Vertical_Sweep_Init( RAS_ARGS Short*  min, Short*  max )
+  {
+    switch ( ras.target.flow )
+    {
+    case FT_Flow_Up:
+      ras.traceOfs  = *min * ras.target.cols;
+      ras.traceIncr = ras.target.cols;
+      break;
+
+    default:
+      ras.traceOfs  = ( ras.target.rows - 1 - *min ) * ras.target.cols;
+      ras.traceIncr = -ras.target.cols;
+    }
+
+    ras.gray_min_x = 0;
+    ras.gray_max_x = 0;
+  }
+
+
+  static void  Vertical_Sweep_Span( RAS_ARGS Short       y,
+                                             FT_F26Dot6  x1,
+                                             FT_F26Dot6  x2,
+                                             PProfile    left,
+                                             PProfile    right )
+  {
+    Long   e1, e2;
+    Short  c1, c2;
+    Short  f1, f2;
+    Byte*  target;
+
+
+    /* Drop-out control */
+
+    e1 = TRUNC( CEILING( x1 ) );
+
+    if ( x2-x1-ras.precision <= ras.precision_jitter )
+      e2 = e1;
+    else
+      e2 = TRUNC( FLOOR( x2 ) );
+
+    if ( e2 >= 0 && e1 < ras.bWidth )
+    {
+      if ( e1 < 0 )           e1 = 0;
+      if ( e2 >= ras.bWidth ) e2 = ras.bWidth-1;
+
+      c1 = (Short)(e1 >> 3);
+      c2 = (Short)(e2 >> 3);
+
+      f1 = e1 & 7;
+      f2 = e2 & 7;
+
+      if ( ras.gray_min_x > c1 ) ras.gray_min_x = c1;
+      if ( ras.gray_max_x < c2 ) ras.gray_max_x = c2;
+
+      target = ras.bTarget + ras.traceOfs + c1;
+
+      if ( c1 != c2 )
+      {
+        *target |= LMask[f1];
+
+        if ( c2 > c1 + 1 )
+          MEM_Set( target + 1, 0xFF, c2 - c1 - 1 );
+
+        target[c2 - c1] |= RMask[f2];
+      }
+      else
+        *target |= ( LMask[f1] & RMask[f2] );
+    }
+  }
+
+
+  static void  Vertical_Sweep_Drop( RAS_ARGS Short       y,
+                                             FT_F26Dot6  x1,
+                                             FT_F26Dot6  x2,
+                                             PProfile    left,
+                                             PProfile    right )
+  {
+    Long   e1, e2;
+    Short  c1, f1;
+
+
+    /* Drop-out control */
+
+    e1 = CEILING( x1 );
+    e2 = FLOOR  ( x2 );
+
+    if ( e1 > e2 )
+    {
+      if ( e1 == e2 + ras.precision )
+      {
+        switch ( ras.dropOutControl )
+        {
+        case 1:
+          e1 = e2;
+          break;
+
+        case 4:
+          e1 = CEILING( (x1 + x2 + 1) / 2 );
+          break;
+
+        case 2:
+        case 5:
+          /* Drop-out Control Rule #4 */
+
+          /* The spec is not very clear regarding rule #4.  It      */
+          /* presents a method that is way too costly to implement  */
+          /* while the general idea seems to get rid of 'stubs'.    */
+          /*                                                        */
+          /* Here, we only get rid of stubs recognized when:        */
+          /*                                                        */
+          /*  upper stub:                                           */
+          /*                                                        */
+          /*   - P_Left and P_Right are in the same contour         */
+          /*   - P_Right is the successor of P_Left in that contour */
+          /*   - y is the top of P_Left and P_Right                 */
+          /*                                                        */
+          /*  lower stub:                                           */
+          /*                                                        */
+          /*   - P_Left and P_Right are in the same contour         */
+          /*   - P_Left is the successor of P_Right in that contour */
+          /*   - y is the bottom of P_Left                          */
+          /*                                                        */
+
+          /* FIXXXME : uncommenting this line solves the disappearing */
+          /*           bit problem in the '7' of verdana 10pts, but   */
+          /*           makes a new one in the 'C' of arial 14pts      */
+
+          /* if ( x2-x1 < ras.precision_half ) */
+          {
+            /* upper stub test */
+
+            if ( left->next == right && left->height <= 0 ) return;
+
+            /* lower stub test */
+
+            if ( right->next == left && left->start == y ) return;
+          }
+
+          /* check that the rightmost pixel isn't set */
+
+          e1 = TRUNC( e1 );
+
+          c1 = (Short)(e1 >> 3);
+          f1 = e1 &  7;
+
+          if ( e1 >= 0 && e1 < ras.bWidth &&
+               ras.bTarget[ras.traceOfs + c1] & (0x80 >> f1) )
+            return;
+
+          if ( ras.dropOutControl == 2 )
+            e1 = e2;
+          else
+            e1 = CEILING( (x1 + x2 + 1) / 2 );
+
+          break;
+
+        default:
+          return;  /* unsupported mode */
+        }
+      }
+      else
+        return;
+    }
+
+    e1 = TRUNC( e1 );
+
+    if ( e1 >= 0 && e1 < ras.bWidth )
+    {
+      c1 = (Short)(e1 >> 3);
+      f1 = e1 & 7;
+
+      if ( ras.gray_min_x > c1 ) ras.gray_min_x = c1;
+      if ( ras.gray_max_x < c1 ) ras.gray_max_x = c1;
+
+      ras.bTarget[ras.traceOfs + c1] |= (Char)(0x80 >> f1);
+    }
+  }
+
+
+  static void Vertical_Sweep_Step( RAS_ARG )
+  {
+    ras.traceOfs += ras.traceIncr;
+  }
+
+
+/***********************************************************************/
+/*                                                                     */
+/*  Horizontal Sweep Procedure Set :                                   */
+/*                                                                     */
+/*  These three routines are used during the horizontal black/white    */
+/*  sweep phase by the generic Draw_Sweep() function.                  */
+/*                                                                     */
+/***********************************************************************/
+
+  static void  Horizontal_Sweep_Init( RAS_ARGS Short*  min, Short*  max )
+  {
+    /* nothing, really */
+  }
+
+
+  static void  Horizontal_Sweep_Span( RAS_ARGS Short       y,
+                                               FT_F26Dot6  x1,
+                                               FT_F26Dot6  x2,
+                                               PProfile    left,
+                                               PProfile    right )
+  {
+    Long  e1, e2;
+    PByte bits;
+    Byte  f1;
+
+
+    if ( x2-x1 < ras.precision )
+    {
+      e1 = CEILING( x1 );
+      e2 = FLOOR  ( x2 );
+
+      if ( e1 == e2 )
+      {
+        bits = ras.bTarget + (y >> 3);
+        f1   = (Byte)(0x80 >> (y  & 7));
+
+        e1 = TRUNC( e1 );
+
+        if ( e1 >= 0 && e1 < ras.target.rows )
+        {
+          if ( ras.target.flow == FT_Flow_Down )
+            bits[(ras.target.rows-1 - e1) * ras.target.cols] |= f1;
+          else
+            bits[e1 * ras.target.cols] |= f1;
+        }
+      }
+    }
+#if 0
+      e2 = TRUNC( e2 );
+
+      if ( e2 >= 0 && e2 < ras.target.rows )
+        if ( ras.target.flow == FT_Flow_Down )
+          bits[(ras.target.rows-1-e2) * ras.target.cols] |= f1;
+        else
+          bits[e2 * ras.target.cols] |= f1;
+#endif
+  }
+
+
+  static void  Horizontal_Sweep_Drop( RAS_ARGS Short       y,
+                                               FT_F26Dot6  x1,
+                                               FT_F26Dot6  x2,
+                                               PProfile    left,
+                                               PProfile    right )
+  {
+    Long  e1, e2;
+    PByte bits;
+    Byte  f1;
+
+
+    /* During the horizontal sweep, we only take care of drop-outs */
+
+    e1 = CEILING( x1 );
+    e2 = FLOOR  ( x2 );
+
+    if ( e1 > e2 )
+    {
+      if ( e1 == e2 + ras.precision )
+      {
+        switch ( ras.dropOutControl )
+        {
+        case 1:
+          e1 = e2;
+          break;
+
+        case 4:
+          e1 = CEILING( (x1 + x2 + 1) / 2 );
+          break;
+
+        case 2:
+        case 5:
+
+          /* Drop-out Control Rule #4 */
+
+          /* The spec is not very clear regarding rule #4.  It      */
+          /* presents a method that is way too costly to implement  */
+          /* while the general idea seems to get rid of 'stubs'.    */
+          /*                                                        */
+
+          /* rightmost stub test */
+
+          if ( left->next == right && left->height <= 0 ) return;
+
+          /* leftmost stub test */
+
+          if ( right->next == left && left->start == y ) return;
+
+          /* check that the rightmost pixel isn't set */
+
+          e1 = TRUNC( e1 );
+
+          bits = ras.bTarget + (y >> 3);
+          f1   = (Byte)(0x80 >> (y &  7));
+
+          if ( ras.target.flow == FT_Flow_Down )
+            bits += (ras.target.rows-1-e1) * ras.target.cols;
+          else
+            bits += e1 * ras.target.cols;
+
+          if ( e1 >= 0              &&
+               e1 < ras.target.rows &&
+               *bits & f1 )
+            return;
+
+          if ( ras.dropOutControl == 2 )
+            e1 = e2;
+          else
+            e1 = CEILING( (x1 + x2 + 1) / 2 );
+
+          break;
+
+        default:
+          return;  /* unsupported mode */
+        }
+      }
+      else
+        return;
+    }
+
+    bits = ras.bTarget + (y >> 3);
+    f1   = (Byte)(0x80 >> (y  & 7));
+
+    e1 = TRUNC( e1 );
+
+    if ( e1 >= 0 && e1 < ras.target.rows )
+    {
+      if (ras.target.flow==FT_Flow_Down)
+        bits[(ras.target.rows-1-e1) * ras.target.cols] |= f1;
+      else
+        bits[e1 * ras.target.cols] |= f1;
+    }
+  }
+
+
+  static void Horizontal_Sweep_Step( RAS_ARG )
+  {
+    /* Nothing, really */
+  }
+
+
+#ifdef FT_CONFIG_OPTION_GRAY_SCALING
+
+/***********************************************************************/
+/*                                                                     */
+/*  Vertical Gray Sweep Procedure Set:                                 */
+/*                                                                     */
+/*  These two routines are used during the vertical gray-levels        */
+/*  sweep phase by the generic Draw_Sweep() function.                  */
+/*                                                                     */
+/*                                                                     */
+/*  NOTES:                                                             */
+/*                                                                     */
+/*  - The target pixmap's width *must* be a multiple of 4.             */
+/*                                                                     */
+/*  - you have to use the function Vertical_Sweep_Span() for           */
+/*    the gray span call.                                              */
+/*                                                                     */
+/***********************************************************************/
+
+  static void  Vertical_Gray_Sweep_Init( RAS_ARGS Short*  min, Short*  max )
+  {
+    *min = *min & -2;
+    *max = ( *max + 3 ) & -2;
+
+    ras.traceOfs = 0;
+
+    switch ( ras.target.flow )
+    {
+    case FT_Flow_Up:
+      ras.traceG  = (*min / 2) * ras.target.cols;
+      ras.traceIncr = ras.target.cols;
+      break;
+
+    default:
+      ras.traceG    = (ras.target.rows-1 - *min/2) * ras.target.cols;
+      ras.traceIncr = -ras.target.cols;
+    }
+
+    ras.gray_min_x =  ras.target.cols;
+    ras.gray_max_x = -ras.target.cols;
+  }
+
+
+  static void  Vertical_Gray_Sweep_Step( RAS_ARG )
+  {
+    Int    c1, c2;
+    PByte  pix, bit, bit2;
+    Int*   count = ras.count_table;
+    Byte*  grays;
+
+
+    ras.traceOfs += ras.gray_width;
+
+    if ( ras.traceOfs > ras.gray_width )
+    {
+      pix   = ras.gTarget + ras.traceG + ras.gray_min_x * 4;
+      grays = ras.grays;
+
+      if ( ras.gray_max_x >= 0 )
+      {
+        if ( ras.gray_max_x >= ras.target.width )
+          ras.gray_max_x = ras.target.width-1;
+
+        if ( ras.gray_min_x < 0 )
+          ras.gray_min_x = 0;
+
+        bit   = ras.bTarget + ras.gray_min_x;
+        bit2  = bit + ras.gray_width;
+
+        c1 = ras.gray_max_x - ras.gray_min_x;
+
+        while ( c1 >= 0 )
+        {
+          c2 = count[*bit] + count[*bit2];
+
+          if ( c2 )
+          {
+            pix[0] = grays[(c2 & 0xF000) >> 12];
+            pix[1] = grays[(c2 & 0x0F00) >>  8];
+            pix[2] = grays[(c2 & 0x00F0) >>  4];
+            pix[3] = grays[(c2 & 0x000F)      ];
+
+            *bit  = 0;
+            *bit2 = 0;
+          }
+
+          bit ++;
+          bit2++;
+          pix += 4;
+          c1  --;
+        }
+      }
+
+      ras.traceOfs = 0;
+      ras.traceG  += ras.traceIncr;
+
+      ras.gray_min_x =  ras.target.cols;
+      ras.gray_max_x = -ras.target.cols;
+    }
+  }
+
+
+  static void  Horizontal_Gray_Sweep_Span( RAS_ARGS Short       y,
+                                                    FT_F26Dot6  x1,
+                                                    FT_F26Dot6  x2,
+                                                    PProfile    left,
+                                                    PProfile    right )
+  {
+    /* nothing, really */
+  }
+
+  static void  Horizontal_Gray_Sweep_Drop( RAS_ARGS Short       y,
+                                                    FT_F26Dot6  x1,
+                                                    FT_F26Dot6  x2,
+                                                    PProfile    left,
+                                                    PProfile    right )
+  {
+    Long  e1, e2;
+    PByte pixel;
+    Byte  color;
+
+
+    /* During the horizontal sweep, we only take care of drop-outs */
+    e1 = CEILING( x1 );
+    e2 = FLOOR  ( x2 );
+
+    if ( e1 > e2 )
+    {
+      if ( e1 == e2 + ras.precision )
+      {
+        switch ( ras.dropOutControl )
+        {
+        case 1:
+          e1 = e2;
+          break;
+
+        case 4:
+          e1 = CEILING( (x1 + x2 + 1) / 2 );
+          break;
+
+        case 2:
+        case 5:
+
+          /* Drop-out Control Rule #4 */
+
+          /* The spec is not very clear regarding rule #4.  It      */
+          /* presents a method that is way too costly to implement  */
+          /* while the general idea seems to get rid of 'stubs'.    */
+          /*                                                        */
+
+          /* rightmost stub test */
+          if ( left->next == right && left->height <= 0 ) return;
+
+          /* leftmost stub test */
+          if ( right->next == left && left->start == y ) return;
+
+          if ( ras.dropOutControl == 2 )
+            e1 = e2;
+          else
+            e1 = CEILING( (x1 + x2 + 1) / 2 );
+
+          break;
+
+        default:
+          return;  /* unsupported mode */
+        }
+      }
+      else
+        return;
+    }
+
+    if ( e1 >= 0 )
+    {
+      if ( x2 - x1 >= ras.precision_half )
+        color = ras.grays[2];
+      else
+        color = ras.grays[1];
+
+      e1 = TRUNC( e1 ) / 2;
+      if ( e1 < ras.target.rows )
+      {
+        if ( ras.target.flow == FT_Flow_Down )
+          pixel = ras.gTarget +
+                  (ras.target.rows - 1 - e1) * ras.target.cols + y / 2;
+        else
+          pixel = ras.gTarget +
+                  e1 * ras.target.cols + y / 2;
+
+        if (pixel[0] == ras.grays[0])
+          pixel[0] = color;
+      }
+    }
+  }
+
+#endif /* FT_CONFIG_OPTION_GRAY_SCALING */
+
+
+/********************************************************************/
+/*                                                                  */
+/*  Generic Sweep Drawing routine                                   */
+/*                                                                  */
+/********************************************************************/
+
+  static Bool  Draw_Sweep( RAS_ARG )
+  {
+    Short  y, y_change, y_height;
+
+    PProfile  P, Q, P_Left, P_Right;
+
+    Short  min_Y, max_Y, top, bottom, dropouts;
+
+    Long  x1, x2, xs, e1, e2;
+
+    TProfileList  wait;
+    TProfileList  draw_left, draw_right;
+
+
+    /* Init empty linked lists */
+
+    Init_Linked( &wait );
+
+    Init_Linked( &draw_left  );
+    Init_Linked( &draw_right );
+
+    /* first, compute min and max Y */
+
+    P     = ras.fProfile;
+    max_Y = (short)TRUNC( ras.minY );
+    min_Y = (short)TRUNC( ras.maxY );
+
+    while ( P )
+    {
+      Q = P->link;
+
+      bottom = P->start;
+      top    = P->start + P->height-1;
+
+      if ( min_Y > bottom ) min_Y = bottom;
+      if ( max_Y < top    ) max_Y = top;
+
+      P->X = 0;
+      InsNew( &wait, P );
+
+      P = Q;
+    }
+
+    /* Check the Y-turns */
+    if ( ras.numTurns == 0 )
+    {
+      ras.error = Raster_Err_Invalid;
+      return FAILURE;
+    }
+
+    /* Now inits the sweep */
+
+    ras.Proc_Sweep_Init( RAS_VARS  &min_Y, &max_Y );
+
+    /* Then compute the distance of each profile from min_Y */
+
+    P = wait;
+
+    while ( P )
+    {
+      P->countL = P->start - min_Y;
+      P = P->link;
+    }
+
+    /* Let's go */
+
+    y        = min_Y;
+    y_height = 0;
+
+    if ( ras.numTurns > 0 &&
+         ras.sizeBuff[-ras.numTurns] == min_Y )
+      ras.numTurns--;
+
+    while ( ras.numTurns > 0 )
+    {
+      /* look in the wait list for new activations */
+
+      P = wait;
+
+      while ( P )
+      {
+        Q = P->link;
+        P->countL -= y_height;
+        if ( P->countL == 0 )
+        {
+          DelOld( &wait, P );
+
+          switch ( P->flow )
+          {
+            case FT_Flow_Up:    InsNew( &draw_left,  P ); break;
+            case FT_Flow_Down:  InsNew( &draw_right, P ); break;
+          }
+        }
+
+        P = Q;
+      }
+
+      /* Sort the drawing lists */
+
+      Sort( &draw_left );
+      Sort( &draw_right );
+
+      y_change = (Short)ras.sizeBuff[-ras.numTurns--];
+      y_height = y_change - y;
+
+      while ( y < y_change )
+      {
+
+        /* Let's trace */
+
+        dropouts = 0;
+
+        P_Left  = draw_left;
+        P_Right = draw_right;
+
+        while ( P_Left )
+        {
+          x1 = P_Left ->X;
+          x2 = P_Right->X;
+
+          if ( x1 > x2 )
+          {
+            xs = x1;
+            x1 = x2;
+            x2 = xs;
+          }
+
+          if ( x2-x1 <= ras.precision )
+          {
+            e1 = FLOOR( x1 );
+            e2 = CEILING( x2 );
+
+            if ( ras.dropOutControl != 0 &&
+                 (e1 > e2 || e2 == e1 + ras.precision) )
+            {
+              /* a drop out was detected */
+
+              P_Left ->X = x1;
+              P_Right->X = x2;
+
+              /* mark profile for drop-out processing */
+              P_Left->countL = 1;
+              dropouts++;
+
+              goto Skip_To_Next;
+            }
+          }
+
+          ras.Proc_Sweep_Span( RAS_VARS  y, x1, x2, P_Left, P_Right );
+
+   Skip_To_Next:
+
+          P_Left  = P_Left->link;
+          P_Right = P_Right->link;
+        }
+
+        /* now perform the dropouts _after_ the span drawing   */
+        /* drop-outs processing has been moved out of the loop */
+        /* for performance tuning                              */
+        if (dropouts > 0)
+          goto Scan_DropOuts;
+
+   Next_Line:
+
+        ras.Proc_Sweep_Step( RAS_VAR );
+
+        y++;
+
+        if ( y < y_change )
+        {
+          Sort( &draw_left  );
+          Sort( &draw_right );
+        }
+
+      }
+
+      /* Now finalize the profiles that needs it */
+
+      {
+        PProfile  Q, P;
+        P = draw_left;
+        while ( P )
+        {
+          Q = P->link;
+          if ( P->height == 0 )
+            DelOld( &draw_left, P );
+          P = Q;
+        }
+      }
+
+      {
+        PProfile  Q, P = draw_right;
+        while ( P )
+        {
+          Q = P->link;
+          if ( P->height == 0 )
+            DelOld( &draw_right, P );
+          P = Q;
+        }
+      }
+    }
+
+    /* for gray-scaling, flushes the bitmap scanline cache */
+    while ( y <= max_Y )
+    {
+      ras.Proc_Sweep_Step( RAS_VAR );
+      y++;
+    }
+
+    return SUCCESS;
+
+Scan_DropOuts :
+
+    P_Left  = draw_left;
+    P_Right = draw_right;
+
+    while ( P_Left )
+    {
+      if ( P_Left->countL )
+      {
+        P_Left->countL = 0;
+        /* dropouts--;    -- this is useful when debugging only */
+        ras.Proc_Sweep_Drop( RAS_VARS  y,
+                                       P_Left->X,
+                                       P_Right->X,
+                                       P_Left,
+                                       P_Right );
+      }
+
+      P_Left  = P_Left->link;
+      P_Right = P_Right->link;
+    }
+
+    goto Next_Line;
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Render_Single_Pass                                          */
+/*                                                                          */
+/* Description: Performs one sweep with sub-banding.                        */
+/*                                                                          */
+/* Input:       _XCoord, _YCoord : x and y coordinates arrays               */
+/*                                                                          */
+/* Returns:     SUCCESS on success                                          */
+/*              FAILURE if any error was encountered during render.         */
+/*                                                                          */
+/****************************************************************************/
+
+  static FT_Error  Render_Single_Pass( RAS_ARGS Bool  flipped )
+  {
+    Short  i, j, k;
+
+
+    while ( ras.band_top >= 0 )
+    {
+      ras.maxY = (Long)ras.band_stack[ras.band_top].y_max * ras.precision;
+      ras.minY = (Long)ras.band_stack[ras.band_top].y_min * ras.precision;
+
+      ras.top = ras.buff;
+
+      ras.error = Raster_Err_None;
+
+      if ( Convert_Glyph( RAS_VARS  flipped ) )
+      {
+        if ( ras.error != Raster_Err_Overflow ) return FAILURE;
+
+        ras.error = Raster_Err_None;
+
+        /* sub-banding */
+
+#ifdef DEBUG_RASTER
+        ClearBand( RAS_VARS  TRUNC( ras.minY ), TRUNC( ras.maxY ) );
+#endif
+
+        i = ras.band_stack[ras.band_top].y_min;
+        j = ras.band_stack[ras.band_top].y_max;
+
+        k = ( i + j ) / 2;
+
+        if ( ras.band_top >= 7 || k < i )
+        {
+          ras.band_top     = 0;
+          ras.error = Raster_Err_Invalid;
+          return ras.error;
+        }
+
+        ras.band_stack[ras.band_top+1].y_min = k;
+        ras.band_stack[ras.band_top+1].y_max = j;
+
+        ras.band_stack[ras.band_top].y_max = k - 1;
+
+        ras.band_top++;
+      }
+      else
+      {
+        if ( ras.fProfile )
+          if ( Draw_Sweep( RAS_VAR ) ) return ras.error;
+        ras.band_top--;
+      }
+    }
+
+    return FT_Err_Ok;
+  }
+
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Render_Glyph                                                */
+/*                                                                          */
+/* Description: Renders a glyph in a bitmap.  Sub-banding if needed.        */
+/*                                                                          */
+/* Input:       AGlyph   Glyph record                                       */
+/*                                                                          */
+/* Returns:     SUCCESS on success.                                         */
+/*              FAILURE if any error was encountered during rendering.      */
+/*                                                                          */
+/****************************************************************************/
+
+  LOCAL_FUNC
+  FT_Error  Render_Glyph( RAS_ARGS FT_Outline*     glyph,
+                                   FT_Raster_Map*  target_map )
+  {
+    FT_Error  error;
+
+
+    if ( glyph->n_points == 0 || glyph->n_contours <= 0 )
+      return FT_Err_Ok;
+
+    if ( !ras.buff )
+    {
+      ras.error = Raster_Err_Not_Ini;
+      return ras.error;
+    }
+
+    if ( glyph->n_points < glyph->contours[glyph->n_contours - 1] )
+    {
+      ras.error = FT_Err_Too_Many_Points;
+      return ras.error;
+    }
+
+    if ( target_map )
+      ras.target = *target_map;
+
+    ras.outs      = glyph->contours;
+    ras.flags     = glyph->flags;
+    ras.nPoints   = glyph->n_points;
+    ras.nContours = glyph->n_contours;
+    ras.coords    = glyph->points;
+
+    Set_High_Precision( RAS_VARS glyph->high_precision );
+    ras.scale_shift    = ras.precision_shift;
+    ras.dropOutControl = glyph->dropout_mode;
+    ras.second_pass    = glyph->second_pass;
+
+
+    /* Vertical Sweep */
+    ras.Proc_Sweep_Init = Vertical_Sweep_Init;
+    ras.Proc_Sweep_Span = Vertical_Sweep_Span;
+    ras.Proc_Sweep_Drop = Vertical_Sweep_Drop;
+    ras.Proc_Sweep_Step = Vertical_Sweep_Step;
+
+    ras.band_top            = 0;
+    ras.band_stack[0].y_min = 0;
+    ras.band_stack[0].y_max = ras.target.rows - 1;
+
+    ras.bWidth  = ras.target.width;
+    ras.bTarget = (Byte*)ras.target.bitmap;
+
+    if ( (error = Render_Single_Pass( RAS_VARS 0 )) != 0 )
+      return error;
+
+    /* Horizontal Sweep */
+
+    if ( ras.second_pass && ras.dropOutControl != 0 )
+    {
+      ras.Proc_Sweep_Init = Horizontal_Sweep_Init;
+      ras.Proc_Sweep_Span = Horizontal_Sweep_Span;
+      ras.Proc_Sweep_Drop = Horizontal_Sweep_Drop;
+      ras.Proc_Sweep_Step = Horizontal_Sweep_Step;
+
+      ras.band_top            = 0;
+      ras.band_stack[0].y_min = 0;
+      ras.band_stack[0].y_max = ras.target.width - 1;
+
+      if ( (error = Render_Single_Pass( RAS_VARS  1 )) != 0 )
+        return error;
+    }
+
+    return FT_Err_Ok;
+  }
+
+
+#ifdef FT_CONFIG_OPTION_GRAY_SCALING
+
+/****************************************************************************/
+/*                                                                          */
+/* Function:    Render_Gray_Glyph                                           */
+/*                                                                          */
+/* Description: Renders a glyph with grayscaling. Sub-banding if needed.    */
+/*                                                                          */
+/* Input:       AGlyph   Glyph record                                       */
+/*                                                                          */
+/* Returns:     SUCCESS on success                                          */
+/*              FAILURE if any error was encountered during rendering.      */
+/*                                                                          */
+/****************************************************************************/
+
+  LOCAL_FUNC
+  FT_Error  Render_Gray_Glyph( RAS_ARGS  FT_Outline*     glyph,
+                                         FT_Raster_Map*  target_map,
+                                         Byte*           palette )
+  {
+    Int       i;
+    FT_Error  error;
+
+    if ( !ras.buff )
+    {
+      ras.error = Raster_Err_Not_Ini;
+      return ras.error;
+    }
+
+    if ( glyph->n_points == 0 || glyph->n_contours <= 0 )
+      return FT_Err_Ok;
+
+    if ( glyph->n_points < glyph->contours[glyph->n_contours - 1] )
+    {
+      ras.error = FT_Err_Too_Many_Points;
+      return ras.error;
+    }
+
+    if ( palette )
+    {
+      for ( i = 0; i < 5; i++ )
+        ras.grays[i] = palette[i];
+    }
+
+    if ( target_map )
+      ras.target = *target_map;
+
+    ras.outs      = glyph->contours;
+    ras.flags     = glyph->flags;
+    ras.nPoints   = glyph->n_points;
+    ras.nContours = glyph->n_contours;
+    ras.coords    = glyph->points;
+
+    Set_High_Precision( RAS_VARS glyph->high_precision );
+    ras.scale_shift    = ras.precision_shift+1;
+    ras.dropOutControl = glyph->dropout_mode;
+    ras.second_pass    = glyph->second_pass;
+
+
+    /* Vertical Sweep */
+
+    ras.band_top            = 0;
+    ras.band_stack[0].y_min = 0;
+    ras.band_stack[0].y_max = 2 * ras.target.rows - 1;
+
+    ras.bWidth  = ras.gray_width;
+    if ( ras.bWidth > ras.target.cols/4 )
+      ras.bWidth = ras.target.cols/4;
+
+    ras.bWidth  = ras.bWidth * 8;
+    ras.bTarget = (Byte*)ras.gray_lines;
+    ras.gTarget = (Byte*)ras.target.bitmap;
+
+    ras.Proc_Sweep_Init = Vertical_Gray_Sweep_Init;
+    ras.Proc_Sweep_Span = Vertical_Sweep_Span;
+    ras.Proc_Sweep_Drop = Vertical_Sweep_Drop;
+    ras.Proc_Sweep_Step = Vertical_Gray_Sweep_Step;
+
+    error = Render_Single_Pass( RAS_VARS  0 );
+    if (error)
+      return error;
+
+    /* Horizontal Sweep */
+
+    if ( ras.second_pass && ras.dropOutControl != 0 )
+    {
+      ras.Proc_Sweep_Init = Horizontal_Sweep_Init;
+      ras.Proc_Sweep_Span = Horizontal_Gray_Sweep_Span;
+      ras.Proc_Sweep_Drop = Horizontal_Gray_Sweep_Drop;
+      ras.Proc_Sweep_Step = Horizontal_Sweep_Step;
+
+      ras.band_top            = 0;
+      ras.band_stack[0].y_min = 0;
+      ras.band_stack[0].y_max = ras.target.width * 2 - 1;
+
+      error = Render_Single_Pass( RAS_VARS  1 );
+      if (error)
+        return error;
+    }
+
+    return FT_Err_Ok;
+  }
+
+#endif /* FT_CONFIG_OPTION_GRAY_SCALING */
+
+
+/************************************************/
+/*                                              */
+/* InitRasterizer                               */
+/*                                              */
+/*  Raster Initialization.                      */
+/*  Gets the bitmap description and render pool */
+/*  addresses.                                  */
+/*                                              */
+/************************************************/
+
+#undef ras
+
+  LOCAL_FUNC
+  FT_Error  TTRaster_Done( PEngine_Instance  engine )
+  {
+    TRaster_Instance*  ras = (TRaster_Instance*)engine->raster_component;
+
+
+    if ( !ras )
+      return FT_Err_Ok;
+
+    FREE( ras->buff );
+    FREE( ras->gray_lines );
+
+    return FT_Err_Ok;
+  }
+
+
+  LOCAL_FUNC
+  FT_Error  TTRaster_Init( PEngine_Instance  engine )
+  {
+    FT_Error  error;
+
+    Int  i, l, j, c;
+
+    TRaster_Instance*  ras;
+
+
+#ifdef FT_CONFIG_OPTION_STATIC_RASTER
+    ras = engine->raster_component = &cur_ras;
+#else
+    if ( ALLOC( engine->raster_component, sizeof ( TRaster_Instance ) ) )
+      return error;
+
+    ras = (TRaster_Instance*)engine->raster_component;
+#endif
+
+    if ( ALLOC( ras->buff,       RASTER_RENDER_POOL )  ||
+         ALLOC( ras->gray_lines, RASTER_GRAY_LINES ) )
+       return error;
+
+    ras->sizeBuff   = ras->buff + ( RASTER_RENDER_POOL/sizeof(long) );
+    ras->gray_width = RASTER_GRAY_LINES/2;
+
+    /* Initialization of Count_Table */
+
+    for ( i = 0; i < 256; i++ )
+    {
+      l = 0;
+      j = i;
+
+      for ( c = 0; c < 4; c++ )
+      {
+        l <<= 4;
+
+        if ( j & 0x80 ) l++;
+        if ( j & 0x40 ) l++;
+
+        j = ( j << 2 ) & 0xFF;
+      }
+
+      ras->count_table[i] = l;
+    }
+
+    ras->dropOutControl = 2;
+    ras->error          = Raster_Err_None;
+
+    return FT_Err_Ok;
+  }
+
+
+/* END */