2011-03-30 05:46:40 -07:00
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
#include <draw.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default version: treat as file name
|
|
|
|
*/
|
|
|
|
|
|
|
|
Subfont*
|
|
|
|
_getsubfont(Display *d, char *name)
|
|
|
|
{
|
2015-02-23 18:25:26 -08:00
|
|
|
int dolock, fd;
|
2011-03-30 05:46:40 -07:00
|
|
|
Subfont *f;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-02-23 18:25:26 -08:00
|
|
|
dolock = d != nil && d->locking == 0;
|
|
|
|
if(dolock)
|
2011-03-30 05:46:40 -07:00
|
|
|
unlockdisplay(d);
|
2015-02-23 18:25:26 -08:00
|
|
|
|
|
|
|
fd = open(name, OREAD);
|
|
|
|
if(fd < 0) {
|
|
|
|
fprint(2, "getsubfont: can't open %s: %r\n", name);
|
|
|
|
f = nil;
|
|
|
|
} else {
|
|
|
|
f = readsubfont(d, name, fd, dolock);
|
|
|
|
if(f == nil)
|
|
|
|
fprint(2, "getsubfont: can't read %s: %r\n", name);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dolock)
|
2011-03-30 05:46:40 -07:00
|
|
|
lockdisplay(d);
|
2015-02-23 18:25:26 -08:00
|
|
|
|
2011-03-30 05:46:40 -07:00
|
|
|
return f;
|
|
|
|
}
|