pdf: add splines
[neatpost.git] / dev.c
blob30af156402d9255a776609e86f2e76666255e817
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include "post.h"
7 static char dev_dir[PATHLEN]; /* device directory */
8 static char dev_dev[PATHLEN]; /* output device name */
9 int dev_res; /* device resolution */
10 int dev_uwid; /* device unitwidth */
11 int dev_hor; /* minimum horizontal movement */
12 int dev_ver; /* minimum vertical movement */
14 /* mounted fonts */
15 static char fn_name[NFONTS][FNLEN]; /* font names */
16 static struct font *fn_font[NFONTS]; /* font structs */
17 static int fn_n; /* number of device fonts */
19 static void skipline(FILE* filp)
21 int c;
22 do {
23 c = getc(filp);
24 } while (c != '\n' && c != EOF);
27 struct font *dev_fontopen(char *name)
29 char path[PATHLEN];
30 if (strchr(name, '/'))
31 strcpy(path, name);
32 else
33 sprintf(path, "%s/dev%s/%s", dev_dir, dev_dev, name);
34 return font_open(path);
37 int dev_mnt(int pos, char *id, char *name)
39 struct font *fn;
40 if (pos >= NFONTS)
41 return -1;
42 fn = dev_fontopen(name);
43 if (!fn)
44 return -1;
45 if (fn_font[pos])
46 font_close(fn_font[pos]);
47 if (fn_name[pos] != name) /* ignore if fn_name[pos] is passed */
48 snprintf(fn_name[pos], sizeof(fn_name[pos]), "%s", id);
49 fn_font[pos] = fn;
50 return pos;
53 int dev_open(char *dir, char *dev)
55 char path[PATHLEN];
56 char tok[128];
57 int i;
58 FILE *desc;
59 strcpy(dev_dir, dir);
60 strcpy(dev_dev, dev);
61 sprintf(path, "%s/dev%s/DESC", dir, dev);
62 desc = fopen(path, "r");
63 if (!desc)
64 return 1;
65 while (fscanf(desc, "%127s", tok) == 1) {
66 if (tok[0] == '#') {
67 skipline(desc);
68 continue;
70 if (!strcmp("fonts", tok)) {
71 fscanf(desc, "%d", &fn_n);
72 for (i = 0; i < fn_n; i++)
73 fscanf(desc, "%s", fn_name[i + 1]);
74 fn_n++;
75 continue;
77 if (!strcmp("sizes", tok)) {
78 while (fscanf(desc, "%127s", tok) == 1)
79 if (!strcmp("0", tok))
80 break;
81 continue;
83 if (!strcmp("res", tok)) {
84 fscanf(desc, "%d", &dev_res);
85 continue;
87 if (!strcmp("unitwidth", tok)) {
88 fscanf(desc, "%d", &dev_uwid);
89 continue;
91 if (!strcmp("hor", tok)) {
92 fscanf(desc, "%d", &dev_hor);
93 continue;
95 if (!strcmp("ver", tok)) {
96 fscanf(desc, "%d", &dev_ver);
97 continue;
99 if (!strcmp("charset", tok))
100 break;
101 skipline(desc);
103 fclose(desc);
104 return 0;
107 void dev_close(void)
109 int i;
110 for (i = 0; i < NFONTS; i++) {
111 if (fn_font[i])
112 font_close(fn_font[i]);
113 fn_font[i] = NULL;
117 struct glyph *dev_glyph(char *c, int fn)
119 if (!strncmp("GID=", c, 4))
120 return font_glyph(fn_font[fn], c + 4);
121 return font_find(fn_font[fn], c);
124 /* return the font struct at pos */
125 struct font *dev_font(int pos)
127 return pos >= 0 && pos < NFONTS ? fn_font[pos] : NULL;
130 int dev_fontid(struct font *fn)
132 int i;
133 for (i = 0; i < NFONTS; i++)
134 if (fn_font[i] == fn)
135 return i;
136 return 0;