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