font.c 692 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <libg.h>
  4. #include <bio.h>
  5. #include "hdr.h"
  6. Subfont *
  7. bf(int n, int size, Bitmap *b, int *done)
  8. {
  9. Fontchar *fc;
  10. int i, j;
  11. Subfont *f;
  12. fc = (Fontchar *)malloc(sizeof(Fontchar)*(n+1));
  13. if(fc == 0){
  14. fprint(2, "%s: fontchar malloc(%d) failure\n", argv0, sizeof(Fontchar)*(n+1));
  15. exits("fontchar malloc failure");
  16. }
  17. j = 0;
  18. for(i = 0; i <= n; i++){
  19. fc[i] = (Fontchar){j, 0, size, 0, size};
  20. if(done[i])
  21. j += size;
  22. else
  23. fc[i].width = 0;
  24. }
  25. fc[n] = (Fontchar){j, 0, size, 0, size};
  26. f = subfalloc(n, size, size*7/8, fc, b, ~0, ~0);
  27. if(f == 0){
  28. fprint(2, "%s: falloc failure\n", argv0);
  29. exits("falloc failure");
  30. }
  31. return(f);
  32. }