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

@@ -17,6 +17,9 @@ static char *e_atr2str(int);
void cmov(int, int);
void nocmov(int, int);
void term_start_24bitcolor(struct unicode_representation *);
void term_end_24bitcolor(void);
#if defined(TEXTCOLOR) && defined(TERMLIB)
#if (!defined(UNIX) || !defined(TERMINFO)) && !defined(TOS)
static void analyze_seq(char *, int *, int *);
@@ -430,11 +433,12 @@ tty_decgraphics_termcap_fixup(void)
#endif /* TERMLIB */
#if defined(ASCIIGRAPH) && defined(PC9800)
extern void (*ibmgraphics_mode_callback)(void); /* defined in drawing.c */
extern void (*ibmgraphics_mode_callback)(void); /* defined in symbols.c */
#endif
extern void (*utf8graphics_mode_callback)(void); /* defined in symbols.c */
#ifdef PC9800
extern void (*ascgraphics_mode_callback)(void); /* defined in drawing.c */
extern void (*ascgraphics_mode_callback)(void); /* defined in symbols.c */
static void tty_ascgraphics_hilite_fixup(void);
static void
@@ -478,6 +482,10 @@ tty_start_screen(void)
/* set up callback in case option is not set yet but toggled later */
decgraphics_mode_callback = tty_decgraphics_termcap_fixup;
#endif
#ifdef ENHANCED_SYMBOLS
utf8graphics_mode_callback = tty_utf8graphics_fixup;
#endif
if (g.Cmd.num_pad)
tty_number_pad(1); /* make keypad send digits */
}
@@ -870,14 +878,21 @@ const struct {
{ COLOR_MAGENTA, CLR_MAGENTA, CLR_BRIGHT_MAGENTA },
{ COLOR_CYAN, CLR_CYAN, CLR_BRIGHT_CYAN } };
typedef struct {
unsigned char r, g, b;
} RGB;
static char nilstring[] = "";
static void
init_hilite(void)
{
int c, colors;
char *setf, *scratch;
int c, md_len = 0;
int colors = tgetnum("Co");
colors = tgetnum("Co");
iflags.colorcount = colors;
int md_len = 0;
if (colors < 8 || (MD == NULL) || (strlen(MD) == 0)
|| ((setf = tgetstr("AF", (char **) 0)) == (char *) 0
@@ -1410,9 +1425,66 @@ term_start_color(int color)
if (color < CLR_MAX && hilites[color] && *hilites[color])
xputs(hilites[color]);
}
#endif /* TEXTCOLOR */
#endif /* TTY_GRAPHICS && !NO_TERMS */
#ifdef ENHANCED_SYMBOLS
#ifndef SEP2
#define tcfmtstr "\033[38;2;%ld;%ld;%ldm"
#ifdef UNIX
#define tcfmtstr24bit "\033[38;2;%u;%u;%um"
#define tcfmtstr256 "\033[38;5;%dm"
#else
#define tcfmtstr "\033[38:2:%ld:%ld:%ldm"
#define tcfmtstr24bit "\033[38;2;%lu;%lu;%lum"
#define tcfmtstr256 "\033[38:5:%ldm"
#endif
#endif
static void emit24bit(long mcolor);
static void emit256(int u256coloridx);
static void emit24bit(long mcolor)
{
static char tcolorbuf[QBUFSZ];
Snprintf(tcolorbuf, sizeof tcolorbuf, tcfmtstr,
((mcolor >> 16) & 0xFF), /* red */
((mcolor >> 8) & 0xFF), /* green */
((mcolor >> 0) & 0xFF)); /* blue */
xputs(tcolorbuf);
}
static void emit256(int u256coloridx)
{
static char tcolorbuf[QBUFSZ];
Snprintf(tcolorbuf, sizeof tcolorbuf, tcfmtstr256,
u256coloridx);
xputs(tcolorbuf);
}
void
term_start_24bitcolor(struct unicode_representation *urep)
{
if (urep && SYMHANDLING(H_UTF8)) {
/* color 0 has bit 0x1000000 set */
long mcolor = (urep->ucolor & 0xFFFFFF);
if (iflags.colorcount == 256)
emit256(urep->u256coloridx);
else
emit24bit(mcolor);
}
}
void
term_end_24bitcolor(void)
{
if (SYMHANDLING(H_UTF8)) {
xputs("\033[0m");
}
}
#endif /* ENHANCED_SYMBOLS */
#endif /* TTY_GRAPHICS && !NO_TERMS */
/*termcap.c*/