main.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <libg.h>
  4. #include <bio.h>
  5. #include "hdr.h"
  6. /*
  7. produces the bitmap for the designated han characters
  8. */
  9. static void usage(void);
  10. enum { Jis = 0, Big5, Gb_bdf, Gb_qw };
  11. enum { Size24 = 0, Size16 };
  12. struct {
  13. char *names[2];
  14. mapfn *mfn;
  15. readbitsfn *bfn;
  16. } source[] = {
  17. [Jis] { "../han/jis.bits", "../han/jis16.bits", kmap, kreadbits },
  18. [Big5] { "no 24 bit file", "../han/big5.16.bits", bmap, breadbits },
  19. [Gb_bdf] { "no 24 bit file", "../han/cclib16fs.bdf", gmap, greadbits },
  20. [Gb_qw] { "no 24 bit file", "no 16bit file", gmap, qreadbits },
  21. };
  22. void
  23. main(int argc, char **argv)
  24. {
  25. int from, to;
  26. int size = 24;
  27. int src = Jis;
  28. char *file = 0;
  29. long nc, nb;
  30. int x;
  31. uchar *bits;
  32. long *chars;
  33. int raw = 0;
  34. Bitmap *b, *b1;
  35. Subfont *f;
  36. int *found;
  37. ARGBEGIN{
  38. case 'f': file = ARGF(); break;
  39. case 'r': raw = 1; break;
  40. case '5': src = Big5; break;
  41. case 's': size = 16; break;
  42. case 'g': src = Gb_bdf; break;
  43. case 'q': src = Gb_qw; break;
  44. default: usage();
  45. }ARGEND
  46. if(file == 0)
  47. file = source[src].names[(size==24)? Size24:Size16];
  48. if(argc != 2)
  49. usage();
  50. from = strtol(argv[0], (char **)0, 0);
  51. to = strtol(argv[1], (char **)0, 0);
  52. binit(0, 0, "fontgen");
  53. nc = to-from+1;
  54. nb = size*size/8; /* bytes per char */
  55. nb *= nc;
  56. bits = (uchar *)malloc(nb);
  57. chars = (long *)malloc(sizeof(long)*nc);
  58. found = (int *)malloc(sizeof(found[0])*nc);
  59. if(bits == 0 || chars == 0){
  60. fprint(2, "%s: couldn't malloc %d bytes for %d chars\n", argv0, nb, nc);
  61. exits("out of memory");
  62. }
  63. if(raw){
  64. for(x = from; x <= to; x++)
  65. chars[x-from] = x;
  66. } else
  67. source[src].mfn(from, to, chars);
  68. memset(bits, 0, nb);
  69. b = source[src].bfn(file, nc, chars, size, bits, &found);
  70. b1 = balloc(b->r, b->ldepth);
  71. bitblt(b1, b1->r.min, b, b->r, S);
  72. f = bf(nc, size, b1, found);
  73. wrbitmapfile(1, b);
  74. wrsubfontfile(1, f);/**/
  75. exits(0);
  76. }
  77. static void
  78. usage(void)
  79. {
  80. fprint(2, "Usage: %s [-s] from to\n", argv0);
  81. exits("usage");
  82. }