subfontname.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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: convert to file name
  14. */
  15. char*
  16. subfontname(char *cfname, char *fname, int maxdepth)
  17. {
  18. char *t, *u, *tmp1, *tmp2;
  19. int i;
  20. t = strdup(cfname); /* t is the return string */
  21. if(strcmp(cfname, "*default*") == 0)
  22. return t;
  23. if(t[0] != '/'){
  24. tmp2 = strdup(fname);
  25. u = utfrrune(tmp2, '/');
  26. if(u)
  27. u[0] = 0;
  28. else
  29. strcpy(tmp2, ".");
  30. tmp1 = smprint("%s/%s", tmp2, t);
  31. free(tmp2);
  32. free(t);
  33. t = tmp1;
  34. }
  35. if(maxdepth > 8)
  36. maxdepth = 8;
  37. for(i=3; i>=0; i--){
  38. if((1<<i) > maxdepth)
  39. continue;
  40. /* try i-bit grey */
  41. tmp2 = smprint("%s.%d", t, i);
  42. if(access(tmp2, AREAD) == 0) {
  43. free(t);
  44. return tmp2;
  45. }
  46. free(tmp2);
  47. }
  48. /* try default */
  49. if(access(t, AREAD) == 0)
  50. return t;
  51. free(t);
  52. return nil;
  53. }