mkfont.c 1.3 KB

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