5 static char *pf_read_token(FILE *fp
);
7 void read_pfa_file(input
*in
) {
8 rdstringc rsc
= { 0, 0, NULL
};
13 FILE *fp
= in
->currfp
;
21 error(err_pfeof
, &in
->pos
);
25 } while (c
!= 012 && c
!= 015);
27 if ((p
= strchr(p
, ':')) == NULL
) {
29 error(err_pfhead
, &in
->pos
);
33 p
+= strspn(p
, " \t");
34 len
= strcspn(p
, " \t");
35 fontname
= snewn(len
+ 1, char);
36 memcpy(fontname
, p
, len
);
40 for (fi
= all_fonts
; fi
; fi
= fi
->next
) {
41 if (strcmp(fi
->name
, fontname
) == 0) {
44 fi
->length1
= fi
->length2
= 0;
49 error(err_pfnoafm
, &in
->pos
, fontname
);
55 * PostScript white space characters; PLRM3 table 3.1
57 static int pf_isspace(int c
) {
58 return c
== 000 || c
== 011 || c
== 012 || c
== 014 || c
== 015 ||
63 * PostScript special characters; PLRM3 page 27
65 static int pf_isspecial(int c
) {
66 return c
== '(' || c
== ')' || c
== '<' || c
== '>' || c
== '[' ||
67 c
== ']' || c
== '{' || c
== '}' || c
== '/' || c
== '%';
70 static long pf_length1(font_info
*fi
) {
75 tok
= pf_read_token(fp
);
76 while (tok
&& strcmp(tok
, "eexec") != 0) {
78 tok
= pf_read_token(fp
);
81 error(err_pfeof
, &fi
->pos
);
88 * Return the initial, unencrypted, part of a font.
90 void pf_part1(font_info
*fi
, char **bufp
, size_t *lenp
) {
94 fi
->length1
= pf_length1(fi
);
96 *bufp
= snewn(fi
->length1
, char);
98 if (fread(*bufp
, 1, fi
->length1
, fp
) != (size_t)fi
->length1
) {
99 error(err_pfeof
, &fi
->pos
);
106 static int hexval(char c
) {
107 if (c
>= '0' && c
<= '9') return c
- '0';
108 if (c
>= 'A' && c
<= 'F') return c
- 'A' + 0xA;
109 if (c
>= 'a' && c
<= 'f') return c
- 'a' + 0xa;
114 * Return the middle, encrypted, part of a font.
116 void pf_part2(font_info
*fi
, char **bufp
, size_t *lenp
) {
118 rdstringc rsc
= { 0, 0, NULL
};
120 unsigned char nybble
;
123 if (fi
->length1
== 0)
124 fi
->length1
= pf_length1(fi
);
125 fseek(fp
, fi
->length1
, SEEK_SET
);
126 tok
= pf_read_token(fp
);
127 while (tok
&& strcmp(tok
, "cleartomark") != 0) {
128 for (p
= tok
; *p
; p
++) {
129 if (pf_isspace(*p
)) continue;
133 rdaddc(&rsc
, (nybble
<< 4) | hexval(*p
));
134 havenybble
= !havenybble
;
137 tok
= pf_read_token(fp
);
140 error(err_pfeof
, &fi
->pos
);
145 /* Trim off the trailing zeroes */
147 *lenp
= rsc
.pos
- 256;
149 error(err_pfbad
, &fi
->pos
);
155 static char *pf_read_litstring(FILE *fp
) {
156 rdstringc rsc
= { 0, 0, NULL
};
173 if (c
!= EOF
) rdaddc(&rsc
, c
);
174 } while (depth
> 0 && c
!= EOF
);
178 static char *pf_read_hexstring(FILE *fp
) {
179 rdstringc rsc
= { 0, 0, NULL
};
185 if (c
!= EOF
) rdaddc(&rsc
, c
);
186 } while (c
!= '>' && c
!= EOF
);
190 static char *pf_read_word(FILE *fp
, int c
) {
191 rdstringc rsc
= { 0, 0, NULL
};
194 if (c
== '{' || c
== '}' || c
== '[' || c
== ']')
198 if (pf_isspecial(c
) || pf_isspace(c
) || c
== EOF
) break;
201 if (pf_isspecial(c
)) ungetc(c
, fp
);
205 static char *pf_read_token(FILE *fp
) {
210 } while (pf_isspace(c
));
211 if (c
== EOF
) return NULL
;
215 } while (c
!= 012 && c
!= 015);
216 return pf_read_token(fp
);
218 if (c
== '(') return pf_read_litstring(fp
);
219 if (c
== '<') return pf_read_hexstring(fp
);
220 return pf_read_word(fp
, c
);