summaryrefslogtreecommitdiff
path: root/in_pf.c
blob: 50e663ee451cce7997148467eefc2b73266bf2c1 (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
#include <stdio.h>
#include "halibut.h"
#include "paper.h"

void read_pfa_file(input *in) {
    char buf[512], *p;
    size_t len;
    char *fontname;
    font_info *fi;

    len = fread(buf, 1, sizeof(buf) - 1, in->currfp);
    buf[len] = 0;
    if (strncmp(buf, "%!FontType1-", 12) &&
	strncmp(buf, "%!PS-AdobeFont-", 15))
	return;
    p = buf;
    p += strcspn(p, ":") + 1;
    p += strspn(p, " \t");
    len = strcspn(p, " \t");
    fontname = snewn(len + 1, char);
    memcpy(fontname, p, len);
    fontname[len] = 0;
    for (fi = all_fonts; fi; fi = fi->next) {
	if (strcmp(fi->name, fontname) == 0) {
	    fi->fp = in->currfp;
	    sfree(fontname);
	    return;
	}
    }
    fclose(in->currfp);
    sfree(fontname);
}