getsubfont.c 772 B

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