getsubfont.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <draw.h>
  12. /*
  13. * Default version: treat as file name
  14. */
  15. Subfont*
  16. _getsubfont(Display *d, char *name)
  17. {
  18. int fd;
  19. Subfont *f;
  20. fd = open(name, OREAD);
  21. if(fd < 0){
  22. fprint(2, "getsubfont: can't open %s: %r\n", name);
  23. return 0;
  24. }
  25. /*
  26. * unlock display so i/o happens with display released, unless
  27. * user is doing his own locking, in which case this could break things.
  28. * _getsubfont is called only from string.c and stringwidth.c,
  29. * which are known to be safe to have this done.
  30. */
  31. if(d && d->locking == 0)
  32. unlockdisplay(d);
  33. f = readsubfont(d, name, fd, d && d->locking==0);
  34. if(d && d->locking == 0)
  35. lockdisplay(d);
  36. if(f == 0)
  37. fprint(2, "getsubfont: can't read %s: %r\n", name);
  38. close(fd);
  39. setmalloctag(f, getcallerpc());
  40. return f;
  41. }