subfontcache.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. * Easy versions of the cache routines; may be substituted by fancier ones for other purposes
  14. */
  15. static char *lastname;
  16. Subfont *lastsubfont;
  17. Subfont*
  18. lookupsubfont(Display *d, char *name)
  19. {
  20. if(d && strcmp(name, "*default*") == 0)
  21. return d->defaultsubfont;
  22. if(lastname && strcmp(name, lastname)==0)
  23. if(d==lastsubfont->bits->display){
  24. lastsubfont->ref++;
  25. return lastsubfont;
  26. }
  27. return 0;
  28. }
  29. void
  30. installsubfont(char *name, Subfont *subfont)
  31. {
  32. free(lastname);
  33. lastname = strdup(name);
  34. lastsubfont = subfont; /* notice we don't free the old one; that's your business */
  35. }
  36. void
  37. uninstallsubfont(Subfont *subfont)
  38. {
  39. if(subfont == lastsubfont){
  40. lastname = 0;
  41. lastsubfont = 0;
  42. }
  43. }