Changeset View
Changeset View
Standalone View
Standalone View
tools/tools/vt/mkkfont/mkkfont.c
Show All 26 Lines | |||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/endian.h> | #include <sys/endian.h> | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/font.h> | |||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
struct file_mapping { | |||||
uint32_t source; | |||||
uint16_t destination; | |||||
uint16_t length; | |||||
} __packed; | |||||
struct file_header { | |||||
uint8_t magic[8]; | |||||
uint8_t width; | |||||
uint8_t height; | |||||
uint16_t pad; | |||||
uint32_t glyph_count; | |||||
uint32_t map_count[4]; | |||||
} __packed; | |||||
static int | static int | ||||
print_glyphs(struct file_header *fh) | print_glyphs(struct font_header *fh) | ||||
{ | { | ||||
unsigned int gbytes, glyph_count, j, k, total; | unsigned int gbytes, glyph_count, j, k, total; | ||||
uint8_t *gbuf; | uint8_t *gbuf; | ||||
gbytes = howmany(fh->width, 8) * fh->height; | gbytes = howmany(fh->fh_width, 8) * fh->fh_height; | ||||
glyph_count = be32toh(fh->glyph_count); | glyph_count = be32toh(fh->fh_glyph_count); | ||||
printf("\nstatic uint8_t font_bytes[%u * %u] = {", glyph_count, gbytes); | printf("\nstatic uint8_t font_bytes[%u * %u] = {", glyph_count, gbytes); | ||||
total = glyph_count * gbytes; | total = glyph_count * gbytes; | ||||
gbuf = malloc(total); | gbuf = malloc(total); | ||||
if (fread(gbuf, total, 1, stdin) != 1) { | if (fread(gbuf, total, 1, stdin) != 1) { | ||||
perror("glyph"); | perror("glyph"); | ||||
return (1); | return (1); | ||||
Show All 11 Lines | print_glyphs(struct font_header *fh) | ||||
return (0); | return (0); | ||||
} | } | ||||
static const char *map_names[4] = { | static const char *map_names[4] = { | ||||
"normal", "normal_right", "bold", "bold_right" }; | "normal", "normal_right", "bold", "bold_right" }; | ||||
static int | static int | ||||
print_mappings(struct file_header *fh, int map_index) | print_mappings(struct font_header *fh, int map_index) | ||||
{ | { | ||||
struct file_mapping fm; | vfnt_map_t fm; | ||||
unsigned int nmappings, i, col = 0; | unsigned int nmappings, i, col = 0; | ||||
nmappings = be32toh(fh->map_count[map_index]); | nmappings = be32toh(fh->fh_map_count[map_index]); | ||||
if (nmappings == 0) | if (nmappings == 0) | ||||
return (0); | return (0); | ||||
printf("\nstatic struct vt_font_map font_mapping_%s[%u] = {", | printf("\nstatic vfnt_map_t font_mapping_%s[%u] = {", | ||||
map_names[map_index], nmappings); | map_names[map_index], nmappings); | ||||
for (i = 0; i < nmappings; i++) { | for (i = 0; i < nmappings; i++) { | ||||
if (fread(&fm, sizeof fm, 1, stdin) != 1) { | if (fread(&fm, sizeof fm, 1, stdin) != 1) { | ||||
perror("mapping"); | perror("mapping"); | ||||
return (1); | return (1); | ||||
} | } | ||||
printf(col == 0 ? "\n\t" : " "); | printf(col == 0 ? "\n\t" : " "); | ||||
printf("{ 0x%04x, 0x%04x, 0x%02x },", | printf("{ 0x%04x, 0x%04x, 0x%02x },", | ||||
be32toh(fm.source), be16toh(fm.destination), | be32toh(fm.vfm_src), be16toh(fm.vfm_dst), | ||||
be16toh(fm.length)); | be16toh(fm.vfm_len)); | ||||
col = (col + 1) % 2; | col = (col + 1) % 2; | ||||
} | } | ||||
printf("\n};\n"); | printf("\n};\n"); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
print_info(struct file_header *fh) | print_info(struct font_header *fh) | ||||
{ | { | ||||
unsigned int i; | unsigned int i; | ||||
printf( | printf( | ||||
"\nstruct vt_font vt_font_default = {\n" | "\nstruct vt_font vt_font_default = {\n" | ||||
"\t.vf_width\t\t= %u,\n" | "\t.vf_width\t\t= %u,\n" | ||||
"\t.vf_height\t\t= %u,\n" | "\t.vf_height\t\t= %u,\n" | ||||
"\t.vf_bytes\t\t= font_bytes,\n", | "\t.vf_bytes\t\t= font_bytes,\n", | ||||
fh->width, fh->height); | fh->fh_width, fh->fh_height); | ||||
printf("\t.vf_map\t\t\t= {\n"); | printf("\t.vf_map\t\t\t= {\n"); | ||||
for (i = 0; i < 4; i++) { | for (i = 0; i < 4; i++) { | ||||
if (fh->map_count[i] > 0) | if (fh->fh_map_count[i] > 0) | ||||
printf("\t\t\t\t font_mapping_%s,\n", map_names[i]); | printf("\t\t\t\t font_mapping_%s,\n", map_names[i]); | ||||
else | else | ||||
printf("\t\t\t\t NULL,\n"); | printf("\t\t\t\t NULL,\n"); | ||||
} | } | ||||
printf("\t\t\t\t },\n"); | printf("\t\t\t\t },\n"); | ||||
printf("\t.vf_map_count\t\t= { %u, %u, %u, %u },\n", | printf("\t.vf_map_count\t\t= { %u, %u, %u, %u },\n", | ||||
be32toh(fh->map_count[0]), | be32toh(fh->fh_map_count[0]), | ||||
be32toh(fh->map_count[1]), | be32toh(fh->fh_map_count[1]), | ||||
be32toh(fh->map_count[2]), | be32toh(fh->fh_map_count[2]), | ||||
be32toh(fh->map_count[3])); | be32toh(fh->fh_map_count[3])); | ||||
printf("\t.vf_refcount\t\t= 1,\n};\n"); | printf("\t.vf_refcount\t\t= 1,\n};\n"); | ||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
main(int argc __unused, char *argv[] __unused) | main(int argc __unused, char *argv[] __unused) | ||||
{ | { | ||||
struct file_header fh; | struct font_header fh; | ||||
unsigned int i; | unsigned int i; | ||||
if (fread(&fh, sizeof fh, 1, stdin) != 1) { | if (fread(&fh, sizeof fh, 1, stdin) != 1) { | ||||
perror("file_header"); | perror("font_header"); | ||||
return (1); | return (1); | ||||
} | } | ||||
if (memcmp(fh.magic, "VFNT0002", 8) != 0) { | if (memcmp(fh.fh_magic, "VFNT0002", 8) != 0) { | ||||
fprintf(stderr, "Bad magic\n"); | fprintf(stderr, "Bad magic\n"); | ||||
return (1); | return (1); | ||||
} | } | ||||
printf("#include <dev/vt/vt.h>\n"); | printf("#include <dev/vt/vt.h>\n"); | ||||
if (print_glyphs(&fh) != 0) | if (print_glyphs(&fh) != 0) | ||||
return (1); | return (1); | ||||
for (i = 0; i < 4; i++) | for (i = 0; i < 4; i++) | ||||
if (print_mappings(&fh, i) != 0) | if (print_mappings(&fh, i) != 0) | ||||
return (1); | return (1); | ||||
if (print_info(&fh) != 0) | if (print_info(&fh) != 0) | ||||
return (1); | return (1); | ||||
return (0); | return (0); | ||||
} | } |