Skip to content

Commit fa29204

Browse files
committed
pdf: a basic pdf post-processor
1 parent 20d081c commit fa29204

File tree

10 files changed

+991
-386
lines changed

10 files changed

+991
-386
lines changed

Makefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ FDIR = /neatroff/font
44
CC = cc
55
CFLAGS = -Wall -O2 "-DTROFFFDIR=\"$(FDIR)\""
66
LDFLAGS =
7-
OBJS = post.o out.o ps.o font.o dev.o clr.o dict.o iset.o
7+
OBJS = post.o ps.o font.o dev.o clr.o dict.o iset.o
8+
OBJSPDF = post.o pdf.o font.o dev.o clr.o dict.o iset.o sbuf.o
89

9-
all: post
10+
all: post pdf
1011
%.o: %.c post.h
1112
$(CC) -c $(CFLAGS) $<
1213
post: $(OBJS)
1314
$(CC) -o $@ $(OBJS) $(LDFLAGS)
15+
pdf: $(OBJSPDF)
16+
$(CC) -o $@ $(OBJSPDF) $(LDFLAGS)
1417
clean:
15-
rm -f *.o post
18+
rm -f *.o post pdf

dict.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static void dict_extend(struct dict *d, int size)
2525

2626
struct dict *dict_make(int notfound, int dupkeys)
2727
{
28-
struct dict *d = xmalloc(sizeof(*d));
28+
struct dict *d = malloc(sizeof(*d));
2929
memset(d, 0, sizeof(*d));
3030
d->n = 1;
3131
d->dupkeys = dupkeys;
@@ -54,7 +54,7 @@ void dict_put(struct dict *d, char *key, int val)
5454
dict_extend(d, d->n + CNTMIN);
5555
if (d->dupkeys) {
5656
int len = strlen(key) + 1;
57-
char *dup = xmalloc(len);
57+
char *dup = malloc(len);
5858
memcpy(dup, key, len);
5959
key = dup;
6060
}

font.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
struct font {
88
char name[FNLEN];
99
char fontname[FNLEN];
10+
char fontpath[1024];
1011
int spacewid;
1112
struct glyph *gl; /* glyphs present in the font */
1213
int gl_n, gl_sz; /* number of glyphs in the font */
@@ -108,7 +109,7 @@ struct font *font_open(char *path)
108109
fin = fopen(path, "r");
109110
if (!fin)
110111
return NULL;
111-
fn = xmalloc(sizeof(*fn));
112+
fn = malloc(sizeof(*fn));
112113
if (!fn) {
113114
fclose(fin);
114115
return NULL;
@@ -126,6 +127,12 @@ struct font *font_open(char *path)
126127
fscanf(fin, "%s", fn->name);
127128
} else if (!strcmp("fontname", tok)) {
128129
fscanf(fin, "%s", fn->fontname);
130+
} else if (!strcmp("fontpath", tok)) {
131+
int c = fgetc(fin);
132+
while (c == ' ')
133+
c = fgetc(fin);
134+
ungetc(c, fin);
135+
tilleol(fin, fn->fontpath);
129136
} else if (!strcmp("ligatures", tok)) {
130137
while (fscanf(fin, "%s", tok) == 1)
131138
if (!strcmp("0", tok))
@@ -166,3 +173,18 @@ char *font_name(struct font *fn)
166173
{
167174
return fn->fontname;
168175
}
176+
177+
char *font_path(struct font *fn)
178+
{
179+
return fn->fontpath;
180+
}
181+
182+
int font_glnum(struct font *fn, struct glyph *g)
183+
{
184+
return g - fn->gl;
185+
}
186+
187+
struct glyph *font_glget(struct font *fn, int id)
188+
{
189+
return id >= 0 && id < fn->gl_n ? &fn->gl[id] : NULL;
190+
}

iset.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static void iset_extend(struct iset *iset, int cnt)
2424

2525
struct iset *iset_make(void)
2626
{
27-
struct iset *iset = xmalloc(sizeof(*iset));
27+
struct iset *iset = malloc(sizeof(*iset));
2828
memset(iset, 0, sizeof(*iset));
2929
iset_extend(iset, CNTMIN);
3030
return iset;
@@ -60,7 +60,7 @@ void iset_put(struct iset *iset, int key, int ent)
6060
if (key >= 0 && key < iset->cnt && iset->len[key] + 1 >= iset->sz[key]) {
6161
int olen = iset->sz[key];
6262
int nlen = iset->sz[key] * 2 + 8;
63-
void *nset = xmalloc(nlen * sizeof(iset->set[key][0]));
63+
void *nset = malloc(nlen * sizeof(iset->set[key][0]));
6464
if (iset->set[key]) {
6565
memcpy(nset, iset->set[key],
6666
olen * sizeof(iset->set[key][0]));

0 commit comments

Comments
 (0)