subfontcache.c 752 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <draw.h>
  4. /*
  5. * Easy versions of the cache routines; may be substituted by fancier ones for other purposes
  6. */
  7. static char *lastname;
  8. Subfont *lastsubfont;
  9. Subfont*
  10. lookupsubfont(Display *d, char *name)
  11. {
  12. if(d && strcmp(name, "*default*") == 0)
  13. return d->defaultsubfont;
  14. if(lastname && strcmp(name, lastname)==0)
  15. if(d==lastsubfont->bits->display){
  16. lastsubfont->ref++;
  17. return lastsubfont;
  18. }
  19. return 0;
  20. }
  21. void
  22. installsubfont(char *name, Subfont *subfont)
  23. {
  24. free(lastname);
  25. lastname = strdup(name);
  26. lastsubfont = subfont; /* notice we don't free the old one; that's your business */
  27. }
  28. void
  29. uninstallsubfont(Subfont *subfont)
  30. {
  31. if(subfont == lastsubfont){
  32. lastname = 0;
  33. lastsubfont = 0;
  34. }
  35. }