2 * Copyright (c) 2009 The FreeBSD Foundation
5 * This software was developed by Ed Schouten under sponsorship from the
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/endian.h>
34 #include <sys/param.h>
53 uint32_t map_count[4];
57 print_glyphs(struct file_header *fh)
59 unsigned int gbytes, glyph_count, j, k, total;
62 gbytes = howmany(fh->width, 8) * fh->height;
63 glyph_count = be32toh(fh->glyph_count);
65 printf("\nstatic uint8_t font_bytes[%u * %u] = {", glyph_count, gbytes);
66 total = glyph_count * gbytes;
69 if (fread(gbuf, total, 1, stdin) != 1) {
74 for (j = 0; j < total; j += 12) {
75 for (k = 0; k < 12 && k < total - j; k++) {
76 printf(k == 0 ? "\n\t" : " ");
77 printf("0x%02hhx,", gbuf[j + k]);
87 static const char *map_names[4] = {
88 "normal", "normal_right", "bold", "bold_right" };
91 print_mappings(struct file_header *fh, int map_index)
93 struct file_mapping fm;
94 unsigned int nmappings, i, col = 0;
97 nmappings = be32toh(fh->map_count[map_index]);
102 printf("\nstatic struct vt_font_map font_mapping_%s[%u] = {",
103 map_names[map_index], nmappings);
105 for (i = 0; i < nmappings; i++) {
106 if (fread(&fm, sizeof fm, 1, stdin) != 1) {
111 printf(col == 0 ? "\n\t" : " ");
112 printf("{ 0x%04x, 0x%04x, 0x%02x },",
113 be32toh(fm.source), be16toh(fm.destination),
124 print_info(struct file_header *fh)
129 "\nstruct vt_font vt_font_default = {\n"
130 "\t.vf_width\t\t= %u,\n"
131 "\t.vf_height\t\t= %u,\n"
132 "\t.vf_bytes\t\t= font_bytes,\n",
133 fh->width, fh->height);
135 printf("\t.vf_map\t\t\t= {\n");
136 for (i = 0; i < 4; i++) {
137 if (fh->map_count[i] > 0)
138 printf("\t\t\t\t font_mapping_%s,\n", map_names[i]);
140 printf("\t\t\t\t NULL,\n");
142 printf("\t\t\t\t },\n");
143 printf("\t.vf_map_count\t\t= { %u, %u, %u, %u },\n",
144 be32toh(fh->map_count[0]),
145 be32toh(fh->map_count[1]),
146 be32toh(fh->map_count[2]),
147 be32toh(fh->map_count[3]));
148 printf("\t.vf_refcount\t\t= 1,\n};\n");
154 main(int argc __unused, char *argv[] __unused)
156 struct file_header fh;
159 if (fread(&fh, sizeof fh, 1, stdin) != 1) {
160 perror("file_header");
164 if (memcmp(fh.magic, "VFNT0002", 8) != 0) {
165 fprintf(stderr, "Bad magic\n");
169 printf("#include <dev/vt/vt.h>\n");
171 if (print_glyphs(&fh) != 0)
173 for (i = 0; i < 4; i++)
174 if (print_mappings(&fh, i) != 0)
176 if (print_info(&fh) != 0)