writesubfont.c 689 B

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