Debian Codegraph @

texk/ps2pk/scanfont.c

raw
1 /* $XConsortium: scanfont.c,v 1.9 92/07/07 17:14:56 gildea Exp $ */
2 /* Copyright International Business Machines,Corp. 1991
3 * All Rights Reserved
4 *
5 * License to use, copy, modify, and distribute this software
6 * and its documentation for any purpose and without fee is
7 * hereby granted, provided that the above copyright notice
8 * appear in all copies and that both that copyright notice and
9 * this permission notice appear in supporting documentation,
10 * and that the name of IBM not be used in advertising or
11 * publicity pertaining to distribution of the software without
12 * specific, written prior permission.
13 *
14 * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
15 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
16 * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
18 * THIRD PARTY RIGHTS. THE ENTIRE RISK AS TO THE QUALITY AND
19 * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
20 * OR MAINTAIN, BELONGS TO THE LICENSEE. SHOULD ANY PORTION OF
21 * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
22 * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION. IN
23 * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
24 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
25 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
26 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
27 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
28 * SOFTWARE.
29 */
30 /* Author: Katherine A. Hitchcock IBM Almaden Research Laboratory */
31
32 #include "types.h"
33 #include <string.h>
34
35 #include "t1stdio.h"
36 #include "util.h"
37 #include "token.h"
38 #include "objects.h"
39 #include "spaces.h"
40 #include "fontmisc.h"
41 #include "ffilest.h"
42 #include "fontfcn.h"
43 #include "blues.h"
44
45
46 static int rc;
47 static boolean InPrivateDict;
48 static boolean WantFontInfo;
49 static boolean TwoSubrs;
50 static psobj inputFile;
51 static psobj filterFile;
52 static psobj *inputP;
53
54
55 /**********************************************************************/
56 /* Init_BuiltInEncoding() */
57 /* */
58 /* Initializes the StandardEncoding and ISOLatin1Encoding vector. */
59 /* */
60 /**********************************************************************/
61 typedef struct /* Builtin Standard Encoding */
62 {
63 int index;
64 const char *name;
65 } EncodingTable;
66
67 static EncodingTable StdEnc[] = {
68 { 040 , "space" },
69 { 041 , "exclam" },
70 { 042 , "quotedbl" },
71 { 043 , "numbersign" },
72 { 044 , "dollar" },
73 { 045 , "percent" },
74 { 046 , "ampersand" },
75 { 047 , "quoteright" },
76 { 050 , "parenleft" },
77 { 051 , "parenright" },
78 { 052 , "asterisk" },
79 { 053 , "plus" },
80 { 054 , "comma" },
81 { 055 , "hyphen" },
82 { 056 , "period" },
83 { 057 , "slash" },
84 { 060 , "zero" },
85 { 061 , "one" },
86 { 062 , "two" },
87 { 063 , "three" },
88 { 064 , "four" },
89 { 065 , "five" },
90 { 066 , "six" },
91 { 067 , "seven" },
92 { 070 , "eight" },
93 { 071 , "nine" },
94 { 072 , "colon" },
95 { 073 , "semicolon" },
96 { 074 , "less" },
97 { 075 , "equal" },
98 { 076 , "greater" },
99 { 077 , "question" },
100 { 0100 , "at" },
101 { 0101 , "A" },
102 { 0102 , "B" },
103 { 0103 , "C" },
104 { 0104 , "D" },
105 { 0105 , "E" },
106 { 0106 , "F" },
107 { 0107 , "G" },
108 { 0110 , "H" },
109 { 0111 , "I" },
110 { 0112 , "J" },
111 { 0113 , "K" },
112 { 0114 , "L" },
113 { 0115 , "M" },
114 { 0116 , "N" },
115 { 0117 , "O" },
116 { 0120 , "P" },
117 { 0121 , "Q" },
118 { 0122 , "R" },
119 { 0123 , "S" },
120 { 0124 , "T" },
121 { 0125 , "U" },
122 { 0126 , "V" },
123 { 0127 , "W" },
124 { 0130 , "X" },
125 { 0131 , "Y" },
126 { 0132 , "Z" },
127 { 0133 , "bracketleft" },
128 { 0134 , "backslash" },
129 { 0135 , "bracketright" },
130 { 0136 , "asciicircum" },
131 { 0137 , "underscore" },
132 { 0140 , "quoteleft" },
133 { 0141 , "a" },
134 { 0142 , "b" },
135 { 0143 , "c" },
136 { 0144 , "d" },
137 { 0145 , "e" },
138 { 0146 , "f" },
139 { 0147 , "g" },
140 { 0150 , "h" },
141 { 0151 , "i" },
142 { 0152 , "j" },
143 { 0153 , "k" },
144 { 0154 , "l" },
145 { 0155 , "m" },
146 { 0156 , "n" },
147 { 0157 , "o" },
148 { 0160 , "p" },
149 { 0161 , "q" },
150 { 0162 , "r" },
151 { 0163 , "s" },
152 { 0164 , "t" },
153 { 0165 , "u" },
154 { 0166 , "v" },
155 { 0167 , "w" },
156 { 0170 , "x" },
157 { 0171 , "y" },
158 { 0172 , "z" },
159 { 0173 , "braceleft" },
160 { 0174 , "bar" },
161 { 0175 , "braceright" },
162 { 0176 , "asciitilde" },
163 { 0241 , "exclamdown" },
164 { 0242 , "cent" },
165 { 0243 , "sterling" },
166 { 0244 , "fraction" },
167 { 0245 , "yen" },
168 { 0246 , "florin" },
169 { 0247 , "section" },
170 { 0250 , "currency" },
171 { 0251 , "quotesingle" },
172 { 0252 , "quotedblleft" },
173 { 0253 , "guillemotleft" },
174 { 0254 , "guilsinglleft" },
175 { 0255 , "guilsinglright" },
176 { 0256 , "fi" },
177 { 0257 , "fl" },
178 { 0261 , "endash" },
179 { 0262 , "dagger" },
180 { 0263 , "daggerdbl" },
181 { 0264 , "periodcentered" },
182 { 0266 , "paragraph" },
183 { 0267 , "bullet" },
184 { 0270 , "quotesinglbase" },
185 { 0271 , "quotedblbase" },
186 { 0272 , "quotedblright" },
187 { 0273 , "guillemotright" },
188 { 0274 , "ellipsis" },
189 { 0275 , "perthousand" },
190 { 0277 , "questiondown" },
191 { 0301 , "grave" },
192 { 0302 , "acute" },
193 { 0303 , "circumflex" },
194 { 0304 , "tilde" },
195 { 0305 , "macron" },
196 { 0306 , "breve" },
197 { 0307 , "dotaccent" },
198 { 0310 , "dieresis" },
199 { 0312 , "ring" },
200 { 0313 , "cedilla" },
201 { 0315 , "hungarumlaut" },
202 { 0316 , "ogonek" },
203 { 0317 , "caron" },
204 { 0320 , "emdash" },
205 { 0341 , "AE" },
206 { 0343 , "ordfeminine" },
207 { 0350 , "Lslash" },
208 { 0351 , "Oslash" },
209 { 0352 , "OE" },
210 { 0353 , "ordmasculine" },
211 { 0361 , "ae" },
212 { 0365 , "dotlessi" },
213 { 0370 , "lslash" },
214 { 0371 , "oslash" },
215 { 0372 , "oe" },
216 { 0373 , "germandbls" },
217 { 0, 0 }
218 };
219
220 static EncodingTable ISO8859Enc[] = {
221 { 32, "space" },
222 { 33, "exclam" },
223 { 34, "quotedbl" },
224 { 35, "numbersign" },
225 { 36, "dollar" },
226 { 37, "percent" },
227 { 38, "ampersand" },
228 { 39, "quoteright" },
229 { 40, "parenleft" },
230 { 41, "parenright" },
231 { 42, "asterisk" },
232 { 43, "plus" },
233 { 44, "comma" },
234 { 45, "minus" },
235 { 46, "period" },
236 { 47, "slash" },
237 { 48, "zero" },
238 { 49, "one" },
239 { 50, "two" },
240 { 51, "three" },
241 { 52, "four" },
242 { 53, "five" },
243 { 54, "six" },
244 { 55, "seven" },
245 { 56, "eight" },
246 { 57, "nine" },
247 { 58, "colon" },
248 { 59, "semicolon" },
249 { 60, "less" },
250 { 61, "equal" },
251 { 62, "greater" },
252 { 63, "question" },
253 { 64, "at" },
254 { 65, "A" },
255 { 66, "B" },
256 { 67, "C" },
257 { 68, "D" },
258 { 69, "E" },
259 { 70, "F" },
260 { 71, "G" },
261 { 72, "H" },
262 { 73, "I" },
263 { 74, "J" },
264 { 75, "K" },
265 { 76, "L" },
266 { 77, "M" },
267 { 78, "N" },
268 { 79, "O" },
269 { 80, "P" },
270 { 81, "Q" },
271 { 82, "R" },
272 { 83, "S" },
273 { 84, "T" },
274 { 85, "U" },
275 { 86, "V" },
276 { 87, "W" },
277 { 88, "X" },
278 { 89, "Y" },
279 { 90, "Z" },
280 { 91, "bracketleft" },
281 { 92, "backslash" },
282 { 93, "bracketright" },
283 { 94, "asciicircum" },
284 { 95, "underscore" },
285 { 96, "quoteleft" },
286 { 97, "a" },
287 { 98, "b" },
288 { 99, "c" },
289 { 100, "d" },
290 { 101, "e" },
291 { 102, "f" },
292 { 103, "g" },
293 { 104, "h" },
294 { 105, "i" },
295 { 106, "j" },
296 { 107, "k" },
297 { 108, "l" },
298 { 109, "m" },
299 { 110, "n" },
300 { 111, "o" },
301 { 112, "p" },
302 { 113, "q" },
303 { 114, "r" },
304 { 115, "s" },
305 { 116, "t" },
306 { 117, "u" },
307 { 118, "v" },
308 { 119, "w" },
309 { 120, "x" },
310 { 121, "y" },
311 { 122, "z" },
312 { 123, "braceleft" },
313 { 124, "bar" },
314 { 125, "braceright" },
315 { 126, "asciitilde" },
316 { 161, "exclamdown" },
317 { 162, "cent" },
318 { 163, "sterling" },
319 { 164, "currency" },
320 { 165, "yen" },
321 { 166, "brokenbar" },
322 { 167, "section" },
323 { 168, "dieresis" },
324 { 169, "copyright" },
325 { 170, "ordfeminine" },
326 { 171, "guillemotleft" },
327 { 172, "logicalnot" },
328 { 173, "hyphen" },
329 { 174, "registered" },
330 { 175, "macron" },
331 { 176, "degree" },
332 { 177, "plusminus" },
333 { 178, "twosuperior" },
334 { 179, "threesuperior" },
335 { 180, "acute" },
336 { 181, "mu" },
337 { 182, "paragraph" },
338 { 183, "periodcentered" },
339 { 184, "cedilla" },
340 { 185, "onesuperior" },
341 { 186, "ordmasculine" },
342 { 187, "guillemotright" },
343 { 188, "onequarter" },
344 { 189, "onehalf" },
345 { 190, "threequarters" },
346 { 191, "questiondown" },
347 { 192, "Agrave" },
348 { 193, "Aacute" },
349 { 194, "Acircumflex" },
350 { 195, "Atilde" },
351 { 196, "Adieresis" },
352 { 197, "Aring" },
353 { 198, "AE" },
354 { 199, "Ccedilla" },
355 { 200, "Egrave" },
356 { 201, "Eacute" },
357 { 202, "Ecircumflex" },
358 { 203, "Edieresis" },
359 { 204, "Igrave" },
360 { 205, "Iacute" },
361 { 206, "Icircumflex" },
362 { 207, "Idieresis" },
363 { 208, "Eth" },
364 { 209, "Ntilde" },
365 { 210, "Ograve" },
366 { 211, "Oacute" },
367 { 212, "Ocircumflex" },
368 { 213, "Otilde" },
369 { 214, "Odieresis" },
370 { 215, "multiply" },
371 { 216, "Oslash" },
372 { 217, "Ugrave" },
373 { 218, "Uacute" },
374 { 219, "Ucircumflex" },
375 { 220, "Udieresis" },
376 { 221, "Yacute" },
377 { 222, "Thorn" },
378 { 223, "germandbls" },
379 { 224, "agrave" },
380 { 225, "aacute" },
381 { 226, "acircumflex" },
382 { 227, "atilde" },
383 { 228, "adieresis" },
384 { 229, "aring" },
385 { 230, "ae" },
386 { 231, "ccedilla" },
387 { 232, "egrave" },
388 { 233, "eacute" },
389 { 234, "ecircumflex" },
390 { 235, "edieresis" },
391 { 236, "igrave" },
392 { 237, "iacute" },
393 { 238, "icircumflex" },
394 { 239, "idieresis" },
395 { 240, "eth" },
396 { 241, "ntilde" },
397 { 242, "ograve" },
398 { 243, "oacute" },
399 { 244, "ocircumflex" },
400 { 245, "otilde" },
401 { 246, "odieresis" },
402 { 247, "divide" },
403 { 248, "oslash" },
404 { 249, "ugrave" },
405 { 250, "uacute" },
406 { 251, "ucircumflex" },
407 { 252, "udieresis" },
408 { 253, "yacute" },
409 { 254, "thorn" },
410 { 255, "ydieresis" },
411 { 0, 0 }
412 };
413
414 static psobj *StdEncArrayP = NULL;
415 psobj *ISOLatin1EncArrayP = NULL;
416
417 static psobj *MakeEncodingArrayP(EncodingTable *encodingTable)
418 {
419 int i;
420 psobj *encodingArrayP;
421
422 encodingArrayP = (psobj *)vm_alloc(256*(sizeof(psobj)));
423 if (!encodingArrayP)
424 return NULL;
425
426 /* initialize everything to .notdef */
427 for (i=0; i<256;i++)
428 objFormatName(&(encodingArrayP[i]),7, ".notdef");
429
430 for (i=0; encodingTable[i].name; i++)
431 {
432 objFormatName(&(encodingArrayP[encodingTable[i].index]),
433 strlen(encodingTable[i].name),
434 encodingTable[i].name);
435 }
436
437 return(encodingArrayP);
438 }
439
440 boolean Init_BuiltInEncoding(void)
441 {
442 StdEncArrayP = MakeEncodingArrayP(StdEnc);
443 ISOLatin1EncArrayP = MakeEncodingArrayP(ISO8859Enc);
444 return (StdEncArrayP && ISOLatin1EncArrayP);
445 }
446
447 /********************************************************************/
448 /***================================================================***/
449 static int getNextValue(int valueType)
450 {
451 scan_token(inputP);
452 if (tokenType != valueType) {
453 return(SCAN_ERROR);
454 }
455 return(SCAN_OK);
456
457 }
458 /***================================================================***/
459 /* This routine will set the global rc if there is an error */
460 /***================================================================***/
461 static int getInt(void)
462 {
463 scan_token(inputP);
464 if (tokenType != TOKEN_INTEGER) {
465 rc = SCAN_ERROR;
466 return(0);
467 }
468 else {
469 return( tokenValue.integer);
470 }
471
472 }
473 /***================================================================***/
474 /*
475 * See Sec 10.3 of ``Adobe Type 1 Font Format'' v1.1,
476 * for parsing Encoding.
477 */
478 static int getEncoding(psobj *arrayP)
479 {
480
481 scan_token(inputP);
482 if ((tokenType == TOKEN_NAME)
483 &&
484 (((tokenLength==16) && (!strncmp(tokenStartP,"StandardEncoding",16))) ||
485 (((tokenLength==17) && (!strncmp(tokenStartP,"ISOLatin1Encoding",17))))))
486 {
487 /* Adobe Standard Encoding */
488
489 if (tokenLength == 16)
490 arrayP->data.valueP = (char *) StdEncArrayP;
491 else
492 arrayP->data.valueP = (char *) ISOLatin1EncArrayP;
493
494 arrayP->len = 256;
495 return(SCAN_OK);
496 }
497 else if ( (tokenType == TOKEN_LEFT_BRACE) ||
498 (tokenType == TOKEN_LEFT_BRACKET) )
499 {
500 /* Array of literal names */
501
502 psobj *objP;
503 int i;
504
505 objP = (psobj *)vm_alloc(256*(sizeof(psobj)));
506 if (!(objP)) return(SCAN_OUT_OF_MEMORY);
507
508 arrayP->data.valueP = (char *) objP;
509 arrayP->len = 256;
510
511 for (i=0; i<256; i++, objP++)
512 {
513 scan_token(inputP);
514
515 if (tokenType != TOKEN_LITERAL_NAME)
516 return(SCAN_ERROR);
517
518 if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY);
519 objFormatName(objP,tokenLength,tokenStartP);
520 }
521
522 scan_token(inputP);
523 if ( (tokenType == TOKEN_RIGHT_BRACE) ||
524 (tokenType == TOKEN_RIGHT_BRACKET) )
525 return(SCAN_OK);
526 }
527 else
528 {
529 /* Must be sequences of ``dup <index> <charactername> put" */
530
531 psobj *objP;
532 int i;
533
534 objP = (psobj *)vm_alloc(256*(sizeof(psobj)));
535 if (!(objP)) return(SCAN_OUT_OF_MEMORY);
536
537 arrayP->data.valueP = (char *) objP;
538 arrayP->len = 256;
539
540 for (i=0; i<256; i++)
541 objFormatName(objP + i, 7, ".notdef");
542
543 while (TRUE)
544 {
545 scan_token(inputP);
546
547 switch (tokenType)
548 {
549 case TOKEN_NAME:
550 if (tokenLength == 3)
551 {
552 if (strncmp(tokenStartP,"dup",3) == 0)
553 {
554 /* get <index> */
555 scan_token(inputP);
556 if (tokenType != TOKEN_INTEGER ||
557 tokenValue.integer < 0 ||
558 tokenValue.integer > 255)
559 return (SCAN_ERROR);
560 i = tokenValue.integer;
561
562 /* get <characer_name> */
563 scan_token(inputP);
564 if (tokenType != TOKEN_LITERAL_NAME)
565 return(SCAN_ERROR);
566
567 if (!(vm_alloc(tokenLength)) )
568 return(SCAN_OUT_OF_MEMORY);
569 objFormatName(objP + i,tokenLength,tokenStartP);
570
571 /* get "put" */
572 scan_token(inputP);
573 if (tokenType != TOKEN_NAME)
574 return(SCAN_ERROR);
575 }
576 else if (strncmp(tokenStartP,"def",3) == 0)
577 return (SCAN_OK);
578 }
579 break;
580 case TOKEN_EOF:
581 case TOKEN_NONE:
582 case TOKEN_INVALID:
583 return (SCAN_ERROR);
584 }
585 }
586 }
587
588 return (SCAN_ERROR);
589 }
590 /***================================================================***/
591 static int getArray(psobj *arrayP)
592 {
593 int N; /* count the items in the array */
594 psobj *objP;
595
596
597 scan_token(inputP);
598 if ( (tokenType != TOKEN_LEFT_BRACE) &&
599 (tokenType != TOKEN_LEFT_BRACKET) ) {
600 return(SCAN_ERROR);
601 }
602 /* format the array in memory, save pointer to the beginning */
603 arrayP->data.valueP = tokenStartP;
604 /* loop, picking up next object, until right BRACE or BRACKET */
605 N = 0;
606 do {
607 scan_token(inputP);
608 if ( (tokenType == TOKEN_RIGHT_BRACE) ||
609 (tokenType == TOKEN_RIGHT_BRACKET) ) {
610 /* save then number of items in the array */
611 arrayP->len = N;
612 return(SCAN_OK);
613 }
614 /* allocate the space for the object */
615 objP = (psobj *)vm_alloc(sizeof(psobj));
616 if (!(objP)) return(SCAN_OUT_OF_MEMORY);
617
618 /* array is an array of numbers, (real or integer) */
619 if (tokenType == TOKEN_REAL) {
620 objFormatReal(objP, tokenValue.real);
621 }
622 else
623 if (tokenType == TOKEN_INTEGER) {
624 objFormatInteger(objP, tokenValue.integer);
625 }
626 else return(SCAN_ERROR);
627 N++;
628 } while ( 1>0 );
629 /* NOTREACHED*/
630 }
631 /***================================================================***/
632 static int getName(const char *nameP)
633 {
634 do {
635 scan_token(inputP);
636 if (tokenType <= TOKEN_NONE) {
637 if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
638 return(SCAN_ERROR);
639 }
640 } while ((tokenType != TOKEN_NAME) ||
641 (0 != strncmp(tokenStartP,nameP,strlen(nameP))) );
642 /* found */
643 return(SCAN_OK);
644 }
645 /***================================================================***/
646 static int getNbytes(int N)
647 {
648 int I;
649
650 if (N > vm_free_bytes()) {
651 if (!vm_init()) return(SCAN_OUT_OF_MEMORY);
652 }
653 tokenStartP = vm_next_byte();
654 I = fread(tokenStartP,1,N,inputP->data.fileP);
655 if ( I != N ) return(SCAN_FILE_EOF);
656 return(SCAN_OK);
657 }
658
659 /***================================================================***/
660 /* getLiteralName(nameObjP) */
661 /* scan for next literal. */
662 /* if we encounter the name 'end' then terminate and say ok. */
663 /* It means that the CharStrings does not have as many characters */
664 /* as the dictionary said it would and that is ok. */
665 /***================================================================***/
666 static int getLiteralName(psobj *nameObjP)
667 {
668 do {
669 scan_token(inputP);
670 if (tokenType <= TOKEN_NONE) {
671 if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
672 return(SCAN_ERROR);
673 }
674 if (tokenType == TOKEN_NAME) {
675 if (0 == strncmp(tokenStartP,"end",3) ) {
676 return(SCAN_END);
677 }
678 }
679 } while (tokenType != TOKEN_LITERAL_NAME) ;
680 nameObjP->len = tokenLength;
681 /* allocate all the names in the CharStrings Structure */
682 if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY);
683 nameObjP->data.valueP = tokenStartP;
684 /* found */
685 return(SCAN_OK);
686 }
687
688 /***================================================================***/
689 /*
690 * BuildSubrs routine
691 */
692 /***================================================================***/
693
694 static int BuildSubrs(psfont *FontP)
695 {
696 int N; /* number of values in Subrs */
697 int I; /* index into Subrs */
698 int i; /* loop thru Subrs */
699 int J; /* length of Subrs entry */
700 psobj *arrayP;
701
702 /* next token should be a positive int */
703 /* note: rc is set by getInt. */
704 N = getInt();
705 if (rc) return(rc);
706 if (N < 0 ) return(SCAN_ERROR);
707 /* if we already have a Subrs, then skip the second one */
708 /* The second one is for hiresolution devices. */
709 if (FontP->Subrs.data.arrayP != NULL) {
710 TwoSubrs = TRUE;
711 /* process all the Subrs, but do not update anything */
712 /* can not just skip them because of the binary data */
713 for (i=0;i<N;i++) {
714 /* look for dup */
715 rc = getName("dup");
716 if (rc) return(rc);
717 /* get 2 integers */
718 I = getInt();
719 if (rc) return(rc);
720 J = getInt();
721 if (rc) return(rc);
722 if ( (I < 0) || (J < 0 ) ) return (SCAN_ERROR);
723 /* get the next token, it should be RD or -|, either is ok */
724 rc = getNextValue(TOKEN_NAME);
725 if ( rc != SCAN_OK ) return(rc);
726 rc = getNbytes(J);
727 if (rc) return(rc);
728 }
729 return(SCAN_OK);
730 }
731
732 arrayP = (psobj *)vm_alloc(N*sizeof(psobj));
733 if (!(arrayP) ) return(SCAN_OUT_OF_MEMORY);
734 FontP->Subrs.len = N;
735 FontP->Subrs.data.arrayP = arrayP;
736 /* get N values for Subrs */
737 for (i=0;i<N;i++) {
738 /* look for dup */
739 rc = getName("dup");
740 if (rc) return(rc);
741 /* get 2 integers */
742 I = getInt();
743 if (rc) return(rc);
744 J = getInt();
745 if (rc) return(rc);
746 if ( (I < 0) || (J < 0 ) ) return (SCAN_ERROR);
747 arrayP[I].len = J;
748 /* get the next token, it should be RD or -|, either is ok */
749 rc = getNextValue(TOKEN_NAME);
750 if ( rc != SCAN_OK ) return(rc);
751 rc = getNbytes(J);
752 if (rc == SCAN_OK) {
753 arrayP[I].data.valueP = tokenStartP;
754 if ( !(vm_alloc(J)) ) return(SCAN_OUT_OF_MEMORY);
755 }
756 else return(rc);
757 }
758 return(SCAN_OK);
759
760 }
761 /***================================================================***/
762 /***================================================================***/
763 /*
764 * BuildCharStrings routine
765 */
766 /***================================================================***/
767
768 static int BuildCharStrings(psfont *FontP)
769 {
770 int N; /* number of values in CharStrings */
771 int i; /* loop thru Subrs */
772 int J; /* length of Subrs entry */
773 psdict *dictP;
774
775 /* next token should be a positive int */
776 N = getInt();
777 if (rc) {
778 /* check if file had TwoSubrs, hi resolution stuff is in file*/
779 if (TwoSubrs) {
780 do {
781 scan_token(inputP);
782 if (tokenType <= TOKEN_NONE) {
783 if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
784 return(SCAN_ERROR);
785 }
786 } while (tokenType != TOKEN_INTEGER);
787 N = tokenValue.integer;
788 }
789 else return(rc); /* if next token was not an Int */
790 }
791 if (N<=0) return(SCAN_ERROR);
792 /* save number of entries in the dictionary */
793
794 dictP = (psdict *)vm_alloc((N+1)*sizeof(psdict));
795 if (!(dictP)) return(SCAN_OUT_OF_MEMORY);
796 FontP->CharStringsP = dictP;
797 dictP[0].key.len = N;
798 /* get N values for CharStrings */
799 for (i=1;i<=N;i++) {
800 /* look for next literal name */
801 rc = getLiteralName(&(dictP[i].key));
802 if (rc) return(rc);
803 /* get 1 integer */
804 J = getInt();
805 if (rc) return(rc); /* if next token was not an Int */
806 if (J<0) return (SCAN_ERROR);
807 dictP[i].value.len = J;
808 /* get the next token, it should be RD or -|, either is ok */
809 rc = getNextValue(TOKEN_NAME);
810 if ( rc != SCAN_OK ) return(rc);
811 rc = getNbytes(J);
812 if (rc == SCAN_OK) {
813 dictP[i].value.data.valueP = tokenStartP;
814 if ( !(vm_alloc(J)) ) return(SCAN_OUT_OF_MEMORY);
815 }
816 else return(rc);
817 }
818 return(SCAN_OK);
819
820 }
821 /***================================================================***/
822 /***================================================================***/
823 /*
824 * BuildFontInfo Dictionary
825 */
826 /***================================================================***/
827 static int BuildFontInfo(psfont *fontP)
828 {
829 psdict *dictP;
830
831 /* allocate the private dictionary */
832 dictP = (psdict *)vm_alloc(20*sizeof(psdict));
833 if (!(dictP)) return(SCAN_OUT_OF_MEMORY);
834
835 fontP->fontInfoP = dictP;
836 fontP->fontInfoP[0].key.len = 17; /* number of actual entries */
837 objFormatName(&(dictP[FONTNAME].key),8,"FontName");
838 objFormatName(&(dictP[FONTNAME].value),0,NULL);
839 objFormatName(&(dictP[PAINTTYPE].key),9,"PaintType");
840 objFormatInteger(&(dictP[PAINTTYPE].value),0);
841 objFormatName(&(dictP[FONTTYPENUM].key),8,"FontType");
842 objFormatInteger(&(dictP[FONTTYPENUM].value),0);
843 objFormatName(&(dictP[FONTMATRIX].key),10,"FontMatrix");
844 objFormatArray(&(dictP[FONTMATRIX].value),0,NULL);
845 objFormatName(&(dictP[FONTBBOX].key),8,"FontBBox");
846 objFormatArray(&(dictP[FONTBBOX].value),0,NULL);
847 objFormatName(&(dictP[ENCODING].key),8,"Encoding");
848 objFormatEncoding(&(dictP[ENCODING].value),0,NULL);
849 objFormatName(&(dictP[UNIQUEID].key),8,"UniqueID");
850 objFormatInteger(&(dictP[UNIQUEID].value),0);
851 objFormatName(&(dictP[STROKEWIDTH].key),11,"StrokeWidth");
852 objFormatReal(&(dictP[STROKEWIDTH].value),0.0);
853 objFormatName(&(dictP[VERSION].key),7,"version");
854 objFormatString(&(dictP[VERSION].value),0,NULL);
855 objFormatName(&(dictP[NOTICE].key),6,"Notice");
856 objFormatString(&(dictP[NOTICE].value),0,NULL);
857 objFormatName(&(dictP[FULLNAME].key),8,"FullName");
858 objFormatString(&(dictP[FULLNAME].value),0,NULL);
859 objFormatName(&(dictP[FAMILYNAME].key),10,"FamilyName");
860 objFormatString(&(dictP[FAMILYNAME].value),0,NULL);
861 objFormatName(&(dictP[WEIGHT].key),6,"Weight");
862 objFormatString(&(dictP[WEIGHT].value),0,NULL);
863 objFormatName(&(dictP[ITALICANGLE].key),11,"ItalicAngle");
864 objFormatReal(&(dictP[ITALICANGLE].value),0.0);
865 objFormatName(&(dictP[ISFIXEDPITCH].key),12,"isFixedPitch");
866 objFormatBoolean(&(dictP[ISFIXEDPITCH].value),FALSE);
867 objFormatName(&(dictP[UNDERLINEPOSITION].key),17,"UnderlinePosition");
868 objFormatReal(&(dictP[UNDERLINEPOSITION].value),0.0);
869 objFormatName(&(dictP[UNDERLINETHICKNESS].key),18,"UnderlineThickness");
870 objFormatReal(&(dictP[UNDERLINETHICKNESS].value),0.0);
871 return(SCAN_OK);
872 }
873 /***================================================================***/
874 /*
875 * BuildPrivate Dictionary
876 */
877 /***================================================================***/
878 static int BuildPrivate(psfont *fontP)
879 {
880 psdict *Private;
881
882 /* allocate the private dictionary */
883 Private = (psdict *)vm_alloc(20*sizeof(psdict));
884
885 if (!(Private)) return(SCAN_OUT_OF_MEMORY);
886
887 fontP->Private = Private;
888 fontP->Private[0].key.len = 16; /* number of actual entries */
889
890 objFormatName(&(Private[BLUEVALUES].key),10,"BlueValues");
891 objFormatArray(&(Private[BLUEVALUES].value),0,NULL);
892 objFormatName(&(Private[OTHERBLUES].key),10,"OtherBlues");
893 objFormatArray(&(Private[OTHERBLUES].value),0,NULL);
894 objFormatName(&(Private[FAMILYBLUES].key),11,"FamilyBlues");
895 objFormatArray(&(Private[FAMILYBLUES].value),0,NULL);
896 objFormatName(&(Private[FAMILYOTHERBLUES].key),16,"FamilyOtherBlues");
897 objFormatArray(&(Private[FAMILYOTHERBLUES].value),0,NULL);
898 objFormatName(&(Private[BLUESCALE].key),9,"BlueScale");
899 objFormatReal(&(Private[BLUESCALE].value),DEFAULTBLUESCALE);
900 objFormatName(&(Private[BLUESHIFT].key),9,"BlueShift");
901 objFormatInteger(&(Private[BLUESHIFT].value),DEFAULTBLUESHIFT);
902 objFormatName(&(Private[BLUEFUZZ].key),8,"BlueFuzz");
903 objFormatInteger(&(Private[BLUEFUZZ].value),DEFAULTBLUEFUZZ);
904 objFormatName(&(Private[STDHW].key),5,"StdHW");
905 objFormatArray(&(Private[STDHW].value),0,NULL);
906 objFormatName(&(Private[STDVW].key),5,"StdVW");
907 objFormatArray(&(Private[STDVW].value),0,NULL);
908 objFormatName(&(Private[STEMSNAPH].key),9,"StemSnapH");
909 objFormatArray(&(Private[STEMSNAPH].value),0,NULL);
910 objFormatName(&(Private[STEMSNAPV].key),9,"StemSnapV");
911 objFormatArray(&(Private[STEMSNAPV].value),0,NULL);
912 objFormatName(&(Private[FORCEBOLD].key),9,"ForceBold");
913 objFormatBoolean(&(Private[FORCEBOLD].value),DEFAULTFORCEBOLD);
914 objFormatName(&(Private[LANGUAGEGROUP].key),13,"LanguageGroup");
915 objFormatInteger(&(Private[LANGUAGEGROUP].value),DEFAULTLANGUAGEGROUP);
916 objFormatName(&(Private[LENIV].key),5,"LenIV");
917 objFormatInteger(&(Private[LENIV].value),DEFAULTLENIV);
918 objFormatName(&(Private[RNDSTEMUP].key),9,"RndStemUp");
919 objFormatBoolean(&(Private[RNDSTEMUP].value),DEFAULTRNDSTEMUP);
920 objFormatName(&(Private[EXPANSIONFACTOR].key),9,"ExpansionFactor");
921 objFormatReal(&(Private[EXPANSIONFACTOR].value),
922 DEFAULTEXPANSIONFACTOR);
923 return(SCAN_OK);
924 }
925 /***================================================================***/
926 /**********************************************************************/
927 /* GetType1Blues(fontP) */
928 /* */
929 /* Routine to support font-level hints. */
930 /* */
931 /* Gets all the Blues information from the Private dictionary */
932 /* for the font. */
933 /* */
934 /* */
935 /**********************************************************************/
936 static int GetType1Blues(psfont *fontP)
937 {
938 psdict *PrivateDictP; /* the Private dict relating to hints */
939 struct blues_struct *blues; /* ptr for the blues struct we will allocate */
940 int i;
941 psobj *HintEntryP;
942
943
944
945 /* get the Private dictionary pointer */
946 PrivateDictP = fontP->Private;
947
948 /* allocate the memory for the blues structure */
949 blues = (struct blues_struct *) vm_alloc(sizeof(struct blues_struct));
950
951 if (!blues) return(SCAN_OUT_OF_MEMORY);
952
953 /* Make fontP's blues ptr point to this newly allocated structure. */
954 fontP->BluesP = blues;
955
956 /* fill in the BlueValues array */
957 HintEntryP = &(PrivateDictP[BLUEVALUES].value);
958 /* check to see if the entry exists and if it's an array */
959 if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
960 blues->numBlueValues = 0;
961 else {
962 /* get the number of values in the array */
963 if (HintEntryP->len > NUMBLUEVALUES) {
964 blues->numBlueValues = NUMBLUEVALUES;
965 } else
966 blues->numBlueValues = HintEntryP->len;
967 for (i = 0; i<= blues->numBlueValues-1; ++i) {
968 if (objPIsInteger(&HintEntryP->data.arrayP[i]))
969 blues->BlueValues[i] =
970 HintEntryP->data.arrayP[i].data.integer;
971 else if (objPIsReal(&HintEntryP->data.arrayP[i]))
972 blues->BlueValues[i] =
973 HintEntryP->data.arrayP[i].data.real;
974 else
975 blues->BlueValues[i] = 0;
976 }
977 }
978
979 /* fill in the OtherBlues array */
980 HintEntryP = &(PrivateDictP[OTHERBLUES].value);
981 /* check to see if the entry exists and if it's an array */
982 if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
983 blues->numOtherBlues = 0;
984 else {
985 /* get the number of values in the array */
986 if (HintEntryP->len > NUMOTHERBLUES) {
987 blues->numOtherBlues = NUMOTHERBLUES;
988 } else
989 blues->numOtherBlues = HintEntryP->len;
990 for (i = 0; i<= blues->numOtherBlues-1; ++i) {
991 if (objPIsInteger(&HintEntryP->data.arrayP[i]))
992 blues->OtherBlues[i] =
993 HintEntryP->data.arrayP[i].data.integer;
994 else if (objPIsReal(&HintEntryP->data.arrayP[i]))
995 blues->OtherBlues[i] =
996 HintEntryP->data.arrayP[i].data.real;
997 else
998 blues->OtherBlues[i] = 0;
999 }
1000 }
1001
1002 /* fill in the FamilyBlues array */
1003 HintEntryP = &(PrivateDictP[FAMILYBLUES].value);
1004 /* check to see if the entry exists and if it's an array */
1005 if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
1006 blues->numFamilyBlues = 0;
1007 else {
1008 /* get the number of values in the array */
1009 if (HintEntryP->len > NUMFAMILYBLUES) {
1010 blues->numFamilyBlues = NUMFAMILYBLUES;
1011 } else
1012 blues->numFamilyBlues = HintEntryP->len;
1013 for (i = 0; i<= blues->numFamilyBlues-1; ++i) {
1014 if (objPIsInteger(&HintEntryP->data.arrayP[i]))
1015 blues->FamilyBlues[i] =
1016 HintEntryP->data.arrayP[i].data.integer;
1017 else if (objPIsReal(&HintEntryP->data.arrayP[i]))
1018 blues->FamilyBlues[i] =
1019 HintEntryP->data.arrayP[i].data.real;
1020 else
1021 blues->FamilyBlues[i] = 0;
1022 }
1023 }
1024
1025 /* fill in the FamilyOtherBlues array */
1026 HintEntryP = &(PrivateDictP[FAMILYOTHERBLUES].value);
1027 /* check to see if the entry exists and if it's an array */
1028 if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
1029 blues->numFamilyOtherBlues = 0;
1030 else {
1031 /* get the number of values in the array */
1032 if (HintEntryP->len > NUMFAMILYOTHERBLUES) {
1033 blues->numFamilyOtherBlues = NUMFAMILYOTHERBLUES;
1034 } else
1035 blues->numFamilyOtherBlues = HintEntryP->len;
1036 for (i = 0; i<= blues->numFamilyOtherBlues-1; ++i) {
1037 if (objPIsInteger(&HintEntryP->data.arrayP[i]))
1038 blues->FamilyOtherBlues[i] =
1039 HintEntryP->data.arrayP[i].data.integer;
1040 else if (objPIsReal(&HintEntryP->data.arrayP[i]))
1041 blues->FamilyOtherBlues[i] =
1042 HintEntryP->data.arrayP[i].data.real;
1043 else
1044 blues->FamilyOtherBlues[i] = 0;
1045 }
1046 }
1047
1048 /* fill in the StemSnapH array */
1049 HintEntryP = &(PrivateDictP[STEMSNAPH].value);
1050 /* check to see if the entry exists and if it's an array */
1051 if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
1052 blues->numStemSnapH = 0;
1053 else {
1054 /* get the number of values in the array */
1055 if (HintEntryP->len > NUMSTEMSNAPH) {
1056 blues->numStemSnapH = NUMSTEMSNAPH;
1057 } else
1058 blues->numStemSnapH = HintEntryP->len;
1059 for (i = 0; i<= blues->numStemSnapH-1; ++i) {
1060 if (objPIsInteger(&HintEntryP->data.arrayP[i]))
1061 blues->StemSnapH[i] =
1062 HintEntryP->data.arrayP[i].data.integer;
1063 else if (objPIsReal(&HintEntryP->data.arrayP[i]))
1064 blues->StemSnapH[i] =
1065 HintEntryP->data.arrayP[i].data.real;
1066 else
1067 blues->StemSnapH[i] = 0;
1068 }
1069 }
1070
1071 /* fill in the StemSnapV array */
1072 HintEntryP = &(PrivateDictP[STEMSNAPV].value);
1073 /* check to see if the entry exists and if it's an array */
1074 if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
1075 blues->numStemSnapV = 0;
1076 else {
1077 /* get the number of values in the array */
1078 if (HintEntryP->len > NUMSTEMSNAPV) {
1079 blues->numStemSnapV = NUMSTEMSNAPV;
1080 } else
1081 blues->numStemSnapV = HintEntryP->len;
1082 for (i = 0; i<= blues->numStemSnapV-1; ++i) {
1083 if (objPIsInteger(&HintEntryP->data.arrayP[i]))
1084 blues->StemSnapV[i] =
1085 HintEntryP->data.arrayP[i].data.integer;
1086 else if (objPIsReal(&HintEntryP->data.arrayP[i]))
1087 blues->StemSnapV[i] =
1088 HintEntryP->data.arrayP[i].data.real;
1089 else
1090 blues->StemSnapV[i] = 0;
1091 }
1092 }
1093
1094 /* fill in the StdVW array */
1095 HintEntryP = &(PrivateDictP[STDVW].value);
1096 /* check to see if the entry exists and if it's an array */
1097 if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
1098 /* a value of zero signifies no entry */
1099 blues->StdVW = 0;
1100 else {
1101 if (HintEntryP->len > NUMSTDVW) {
1102 }
1103 if (objPIsInteger(&HintEntryP->data.arrayP[0]))
1104 blues->StdVW = HintEntryP->data.arrayP[0].data.integer;
1105 else if (objPIsReal(&HintEntryP->data.arrayP[0]))
1106 blues->StdVW = HintEntryP->data.arrayP[0].data.real;
1107 else
1108 blues->StdVW = 0;
1109 }
1110
1111 /* fill in the StdHW array */
1112 HintEntryP = &(PrivateDictP[STDHW].value);
1113 /* check to see if the entry exists and if it's an array */
1114 if ( !objPIsArray(HintEntryP) || (HintEntryP->len == 0 ))
1115 /* a value of zero signifies no entry */
1116 blues->StdHW = 0;
1117 else {
1118 if (HintEntryP->len > NUMSTDHW) {
1119 }
1120 if (objPIsInteger(&HintEntryP->data.arrayP[0]))
1121 blues->StdHW = HintEntryP->data.arrayP[0].data.integer;
1122 else if (objPIsReal(&HintEntryP->data.arrayP[0]))
1123 blues->StdHW = HintEntryP->data.arrayP[0].data.real;
1124 else
1125 blues->StdHW = 0;
1126 }
1127
1128
1129 /* get the ptr to the BlueScale entry */
1130 HintEntryP = &(PrivateDictP[BLUESCALE].value);
1131 /* put the BlueScale in the blues structure */
1132 if (objPIsInteger(HintEntryP)) /* Must be integer! */
1133 blues->BlueScale = HintEntryP->data.integer;
1134 else if (objPIsReal(HintEntryP)) /* Error? */
1135 blues->BlueScale = HintEntryP->data.real;
1136 else
1137 blues->BlueScale = DEFAULTBLUESCALE;
1138
1139 /* get the ptr to the BlueShift entry */
1140 HintEntryP = &(PrivateDictP[BLUESHIFT].value);
1141 if (objPIsInteger(HintEntryP)) /* Must be integer! */
1142 blues->BlueShift = HintEntryP->data.integer;
1143 else if (objPIsReal(HintEntryP)) /* Error? */
1144 blues->BlueShift = HintEntryP->data.real;
1145 else
1146 blues->BlueShift = DEFAULTBLUESHIFT;
1147
1148 /* get the ptr to the BlueFuzz entry */
1149 HintEntryP = &(PrivateDictP[BLUEFUZZ].value);
1150 if (objPIsInteger(HintEntryP)) /* Must be integer! */
1151 blues->BlueFuzz = HintEntryP->data.integer;
1152 else if (objPIsReal(HintEntryP)) /* Error? */
1153 blues->BlueFuzz = HintEntryP->data.real;
1154 else
1155 blues->BlueFuzz = DEFAULTBLUEFUZZ;
1156
1157 /* get the ptr to the ForceBold entry */
1158 HintEntryP = &(PrivateDictP[FORCEBOLD].value);
1159 if (objPIsBoolean(HintEntryP)) /* Must be integer! */
1160 blues->ForceBold = HintEntryP->data.boolean;
1161 else
1162 blues->ForceBold = DEFAULTFORCEBOLD;
1163
1164 /* get the ptr to the LanguageGroup entry */
1165 HintEntryP = &(PrivateDictP[LANGUAGEGROUP].value);
1166 if (objPIsInteger(HintEntryP)) /* Must be integer! */
1167 blues->LanguageGroup = HintEntryP->data.integer;
1168 else
1169 blues->LanguageGroup = DEFAULTLANGUAGEGROUP;
1170
1171 /* get the ptr to the RndStemUp entry */
1172 HintEntryP = &(PrivateDictP[RNDSTEMUP].value);
1173 if (objPIsBoolean(HintEntryP)) /* Must be integer! */
1174 blues->RndStemUp = HintEntryP->data.boolean;
1175 else
1176 blues->RndStemUp = DEFAULTRNDSTEMUP;
1177
1178 /* get the ptr to the lenIV entry */
1179 HintEntryP = &(PrivateDictP[LENIV].value);
1180 if (objPIsInteger(HintEntryP)) /* Must be integer! */
1181 blues->lenIV = HintEntryP->data.integer;
1182 else
1183 blues->lenIV = DEFAULTLENIV;
1184
1185 /* get the ptr to the ExpansionFactor entry */
1186 HintEntryP = &(PrivateDictP[EXPANSIONFACTOR].value);
1187 if (objPIsInteger(HintEntryP))
1188 blues->ExpansionFactor = HintEntryP->data.integer;
1189 else if (objPIsReal(HintEntryP))
1190 blues->ExpansionFactor = HintEntryP->data.real;
1191 else
1192 blues->ExpansionFactor = DEFAULTEXPANSIONFACTOR;
1193 return(SCAN_OK);
1194 }
1195 /**********************************************************************/
1196 /* GetType1CharString(fontP,code) */
1197 /* */
1198 /* Look up code in the standard encoding vector and return */
1199 /* the charstring associated with the character name. */
1200 /* */
1201 /* fontP is the psfont structure. */
1202 /* */
1203 /* Returns a psobj (string) */
1204 /**********************************************************************/
1205 psobj *GetType1CharString(psfont *fontP, unsigned char code)
1206 {
1207 int N; /* the 'Nth' entry in the CharStrings */
1208 psobj *charnameP; /* points to psobj that is name of character*/
1209
1210 psdict *CharStringsDictP; /* dictionary with char strings */
1211 psobj *theStringP; /* the definition for the code */
1212
1213
1214
1215 if (StdEncArrayP == NULL) {
1216 return(NULL);
1217 }
1218 /* use the code to index into the standard encoding vector */
1219 charnameP = &(StdEncArrayP[code]);
1220
1221 /* test if the encoding array points to a name */
1222 if (!(objPIsName(charnameP)) ) {
1223 return(NULL);
1224 }
1225
1226 /* Now that we have the character name out of the standardencoding */
1227 /* get the character definition out of the current font */
1228 CharStringsDictP = fontP->CharStringsP;
1229
1230 /* search the chars string for this charname as key */
1231 N = SearchDictName(CharStringsDictP,charnameP);
1232 if (N<=0) {
1233 return(NULL);
1234 }
1235 /* OK, the nth item is the psobj that is the string for this char */
1236 theStringP = &(CharStringsDictP[N].value);
1237
1238 return(theStringP);
1239 }
1240
1241 /***================================================================***/
1242 /*
1243 * FindDictValue
1244 */
1245 /***================================================================***/
1246
1247 static int FindDictValue(psdict *dictP)
1248 {
1249 psobj LitName;
1250 int N;
1251 int V;
1252
1253 /* we have just scanned a token and it is a literal name */
1254 /* need to check if that name is in Private dictionary */
1255 objFormatName(&LitName,tokenLength,tokenStartP);
1256 /* is it in the dictP */
1257 N = SearchDictName(dictP,&LitName);
1258 /* if found */
1259 if ( N > 0 ) {
1260 /* what type */
1261 switch (dictP[N].value.type) {
1262 case OBJ_ENCODING:
1263 V = getEncoding(&(dictP[N].value));
1264 if ( V != SCAN_OK ) return(V);
1265 break;
1266 case OBJ_ARRAY:
1267 V = getArray(&(dictP[N].value));
1268 if ( V != SCAN_OK ) return(V);
1269 break;
1270 case OBJ_INTEGER:
1271 /* next value in integer */
1272 dictP[N].value.data.integer = getInt();
1273 if (rc) return(rc); /* if next token was not an Int */
1274 break;
1275 case OBJ_REAL:
1276 /* next value must be real or int, store as a real */
1277 scan_token(inputP);
1278 if (tokenType == TOKEN_REAL) {
1279 dictP[N].value.data.real = tokenValue.real;
1280 }
1281 else
1282 if (tokenType == TOKEN_INTEGER) {
1283 dictP[N].value.data.real = tokenValue.integer;
1284 }
1285 else return(SCAN_ERROR);
1286 break;
1287 case OBJ_NAME:
1288 V = getNextValue(TOKEN_LITERAL_NAME);
1289 if ( V != SCAN_OK ) return(V);
1290 if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY);
1291 objFormatName(&(dictP[N].value),tokenLength,tokenStartP);
1292 break;
1293 case OBJ_STRING:
1294 V = getNextValue(TOKEN_STRING);
1295 if ( V != SCAN_OK ) return(V);
1296 if (!(vm_alloc(tokenLength)) ) return(SCAN_OUT_OF_MEMORY);
1297 objFormatString(&(dictP[N].value),tokenLength,tokenStartP);
1298 break;
1299 case OBJ_BOOLEAN:
1300 scan_token(inputP);
1301 if (tokenType != TOKEN_NAME) {
1302 return(SCAN_ERROR);
1303 }
1304 if (0 == strncmp(tokenStartP,"true",4) ) {
1305 dictP[N].value.data.boolean =TRUE;
1306 }
1307 else
1308 if (0 == strncmp(tokenStartP,"false",5) ) {
1309 dictP[N].value.data.boolean =FALSE;
1310 }
1311 else return(SCAN_ERROR);
1312 break;
1313
1314 default:
1315 return(SCAN_ERROR);
1316 break;
1317 }
1318 }
1319 /* Name is not in dictionary. That is ok. */
1320 return(SCAN_OK);
1321
1322 }
1323 /***================================================================***/
1324
1325 /*
1326 * -------------------------------------------------------------------
1327 * Scan the next token and convert it into an object
1328 * Result is placed on the Operand Stack as next object
1329 * -------------------------------------------------------------------
1330 */
1331 int scan_font(psfont *FontP)
1332 {
1333
1334
1335 char filename[128];
1336 char filetype[3];
1337 FILE *fileP;
1338 const char *nameP;
1339 int namelen;
1340 int V;
1341 int i;
1342 boolean starthex80;
1343
1344 starthex80 = FALSE;
1345 filetype[0] = 'r';
1346 filetype[1] = 'b';
1347 filetype[2] = '\0';
1348 /* copy the filename and remove leading or trailing blanks */
1349 /* point to name and search for leading blanks */
1350 nameP= FontP->FontFileName.data.nameP;
1351 namelen = FontP->FontFileName.len;
1352 while (nameP[0] == ' ') {
1353 nameP++;
1354 namelen--;
1355 }
1356 /* now remove any trailing blanks */
1357 while ((namelen>0) && ( nameP[namelen-1] == ' ')) {
1358 namelen--;
1359 }
1360 strncpy(filename,nameP,namelen);
1361 filename[namelen] = '\0';
1362 /* file name is now constructed */
1363 inputFile.data.fileP = NULL;
1364 filterFile.data.fileP = NULL;
1365
1366 inputP = &inputFile;
1367 if ((fileP = fopen(filename,filetype))) {
1368 /* get the first byte of file */
1369 V = getc(fileP);
1370 /* if file starts with x'80' then skip next 5 bytes */
1371 if ( V == 0X80 ) {
1372 for (i=0;i<5;i++) V = getc(fileP);
1373 starthex80 = TRUE;
1374 }
1375 else ungetc(V,fileP);
1376 objFormatFile(inputP,fileP);
1377 }
1378 else {
1379 return(SCAN_FILE_OPEN_ERROR);
1380 };
1381
1382 WantFontInfo = TRUE;
1383 InPrivateDict = FALSE;
1384 TwoSubrs = FALSE;
1385 rc = BuildFontInfo(FontP);
1386 if (rc != 0) return(rc);
1387
1388 /* Assume everything will be OK */
1389 rc = 0;
1390
1391 /* Loop until complete font is read */
1392 do {
1393 /* Scan the next token */
1394 scan_token(inputP);
1395
1396 /* ==> tokenLength, tokenTooLong, tokenType, and tokenValue are */
1397 /* now set */
1398
1399 switch (tokenType) {
1400 case TOKEN_EOF:
1401 case TOKEN_NONE:
1402 case TOKEN_INVALID:
1403 /* in this case we are done */
1404 if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
1405 rc = SCAN_ERROR;
1406 break;
1407 case TOKEN_LITERAL_NAME:
1408 /* Look up the name */
1409 tokenStartP[tokenLength] = '\0';
1410 if (InPrivateDict ) {
1411 if (0== strncmp(tokenStartP,"Subrs",5) ) {
1412 rc = BuildSubrs(FontP);
1413 break;
1414 }
1415 if (0== strncmp(tokenStartP,"CharStrings",11) ) {
1416 rc = BuildCharStrings(FontP);
1417 if ( (rc == SCAN_OK) ||(rc == SCAN_END) ) {
1418 fclose(inputP->data.fileP);
1419 /* Build the Blues Structure */
1420 rc = GetType1Blues(FontP);
1421 /* whatever the return code, return it */
1422 /* all the work is done. This is the normal exit.*/
1423 return(rc);
1424 }
1425 break;
1426 }
1427 rc = FindDictValue(FontP->Private);
1428 /* we are not going to report errors */
1429 /* Sometimes the font file may test a value such as */
1430 /* testing to see if the font is alreadly loaded with */
1431 /* same UniqueID. We would faile on /UniqueID get */
1432 /* because we are expecting a int to follow UniqueID*/
1433 /* If the correct object type does not follow a Name*/
1434 /* then we will skip over it without reporting error*/
1435 rc = SCAN_OK;
1436 break;
1437 } /* end of reading Private dictionary */
1438 else
1439 if (0== strncmp(tokenStartP,"Private",7) ) {
1440 InPrivateDict = TRUE;
1441 rc = BuildPrivate(FontP);
1442 break;
1443 }
1444 else
1445 if (WantFontInfo) {
1446 rc = FindDictValue(FontP->fontInfoP);
1447 /* we are not going to report errors */
1448 rc = SCAN_OK;
1449 break;
1450 }
1451 break;
1452 case TOKEN_NAME:
1453 if (0 == strncmp(tokenStartP,"eexec",5) ) {
1454 /* if file started with x'80', check next 5 bytes */
1455 if (starthex80) {
1456 V = getc(fileP);
1457 if ( V == 0X80 ) {
1458 for (i=0;i<5;i++) V = getc(fileP);
1459 }
1460 else ungetc(V,fileP);
1461 }
1462 filterFile.data.fileP = T1eexec(inputP->data.fileP);
1463 if (filterFile.data.fileP == NULL) {
1464 fclose(inputFile.data.fileP);
1465 return(SCAN_FILE_OPEN_ERROR);
1466 }
1467 inputP = &filterFile;
1468
1469 WantFontInfo = FALSE;
1470 }
1471 break;
1472 }
1473
1474 }
1475 while (rc ==0);
1476 fclose(inputP->data.fileP);
1477 if (tokenTooLong) return(SCAN_OUT_OF_MEMORY);
1478 return(rc);
1479 }
1480