xref: /inferno-os/libdraw/getsubfont.c (revision 37da2899f40661e3e9631e497da8dc59b971cbd0)
1 #include "lib9.h"
2 #include "kernel.h"
3 #include "draw.h"
4 
5 /*
6  * Default version: treat as file name
7  */
8 
9 Subfont*
_getsubfont(Display * d,char * name)10 _getsubfont(Display *d, char *name)
11 {
12 	int fd;
13 	Subfont *f;
14 
15 	fd = libopen(name, OREAD);
16 
17 	if(fd < 0){
18 		_drawprint(2, "getsubfont: can't open %s: %r\n", name);
19 		return 0;
20 	}
21 	/*
22 	 * unlock display so i/o happens with display released, unless
23 	 * user is doing his own locking, in which case this could break things.
24 	 * _getsubfont is called only from string.c and stringwidth.c,
25 	 * which are known to be safe to have this done.
26 	 */
27 	if(d->local == 0)
28 		unlockdisplay(d);
29 	f = readsubfont(d, name, fd, d->local == 0);
30 	if(d->local == 0)
31 		lockdisplay(d);
32 	if(f == 0)
33 		_drawprint(2, "getsubfont: can't read %s: %r\n", name);
34 	libclose(fd);
35 	return f;
36 }
37