mkfont.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "lib9.h"
  2. #include "draw.h"
  3. /*
  4. * Cobble fake font using existing subfont
  5. */
  6. Font*
  7. mkfont(Subfont *subfont, Rune min)
  8. {
  9. Font *font;
  10. Cachefont *c;
  11. font = malloc(sizeof(Font));
  12. if(font == 0)
  13. return 0;
  14. memset(font, 0, sizeof(Font));
  15. font->display = subfont->bits->display;
  16. font->name = strdup("<synthetic>");
  17. font->ncache = NFCACHE+NFLOOK;
  18. font->nsubf = NFSUBF;
  19. font->cache = malloc(font->ncache * sizeof(font->cache[0]));
  20. font->subf = malloc(font->nsubf * sizeof(font->subf[0]));
  21. if(font->name==0 || font->cache==0 || font->subf==0){
  22. Err:
  23. free(font->name);
  24. free(font->cache);
  25. free(font->subf);
  26. free(font->sub);
  27. free(font);
  28. return 0;
  29. }
  30. memset(font->cache, 0, font->ncache*sizeof(font->cache[0]));
  31. memset(font->subf, 0, font->nsubf*sizeof(font->subf[0]));
  32. font->height = subfont->height;
  33. font->ascent = subfont->ascent;
  34. font->age = 1;
  35. font->sub = malloc(sizeof(Cachefont*));
  36. if(font->sub == 0)
  37. goto Err;
  38. c = malloc(sizeof(Cachefont));
  39. if(c == 0)
  40. goto Err;
  41. font->nsub = 1;
  42. font->sub[0] = c;
  43. c->min = min;
  44. c->max = min+subfont->n-1;
  45. c->offset = 0;
  46. c->name = 0; /* noticed by freeup() and agefont() */
  47. c->subfontname = 0;
  48. font->subf[0].age = 0;
  49. font->subf[0].cf = c;
  50. font->subf[0].f = subfont;
  51. return font;
  52. }