summaryrefslogtreecommitdiff
path: root/src/Type1/scanfont.c
blob: 04e3fe2f30f9d9574036b432cc4f3b6dfc889550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
/* $XdotOrg: xc/lib/font/Type1/scanfont.c,v 1.5 2005/07/09 23:18:27 keithp Exp $ */
/* $Xorg: scanfont.c,v 1.3 2000/08/17 19:46:32 cpqbld Exp $ */
/* Copyright International Business Machines,Corp. 1991
 * All Rights Reserved
 *
 * License to use, copy, modify, and distribute this software
 * and its documentation for any purpose and without fee is
 * hereby granted, provided that the above copyright notice
 * appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation,
 * and that the name of IBM not be used in advertising or
 * publicity pertaining to distribution of the software without
 * specific, written prior permission.
 *
 * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
 * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
 * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
 * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
 * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
 * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
 * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
 * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */
/* Author: Katherine A. Hitchcock    IBM Almaden Research Laboratory */
/* Copyright (c) 1994-1999 Silicon Graphics, Inc. All Rights Reserved.
 *
 * The contents of this file are subject to the CID Font Code Public Licence
 * Version 1.0 (the "License"). You may not use this file except in compliance
 * with the Licence. You may obtain a copy of the License at Silicon Graphics,
 * Inc., attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA
 * 94043 or at http://www.sgi.com/software/opensource/cid/license.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis.
 * ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED
 * WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR PURPOSE OR OF
 * NON-INFRINGEMENT. See the License for the specific language governing
 * rights and limitations under the License.
 *
 * The Original Software is CID font code that was developed by Silicon
 * Graphics, Inc.
 */
/* $XFree86: xc/lib/font/Type1/scanfont.c,v 1.16 2003/05/27 22:26:46 tsi Exp $ */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef BUILDCID
#define XFONT_CID 1
#endif

#ifndef FONTMODULE
#include <string.h>
#else
#include "Xdefs.h"	/* Bool declaration */
#include "Xmd.h"	/* INT32 declaration */
#include "xf86_ansic.h"
#endif
#include "t1stdio.h"
#include "util.h"
#include "token.h"
#if XFONT_CID
#include "range.h"
#endif
#include "objects.h"
#include "spaces.h"
#include "fontfcn.h"
#include "blues.h"
 
#if XFONT_CID
#define CID_BUFSIZE 80

extern psfont *FDArrayP;
static spacerange *spacerangeP;
static cidrange *notdefrangeP;
static cidrange *cidrangeP;
extern int FDArrayIndex;
static boolean CIDWantFontInfo;
static psobj inputFile1;
#endif
 
static int rc;
static boolean InPrivateDict;
static boolean WantFontInfo;
static boolean TwoSubrs;
static psobj inputFile;
static psobj filterFile;
static psobj *inputP;
 
 
/**********************************************************************/
/*   Init_BuiltInEncoding()                                           */
/*                                                                    */
/*     Initializes the StandardEncoding and ISOLatin1Encoding vector. */
/*                                                                    */
/**********************************************************************/
typedef struct				/* Builtin Standard Encoding */
{
   int  index;
   char *name;
} EncodingTable;

static EncodingTable StdEnc[] = {
  {  040 , "space" },
  {  041 , "exclam" },
  {  042 , "quotedbl" },
  {  043 , "numbersign" },
  {  044 , "dollar" },
  {  045 , "percent" },
  {  046 , "ampersand" },
  {  047 , "quoteright" },
  {  050 , "parenleft" },
  {  051 , "parenright" },
  {  052 , "asterisk" },
  {  053 , "plus" },
  {  054 , "comma" },
  {  055 , "hyphen" },
  {  056 , "period" },
  {  057 , "slash" },
  {  060 , "zero" },
  {  061 , "one" },
  {  062 , "two" },
  {  063 , "three" },
  {  064 , "four" },
  {  065 , "five" },
  {  066 , "six" },
  {  067 , "seven" },
  {  070 , "eight" },
  {  071 , "nine" },
  {  072 , "colon" },
  {  073 , "semicolon" },
  {  074 , "less" },
  {  075 , "equal" },
  {  076 , "greater" },
  {  077 , "question" },
  { 0100 , "at" },
  { 0101 , "A" },
  { 0102 , "B" },
  { 0103 , "C" },
  { 0104 , "D" },
  { 0105 , "E" },
  { 0106 , "F" },
  { 0107 , "G" },
  { 0110 , "H" },
  { 0111 , "I" },
  { 0112 , "J" },
  { 0113 , "K" },
  { 0114 , "L" },
  { 0115 , "M" },
  { 0116 , "N" },
  { 0117 , "O" },
  { 0120 , "P" },
  { 0121 , "Q" },
  { 0122 , "R" },
  { 0123 , "S" },
  { 0124 , "T" },
  { 0125 , "U" },
  { 0126 , "V" },
  { 0127 , "W" },
  { 0130 , "X" },
  { 0131 , "Y" },
  { 0132 , "Z" },
  { 0133 , "bracketleft" },
  { 0134 , "backslash" },
  { 0135 , "bracketright" },
  { 0136 , "asciicircum" },
  { 0137 , "underscore" },
  { 0140 , "quoteleft" },
  { 0141 , "a" },
  { 0142 , "b" },
  { 0143 , "c" },
  { 0144 , "d" },
  { 0145 , "e" },
  { 0146 , "f" },
  { 0147 , "g" },
  { 0150 , "h" },
  { 0151 , "i" },
  { 0152 , "j" },
  { 0153 , "k" },
  { 0154 , "l" },
  { 0155 , "m" },
  { 0156 , "n" },
  { 0157 , "o" },
  { 0160 , "p" },
  { 0161 , "q" },
  { 0162 , "r" },
  { 0163 , "s" },
  { 0164 , "t" },
  { 0165 , "u" },
  { 0166 , "v" },
  { 0167 , "w" },
  { 0170 , "x" },
  { 0171 , "y" },
  { 0172 , "z" },
  { 0173 , "braceleft" },
  { 0174 , "bar" },
  { 0175 , "braceright" },
  { 0176 , "asciitilde" },
  { 0241 , "exclamdown" },
  { 0242 , "cent" },
  { 0243 , "sterling" },
  { 0244 , "fraction" },
  { 0245 , "yen" },
  { 0246 , "florin" },
  { 0247 , "section" },
  { 0250 , "currency" },
  { 0251 , "quotesingle" },
  { 0252 , "quotedblleft" },
  { 0253 , "guillemotleft" },
  { 0254 , "guilsinglleft" },
  { 0255 , "guilsinglright" },
  { 0256 , "fi" },
  { 0257 , "fl" },
  { 0261 , "endash" },
  { 0262 , "dagger" },
  { 0263 , "daggerdbl" },
  { 0264 , "periodcentered" },
  { 0266 , "paragraph" },
  { 0267 , "bullet" },
  { 0270 , "quotesinglbase" },
  { 0271 , "quotedblbase" },
  { 0272 , "quotedblright" },
  { 0273 , "guillemotright" },
  { 0274 , "ellipsis" },
  { 0275 , "perthousand" },
  { 0277 , "questiondown" },
  { 0301 , "grave" },
  { 0302 , "acute" },
  { 0303 , "circumflex" },
  { 0304 , "tilde" },
  { 0305 , "macron" },
  { 0306 , "breve" },
  { 0307 , "dotaccent" },
  { 0310 , "dieresis" },
  { 0312 , "ring" },
  { 0313 , "cedilla" },
  { 0315 , "hungarumlaut" },
  { 0316 , "ogonek" },
  { 0317 , "caron" },
  { 0320 , "emdash" },
  { 0341 , "AE" },
  { 0343 , "ordfeminine" },
  { 0350 , "Lslash" },
  { 0351 , "Oslash" },
  { 0352 , "OE" },
  { 0353 , "ordmasculine" },
  { 0361 , "ae" },
  { 0365 , "dotlessi" },
  { 0370 , "lslash" },
  { 0371 , "oslash" },
  { 0372 , "oe" },
  { 0373 , "germandbls" },
  {    0,      0 }
};

static EncodingTable ISO8859Enc[] = {
 {  32, "space" },
 {  33, "exclam" },
 {  34, "quotedbl" },
 {  35, "numbersign" },
 {  36, "dollar" },
 {  37, "percent" },
 {  38, "ampersand" },
 {  39, "quoteright" },
 {  40, "parenleft" },
 {  41, "parenright" },
 {  42, "asterisk" },
 {  43, "plus" },
 {  44, "comma" },
 {  45, "minus" },
 {  46, "period" },
 {  47, "slash" },
 {  48, "zero" },
 {  49, "one" },
 {  50, "two" },
 {  51, "three" },
 {  52, "four" },
 {  53, "five" },
 {  54, "six" },
 {  55, "seven" },
 {  56, "eight" },
 {  57, "nine" },
 {  58, "colon" },
 {  59, "semicolon" },
 {  60, "less" },
 {  61, "equal" },
 {  62, "greater" },
 {  63, "question" },
 {  64, "at" },
 {  65, "A" },
 {  66, "B" },
 {  67, "C" },
 {  68, "D" },
 {  69, "E" },
 {  70, "F" },
 {  71, "G" },
 {  72, "H" },
 {  73, "I" },
 {  74, "J" },
 {  75, "K" },
 {  76, "L" },
 {  77, "M" },
 {  78, "N" },
 {  79, "O" },
 {  80, "P" },
 {  81, "Q" },
 {  82, "R" },
 {  83, "S" },
 {  84, "T" },
 {  85, "U" },
 {  86, "V" },
 {  87, "W" },
 {  88, "X" },
 {  89, "Y" },
 {  90, "Z" },
 {  91, "bracketleft" },
 {  92, "backslash" },
 {  93, "bracketright" },
 {  94, "asciicircum" },
 {  95, "underscore" },
 {  96, "quoteleft" },
 {  97, "a" },
 {  98, "b" },
 {  99, "c" },
 { 100, "d" },
 { 101, "e" },
 { 102, "f" },
 { 103, "g" },
 { 104, "h" },
 { 105, "i" },
 { 106, "j" },
 { 107, "k" },
 { 108, "l" },
 { 109, "m" },
 { 110, "n" },
 { 111, "o" },
 { 112, "p" },
 { 113, "q" },
 { 114, "r" },
 { 115, "s" },
 { 116, "t" },
 { 117, "u" },
 { 118, "v" },
 { 119, "w" },
 { 120, "x" },
 { 121, "y" },
 { 122, "z" },
 { 123, "braceleft" },
 { 124, "bar" },
 { 125, "braceright" },
 { 126, "asciitilde" },
 { 160, "space" },
 { 161, "exclamdown" },
 { 162, "cent" },
 { 163, "sterling" },
 { 164, "currency" },
 { 165, "yen" },
 { 166, "brokenbar" },
 { 167, "section" },
 { 168, "dieresis" },
 { 169, "copyright" },
 { 170, "ordfeminine" },
 { 171, "guillemotleft" },
 { 172, "logicalnot" },
 { 173, "hyphen" },
 { 174, "registered" },
 { 175, "macron" },
 { 176, "degree" },
 { 177, "plusminus" },
 { 178, "twosuperior" },
 { 179, "threesuperior" },
 { 180, "acute" },
 { 181, "mu" },
 { 182, "paragraph" },
 { 183, "periodcentered" },
 { 184, "cedilla" },
 { 185, "onesuperior" },
 { 186, "ordmasculine" },
 { 187, "guillemotright" },
 { 188, "onequarter" },
 { 189, "onehalf" },
 { 190, "threequarters" },
 { 191, "questiondown" },
 { 192, "Agrave" },
 { 193, "Aacute" },
 { 194, "Acircumflex" },
 { 195, "Atilde" },
 { 196, "Adieresis" },
 { 197, "Aring" },
 { 198, "AE" },
 { 199, "Ccedilla" },
 { 200, "Egrave" },
 { 201, "Eacute" },
 { 202, "Ecircumflex" },
 { 203, "Edieresis" },
 { 204, "Igrave" },
 { 205, "Iacute" },
 { 206, "Icircumflex" },
 { 207, "Idieresis" },
 { 208, "Eth" },
 { 209, "Ntilde" },
 { 210, "Ograve" },
 { 211, "Oacute" },
 { 212, "Ocircumflex" },
 { 213, "Otilde" },
 { 214, "Odieresis" },
 { 215, "multiply" },
 { 216, "Oslash" },
 { 217, "Ugrave" },
 { 218, "Uacute" },
 { 219, "Ucircumflex" },
 { 220, "Udieresis" },
 { 221, "Yacute" },
 { 222, "Thorn" },
 { 223, "germandbls" },
 { 224, "agrave" },
 { 225, "aacute" },
 { 226, "acircumflex" },
 { 227, "atilde" },
 { 228, "adieresis" },
 { 229, "aring" },
 { 230, "ae" },
 { 231, "ccedilla" },
 { 232, "egrave" },
 { 233, "eacute" },
 { 234, "ecircumflex" },
 { 235, "edieresis" },
 { 236, "igrave" },
 { 237, "iacute" },
 { 238, "icircumflex" },
 { 239, "idieresis" },
 { 240, "eth" },
 { 241, "ntilde" },
 { 242, "ograve" },
 { 243, "oacute" },
 { 244, "ocircumflex" },
 { 245, "otilde" },
 { 246, "odieresis" },
 { 247, "divide" },
 { 248, "oslash" },
 { 249, "ugrave" },
 { 250, "uacute" },
 { 251, "ucircumflex" },
 { 252, "udieresis" },
 { 253, "yacute" },
 { 254, "thorn" },
 { 255, "ydieresis" },
 {   0,      0 }
};

static psobj *StdEncArrayP = NULL;
psobj *ISOLatin1EncArrayP = NULL; 
 
static psobj *
MakeEncodingArrayP(EncodingTable *encodingTable)
{
  int i;
  psobj *encodingArrayP;
 
  encodingArrayP = (psobj *)vm_alloc(256*(sizeof(psobj)));
  if (!encodingArrayP)
      return NULL;

  /* initialize everything to .notdef */
  for (i=0; i<256;i++)
      objFormatName(&(encodingArrayP[i]),7, ".notdef");

  for (i=0; encodingTable[i].name; i++)
  {
      objFormatName(&(encodingArrayP[encodingTable[i].index]),
		    strlen(encodingTable[i].name),
		    encodingTable[i].name);
  }

  return(encodingArrayP);
}
 
boolean 
Init_BuiltInEncoding(void)
{
    StdEncArrayP = MakeEncodingArrayP(StdEnc);
    ISOLatin1EncArrayP = MakeEncodingArrayP(ISO8859Enc);
    return (StdEncArrayP && ISOLatin1EncArrayP);
}
 
/********************************************************************/
/***================================================================***/
static int 
getNextValue(int valueType)
{
  scan_token(inputP);
  if (tokenType != valueType) {
    return(SCAN_ERROR);
  }
  return(SCAN_OK);
 
}
/***================================================================***/
/*  This routine will set the global rc if there is an error          */
/***================================================================***/
static int 
getInt(void)
{
  scan_token(inputP);
  if (tokenType != TOKEN_INTEGER) {
    rc = SCAN_ERROR;
    return(0);
  }
  else {
    return( tokenValue.integer);
  }
 
}
/***================================================================***/
/*
 * See Sec 10.3 of ``Adobe Type 1 Font Format'' v1.1,
 * for parsing Encoding.
 */
static int 
getEncoding(psobj *arrayP)
{
  scan_token(inputP);
  if ((tokenType == TOKEN_NAME && (tokenLength==16 || tokenLength==17)))
  {
    if((tokenLength==16) && (!strncmp(tokenStartP,"StandardEncoding",16)))
          arrayP->data.valueP = (char *) StdEncArrayP;
    else
          arrayP->data.valueP = (char *) ISOLatin1EncArrayP;
      arrayP->len = 256;
      return(SCAN_OK);
  }
  else if ( (tokenType == TOKEN_LEFT_BRACE) ||
       (tokenType == TOKEN_LEFT_BRACKET) )
  {
      /* Array of literal names */

      psobj *objP;
      int i;

      objP = (psobj *)vm_alloc(256*(sizeof(psobj)));
      if (!(objP)) return(SCAN_OUT_OF_MEMORY);

      arrayP->data.valueP = (char *) objP;
      arrayP->len = 256;

      for (i=0; i<256; i++, objP++)
      {
	  scan_token(inputP);
	  
	  if (tokenType != TOKEN_LITERAL_NAME)
	      return(SCAN_ERROR);

	  if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY);
	  objFormatName(objP,tokenLength,tokenStartP);
      }

      scan_token(inputP);
      if ( (tokenType == TOKEN_RIGHT_BRACE) ||
	  (tokenType == TOKEN_RIGHT_BRACKET) )
	  return(SCAN_OK);
  }
  else
  {
      /* Must be sequences of ``dup <index> <charactername> put" */

      psobj *objP;
      int i;

      objP = (psobj *)vm_alloc(256*(sizeof(psobj)));
      if (!(objP)) return(SCAN_OUT_OF_MEMORY);

      arrayP->data.valueP = (char *) objP;
      arrayP->len = 256;

      for (i=0; i<256; i++)
	  objFormatName(objP + i, 7, ".notdef");

      while (TRUE)
      {
	  scan_token(inputP);

	  switch (tokenType)
	  {
	  case TOKEN_NAME:
	      if (tokenLength == 3)
	      {
		  if (strncmp(tokenStartP,"dup",3) == 0)
		  {
		      /* get <index> */
		      scan_token(inputP);
		      if (tokenType != TOKEN_INTEGER ||
			  tokenValue.integer < 0 ||
			  tokenValue.integer > 255)
			  return (SCAN_ERROR);
		      i = tokenValue.integer;

		      /* get <characer_name> */
		      scan_token(inputP);
		      if (tokenType != TOKEN_LITERAL_NAME)
			  return(SCAN_ERROR);

		      if (!(vm_alloc(tokenLength)) )
			  return(SCAN_OUT_OF_MEMORY);
		      objFormatName(objP + i,tokenLength,tokenStartP);

		      /* get "put" */
		      scan_token(inputP);
		      if (tokenType != TOKEN_NAME)
			  return(SCAN_ERROR);
		  }
		  else if (strncmp(tokenStartP,"def",3) == 0)
		      return (SCAN_OK);
	      }
	      break;
	  case TOKEN_EOF:
	  case TOKEN_NONE:
	  case TOKEN_INVALID:
	      return (SCAN_ERROR);
	  }
      }
  }

  return (SCAN_ERROR);
}
/***================================================================***/
#if XFONT_CID
static int 
getFDArray(psobj *arrayP)
{
  int rc;

  /* get the number of items in the FDArray */
  scan_token(inputP);
  if (tokenType == TOKEN_INTEGER) {
      /* an FD array must contain at least one element */
      if (tokenValue.integer <= 0)
          return(SCAN_ERROR);
      arrayP->len = tokenValue.integer;
  } else
      return(SCAN_ERROR);

  /* get the token "array" */
  scan_token(inputP);
  if (tokenType != TOKEN_NAME || strncmp(tokenStartP, "array", 5) != 0)
      return(SCAN_ERROR);
 
  /* format the array in memory, save pointer to the beginning */
  arrayP->data.valueP = tokenStartP;

  /* allocate FDArray */
  FDArrayP = (psfont *)vm_alloc(arrayP->len*(sizeof(psfont)));
  if (!(FDArrayP)) return(SCAN_OUT_OF_MEMORY);

  /* get a specified number of font dictionaries */
  for (FDArrayIndex = 0; FDArrayIndex < arrayP->len; FDArrayIndex++) {
      /* get "dup" */
      scan_token(inputP);
      if (tokenType != TOKEN_NAME || strncmp(tokenStartP, "dup", 3) != 0)
          return(SCAN_ERROR);
      /* get an integer digit */
      scan_token(inputP);
      if (tokenType != TOKEN_INTEGER)
          return(SCAN_ERROR);

      /* read a CID version of a Type 1 font */
      if (!CIDType1fontfcnA(&rc))
          return(rc);

      /* get "put" */
      scan_token(inputP);
      if (tokenType != TOKEN_NAME || strncmp(tokenStartP, "put", 3) != 0)
          return(SCAN_ERROR);
  }
  return(SCAN_OK);
}
#endif

static int 
getArray(psobj *arrayP)
{
  int N;   /* count the items in the array */
  psobj *objP;

  /* That is totally a kludge. If some stupid font file has
   *	/foo/foo	# ftp://ftp.cdrom.com/pub/os2/fonts/future.zip
   * we will treat it as /foo.
   *  H.J. */
  char tmp [1024];

  strncpy (tmp, tokenStartP, sizeof (tmp));
  tmp [sizeof (tmp) - 1] = '\0';

restart: 
  scan_token(inputP);
  switch (tokenType)
  {
  case TOKEN_LEFT_BRACE:
  case TOKEN_LEFT_BRACKET:
    break;

  case TOKEN_LITERAL_NAME:
    tokenStartP[tokenLength] = '\0';
    if (strcmp (tokenStartP, tmp) == 0)
    {
      /* Ok, We see /foo/foo. Let's restart. */
      goto restart;
    }

  default:
    return(SCAN_ERROR);
  }
  /* format the array in memory, save pointer to the beginning */
  arrayP->data.valueP = tokenStartP;
  /* loop, picking up next object, until right BRACE or BRACKET */
  N = 0;
  do {
    scan_token(inputP);
    if ( (tokenType == TOKEN_RIGHT_BRACE) ||
         (tokenType == TOKEN_RIGHT_BRACKET) ) {
      /* save then number of items in the array */
      arrayP->len = N;
      return(SCAN_OK);
    }
     /* allocate the space for the object */
    objP = (psobj *)vm_alloc(sizeof(psobj));
    if (!(objP)) return(SCAN_OUT_OF_MEMORY);
 
    /* array is an array of numbers, (real or integer)  */
    if (tokenType == TOKEN_REAL) {
      objFormatReal(objP, tokenValue.real);
    }
    else
      if (tokenType == TOKEN_INTEGER) {
        objFormatInteger(objP, tokenValue.integer);
      }
      else return(SCAN_ERROR);
    N++;
  }  while ( 1>0 );
  /* NOTREACHED*/
}
/***================================================================***/
static int 
getName(char *nameP)
{
  do {
    scan_token(inputP);
    if (tokenType <= TOKEN_NONE) {
      if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
      return(SCAN_ERROR);
    }
  } while ((tokenType != TOKEN_NAME) ||
    (0 != strncmp(tokenStartP,nameP,strlen(nameP))) );
  /* found */
  return(SCAN_OK);
}
/***================================================================***/
static int 
getNbytes(int N)
{
  int I;
 
 
  tokenStartP = vm_next_byte();
  tokenMaxP = tokenStartP + MIN(vm_free_bytes(), MAX_STRING_LEN);
  if (N > vm_free_bytes()) {
    return(SCAN_OUT_OF_MEMORY);
  }
  I = T1Read(tokenStartP,1,N,inputP->data.fileP);
  if ( I != N )     return(SCAN_FILE_EOF);
  return(SCAN_OK);
}
 
/***================================================================***/
/*  getLiteralName(nameObjP)                                          */
/*     scan for next literal.                                         */
/*  if we encounter the name 'end' then terminate and say ok.         */
/*    It means that the CharStrings does not have as many characters  */
/*    as the dictionary said it would and that is ok.                 */
/***================================================================***/
static int 
getLiteralName(psobj *nameObjP)
{
  do {
    scan_token(inputP);
    if (tokenType <= TOKEN_NONE) {
      if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
      return(SCAN_ERROR);
    }
    if (tokenType == TOKEN_NAME) {
      if (0 == strncmp(tokenStartP,"end",3) ) {
        return(SCAN_END);
      }
    }
  } while  (tokenType != TOKEN_LITERAL_NAME) ;
  nameObjP->len = tokenLength;
  /* allocate all the names in the CharStrings Structure */
  if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY);
  nameObjP->data.valueP =  tokenStartP;
  /* found */
  return(SCAN_OK);
}
 
/***================================================================***/
/*
 *   BuildSubrs routine
 */
/***================================================================***/
 
static int 
BuildSubrs(psfont *FontP)
{
   int N;   /* number of values in Subrs */
   int I;   /* index into Subrs */
   int i;   /* loop thru  Subrs */
   int J;   /* length of Subrs entry */
   psobj *arrayP;
 
   /* next token should be a positive int */
   /* note: rc is set by getInt. */
   N = getInt();
   if (rc) return(rc);
   if (N < 0 ) return(SCAN_ERROR);
   /* if we already have a Subrs, then skip the second one */
   /* The second one is for hiresolution devices.          */
   if (FontP->Subrs.data.arrayP != NULL) {
     TwoSubrs = TRUE;
     /* process all the Subrs, but do not update anything */
     /* can not just skip them because of the binary data */
     for (i=0;i<N;i++) {
       /* look for dup */
       rc = getName("dup");
       if (rc) return(rc);
       /* get 2 integers */
       I = getInt();
       if (rc) return(rc);
       J = getInt();
       if (rc) return(rc);
       if ( (I < 0) || (J < 0 ) ) return (SCAN_ERROR);
       /* get the next token, it should be RD or -|, either is ok */
       rc = getNextValue(TOKEN_NAME);
       if ( rc != SCAN_OK ) return(rc);
       rc = getNbytes(J);
       if (rc) return(rc);
     }
     return(SCAN_OK);
   }
 
   arrayP = (psobj *)vm_alloc(N*sizeof(psobj));
   if (!(arrayP) ) return(SCAN_OUT_OF_MEMORY);
   FontP->Subrs.len = N;
   FontP->Subrs.data.arrayP =  arrayP;
   /* get N values for Subrs */
   for (i=0;i<N;i++) {
     /* look for dup */
     rc = getName("dup");
     if (rc) return(rc);
     /* get 2 integers */
     I = getInt();
     if (rc) return(rc);
     J = getInt();
     if (rc) return(rc);
     if ( (I < 0) || (J < 0 ) ) return (SCAN_ERROR);
     arrayP[I].len = J;
     /* get the next token, it should be RD or -|, either is ok */
     rc = getNextValue(TOKEN_NAME);
     if ( rc != SCAN_OK ) return(rc);
     rc = getNbytes(J);
     if (rc == SCAN_OK) {
       arrayP[I].data.valueP = tokenStartP;
       if ( !(vm_alloc(J)) ) return(SCAN_OUT_OF_MEMORY);
     }
     else return(rc);
   }
   return(SCAN_OK);
 
}
/***================================================================***/
/***================================================================***/
/*
 *   BuildCharStrings routine
 */
/***================================================================***/
 
static int 
BuildCharStrings(psfont *FontP)
{
   int N;   /* number of values in CharStrings */
   int i;   /* loop thru  Subrs */
   int J;   /* length of Subrs entry */
   psdict  *dictP;
 
   /* next token should be a positive int */
   N = getInt();
   if (rc) {
     /* check if file had TwoSubrs, hi resolution stuff is in file*/
     if (TwoSubrs) {
       do {
         scan_token(inputP);
         if (tokenType <= TOKEN_NONE) {
           if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
           return(SCAN_ERROR);
         }
       } while (tokenType != TOKEN_INTEGER);
       N = tokenValue.integer;
     }
     else return(rc);  /* if next token was not an Int */
   }
   if (N<=0) return(SCAN_ERROR);
   /* save number of entries in the dictionary */
 
   dictP = (psdict *)vm_alloc((N+1)*sizeof(psdict));
   if (!(dictP)) return(SCAN_OUT_OF_MEMORY);
   FontP->CharStringsP = dictP;
   dictP[0].key.len = N;
   /* get N values for CharStrings */
   for (i=1;i<=N;i++) {
     /* look for next literal name  */
     rc = getLiteralName(&(dictP[i].key));
     if (rc) return(rc);
     /* get 1 integer */
     J = getInt();
     if (rc) return(rc);  /* if next token was not an Int */
     if (J<0) return (SCAN_ERROR);
     dictP[i].value.len = J;
     /* get the next token, it should be RD or -|, either is ok */
     rc = getNextValue(TOKEN_NAME);
     if ( rc != SCAN_OK ) return(rc);
     rc = getNbytes(J);
     if (rc == SCAN_OK) {
       dictP[i].value.data.valueP = tokenStartP;
       if ( !(vm_alloc(J)) ) return(SCAN_OUT_OF_MEMORY);
     }
     else return(rc);
   }
   return(SCAN_OK);
 
}
/***================================================================***/
#if XFONT_CID
/***================================================================***/
/*
 *   BuildCIDFontInfo Dictionary
 */
/***================================================================***/
static int 
BuildCIDFontInfo(cidfont *CIDfontP)
{
  psdict *dictP;

  /* allocate the private dictionary (max number of entries + 1) */
  dictP = (psdict *)vm_alloc(20*sizeof(psdict));
  if (!(dictP)) return(SCAN_OUT_OF_MEMORY);

  CIDfontP->CIDfontInfoP = dictP;
  CIDfontP->CIDfontInfoP[0].key.len = 18;  /* number of actual entries */
  objFormatName(&(dictP[CIDCOUNT].key),8,"CIDCount");
  objFormatInteger(&(dictP[CIDCOUNT].value),-1);
  objFormatName(&(dictP[CIDFONTNAME].key),11,"CIDFontName");
  objFormatName(&(dictP[CIDFONTNAME].value),0,NULL);
  objFormatName(&(dictP[CIDFONTTYPE].key),11,"CIDFontType");
  objFormatInteger(&(dictP[CIDFONTTYPE].value),-1);
  objFormatName(&(dictP[CIDVERSION].key),14,"CIDFontVersion");
  objFormatInteger(&(dictP[CIDVERSION].value),-1);
  objFormatName(&(dictP[CIDREGISTRY].key),8,"Registry");
  objFormatString(&(dictP[CIDREGISTRY].value),0,NULL);
  objFormatName(&(dictP[CIDORDERING].key),8,"Ordering");
  objFormatString(&(dictP[CIDORDERING].value),0,NULL);
  objFormatName(&(dictP[CIDSUPPLEMENT].key),10,"Supplement");
  objFormatInteger(&(dictP[CIDSUPPLEMENT].value),-1);
  objFormatName(&(dictP[CIDMAPOFFSET].key),12,"CIDMapOffset");
  objFormatInteger(&(dictP[CIDMAPOFFSET].value),-1);
  objFormatName(&(dictP[CIDFDARRAY].key),7,"FDArray");
  objFormatArray(&(dictP[CIDFDARRAY].value),0,NULL);
  objFormatName(&(dictP[CIDFDBYTES].key),7,"FDBytes");
  objFormatInteger(&(dictP[CIDFDBYTES].value),-1);
  objFormatName(&(dictP[CIDFONTBBOX].key),8,"FontBBox");
  objFormatArray(&(dictP[CIDFONTBBOX].value),0,NULL);
  objFormatName(&(dictP[CIDFULLNAME].key),8,"FullName");
  objFormatString(&(dictP[CIDFULLNAME].value),0,NULL);
  objFormatName(&(dictP[CIDFAMILYNAME].key),10,"FamilyName");
  objFormatString(&(dictP[CIDFAMILYNAME].value),0,NULL);
  objFormatName(&(dictP[CIDWEIGHT].key),6,"Weight");
  objFormatString(&(dictP[CIDWEIGHT].value),0,NULL);
  objFormatName(&(dictP[CIDNOTICE].key),6,"Notice");
  objFormatString(&(dictP[CIDNOTICE].value),0,NULL);
  objFormatName(&(dictP[CIDGDBYTES].key),7,"GDBytes");
  objFormatInteger(&(dictP[CIDGDBYTES].value),-1);
  objFormatName(&(dictP[CIDUIDBASE].key),7,"UIDBase");
  objFormatInteger(&(dictP[CIDUIDBASE].value),0);
  objFormatName(&(dictP[CIDXUID].key),4,"XUID");
  objFormatInteger(&(dictP[CIDXUID].value),0);
  return(SCAN_OK);
}
/***================================================================***/
/*
 *   BuildCMapInfo Dictionary
 */
/***================================================================***/
static int 
BuildCMapInfo(cmapres *CMapP)
{
  psdict *dictP;

  /* allocate the private dictionary (max number of entries + 1) */
  dictP = (psdict *)vm_alloc(20*sizeof(psdict));
  if (!(dictP)) return(SCAN_OUT_OF_MEMORY);

  CMapP->CMapInfoP = dictP;
  CMapP->CMapInfoP[0].key.len = 8;  /* number of actual entries */
  objFormatName(&(dictP[CMAPREGISTRY].key),8,"Registry");
  objFormatString(&(dictP[CMAPREGISTRY].value),0,NULL);
  objFormatName(&(dictP[CMAPORDERING].key),8,"Ordering");
  objFormatString(&(dictP[CMAPORDERING].value),0,NULL);
  objFormatName(&(dictP[CMAPSUPPLEMENT].key),10,"Supplement");
  objFormatInteger(&(dictP[CMAPSUPPLEMENT].value),-1);
  objFormatName(&(dictP[CMAPNAME].key),8,"CMapName");
  objFormatString(&(dictP[CMAPNAME].value),0,NULL);
  objFormatName(&(dictP[CMAPVERSION].key),11,"CMapVersion");
  objFormatInteger(&(dictP[CMAPVERSION].value),-1);
  objFormatName(&(dictP[CMAPTYPE].key),8,"CMapType");
  objFormatInteger(&(dictP[CMAPTYPE].value),-1);
  objFormatName(&(dictP[CMAPWMODE].key),5,"WMode");
  objFormatInteger(&(dictP[CMAPWMODE].value),-1);
  objFormatName(&(dictP[CMAPCIDCOUNT].key),8,"CIDCount");
  objFormatInteger(&(dictP[CMAPCIDCOUNT].value),-1);
  return(SCAN_OK);
}
#endif

/***================================================================***/
/*
 *   BuildFontInfo Dictionary
 */
/***================================================================***/
static int 
BuildFontInfo(psfont *fontP)
{
  psdict *dictP;
 
  /* allocate the private dictionary */
  dictP = (psdict *)vm_alloc(20*sizeof(psdict));
  if (!(dictP)) return(SCAN_OUT_OF_MEMORY);
 
  fontP->fontInfoP = dictP;
  fontP->fontInfoP[0].key.len = 17;  /* number of actual entries */
  objFormatName(&(dictP[FONTNAME].key),8,"FontName");
  objFormatName(&(dictP[FONTNAME].value),0,NULL);
  objFormatName(&(dictP[PAINTTYPE].key),9,"PaintType");
  objFormatInteger(&(dictP[PAINTTYPE].value),0);
  objFormatName(&(dictP[FONTTYPENUM].key),8,"FontType");
  objFormatInteger(&(dictP[FONTTYPENUM].value),0);
  objFormatName(&(dictP[FONTMATRIX].key),10,"FontMatrix");
  objFormatArray(&(dictP[FONTMATRIX].value),0,NULL);
  objFormatName(&(dictP[FONTBBOX].key),8,"FontBBox");
  objFormatArray(&(dictP[FONTBBOX].value),0,NULL);
  objFormatName(&(dictP[ENCODING].key),8,"Encoding");
  objFormatEncoding(&(dictP[ENCODING].value),0,NULL);
  objFormatName(&(dictP[UNIQUEID].key),8,"UniqueID");
  objFormatInteger(&(dictP[UNIQUEID].value),0);
  objFormatName(&(dictP[STROKEWIDTH].key),11,"StrokeWidth");
  objFormatReal(&(dictP[STROKEWIDTH].value),0.0);
  objFormatName(&(dictP[VERSION].key),7,"version");
  objFormatString(&(dictP[VERSION].value),0,NULL);
  objFormatName(&(dictP[NOTICE].key),6,"Notice");
  objFormatString(&(dictP[NOTICE].value),0,NULL);
  objFormatName(&(dictP[FULLNAME].key),8,"FullName");
  objFormatString(&(dictP[FULLNAME].value),0,NULL);
  objFormatName(&(dictP[FAMILYNAME].key),10,"FamilyName");
  objFormatString(&(dictP[FAMILYNAME].value),0,NULL);
  objFormatName(&(dictP[WEIGHT].key),6,"Weight");
  objFormatString(&(dictP[WEIGHT].value),0,NULL);
  objFormatName(&(dictP[ITALICANGLE].key),11,"ItalicAngle");
  objFormatReal(&(dictP[ITALICANGLE].value),0.0);
  objFormatName(&(dictP[ISFIXEDPITCH].key),12,"isFixedPitch");
  objFormatBoolean(&(dictP[ISFIXEDPITCH].value),FALSE);
  objFormatName(&(dictP[UNDERLINEPOSITION].key),17,"UnderlinePosition");
  objFormatReal(&(dictP[UNDERLINEPOSITION].value),0.0);
  objFormatName(&(dictP[UNDERLINETHICKNESS].key),18,"UnderlineThickness");
  objFormatReal(&(dictP[UNDERLINETHICKNESS].value),0.0);
  return(SCAN_OK);
}
#if XFONT_CID
/***================================================================***/
/*
 *   BuildCIDType1Private Dictionary
 */
/***================================================================***/
static int 
BuildCIDType1Private(psfont *fontP)
{
  psdict *Private;

  /* allocate the private dictionary */
  Private = (psdict *)vm_alloc(21*sizeof(psdict));

  if (!(Private)) return(SCAN_OUT_OF_MEMORY);

  fontP->Private = Private;
  fontP->Private[0].key.len = 20;  /* number of actual entries */

  objFormatName(&(Private[CIDT1MINFEATURE].key),10,"MinFeature");
  objFormatArray(&(Private[CIDT1MINFEATURE].value),0,NULL);
  objFormatName(&(Private[CIDT1LENIV].key),5,"lenIV");
  objFormatInteger(&(Private[CIDT1LENIV].value),DEFAULTLENIV);
  objFormatName(&(Private[CIDT1LANGGROUP].key),13,"LanguageGroup");
  objFormatInteger(&(Private[CIDT1LANGGROUP].value),DEFAULTLANGUAGEGROUP);
  objFormatName(&(Private[CIDT1BLUEVALUES].key),10,"BlueValues");
  objFormatArray(&(Private[CIDT1BLUEVALUES].value),0,NULL);
  objFormatName(&(Private[CIDT1OTHERBLUES].key),10,"OtherBlues");
  objFormatArray(&(Private[CIDT1OTHERBLUES].value),0,NULL);
  objFormatName(&(Private[CIDT1BLUESCALE].key),9,"BlueScale");
  objFormatReal(&(Private[CIDT1BLUESCALE].value),DEFAULTBLUESCALE);
  objFormatName(&(Private[CIDT1BLUEFUZZ].key),8,"BlueFuzz");
  objFormatInteger(&(Private[CIDT1BLUEFUZZ].value),DEFAULTBLUEFUZZ);
  objFormatName(&(Private[CIDT1BLUESHIFT].key),9,"BlueShift");
  objFormatInteger(&(Private[CIDT1BLUESHIFT].value),DEFAULTBLUESHIFT);
  objFormatName(&(Private[CIDT1FAMBLUES].key),11,"FamilyBlues");
  objFormatArray(&(Private[CIDT1FAMBLUES].value),0,NULL);
  objFormatName(&(Private[CIDT1FAMOTHERBLUES].key),16,"FamilyOtherBlues");
  objFormatArray(&(Private[CIDT1FAMOTHERBLUES].value),0,NULL);
  objFormatName(&(Private[CIDT1STDHW].key),5,"StdHW");
  objFormatArray(&(Private[CIDT1STDHW].value),0,NULL);
  objFormatName(&(Private[CIDT1STDVW].key),5,"StdVW");
  objFormatArray(&(Private[CIDT1STDVW].value),0,NULL);
  objFormatName(&(Private[CIDT1STEMSNAPH].key),9,"StemSnapH");
  objFormatArray(&(Private[CIDT1STEMSNAPH].value),0,NULL);
  objFormatName(&(Private[CIDT1STEMSNAPV].key),9,"StemSnapV");
  objFormatArray(&(Private[CIDT1STEMSNAPV].value),0,NULL);
  /* skip password */
  objFormatName(&(Private[CIDT1SUBMAPOFF].key),13,"SubrMapOffset");
  objFormatInteger(&(Private[CIDT1SUBMAPOFF].value),0);
  objFormatName(&(Private[CIDT1SDBYTES].key),7,"SDBytes");
  objFormatInteger(&(Private[CIDT1SDBYTES].value),0);
  objFormatName(&(Private[CIDT1SUBRCNT].key),9,"SubrCount");
  objFormatInteger(&(Private[CIDT1SUBRCNT].value),0);
  objFormatName(&(Private[CIDT1FORCEBOLD].key),9,"ForceBold");
  objFormatBoolean(&(Private[CIDT1FORCEBOLD].value),DEFAULTFORCEBOLD);
  objFormatName(&(Private[CIDT1RNDSTEMUP].key),9,"RndStemUp");
  objFormatBoolean(&(Private[CIDT1RNDSTEMUP].value),DEFAULTRNDSTEMUP);
  objFormatName(&(Private[CIDT1EXPFACTOR].key),15,"ExpansionFactor");
  objFormatReal(&(Private[CIDT1EXPFACTOR].value),
                          DEFAULTEXPANSIONFACTOR);
  return(SCAN_OK);
}
#endif
/***================================================================***/
/*
 *   BuildPrivate Dictionary
 */
/***================================================================***/
static int 
BuildPrivate(psfont *fontP)
{
  psdict *Private;
 
  /* allocate the private dictionary */
  Private = (psdict *)vm_alloc(20*sizeof(psdict));
 
  if (!(Private)) return(SCAN_OUT_OF_MEMORY);
 
  fontP->Private = Private;
  fontP->Private[0].key.len = 16;  /* number of actual entries */
 
  objFormatName(&(Private[BLUEVALUES].key),10,"BlueValues");
  objFormatArray(&(Private[BLUEVALUES].value),0,NULL);
  objFormatName(&(Private[OTHERBLUES].key),10,"OtherBlues");
  objFormatArray(&(Private[OTHERBLUES].value),0,NULL);
  objFormatName(&(Private[FAMILYBLUES].key),11,"FamilyBlues");
  objFormatArray(&(Private[FAMILYBLUES].value),0,NULL);
  objFormatName(&(Private[FAMILYOTHERBLUES].key),16,"FamilyOtherBlues");
  objFormatArray(&(Private[FAMILYOTHERBLUES].value),0,NULL);
  objFormatName(&(Private[BLUESCALE].key),9,"BlueScale");
  objFormatReal(&(Private[BLUESCALE].value),DEFAULTBLUESCALE);
  objFormatName(&(Private[BLUESHIFT].key),9,"BlueShift");
  objFormatInteger(&(Private[BLUESHIFT].value),DEFAULTBLUESHIFT);
  objFormatName(&(Private[BLUEFUZZ].key),8,"BlueFuzz");
  objFormatInteger(&(Private[BLUEFUZZ].value),DEFAULTBLUEFUZZ);
  objFormatName(&(Private[STDHW].key),5,"StdHW");
  objFormatArray(&(Private[STDHW].value),0,NULL);
  objFormatName(&(Private[STDVW].key),5,"StdVW");
  objFormatArray(&(Private[STDVW].value),0,NULL);
  objFormatName(&(Private[STEMSNAPH].key),9,"StemSnapH");
  objFormatArray(&(Private[STEMSNAPH].value),0,NULL);
  objFormatName(&(Private[STEMSNAPV].key),9,"StemSnapV");
  objFormatArray(&(Private[STEMSNAPV].value),0,NULL);
  objFormatName(&(Private[FORCEBOLD].key),9,"ForceBold");
  objFormatBoolean(&(Private[FORCEBOLD].value),DEFAULTFORCEBOLD);
  objFormatName(&(Private[LANGUAGEGROUP].key),13,"LanguageGroup");
  objFormatInteger(&(Private[LANGUAGEGROUP].value),DEFAULTLANGUAGEGROUP);
  objFormatName(&(Private[LENIV].key),5,"lenIV");
  objFormatInteger(&(Private[LENIV].value),DEFAULTLENIV);
  objFormatName(&(Private[RNDSTEMUP].key),9,"RndStemUp");
  objFormatBoolean(&(Private[RNDSTEMUP].value),DEFAULTRNDSTEMUP);
  objFormatName(&(Private[EXPANSIONFACTOR].key),9,"ExpansionFactor");
  objFormatReal(&(Private[EXPANSIONFACTOR].value),
                          DEFAULTEXPANSIONFACTOR);
  return(SCAN_OK);
}
/***================================================================***/
/**********************************************************************/
/*     GetType1Blues(fontP)                                           */
/*                                                                    */
/*   Routine to support font-level hints.                             */
/*                                                                    */
/*         Gets all the Blues information from the Private dictionary */
/*         for the font.                                              */
/*                                                                    */
/*                                                                    */
/**********************************************************************/
static int 
GetType1Blues(psfont *fontP)
{
  psdict *PrivateDictP;   /* the Private dict relating to hints */
  struct blues_struct *blues;  /* ptr for the blues struct we will allocate */
  int i;
  psobj *HintEntryP;
 
 
 
  /* get the Private dictionary pointer */
  PrivateDictP = fontP->Private;
 
  /* allocate the memory for the blues structure */
  blues = (struct blues_struct *) vm_alloc(sizeof(struct blues_struct));
 
  if (!blues)  return(SCAN_OUT_OF_MEMORY);
 
  /* Make fontP's blues ptr point to this newly allocated structure. */
  fontP->BluesP = blues;
 
  /* fill in the BlueValues array */
  HintEntryP = &(PrivateDictP[BLUEVALUES].value);
  /* check to see if the entry exists and if it's an array */
  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
      blues->numBlueValues = 0;
  else {
      /* get the number of values in the array */
      if (HintEntryP->len > NUMBLUEVALUES) {
          blues->numBlueValues = NUMBLUEVALUES;
      } else
          blues->numBlueValues = HintEntryP->len;
      for (i = 0; i<= blues->numBlueValues-1; ++i) {
          if (objPIsInteger(&HintEntryP->data.arrayP[i]))
              blues->BlueValues[i] =
                  HintEntryP->data.arrayP[i].data.integer;
          else if (objPIsReal(&HintEntryP->data.arrayP[i]))
              blues->BlueValues[i] =
                  HintEntryP->data.arrayP[i].data.real;
          else
              blues->BlueValues[i] = 0;
      }
  }
 
  /* fill in the OtherBlues array */
  HintEntryP =  &(PrivateDictP[OTHERBLUES].value);
  /* check to see if the entry exists and if it's an array */
  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
      blues->numOtherBlues = 0;
  else {
      /* get the number of values in the array */
      if (HintEntryP->len > NUMOTHERBLUES) {
          blues->numOtherBlues = NUMOTHERBLUES;
      } else
          blues->numOtherBlues = HintEntryP->len;
      for (i = 0; i<= blues->numOtherBlues-1; ++i) {
          if (objPIsInteger(&HintEntryP->data.arrayP[i]))
              blues->OtherBlues[i] =
                  HintEntryP->data.arrayP[i].data.integer;
          else if (objPIsReal(&HintEntryP->data.arrayP[i]))
              blues->OtherBlues[i] =
                  HintEntryP->data.arrayP[i].data.real;
          else
              blues->OtherBlues[i] = 0;
      }
  }
 
  /* fill in the FamilyBlues array */
  HintEntryP =  &(PrivateDictP[FAMILYBLUES].value);
  /* check to see if the entry exists and if it's an array */
  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
      blues->numFamilyBlues = 0;
  else {
      /* get the number of values in the array */
      if (HintEntryP->len > NUMFAMILYBLUES) {
          blues->numFamilyBlues = NUMFAMILYBLUES;
      } else
          blues->numFamilyBlues = HintEntryP->len;
      for (i = 0; i<= blues->numFamilyBlues-1; ++i) {
          if (objPIsInteger(&HintEntryP->data.arrayP[i]))
              blues->FamilyBlues[i] =
                  HintEntryP->data.arrayP[i].data.integer;
          else if (objPIsReal(&HintEntryP->data.arrayP[i]))
              blues->FamilyBlues[i] =
                  HintEntryP->data.arrayP[i].data.real;
          else
              blues->FamilyBlues[i] = 0;
      }
  }
 
  /* fill in the FamilyOtherBlues array */
  HintEntryP =  &(PrivateDictP[FAMILYOTHERBLUES].value);
  /* check to see if the entry exists and if it's an array */
  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
      blues->numFamilyOtherBlues = 0;
  else {
      /* get the number of values in the array */
      if (HintEntryP->len > NUMFAMILYOTHERBLUES) {
          blues->numFamilyOtherBlues = NUMFAMILYOTHERBLUES;
      } else
          blues->numFamilyOtherBlues = HintEntryP->len;
      for (i = 0; i<= blues->numFamilyOtherBlues-1; ++i) {
          if (objPIsInteger(&HintEntryP->data.arrayP[i]))
              blues->FamilyOtherBlues[i] =
                  HintEntryP->data.arrayP[i].data.integer;
          else if (objPIsReal(&HintEntryP->data.arrayP[i]))
              blues->FamilyOtherBlues[i] =
                  HintEntryP->data.arrayP[i].data.real;
          else
              blues->FamilyOtherBlues[i] = 0;
      }
  }
 
  /* fill in the StemSnapH array */
  HintEntryP =  &(PrivateDictP[STEMSNAPH].value);
  /* check to see if the entry exists and if it's an array */
  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
      blues->numStemSnapH = 0;
  else {
      /* get the number of values in the array */
      if (HintEntryP->len > NUMSTEMSNAPH) {
          blues->numStemSnapH = NUMSTEMSNAPH;
      } else
          blues->numStemSnapH = HintEntryP->len;
      for (i = 0; i<= blues->numStemSnapH-1; ++i) {
          if (objPIsInteger(&HintEntryP->data.arrayP[i]))
              blues->StemSnapH[i] =
                  HintEntryP->data.arrayP[i].data.integer;
          else if (objPIsReal(&HintEntryP->data.arrayP[i]))
              blues->StemSnapH[i] =
                  HintEntryP->data.arrayP[i].data.real;
          else
              blues->StemSnapH[i] = 0;
      }
  }
 
  /* fill in the StemSnapV array */
  HintEntryP =  &(PrivateDictP[STEMSNAPV].value);
  /* check to see if the entry exists and if it's an array */
  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
      blues->numStemSnapV = 0;
  else {
      /* get the number of values in the array */
      if (HintEntryP->len > NUMSTEMSNAPV) {
          blues->numStemSnapV = NUMSTEMSNAPV;
      } else
          blues->numStemSnapV = HintEntryP->len;
      for (i = 0; i<= blues->numStemSnapV-1; ++i) {
          if (objPIsInteger(&HintEntryP->data.arrayP[i]))
              blues->StemSnapV[i] =
                  HintEntryP->data.arrayP[i].data.integer;
          else if (objPIsReal(&HintEntryP->data.arrayP[i]))
              blues->StemSnapV[i] =
                  HintEntryP->data.arrayP[i].data.real;
          else
              blues->StemSnapV[i] = 0;
      }
  }
 
  /* fill in the StdVW array */
  HintEntryP =  &(PrivateDictP[STDVW].value);
  /* check to see if the entry exists and if it's an array */
  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
      /* a value of zero signifies no entry */
      blues->StdVW = 0;
  else {
      if (HintEntryP->len > NUMSTDVW) {
      }
      if (objPIsInteger(&HintEntryP->data.arrayP[0]))
          blues->StdVW = HintEntryP->data.arrayP[0].data.integer;
      else if (objPIsReal(&HintEntryP->data.arrayP[0]))
          blues->StdVW = HintEntryP->data.arrayP[0].data.real;
      else
          blues->StdVW = 0;
  }
 
  /* fill in the StdHW array */
  HintEntryP =  &(PrivateDictP[STDHW].value);
  /* check to see if the entry exists and if it's an array */
  if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
      /* a value of zero signifies no entry */
      blues->StdHW = 0;
  else {
      if (HintEntryP->len > NUMSTDHW) {
      }
          if (objPIsInteger(&HintEntryP->data.arrayP[0]))
             blues->StdHW = HintEntryP->data.arrayP[0].data.integer;
          else if (objPIsReal(&HintEntryP->data.arrayP[0]))
             blues->StdHW = HintEntryP->data.arrayP[0].data.real;
          else
             blues->StdHW = 0;
  }
 
 
  /* get the ptr to the BlueScale entry */
  HintEntryP =  &(PrivateDictP[BLUESCALE].value);
  /* put the BlueScale in the blues structure */
  if (objPIsInteger(HintEntryP)) /* Must be integer! */
      blues->BlueScale = HintEntryP->data.integer;
  else if (objPIsReal(HintEntryP)) /* Error? */
      blues->BlueScale = HintEntryP->data.real;
  else
      blues->BlueScale = DEFAULTBLUESCALE;
 
  /* get the ptr to the BlueShift entry */
  HintEntryP =  &(PrivateDictP[BLUESHIFT].value);
  if (objPIsInteger(HintEntryP)) /* Must be integer! */
      blues->BlueShift = HintEntryP->data.integer;
  else if (objPIsReal(HintEntryP)) /* Error? */
      blues->BlueShift = HintEntryP->data.real;
  else
      blues->BlueShift = DEFAULTBLUESHIFT;
 
  /* get the ptr to the BlueFuzz entry */
  HintEntryP =  &(PrivateDictP[BLUEFUZZ].value);
  if (objPIsInteger(HintEntryP)) /* Must be integer! */
      blues->BlueFuzz = HintEntryP->data.integer;
  else if (objPIsReal(HintEntryP)) /* Error? */
      blues->BlueFuzz = HintEntryP->data.real;
  else
      blues->BlueFuzz = DEFAULTBLUEFUZZ;
 
  /* get the ptr to the ForceBold entry */
  HintEntryP =  &(PrivateDictP[FORCEBOLD].value);
  if (objPIsBoolean(HintEntryP))  /* Must be integer! */
      blues->ForceBold = HintEntryP->data.boolean;
  else
      blues->ForceBold = DEFAULTFORCEBOLD;
 
  /* get the ptr to the LanguageGroup entry */
  HintEntryP =  &(PrivateDictP[LANGUAGEGROUP].value);
  if (objPIsInteger(HintEntryP)) /* Must be integer! */
      blues->LanguageGroup = HintEntryP->data.integer;
  else
      blues->LanguageGroup = DEFAULTLANGUAGEGROUP;
 
  /* get the ptr to the RndStemUp entry */
  HintEntryP =  &(PrivateDictP[RNDSTEMUP].value);
  if (objPIsBoolean(HintEntryP)) /* Must be integer! */
      blues->RndStemUp = HintEntryP->data.boolean;
  else
      blues->RndStemUp = DEFAULTRNDSTEMUP;
 
  /* get the ptr to the lenIV entry */
  HintEntryP =  &(PrivateDictP[LENIV].value);
  if (objPIsInteger(HintEntryP)) /* Must be integer! */
      blues->lenIV = HintEntryP->data.integer;
  else
      blues->lenIV = DEFAULTLENIV;
 
  /* get the ptr to the ExpansionFactor entry */
  HintEntryP =  &(PrivateDictP[EXPANSIONFACTOR].value);
  if (objPIsInteger(HintEntryP))
      blues->ExpansionFactor = HintEntryP->data.integer;
  else if (objPIsReal(HintEntryP))
      blues->ExpansionFactor = HintEntryP->data.real;
  else
      blues->ExpansionFactor = DEFAULTEXPANSIONFACTOR;
  return(SCAN_OK);
}
/**********************************************************************/
/*   GetType1CharString(fontP,code)                                   */
/*                                                                    */
/*          Look up code in the standard encoding vector and return   */
/*          the charstring associated with the character name.        */
/*                                                                    */
/*   fontP  is the psfont structure.                                  */
/*                                                                    */
/*   Returns a psobj (string)                                         */
/**********************************************************************/
psobj *
GetType1CharString(psfont *fontP, unsigned char code)
{
  int  N;           /* the 'Nth' entry in the CharStrings       */
  psobj *charnameP; /* points to psobj that is name of character*/
 
  psdict *CharStringsDictP; /* dictionary with char strings     */
  psobj  *theStringP;  /* the definition for the code */
 
 
 
  if (StdEncArrayP == NULL) {
    return(NULL);
  }
  /* use the code to index into the standard encoding vector  */
  charnameP = &(StdEncArrayP[code]);
 
  /* test if the encoding array points to a name */
  if (!(objPIsName(charnameP)) ) {
    return(NULL);
  }
 
  /* Now that we have the character name out of the standardencoding */
  /* get the character definition out of the current font */
  CharStringsDictP =  fontP->CharStringsP;
 
  /* search the chars string for this charname as key */
  N = SearchDictName(CharStringsDictP,charnameP);
  if (N<=0) {
    return(NULL);
  }
  /* OK, the nth item is the psobj that is the string for this char */
  theStringP = &(CharStringsDictP[N].value);
 
  return(theStringP);
}
 
/***================================================================***/
/*
 *   FindDictValue
 */
/***================================================================***/
 
static int 
FindDictValue(psdict *dictP)
{
   psobj LitName;
   int   N;
   int   V;
 
   /* we have just scanned a token and it is a literal name */
   /* need to check if that name is in Private dictionary */
   objFormatName(&LitName,tokenLength,tokenStartP);
   /* is it in the dictP */
   N = SearchDictName(dictP,&LitName);
   /* if found */
   if ( N > 0 ) {
     /* what type */
     switch (dictP[N].value.type) {
       case OBJ_ENCODING:
         V = getEncoding(&(dictP[N].value));
         if ( V != SCAN_OK ) return(V);
         break;
       case OBJ_ARRAY:
#if XFONT_CID
         if (0 == strncmp(tokenStartP,"FDArray",7))
             V = getFDArray(&(dictP[N].value));
         else
             V = getArray(&(dictP[N].value));
#else
         V = getArray(&(dictP[N].value));
#endif
         if ( V != SCAN_OK ) return(V);
         break;
       case OBJ_INTEGER:
         /* next value in integer */
         dictP[N].value.data.integer = getInt();
         if (rc) return(rc);  /* if next token was not an Int */
         break;
       case OBJ_REAL:
         /* next value must be real or int, store as a real */
         scan_token(inputP);
         if (tokenType == TOKEN_REAL) {
           dictP[N].value.data.real = tokenValue.real;
         }
         else
           if (tokenType == TOKEN_INTEGER) {
             dictP[N].value.data.real = tokenValue.integer;
           }
         else return(SCAN_ERROR);
         break;
       case OBJ_NAME:
         V = getNextValue(TOKEN_LITERAL_NAME);
         if ( V != SCAN_OK ) return(V);
         if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY);
         objFormatName(&(dictP[N].value),tokenLength,tokenStartP);
         break;
       case OBJ_STRING:
         V = getNextValue(TOKEN_STRING);
         if ( V != SCAN_OK ) return(V);
         if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY);
         objFormatString(&(dictP[N].value),tokenLength,tokenStartP);
         break;
       case OBJ_BOOLEAN:
         scan_token(inputP);
         if (tokenType != TOKEN_NAME) {
           return(SCAN_ERROR);
         }
         if (0 == strncmp(tokenStartP,"true",4) ) {
           dictP[N].value.data.boolean =TRUE;
         }
         else
           if (0 == strncmp(tokenStartP,"false",5) ) {
             dictP[N].value.data.boolean =FALSE;
           }
           else return(SCAN_ERROR);
         break;
 
       default:
         return(SCAN_ERROR);
     }
   }
   /* Name is not in dictionary.  That is ok. */
   return(SCAN_OK);
 
}
/***================================================================***/

#if XFONT_CID
/*
 * -------------------------------------------------------------------
 *  Scan the next token and convert it into an object
 *  Result is placed on the Operand Stack as next object
 * -------------------------------------------------------------------
 */
int 
scan_cidfont(cidfont *CIDFontP, cmapres *CMapP)
{
  char   filename[CID_PATH_MAX];
  char   cmapfile[CID_PATH_MAX];
  char   buf[CID_BUFSIZE];
  char   filetype[3];
  FILE   *fileP;
  FILE   *fileP1;
  char   *nameP;
  int    namelen;
  int    i, j;
  int    cread, rangecnt;
  unsigned int char_row, char_col;

    filetype[0] = 'r';
    filetype[1] = 'b';
    filetype[2] = '\0';

    /* copy the filename and remove leading or trailing blanks */
    /* point to name and search for leading blanks */
    nameP= CIDFontP->CIDFontFileName.data.nameP;
    namelen  = CIDFontP->CIDFontFileName.len;
    while (nameP[0] == ' ') {
        nameP++;
        namelen--;
    }
    /* now remove any trailing blanks */
    while ((namelen>0) && ( nameP[namelen-1] == ' ')) {
      namelen--;
    }
    strncpy(filename,nameP,namelen);
    filename[namelen] = '\0';
    /* file name is now constructed */
    inputFile.data.fileP = NULL;
    filterFile.data.fileP = NULL;

    /* check whether a CIDFont file */
    if ((fileP = fopen(filename,filetype))) {
        cread = fread(buf, 1, CID_BUFSIZE, fileP);
        fclose(fileP);
        if (cread > 17) {
            if (strncmp(buf, "%!", 2) ||
                strstr(buf, "Resource-CIDFont") == NULL)
                return(SCAN_FILE_OPEN_ERROR);
        } else
            return(SCAN_FILE_OPEN_ERROR);
    } else
        return(SCAN_FILE_OPEN_ERROR);

    /* copy the CMap file name and remove leading or trailing blanks */
    /* point to name and search for leading blanks                   */
    nameP = CMapP->CMapFileName.data.nameP;
    namelen  = CMapP->CMapFileName.len;
    while (nameP[0] == ' ') {
        nameP++;
        namelen--;
    }
    /* now remove any trailing blanks */
    while ((namelen>0) && ( nameP[namelen-1] == ' ')) {
      namelen--;
    }
    strncpy(cmapfile,nameP,namelen);
    cmapfile[namelen] = '\0';
    /* CMap file name is now constructed */
    inputFile1.data.fileP = NULL;

    /* check whether a CMap file */
    if ((fileP1 = fopen(cmapfile,filetype))) {
        cread = fread(buf, 1, CID_BUFSIZE, fileP1);
        fclose(fileP1);
        if (cread > 17) {
            if (strncmp(buf, "%!", 2) ||
                strstr(buf, "Resource-CMap") == NULL)
                return(SCAN_FILE_OPEN_ERROR);
        } else
            return(SCAN_FILE_OPEN_ERROR);
    } else
        return(SCAN_FILE_OPEN_ERROR);

  /* read the specified CMap file */
  inputP = &inputFile1;

  if (!(fileP1 = fopen(cmapfile,filetype)))
    return(SCAN_FILE_OPEN_ERROR);

  objFormatFile(inputP,fileP1);

  if ((rc = BuildCMapInfo(CMapP)) != 0)
    return(rc);

  /* Assume everything will be OK */
  rc = 0;
  rangecnt = 0;

  do {
    /* Scan the next token */
    scan_token(inputP);
    if (tokenType == TOKEN_INTEGER)
      rangecnt = tokenValue.integer;

    /* ==> tokenLength, tokenTooLong, tokenType, and */
    /* tokenValue are now set                        */

    switch (tokenType) {
      case TOKEN_EOF:
      case TOKEN_NONE:
      case TOKEN_INVALID:
        /* in this case we are done */
        if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
        rc = SCAN_ERROR;
        break;
      case TOKEN_LITERAL_NAME:
        /* Look up the name */
        tokenStartP[tokenLength] = '\0';

        rc = FindDictValue(CMapP->CMapInfoP);
        /* we are not going to report errors except out of memory */
        if (rc != SCAN_OUT_OF_MEMORY)
          rc = SCAN_OK;
        break;
      case TOKEN_NAME:
        if (0 == strncmp(tokenStartP,"begincodespacerange",19)) {
          CIDFontP->spacerangecnt++;
          spacerangeP = (spacerange *)vm_alloc(sizeof(spacerange));
          if (!spacerangeP) {
            rc = SCAN_OUT_OF_MEMORY;
            break;
          }
          spacerangeP->next = NULL;
          spacerangeP->rangecnt = rangecnt;
          spacerangeP->spacecode =
            (spacerangecode *)vm_alloc(rangecnt*sizeof(spacerangecode));
          if (!spacerangeP->spacecode) {
            rc = SCAN_OUT_OF_MEMORY;
            break;
          }
          for (i = 0; i < rangecnt; i++) {
            scan_token(inputP);
            if (tokenType != TOKEN_HEX_STRING) {
              rc = SCAN_ERROR;
              break;
            }
            spacerangeP->spacecode[i].srcCodeLo = 0;
            for (j = 0; j < tokenLength; j++)
              spacerangeP->spacecode[i].srcCodeLo +=
                (unsigned char)tokenStartP[j] << (8 * (tokenLength - 1 - j));

            scan_token(inputP);
            if (tokenType != TOKEN_HEX_STRING) {
              rc = SCAN_ERROR;
              break;
            }
            spacerangeP->spacecode[i].srcCodeHi = 0;
            for (j = 0; j < tokenLength; j++)
              spacerangeP->spacecode[i].srcCodeHi +=
                (unsigned char)tokenStartP[j] << (8 * (tokenLength - 1 - j));
          }

          if (CIDFontP->spacerangeP) {
            if (CIDFontP->spacerangeP->next == NULL)
              CIDFontP->spacerangeP->next = spacerangeP;
            else {
              spacerangeP->next = CIDFontP->spacerangeP->next;
              CIDFontP->spacerangeP->next = spacerangeP;
            }
          } else
            CIDFontP->spacerangeP = spacerangeP;
 
          /* read "endcodespacerange" */
          scan_token(inputP);
          if (tokenType != TOKEN_NAME || (tokenType == TOKEN_NAME &&
            (strncmp(tokenStartP,"endcodespacerange",17) != 0))) {
            rc = SCAN_ERROR;
            break;
          }
        }
        if (0 == strncmp(tokenStartP,"begincidrange",13)) {
          CIDFontP->cidrangecnt++;
          cidrangeP = (cidrange *)vm_alloc(sizeof(cidrange));
          if (!cidrangeP) {
            rc = SCAN_OUT_OF_MEMORY;
            break;
          }
          cidrangeP->next = NULL;
          cidrangeP->rangecnt = rangecnt;
          cidrangeP->range =
            (cidrangecode *)vm_alloc(rangecnt*sizeof(cidrangecode));
          if (!cidrangeP->range) {
            rc = SCAN_OUT_OF_MEMORY;
            break;
          }
          for (i = 0; i < rangecnt; i++) {
            scan_token(inputP);
            if (tokenType != TOKEN_HEX_STRING) {
              rc = SCAN_ERROR;
              break;
            }
            cidrangeP->range[i].srcCodeLo = 0;
            for (j = 0; j < tokenLength; j++)
              cidrangeP->range[i].srcCodeLo +=
                (unsigned char)tokenStartP[j] << (8 * (tokenLength - 1 - j));
            char_row = (cidrangeP->range[i].srcCodeLo >> 8) & 0xff;
            char_col = cidrangeP->range[i].srcCodeLo & 0xff;
            if (char_row < CMapP->firstRow)
              CMapP->firstRow = char_row;
            if (char_row > CMapP->lastRow)
              CMapP->lastRow = char_row;
            if (char_col < CMapP->firstCol)
              CMapP->firstCol = char_col;
            if (char_col > CMapP->lastCol)
              CMapP->lastCol = char_col;
            scan_token(inputP);
            if (tokenType != TOKEN_HEX_STRING) {
              rc = SCAN_ERROR;
              break;
            }
            cidrangeP->range[i].srcCodeHi = 0;
            for (j = 0; j < tokenLength; j++)
              cidrangeP->range[i].srcCodeHi +=
                (unsigned char)tokenStartP[j] << (8 * (tokenLength - 1 - j));
            char_row = (cidrangeP->range[i].srcCodeHi >> 8) & 0xff;
            char_col = cidrangeP->range[i].srcCodeHi & 0xff;
            if (char_row < CMapP->firstRow)
              CMapP->firstRow = char_row;
            if (char_row > CMapP->lastRow)
              CMapP->lastRow = char_row;
            if (char_col < CMapP->firstCol)
              CMapP->firstCol = char_col;
            if (char_col > CMapP->lastCol)
              CMapP->lastCol = char_col;
            scan_token(inputP);
            if (tokenType != TOKEN_INTEGER) {
              rc = SCAN_ERROR;
              break;
            }
            cidrangeP->range[i].dstCIDLo = tokenValue.integer;
          }

          if (CIDFontP->cidrangeP) {
            if (CIDFontP->cidrangeP->next == NULL)
              CIDFontP->cidrangeP->next = cidrangeP;
            else {
              cidrangeP->next = CIDFontP->cidrangeP->next;
              CIDFontP->cidrangeP->next = cidrangeP;
            }
          } else
            CIDFontP->cidrangeP = cidrangeP;

          /* read "endcidrange" */
          scan_token(inputP);
          if (tokenType != TOKEN_NAME || (tokenType == TOKEN_NAME &&
            (strncmp(tokenStartP,"endcidrange",11) != 0))) {
            rc = SCAN_ERROR;
            break;
          }
        }

        if (0 == strncmp(tokenStartP,"beginnotdefrange",16)) {
          CIDFontP->notdefrangecnt++;
          notdefrangeP = (cidrange *)vm_alloc(sizeof(cidrange));
          if (!notdefrangeP) {
            rc = SCAN_OUT_OF_MEMORY;
            break;
          }
          notdefrangeP->next = 0;
          notdefrangeP->rangecnt = rangecnt;
          notdefrangeP->range =
            (cidrangecode *)vm_alloc(rangecnt*sizeof(cidrangecode));
          if (!notdefrangeP->range) {
            rc = SCAN_OUT_OF_MEMORY;
            break;
          }
          for (i = 0; i < rangecnt; i++) {
            scan_token(inputP);
            if (tokenType != TOKEN_HEX_STRING) {
              rc = SCAN_ERROR;
              break;
            }
            notdefrangeP->range[i].srcCodeLo = 0;
            for (j = 0; j < tokenLength; j++)
              notdefrangeP->range[i].srcCodeLo = (int)(tokenStartP[j] <<
                (8 * (tokenLength - 1 - j)));
            scan_token(inputP);
            if (tokenType != TOKEN_HEX_STRING) {
              rc = SCAN_ERROR;
              break;
            }
            notdefrangeP->range[i].srcCodeHi = 0;
            for (j = 0; j < tokenLength; j++)
              notdefrangeP->range[i].srcCodeHi = (int)(tokenStartP[j] <<
                (8 * (tokenLength - 1 - j)));
            scan_token(inputP);
            if (tokenType != TOKEN_INTEGER) {
              rc = SCAN_ERROR;
              break;
            }
            notdefrangeP->range[i].dstCIDLo = tokenValue.integer;
          }
          if (CIDFontP->notdefrangeP) {
            if (CIDFontP->notdefrangeP->next == NULL)
              CIDFontP->notdefrangeP->next = notdefrangeP;
            else {
              notdefrangeP->next = CIDFontP->notdefrangeP->next;
              CIDFontP->notdefrangeP->next = notdefrangeP;
            }
          } else
            CIDFontP->notdefrangeP = notdefrangeP;

          /* read "endnotdefrange" */
          scan_token(inputP);
          if (tokenType != TOKEN_NAME || (tokenType == TOKEN_NAME &&
            (strncmp(tokenStartP,"endnotdefrange",14) != 0))) {
            rc = SCAN_ERROR;
            break;
          }
        }

        if (0 == strncmp(tokenStartP,"endcmap",7)) {
          if (CMapP->CMapInfoP[CMAPREGISTRY].value.data.valueP == NULL ||
            CMapP->CMapInfoP[CMAPORDERING].value.data.valueP == NULL ||
            CMapP->CMapInfoP[CMAPSUPPLEMENT].value.data.integer == -1) {
            rc = SCAN_ERROR;
            break;
          } else {
            rc = SCAN_FILE_EOF;
            break;
          }
        }
        break;
    }
  }
  while (rc == 0);
  fclose(inputP->data.fileP);
  if (tokenTooLong)
      rc = SCAN_OUT_OF_MEMORY;
  if (rc == SCAN_OUT_OF_MEMORY) return(rc);

  /* open the specified CIDFont file */
  if (!(fileP = fopen(filename,filetype)))
      return(SCAN_FILE_OPEN_ERROR);

  inputP = &inputFile;
  objFormatFile(inputP,fileP);
  CIDWantFontInfo  = TRUE;
  TwoSubrs      = FALSE;
  rc = BuildCIDFontInfo(CIDFontP);
  if (rc != 0) return(rc);

  /* Assume everything will be OK */
  rc = 0;

  /* Loop until complete font is read  */
  do {
    /* Scan the next token */
    scan_token(inputP);

    /* ==> tokenLength, tokenTooLong, tokenType, and tokenValue are */
    /* now set */

    switch (tokenType) {
      case TOKEN_EOF:
      case TOKEN_NONE:
      case TOKEN_INVALID:
        /* in this case we are done */
        if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
        rc = SCAN_ERROR;
        break;
      case TOKEN_LITERAL_NAME:
        /* Look up the name */
        tokenStartP[tokenLength] = '\0';

         if (CIDWantFontInfo) {
             rc = FindDictValue(CIDFontP->CIDfontInfoP);
             /* we are not going to report errors except out of memory */
             if (rc != SCAN_OUT_OF_MEMORY)
               rc = SCAN_OK;
             break;
         }
        break;
      case TOKEN_STRING:
        tokenStartP[tokenLength] = '\0';
        if (0 == strncmp(tokenStartP,"Binary",6)) {
          CIDFontP->binarydata = 1;
          scan_token(inputP);
          if (tokenType == TOKEN_INTEGER)
            CIDFontP->bytecnt = tokenValue.integer;
          else {
            rc = SCAN_ERROR;
            break;
          }
        } else if (0 == strncmp(tokenStartP,"Hex",3)) {
          /* not yet supported */
          rc = SCAN_ERROR;
          break;
#if 0
          /* uncomment when the hex format is supported */
          CIDFontP->binarydata = 0;
          scan_token(inputP);
          if (tokenType == TOKEN_INTEGER)
            CIDFontP->bytecnt = tokenValue.integer;
          else {
            rc = SCAN_ERROR;
            break;
          }
#endif
        }
        break;
      case TOKEN_NAME:
        /* end of PostScript and beginning of data */
        if (0 == strncmp(tokenStartP,"StartData",9)) {
          /* every CIDFont must have an FDArray */
          /* check whether other required dictionary entries were found */
          if (CIDFontP->CIDfontInfoP[CIDFDARRAY].value.data.arrayP == NULL ||
            CIDFontP->CIDfontInfoP[CIDFONTNAME].value.data.nameP == NULL ||
            CIDFontP->CIDfontInfoP[CIDFONTTYPE].value.data.integer == -1 ||
            CIDFontP->CIDfontInfoP[CIDVERSION].value.data.integer == -1 ||
            CIDFontP->CIDfontInfoP[CIDREGISTRY].value.data.valueP == NULL ||
            CIDFontP->CIDfontInfoP[CIDORDERING].value.data.valueP == NULL ||
            CIDFontP->CIDfontInfoP[CIDSUPPLEMENT].value.data.integer == -1 ||
            CIDFontP->CIDfontInfoP[CIDFONTBBOX].value.data.arrayP == NULL ||
            CIDFontP->CIDfontInfoP[CIDMAPOFFSET].value.data.integer == -1 ||
            CIDFontP->CIDfontInfoP[CIDFDBYTES].value.data.integer == -1 ||
            CIDFontP->CIDfontInfoP[CIDGDBYTES].value.data.integer == -1 ||
            CIDFontP->CIDfontInfoP[CIDCOUNT].value.data.integer == -1) {
            rc = SCAN_ERROR;
            break;
          } else {
            /* do Registry and Ordering entries match? */
            if (strcmp(CIDFontP->CIDfontInfoP[CIDREGISTRY].value.data.valueP,
              CMapP->CMapInfoP[CMAPREGISTRY].value.data.valueP) != 0 ||
              strcmp(CIDFontP->CIDfontInfoP[CIDORDERING].value.data.valueP,
              CMapP->CMapInfoP[CMAPORDERING].value.data.valueP) != 0) {
              rc = SCAN_ERROR;
              break;
            } else {
              fclose(inputP->data.fileP);
              return(SCAN_OK);
            }
          }
        }
        break;
    }

  }
  while (rc ==0);
  fclose(inputP->data.fileP);
  if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
  return(rc);
}

/*
 * -------------------------------------------------------------------
 *  Scan the next token and convert it into an object
 *  Result is placed on the Operand Stack as next object
 * -------------------------------------------------------------------
 */
int 
scan_cidtype1font(psfont *FontP)
{
  int    i;
  int    begincnt = 0; /* counter for the number of unpaired begin operators */
  int    currentfilefound = 0;

  WantFontInfo  = TRUE;
  InPrivateDict = FALSE;
  TwoSubrs      = FALSE;
  rc = BuildFontInfo(FontP);
  if (rc != 0) return(rc);

  /* Assume everything will be OK */
  rc       = 0;
  filterFile.data.fileP = NULL;

  /* Loop until complete font is read  */
  do {
    /* Scan the next token */
    scan_token(inputP);

    /* ==> tokenLength, tokenTooLong, tokenType, and tokenValue are */
    /* now set */

    switch (tokenType) {
      case TOKEN_EOF:
      case TOKEN_NONE:
      case TOKEN_INVALID:
        /* in this case we are done */
        if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
        rc = SCAN_ERROR;
        break;
      case TOKEN_LITERAL_NAME:
            /* Look up the name */
            tokenStartP[tokenLength] = '\0';
            if (InPrivateDict ) {
              rc = FindDictValue(FontP->Private);
              /* we are not going to report errors */
              /* Sometimes the font file may test a value such as */
              /* testing to see if the font is alreadly loaded with */
              /* same UniqueID.  We would faile on /UniqueID get  */
              /* because we are expecting a int to follow UniqueID*/
              /* If the correct object type does not follow a Name*/
              /* then we will skip over it without reporting error except */
              /* out of memory */
              if (rc != SCAN_OUT_OF_MEMORY)
                rc = SCAN_OK;
              break;
            }   /* end of reading Private dictionary */
            else
              if (0 == strncmp(tokenStartP,"Private",7) ) {
                InPrivateDict = TRUE;
                rc = BuildCIDType1Private(FontP);
                break;
              }
              else
                if (WantFontInfo) {
                  rc = FindDictValue(FontP->fontInfoP);
                  /* we are not going to report errors except out of memory */
                  if (rc != SCAN_OUT_OF_MEMORY)
                    rc = SCAN_OK;
                  break;
                }
        break;
      case TOKEN_NAME:
            if (0 == strncmp(tokenStartP,"currentfile",11)) {
                currentfilefound = 1;
                break;
            } else if (0 == strncmp(tokenStartP,"eexec",5)) {
                if (currentfilefound == 1) {
                    currentfilefound = 0;
                    filterFile.data.fileP = CIDeexec(inputP->data.fileP);
                    if (filterFile.data.fileP == NULL) {
                      fclose(inputFile.data.fileP);
                      return(SCAN_FILE_OPEN_ERROR);
                    }
                    inputP = &filterFile;
                } else {
                    rc = SCAN_ERROR;
                    break;
                }
            } else if (0 == strncmp(tokenStartP,"begin",5)) {
                begincnt++;
                currentfilefound = 0;
            } else if (0 == strncmp(tokenStartP,"end",3)) {
                currentfilefound = 0;
                begincnt--;
                if (begincnt == 0) {
                    if (filterFile.data.fileP != NULL) {
                        scan_token(inputP); /* get 'currentfile' */
                        scan_token(inputP); /* get 'closefile' */
                        inputP = &inputFile;
                        resetDecrypt();
                        inputP->data.fileP->b_cnt =
                            F_BUFSIZ - (inputP->data.fileP->b_ptr -
                            inputP->data.fileP->b_base);
                        if (inputP->data.fileP->b_cnt > 0) {
                            for (i = 0; i < inputP->data.fileP->b_cnt; i++)
                                if (*(inputP->data.fileP->b_ptr + i) == '%')
                                    break;
                            if (i < inputP->data.fileP->b_cnt) {
                                inputP->data.fileP->b_cnt -= i;
                                inputP->data.fileP->b_ptr += i;
                            } else
                                inputP->data.fileP->b_cnt = 0;
                        }
                    }
                    rc = SCAN_OK;
                    return(rc);
                }
                if (begincnt < 0) {
                    rc = SCAN_ERROR;
                    break;
                }
            }
        break;
    }

  }
  while (rc == 0);
  if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
  return(rc);
}
#endif

/*
 * -------------------------------------------------------------------
 *  Scan the next token and convert it into an object
 *  Result is placed on the Operand Stack as next object
 * -------------------------------------------------------------------
 */
int 
scan_font(psfont *FontP)
{
 
 
  char   filename[128];
  char   filetype[3];
  FILE   *fileP;
  char   *nameP;
  int    namelen;
  int    V;
  int    i;
  boolean starthex80;
 
    starthex80 = FALSE;
    filetype[0] = 'r';
    filetype[1] = 'b';
    filetype[2] = '\0';
    /* copy the filename and remove leading or trailing blanks */
    /* point to name and search for leading blanks */
    nameP= FontP->FontFileName.data.nameP;
    namelen  = FontP->FontFileName.len;
    while (nameP[0] == ' ') {
        nameP++;
        namelen--;
    }
    /* now remove any trailing blanks */
    while ((namelen>0) && ( nameP[namelen-1] == ' ')) {
      namelen--;
    }
    strncpy(filename,nameP,namelen);
    filename[namelen] = '\0';
    /* file name is now constructed */
    inputFile.data.fileP = NULL;
    filterFile.data.fileP = NULL;
 
    inputP = &inputFile;
    if ((fileP = T1Open(filename,filetype))) {
      /* get the first byte of file */
      V = _XT1getc(fileP);
      /* if file starts with x'80' then skip next 5 bytes */
      if ( V == 0X80 ) {
        for (i=0;i<5;i++) V = _XT1getc(fileP);
        starthex80 = TRUE;
      }
      else T1Ungetc(V,fileP);
      objFormatFile(inputP,fileP);
    }
    else {
      return(SCAN_FILE_OPEN_ERROR);
    };
 
  WantFontInfo  = TRUE;
  InPrivateDict = FALSE;
  TwoSubrs      = FALSE;
  rc = BuildFontInfo(FontP);
  if (rc != 0) return(rc);
 
  /* Assume everything will be OK */
  rc       = 0;
 
  /* Loop until complete font is read  */
  do {
    /* Scan the next token */
    scan_token(inputP);
 
    /* ==> tokenLength, tokenTooLong, tokenType, and tokenValue are */
    /* now set */
 
    switch (tokenType) {
      case TOKEN_EOF:
      case TOKEN_NONE:
      case TOKEN_INVALID:
        /* in this case we are done */
        if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
        rc = SCAN_ERROR;
        break;
      case TOKEN_LITERAL_NAME:
            /* Look up the name */
            tokenStartP[tokenLength] = '\0';
            if (InPrivateDict ) {
              if (0== strncmp(tokenStartP,"Subrs",5) ) {
                rc = BuildSubrs(FontP);
                break;
              }
              if (0== strncmp(tokenStartP,"CharStrings",11) ) {
                rc = BuildCharStrings(FontP);
                if ( (rc == SCAN_OK) ||(rc == SCAN_END) ) {
                  T1Close(inputP->data.fileP);
                  /* Build the Blues Structure */
                  rc = GetType1Blues(FontP);
                  /* whatever the return code, return it */
                  /* all the work is done. This is the normal exit.*/
                  return(rc);
                }
                break;
              }
              rc = FindDictValue(FontP->Private);
              /* we are not going to report errors */
              /* Sometimes the font file may test a value such as */
              /* testing to see if the font is alreadly loaded with */
              /* same UniqueID.  We would faile on /UniqueID get  */
              /* because we are expecting a int to follow UniqueID*/
              /* If the correct object type does not follow a Name*/
              /* then we will skip over it without reporting error except */
              /* when out of memory */
              if (rc != SCAN_OUT_OF_MEMORY)
                rc = SCAN_OK;
              break;
            }   /* end of reading Private dictionary */
            else
              if (0== strncmp(tokenStartP,"Private",7) ) {
                InPrivateDict = TRUE;
                rc = BuildPrivate(FontP);
                break;
              }
              else
                if (WantFontInfo) {
                  rc = FindDictValue(FontP->fontInfoP);
                  /* we are not going to report errors except out of memory */
                  if (rc != SCAN_OUT_OF_MEMORY)
                    rc = SCAN_OK;
                  break;
                }
        break;
      case TOKEN_NAME:
            if (0 == strncmp(tokenStartP,"eexec",5) ) {
               /* if file started with x'80', check next 5 bytes */
               if (starthex80) {
                 V = _XT1getc(fileP);
                 if ( V == 0X80 ) {
                   for (i=0;i<5;i++) V = _XT1getc(fileP);
                 }
                 else T1Ungetc(V,fileP);
               }
               filterFile.data.fileP = T1eexec(inputP->data.fileP);
               if (filterFile.data.fileP == NULL) {
                 T1Close(inputFile.data.fileP);
                 return(SCAN_FILE_OPEN_ERROR);
               }
               inputP = &filterFile;
 
               WantFontInfo = FALSE;
            }
        break;
    }
 
  }
  while (rc ==0);
  T1Close(inputP->data.fileP);
  if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
  return(rc);
}