]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libdraw/getsubfont.c
Import sources from 2011-03-30 iso image - lib
[plan9front.git] / sys / src / libdraw / getsubfont.c
1 #include <u.h>
2 #include <libc.h>
3 #include <draw.h>
4
5 /*
6  * Default version: treat as file name
7  */
8
9 Subfont*
10 _getsubfont(Display *d, char *name)
11 {
12         int fd;
13         Subfont *f;
14
15         fd = open(name, OREAD);
16                 
17         if(fd < 0){
18                 fprint(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 && d->locking == 0)
28                 unlockdisplay(d);
29         f = readsubfont(d, name, fd, d && d->locking==0);
30         if(d && d->locking == 0)
31                 lockdisplay(d);
32         if(f == 0)
33                 fprint(2, "getsubfont: can't read %s: %r\n", name);
34         close(fd);
35         setmalloctag(f, getcallerpc(&d));
36         return f;
37 }