Support SGR 2 to dim the foreground colour.

I've done this on a 'where possible' basis: in Windows paletted mode
(in case anyone is still using an old enough graphics card to need
that!) I simply haven't bothered, and will completely ignore the dim
flag.
This commit is contained in:
Simon Tatham 2017-10-05 21:02:56 +01:00
Родитель 4743798400
Коммит 1a718403d4
4 изменённых файлов: 67 добавлений и 29 удалений

19
putty.h
Просмотреть файл

@ -104,15 +104,16 @@ typedef struct terminal_tag Terminal;
*/ */
#define UCSWIDE 0xDFFF #define UCSWIDE 0xDFFF
#define ATTR_NARROW 0x800000U #define ATTR_NARROW 0x0800000U
#define ATTR_WIDE 0x400000U #define ATTR_WIDE 0x0400000U
#define ATTR_BOLD 0x040000U #define ATTR_BOLD 0x0040000U
#define ATTR_UNDER 0x080000U #define ATTR_UNDER 0x0080000U
#define ATTR_REVERSE 0x100000U #define ATTR_REVERSE 0x0100000U
#define ATTR_BLINK 0x200000U #define ATTR_BLINK 0x0200000U
#define ATTR_FGMASK 0x0001FFU #define ATTR_FGMASK 0x00001FFU
#define ATTR_BGMASK 0x03FE00U #define ATTR_BGMASK 0x003FE00U
#define ATTR_COLOURS 0x03FFFFU #define ATTR_COLOURS 0x003FFFFU
#define ATTR_DIM 0x1000000U
#define ATTR_FGSHIFT 0 #define ATTR_FGSHIFT 0
#define ATTR_BGSHIFT 9 #define ATTR_BGSHIFT 9

Просмотреть файл

@ -3881,6 +3881,10 @@ static void term_out(Terminal *term)
compatibility(VT100AVO); compatibility(VT100AVO);
term->curr_attr |= ATTR_BOLD; term->curr_attr |= ATTR_BOLD;
break; break;
case 2: /* enable dim */
compatibility(OTHER);
term->curr_attr |= ATTR_DIM;
break;
case 21: /* (enable double underline) */ case 21: /* (enable double underline) */
compatibility(OTHER); compatibility(OTHER);
case 4: /* enable underline */ case 4: /* enable underline */
@ -3912,9 +3916,9 @@ static void term_out(Terminal *term)
compatibility(SCOANSI); compatibility(SCOANSI);
if (term->no_remote_charset) break; if (term->no_remote_charset) break;
term->sco_acs = 2; break; term->sco_acs = 2; break;
case 22: /* disable bold */ case 22: /* disable bold and dim */
compatibility2(OTHER, VT220); compatibility2(OTHER, VT220);
term->curr_attr &= ~ATTR_BOLD; term->curr_attr &= ~(ATTR_BOLD | ATTR_DIM);
break; break;
case 24: /* disable underline */ case 24: /* disable underline */
compatibility2(OTHER, VT220); compatibility2(OTHER, VT220);

Просмотреть файл

@ -3023,24 +3023,44 @@ static void draw_update(struct draw_ctx *dctx, int x, int y, int w, int h)
gtk_widget_queue_draw_area(dctx->inst->area, x, y, w, h); gtk_widget_queue_draw_area(dctx->inst->area, x, y, w, h);
} }
static void draw_set_colour(struct draw_ctx *dctx, int col) #ifdef DRAW_TEXT_CAIRO
static void cairo_set_source_rgb_dim(cairo_t *cr, double r, double g, double b,
int dim)
{
if (dim)
cairo_set_source_rgb(cr, r * 2 / 3, g * 2 / 3, b * 2 / 3);
else
cairo_set_source_rgb(cr, r, g, b);
}
#endif
static void draw_set_colour(struct draw_ctx *dctx, int col, int dim)
{ {
#ifdef DRAW_TEXT_GDK #ifdef DRAW_TEXT_GDK
if (dctx->uctx.type == DRAWTYPE_GDK) { if (dctx->uctx.type == DRAWTYPE_GDK) {
gdk_gc_set_foreground(dctx->uctx.u.gdk.gc, &dctx->inst->cols[col]); if (dim) {
GdkColor color;
color.red = dctx->inst->cols[col].red * 2 / 3;
color.green = dctx->inst->cols[col].green * 2 / 3;
color.blue = dctx->inst->cols[col].blue * 2 / 3;
gdk_gc_set_rgb_fg_color(dctx->uctx.u.gdk.gc, &color);
} else {
gdk_gc_set_foreground(dctx->uctx.u.gdk.gc, &dctx->inst->cols[col]);
}
} }
#endif #endif
#ifdef DRAW_TEXT_CAIRO #ifdef DRAW_TEXT_CAIRO
if (dctx->uctx.type == DRAWTYPE_CAIRO) { if (dctx->uctx.type == DRAWTYPE_CAIRO) {
cairo_set_source_rgb(dctx->uctx.u.cairo.cr, cairo_set_source_rgb_dim(dctx->uctx.u.cairo.cr,
dctx->inst->cols[col].red / 65535.0, dctx->inst->cols[col].red / 65535.0,
dctx->inst->cols[col].green / 65535.0, dctx->inst->cols[col].green / 65535.0,
dctx->inst->cols[col].blue / 65535.0); dctx->inst->cols[col].blue / 65535.0, dim);
} }
#endif #endif
} }
static void draw_set_colour_rgb(struct draw_ctx *dctx, optionalrgb orgb) static void draw_set_colour_rgb(struct draw_ctx *dctx, optionalrgb orgb,
int dim)
{ {
#ifdef DRAW_TEXT_GDK #ifdef DRAW_TEXT_GDK
if (dctx->uctx.type == DRAWTYPE_GDK) { if (dctx->uctx.type == DRAWTYPE_GDK) {
@ -3048,13 +3068,19 @@ static void draw_set_colour_rgb(struct draw_ctx *dctx, optionalrgb orgb)
color.red = orgb.r * 256; color.red = orgb.r * 256;
color.green = orgb.g * 256; color.green = orgb.g * 256;
color.blue = orgb.b * 256; color.blue = orgb.b * 256;
if (dim) {
color.red = color.red * 2 / 3;
color.green = color.green * 2 / 3;
color.blue = color.blue * 2 / 3;
}
gdk_gc_set_rgb_fg_color(dctx->uctx.u.gdk.gc, &color); gdk_gc_set_rgb_fg_color(dctx->uctx.u.gdk.gc, &color);
} }
#endif #endif
#ifdef DRAW_TEXT_CAIRO #ifdef DRAW_TEXT_CAIRO
if (dctx->uctx.type == DRAWTYPE_CAIRO) if (dctx->uctx.type == DRAWTYPE_CAIRO) {
cairo_set_source_rgb(dctx->uctx.u.cairo.cr, cairo_set_source_rgb_dim(dctx->uctx.u.cairo.cr, orgb.r / 255.0,
orgb.r / 255.0, orgb.g / 255.0, orgb.b / 255.0); orgb.g / 255.0, orgb.b / 255.0, dim);
}
#endif #endif
} }
@ -3238,7 +3264,7 @@ static void draw_backing_rect(struct gui_data *inst)
struct draw_ctx *dctx = get_ctx(inst); struct draw_ctx *dctx = get_ctx(inst);
int w = inst->width * inst->font_width + 2*inst->window_border; int w = inst->width * inst->font_width + 2*inst->window_border;
int h = inst->height * inst->font_height + 2*inst->window_border; int h = inst->height * inst->font_height + 2*inst->window_border;
draw_set_colour(dctx, 258); draw_set_colour(dctx, 258, FALSE);
draw_rectangle(dctx, 1, 0, 0, w, h); draw_rectangle(dctx, 1, 0, 0, w, h);
draw_update(dctx, 0, 0, w, h); draw_update(dctx, 0, 0, w, h);
free_ctx(dctx); free_ctx(dctx);
@ -3288,6 +3314,7 @@ void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len,
truecolour.fg = truecolour.bg = optionalrgb_none; truecolour.fg = truecolour.bg = optionalrgb_none;
nfg = 260; nfg = 260;
nbg = 261; nbg = 261;
attr &= ~ATTR_DIM; /* don't dim the cursor */
} }
fontid = shadow = 0; fontid = shadow = 0;
@ -3350,18 +3377,18 @@ void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len,
} }
if (truecolour.bg.enabled) if (truecolour.bg.enabled)
draw_set_colour_rgb(dctx, truecolour.bg); draw_set_colour_rgb(dctx, truecolour.bg, attr & ATTR_DIM);
else else
draw_set_colour(dctx, nbg); draw_set_colour(dctx, nbg, attr & ATTR_DIM);
draw_rectangle(dctx, TRUE, draw_rectangle(dctx, TRUE,
x*inst->font_width+inst->window_border, x*inst->font_width+inst->window_border,
y*inst->font_height+inst->window_border, y*inst->font_height+inst->window_border,
rlen*widefactor*inst->font_width, inst->font_height); rlen*widefactor*inst->font_width, inst->font_height);
if (truecolour.fg.enabled) if (truecolour.fg.enabled)
draw_set_colour_rgb(dctx, truecolour.fg); draw_set_colour_rgb(dctx, truecolour.fg, attr & ATTR_DIM);
else else
draw_set_colour(dctx, nfg); draw_set_colour(dctx, nfg, attr & ATTR_DIM);
if (ncombining > 1) { if (ncombining > 1) {
assert(len == 1); assert(len == 1);
unifont_draw_combining(&dctx->uctx, inst->fonts[fontid], unifont_draw_combining(&dctx->uctx, inst->fonts[fontid],
@ -3475,7 +3502,7 @@ void do_cursor(Context ctx, int x, int y, wchar_t *text, int len,
* if it's passive. * if it's passive.
*/ */
if (passive) { if (passive) {
draw_set_colour(dctx, 261); draw_set_colour(dctx, 261, FALSE);
draw_rectangle(dctx, FALSE, draw_rectangle(dctx, FALSE,
x*inst->font_width+inst->window_border, x*inst->font_width+inst->window_border,
y*inst->font_height+inst->window_border, y*inst->font_height+inst->window_border,
@ -3514,7 +3541,7 @@ void do_cursor(Context ctx, int x, int y, wchar_t *text, int len,
length = inst->font_height; length = inst->font_height;
} }
draw_set_colour(dctx, 261); draw_set_colour(dctx, 261, FALSE);
if (passive) { if (passive) {
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (i % 2 == 0) { if (i % 2 == 0) {

Просмотреть файл

@ -3440,7 +3440,7 @@ void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len,
if ((attr & TATTR_ACTCURS) && (cursor_type == 0 || term->big_cursor)) { if ((attr & TATTR_ACTCURS) && (cursor_type == 0 || term->big_cursor)) {
truecolour.fg = truecolour.bg = optionalrgb_none; truecolour.fg = truecolour.bg = optionalrgb_none;
attr &= ~(ATTR_REVERSE|ATTR_BLINK|ATTR_COLOURS); attr &= ~(ATTR_REVERSE|ATTR_BLINK|ATTR_COLOURS|ATTR_DIM);
/* cursor fg and bg */ /* cursor fg and bg */
attr |= (260 << ATTR_FGSHIFT) | (261 << ATTR_BGSHIFT); attr |= (260 << ATTR_FGSHIFT) | (261 << ATTR_BGSHIFT);
is_cursor = TRUE; is_cursor = TRUE;
@ -3543,6 +3543,12 @@ void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len,
else else
bg = colours[nbg]; bg = colours[nbg];
if (!pal && (attr & ATTR_DIM)) {
fg = RGB(GetRValue(fg) * 2 / 3,
GetGValue(fg) * 2 / 3,
GetBValue(fg) * 2 / 3);
}
SelectObject(hdc, fonts[nfont]); SelectObject(hdc, fonts[nfont]);
SetTextColor(hdc, fg); SetTextColor(hdc, fg);
SetBkColor(hdc, bg); SetBkColor(hdc, bg);