1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 11:32:48 -05:00

Support SGR 9 for strikethrough effect on text.

This is mostly easy: it's just like drawing an underline, except that
you put it at a different height in the character cell. The only
question is _where_ in the character cell.

Pango, and Windows GetOutlineTextMetrics, will tell you exactly where
the font wants to have it. Following xterm, I fall back to 3/8 of the
font's ascent (above the baseline) if either of those is unavailable.
This commit is contained in:
Simon Tatham
2020-08-13 21:08:53 +01:00
parent 334d87251e
commit 06a8d11964
6 changed files with 52 additions and 15 deletions

View File

@ -511,6 +511,7 @@ static unifont *x11font_create(GtkWidget *widget, const char *name,
xfont->u.height = xfont->u.ascent + xfont->u.descent;
xfont->u.public_charset = pubcs;
xfont->u.want_fallback = true;
xfont->u.strikethrough_y = xfont->u.ascent - (xfont->u.ascent * 3 / 8);
#ifdef DRAW_TEXT_GDK
xfont->u.preferred_drawtype = DRAWTYPE_GDK;
#elif defined DRAW_TEXT_CAIRO
@ -1463,6 +1464,9 @@ static unifont *pangofont_create_internal(GtkWidget *widget,
pfont->u.descent =
PANGO_PIXELS_CEIL(pango_font_metrics_get_descent(metrics));
pfont->u.height = pfont->u.ascent + pfont->u.descent;
pfont->u.strikethrough_y =
PANGO_PIXELS(pango_font_metrics_get_ascent(metrics) -
pango_font_metrics_get_strikethrough_position(metrics));
pfont->u.want_fallback = false;
#ifdef DRAW_TEXT_CAIRO
pfont->u.preferred_drawtype = DRAWTYPE_CAIRO;
@ -2242,6 +2246,7 @@ unifont *multifont_create(GtkWidget *widget, const char *name,
mfont->u.ascent = font->ascent;
mfont->u.descent = font->descent;
mfont->u.height = font->height;
mfont->u.strikethrough_y = font->strikethrough_y;
mfont->u.public_charset = font->public_charset;
mfont->u.want_fallback = false; /* shouldn't be needed, but just in case */
mfont->u.preferred_drawtype = font->preferred_drawtype;

View File

@ -67,7 +67,7 @@ typedef struct unifont {
/*
* Font dimensions needed by clients.
*/
int width, height, ascent, descent;
int width, height, ascent, descent, strikethrough_y;
/*
* Indicates whether this font is capable of handling all glyphs

View File

@ -3887,6 +3887,14 @@ static void do_text_internal(
y*inst->font_height + uheight + inst->window_border);
}
if (attr & ATTR_STRIKE) {
int sheight = inst->fonts[fontid]->strikethrough_y;
draw_line(inst, x*inst->font_width+inst->window_border,
y*inst->font_height + sheight + inst->window_border,
(x+len)*widefactor*inst->font_width-1+inst->window_border,
y*inst->font_height + sheight + inst->window_border);
}
if ((lattr & LATTR_MODE) != LATTR_NORM) {
draw_stretch_after(inst,
x*inst->font_width+inst->window_border,