ENHANCED_SYMBOLS

A new feature, enabled by default to maximize testing, but one which can
be disabled by commenting it out in config.h

With this, some additional information is added to the glyphmap entries
in a new optional substructure called u with these fields:
    ucolor          RGB color for use with truecolor terminals/platforms.
                    A ucolor value of zero means "not set." The actual
                    rgb value of 0 has the 0x1000000 bit set.
    u256coloridx    256 color index value for use with 256 color
                    terminals, the closest color match to ucolor.
    utf8str         Custom representation via utf-8 string (can be null).

There is a new symset included in the symbols file, called enhanced1.

Some initial code has been added to parse individual
OPTIONS=glyph:glyphid/R-G-B entries in the config file.

The glyphid can, in theory, either be an individual glyph (G_* glyphid)
for a single glyph, or it can be an existing symbol S_ value
(monster, object, or cmap symbol) to store the custom representation for
all the glyphs that match that symbol.

Examples:
   OPTIONS=glyph:G_fountain/U+03A8/0-150-255

(Your platform/terminal font needs to be able to include/display the
character, of course.)

The NetHack core code does parsing and storing the customized
entries, and adding them to the glyphmap data structure.

Any window port can utilize the additional information in the glyphinfo
that is passed to them, once code is added to do so.

Also, consolidate some symbol-related code into symbols.c, and remove it from
files.c and options.c
This commit is contained in:
nhmall
2022-05-07 10:25:13 -04:00
parent 132e1d433a
commit cb0c21e91d
50 changed files with 3072 additions and 1242 deletions

View File

@@ -1375,7 +1375,7 @@ glyph2symidx(int glyph)
glyph_info glyphinfo;
map_glyphinfo(0, 0, glyph, 0, &glyphinfo);
return glyphinfo.gm.symidx;
return glyphinfo.gm.sym.symidx;
}
char *
@@ -1387,10 +1387,37 @@ encglyph(int glyph)
return encbuf;
}
int
decode_glyph(const char *str, int *glyph_ptr)
{
static const char hex[] = "00112233445566778899aAbBcCdDeEfF";
int rndchk = 0, dcount = 0, retval = 0;
const char *dp;
for (; *str && ++dcount <= 4; ++str) {
if ((dp = index(hex, *str)) != 0) {
retval++;
rndchk = (rndchk * 16) + ((int) (dp - hex) / 2);
} else
break;
}
if (rndchk == g.context.rndencode) {
*glyph_ptr = dcount = 0;
for (; *str && ++dcount <= 4; ++str) {
if ((dp = index(hex, *str)) != 0) {
retval++;
*glyph_ptr = (*glyph_ptr * 16) + ((int) (dp - hex) / 2);
} else
break;
}
return retval;
}
return 0;
}
char *
decode_mixed(char *buf, const char *str)
{
static const char hex[] = "00112233445566778899aAbBcCdDeEfF";
char *put = buf;
glyph_info glyphinfo = nul_glyphinfo;
@@ -1399,27 +1426,16 @@ decode_mixed(char *buf, const char *str)
while (*str) {
if (*str == '\\') {
int rndchk, dcount, so, gv;
const char *dp, *save_str;
int dcount, so, gv;
const char *save_str;
save_str = str++;
switch (*str) {
case 'G': /* glyph value \GXXXXNNNN*/
rndchk = dcount = 0;
for (++str; *str && ++dcount <= 4; ++str)
if ((dp = index(hex, *str)) != 0)
rndchk = (rndchk * 16) + ((int) (dp - hex) / 2);
else
break;
if (rndchk == g.context.rndencode) {
gv = dcount = 0;
for (; *str && ++dcount <= 4; ++str)
if ((dp = index(hex, *str)) != 0)
gv = (gv * 16) + ((int) (dp - hex) / 2);
else
break;
if ((dcount = decode_glyph(str + 1, &gv))) {
str += (dcount + 1);
map_glyphinfo(0, 0, gv, 0, &glyphinfo);
so = glyphinfo.gm.symidx;
so = glyphinfo.gm.sym.symidx;
*put++ = g.showsyms[so];
/* 'str' is ready for the next loop iteration and '*str'
should not be copied at the end of this iteration */
@@ -1429,25 +1445,6 @@ decode_mixed(char *buf, const char *str)
str = save_str;
}
break;
#if 0
case 'S': /* symbol offset */
so = rndchk = dcount = 0;
for (++str; *str && ++dcount <= 4; ++str)
if ((dp = index(hex, *str)) != 0)
rndchk = (rndchk * 16) + ((int) (dp - hex) / 2);
else
break;
if (rndchk == g.context.rndencode) {
dcount = 0;
for (; *str && ++dcount <= 2; ++str)
if ((dp = index(hex, *str)) != 0)
so = (so * 16) + ((int) (dp - hex) / 2);
else
break;
}
*put++ = g.showsyms[so];
break;
#endif
case '\\':
break;
case '\0':
@@ -1467,6 +1464,7 @@ decode_mixed(char *buf, const char *str)
return buf;
}
/*
* This differs from putstr() because the str parameter can
* contain a sequence of characters representing: