Make the proof-of-concept UTF-8 support in Syscons less useless.
Add a small Unicode-to-CP437 remapping table to at least demonstrate that the terminal emulator is perfectly capable of handling UTF-8. This will of course break if the user loads a different font map, but it at least allows people to give it a try. I can now see the box drawing in dialog(1) and the arrows in mutt(1) correctly.
This commit is contained in:
parent
738e0afd67
commit
b32dcb662a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=194103
@ -335,6 +335,121 @@ scteken_cursor(void *arg, const teken_pos_t *p)
|
||||
sc_move_cursor(scp, p->tp_col, p->tp_row);
|
||||
}
|
||||
|
||||
#ifdef TEKEN_UTF8
|
||||
struct unicp437 {
|
||||
uint16_t unicode_base;
|
||||
uint8_t cp437_base;
|
||||
uint8_t length;
|
||||
};
|
||||
|
||||
static const struct unicp437 cp437table[] = {
|
||||
{ 0x0020, 0x20, 0x5e }, { 0x00a1, 0xad, 0x00 },
|
||||
{ 0x00a2, 0x9b, 0x00 }, { 0x00a3, 0x9c, 0x00 },
|
||||
{ 0x00a5, 0x9d, 0x00 }, { 0x00a7, 0x15, 0x00 },
|
||||
{ 0x00aa, 0xa6, 0x00 }, { 0x00ab, 0xae, 0x00 },
|
||||
{ 0x00ac, 0xaa, 0x00 }, { 0x00b0, 0xf8, 0x00 },
|
||||
{ 0x00b1, 0xf1, 0x00 }, { 0x00b2, 0xfd, 0x00 },
|
||||
{ 0x00b5, 0xe6, 0x00 }, { 0x00b6, 0x14, 0x00 },
|
||||
{ 0x00b7, 0xfa, 0x00 }, { 0x00ba, 0xa7, 0x00 },
|
||||
{ 0x00bb, 0xaf, 0x00 }, { 0x00bc, 0xac, 0x00 },
|
||||
{ 0x00bd, 0xab, 0x00 }, { 0x00bf, 0xa8, 0x00 },
|
||||
{ 0x00c4, 0x8e, 0x01 }, { 0x00c6, 0x92, 0x00 },
|
||||
{ 0x00c7, 0x80, 0x00 }, { 0x00c9, 0x90, 0x00 },
|
||||
{ 0x00d1, 0xa5, 0x00 }, { 0x00d6, 0x99, 0x00 },
|
||||
{ 0x00dc, 0x9a, 0x00 }, { 0x00df, 0xe1, 0x00 },
|
||||
{ 0x00e0, 0x85, 0x00 }, { 0x00e1, 0xa0, 0x00 },
|
||||
{ 0x00e2, 0x83, 0x00 }, { 0x00e4, 0x84, 0x00 },
|
||||
{ 0x00e5, 0x86, 0x00 }, { 0x00e6, 0x91, 0x00 },
|
||||
{ 0x00e7, 0x87, 0x00 }, { 0x00e8, 0x8a, 0x00 },
|
||||
{ 0x00e9, 0x82, 0x00 }, { 0x00ea, 0x88, 0x01 },
|
||||
{ 0x00ec, 0x8d, 0x00 }, { 0x00ed, 0xa1, 0x00 },
|
||||
{ 0x00ee, 0x8c, 0x00 }, { 0x00ef, 0x8b, 0x00 },
|
||||
{ 0x00f1, 0xa4, 0x00 }, { 0x00f2, 0x95, 0x00 },
|
||||
{ 0x00f3, 0xa2, 0x00 }, { 0x00f4, 0x93, 0x00 },
|
||||
{ 0x00f6, 0x94, 0x00 }, { 0x00f7, 0xf6, 0x00 },
|
||||
{ 0x00f9, 0x97, 0x00 }, { 0x00fa, 0xa3, 0x00 },
|
||||
{ 0x00fb, 0x96, 0x00 }, { 0x00fc, 0x81, 0x00 },
|
||||
{ 0x00ff, 0x98, 0x00 }, { 0x0192, 0x9f, 0x00 },
|
||||
{ 0x0393, 0xe2, 0x00 }, { 0x0398, 0xe9, 0x00 },
|
||||
{ 0x03a3, 0xe4, 0x00 }, { 0x03a6, 0xe8, 0x00 },
|
||||
{ 0x03a9, 0xea, 0x00 }, { 0x03b1, 0xe0, 0x00 },
|
||||
{ 0x03b4, 0xeb, 0x00 }, { 0x03b5, 0xee, 0x00 },
|
||||
{ 0x03c0, 0xe3, 0x00 }, { 0x03c3, 0xe5, 0x00 },
|
||||
{ 0x03c4, 0xe7, 0x00 }, { 0x03c6, 0xed, 0x00 },
|
||||
{ 0x203c, 0x13, 0x00 }, { 0x207f, 0xfc, 0x00 },
|
||||
{ 0x20a7, 0x9e, 0x00 }, { 0x2190, 0x1b, 0x00 },
|
||||
{ 0x2191, 0x18, 0x00 }, { 0x2192, 0x1a, 0x00 },
|
||||
{ 0x2193, 0x19, 0x00 }, { 0x2194, 0x1d, 0x00 },
|
||||
{ 0x2195, 0x12, 0x00 }, { 0x21a8, 0x17, 0x00 },
|
||||
{ 0x2219, 0xf9, 0x00 }, { 0x221a, 0xfb, 0x00 },
|
||||
{ 0x221e, 0xec, 0x00 }, { 0x221f, 0x1c, 0x00 },
|
||||
{ 0x2229, 0xef, 0x00 }, { 0x2248, 0xf7, 0x00 },
|
||||
{ 0x2261, 0xf0, 0x00 }, { 0x2264, 0xf3, 0x00 },
|
||||
{ 0x2265, 0xf2, 0x00 }, { 0x2302, 0x7f, 0x00 },
|
||||
{ 0x2310, 0xa9, 0x00 }, { 0x2320, 0xf4, 0x00 },
|
||||
{ 0x2321, 0xf5, 0x00 }, { 0x2500, 0xc4, 0x00 },
|
||||
{ 0x2502, 0xb3, 0x00 }, { 0x250c, 0xda, 0x00 },
|
||||
{ 0x2510, 0xbf, 0x00 }, { 0x2514, 0xc0, 0x00 },
|
||||
{ 0x2518, 0xd9, 0x00 }, { 0x251c, 0xc3, 0x00 },
|
||||
{ 0x2524, 0xb4, 0x00 }, { 0x252c, 0xc2, 0x00 },
|
||||
{ 0x2534, 0xc1, 0x00 }, { 0x253c, 0xc5, 0x00 },
|
||||
{ 0x2550, 0xcd, 0x00 }, { 0x2551, 0xba, 0x00 },
|
||||
{ 0x2552, 0xd5, 0x00 }, { 0x2553, 0xd6, 0x00 },
|
||||
{ 0x2554, 0xc9, 0x00 }, { 0x2555, 0xb8, 0x00 },
|
||||
{ 0x2556, 0xb7, 0x00 }, { 0x2557, 0xbb, 0x00 },
|
||||
{ 0x2558, 0xd4, 0x00 }, { 0x2559, 0xd3, 0x00 },
|
||||
{ 0x255a, 0xc8, 0x00 }, { 0x255b, 0xbe, 0x00 },
|
||||
{ 0x255c, 0xbd, 0x00 }, { 0x255d, 0xbc, 0x00 },
|
||||
{ 0x255e, 0xc6, 0x01 }, { 0x2560, 0xcc, 0x00 },
|
||||
{ 0x2561, 0xb5, 0x00 }, { 0x2562, 0xb6, 0x00 },
|
||||
{ 0x2563, 0xb9, 0x00 }, { 0x2564, 0xd1, 0x01 },
|
||||
{ 0x2566, 0xcb, 0x00 }, { 0x2567, 0xcf, 0x00 },
|
||||
{ 0x2568, 0xd0, 0x00 }, { 0x2569, 0xca, 0x00 },
|
||||
{ 0x256a, 0xd8, 0x00 }, { 0x256b, 0xd7, 0x00 },
|
||||
{ 0x256c, 0xce, 0x00 }, { 0x2580, 0xdf, 0x00 },
|
||||
{ 0x2584, 0xdc, 0x00 }, { 0x2588, 0xdb, 0x00 },
|
||||
{ 0x258c, 0xdd, 0x00 }, { 0x2590, 0xde, 0x00 },
|
||||
{ 0x2591, 0xb0, 0x02 }, { 0x25a0, 0xfe, 0x00 },
|
||||
{ 0x25ac, 0x16, 0x00 }, { 0x25b2, 0x1e, 0x00 },
|
||||
{ 0x25ba, 0x10, 0x00 }, { 0x25bc, 0x1f, 0x00 },
|
||||
{ 0x25c4, 0x11, 0x00 }, { 0x263a, 0x01, 0x01 },
|
||||
{ 0x263c, 0x0f, 0x00 }, { 0x2660, 0x06, 0x00 },
|
||||
{ 0x2663, 0x05, 0x00 }, { 0x2665, 0x03, 0x01 },
|
||||
{ 0x266b, 0x0e, 0x00 },
|
||||
};
|
||||
|
||||
static void
|
||||
scteken_get_cp437(teken_char_t *c, int *attr)
|
||||
{
|
||||
int min, mid, max;
|
||||
|
||||
min = 0;
|
||||
max = (sizeof(cp437table) / sizeof(struct unicp437)) - 1;
|
||||
|
||||
if (*c < cp437table[0].unicode_base ||
|
||||
*c > cp437table[max].unicode_base + cp437table[max].length)
|
||||
goto bad;
|
||||
|
||||
while (max >= min) {
|
||||
mid = (min + max) / 2;
|
||||
if (*c < cp437table[mid].unicode_base) {
|
||||
max = mid - 1;
|
||||
} else if (*c > cp437table[mid].unicode_base +
|
||||
cp437table[mid].length) {
|
||||
min = mid + 1;
|
||||
} else {
|
||||
*c -= cp437table[mid].unicode_base;
|
||||
*c += cp437table[mid].cp437_base;
|
||||
return;
|
||||
}
|
||||
}
|
||||
bad:
|
||||
/* Character not present in CP437. */
|
||||
*attr = (FG_RED|BG_BLACK) << 8;
|
||||
*c = '?';
|
||||
}
|
||||
#endif /* TEKEN_UTF8 */
|
||||
|
||||
static void
|
||||
scteken_putchar(void *arg, const teken_pos_t *tp, teken_char_t c,
|
||||
const teken_attr_t *a)
|
||||
@ -345,17 +460,11 @@ scteken_putchar(void *arg, const teken_pos_t *tp, teken_char_t c,
|
||||
vm_offset_t p;
|
||||
int cursor, attr;
|
||||
|
||||
attr = scteken_attr(a) << 8;
|
||||
#ifdef TEKEN_UTF8
|
||||
if (c >= 0x80) {
|
||||
/* XXX: Don't display UTF-8 yet. */
|
||||
attr = (FG_YELLOW|BG_RED) << 8;
|
||||
ch = '?';
|
||||
} else
|
||||
scteken_get_cp437(&c, &attr);
|
||||
#endif /* TEKEN_UTF8 */
|
||||
{
|
||||
attr = scteken_attr(a) << 8;
|
||||
ch = c;
|
||||
}
|
||||
ch = c;
|
||||
|
||||
map = scp->sc->scr_map;
|
||||
|
||||
@ -381,17 +490,11 @@ scteken_fill(void *arg, const teken_rect_t *r, teken_char_t c,
|
||||
unsigned int width;
|
||||
int attr, row;
|
||||
|
||||
attr = scteken_attr(a) << 8;
|
||||
#ifdef TEKEN_UTF8
|
||||
if (c >= 0x80) {
|
||||
/* XXX: Don't display UTF-8 yet. */
|
||||
attr = (FG_YELLOW|BG_RED) << 8;
|
||||
ch = '?';
|
||||
} else
|
||||
scteken_get_cp437(&c, &attr);
|
||||
#endif /* TEKEN_UTF8 */
|
||||
{
|
||||
attr = scteken_attr(a) << 8;
|
||||
ch = c;
|
||||
}
|
||||
ch = c;
|
||||
|
||||
map = scp->sc->scr_map;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user