8 static char dev_dir
[PATHLEN
]; /* device directory */
9 static char dev_dev
[PATHLEN
]; /* output device name */
10 int dev_res
; /* device resolution */
11 int dev_uwid
; /* device unitwidth */
12 int dev_hor
; /* minimum horizontal movement */
13 int dev_ver
; /* minimum vertical movement */
16 static char fn_name
[NFONTS
][FNLEN
]; /* font names */
17 static struct font
*fn_font
[NFONTS
]; /* font structs */
18 static int fn_n
; /* number of device fonts */
20 /* .fspecial request */
21 static char fspecial_fn
[NFONTS
][FNLEN
]; /* .fspecial first arguments */
22 static char fspecial_sp
[NFONTS
][FNLEN
]; /* .fspecial special fonts */
23 static int fspecial_n
; /* number of fonts in fspecial_sp[] */
25 static void skipline(FILE* filp
)
30 } while (c
!= '\n' && c
!= EOF
);
33 static void dev_prologue(void)
35 out("x T %s\n", dev_dev
);
36 out("x res %d %d %d\n", dev_res
, dev_hor
, dev_ver
);
40 int dev_mnt(int pos
, char *id
, char *name
)
46 if (strchr(name
, '/'))
49 sprintf(path
, "%s/dev%s/%s", dev_dir
, dev_dev
, name
);
54 font_close(fn_font
[pos
]);
55 if (fn_name
[pos
] != name
) /* ignore if fn_name[pos] is passed */
56 strcpy(fn_name
[pos
], id
);
58 out("x font %d %s\n", pos
, name
);
62 int dev_open(char *dir
, char *dev
)
70 sprintf(path
, "%s/dev%s/DESC", dir
, dev
);
71 desc
= fopen(path
, "r");
74 while (fscanf(desc
, "%s", tok
) == 1) {
79 if (!strcmp("fonts", tok
)) {
80 fscanf(desc
, "%d", &fn_n
);
81 for (i
= 0; i
< fn_n
; i
++)
82 fscanf(desc
, "%s", fn_name
[i
+ 1]);
86 if (!strcmp("sizes", tok
)) {
87 while (fscanf(desc
, "%s", tok
) == 1)
88 if (!strcmp("0", tok
))
92 if (!strcmp("res", tok
)) {
93 fscanf(desc
, "%d", &dev_res
);
96 if (!strcmp("unitwidth", tok
)) {
97 fscanf(desc
, "%d", &dev_uwid
);
100 if (!strcmp("hor", tok
)) {
101 fscanf(desc
, "%d", &dev_hor
);
104 if (!strcmp("ver", tok
)) {
105 fscanf(desc
, "%d", &dev_ver
);
108 if (!strcmp("charset", tok
))
114 for (i
= 0; i
< fn_n
; i
++)
116 dev_mnt(i
, fn_name
[i
], fn_name
[i
]);
120 static void dev_epilogue(void)
130 for (i
= 0; i
< NFONTS
; i
++) {
132 font_close(fn_font
[i
]);
137 /* glyph handling functions */
139 static struct glyph
*dev_find(char *c
, int fn
, int byid
)
141 struct glyph
*(*find
)(struct font
*fn
, char *name
);
144 find
= byid
? font_glyph
: font_find
;
145 if ((g
= find(fn_font
[fn
], c
)))
147 for (i
= 0; i
< fspecial_n
; i
++)
148 if (dev_pos(fspecial_fn
[i
]) == fn
&& dev_pos(fspecial_sp
[i
]) >= 0)
149 if ((g
= find(dev_font(dev_pos(fspecial_sp
[i
])), c
)))
151 for (i
= 0; i
< NFONTS
; i
++)
152 if (fn_font
[i
] && font_special(fn_font
[i
]))
153 if ((g
= find(fn_font
[i
], c
)))
158 struct glyph
*dev_glyph(char *c
, int fn
)
160 if ((c
[0] == c_ec
|| c
[0] == c_ni
) && c
[1] == c_ec
)
162 if (c
[0] == c_ec
&& c
[1] == '(')
165 if (!strncmp("GID=", c
, 4))
166 return dev_find(c
+ 4, fn
, 1);
167 return dev_find(c
, fn
, 0);
170 /* return the mounted position of a font */
171 int dev_pos(char *id
)
174 if (isdigit(id
[0])) {
176 if (num
< 0 || num
>= NFONTS
|| !fn_font
[num
]) {
177 errmsg("bad font position\n");
182 for (i
= 1; i
< NFONTS
; i
++)
183 if (!strcmp(fn_name
[i
], id
))
185 if (!strcmp(fn_name
[0], id
))
187 return dev_mnt(0, id
, id
);
190 /* return the mounted position of a font struct */
191 int dev_fontpos(struct font
*fn
)
194 for (i
= 0; i
< NFONTS
; i
++)
195 if (fn_font
[i
] == fn
)
200 /* return the font struct at pos */
201 struct font
*dev_font(int pos
)
203 return pos
>= 0 && pos
< NFONTS
? fn_font
[pos
] : NULL
;
206 void tr_fspecial(char **args
)
214 for (i
= 2; i
< NARGS
; i
++) {
215 if (args
[i
] && fspecial_n
< LEN(fspecial_fn
)) {
216 strcpy(fspecial_fn
[fspecial_n
], fn
);
217 strcpy(fspecial_sp
[fspecial_n
], args
[i
]);