aboutsummaryrefslogtreecommitdiff
path: root/src/libdraw/getsubfont.c
blob: 0d8be9ff4e2a99a9a0e74d449e5bc2010cd88237 (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
35
36
37
38
39
40
#include <u.h>
#include <libc.h>
#include <draw.h>

/*
 * Default version: treat as file name
 */

int _fontpipe(char*);

Subfont*
_getsubfont(Display *d, char *name)
{
	int fd;
	Subfont *f;

	fd = open(name, OREAD);
	if(fd < 0 && strncmp(name, "/mnt/font/", 10) == 0)
		fd = _fontpipe(name+10);

	if(fd < 0){
		fprint(2, "getsubfont: can't open %s: %r\n", name);
		return 0;
	}
	/*
	 * unlock display so i/o happens with display released, unless
	 * user is doing his own locking, in which case this could break things.
	 * _getsubfont is called only from string.c and stringwidth.c,
	 * which are known to be safe to have this done.
	 */
	if(d && d->locking == 0)
		unlockdisplay(d);
	f = readsubfont(d, name, fd, d && d->locking==0);
	if(d && d->locking == 0)
		lockdisplay(d);
	if(f == 0)
		fprint(2, "getsubfont: can't read %s: %r\n", name);
	close(fd);
	return f;
}