writesubfont.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. static
  13. void
  14. packinfo(Fontchar *fc, uint8_t *p, int n)
  15. {
  16. int j;
  17. for(j=0; j<=n; j++){
  18. p[0] = fc->x;
  19. p[1] = fc->x>>8;
  20. p[2] = fc->top;
  21. p[3] = fc->bottom;
  22. p[4] = fc->left;
  23. p[5] = fc->width;
  24. fc++;
  25. p += 6;
  26. }
  27. }
  28. int
  29. writesubfont(int fd, Subfont *f)
  30. {
  31. char hdr[3*12+1];
  32. uint8_t *data;
  33. int nb;
  34. sprint(hdr, "%11d %11d %11d ", f->n, f->height, f->ascent);
  35. if(write(fd, hdr, 3*12) != 3*12){
  36. Err:
  37. werrstr("writesubfont: bad write: %r");
  38. return -1;
  39. }
  40. nb = 6*(f->n+1);
  41. data = malloc(nb);
  42. if(data == nil)
  43. return -1;
  44. packinfo(f->info, data, f->n);
  45. if(write(fd, data, nb) != nb)
  46. goto Err;
  47. free(data);
  48. return 0;
  49. }