mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-21 09:13:37 +00:00
Support double-width characters in vt(9)
Normal and bold fonts each have a glyph map for single or left half- glyphs, and right half glyphs. The flag TF_CJK_RIGHT in term_char_t requests the right half-glyph. Reviewed by: ed@ Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
2b22d5cc07
commit
41fb066511
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=259680
|
@ -2194,9 +2194,8 @@ struct vt_font vt_font_default = {
|
|||
.vf_width = 8,
|
||||
.vf_height = 16,
|
||||
.vf_bytes = font_bytes,
|
||||
.vf_normal = font_mapping_normal,
|
||||
.vf_normal_length = 248,
|
||||
.vf_bold = font_mapping_bold,
|
||||
.vf_bold_length = 260,
|
||||
.vf_map = { font_mapping_normal, NULL,
|
||||
font_mapping_bold, NULL },
|
||||
.vf_map_count = { 248, 0, 260, 0 },
|
||||
.vf_refcount = 1,
|
||||
};
|
||||
|
|
|
@ -388,11 +388,10 @@ struct vt_font_map {
|
|||
};
|
||||
|
||||
struct vt_font {
|
||||
struct vt_font_map *vf_bold;
|
||||
struct vt_font_map *vf_normal;
|
||||
struct vt_font_map *vf_map[VFNT_MAPS];
|
||||
uint8_t *vf_bytes;
|
||||
unsigned int vf_height, vf_width,
|
||||
vf_normal_length, vf_bold_length;
|
||||
unsigned int vf_height, vf_width;
|
||||
unsigned int vf_map_count[VFNT_MAPS];
|
||||
unsigned int vf_refcount;
|
||||
};
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$");
|
|||
static MALLOC_DEFINE(M_VTFONT, "vtfont", "vt font");
|
||||
|
||||
/* Some limits to prevent abnormal fonts from being loaded. */
|
||||
#define VTFONT_MAXMAPPINGS 1024
|
||||
#define VTFONT_MAXMAPPINGS 8192
|
||||
#define VTFONT_MAXGLYPHSIZE 262144
|
||||
#define VTFONT_MAXDIMENSION 128
|
||||
|
||||
|
@ -86,6 +86,8 @@ vtfont_lookup(const struct vt_font *vf, term_char_t c)
|
|||
uint32_t src;
|
||||
uint16_t dst;
|
||||
size_t stride;
|
||||
unsigned int normal_map;
|
||||
unsigned int bold_map;
|
||||
|
||||
/*
|
||||
* No support for printing right hand sides for CJK fullwidth
|
||||
|
@ -93,15 +95,22 @@ vtfont_lookup(const struct vt_font *vf, term_char_t c)
|
|||
* hand side describes the entire character.
|
||||
*/
|
||||
src = TCHAR_CHARACTER(c);
|
||||
if (TCHAR_FORMAT(c) & TF_CJK_RIGHT)
|
||||
src = ' ';
|
||||
if (TCHAR_FORMAT(c) & TF_CJK_RIGHT) {
|
||||
normal_map = VFNT_MAP_NORMAL_RIGHT;
|
||||
bold_map = VFNT_MAP_BOLD_RIGHT;
|
||||
} else {
|
||||
normal_map = VFNT_MAP_NORMAL;
|
||||
bold_map = VFNT_MAP_BOLD;
|
||||
}
|
||||
|
||||
if (TCHAR_FORMAT(c) & TF_BOLD) {
|
||||
dst = vtfont_bisearch(vf->vf_bold, vf->vf_bold_length, src);
|
||||
dst = vtfont_bisearch(vf->vf_map[bold_map],
|
||||
vf->vf_map_count[bold_map], src);
|
||||
if (dst != 0)
|
||||
goto found;
|
||||
}
|
||||
dst = vtfont_bisearch(vf->vf_normal, vf->vf_normal_length, src);
|
||||
dst = vtfont_bisearch(vf->vf_map[normal_map],
|
||||
vf->vf_map_count[normal_map], src);
|
||||
|
||||
found:
|
||||
stride = howmany(vf->vf_width, 8) * vf->vf_height;
|
||||
|
@ -119,10 +128,11 @@ vtfont_ref(struct vt_font *vf)
|
|||
void
|
||||
vtfont_unref(struct vt_font *vf)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if (refcount_release(&vf->vf_refcount)) {
|
||||
free(vf->vf_normal, M_VTFONT);
|
||||
free(vf->vf_bold, M_VTFONT);
|
||||
for (i = 0; i < VFNT_MAPS; i++)
|
||||
free(vf->vf_map[i], M_VTFONT);
|
||||
free(vf->vf_bytes, M_VTFONT);
|
||||
free(vf, M_VTFONT);
|
||||
}
|
||||
|
@ -130,7 +140,7 @@ vtfont_unref(struct vt_font *vf)
|
|||
|
||||
static int
|
||||
vtfont_validate_map(struct vt_font_map *vfm, unsigned int length,
|
||||
unsigned int nglyphs)
|
||||
unsigned int glyph_count)
|
||||
{
|
||||
unsigned int i, last = 0;
|
||||
|
||||
|
@ -141,8 +151,8 @@ vtfont_validate_map(struct vt_font_map *vfm, unsigned int length,
|
|||
/*
|
||||
* Destination extends amount of glyphs.
|
||||
*/
|
||||
if (vfm[i].vfm_dst >= nglyphs ||
|
||||
vfm[i].vfm_dst + vfm[i].vfm_len >= nglyphs)
|
||||
if (vfm[i].vfm_dst >= glyph_count ||
|
||||
vfm[i].vfm_dst + vfm[i].vfm_len >= glyph_count)
|
||||
return (EINVAL);
|
||||
last = vfm[i].vfm_src + vfm[i].vfm_len;
|
||||
}
|
||||
|
@ -153,9 +163,10 @@ vtfont_validate_map(struct vt_font_map *vfm, unsigned int length,
|
|||
int
|
||||
vtfont_load(vfnt_t *f, struct vt_font **ret)
|
||||
{
|
||||
size_t glyphsize;
|
||||
size_t glyphsize, mapsize;
|
||||
struct vt_font *vf;
|
||||
int error;
|
||||
unsigned int i;
|
||||
|
||||
/* Make sure the dimensions are valid. */
|
||||
if (f->width < 1 || f->height < 1)
|
||||
|
@ -164,50 +175,43 @@ vtfont_load(vfnt_t *f, struct vt_font **ret)
|
|||
return (E2BIG);
|
||||
|
||||
/* Not too many mappings. */
|
||||
if (f->nnormal > VTFONT_MAXMAPPINGS || f->nbold > VTFONT_MAXMAPPINGS)
|
||||
for (i = 0; i < VFNT_MAPS; i++)
|
||||
if (f->map_count[i] > VTFONT_MAXMAPPINGS)
|
||||
return (E2BIG);
|
||||
|
||||
/* Character 0 must always be present. */
|
||||
if (f->nglyphs < 1)
|
||||
if (f->glyph_count < 1)
|
||||
return (EINVAL);
|
||||
|
||||
glyphsize = howmany(f->width, 8) * f->height * f->nglyphs;
|
||||
glyphsize = howmany(f->width, 8) * f->height * f->glyph_count;
|
||||
if (glyphsize > VTFONT_MAXGLYPHSIZE)
|
||||
return (E2BIG);
|
||||
|
||||
/* Allocate new font structure. */
|
||||
vf = malloc(sizeof *vf, M_VTFONT, M_WAITOK);
|
||||
vf->vf_normal = malloc(f->nnormal * sizeof(struct vt_font_map),
|
||||
M_VTFONT, M_WAITOK);
|
||||
vf->vf_bold = malloc(f->nbold * sizeof(struct vt_font_map),
|
||||
M_VTFONT, M_WAITOK);
|
||||
vf = malloc(sizeof *vf, M_VTFONT, M_WAITOK | M_ZERO);
|
||||
vf->vf_bytes = malloc(glyphsize, M_VTFONT, M_WAITOK);
|
||||
vf->vf_height = f->height;
|
||||
vf->vf_width = f->width;
|
||||
vf->vf_normal_length = f->nnormal;
|
||||
vf->vf_bold_length = f->nbold;
|
||||
vf->vf_refcount = 1;
|
||||
|
||||
/* Copy in data. */
|
||||
error = copyin(f->normal, vf->vf_normal,
|
||||
vf->vf_normal_length * sizeof(struct vt_font_map));
|
||||
/* Allocate, copy in, and validate mappings. */
|
||||
for (i = 0; i < VFNT_MAPS; i++) {
|
||||
vf->vf_map_count[i] = f->map_count[i];
|
||||
if (f->map_count[i] == 0)
|
||||
continue;
|
||||
mapsize = f->map_count[i] * sizeof(struct vt_font_map);
|
||||
vf->vf_map[i] = malloc(mapsize, M_VTFONT, M_WAITOK);
|
||||
error = copyin(f->map[i], vf->vf_map[i], mapsize);
|
||||
if (error)
|
||||
goto bad;
|
||||
error = copyin(f->bold, vf->vf_bold,
|
||||
vf->vf_bold_length * sizeof(struct vt_font_map));
|
||||
if (error)
|
||||
goto bad;
|
||||
error = copyin(f->glyphs, vf->vf_bytes, glyphsize);
|
||||
error = vtfont_validate_map(vf->vf_map[i], vf->vf_map_count[i],
|
||||
f->glyph_count);
|
||||
if (error)
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/* Validate mappings. */
|
||||
error = vtfont_validate_map(vf->vf_normal, vf->vf_normal_length,
|
||||
f->nglyphs);
|
||||
if (error)
|
||||
goto bad;
|
||||
error = vtfont_validate_map(vf->vf_bold, vf->vf_bold_length,
|
||||
f->nglyphs);
|
||||
/* Copy in glyph data. */
|
||||
error = copyin(f->glyphs, vf->vf_bytes, glyphsize);
|
||||
if (error)
|
||||
goto bad;
|
||||
|
||||
|
|
|
@ -216,13 +216,16 @@ struct vfnt_map {
|
|||
};
|
||||
typedef struct vfnt_map vfnt_map_t;
|
||||
|
||||
#define VFNT_MAP_NORMAL 0
|
||||
#define VFNT_MAP_NORMAL_RIGHT 1
|
||||
#define VFNT_MAP_BOLD 2
|
||||
#define VFNT_MAP_BOLD_RIGHT 3
|
||||
#define VFNT_MAPS 4
|
||||
struct vfnt {
|
||||
vfnt_map_t *normal;
|
||||
vfnt_map_t *bold;
|
||||
vfnt_map_t *map[VFNT_MAPS];
|
||||
uint8_t *glyphs;
|
||||
unsigned int nnormal;
|
||||
unsigned int nbold;
|
||||
unsigned int nglyphs;
|
||||
unsigned int map_count[VFNT_MAPS];
|
||||
unsigned int glyph_count;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
};
|
||||
|
|
|
@ -40,6 +40,10 @@ __FBSDID("$FreeBSD$");
|
|||
#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 {
|
||||
|
@ -48,9 +52,14 @@ struct glyph {
|
|||
unsigned int g_index;
|
||||
};
|
||||
|
||||
static TAILQ_HEAD(, glyph) glyph_list = TAILQ_HEAD_INITIALIZER(glyph_list);
|
||||
static unsigned int glyph_total, glyph_normal, glyph_bold,
|
||||
glyph_unique, glyph_dupe;
|
||||
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;
|
||||
|
@ -60,12 +69,14 @@ struct mapping {
|
|||
};
|
||||
|
||||
TAILQ_HEAD(mapping_list, mapping);
|
||||
static struct mapping_list mapping_list_normal =
|
||||
TAILQ_HEAD_INITIALIZER(mapping_list_normal);
|
||||
static struct mapping_list mapping_list_bold =
|
||||
TAILQ_HEAD_INITIALIZER(mapping_list_bold);
|
||||
static unsigned int mapping_total, mapping_normal, mapping_normal_folded,
|
||||
mapping_bold, mapping_bold_folded, mapping_unique, mapping_dupe;
|
||||
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)
|
||||
|
@ -77,17 +88,18 @@ usage(void)
|
|||
}
|
||||
|
||||
static int
|
||||
add_mapping(struct glyph *gl, unsigned int c, int bold)
|
||||
add_mapping(struct glyph *gl, unsigned int c, unsigned int map_idx)
|
||||
{
|
||||
struct mapping *mp;
|
||||
struct mapping_list *ml;
|
||||
|
||||
mapping_total++;
|
||||
|
||||
if (bold) {
|
||||
if (map_idx >= VFNT_MAP_BOLD) {
|
||||
int found = 0;
|
||||
unsigned normal_map_idx = map_idx - VFNT_MAP_BOLD;
|
||||
|
||||
TAILQ_FOREACH(mp, &mapping_list_normal, m_list) {
|
||||
TAILQ_FOREACH(mp, &maps[normal_map_idx], m_list) {
|
||||
if (mp->m_char < c)
|
||||
continue;
|
||||
else if (mp->m_char > c)
|
||||
|
@ -116,7 +128,7 @@ add_mapping(struct glyph *gl, unsigned int c, int bold)
|
|||
mp->m_glyph = gl;
|
||||
mp->m_length = 0;
|
||||
|
||||
ml = bold ? &mapping_list_bold : &mapping_list_normal;
|
||||
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);
|
||||
|
@ -124,53 +136,89 @@ add_mapping(struct glyph *gl, unsigned int c, int bold)
|
|||
}
|
||||
TAILQ_INSERT_TAIL(ml, mp, m_list);
|
||||
|
||||
if (bold)
|
||||
mapping_bold++;
|
||||
else
|
||||
mapping_normal++;
|
||||
map_count[map_idx]++;
|
||||
mapping_unique++;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static struct glyph *
|
||||
add_glyph(const uint8_t *bytes, int bold, int fallback)
|
||||
add_glyph(const uint8_t *bytes, unsigned int map_idx, int fallback)
|
||||
{
|
||||
struct glyph *gl;
|
||||
unsigned int i;
|
||||
|
||||
glyph_total++;
|
||||
if (bold)
|
||||
glyph_bold++;
|
||||
else
|
||||
glyph_normal++;
|
||||
glyph_count[map_idx]++;
|
||||
|
||||
TAILQ_FOREACH(gl, &glyph_list, g_list) {
|
||||
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(&glyph_list, gl, g_list);
|
||||
TAILQ_INSERT_HEAD(&glyphs[map_idx], gl, g_list);
|
||||
else
|
||||
TAILQ_INSERT_TAIL(&glyph_list, gl, g_list);
|
||||
TAILQ_INSERT_TAIL(&glyphs[map_idx], gl, g_list);
|
||||
|
||||
glyph_unique++;
|
||||
return (gl);
|
||||
}
|
||||
|
||||
static int
|
||||
parse_bdf(const char *filename, int bold __unused)
|
||||
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];
|
||||
unsigned int curchar = 0, i, line;
|
||||
uint8_t bytes[wbytes * height], bytes_r[wbytes * height];
|
||||
unsigned int curchar = 0, dwidth = 0, i, line;
|
||||
struct glyph *gl;
|
||||
|
||||
fp = fopen(filename, "r");
|
||||
|
@ -186,6 +234,10 @@ parse_bdf(const char *filename, int bold __unused)
|
|||
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) {
|
||||
|
@ -194,26 +246,25 @@ parse_bdf(const char *filename, int bold __unused)
|
|||
}
|
||||
ln[length - 1] = '\0';
|
||||
sscanf(ln, "%x", &line);
|
||||
if (wbytes == 1) {
|
||||
bytes[i] = line;
|
||||
} else if (wbytes == 2) {
|
||||
bytes[i * 2 + 0] = line >> 8;
|
||||
bytes[i * 2 + 1] = line;
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"Unsupported wbytes!\n");
|
||||
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 (!bold)
|
||||
gl = add_glyph(bytes, bold, 1);
|
||||
if (map_idx < VFNT_MAP_BOLD)
|
||||
gl = add_glyph(bytes, 0, 1);
|
||||
} else if (curchar >= 0x20) {
|
||||
gl = add_glyph(bytes, bold, 0);
|
||||
if (add_mapping(gl, curchar, bold) != 0)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -225,9 +276,10 @@ static void
|
|||
number_glyphs(void)
|
||||
{
|
||||
struct glyph *gl;
|
||||
unsigned int idx = 0;
|
||||
unsigned int i, idx = 0;
|
||||
|
||||
TAILQ_FOREACH(gl, &glyph_list, g_list)
|
||||
for (i = 0; i < VFNT_MAPS; i++)
|
||||
TAILQ_FOREACH(gl, &glyphs[i], g_list)
|
||||
gl->g_index = idx++;
|
||||
}
|
||||
|
||||
|
@ -235,22 +287,20 @@ static void
|
|||
write_glyphs(FILE *fp)
|
||||
{
|
||||
struct glyph *gl;
|
||||
unsigned int i;
|
||||
|
||||
TAILQ_FOREACH(gl, &glyph_list, g_list)
|
||||
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(int bold)
|
||||
fold_mappings(unsigned int map_idx)
|
||||
{
|
||||
struct mapping_list *ml;
|
||||
struct mapping_list *ml = &maps[map_idx];
|
||||
struct mapping *mn, *mp, *mbase;
|
||||
|
||||
if (bold)
|
||||
ml = &mapping_list_bold;
|
||||
else
|
||||
ml = &mapping_list_normal;
|
||||
|
||||
mp = mbase = TAILQ_FIRST(ml);
|
||||
for (mp = mbase = TAILQ_FIRST(ml); mp != NULL; mp = mn) {
|
||||
mn = TAILQ_NEXT(mp, m_list);
|
||||
|
@ -259,10 +309,7 @@ fold_mappings(int bold)
|
|||
continue;
|
||||
mbase->m_length = mp->m_char - mbase->m_char + 1;
|
||||
mbase = mp = mn;
|
||||
if (bold)
|
||||
mapping_bold_folded++;
|
||||
else
|
||||
mapping_normal_folded++;
|
||||
map_folded_count[map_idx]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,18 +320,13 @@ struct file_mapping {
|
|||
} __packed;
|
||||
|
||||
static void
|
||||
write_mappings(FILE *fp, int bold)
|
||||
write_mappings(FILE *fp, unsigned int map_idx)
|
||||
{
|
||||
struct mapping_list *ml;
|
||||
struct mapping_list *ml = &maps[map_idx];
|
||||
struct mapping *mp;
|
||||
struct file_mapping fm;
|
||||
unsigned int i = 0, j = 0;
|
||||
|
||||
if (bold)
|
||||
ml = &mapping_list_bold;
|
||||
else
|
||||
ml = &mapping_list_normal;
|
||||
|
||||
TAILQ_FOREACH(mp, ml, m_list) {
|
||||
j++;
|
||||
if (mp->m_length > 0) {
|
||||
|
@ -302,9 +344,9 @@ struct file_header {
|
|||
uint8_t magic[8];
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
uint16_t nglyphs;
|
||||
uint16_t nmappings_normal;
|
||||
uint16_t nmappings_bold;
|
||||
uint16_t pad;
|
||||
uint32_t glyph_count;
|
||||
uint32_t map_count[4];
|
||||
} __packed;
|
||||
|
||||
static int
|
||||
|
@ -312,7 +354,7 @@ write_fnt(const char *filename)
|
|||
{
|
||||
FILE *fp;
|
||||
struct file_header fh = {
|
||||
.magic = "VFNT 1.0",
|
||||
.magic = "VFNT0002",
|
||||
};
|
||||
|
||||
fp = fopen(filename, "wb");
|
||||
|
@ -323,14 +365,18 @@ write_fnt(const char *filename)
|
|||
|
||||
fh.width = width;
|
||||
fh.height = height;
|
||||
fh.nglyphs = htobe16(glyph_unique);
|
||||
fh.nmappings_normal = htobe16(mapping_normal_folded);
|
||||
fh.nmappings_bold = htobe16(mapping_bold_folded);
|
||||
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, 0);
|
||||
write_mappings(fp, VFNT_MAP_NORMAL);
|
||||
write_mappings(fp, 1);
|
||||
write_mappings(fp, VFNT_MAP_BOLD);
|
||||
write_mappings(fp, 3);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -339,7 +385,7 @@ int
|
|||
main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
assert(sizeof(struct file_header) == 16);
|
||||
assert(sizeof(struct file_header) == 32);
|
||||
assert(sizeof(struct file_mapping) == 8);
|
||||
|
||||
if (argc != 6)
|
||||
|
@ -349,13 +395,15 @@ main(int argc, char *argv[])
|
|||
wbytes = howmany(width, 8);
|
||||
height = atoi(argv[2]);
|
||||
|
||||
if (parse_bdf(argv[3], 0) != 0)
|
||||
if (parse_bdf(argv[3], VFNT_MAP_NORMAL) != 0)
|
||||
return (1);
|
||||
if (parse_bdf(argv[4], 1) != 0)
|
||||
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);
|
||||
|
||||
|
@ -363,22 +411,33 @@ main(int argc, char *argv[])
|
|||
"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_normal, glyph_bold,
|
||||
glyph_count[0],
|
||||
glyph_count[1],
|
||||
glyph_count[2],
|
||||
glyph_count[3],
|
||||
glyph_unique, glyph_dupe,
|
||||
mapping_total,
|
||||
mapping_normal, mapping_normal_folded,
|
||||
mapping_bold, mapping_bold_folded,
|
||||
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);
|
||||
|
|
|
@ -48,22 +48,22 @@ struct file_header {
|
|||
uint8_t magic[8];
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
uint16_t nglyphs;
|
||||
uint16_t nmappings_normal;
|
||||
uint16_t nmappings_bold;
|
||||
uint16_t pad;
|
||||
uint32_t glyph_count;
|
||||
uint32_t map_count[4];
|
||||
} __packed;
|
||||
|
||||
static int
|
||||
print_glyphs(struct file_header *fh)
|
||||
{
|
||||
unsigned int gbytes, nglyphs, j, k, total;
|
||||
unsigned int gbytes, glyph_count, j, k, total;
|
||||
uint8_t *gbuf;
|
||||
|
||||
gbytes = howmany(fh->width, 8) * fh->height;
|
||||
nglyphs = be16toh(fh->nglyphs);
|
||||
glyph_count = be32toh(fh->glyph_count);
|
||||
|
||||
printf("\nstatic uint8_t font_bytes[%u * %u] = {", nglyphs, gbytes);
|
||||
total = nglyphs * gbytes;
|
||||
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) {
|
||||
|
@ -84,26 +84,23 @@ print_glyphs(struct file_header *fh)
|
|||
return (0);
|
||||
}
|
||||
|
||||
static const char *map_names[4] = {
|
||||
"normal", "normal_right", "bold", "bold_right" };
|
||||
|
||||
static int
|
||||
print_mappings(struct file_header *fh, int bold)
|
||||
print_mappings(struct file_header *fh, int map_index)
|
||||
{
|
||||
struct file_mapping fm;
|
||||
const char *name;
|
||||
unsigned int nmappings, i, col = 0;
|
||||
|
||||
if (bold) {
|
||||
nmappings = be16toh(fh->nmappings_bold);
|
||||
name = "bold";
|
||||
} else {
|
||||
nmappings = be16toh(fh->nmappings_normal);
|
||||
name = "normal";
|
||||
}
|
||||
|
||||
nmappings = be32toh(fh->map_count[map_index]);
|
||||
|
||||
if (nmappings == 0)
|
||||
return (0);
|
||||
|
||||
printf("\nstatic struct vt_font_map font_mapping_%s[%u] = {",
|
||||
name, nmappings);
|
||||
map_names[map_index], nmappings);
|
||||
|
||||
for (i = 0; i < nmappings; i++) {
|
||||
if (fread(&fm, sizeof fm, 1, stdin) != 1) {
|
||||
|
@ -126,7 +123,7 @@ print_mappings(struct file_header *fh, int bold)
|
|||
static int
|
||||
print_info(struct file_header *fh)
|
||||
{
|
||||
unsigned int nnormal, nbold;
|
||||
unsigned int i;
|
||||
|
||||
printf(
|
||||
"\nstruct vt_font vt_font_default = {\n"
|
||||
|
@ -135,17 +132,19 @@ print_info(struct file_header *fh)
|
|||
"\t.vf_bytes\t\t= font_bytes,\n",
|
||||
fh->width, fh->height);
|
||||
|
||||
nnormal = be16toh(fh->nmappings_normal);
|
||||
nbold = be16toh(fh->nmappings_bold);
|
||||
|
||||
if (nnormal != 0)
|
||||
printf(
|
||||
"\t.vf_normal\t\t= font_mapping_normal,\n"
|
||||
"\t.vf_normal_length\t= %u,\n", nnormal);
|
||||
if (nbold != 0)
|
||||
printf(
|
||||
"\t.vf_bold\t\t= font_mapping_bold,\n"
|
||||
"\t.vf_bold_length\t\t= %u,\n", nbold);
|
||||
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);
|
||||
|
@ -161,7 +160,7 @@ main(int argc __unused, char *argv[] __unused)
|
|||
return (1);
|
||||
}
|
||||
|
||||
if (memcmp(fh.magic, "VFNT 1.0", 8) != 0) {
|
||||
if (memcmp(fh.magic, "VFNT0002", 8) != 0) {
|
||||
fprintf(stderr, "Bad magic\n");
|
||||
return (1);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/consio.h>
|
||||
#include <sys/endian.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
@ -12,9 +15,9 @@ struct file_header {
|
|||
uint8_t magic[8];
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
uint16_t nglyphs;
|
||||
uint16_t nmappings_normal;
|
||||
uint16_t nmappings_bold;
|
||||
uint16_t pad;
|
||||
uint32_t glyph_count;
|
||||
uint32_t map_count[4];
|
||||
} __packed;
|
||||
|
||||
static vfnt_map_t *
|
||||
|
@ -48,24 +51,25 @@ 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, "VFNT 1.0", 8) != 0) {
|
||||
if (memcmp(fh.magic, "VFNT0002", 8) != 0) {
|
||||
fprintf(stderr, "Bad magic\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
vfnt.nnormal = be16toh(fh.nmappings_normal);
|
||||
vfnt.nbold = be16toh(fh.nmappings_bold);
|
||||
vfnt.nglyphs = be16toh(fh.nglyphs);
|
||||
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.nglyphs;
|
||||
glyphsize = howmany(vfnt.width, 8) * vfnt.height * vfnt.glyph_count;
|
||||
vfnt.glyphs = malloc(glyphsize);
|
||||
|
||||
if (fread(vfnt.glyphs, glyphsize, 1, stdin) != 1) {
|
||||
|
@ -73,8 +77,8 @@ main(int argc __unused, char *argv[] __unused)
|
|||
return (1);
|
||||
}
|
||||
|
||||
vfnt.normal = load_mappingtable(vfnt.nnormal);
|
||||
vfnt.bold = load_mappingtable(vfnt.nbold);
|
||||
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");
|
||||
|
|
Loading…
Reference in a new issue