Commit 347a714c5438218c0294290d5b26993df6829e02

Werner Lemberg 2002-05-15T06:16:57

Initial revision

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
diff --git a/src/type42/module.mk b/src/type42/module.mk
new file mode 100644
index 0000000..ceaea41
--- /dev/null
+++ b/src/type42/module.mk
@@ -0,0 +1,22 @@
+#
+# FreeType 2 Type42 module definition
+#
+
+
+# Copyright 2002 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.
+
+
+make_module_list: add_type42_driver
+
+add_type42_driver:
+	$(OPEN_DRIVER)t42_driver_class$(CLOSE_DRIVER)
+	$(ECHO_DRIVER)type42     $(ECHO_DRIVER_DESC)Type 42 font files with no known extension$(ECHO_DRIVER_DONE)
+
+# EOF
diff --git a/src/type42/rules.mk b/src/type42/rules.mk
new file mode 100644
index 0000000..a55f42e
--- /dev/null
+++ b/src/type42/rules.mk
@@ -0,0 +1,66 @@
+#
+# FreeType 2 Type42 driver configuration rules
+#
+
+
+# Copyright 2002 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.
+
+
+# Type42 driver directory
+#
+T42_DIR  := $(SRC_)type42
+T42_DIR_ := $(T42_DIR)$(SEP)
+
+
+# compilation flags for the driver
+#
+T42_COMPILE := $(FT_COMPILE) $I$(T42_DIR)
+
+
+# Type42 driver source
+#
+T42_DRV_SRC := $(T42_DIR_)t42drivr.c
+
+# Type42 driver headers
+#
+T42_DRV_H :=
+
+
+# Type42 driver object(s)
+#
+#   T42_DRV_OBJ_M is used during `multi' builds
+#   T42_DRV_OBJ_S is used during `single' builds
+#
+T42_DRV_OBJ_M := $(T42_DRV_SRC:$(T42_DIR_)%.c=$(OBJ_)%.$O)
+T42_DRV_OBJ_S := $(OBJ_)t42drivr.$O
+
+# Type42 driver source file for single build
+#
+T42_DRV_SRC_S := $(T42_DIR_)t42drivr.c
+
+
+# Type42 driver - single object
+#
+$(T42_DRV_OBJ_S): $(T42_DRV_SRC_S) $(T42_DRV_SRC) $(FREETYPE_H) $(T42_DRV_H)
+	$(T42_COMPILE) $T$@ $(T42_DRV_SRC_S)
+
+
+# Type42 driver - multiple objects
+#
+$(OBJ_)%.$O: $(T42_DIR_)%.c $(FREETYPE_H) $(T42_DRV_H)
+	$(T42_COMPILE) $T$@ $<
+
+
+# update main driver object lists
+#
+DRV_OBJS_S += $(T42_DRV_OBJ_S)
+DRV_OBJS_M += $(T42_DRV_OBJ_M)
+
+# EOF
diff --git a/src/type42/t42drivr.c b/src/type42/t42drivr.c
new file mode 100644
index 0000000..81e0e8a
--- /dev/null
+++ b/src/type42/t42drivr.c
@@ -0,0 +1,2138 @@
+/***************************************************************************/
+/*                                                                         */
+/*  t42drivr.c                                                             */
+/*                                                                         */
+/*    FreeType font driver for Type 42 fonts (body only).                  */
+/*                                                                         */
+/*  Copyright 2002 by Roberto Alameda.                                     */
+/*                                                                         */
+/*  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.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+
+#include <ft2build.h>
+#define FT_ERR_PREFIX  T42_Err_
+#define FT_ERR_BASE    FT_Mod_Err_Type42
+
+#include FT_CONFIG_STANDARD_LIBRARY_H
+
+#include FT_INTERNAL_DEBUG_H
+#include FT_CONFIG_CONFIG_H
+
+#include FT_ERRORS_H
+#include FT_FREETYPE_H
+#include FT_TYPE1_TABLES_H
+#include FT_LIST_H
+
+#include FT_INTERNAL_DRIVER_H
+#include FT_INTERNAL_OBJECTS_H
+#include FT_INTERNAL_TYPE1_TYPES_H
+#include FT_INTERNAL_POSTSCRIPT_AUX_H
+#include FT_INTERNAL_STREAM_H
+
+
+  /********************* Data Definitions ******************/
+
+  typedef enum  T42_EncodingType_
+  {
+    T42_ENCODING_TYPE_NONE = 0,
+    T42_ENCODING_TYPE_ARRAY,
+    T42_ENCODING_TYPE_STANDARD,
+    T42_ENCODING_TYPE_EXPERT,
+    T42_ENCODING_TYPE_ISOLATIN1
+  
+  } T42_EncodingType;
+
+
+  typedef struct  T42_Font_ 
+  {
+    /* font info dictionary */
+    PS_FontInfoRec   font_info; 
+
+    /* top-level dictionary */
+    FT_String*        font_name;
+
+    T42_EncodingType  encoding_type; 
+    T1_EncodingRec    encoding;
+
+    FT_Byte*          charstrings_block;
+    FT_Byte*          glyph_names_block;
+
+    FT_Int            num_glyphs;
+    FT_String**       glyph_names;       /* array of glyph names       */
+    FT_Byte**         charstrings;       /* array of glyph charstrings */
+    FT_Int*           charstrings_len;
+
+    FT_Byte           paint_type;
+    FT_Byte           font_type;
+    FT_Matrix         font_matrix; /* From FontMatrix field: a, b, c, d */
+    FT_Vector         font_offset; /* From FontMatrix field: tx, ty */
+    FT_BBox           font_bbox;
+
+    FT_Int            stroke_width;  
+
+  } T42_FontRec, *T42_Font;
+
+
+  typedef struct  T42_FaceRec_
+  {
+    FT_FaceRec     root;
+    T42_FontRec    type42;
+    void*          psnames;
+    void*          psaux;
+    void*          afm_data;
+    FT_Byte*       ttf_data;
+    FT_ULong       ttf_size;
+    FT_Face        ttf_face;
+    FT_CharMapRec  charmaprecs[2];
+    FT_CharMap     charmaps[2];
+    PS_Unicodes    unicode_map;
+
+  } T42_FaceRec, *T42_Face;
+
+
+  typedef struct  T42_DriverRec_
+  {
+    FT_DriverRec     root;
+    FT_Driver_Class  ttclazz;
+    void*            extension_component;
+
+  } T42_DriverRec, *T42_Driver;
+
+
+  typedef struct  T42_SizeRec_
+  {
+    FT_SizeRec  root;
+    FT_Size     ttsize;
+
+  } T42_SizeRec, *T42_Size;
+
+
+  typedef struct  T42_GlyphSlotRec_
+  {
+    FT_GlyphSlotRec  root;
+    FT_GlyphSlot     ttslot;
+
+  } T42_GlyphSlotRec, *T42_GlyphSlot;
+
+
+  /*********** Parser definitions *************/
+
+  typedef struct  T42_ParserRec_
+  {
+    PS_ParserRec  root;
+    FT_Stream     stream;
+
+    FT_Byte*      base_dict;
+    FT_Int        base_len;
+
+    FT_Byte       in_memory;
+
+  } T42_ParserRec, *T42_Parser;
+
+
+  typedef struct  T42_Loader_
+  {
+    T42_ParserRec  parser;          /* parser used to read the stream */
+
+    FT_Int         num_chars;       /* number of characters in encoding */
+    PS_TableRec    encoding_table;  /* PS_Table used to store the       */
+                                    /* encoding character names         */
+
+    FT_Int         num_glyphs;
+    PS_TableRec    glyph_names;
+    PS_TableRec    charstrings;
+
+  } T42_LoaderRec, *T42_Loader;
+
+
+  /*********************** Prototypes *********************/
+
+  static void
+  parse_font_name( T42_Face    face,
+                   T42_Loader  loader );
+  static void
+  parse_font_bbox( T42_Face    face,
+                   T42_Loader  loader );
+  static void
+  parse_font_matrix( T42_Face    face,
+                     T42_Loader  loader );
+  static void
+  parse_encoding( T42_Face    face,
+                  T42_Loader  loader );
+  static void
+  parse_charstrings( T42_Face    face,
+                     T42_Loader  loader );
+  static void
+  parse_sfnts( T42_Face    face,
+               T42_Loader  loader );
+
+
+  static const
+  T1_FieldRec  t42_keywords[] = {
+
+#undef  FT_STRUCTURE
+#define FT_STRUCTURE  T1_FontInfo
+#undef  T1CODE
+#define T1CODE        T1_FIELD_LOCATION_FONT_INFO
+
+    T1_FIELD_STRING   ( "version",            version )
+    T1_FIELD_STRING   ( "Notice",             notice )
+    T1_FIELD_STRING   ( "FullName",           full_name )
+    T1_FIELD_STRING   ( "FamilyName",         family_name )
+    T1_FIELD_STRING   ( "Weight",             weight )
+    T1_FIELD_NUM      ( "ItalicAngle",        italic_angle )
+    T1_FIELD_TYPE_BOOL( "isFixedPitch",       is_fixed_pitch )
+    T1_FIELD_NUM      ( "UnderlinePosition",  underline_position )
+    T1_FIELD_NUM      ( "UnderlineThickness", underline_thickness )
+
+#undef  FT_STRUCTURE
+#define FT_STRUCTURE  T42_FontRec
+#undef  T1CODE
+#define T1CODE        T1_FIELD_LOCATION_FONT_DICT
+
+    T1_FIELD_NUM( "PaintType",   paint_type )
+    T1_FIELD_NUM( "FontType",    font_type )
+    T1_FIELD_NUM( "StrokeWidth", stroke_width )
+
+    T1_FIELD_CALLBACK( "FontName",    parse_font_name )
+    T1_FIELD_CALLBACK( "FontBBox",    parse_font_bbox )
+    T1_FIELD_CALLBACK( "FontMatrix",  parse_font_matrix )
+    T1_FIELD_CALLBACK( "Encoding",    parse_encoding )
+    T1_FIELD_CALLBACK( "CharStrings", parse_charstrings )
+    T1_FIELD_CALLBACK( "sfnts",       parse_sfnts )
+
+    { 0, T1_FIELD_LOCATION_CID_INFO, T1_FIELD_TYPE_NONE, 0, 0, 0, 0, 0 }
+  };
+
+
+#define T1_Add_Table( p, i, o, l )  (p)->funcs.add( (p), i, o, l )
+#define T1_Done_Table( p )          \
+          do                        \
+          {                         \
+            if ( (p)->funcs.done )  \
+              (p)->funcs.done( p ); \
+          } while ( 0 )
+#define T1_Release_Table( p )          \
+          do                           \
+          {                            \
+            if ( (p)->funcs.release )  \
+              (p)->funcs.release( p ); \
+          } while ( 0 )
+
+#define T1_Skip_Spaces( p )  (p)->root.funcs.skip_spaces( &(p)->root )
+#define T1_Skip_Alpha( p )   (p)->root.funcs.skip_alpha ( &(p)->root )
+
+#define T1_ToInt( p )       (p)->root.funcs.to_int( &(p)->root )
+#define T1_ToFixed( p, t )  (p)->root.funcs.to_fixed( &(p)->root, t )
+
+#define T1_ToCoordArray( p, m, c )                           \
+          (p)->root.funcs.to_coord_array( &(p)->root, m, c )
+#define T1_ToFixedArray( p, m, f, t )                           \
+          (p)->root.funcs.to_fixed_array( &(p)->root, m, f, t )
+#define T1_ToToken( p, t )                          \
+          (p)->root.funcs.to_token( &(p)->root, t )
+#define T1_ToTokenArray( p, t, m, c )                           \
+          (p)->root.funcs.to_token_array( &(p)->root, t, m, c )
+
+#define T1_Load_Field( p, f, o, m, pf )                         \
+          (p)->root.funcs.load_field( &(p)->root, f, o, m, pf )
+#define T1_Load_Field_Table( p, f, o, m, pf )                         \
+          (p)->root.funcs.load_field_table( &(p)->root, f, o, m, pf )
+
+
+  /********************* Parsing Functions ******************/
+
+  static FT_Error
+  T42_New_Parser( T42_Parser     parser,
+                  FT_Stream      stream,
+                  FT_Memory      memory,
+                  PSAux_Service  psaux )
+  {
+    FT_Error  error = T42_Err_Ok;
+    FT_Long   size;
+
+
+    psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory );
+
+    parser->stream    = stream;
+    parser->base_len  = 0;
+    parser->base_dict = 0;
+    parser->in_memory = 0;
+
+    /*******************************************************************/
+    /*                                                                 */
+    /* Here a short summary of what is going on:                       */
+    /*                                                                 */
+    /*   When creating a new Type 42 parser, we try to locate and load */
+    /*   the base dictionary, loading the whole font into memory.      */
+    /*                                                                 */
+    /*   When `loading' the base dictionary, we only setup pointers in */
+    /*   the case of a memory-based stream.  Otherwise, we allocate    */
+    /*   and load the base dictionary in it.                           */
+    /*                                                                 */
+    /*   parser->in_memory is set if we have a memory stream.          */
+    /*                                                                 */
+
+    if ( FT_STREAM_SEEK( 0L ) )
+      goto Exit;
+
+    size = stream->size;
+
+    /* now, try to load `size' bytes of the `base' dictionary we */
+    /* found previously                                          */
+
+    /* if it is a memory-based resource, set up pointers */
+    if ( !stream->read )
+    {
+      parser->base_dict = (FT_Byte*)stream->base + stream->pos;
+      parser->base_len  = size;
+      parser->in_memory = 1;
+
+      /* check that the `size' field is valid */
+      if ( FT_STREAM_SKIP( size ) )
+        goto Exit;
+    }
+    else
+    {
+      /* read segment in memory */
+      if (FT_ALLOC( parser->base_dict, size )       ||
+          FT_STREAM_READ( parser->base_dict, size ) )
+        goto Exit;
+      parser->base_len = size;
+    }
+
+    /* Now check font format; we must see `%!PS-TrueTypeFont' */
+    if (size <= 17                                    ||
+        ( ft_strncmp( (const char*)parser->base_dict,
+                      "%!PS-TrueTypeFont", 17) )      )
+      error = T42_Err_Unknown_File_Format;
+    else
+    {
+      parser->root.base   = parser->base_dict;
+      parser->root.cursor = parser->base_dict;
+      parser->root.limit  = parser->root.cursor + parser->base_len;
+    }
+
+  Exit:
+    if ( error && !parser->in_memory )
+      FT_FREE( parser->base_dict );
+
+    return error;
+  }
+
+
+  static void
+  T42_Finalize_Parser( T42_Parser  parser )
+  {
+    FT_Memory  memory = parser->root.memory;
+
+
+    /* free the base dictionary only when we have a disk stream */
+    if ( !parser->in_memory )
+      FT_FREE( parser->base_dict );
+
+    parser->root.funcs.done( &parser->root );
+  }
+
+
+  static int
+  is_alpha( FT_Byte  c )
+  {
+    /* Note: we must accept "+" as a valid character, as it is used in */
+    /*       embedded type1 fonts in PDF documents.                    */
+    /*                                                                 */
+    return ( ft_isalnum( c ) ||
+             c == '.'        ||
+             c == '_'        ||
+             c == '-'        ||
+             c == '+'        );
+  }
+
+
+  static int
+  is_space( FT_Byte  c )
+  {
+    return ( c == ' ' || c == '\t' || c == '\r' || c == '\n' );
+  }
+
+
+  static void
+  parse_font_name( T42_Face    face,
+                   T42_Loader  loader )
+  {
+    T42_Parser  parser = &loader->parser;
+    FT_Error    error;
+    FT_Memory   memory = parser->root.memory;
+    FT_Int      len;
+    FT_Byte*    cur;
+    FT_Byte*    cur2;
+    FT_Byte*    limit;
+
+
+    T1_Skip_Spaces( parser );
+
+    cur   = parser->root.cursor;
+    limit = parser->root.limit;
+
+    if ( cur >= limit - 1              ||
+         ( *cur != '/' && *cur != '(') )
+      return;
+
+    cur++;
+    cur2 = cur;
+    while ( cur2 < limit && is_alpha( *cur2 ) )
+      cur2++;
+
+    len = (FT_Int)( cur2 - cur );
+    if ( len > 0 )
+    {
+      if ( FT_ALLOC( face->type42.font_name, len + 1 ) )
+      {
+        parser->root.error = error;
+        return;
+      }
+
+      FT_MEM_COPY( face->type42.font_name, cur, len );
+      face->type42.font_name[len] = '\0';
+    }
+    parser->root.cursor = cur2;
+  }
+
+
+  static void
+  parse_font_bbox( T42_Face   face,
+                  T42_Loader  loader )
+  {
+    T42_Parser  parser = &loader->parser;
+    FT_BBox*    bbox   = &face->type42.font_bbox;
+
+    bbox->xMin = T1_ToInt( parser );
+    bbox->yMin = T1_ToInt( parser );
+    bbox->xMax = T1_ToInt( parser );
+    bbox->yMax = T1_ToInt( parser );
+  }
+
+
+  static void
+  parse_font_matrix( T42_Face    face,
+                     T42_Loader  loader )
+  {
+    T42_Parser  parser = &loader->parser;
+    FT_Matrix*  matrix = &face->type42.font_matrix;
+    FT_Vector*  offset = &face->type42.font_offset;
+    FT_Face     root   = (FT_Face)&face->root;
+    FT_Fixed    temp[6];
+    FT_Fixed    temp_scale;
+
+
+    /* XXX: Are these three lines necessary */
+    if ( matrix->xx || matrix->yx )
+      /* with synthetic fonts, it's possible we get here twice  */
+      return;
+
+    (void)T1_ToFixedArray( parser, 6, temp, 3 );
+
+    temp_scale = ABS( temp[3] );
+
+    /* Set Units per EM based on FontMatrix values.  We set the value to */
+    /* 1000 / temp_scale, because temp_scale was already multiplied by   */
+    /* 1000 (in t1_tofixed, from psobjs.c).                              */
+
+    root->units_per_EM = (FT_UShort)( FT_DivFix( 1000 * 0x10000L,
+                                                 temp_scale ) >> 16 );
+
+    /* we need to scale the values by 1.0/temp_scale */
+    if ( temp_scale != 0x10000L ) {
+      temp[0] = FT_DivFix( temp[0], temp_scale );
+      temp[1] = FT_DivFix( temp[1], temp_scale );
+      temp[2] = FT_DivFix( temp[2], temp_scale );
+      temp[4] = FT_DivFix( temp[4], temp_scale );
+      temp[5] = FT_DivFix( temp[5], temp_scale );
+      temp[3] = 0x10000L;
+    }
+
+    matrix->xx = temp[0];
+    matrix->yx = temp[1];
+    matrix->xy = temp[2];
+    matrix->yy = temp[3];
+
+    /* note that the offsets must be expressed in integer font units */
+    offset->x  = temp[4] >> 16;
+    offset->y  = temp[5] >> 16;
+  }
+
+
+  static void
+  parse_encoding( T42_Face    face,
+                  T42_Loader  loader )
+  {
+    T42_Parser     parser = &loader->parser;
+    FT_Byte*       cur    = parser->root.cursor;
+    FT_Byte*       limit  = parser->root.limit;
+
+    PSAux_Service  psaux  = (PSAux_Service)face->psaux;
+
+
+    /* skip whitespace */
+    while ( is_space( *cur ) )
+    {
+      cur++;
+      if ( cur >= limit )
+      {
+        FT_ERROR(( "parse_encoding: out of bounds!\n" ));
+        parser->root.error = T42_Err_Invalid_File_Format;
+        return;
+      }
+    }
+
+    /* if we have a number, then the encoding is an array, */
+    /* and we must load it now                             */
+    if ( (FT_Byte)( *cur - '0' ) < 10 )
+    {
+      T1_Encoding  encode     = &face->type42.encoding;
+      FT_Int       count, n;
+      PS_Table     char_table = &loader->encoding_table;
+      FT_Memory    memory     = parser->root.memory;
+      FT_Error     error;
+
+
+      /* read the number of entries in the encoding, should be 256 */
+      count = T1_ToInt( parser );
+      if ( parser->root.error )
+        return;
+
+      /* we use a T1_Table to store our charnames */
+      loader->num_chars = encode->num_chars = count;
+      if ( FT_NEW_ARRAY( encode->char_index, count ) ||
+           FT_NEW_ARRAY( encode->char_name,  count ) ||
+           FT_SET_ERROR( psaux->ps_table_funcs->init(
+                           char_table, count, memory ) ) )
+      {
+        parser->root.error = error;
+        return;
+      }
+
+      /* We need to `zero' out encoding_table.elements */
+      for ( n = 0; n < count; n++ )
+      {
+        char*  notdef = (char *)".notdef";
+
+
+        T1_Add_Table( char_table, n, notdef, 8 );
+      }
+
+      /* Now, we will need to read a record of the form         */
+      /* ... charcode /charname ... for each entry in our table */
+      /*                                                        */
+      /* We simply look for a number followed by an immediate   */
+      /* name.  Note that this ignores correctly the sequence   */
+      /* that is often seen in type1 fonts:                     */
+      /*                                                        */
+      /*   0 1 255 { 1 index exch /.notdef put } for dup        */
+      /*                                                        */
+      /* used to clean the encoding array before anything else. */
+      /*                                                        */
+      /* We stop when we encounter a `def'.                     */
+
+      cur   = parser->root.cursor;
+      limit = parser->root.limit;
+      n     = 0;
+
+      for ( ; cur < limit; )
+      {
+        FT_Byte  c;
+
+
+        c = *cur;
+
+        /* we stop when we encounter a `def' */
+        if ( c == 'd' && cur + 3 < limit )
+        {
+          if ( cur[1] == 'e'       &&
+               cur[2] == 'f'       &&
+               is_space( cur[-1] ) &&
+               is_space( cur[3] )  )
+          {
+            FT_TRACE6(( "encoding end\n" ));
+            break;
+          }
+        }
+
+        /* otherwise, we must find a number before anything else */
+        if ( (FT_Byte)( c - '0' ) < 10 )
+        {
+          FT_Int  charcode;
+
+
+          parser->root.cursor = cur;
+          charcode = T1_ToInt( parser );
+          cur      = parser->root.cursor;
+
+          /* skip whitespace */
+          while ( cur < limit && is_space( *cur ) )
+            cur++;
+
+          if ( cur < limit && *cur == '/' )
+          {
+            /* bingo, we have an immediate name -- it must be a */
+            /* character name                                   */
+            FT_Byte*  cur2 = cur + 1;
+            FT_Int    len;
+
+
+            while ( cur2 < limit && is_alpha( *cur2 ) )
+              cur2++;
+
+            len = (FT_Int)( cur2 - cur - 1 );
+
+            parser->root.error = T1_Add_Table( char_table, charcode,
+                                               cur + 1, len + 1 );
+            char_table->elements[charcode][len] = '\0';
+            if ( parser->root.error )
+              return;
+
+            cur = cur2;
+          }
+        }
+        else
+          cur++;
+      }
+
+      face->type42.encoding_type = T42_ENCODING_TYPE_ARRAY;
+      parser->root.cursor        = cur;
+    }
+    /* Otherwise, we should have either `StandardEncoding', */
+    /* `ExpertEncoding', or `ISOLatin1Encoding'             */
+    else
+    {
+      if ( cur + 17 < limit                                            &&
+           ft_strncmp( (const char*)cur, "StandardEncoding", 16 ) == 0 )
+        face->type42.encoding_type = T42_ENCODING_TYPE_STANDARD;
+
+      else if ( cur + 15 < limit                                          &&
+                ft_strncmp( (const char*)cur, "ExpertEncoding", 14 ) == 0 )
+        face->type42.encoding_type = T42_ENCODING_TYPE_EXPERT;
+
+      else if ( cur + 18 < limit                                             &&
+                ft_strncmp( (const char*)cur, "ISOLatin1Encoding", 17 ) == 0 )
+        face->type42.encoding_type = T42_ENCODING_TYPE_ISOLATIN1;
+
+      else {
+        FT_ERROR(( "parse_encoding: invalid token!\n" ));
+        parser->root.error = T42_Err_Invalid_File_Format;
+      }
+    }
+  }
+
+
+  static FT_Byte
+  hexval( FT_Byte  v )
+  {
+    if ( v >= 'A' && v <= 'F' )
+      return v - 'A' + 10;
+    if ( v >= 'a' && v <= 'f' )
+      return v - 'a' + 10;
+    if ( v >= '0' && v <= '9' )
+      return v - '0';
+
+    return 0;
+  }
+
+
+  static void
+  parse_sfnts( T42_Face    face,
+               T42_Loader  loader )
+  {
+    T42_Parser  parser = &loader->parser;
+    FT_Memory   memory = parser->root.memory;
+    FT_Byte*    cur    = parser->root.cursor;
+    FT_Byte*    limit  = parser->root.limit;
+    FT_Error    error;
+    FT_Int      num_tables, status;
+    FT_ULong    count, ttf_size, string_size;
+    FT_Bool     in_string  = 0;
+    FT_Byte     v;
+
+
+    /* The format is `/sfnts [ <...> <...> ... ] def' */
+
+    while ( is_space( *cur ) )
+      cur++;
+
+    if (*cur++ == '[')
+    {
+      status = 0;
+      count = 0;
+    }
+    else
+    {
+      FT_ERROR(( "parse_sfnts: can't find begin of sfnts vector!\n" ));
+      error = T42_Err_Invalid_File_Format;
+      goto Fail;
+    }
+
+    while ( cur < limit - 2 )
+    {
+      while ( is_space( *cur ) )
+        cur++;
+
+      switch ( *cur )
+      {
+      case ']':
+        parser->root.cursor = cur++;
+        return;
+
+      case '<':
+        in_string   = 1;
+        string_size = 0;
+        cur++;
+        continue;
+
+      case '>':
+        if ( !in_string )
+        {
+          FT_ERROR(( "parse_sfnts: found unpaired `>'!\n" ));
+          error = T42_Err_Invalid_File_Format;
+          goto Fail;
+        }
+
+        /* A string can have, as a last byte,         */
+        /* a zero byte for padding.  If so, ignore it */
+        if ( ( v == 0 ) && ( string_size % 2 == 1 ) )
+          count--;
+        in_string = 0;
+        cur++;
+        continue;
+
+      case '%':
+        if ( !in_string )
+        {
+          /* Comment found; skip till end of line */
+          while ( *cur != '\n' )
+            cur++;
+          continue;
+        }
+        else
+        {
+          FT_ERROR(( "parse_sfnts: found `%' in string!\n" ));
+          error = T42_Err_Invalid_File_Format;
+          goto Fail;
+        }
+
+      default:
+        if ( !ft_xdigit( *cur ) || !ft_xdigit( *(cur + 1) ) )
+        {
+          FT_ERROR(( "parse_sfnts: found non-hex characters in string" ));
+          error = T42_Err_Invalid_File_Format;
+          goto Fail;
+        }
+
+        v = 16 * hexval( *cur++ ) + hexval( *cur++ );
+        string_size++;
+      }
+
+      switch ( status )
+      {
+      case 0: /* The '[' was read, so load offset table, 12 bytes */
+        if ( count < 12 )
+        {
+          face->ttf_data[count++] = v;
+          continue;
+        }
+        else
+        {
+          num_tables = 16 * face->ttf_data[4] + face->ttf_data[5];
+          status     = 1;
+          ttf_size   = 12 + 16 * num_tables;
+
+          if ( FT_REALLOC( face->ttf_data, 12, ttf_size ) )
+            goto Fail;
+        }
+        /* No break, fall-through */
+
+      case 1: /* The offset table is read; read now the table directory */
+        if ( count < ttf_size )
+        {
+          face->ttf_data[count++] = v;
+          continue;
+        }
+        else
+        {
+          int      i;
+          FT_ULong len;
+
+
+          for ( i = 0; i < num_tables; i++ )
+          {
+            len  = face->ttf_data[12 + 16*i + 12 + 0] << 24;
+            len += face->ttf_data[12 + 16*i + 12 + 1] << 16;
+            len += face->ttf_data[12 + 16*i + 12 + 2] << 8;
+            len += face->ttf_data[12 + 16*i + 12 + 3];
+
+            /* Pad to a 4-byte boundary length */
+            ttf_size += ( len + 3 ) & ~3;
+          }
+
+          status         = 2;
+          face->ttf_size = ttf_size;
+
+          if ( FT_REALLOC( face->ttf_data, 12 + 16 * num_tables,
+                           ttf_size + 1 ) )
+            goto Fail;
+        }
+        /* No break, fall-through */
+
+      case 2: /* We are reading normal tables; just swallow them */
+        face->ttf_data[count++] = v;
+
+      }
+    }
+
+    /* If control reaches this point, the format was not valid */
+    error = T42_Err_Invalid_File_Format;
+
+  Fail:
+    parser->root.error = error;
+  }
+
+
+  static void
+  parse_charstrings( T42_Face    face,
+                     T42_Loader  loader )
+  {
+    T42_Parser     parser     = &loader->parser;
+    PS_Table       code_table = &loader->charstrings;
+    PS_Table       name_table = &loader->glyph_names;
+    FT_Memory      memory     = parser->root.memory;
+    FT_Error       error;
+
+    PSAux_Service  psaux      = (PSAux_Service)face->psaux;
+
+    FT_Byte*       cur;
+    FT_Byte*       limit      = parser->root.limit;
+    FT_Int         n;
+
+
+    loader->num_glyphs = T1_ToInt( parser );
+    if ( parser->root.error )
+      return;
+
+    /* initialize tables */
+
+    error = psaux->ps_table_funcs->init( code_table,
+                                         loader->num_glyphs,
+                                         memory );
+    if ( error )
+      goto Fail;
+
+    error = psaux->ps_table_funcs->init( name_table,
+                                         loader->num_glyphs,
+                                         memory );
+    if ( error )
+      goto Fail;
+
+    n = 0;
+
+    for (;;)
+    {
+      /* the format is simple:                    */
+      /*   `/glyphname' + index + def             */
+      /*                                          */
+      /* note that we stop when we find an `end'  */
+      /*                                          */
+      T1_Skip_Spaces( parser );
+
+      cur = parser->root.cursor;
+      if ( cur >= limit )
+        break;
+
+      /* we stop when we find an `end' keyword */
+      if ( *cur   == 'e'   &&
+           cur + 3 < limit &&
+           cur[1] == 'n'   &&
+           cur[2] == 'd'   )
+        break;
+
+      if ( *cur != '/' )
+        T1_Skip_Alpha( parser );
+      else
+      {
+        FT_Byte*  cur2 = cur + 1;
+        FT_Int    len;
+
+
+        while ( cur2 < limit && is_alpha( *cur2 ) )
+          cur2++;
+        len = (FT_Int)( cur2 - cur - 1 );
+
+        error = T1_Add_Table( name_table, n, cur + 1, len + 1 );
+        if ( error )
+          goto Fail;
+
+        /* add a trailing zero to the name table */
+        name_table->elements[n][len] = '\0';
+
+        parser->root.cursor = cur2;
+        T1_Skip_Spaces( parser );
+
+        cur2 = cur = parser->root.cursor;
+        if ( cur >= limit )
+          break;
+
+        while ( cur2 < limit && is_alpha( *cur2 ) )
+          cur2++;
+        len = (FT_Int)( cur2 - cur );
+
+        error = T1_Add_Table( code_table, n, cur, len + 1 );
+        if ( error )
+          goto Fail;
+
+        code_table->elements[n][len] = '\0';
+
+        n++;
+        if ( n >= loader->num_glyphs )
+          break;
+      }
+    }
+
+    /* Index 0 must be a .notdef element */
+    if ( ft_strcmp( (char *)name_table->elements[0], ".notdef" ) )
+    {
+      FT_ERROR(( "parse_charstrings: Index 0 is not `.notdef'!\n" ));
+      error = T42_Err_Invalid_File_Format;
+      goto Fail;
+    }
+
+    loader->num_glyphs = n;
+    return;
+
+  Fail:
+    parser->root.error = error;
+  }
+
+
+  static FT_Error
+  t42_load_keyword( T42_Face    face,
+                    T42_Loader  loader,
+                    T1_Field    field )
+  {
+    FT_Error  error;
+    void*     dummy_object;
+    void**    objects;
+    FT_UInt   max_objects = 0;
+
+
+    /* if the keyword has a dedicated callback, call it */
+    if ( field->type == T1_FIELD_TYPE_CALLBACK ) {
+      field->reader( (FT_Face)face, loader );
+      error = loader->parser.root.error;
+      goto Exit;
+    }
+
+    /* now, the keyword is either a simple field, or a table of fields; */
+    /* we are now going to take care of it                              */
+    switch ( field->location )
+    {
+    case T1_FIELD_LOCATION_FONT_INFO:
+      dummy_object = &face->type42.font_info;
+      objects      = &dummy_object;
+      break;
+
+    default:
+      dummy_object = &face->type42;
+      objects      = &dummy_object;
+    }
+
+    if ( field->type == T1_FIELD_TYPE_INTEGER_ARRAY ||
+         field->type == T1_FIELD_TYPE_FIXED_ARRAY   )
+      error = T1_Load_Field_Table( &loader->parser, field,
+                                   objects, max_objects, 0 );
+    else
+      error = T1_Load_Field( &loader->parser, field,
+                             objects, max_objects, 0 );
+
+   Exit:
+    return error;
+  }
+
+
+  static FT_Error
+  parse_dict( T42_Face    face,
+              T42_Loader  loader,
+              FT_Byte*    base,
+              FT_Long     size )
+  {
+    T42_Parser  parser = &loader->parser;
+    FT_Byte*    cur    = base;
+    FT_Byte*    limit  = cur + size;
+    FT_UInt     n_keywords = sizeof ( t42_keywords ) / 
+                             sizeof ( t42_keywords[0] );
+
+
+    parser->root.cursor = base;
+    parser->root.limit  = base + size;
+    parser->root.error  = 0;
+
+    for ( ; cur < limit; cur++ )
+    {
+      /* look for `FontDirectory', which causes problems on some fonts */
+      if ( *cur == 'F' && cur + 25 < limit                    &&
+           ft_strncmp( (char*)cur, "FontDirectory", 13 ) == 0 )
+      {
+        FT_Byte*  cur2;
+
+
+        /* skip the `FontDirectory' keyword */
+        cur += 13;
+        cur2 = cur;
+
+        /* lookup the `known' keyword */
+        while ( cur < limit && *cur != 'k'           &&
+                ft_strncmp( (char*)cur, "known", 5 ) )
+          cur++;
+
+        if ( cur < limit )
+        {
+          T1_TokenRec  token;
+
+
+          /* skip the `known' keyword and the token following it */
+          cur += 5;
+          loader->parser.root.cursor = cur;
+          T1_ToToken( &loader->parser, &token );
+
+          /* if the last token was an array, skip it! */
+          if ( token.type == T1_TOKEN_TYPE_ARRAY )
+            cur2 = parser->root.cursor;
+        }
+        cur = cur2;
+      }
+      /* look for immediates */
+      else if ( *cur == '/' && cur + 2 < limit )
+      {
+        FT_Byte*  cur2;
+        FT_UInt    i, len;
+
+
+        cur++;
+        cur2 = cur;
+        while ( cur2 < limit && is_alpha( *cur2 ) )
+          cur2++;
+
+        len  = (FT_UInt)( cur2 - cur );
+        if ( len > 0 && len < 22 ) /* XXX What shall it this 22? */
+        {
+          /* now, compare the immediate name to the keyword table */
+
+          /* Loop through all known keywords */
+          for ( i = 0; i < n_keywords; i++ )
+          {
+            T1_Field  keyword = (T1_Field)&t42_keywords[i];
+            FT_Byte   *name   = (FT_Byte*)keyword->ident;
+
+
+            if ( !name )
+              continue;
+
+            if ( ( len == ft_strlen( (const char *)name ) ) &&
+                 ( ft_memcmp( cur, name, len ) == 0 )       )
+            {
+              /* we found it -- run the parsing callback! */
+              parser->root.cursor = cur2;
+              T1_Skip_Spaces( parser );
+              parser->root.error = t42_load_keyword(face,
+                                                    loader,
+                                                    keyword );
+              if ( parser->root.error )
+                return parser->root.error;
+              cur = parser->root.cursor;
+              break;
+            }
+          }
+        }
+      }
+    }
+    return parser->root.error;
+  }
+
+
+  static void
+  t42_init_loader( T42_Loader  loader,
+                   T42_Face    face )
+  {
+    FT_UNUSED( face );
+
+    FT_MEM_SET( loader, 0, sizeof ( *loader ) );
+    loader->num_glyphs = 0;
+    loader->num_chars  = 0;
+
+    /* initialize the tables -- simply set their `init' field to 0 */
+    loader->encoding_table.init = 0;
+    loader->charstrings.init    = 0;
+    loader->glyph_names.init    = 0;
+  }
+
+
+  static void
+  t42_done_loader( T42_Loader  loader )
+  {
+    T42_Parser  parser = &loader->parser;
+
+
+    /* finalize tables */
+    T1_Release_Table( &loader->encoding_table );
+    T1_Release_Table( &loader->charstrings );
+    T1_Release_Table( &loader->glyph_names );
+
+    /* finalize parser */
+    T42_Finalize_Parser( parser );
+  }
+
+
+  static FT_Error
+  T42_Open_Face( T42_Face  face )
+  {
+    T42_LoaderRec  loader;
+    T42_Parser     parser;
+    T42_Font       type42 = &face->type42;
+    FT_Memory      memory = face->root.memory;
+    FT_Error       error;
+
+    PSAux_Service  psaux  = (PSAux_Service)face->psaux;
+
+
+    t42_init_loader( &loader, face );
+
+    parser = &loader.parser;
+
+    if ( FT_ALLOC( face->ttf_data, 12 ) )
+      goto Exit;
+
+    error = T42_New_Parser( parser,
+                            face->root.stream,
+                            memory,
+                            psaux);
+    if ( error )
+      goto Exit;
+
+    error = parse_dict( face, &loader, parser->base_dict, parser->base_len );
+
+    if ( type42->font_type != 42 )
+    {
+      error = T42_Err_Unknown_File_Format;
+      goto Exit;
+    }
+
+    /* now, propagate the charstrings and glyphnames tables */
+    /* to the Type42 data                                   */
+    type42->num_glyphs = loader.num_glyphs;
+
+    if ( !loader.charstrings.init ) {
+      FT_ERROR(( "T42_Open_Face: no charstrings array in face!\n" ));
+      error = T42_Err_Invalid_File_Format;
+    }
+
+    loader.charstrings.init   = 0;
+    type42->charstrings_block = loader.charstrings.block;
+    type42->charstrings       = loader.charstrings.elements;
+    type42->charstrings_len   = loader.charstrings.lengths;
+
+    /* we copy the glyph names `block' and `elements' fields; */
+    /* the `lengths' field must be released later             */
+    type42->glyph_names_block   = loader.glyph_names.block;
+    type42->glyph_names         = (FT_String**)loader.glyph_names.elements;
+    loader.glyph_names.block    = 0;
+    loader.glyph_names.elements = 0;
+
+    /* we must now build type42.encoding when we have a custom array */
+    if ( type42->encoding_type == T42_ENCODING_TYPE_ARRAY )
+    {
+      FT_Int    charcode, idx, min_char, max_char;
+      FT_Byte*  char_name;
+      FT_Byte*  glyph_name;
+
+
+      /* OK, we do the following: for each element in the encoding   */
+      /* table, look up the index of the glyph having the same name  */
+      /* as defined in the CharStrings array.                        */
+      /* The index is then stored in type42.encoding.char_index, and */
+      /* the name in type42.encoding.char_name                       */
+
+      min_char = +32000;
+      max_char = -32000;
+
+      charcode = 0;
+      for ( ; charcode < loader.encoding_table.max_elems; charcode++ )
+      {
+        type42->encoding.char_index[charcode] = 0;
+        type42->encoding.char_name [charcode] = (char *)".notdef";
+
+        char_name = loader.encoding_table.elements[charcode];
+        if ( char_name )
+          for ( idx = 0; idx < type42->num_glyphs; idx++ )
+          {
+            glyph_name = (FT_Byte*)type42->glyph_names[idx];
+            if ( ft_strcmp( (const char*)char_name,
+                            (const char*)glyph_name ) == 0 )
+            {
+              type42->encoding.char_index[charcode] = (FT_UShort)idx;
+              type42->encoding.char_name [charcode] = (char*)glyph_name;
+
+              /* Change min/max encoded char only if glyph name is */
+              /* not /.notdef                                      */
+              if ( ft_strcmp( (const char*)".notdef",
+                              (const char*)glyph_name ) != 0 )
+              {
+                if ( charcode < min_char ) min_char = charcode;
+                if ( charcode > max_char ) max_char = charcode;
+              }
+              break;
+            }
+          }
+      }
+      type42->encoding.code_first = min_char;
+      type42->encoding.code_last  = max_char;
+      type42->encoding.num_chars  = loader.num_chars;
+    }
+
+  Exit:
+    t42_done_loader( &loader );
+    return error;
+  }
+
+
+  /***************** Driver Functions *************/
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    The face object constructor.                                       */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    stream     ::  input stream where to load font data.               */
+  /*                                                                       */
+  /*    face_index :: The index of the font face in the resource.          */
+  /*                                                                       */
+  /*    num_params :: Number of additional generic parameters.  Ignored.   */
+  /*                                                                       */
+  /*    params     :: Additional generic parameters.  Ignored.             */
+  /*                                                                       */
+  /* <InOut>                                                               */
+  /*    face       :: The face record to build.                            */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  static FT_Error
+  T42_Face_Init( FT_Stream      stream,
+                 T42_Face       face,
+                 FT_Int         face_index,
+                 FT_Int         num_params,
+                 FT_Parameter*  params)
+  {
+    FT_Error          error;
+    PSNames_Service   psnames;
+    PSAux_Service     psaux;
+    FT_Face           root    = (FT_Face)&face->root;
+    FT_CharMap        charmap = face->charmaprecs;
+
+    FT_UNUSED( num_params );
+    FT_UNUSED( params );
+    FT_UNUSED( face_index );
+    FT_UNUSED( stream );
+
+
+    face->ttf_face       = NULL;
+    face->root.num_faces = 1;
+
+    /* XXX */
+    psnames = (PSNames_Service)face->psnames;
+    if ( !psnames )
+    {
+      psnames = (PSNames_Service)
+                FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
+                                         "psnames" );
+      face->psnames = psnames;
+    }
+
+    psaux = (PSAux_Service)face->psaux;
+    if ( !psaux )
+    {
+      psaux = (PSAux_Service)
+              FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
+                                       "psaux" );
+      face->psaux = psaux;
+    }
+
+    /* open the tokenizer, this will also check the font format */
+    error = T42_Open_Face( face );
+    if ( error )
+      goto Exit;
+
+    /* if we just wanted to check the format, leave successfully now */
+    if ( face_index < 0 )
+      goto Exit;
+
+    /* check the face index */
+    if ( face_index != 0 )
+    {
+      FT_ERROR(( "T42_Face_Init: invalid face index\n" ));
+      error = T42_Err_Invalid_Argument;
+      goto Exit;
+    }
+
+    /* Now, load the font program into the face object */
+
+    /* Init the face object fields */
+    /* Now set up root face fields */
+
+    root->num_glyphs   = face->type42.num_glyphs;
+    root->num_charmaps = 1;
+    root->face_index  = face_index;
+
+    root->face_flags  = FT_FACE_FLAG_SCALABLE;
+    root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
+    root->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;
+
+    if ( face->type42.font_info.is_fixed_pitch )
+      root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
+
+    /* XXX: TODO -- add kerning with .afm support */
+
+    /* get style name -- be careful, some broken fonts only */
+    /* have a `/FontName' dictionary entry!                 */
+    root->family_name = face->type42.font_info.family_name;
+    if ( root->family_name )
+    {
+      char*  full   = face->type42.font_info.full_name;
+      char*  family = root->family_name;
+
+
+      if ( full )
+      {
+        while ( *family && *full == *family )
+        {
+          family++;
+          full++;
+        }
+
+        root->style_name = ( *full == ' ' ? full + 1
+                                          : (char *)"Regular" );
+      }
+      else
+        root->style_name = (char *)"Regular";
+    }
+    else
+    {
+      /* do we have a `/FontName'? */
+      if ( face->type42.font_name )
+      {
+        root->family_name = face->type42.font_name;
+        root->style_name  = (char *)"Regular";
+      }
+    }
+
+    /* no embedded bitmap support */
+    root->num_fixed_sizes = 0;
+    root->available_sizes = 0;
+
+    /* Load the TTF font embedded in the T42 font */
+    error = FT_New_Memory_Face( FT_FACE_LIBRARY( face ),
+                                face->ttf_data,
+                                face->ttf_size,
+                                0,
+                                &face->ttf_face );
+    if ( error )
+      goto Exit;
+
+    /* Ignore info in FontInfo dictionary and use the info from the  */
+    /* loaded TTF font.  The PostScript interpreter also ignores it. */
+    root->bbox         = face->ttf_face->bbox;
+    root->units_per_EM = face->ttf_face->units_per_EM;
+
+    root->ascender  = face->ttf_face->ascender;
+    root->descender = face->ttf_face->descender;
+    root->height    = face->ttf_face->height;
+
+    root->max_advance_width = face->ttf_face->max_advance_width;
+    root->max_advance_height = face->ttf_face->max_advance_height;
+
+    root->underline_position  = face->type42.font_info.underline_position;
+    root->underline_thickness = face->type42.font_info.underline_thickness;
+
+    root->internal->max_points   = 0;
+    root->internal->max_contours = 0;
+
+    /* compute style flags */
+    root->style_flags = 0;
+    if ( face->type42.font_info.italic_angle )
+      root->style_flags |= FT_STYLE_FLAG_ITALIC;
+
+    if ( face->ttf_face->style_flags & FT_STYLE_FLAG_BOLD )
+      root->style_flags |= FT_STYLE_FLAG_BOLD;
+
+    if ( face->ttf_face->face_flags & FT_FACE_FLAG_VERTICAL )
+      root->face_flags |= FT_FACE_FLAG_VERTICAL;
+
+    /* XXX: Add support for new cmaps code in FT 2.1.0 */
+
+    /* charmap support -- synthetize unicode charmap if possible */
+
+    /* synthesize a Unicode charmap if there is support in the `PSNames' */
+    /* module                                                            */
+    if ( psnames && psnames->unicode_value )
+    {
+      error = psnames->build_unicodes( root->memory,
+                                       face->type42.num_glyphs,
+                                       (const char**)face->type42.glyph_names,
+                                       &face->unicode_map );
+      if ( !error )
+      {
+        root->charmap        = charmap;
+        charmap->face        = (FT_Face)face;
+        charmap->encoding    = ft_encoding_unicode;
+        charmap->platform_id = 3;
+        charmap->encoding_id = 1;
+        charmap++;
+      }
+
+      /* XXX: Is the following code correct?  It is used in t1objs.c */
+
+      /* simply clear the error in case of failure (which really) */
+      /* means that out of memory or no unicode glyph names       */
+      error = T42_Err_Ok;
+    }
+
+    /* now, support either the standard, expert, or custom encoding */
+    charmap->face        = (FT_Face)face;
+    charmap->platform_id = 7;  /* a new platform id for Adobe fonts? */
+
+    switch ( face->type42.encoding_type )
+    {
+    case T42_ENCODING_TYPE_STANDARD:
+      charmap->encoding    = ft_encoding_adobe_standard;
+      charmap->encoding_id = 0;
+      break;
+
+    case T42_ENCODING_TYPE_EXPERT:
+      charmap->encoding    = ft_encoding_adobe_expert;
+      charmap->encoding_id = 1;
+      break;
+
+    case T42_ENCODING_TYPE_ARRAY:
+      charmap->encoding    = ft_encoding_adobe_custom;
+      charmap->encoding_id = 2;
+      break;
+
+    case T42_ENCODING_TYPE_ISOLATIN1:
+      charmap->encoding    = ft_encoding_latin_1;
+      charmap->encoding_id = 3;
+      break;
+
+    default:
+      FT_ERROR(( "T42_Face_Init: invalid encoding\n" ));
+      error = T42_Err_Invalid_File_Format;
+      goto Exit;
+    }
+
+    root->charmaps     = face->charmaps;
+    root->num_charmaps = charmap - face->charmaprecs + 1;
+    face->charmaps[0]  = &face->charmaprecs[0];
+    face->charmaps[1]  = &face->charmaprecs[1];
+
+  Exit:
+    return error;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*   T42_Face_Done                                                       */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    The face object destructor.                                        */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    face :: A typeless pointer to the face object to destroy.          */
+  /*                                                                       */
+  static void
+  T42_Face_Done( T42_Face  face )
+  {
+    T42_Font     type42;
+    PS_FontInfo  info;
+    FT_Memory    memory;
+
+
+    if ( face )
+    {
+      type42 = &face->type42;
+      info   = &type42->font_info;
+      memory = face->root.memory;
+
+      /* delete internal ttf face prior to freeing face->ttf_data */
+      if ( face->ttf_face )
+        FT_Done_Face( face->ttf_face );
+
+      /* release font info strings */
+      FT_FREE( info->version );
+      FT_FREE( info->notice );
+      FT_FREE( info->full_name );
+      FT_FREE( info->family_name );
+      FT_FREE( info->weight );
+
+      /* release top dictionary */
+      FT_FREE( type42->charstrings_len );
+      FT_FREE( type42->charstrings );
+      FT_FREE( type42->glyph_names );
+
+      FT_FREE( type42->charstrings_block );
+      FT_FREE( type42->glyph_names_block );
+
+      FT_FREE( type42->encoding.char_index );
+      FT_FREE( type42->encoding.char_name );
+      FT_FREE( type42->font_name );
+
+      FT_FREE( face->ttf_data );
+
+#if 0
+      /* release afm data if present */
+      if ( face->afm_data )
+        T1_Done_AFM( memory, (T1_AFM*)face->afm_data );
+#endif
+
+      /* release unicode map, if any */
+      FT_FREE( face->unicode_map.maps );
+      face->unicode_map.num_maps = 0;
+
+      face->root.family_name = 0;
+      face->root.style_name  = 0;
+    }
+  }
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    T42_Driver_Init                                                    */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Initializes a given Type 42 driver object.                         */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    driver :: A handle to the target driver object.                    */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0 means success.                             */
+  /*                                                                       */
+  static FT_Error
+  T42_Driver_Init( T42_Driver  driver )
+  {
+    FT_Module  ttmodule;
+
+
+    ttmodule = FT_Get_Module( driver->root.root.library, "truetype" );
+    driver->ttclazz = (FT_Driver_Class)ttmodule->clazz;
+
+    /* XXX: What about hinter support? */
+#if 0
+    if (ttmodule->clazz->module_flags & ft_module_driver_has_hinter)
+      driver->root.clazz->root.module_flags |= ft_module_driver_has_hinter;
+#endif
+
+    return T42_Err_Ok;
+  }
+
+
+  static void
+  T42_Driver_Done( T42_Driver  driver )
+  {
+    FT_UNUSED( driver );
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    Get_Char_Index                                                     */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Uses a charmap to return a given character code's glyph index.     */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    charmap  :: A handle to the source charmap object.                 */
+  /*                                                                       */
+  /*    charcode :: The character code.                                    */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    Glyph index.  0 means `undefined character code'.                  */
+  /*                                                                       */
+  static FT_UInt
+  Get_Char_Index( FT_CharMap  charmap,
+                  FT_Long     charcode )
+  {
+    T42_Face         face;
+    FT_UInt          result = 0;
+    PSNames_Service  psnames;
+
+
+    face    = (T42_Face)charmap->face;
+    psnames = (PSNames_Service)face->psnames;
+    if (!psnames )
+      goto Exit;
+
+    switch ( charmap->encoding )
+    {
+      /*******************************************************************/
+      /*                                                                 */
+      /* Unicode encoding support                                        */
+      /*                                                                 */
+    case ft_encoding_unicode:
+      /* if this charmap is used, we ignore the encoding of the font and */
+      /* use the `PSNames' module to synthetize the Unicode charmap      */
+      result = psnames->lookup_unicode( &face->unicode_map,
+                                        (FT_ULong)charcode );
+
+      /* the function returns 0xFFFF if the Unicode charcode has */
+      /* no corresponding glyph                                  */
+      if ( result == 0xFFFFU )
+        result = 0;
+
+      /* The result returned is the index (position)in the CharStrings */
+      /* array.  This must be used now to get the value associated to  */
+      /* that glyph_name, which is the real index within the truetype  */
+      /* structure.                                                    */
+      result = ft_atoi( (const char*)face->type42.charstrings[result] );
+      goto Exit;
+
+      /*******************************************************************/
+      /*                                                                 */
+      /* ISOLatin1 encoding support                                      */
+      /*                                                                 */
+    case ft_encoding_latin_1:
+      /* ISOLatin1 is the first page of Unicode */
+      if ( charcode < 256 && psnames->unicode_value )
+      {
+        result = psnames->lookup_unicode( &face->unicode_map,
+                                          (FT_ULong)charcode );
+
+        /* the function returns 0xFFFF if the Unicode charcode has */
+        /* no corresponding glyph                                  */
+        if ( result == 0xFFFFU )
+          result = 0;
+      }
+      goto Exit;
+
+      /*******************************************************************/
+      /*                                                                 */
+      /* Custom Type 1 encoding                                          */
+      /*                                                                 */
+    case ft_encoding_adobe_custom:
+      {
+        T1_Encoding  encoding = &face->type42.encoding;
+
+
+        if ( charcode >= encoding->code_first &&
+             charcode <= encoding->code_last  )
+        {
+          FT_UInt idx = encoding->char_index[charcode];
+
+
+          result = ft_atoi( (const char *)face->type42.charstrings[idx] );
+        }
+        goto Exit;
+      }
+
+      /*******************************************************************/
+      /*                                                                 */
+      /* Adobe Standard & Expert encoding support                        */
+      /*                                                                 */
+    default:
+      if ( charcode < 256 )
+      {
+        FT_UInt      code;
+        FT_Int       n;
+        const char*  glyph_name;
+
+
+        code = psnames->adobe_std_encoding[charcode];
+        if ( charmap->encoding == ft_encoding_adobe_expert )
+          code = psnames->adobe_expert_encoding[charcode];
+
+        glyph_name = psnames->adobe_std_strings( code );
+        if ( !glyph_name )
+          break;
+
+        for ( n = 0; n < face->type42.num_glyphs; n++ )
+        {
+          const char*  gname = face->type42.glyph_names[n];
+
+          if ( gname && ( ft_strcmp( gname, glyph_name ) == 0 ) )
+          {
+            result = ft_atoi( (const char *)face->type42.charstrings[n] );
+            break;
+          }
+        }
+      }
+    }
+
+  Exit:
+    return result;
+  }
+
+
+  static FT_Error
+  T42_Size_Init( T42_Size  size )
+  {
+    FT_Face   face = size->root.face;
+    T42_Face  t42face = (T42_Face)face;
+    FT_Size   ttsize;
+    FT_Error  error   = T42_Err_Ok;
+
+
+    if ( face->size == NULL )
+    {
+      /* First size for this face */
+      size->ttsize = t42face->ttf_face->size;
+    }
+    else
+    {
+      error = FT_New_Size( t42face->ttf_face, &ttsize );
+      size->ttsize = ttsize;
+    }
+
+    return error;
+  }
+
+
+  static void
+  T42_Size_Done( T42_Size  size )
+  {
+    FT_Face      face    = size->root.face;
+    T42_Face     t42face = (T42_Face)face;
+    FT_ListNode  node;
+
+
+    node = FT_List_Find( &t42face->ttf_face->sizes_list, size->ttsize );
+    if ( node )
+      FT_Done_Size( size->ttsize );
+  }
+
+
+  static FT_Error
+  T42_GlyphSlot_Init( T42_GlyphSlot  slot )
+  {
+    FT_Face       face    = slot->root.face;
+    T42_Face      t42face = (T42_Face)face;
+    FT_GlyphSlot  ttslot;
+    FT_Error      error   = T42_Err_Ok;
+
+
+    if ( face->glyph == NULL )
+    {
+      /* First glyph slot for this face */
+      slot->ttslot = t42face->ttf_face->glyph;
+    }
+    else
+    {
+      error = FT_New_GlyphSlot( t42face->ttf_face, &ttslot );
+      slot->ttslot = ttslot;
+    }
+
+    return error;
+  }
+
+
+  static void
+  T42_GlyphSlot_Done( T42_GlyphSlot slot )
+  {
+    FT_Face       face    = slot->root.face;
+    T42_Face      t42face = (T42_Face)face;
+    FT_GlyphSlot  cur     = t42face->ttf_face->glyph;
+
+
+    while ( cur )
+    {
+      if ( cur == slot->ttslot )
+      {
+        FT_Done_GlyphSlot( slot->ttslot );
+        break;
+      }
+
+      cur = cur->next;
+    }
+  }
+
+
+  static FT_Error
+  T42_Char_Size( T42_Size    size,
+                 FT_F26Dot6  char_width,
+                 FT_F26Dot6  char_height,
+                 FT_UInt     horz_resolution,
+                 FT_UInt     vert_resolution )
+  {
+    FT_Face   face    = size->root.face;
+    T42_Face  t42face = (T42_Face)face;
+
+
+    return FT_Set_Char_Size( t42face->ttf_face,
+                             char_width,
+                             char_height,
+                             horz_resolution,
+                             vert_resolution );
+  }
+
+
+  static FT_Error
+  T42_Pixel_Size( T42_Size  size,
+                  FT_UInt   pixel_width,
+                  FT_UInt   pixel_height )
+  {
+    FT_Face   face    = size->root.face;
+    T42_Face  t42face = (T42_Face)face;
+
+
+    return FT_Set_Pixel_Sizes( t42face->ttf_face,
+                               pixel_width,
+                               pixel_height );
+  }
+
+
+  static void
+  ft_glyphslot_clear( FT_GlyphSlot  slot )
+  {
+    /* free bitmap if needed */
+    if ( slot->flags & FT_GLYPH_OWN_BITMAP )
+    {
+      FT_Memory  memory = FT_FACE_MEMORY( slot->face );
+
+
+      FT_FREE( slot->bitmap.buffer );
+      slot->flags &= ~FT_GLYPH_OWN_BITMAP;
+    }
+
+    /* clear all public fields in the glyph slot */
+    FT_MEM_SET( &slot->metrics, 0, sizeof ( slot->metrics ) );
+    FT_MEM_SET( &slot->outline, 0, sizeof ( slot->outline ) );
+    FT_MEM_SET( &slot->bitmap,  0, sizeof ( slot->bitmap )  );
+
+    slot->bitmap_left   = 0;
+    slot->bitmap_top    = 0;
+    slot->num_subglyphs = 0;
+    slot->subglyphs     = 0;
+    slot->control_data  = 0;
+    slot->control_len   = 0;
+    slot->other         = 0;
+    slot->format        = ft_glyph_format_none;
+
+    slot->linearHoriAdvance = 0;
+    slot->linearVertAdvance = 0;
+  }
+
+
+  static FT_Error
+  T42_Load_Glyph( FT_GlyphSlot  glyph,
+                  FT_Size       size,
+                  FT_Int        glyph_index,
+                  FT_Int        load_flags )
+  {
+    FT_Error         error;
+    T42_GlyphSlot    t42slot = (T42_GlyphSlot)glyph;
+    T42_Size         t42size = (T42_Size)size;
+    FT_Driver_Class  ttclazz = ((T42_Driver)glyph->face->driver)->ttclazz;
+
+
+    ft_glyphslot_clear( t42slot->ttslot );
+    error = ttclazz->load_glyph( t42slot->ttslot,
+                                 t42size->ttsize,
+                                 glyph_index,
+                                 load_flags | FT_LOAD_NO_BITMAP );
+
+    if ( !error )
+    {
+      glyph->metrics = t42slot->ttslot->metrics;
+
+      glyph->linearHoriAdvance = t42slot->ttslot->linearHoriAdvance;
+      glyph->linearVertAdvance = t42slot->ttslot->linearVertAdvance;
+
+      glyph->format  = t42slot->ttslot->format;
+      glyph->outline = t42slot->ttslot->outline;
+
+      glyph->bitmap      = t42slot->ttslot->bitmap;
+      glyph->bitmap_left = t42slot->ttslot->bitmap_left;
+      glyph->bitmap_top  = t42slot->ttslot->bitmap_top;
+    }
+
+    return error;
+  }
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    Get_Next_Char                                                      */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Uses a charmap to return the next encoded char.                    */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    charmap  :: A handle to the source charmap object.                 */
+  /*                                                                       */
+  /*    charcode :: The character code.                                    */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    Next char code.  0 means `no more char codes'.                     */
+  /*                                                                       */
+  static FT_Long
+  Get_Next_Char( FT_CharMap  charmap,
+                 FT_Long     charcode )
+  {
+    T42_Face         face;
+    PSNames_Service  psnames;
+
+
+    face    = (T42_Face)charmap->face;
+    psnames = (PSNames_Service)face->psnames;
+
+    if ( psnames )
+      switch ( charmap->encoding )
+      {
+        /*******************************************************************/
+        /*                                                                 */
+        /* Unicode encoding support                                        */
+        /*                                                                 */
+      case ft_encoding_unicode:
+        /* use the `PSNames' module to synthetize the Unicode charmap */
+        return psnames->next_unicode( &face->unicode_map,
+                                      (FT_ULong)charcode );
+
+        /*******************************************************************/
+        /*                                                                 */
+        /* ISOLatin1 encoding support                                      */
+        /*                                                                 */
+      case ft_encoding_latin_1:
+        {
+          FT_ULong code;
+
+
+          /* use the `PSNames' module to synthetize the Unicode charmap */
+          code = psnames->next_unicode( &face->unicode_map,
+                                        (FT_ULong)charcode );
+          if ( code < 256 )
+            return code;
+          break;
+        }
+
+        /*******************************************************************/
+        /*                                                                 */
+        /* Custom Type 1 encoding                                          */
+        /*                                                                 */
+      case ft_encoding_adobe_custom:
+        {
+          T1_Encoding  encoding = &face->type42.encoding;
+
+
+          charcode++;
+          if ( charcode < encoding->code_first )
+            charcode = encoding->code_first;
+          while ( charcode <= encoding->code_last  ) {
+            if ( encoding->char_index[charcode] )
+              return charcode;
+            charcode++;
+          }
+        }
+
+
+        /*******************************************************************/
+        /*                                                                 */
+        /* Adobe Standard & Expert encoding support                        */
+        /*                                                                 */
+      default:
+        while ( ++charcode < 256 )
+        {
+          FT_UInt      code;
+          FT_Int       n;
+          const char*  glyph_name;
+
+
+          code = psnames->adobe_std_encoding[charcode];
+          if ( charmap->encoding == ft_encoding_adobe_expert )
+            code = psnames->adobe_expert_encoding[charcode];
+
+          glyph_name = psnames->adobe_std_strings( code );
+          if ( !glyph_name )
+            continue;
+
+          for ( n = 0; n < face->type42.num_glyphs; n++ )
+          {
+            const char*  gname = face->type42.glyph_names[n];
+
+
+            if ( gname && gname[0] == glyph_name[0]  &&
+                 ft_strcmp( gname, glyph_name ) == 0 )
+              return charcode;
+          }
+        }
+      }
+
+    return 0;
+  }
+
+
+  static FT_Error
+  t42_get_glyph_name( T42_Face    face,
+                      FT_UInt     glyph_index,
+                      FT_Pointer  buffer,
+                      FT_UInt     buffer_max )
+  {
+    FT_String*  gname;
+
+
+    gname = face->type42.glyph_names[glyph_index];
+
+    if ( buffer_max > 0 )
+    {
+      FT_UInt  len = (FT_UInt)( ft_strlen( gname ) );
+
+  
+      if ( len >= buffer_max )
+        len = buffer_max - 1;
+      FT_MEM_COPY( buffer, gname, len );
+      ((FT_Byte*)buffer)[len] = 0;
+    }
+
+    return T42_Err_Ok;
+  }
+
+
+  static const char*
+  t42_get_ps_name( T42_Face  face )
+  {
+    return (const char*)face->type42.font_name;
+  }
+
+
+  static FT_UInt
+  t42_get_name_index( T42_Face    face,
+                      FT_String*  glyph_name )
+  {
+    FT_Int      i;
+    FT_String*  gname;
+
+
+    for ( i = 0; i < face->type42.num_glyphs; i++ )
+    {
+      gname = face->type42.glyph_names[i];
+
+      if ( !ft_strcmp( glyph_name, gname ) )
+        return ft_atoi( (const char *)face->type42.charstrings[i] );
+    }
+
+    return 0;
+  }
+
+
+  static FT_Module_Interface
+  Get_Interface( FT_Driver         driver,
+                 const FT_String*  t42_interface )
+  {
+    FT_UNUSED( driver );
+
+    /* Any additional interface are defined here */
+    if (ft_strcmp( (const char*)t42_interface, "glyph_name" ) == 0 )
+      return (FT_Module_Interface)t42_get_glyph_name;
+
+    if ( ft_strcmp( (const char*)t42_interface, "name_index" ) == 0 )
+      return (FT_Module_Interface)t42_get_name_index;
+
+    if ( ft_strcmp( (const char*)t42_interface, "postscript_name" ) == 0 )
+      return (FT_Module_Interface)t42_get_ps_name;
+
+    return 0;
+  }
+
+
+  const FT_Driver_ClassRec  t42_driver_class =
+  {
+    {
+      ft_module_font_driver      |
+      ft_module_driver_scalable  |
+      ft_module_driver_has_hinter,
+
+      sizeof ( T42_DriverRec ),
+
+      "type42",
+      0x10000L,
+      0x20000L,
+
+      0,    /* format interface */
+
+      (FT_Module_Constructor)T42_Driver_Init,
+      (FT_Module_Destructor) T42_Driver_Done,
+      (FT_Module_Requester)  Get_Interface,
+    },
+
+    sizeof ( T42_FaceRec ),
+    sizeof ( T42_SizeRec ),
+    sizeof ( T42_GlyphSlotRec ),
+
+    (FT_Face_InitFunc)        T42_Face_Init,
+    (FT_Face_DoneFunc)        T42_Face_Done,
+    (FT_Size_InitFunc)        T42_Size_Init,
+    (FT_Size_DoneFunc)        T42_Size_Done,
+    (FT_Slot_InitFunc)        T42_GlyphSlot_Init,
+    (FT_Slot_DoneFunc)        T42_GlyphSlot_Done,
+
+    (FT_Size_ResetPointsFunc) T42_Char_Size,
+    (FT_Size_ResetPixelsFunc) T42_Pixel_Size,
+    (FT_Slot_LoadFunc)        T42_Load_Glyph,
+    (FT_CharMap_CharIndexFunc)Get_Char_Index,
+
+    (FT_Face_GetKerningFunc)  0,
+    (FT_Face_AttachFunc)      0,
+
+    (FT_Face_GetAdvancesFunc) 0,
+
+    (FT_CharMap_CharNextFunc) Get_Next_Char
+  };
+
+
+#ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    getDriverClass                                                     */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    This function is used when compiling the TrueType driver as a      */
+  /*    shared library (`.DLL' or `.so').  It will be used by the          */
+  /*    high-level library of FreeType to retrieve the address of the      */
+  /*    driver's generic interface.                                        */
+  /*                                                                       */
+  /*    It shouldn't be implemented in a static build, as each driver must */
+  /*    have the same function as an exported entry point.                 */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    The address of the T42's driver generic interface.  The            */
+  /*    format-specific interface can then be retrieved through the method */
+  /*    interface->get_format_interface.                                   */
+  /*                                                                       */
+  FT_EXPORT_DEF( const FT_Driver_Class )
+  getDriverClass( void )
+  {
+    return &t42_driver_class;
+  }
+
+
+#endif /* FT_CONFIG_OPTION_DYNAMIC_DRIVERS */
+
+
+/* END */