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