diff options
author | jhb <jhb@FreeBSD.org> | 2014-03-06 18:30:56 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2014-03-06 18:30:56 +0000 |
commit | 59b6242e909c7e020d7903a27847e2a465486a45 (patch) | |
tree | 2c015c503188a6a75426ca67e8433237f3533f97 /tools | |
parent | fe643776c1c5732c2d5d8354a64b520b7007e15c (diff) | |
download | FreeBSD-src-59b6242e909c7e020d7903a27847e2a465486a45.zip FreeBSD-src-59b6242e909c7e020d7903a27847e2a465486a45.tar.gz |
MFC 259016,259019,259049,259071,259102,259110,259129,259130,259178,259179,
259203,259221,259261,259532,259615,259650,259651,259667,259680,259727,
259761,259772,259776,259777,259830,259882,259915,260160,260449,260450,
260688,260888,260953,261269,261547,261551,261552,261553,261585:
Merge the vt(4) driver (newcons) to stable/10.
Approved by: ray
Diffstat (limited to 'tools')
-rw-r--r-- | tools/tools/vt/fontcvt/Makefile | 6 | ||||
-rw-r--r-- | tools/tools/vt/fontcvt/fontcvt.c | 444 | ||||
-rw-r--r-- | tools/tools/vt/fontcvt/terminus.sh | 12 | ||||
-rw-r--r-- | tools/tools/vt/mkkfont/Makefile | 6 | ||||
-rw-r--r-- | tools/tools/vt/mkkfont/mkkfont.c | 180 | ||||
-rw-r--r-- | tools/tools/vt/mkkfont/terminus.sh | 5 | ||||
-rw-r--r-- | tools/tools/vt/setfont/Makefile | 6 | ||||
-rw-r--r-- | tools/tools/vt/setfont/setfont.c | 89 |
8 files changed, 748 insertions, 0 deletions
diff --git a/tools/tools/vt/fontcvt/Makefile b/tools/tools/vt/fontcvt/Makefile new file mode 100644 index 0000000..06692d0 --- /dev/null +++ b/tools/tools/vt/fontcvt/Makefile @@ -0,0 +1,6 @@ +PROG= fontcvt +MAN1= + +WARNS?= 6 + +.include <bsd.prog.mk> diff --git a/tools/tools/vt/fontcvt/fontcvt.c b/tools/tools/vt/fontcvt/fontcvt.c new file mode 100644 index 0000000..74a7c40 --- /dev/null +++ b/tools/tools/vt/fontcvt/fontcvt.c @@ -0,0 +1,444 @@ +/*- + * Copyright (c) 2009 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Ed Schouten under sponsorship from the + * FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/endian.h> +#include <sys/param.h> +#include <sys/queue.h> + +#include <assert.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define VFNT_MAPS 4 +#define VFNT_MAP_NORMAL 0 +#define VFNT_MAP_BOLD 2 + +static unsigned int width, wbytes, height; + +struct glyph { + TAILQ_ENTRY(glyph) g_list; + uint8_t *g_data; + unsigned int g_index; +}; + +TAILQ_HEAD(glyph_list, glyph); +static struct glyph_list glyphs[VFNT_MAPS] = { + TAILQ_HEAD_INITIALIZER(glyphs[0]), + TAILQ_HEAD_INITIALIZER(glyphs[1]), + TAILQ_HEAD_INITIALIZER(glyphs[2]), + TAILQ_HEAD_INITIALIZER(glyphs[3]), +}; +static unsigned int glyph_total, glyph_count[4], glyph_unique, glyph_dupe; + +struct mapping { + TAILQ_ENTRY(mapping) m_list; + unsigned int m_char; + unsigned int m_length; + struct glyph *m_glyph; +}; + +TAILQ_HEAD(mapping_list, mapping); +static struct mapping_list maps[VFNT_MAPS] = { + TAILQ_HEAD_INITIALIZER(maps[0]), + TAILQ_HEAD_INITIALIZER(maps[1]), + TAILQ_HEAD_INITIALIZER(maps[2]), + TAILQ_HEAD_INITIALIZER(maps[3]), +}; +static unsigned int mapping_total, map_count[4], map_folded_count[4], + mapping_unique, mapping_dupe; + +static void +usage(void) +{ + + fprintf(stderr, +"usage: fontcvt width height normal.bdf bold.bdf out.fnt\n"); + exit(1); +} + +static int +add_mapping(struct glyph *gl, unsigned int c, unsigned int map_idx) +{ + struct mapping *mp; + struct mapping_list *ml; + + mapping_total++; + + if (map_idx >= VFNT_MAP_BOLD) { + int found = 0; + unsigned normal_map_idx = map_idx - VFNT_MAP_BOLD; + + TAILQ_FOREACH(mp, &maps[normal_map_idx], m_list) { + if (mp->m_char < c) + continue; + else if (mp->m_char > c) + break; + found = 1; + + /* + * No mapping is needed if it's equal to the + * normal mapping. + */ + if (mp->m_glyph == gl) { + mapping_dupe++; + return (0); + } + } + + if (!found) { + fprintf(stderr, + "Character %u not in normal font!\n", c); + return (1); + } + } + + mp = malloc(sizeof *mp); + mp->m_char = c; + mp->m_glyph = gl; + mp->m_length = 0; + + ml = &maps[map_idx]; + if (TAILQ_LAST(ml, mapping_list) != NULL && + TAILQ_LAST(ml, mapping_list)->m_char >= c) { + fprintf(stderr, "Bad ordering at character %u\n", c); + return (1); + } + TAILQ_INSERT_TAIL(ml, mp, m_list); + + map_count[map_idx]++; + mapping_unique++; + + return (0); +} + +static struct glyph * +add_glyph(const uint8_t *bytes, unsigned int map_idx, int fallback) +{ + struct glyph *gl; + unsigned int i; + + glyph_total++; + glyph_count[map_idx]++; + + for (i = 0; i < VFNT_MAPS; i++) { + TAILQ_FOREACH(gl, &glyphs[i], g_list) { + if (memcmp(gl->g_data, bytes, wbytes * height) == 0) { + glyph_dupe++; + return (gl); + } + } + } + + gl = malloc(sizeof *gl); + gl->g_data = malloc(wbytes * height); + memcpy(gl->g_data, bytes, wbytes * height); + if (fallback) + TAILQ_INSERT_HEAD(&glyphs[map_idx], gl, g_list); + else + TAILQ_INSERT_TAIL(&glyphs[map_idx], gl, g_list); + + glyph_unique++; + return (gl); +} + +static int +parse_bitmap_line(uint8_t *left, uint8_t *right, unsigned int line, + unsigned int dwidth) +{ + uint8_t *p; + unsigned int i, subline; + + if (dwidth != width && dwidth != width * 2) { + fprintf(stderr, + "Unsupported width %u!\n", dwidth); + return (1); + } + + /* Move pixel data right to simplify splitting double characters. */ + line >>= (howmany(dwidth, 8) * 8) - dwidth; + + for (i = dwidth / width; i > 0; i--) { + p = (i == 2) ? right : left; + + subline = line & ((1 << width) - 1); + subline <<= (howmany(width, 8) * 8) - width; + + if (wbytes == 1) { + *p = subline; + } else if (wbytes == 2) { + *p++ = subline >> 8; + *p = subline; + } else { + fprintf(stderr, + "Unsupported wbytes %u!\n", wbytes); + return (1); + } + + line >>= width; + } + + return (0); +} + +static int +parse_bdf(const char *filename, unsigned int map_idx) +{ + FILE *fp; + char *ln; + size_t length; + uint8_t bytes[wbytes * height], bytes_r[wbytes * height]; + unsigned int curchar = 0, dwidth = 0, i, line; + struct glyph *gl; + + fp = fopen(filename, "r"); + if (fp == NULL) { + perror(filename); + return (1); + } + + while ((ln = fgetln(fp, &length)) != NULL) { + ln[length - 1] = '\0'; + + if (strncmp(ln, "ENCODING ", 9) == 0) { + curchar = atoi(ln + 9); + } + + if (strncmp(ln, "DWIDTH ", 7) == 0) { + dwidth = atoi(ln + 7); + } + + if (strcmp(ln, "BITMAP") == 0) { + for (i = 0; i < height; i++) { + if ((ln = fgetln(fp, &length)) == NULL) { + fprintf(stderr, "Unexpected EOF!\n"); + return (1); + } + ln[length - 1] = '\0'; + sscanf(ln, "%x", &line); + if (parse_bitmap_line(bytes + i * wbytes, + bytes_r + i * wbytes, line, dwidth) != 0) + return (1); + } + + /* Prevent adding two glyphs for 0xFFFD */ + if (curchar == 0xFFFD) { + if (map_idx < VFNT_MAP_BOLD) + gl = add_glyph(bytes, 0, 1); + } else if (curchar >= 0x20) { + gl = add_glyph(bytes, map_idx, 0); + if (add_mapping(gl, curchar, map_idx) != 0) + return (1); + if (dwidth == width * 2) { + gl = add_glyph(bytes_r, map_idx + 1, 0); + if (add_mapping(gl, curchar, + map_idx + 1) != 0) + return (1); + } + } + } + } + + return (0); +} + +static void +number_glyphs(void) +{ + struct glyph *gl; + unsigned int i, idx = 0; + + for (i = 0; i < VFNT_MAPS; i++) + TAILQ_FOREACH(gl, &glyphs[i], g_list) + gl->g_index = idx++; +} + +static void +write_glyphs(FILE *fp) +{ + struct glyph *gl; + unsigned int i; + + for (i = 0; i < VFNT_MAPS; i++) { + TAILQ_FOREACH(gl, &glyphs[i], g_list) + fwrite(gl->g_data, wbytes * height, 1, fp); + } +} + +static void +fold_mappings(unsigned int map_idx) +{ + struct mapping_list *ml = &maps[map_idx]; + struct mapping *mn, *mp, *mbase; + + mp = mbase = TAILQ_FIRST(ml); + for (mp = mbase = TAILQ_FIRST(ml); mp != NULL; mp = mn) { + mn = TAILQ_NEXT(mp, m_list); + if (mn != NULL && mn->m_char == mp->m_char + 1 && + mn->m_glyph->g_index == mp->m_glyph->g_index + 1) + continue; + mbase->m_length = mp->m_char - mbase->m_char + 1; + mbase = mp = mn; + map_folded_count[map_idx]++; + } +} + +struct file_mapping { + uint32_t source; + uint16_t destination; + uint16_t length; +} __packed; + +static void +write_mappings(FILE *fp, unsigned int map_idx) +{ + struct mapping_list *ml = &maps[map_idx]; + struct mapping *mp; + struct file_mapping fm; + unsigned int i = 0, j = 0; + + TAILQ_FOREACH(mp, ml, m_list) { + j++; + if (mp->m_length > 0) { + i += mp->m_length; + fm.source = htobe32(mp->m_char); + fm.destination = htobe16(mp->m_glyph->g_index); + fm.length = htobe16(mp->m_length - 1); + fwrite(&fm, sizeof fm, 1, fp); + } + } + assert(i == j); +} + +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 +write_fnt(const char *filename) +{ + FILE *fp; + struct file_header fh = { + .magic = "VFNT0002", + }; + + fp = fopen(filename, "wb"); + if (fp == NULL) { + perror(filename); + return (1); + } + + fh.width = width; + fh.height = height; + fh.glyph_count = htobe32(glyph_unique); + fh.map_count[0] = htobe32(map_folded_count[0]); + fh.map_count[1] = htobe32(map_folded_count[1]); + fh.map_count[2] = htobe32(map_folded_count[2]); + fh.map_count[3] = htobe32(map_folded_count[3]); + fwrite(&fh, sizeof fh, 1, fp); + + write_glyphs(fp); + write_mappings(fp, VFNT_MAP_NORMAL); + write_mappings(fp, 1); + write_mappings(fp, VFNT_MAP_BOLD); + write_mappings(fp, 3); + + return (0); +} + +int +main(int argc, char *argv[]) +{ + + assert(sizeof(struct file_header) == 32); + assert(sizeof(struct file_mapping) == 8); + + if (argc != 6) + usage(); + + width = atoi(argv[1]); + wbytes = howmany(width, 8); + height = atoi(argv[2]); + + if (parse_bdf(argv[3], VFNT_MAP_NORMAL) != 0) + return (1); + if (parse_bdf(argv[4], VFNT_MAP_BOLD) != 0) + return (1); + number_glyphs(); + fold_mappings(0); + fold_mappings(1); + fold_mappings(2); + fold_mappings(3); + if (write_fnt(argv[5]) != 0) + return (1); + + printf( +"Statistics:\n" +"- glyph_total: %5u\n" +"- glyph_normal: %5u\n" +"- glyph_normal_right: %5u\n" +"- glyph_bold: %5u\n" +"- glyph_bold_right: %5u\n" +"- glyph_unique: %5u\n" +"- glyph_dupe: %5u\n" +"- mapping_total: %5u\n" +"- mapping_normal: %5u\n" +"- mapping_normal_folded: %5u\n" +"- mapping_normal_right: %5u\n" +"- mapping_normal_right_folded: %5u\n" +"- mapping_bold: %5u\n" +"- mapping_bold_folded: %5u\n" +"- mapping_bold_right: %5u\n" +"- mapping_bold_right_folded: %5u\n" +"- mapping_unique: %5u\n" +"- mapping_dupe: %5u\n", + glyph_total, + glyph_count[0], + glyph_count[1], + glyph_count[2], + glyph_count[3], + glyph_unique, glyph_dupe, + mapping_total, + map_count[0], map_folded_count[0], + map_count[1], map_folded_count[1], + map_count[2], map_folded_count[2], + map_count[3], map_folded_count[3], + mapping_unique, mapping_dupe); + + return (0); +} diff --git a/tools/tools/vt/fontcvt/terminus.sh b/tools/tools/vt/fontcvt/terminus.sh new file mode 100644 index 0000000..260ee07 --- /dev/null +++ b/tools/tools/vt/fontcvt/terminus.sh @@ -0,0 +1,12 @@ +#!/bin/sh +for i in 6:12 8:14 8:16 10:18 10:20 11:22 12:24 14:28 16:32 +do + C=`echo $i | cut -f 1 -d :` + R=`echo $i | cut -f 2 -d :` + ./fontcvt \ + $C $R \ + ~/terminus-font-4.36/ter-u${R}n.bdf \ + ~/terminus-font-4.36/ter-u${R}b.bdf \ + terminus-u${R}.vfnt + gzip -9nf terminus-u${R}.vfnt +done diff --git a/tools/tools/vt/mkkfont/Makefile b/tools/tools/vt/mkkfont/Makefile new file mode 100644 index 0000000..d963d83 --- /dev/null +++ b/tools/tools/vt/mkkfont/Makefile @@ -0,0 +1,6 @@ +PROG= mkkfont +MAN1= + +WARNS?= 6 + +.include <bsd.prog.mk> diff --git a/tools/tools/vt/mkkfont/mkkfont.c b/tools/tools/vt/mkkfont/mkkfont.c new file mode 100644 index 0000000..7700e9c --- /dev/null +++ b/tools/tools/vt/mkkfont/mkkfont.c @@ -0,0 +1,180 @@ +/*- + * Copyright (c) 2009 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Ed Schouten under sponsorship from the + * FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/endian.h> +#include <sys/param.h> + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.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 +print_glyphs(struct file_header *fh) +{ + unsigned int gbytes, glyph_count, j, k, total; + uint8_t *gbuf; + + gbytes = howmany(fh->width, 8) * fh->height; + glyph_count = be32toh(fh->glyph_count); + + printf("\nstatic uint8_t font_bytes[%u * %u] = {", glyph_count, gbytes); + total = glyph_count * gbytes; + gbuf = malloc(total); + + if (fread(gbuf, total, 1, stdin) != 1) { + perror("glyph"); + return (1); + } + + for (j = 0; j < total; j += 12) { + for (k = 0; k < 12 && k < total - j; k++) { + printf(k == 0 ? "\n\t" : " "); + printf("0x%02hhx,", gbuf[j + k]); + } + } + + free(gbuf); + printf("\n};\n"); + + return (0); +} + +static const char *map_names[4] = { + "normal", "normal_right", "bold", "bold_right" }; + +static int +print_mappings(struct file_header *fh, int map_index) +{ + struct file_mapping fm; + unsigned int nmappings, i, col = 0; + + + nmappings = be32toh(fh->map_count[map_index]); + + if (nmappings == 0) + return (0); + + printf("\nstatic struct vt_font_map font_mapping_%s[%u] = {", + map_names[map_index], nmappings); + + for (i = 0; i < nmappings; i++) { + if (fread(&fm, sizeof fm, 1, stdin) != 1) { + perror("mapping"); + return (1); + } + + printf(col == 0 ? "\n\t" : " "); + printf("{ 0x%04x, 0x%04x, 0x%02x },", + be32toh(fm.source), be16toh(fm.destination), + be16toh(fm.length)); + col = (col + 1) % 2; + } + + printf("\n};\n"); + + return (0); +} + +static int +print_info(struct file_header *fh) +{ + unsigned int i; + + printf( + "\nstruct vt_font vt_font_default = {\n" + "\t.vf_width\t\t= %u,\n" + "\t.vf_height\t\t= %u,\n" + "\t.vf_bytes\t\t= font_bytes,\n", + fh->width, fh->height); + + printf("\t.vf_map\t\t\t= {\n"); + for (i = 0; i < 4; i++) { + if (fh->map_count[i] > 0) + printf("\t\t\t\t font_mapping_%s,\n", map_names[i]); + else + printf("\t\t\t\t NULL,\n"); + } + printf("\t\t\t\t }\n"); + printf("\t.vf_map_count\t\t= { %u, %u, %u, %u },\n", + be32toh(fh->map_count[0]), + be32toh(fh->map_count[1]), + be32toh(fh->map_count[2]), + be32toh(fh->map_count[3])); + printf("\t.vf_refcount\t\t= 1,\n};\n"); + + return (0); +} + +int +main(int argc __unused, char *argv[] __unused) +{ + struct file_header fh; + unsigned int i; + + if (fread(&fh, sizeof fh, 1, stdin) != 1) { + perror("file_header"); + return (1); + } + + if (memcmp(fh.magic, "VFNT0002", 8) != 0) { + fprintf(stderr, "Bad magic\n"); + return (1); + } + + printf("#include <dev/vt/vt.h>\n"); + + if (print_glyphs(&fh) != 0) + return (1); + for (i = 0; i < 4; i++) + if (print_mappings(&fh, i) != 0) + return (1); + if (print_info(&fh) != 0) + return (1); + + return (0); +} diff --git a/tools/tools/vt/mkkfont/terminus.sh b/tools/tools/vt/mkkfont/terminus.sh new file mode 100644 index 0000000..2f5863a --- /dev/null +++ b/tools/tools/vt/mkkfont/terminus.sh @@ -0,0 +1,5 @@ +#!/bin/sh +for i in 12 14 16 20 22 24 28 32 +do + zcat ../fontcvt/terminus-u${i}.vfnt.gz | ./mkkfont > terminus-u${i}.c +done diff --git a/tools/tools/vt/setfont/Makefile b/tools/tools/vt/setfont/Makefile new file mode 100644 index 0000000..a242d51 --- /dev/null +++ b/tools/tools/vt/setfont/Makefile @@ -0,0 +1,6 @@ +PROG= setfont +MAN1= + +WARNS?= 6 + +.include <bsd.prog.mk> diff --git a/tools/tools/vt/setfont/setfont.c b/tools/tools/vt/setfont/setfont.c new file mode 100644 index 0000000..127fad3 --- /dev/null +++ b/tools/tools/vt/setfont/setfont.c @@ -0,0 +1,89 @@ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/consio.h> +#include <sys/endian.h> +#include <sys/ioctl.h> +#include <sys/param.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +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 vfnt_map_t * +load_mappingtable(unsigned int nmappings) +{ + vfnt_map_t *t; + unsigned int i; + + if (nmappings == 0) + return (NULL); + + t = malloc(sizeof *t * nmappings); + + if (fread(t, sizeof *t * nmappings, 1, stdin) != 1) { + perror("mappings"); + exit(1); + } + + for (i = 0; i < nmappings; i++) { + t[i].src = be32toh(t[i].src); + t[i].dst = be16toh(t[i].dst); + t[i].len = be16toh(t[i].len); + } + + return (t); +} + +int +main(int argc __unused, char *argv[] __unused) +{ + struct file_header fh; + static vfnt_t vfnt; + size_t glyphsize; + unsigned int i; + + if (fread(&fh, sizeof fh, 1, stdin) != 1) { + perror("file_header"); + return (1); + } + + if (memcmp(fh.magic, "VFNT0002", 8) != 0) { + fprintf(stderr, "Bad magic\n"); + return (1); + } + + for (i = 0; i < VFNT_MAPS; i++) + vfnt.map_count[i] = be32toh(fh.map_count[i]); + vfnt.glyph_count = be32toh(fh.glyph_count); + vfnt.width = fh.width; + vfnt.height = fh.height; + + glyphsize = howmany(vfnt.width, 8) * vfnt.height * vfnt.glyph_count; + vfnt.glyphs = malloc(glyphsize); + + if (fread(vfnt.glyphs, glyphsize, 1, stdin) != 1) { + perror("glyphs"); + return (1); + } + + for (i = 0; i < VFNT_MAPS; i++) + vfnt.map[i] = load_mappingtable(vfnt.map_count[i]); + + if (ioctl(STDOUT_FILENO, PIO_VFONT, &vfnt) == -1) { + perror("PIO_VFONT"); + return (1); + } + + return (0); +} |