From 06f3d4e7023587beafc776a816f144437299fedb Mon Sep 17 00:00:00 2001 From: William McBrine Date: Mon, 1 Jan 2018 09:36:58 -0500 Subject: [PATCH] Added SP->termattrs and PDC_set_bold(). termattrs() is actually useful now. The main goal here is to allow A_BOLD to select *either* high intensity color (the old behavior) *or* a genuine bold font (the new option for SDL-TTF and X11), but not both at once; and also to facilitate similar choice with A_BLINK in the future. (High-intensity color can still be combined with bold fonts by directly selecting one of the 8-15 colors.) A_ITALIC is also half-covered, but since A_INVIS is kind of useless, I've omitted PDC_set_italic(). To Do: Test everywhere; more docs. --- IMPLEMNT.md | 1 + curses.h | 2 ++ dos/pdcscrn.c | 2 ++ dos/pdcsetsc.c | 21 ++++++++++++++++++--- os2/pdcscrn.c | 2 ++ os2/pdcsetsc.c | 22 +++++++++++++++++++--- pdcurses/termattr.c | 12 ++---------- sdl1/pdcdisp.c | 17 +++++++++++++---- sdl1/pdcscrn.c | 6 ++++++ sdl1/pdcsetsc.c | 25 ++++++++++++++++++++++--- sdl2/pdcdisp.c | 17 +++++++++++++---- sdl2/pdcscrn.c | 6 ++++++ sdl2/pdcsetsc.c | 25 ++++++++++++++++++++++--- win32/pdcscrn.c | 2 ++ win32/pdcsetsc.c | 16 +++++++++++++--- x11/pdcsetsc.c | 21 ++++++++++++++++++--- x11/x11.c | 18 +++++++++++++++--- 17 files changed, 176 insertions(+), 39 deletions(-) diff --git a/IMPLEMNT.md b/IMPLEMNT.md index ae2082b0..a46d6c36 100644 --- a/IMPLEMNT.md +++ b/IMPLEMNT.md @@ -325,4 +325,5 @@ pdcsetsc.c: ----------- ### int PDC_set_blink(bool blinkon); +### int PDC_set_bold(bool boldon); ### void PDC_set_title(const char *title); diff --git a/curses.h b/curses.h index 5def5c3d..e87a2ff5 100644 --- a/curses.h +++ b/curses.h @@ -321,6 +321,7 @@ typedef struct int sb_cur_x; #endif short line_color; /* color of line attributes - default -1 */ + attr_t termattrs; /* attribute capabilities */ } SCREEN; /*---------------------------------------------------------------------- @@ -1318,6 +1319,7 @@ PDCEX wchar_t *slk_wlabel(int); PDCEX void PDC_debug(const char *, ...); PDCEX int PDC_ungetch(int); PDCEX int PDC_set_blink(bool); +PDCEX int PDC_set_bold(bool); PDCEX int PDC_set_line_color(short); PDCEX void PDC_set_title(const char *); diff --git a/dos/pdcscrn.c b/dos/pdcscrn.c index aba45302..f2570c7d 100644 --- a/dos/pdcscrn.c +++ b/dos/pdcscrn.c @@ -541,6 +541,8 @@ int PDC_scr_open(int argc, char **argv) SP->mouse_wait = PDC_CLICK_PERIOD; SP->audible = TRUE; + SP->termattrs = (SP->mono ? A_UNDERLINE : A_COLOR) | A_REVERSE | A_BLINK; + /* If the environment variable PDCURSES_BIOS is set, the DOS int10() BIOS calls are used in place of direct video memory access. */ diff --git a/dos/pdcsetsc.c b/dos/pdcsetsc.c index bbf66b6d..ac06a07f 100644 --- a/dos/pdcsetsc.c +++ b/dos/pdcsetsc.c @@ -10,6 +10,7 @@ pdcsetsc ### Synopsis int PDC_set_blink(bool blinkon); + int PDC_set_bold(bool boldon); void PDC_set_title(const char *title); ### Description @@ -18,9 +19,13 @@ pdcsetsc actual blink mode (TRUE), or sets the background color to high intensity (FALSE). The default is platform-dependent (FALSE in most cases). It returns OK if it could set the state to match - the given parameter, ERR otherwise. Current platforms also - adjust the value of COLORS according to this function -- 16 for - FALSE, and 8 for TRUE. + the given parameter, ERR otherwise. On DOS, this function also + adjusts the value of COLORS -- 16 for FALSE, and 8 for TRUE. + + PDC_set_bold() toggles whether the A_BOLD attribute selects an actual + bold font (TRUE), or sets the foreground color to high intensity + (FALSE). It returns OK if it could set the state to match the given + parameter, ERR otherwise. PDC_set_title() sets the title of the window in which the curses program is running. This function may not do anything on some @@ -97,5 +102,15 @@ int PDC_set_blink(bool blinkon) COLORS = 8; } + if (blinkon && (COLORS == 8)) + SP->termattrs |= A_BLINK; + else if (!blinkon && (COLORS == 16)) + SP->termattrs &= ~A_BLINK; + return (COLORS - (blinkon * 8) != 8) ? OK : ERR; } + +int PDC_set_bold(bool boldon) +{ + return boldon ? ERR : OK; +} diff --git a/os2/pdcscrn.c b/os2/pdcscrn.c index 2ba2da74..d4021dba 100644 --- a/os2/pdcscrn.c +++ b/os2/pdcscrn.c @@ -169,6 +169,8 @@ int PDC_scr_open(int argc, char **argv) SP->mouse_wait = PDC_CLICK_PERIOD; SP->audible = TRUE; + SP->termattrs = (SP->mono ? A_UNDERLINE : A_COLOR) | A_REVERSE | A_BLINK; + /* This code for preserving the current screen */ if (getenv("PDC_RESTORE_SCREEN")) diff --git a/os2/pdcsetsc.c b/os2/pdcsetsc.c index 27b7db00..d0335251 100644 --- a/os2/pdcsetsc.c +++ b/os2/pdcsetsc.c @@ -10,6 +10,7 @@ pdcsetsc ### Synopsis int PDC_set_blink(bool blinkon); + int PDC_set_bold(bool boldon); void PDC_set_title(const char *title); ### Description @@ -18,9 +19,13 @@ pdcsetsc actual blink mode (TRUE), or sets the background color to high intensity (FALSE). The default is platform-dependent (FALSE in most cases). It returns OK if it could set the state to match - the given parameter, ERR otherwise. Current platforms also - adjust the value of COLORS according to this function -- 16 for - FALSE, and 8 for TRUE. + the given parameter, ERR otherwise. On OS/2, this function also + adjusts the value of COLORS -- 16 for FALSE, and 8 for TRUE. + + PDC_set_bold() toggles whether the A_BOLD attribute selects an actual + bold font (TRUE), or sets the foreground color to high intensity + (FALSE). It returns OK if it could set the state to match the given + parameter, ERR otherwise. PDC_set_title() sets the title of the window in which the curses program is running. This function may not do anything on some @@ -99,14 +104,25 @@ int PDC_set_blink(bool blinkon) result = VioSetState(&statebuf, 0); VioGetState(&statebuf, 0); /* needed? */ + if (statebuf[2]) + SP->termattrs &= ~A_BLINK; + else + SP->termattrs |= A_BLINK; + if (pdc_color_started) COLORS = statebuf[2] ? 16 : 8; return (result == 0) ? OK : ERR; #else + SP->termattrs &= ~A_BLINK; if (pdc_color_started) COLORS = 16; return blinkon ? ERR : OK; #endif } + +int PDC_set_bold(bool boldon) +{ + return boldon ? ERR : OK; +} diff --git a/pdcurses/termattr.c b/pdcurses/termattr.c index 9e284e4f..53cc2b68 100644 --- a/pdcurses/termattr.c +++ b/pdcurses/termattr.c @@ -117,24 +117,16 @@ char *longname(void) chtype termattrs(void) { - chtype temp = A_BLINK | A_BOLD | A_INVIS | A_REVERSE | A_UNDERLINE; - - /* note: blink is bold background on some platforms */ - PDC_LOG(("termattrs() - called\n")); - if (!SP->mono) - temp |= A_COLOR; - - return temp; + return SP->termattrs; } attr_t term_attrs(void) { PDC_LOG(("term_attrs() - called\n")); - return WA_BLINK | WA_BOLD | WA_INVIS | WA_LEFT | WA_REVERSE | - WA_RIGHT | WA_UNDERLINE; + return SP->termattrs; } char *termname(void) diff --git a/sdl1/pdcdisp.c b/sdl1/pdcdisp.c index 26612bc2..d9a12f17 100644 --- a/sdl1/pdcdisp.c +++ b/sdl1/pdcdisp.c @@ -96,6 +96,8 @@ void PDC_update_rects(void) static void _set_attr(chtype ch) { + attr_t sysattrs = SP->termattrs; + ch &= (A_COLOR|A_BOLD|A_BLINK|A_REVERSE); if (oldch != ch) @@ -107,8 +109,10 @@ static void _set_attr(chtype ch) PDC_pair_content(PAIR_NUMBER(ch), &newfg, &newbg); - newfg |= (ch & A_BOLD) ? 8 : 0; - newbg |= (ch & A_BLINK) ? 8 : 0; + if ((ch & A_BOLD) && !(sysattrs & A_BOLD)) + newfg |= 8; + if ((ch & A_BLINK) && !(sysattrs & A_BLINK)) + newbg |= 8; if (ch & A_REVERSE) { @@ -309,6 +313,7 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) #ifdef PDC_WIDE Uint16 chstr[2] = {0, 0}; #endif + attr_t sysattrs = SP->termattrs; PDC_LOG(("PDC_transform_line() - called: lineno=%d\n", lineno)); @@ -364,8 +369,12 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) #ifdef PDC_WIDE chstr[0] = ch & A_CHARTEXT; - TTF_SetFontStyle(pdc_ttffont, (ch & A_BOLD ? TTF_STYLE_BOLD : 0) | - (ch & A_ITALIC ? TTF_STYLE_ITALIC : 0)); + TTF_SetFontStyle(pdc_ttffont, + ( ((ch & A_BOLD) && (sysattrs & A_BOLD)) ? + TTF_STYLE_BOLD : 0) | + ( ((ch & A_ITALIC) && (sysattrs & A_ITALIC)) ? + TTF_STYLE_ITALIC : 0) ); + pdc_font = TTF_RenderUNICODE_Solid(pdc_ttffont, chstr, pdc_color[foregr]); diff --git a/sdl1/pdcscrn.c b/sdl1/pdcscrn.c index ebacf2eb..6617a6fe 100644 --- a/sdl1/pdcscrn.c +++ b/sdl1/pdcscrn.c @@ -273,6 +273,12 @@ int PDC_scr_open(int argc, char **argv) SP->mouse_wait = PDC_CLICK_PERIOD; SP->audible = FALSE; +#ifdef PDC_WIDE + SP->termattrs = A_COLOR | A_ITALIC | A_PROTECT | A_REVERSE; +#else + SP->termattrs = A_COLOR | A_PROTECT | A_REVERSE; +#endif + PDC_reset_prog_mode(); return OK; diff --git a/sdl1/pdcsetsc.c b/sdl1/pdcsetsc.c index e9af6275..e11879fc 100644 --- a/sdl1/pdcsetsc.c +++ b/sdl1/pdcsetsc.c @@ -10,6 +10,7 @@ pdcsetsc ### Synopsis int PDC_set_blink(bool blinkon); + int PDC_set_bold(bool boldon); void PDC_set_title(const char *title); ### Description @@ -18,9 +19,12 @@ pdcsetsc actual blink mode (TRUE), or sets the background color to high intensity (FALSE). The default is platform-dependent (FALSE in most cases). It returns OK if it could set the state to match - the given parameter, ERR otherwise. Current platforms also - adjust the value of COLORS according to this function -- 16 for - FALSE, and 8 for TRUE. + the given parameter, ERR otherwise. + + PDC_set_bold() toggles whether the A_BOLD attribute selects an actual + bold font (TRUE), or sets the foreground color to high intensity + (FALSE). It returns OK if it could set the state to match the given + parameter, ERR otherwise. PDC_set_title() sets the title of the window in which the curses program is running. This function may not do anything on some @@ -57,8 +61,23 @@ void PDC_set_title(const char *title) int PDC_set_blink(bool blinkon) { + SP->termattrs &= ~A_BLINK; if (pdc_color_started) COLORS = 16; return blinkon ? ERR : OK; } + +int PDC_set_bold(bool boldon) +{ +#ifdef PDC_WIDE + if (boldon) + SP->termattrs |= A_BOLD; + else + SP->termattrs &= ~A_BOLD; + + return OK; +#else + return boldon ? ERR : OK; +#endif +} diff --git a/sdl2/pdcdisp.c b/sdl2/pdcdisp.c index 4ca1f1f8..44a928e5 100644 --- a/sdl2/pdcdisp.c +++ b/sdl2/pdcdisp.c @@ -96,6 +96,8 @@ void PDC_update_rects(void) static void _set_attr(chtype ch) { + attr_t sysattrs = SP->termattrs; + ch &= (A_COLOR|A_BOLD|A_BLINK|A_REVERSE); if (oldch != ch) @@ -107,8 +109,10 @@ static void _set_attr(chtype ch) PDC_pair_content(PAIR_NUMBER(ch), &newfg, &newbg); - newfg |= (ch & A_BOLD) ? 8 : 0; - newbg |= (ch & A_BLINK) ? 8 : 0; + if ((ch & A_BOLD) && !(sysattrs & A_BOLD)) + newfg |= 8; + if ((ch & A_BLINK) && !(sysattrs & A_BLINK)) + newbg |= 8; if (ch & A_REVERSE) { @@ -311,6 +315,7 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) #ifdef PDC_WIDE Uint16 chstr[2] = {0, 0}; #endif + attr_t sysattrs = SP->termattrs; PDC_LOG(("PDC_transform_line() - called: lineno=%d\n", lineno)); @@ -365,8 +370,12 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp) #ifdef PDC_WIDE chstr[0] = ch & A_CHARTEXT; - TTF_SetFontStyle(pdc_ttffont, (ch & A_BOLD ? TTF_STYLE_BOLD : 0) | - (ch & A_ITALIC ? TTF_STYLE_ITALIC : 0)); + TTF_SetFontStyle(pdc_ttffont, + ( ((ch & A_BOLD) && (sysattrs & A_BOLD)) ? + TTF_STYLE_BOLD : 0) | + ( ((ch & A_ITALIC) && (sysattrs & A_ITALIC)) ? + TTF_STYLE_ITALIC : 0) ); + pdc_font = TTF_RenderUNICODE_Solid(pdc_ttffont, chstr, pdc_color[foregr]); diff --git a/sdl2/pdcscrn.c b/sdl2/pdcscrn.c index a89f143c..51217420 100644 --- a/sdl2/pdcscrn.c +++ b/sdl2/pdcscrn.c @@ -287,6 +287,12 @@ int PDC_scr_open(int argc, char **argv) SP->mouse_wait = PDC_CLICK_PERIOD; SP->audible = FALSE; +#ifdef PDC_WIDE + SP->termattrs = A_COLOR | A_ITALIC | A_PROTECT | A_REVERSE; +#else + SP->termattrs = A_COLOR | A_PROTECT | A_REVERSE; +#endif + PDC_reset_prog_mode(); return OK; diff --git a/sdl2/pdcsetsc.c b/sdl2/pdcsetsc.c index 03fab6f4..e906f44d 100644 --- a/sdl2/pdcsetsc.c +++ b/sdl2/pdcsetsc.c @@ -10,6 +10,7 @@ pdcsetsc ### Synopsis int PDC_set_blink(bool blinkon); + int PDC_set_bold(bool boldon); void PDC_set_title(const char *title); ### Description @@ -18,9 +19,12 @@ pdcsetsc actual blink mode (TRUE), or sets the background color to high intensity (FALSE). The default is platform-dependent (FALSE in most cases). It returns OK if it could set the state to match - the given parameter, ERR otherwise. Current platforms also - adjust the value of COLORS according to this function -- 16 for - FALSE, and 8 for TRUE. + the given parameter, ERR otherwise. + + PDC_set_bold() toggles whether the A_BOLD attribute selects an actual + bold font (TRUE), or sets the foreground color to high intensity + (FALSE). It returns OK if it could set the state to match the given + parameter, ERR otherwise. PDC_set_title() sets the title of the window in which the curses program is running. This function may not do anything on some @@ -57,8 +61,23 @@ void PDC_set_title(const char *title) int PDC_set_blink(bool blinkon) { + SP->termattrs &= ~A_BLINK; if (pdc_color_started) COLORS = 16; return blinkon ? ERR : OK; } + +int PDC_set_bold(bool boldon) +{ +#ifdef PDC_WIDE + if (boldon) + SP->termattrs |= A_BOLD; + else + SP->termattrs &= ~A_BOLD; + + return OK; +#else + return boldon ? ERR : OK; +#endif +} diff --git a/win32/pdcscrn.c b/win32/pdcscrn.c index 26a65e92..34af5127 100644 --- a/win32/pdcscrn.c +++ b/win32/pdcscrn.c @@ -407,6 +407,8 @@ int PDC_scr_open(int argc, char **argv) SP->mouse_wait = PDC_CLICK_PERIOD; SP->audible = TRUE; + SP->termattrs = A_COLOR | A_REVERSE; + if (SP->lines < 2 || SP->lines > csbi.dwMaximumWindowSize.Y) { fprintf(stderr, "LINES value must be >= 2 and <= %d: got %d\n", diff --git a/win32/pdcsetsc.c b/win32/pdcsetsc.c index 432fee30..90825d79 100644 --- a/win32/pdcsetsc.c +++ b/win32/pdcsetsc.c @@ -10,6 +10,7 @@ pdcsetsc ### Synopsis int PDC_set_blink(bool blinkon); + int PDC_set_bold(bool boldon); void PDC_set_title(const char *title); ### Description @@ -18,9 +19,12 @@ pdcsetsc actual blink mode (TRUE), or sets the background color to high intensity (FALSE). The default is platform-dependent (FALSE in most cases). It returns OK if it could set the state to match - the given parameter, ERR otherwise. Current platforms also - adjust the value of COLORS according to this function -- 16 for - FALSE, and 8 for TRUE. + the given parameter, ERR otherwise. + + PDC_set_bold() toggles whether the A_BOLD attribute selects an actual + bold font (TRUE), or sets the foreground color to high intensity + (FALSE). It returns OK if it could set the state to match the given + parameter, ERR otherwise. PDC_set_title() sets the title of the window in which the curses program is running. This function may not do anything on some @@ -84,8 +88,14 @@ void PDC_set_title(const char *title) int PDC_set_blink(bool blinkon) { + SP->termattrs &= ~A_BLINK; if (pdc_color_started) COLORS = 16; return blinkon ? ERR : OK; } + +int PDC_set_bold(bool boldon) +{ + return boldon ? ERR : OK; +} diff --git a/x11/pdcsetsc.c b/x11/pdcsetsc.c index 1ea3d958..0a4d94bb 100644 --- a/x11/pdcsetsc.c +++ b/x11/pdcsetsc.c @@ -12,6 +12,7 @@ pdcsetsc ### Synopsis int PDC_set_blink(bool blinkon); + int PDC_set_bold(bool boldon); void PDC_set_title(const char *title); ### Description @@ -20,9 +21,12 @@ pdcsetsc actual blink mode (TRUE), or sets the background color to high intensity (FALSE). The default is platform-dependent (FALSE in most cases). It returns OK if it could set the state to match - the given parameter, ERR otherwise. Current platforms also - adjust the value of COLORS according to this function -- 16 for - FALSE, and 8 for TRUE. + the given parameter, ERR otherwise. + + PDC_set_bold() toggles whether the A_BOLD attribute selects an actual + bold font (TRUE), or sets the foreground color to high intensity + (FALSE). It returns OK if it could set the state to match the given + parameter, ERR otherwise. PDC_set_title() sets the title of the window in which the curses program is running. This function may not do anything on some @@ -69,8 +73,19 @@ void PDC_set_title(const char *title) int PDC_set_blink(bool blinkon) { + SP->termattrs &= ~A_BLINK; if (pdc_color_started) COLORS = 16; return blinkon ? ERR : OK; } + +int PDC_set_bold(bool boldon) +{ + if (boldon) + SP->termattrs |= A_BOLD; + else + SP->termattrs &= ~A_BOLD; + + return OK; +} diff --git a/x11/x11.c b/x11/x11.c index 159520a4..1a49d503 100644 --- a/x11/x11.c +++ b/x11/x11.c @@ -577,6 +577,7 @@ static int _new_packet(chtype attr, bool rev, int len, int col, int row, GC gc; int xpos, ypos; short fore, back; + attr_t sysattrs; PDC_pair_content(PAIR_NUMBER(attr), &fore, &back); @@ -588,8 +589,12 @@ static int _new_packet(chtype attr, bool rev, int len, int col, int row, /* Specify the color table offsets */ - fore |= (attr & A_BOLD) ? 8 : 0; - back |= (attr & A_BLINK) ? 8 : 0; + sysattrs = SP->termattrs; + + if ((attr & A_BOLD) && !(sysattrs & A_BOLD)) + fore |= 8; + if ((attr & A_BLINK) && !(sysattrs & A_BLINK)) + back |= 8; /* Reverse flag = highlighted selection XOR A_REVERSE set */ @@ -597,7 +602,12 @@ static int _new_packet(chtype attr, bool rev, int len, int col, int row, /* Determine which GC to use - normal, italic or bold */ - gc = (attr & A_ITALIC) ? italic_gc : (attr & A_BOLD) ? bold_gc : normal_gc; + if ((attr & A_ITALIC) && (sysattrs & A_ITALIC)) + gc = italic_gc; + else if ((attr & A_BOLD) && (sysattrs & A_BOLD)) + gc = bold_gc; + else + gc = normal_gc; /* Draw it */ @@ -3047,6 +3057,8 @@ int XCursesSetupX(int argc, char *argv[]) SP->mouse_wait = xc_app_data.clickPeriod; SP->audible = TRUE; + SP->termattrs = A_COLOR | A_ITALIC | A_PROTECT | A_REVERSE; + PDC_LOG(("%s:SHM size for curscr %d\n", XCLOGMSG, SP->XcurscrSize)); if ((shmid_Xcurscr = shmget(shmkey_Xcurscr, SP->XcurscrSize +