summaryrefslogtreecommitdiff
path: root/sys/dev/hpc/fontconv.c
blob: 046d5d4271ac111cf0b836a48a82a7c5f6ef2f94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*	$NetBSD: fontconv.c,v 1.3 2001/11/13 12:47:56 lukem Exp $	*/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fontconv.c,v 1.3 2001/11/13 12:47:56 lukem Exp $");

#include <stdio.h>


int width, height, ascent;
char *fontname;
FILE *ifp;
FILE *ofp;


void fc_rcons(int ac, char* av[]);
void fc_rasops(int ac, char* av[]);


main(int ac, char* av[])
{
	ifp = stdin;
	ofp = stdout;
	width = 8;
	height = 8;
	ascent = 8;
	fontname = "vt220l";

	/*
	  fc_rcons(ac, av);
	*/
	fc_rasops(ac, av);
}


void
fc_rasops(int ac, char* av[])
{
	int code;
	int width_in_bytes;
	long code_min = 0x10000;
	long code_max = -1;

	width_in_bytes = (width + 7) / 8;

	code = 0;
	fprintf(ofp, "static u_char %s%dx%d_data[] = {\n",
	    fontname, width, height, code);
	while (1) {
		int n;
		int i, j, k;
		unsigned char buf[200];

		n = fread(buf, width_in_bytes, height, ifp);
		if (n != height) {
			if (!feof(ifp)) {
				perror("fread()");
				exit(1);
			} else {
				break;
			}
		}

		k = 0;
		fprintf(ofp, "    /* code %d */\n", code);
		for (i = 0; i < height; i++) {
			unsigned long d = 0, m;
			fprintf(ofp, "    ");
			for (j = 0; j < width_in_bytes; j++) {
				d |= (((unsigned long)buf[k]) << (24 - 8*j));
				fprintf(ofp, "0x%02x,", (buf[k] & 0xff));
				k++;
			}
			fprintf(ofp, " /* ");
			for (m = 0x80000000, j = 0; j < width; j++, m >>= 1) {
				printf((m & d) ? "##" : "..");
			}
			fprintf(ofp, " */\n");
		}
		fprintf(ofp, "\n");
		if (code < code_min) {
			code_min = code;
		}
		if (code_max < code) {
			code_max = code;
		}
		code++;
	}
	fprintf(ofp, "};\n");

	fprintf(ofp, "struct wsdisplay_font %s%dx%d = {\n",
	    fontname, width, height);
	fprintf(ofp, "    \"%s\",\t\t\t/* typeface name */\n", fontname);
	fprintf(ofp, "    0x%02x,\t\t\t/* firstchar */\n", code_min);
	fprintf(ofp, "    %d,\t\t\t/* numchars */\n", code_max - code_min + 1);
	fprintf(ofp, "    WSDISPLAY_FONTENC_ISO,\t/* encoding */\n");
	fprintf(ofp, "    %d,\t\t\t\t/* width */\n", width);
	fprintf(ofp, "    %d,\t\t\t\t/* height */\n", height);
	fprintf(ofp, "    %d,\t\t\t\t/* stride */\n", width_in_bytes);
	fprintf(ofp, "    WSDISPLAY_FONTENC_L2R,\t/* bit order */\n");
	fprintf(ofp, "    WSDISPLAY_FONTENC_L2R,\t/* byte order */\n");
	fprintf(ofp, "    %s%dx%d_data\t\t/* data */\n",
	    fontname, width, height);
	fprintf(ofp, "};\n");
}


void
fc_rcons(int ac, char* av[])
{
	int code;
	int width_in_bytes;
	long code_min = 0x10000;
	long code_max = -1;

	width_in_bytes = (width + 7) / 8;

	code = 0;
	while (1) {
		int n;
		int i, j, k;
		unsigned char buf[200];

		n = fread(buf, width_in_bytes, height, ifp);
		if (n != height) {
			if (!feof(ifp)) {
				perror("fread()");
				exit(1);
			} else {
				break;
			}
		}

		fprintf(ofp, "static u_int32_t %s%dx%d_%d_pix[] = {\n",
		    fontname, width, height, code);

		k = 0;
		for (i = 0; i < height; i++) {
			unsigned long d = 0, m;
			for (j = 0; j < width_in_bytes; j++) {
				d |= (((unsigned long)buf[k++]) << (24 - 8*j));
			}
			fprintf(ofp, "    0x%08x, /* ", d);
			for (m = 0x80000000, j = 0; j < width; j++, m >>= 1) {
				printf((m & d) ? "##" : "..");
			}
			fprintf(ofp, " */\n");
		}
		fprintf(ofp, "};\n");
		fprintf(ofp, "static struct raster %s%dx%d_%d = {",
		    fontname, width, height, code);
		fprintf(ofp, " %d, %d, 1, 1, %s%dx%d_%d_pix, 0 };\n",
		    width, height, fontname, width, height, code);
		if (code < code_min) {
			code_min = code;
		}
		if (code_max < code) {
			code_max = code;
		}
		code++;
	}

	fprintf(ofp, "struct raster_font %s%dx%d = {\n",
	    fontname, width, height);
	fprintf(ofp, "    %d, %d, %d, ", width, height, ascent);
	fprintf(ofp, "RASFONT_FIXEDWIDTH|RASFONT_NOVERTICALMOVEMENT,\n");
	fprintf(ofp, "    {\n");
	for (code = code_min; code <= code_max; code++) {
		fprintf(ofp, "        { &%s%dx%d_%d, ",
		    fontname, width, height, code);
		fprintf(ofp, "%d, %d, %d, %d },\n", 0, -ascent, width, 0);
	}
	fprintf(ofp, "    },\n");
	fprintf(ofp, "#ifdef COLORFONT_CACHE\n");
	fprintf(ofp, "    (struct raster_fontcache*) -1\n");
	fprintf(ofp, "#endif /*COLORFONT_CACHE*/\n");
	fprintf(ofp, "};\n");
}