mkfont.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. * Cobble fake font using existing subfont
  14. */
  15. Font*
  16. mkfont(Subfont *subfont, Rune min)
  17. {
  18. Font *font;
  19. Cachefont *c;
  20. font = malloc(sizeof(Font));
  21. if(font == 0)
  22. return 0;
  23. memset(font, 0, sizeof(Font));
  24. font->display = subfont->bits->display;
  25. font->name = strdup("<synthetic>");
  26. font->ncache = NFCACHE+NFLOOK;
  27. font->nsubf = NFSUBF;
  28. font->cache = malloc(font->ncache * sizeof(font->cache[0]));
  29. font->subf = malloc(font->nsubf * sizeof(font->subf[0]));
  30. if(font->name==0 || font->cache==0 || font->subf==0){
  31. Err:
  32. free(font->name);
  33. free(font->cache);
  34. free(font->subf);
  35. free(font->sub);
  36. free(font);
  37. return 0;
  38. }
  39. memset(font->cache, 0, font->ncache*sizeof(font->cache[0]));
  40. memset(font->subf, 0, font->nsubf*sizeof(font->subf[0]));
  41. font->height = subfont->height;
  42. font->ascent = subfont->ascent;
  43. font->age = 1;
  44. font->sub = malloc(sizeof(Cachefont*));
  45. if(font->sub == 0)
  46. goto Err;
  47. c = malloc(sizeof(Cachefont));
  48. if(c == 0)
  49. goto Err;
  50. font->nsub = 1;
  51. font->sub[0] = c;
  52. c->min = min;
  53. c->max = min+subfont->n-1;
  54. c->offset = 0;
  55. c->name = 0; /* noticed by freeup() and agefont() */
  56. c->subfontname = 0;
  57. font->subf[0].age = 0;
  58. font->subf[0].cf = c;
  59. font->subf[0].f = subfont;
  60. return font;
  61. }