No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / hpc / fontconv.c
blob07166ebeda76ed05347073f4b0664d6fb8cf6970
1 /* $NetBSD: fontconv.c,v 1.2 2001/06/04 18:59:31 uch Exp $ */
3 #include <sys/cdefs.h>
4 __KERNEL_RCSID(0, "$NetBSD$");
6 #include <stdio.h>
9 int width, height, ascent;
10 char *fontname;
11 FILE *ifp;
12 FILE *ofp;
15 void fc_rcons(int ac, char* av[]);
16 void fc_rasops(int ac, char* av[]);
19 main(int ac, char* av[])
21 ifp = stdin;
22 ofp = stdout;
23 width = 8;
24 height = 8;
25 ascent = 8;
26 fontname = "vt220l";
29 fc_rcons(ac, av);
31 fc_rasops(ac, av);
35 void
36 fc_rasops(int ac, char* av[])
38 int code;
39 int width_in_bytes;
40 long code_min = 0x10000;
41 long code_max = -1;
43 width_in_bytes = (width + 7) / 8;
45 code = 0;
46 fprintf(ofp, "static u_char %s%dx%d_data[] = {\n",
47 fontname, width, height, code);
48 while (1) {
49 int n;
50 int i, j, k;
51 unsigned char buf[200];
53 n = fread(buf, width_in_bytes, height, ifp);
54 if (n != height) {
55 if (!feof(ifp)) {
56 perror("fread()");
57 exit(1);
58 } else {
59 break;
63 k = 0;
64 fprintf(ofp, " /* code %d */\n", code);
65 for (i = 0; i < height; i++) {
66 unsigned long d = 0, m;
67 fprintf(ofp, " ");
68 for (j = 0; j < width_in_bytes; j++) {
69 d |= (((unsigned long)buf[k]) << (24 - 8*j));
70 fprintf(ofp, "0x%02x,", (buf[k] & 0xff));
71 k++;
73 fprintf(ofp, " /* ");
74 for (m = 0x80000000, j = 0; j < width; j++, m >>= 1) {
75 printf((m & d) ? "##" : "..");
77 fprintf(ofp, " */\n");
79 fprintf(ofp, "\n");
80 if (code < code_min) {
81 code_min = code;
83 if (code_max < code) {
84 code_max = code;
86 code++;
88 fprintf(ofp, "};\n");
90 fprintf(ofp, "struct wsdisplay_font %s%dx%d = {\n",
91 fontname, width, height);
92 fprintf(ofp, " \"%s\",\t\t\t/* typeface name */\n", fontname);
93 fprintf(ofp, " 0x%02x,\t\t\t/* firstchar */\n", code_min);
94 fprintf(ofp, " %d,\t\t\t/* numchars */\n", code_max - code_min + 1);
95 fprintf(ofp, " WSDISPLAY_FONTENC_ISO,\t/* encoding */\n");
96 fprintf(ofp, " %d,\t\t\t\t/* width */\n", width);
97 fprintf(ofp, " %d,\t\t\t\t/* height */\n", height);
98 fprintf(ofp, " %d,\t\t\t\t/* stride */\n", width_in_bytes);
99 fprintf(ofp, " WSDISPLAY_FONTENC_L2R,\t/* bit order */\n");
100 fprintf(ofp, " WSDISPLAY_FONTENC_L2R,\t/* byte order */\n");
101 fprintf(ofp, " %s%dx%d_data\t\t/* data */\n",
102 fontname, width, height);
103 fprintf(ofp, "};\n");
107 void
108 fc_rcons(int ac, char* av[])
110 int code;
111 int width_in_bytes;
112 long code_min = 0x10000;
113 long code_max = -1;
115 width_in_bytes = (width + 7) / 8;
117 code = 0;
118 while (1) {
119 int n;
120 int i, j, k;
121 unsigned char buf[200];
123 n = fread(buf, width_in_bytes, height, ifp);
124 if (n != height) {
125 if (!feof(ifp)) {
126 perror("fread()");
127 exit(1);
128 } else {
129 break;
133 fprintf(ofp, "static u_int32_t %s%dx%d_%d_pix[] = {\n",
134 fontname, width, height, code);
136 k = 0;
137 for (i = 0; i < height; i++) {
138 unsigned long d = 0, m;
139 for (j = 0; j < width_in_bytes; j++) {
140 d |= (((unsigned long)buf[k++]) << (24 - 8*j));
142 fprintf(ofp, " 0x%08x, /* ", d);
143 for (m = 0x80000000, j = 0; j < width; j++, m >>= 1) {
144 printf((m & d) ? "##" : "..");
146 fprintf(ofp, " */\n");
148 fprintf(ofp, "};\n");
149 fprintf(ofp, "static struct raster %s%dx%d_%d = {",
150 fontname, width, height, code);
151 fprintf(ofp, " %d, %d, 1, 1, %s%dx%d_%d_pix, 0 };\n",
152 width, height, fontname, width, height, code);
153 if (code < code_min) {
154 code_min = code;
156 if (code_max < code) {
157 code_max = code;
159 code++;
162 fprintf(ofp, "struct raster_font %s%dx%d = {\n",
163 fontname, width, height);
164 fprintf(ofp, " %d, %d, %d, ", width, height, ascent);
165 fprintf(ofp, "RASFONT_FIXEDWIDTH|RASFONT_NOVERTICALMOVEMENT,\n");
166 fprintf(ofp, " {\n");
167 for (code = code_min; code <= code_max; code++) {
168 fprintf(ofp, " { &%s%dx%d_%d, ",
169 fontname, width, height, code);
170 fprintf(ofp, "%d, %d, %d, %d },\n", 0, -ascent, width, 0);
172 fprintf(ofp, " },\n");
173 fprintf(ofp, "#ifdef COLORFONT_CACHE\n");
174 fprintf(ofp, " (struct raster_fontcache*) -1\n");
175 fprintf(ofp, "#endif /*COLORFONT_CACHE*/\n");
176 fprintf(ofp, "};\n");