Skip to content
This repository has been archived by the owner on Feb 10, 2024. It is now read-only.

Commit

Permalink
Implement support for strikethrough text.
Browse files Browse the repository at this point in the history
  • Loading branch information
SadieCat authored and TingPing committed Jun 20, 2021
1 parent 08e13a3 commit 55e4f1c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/common/outbound.c
Expand Up @@ -4434,6 +4434,9 @@ check_special_chars (char *cmd, int do_ascii) /* check for %X */
case 'I':
buf[i] = '\035';
break;
case 'S':
buf[i] = '\036';
break;
case 'C':
buf[i] = '\003';
break;
Expand Down
1 change: 1 addition & 0 deletions src/common/util.c
Expand Up @@ -329,6 +329,7 @@ strip_color2 (const char *src, int len, char *dst, int flags)
case '\026': /*ATTR_REVERSE: */
case '\002': /*ATTR_BOLD: */
case '\037': /*ATTR_UNDERLINE: */
case '\036': /*ATTR_STRIKETHROUGH: */
case '\035': /*ATTR_ITALICS: */
if (!(flags & STRIP_ATTRIB)) goto pass_char;
break;
Expand Down
5 changes: 4 additions & 1 deletion src/fe-gtk/maingui.c
Expand Up @@ -1394,6 +1394,8 @@ mg_color_insert (GtkWidget *item, gpointer userdata)
text = "\037"; break;
case 102:
text = "\035"; break;
case 103:
text = "\036"; break;
default:
text = "\017"; break;
}
Expand Down Expand Up @@ -1447,7 +1449,8 @@ mg_create_color_menu (GtkWidget *menu, session *sess)
mg_markup_item (submenu, _("<b>Bold</b>"), 100);
mg_markup_item (submenu, _("<u>Underline</u>"), 101);
mg_markup_item (submenu, _("<i>Italic</i>"), 102);
mg_markup_item (submenu, _("Normal"), 103);
mg_markup_item (submenu, _("<s>Strikethrough</s>"), 103);
mg_markup_item (submenu, _("Normal"), 999);

subsubmenu = mg_submenu (submenu, _("Colors 0-7"));

Expand Down
20 changes: 20 additions & 0 deletions src/fe-gtk/sexy-spell-entry.c
Expand Up @@ -389,6 +389,17 @@ insert_italic (SexySpellEntry *entry, guint start, gboolean toggle)
pango_attr_list_change (entry->priv->attr_list, iattr);
}

static void
insert_strikethrough (SexySpellEntry *entry, guint start, gboolean toggle)
{
PangoAttribute *sattr;

sattr = pango_attr_strikethrough_new (!toggle);
sattr->start_index = start;
sattr->end_index = PANGO_ATTR_INDEX_TO_TEXT_END;
pango_attr_list_change (entry->priv->attr_list, sattr);
}

static void
insert_color (SexySpellEntry *entry, guint start, int fgcolor, int bgcolor)
{
Expand Down Expand Up @@ -429,6 +440,7 @@ insert_reset (SexySpellEntry *entry, guint start)
insert_bold (entry, start, TRUE);
insert_underline (entry, start, TRUE);
insert_italic (entry, start, TRUE);
insert_strikethrough (entry, start, TRUE);
insert_color (entry, start, -1, -1);
}

Expand Down Expand Up @@ -918,6 +930,7 @@ check_attributes (SexySpellEntry *entry, const char *text, int len)
gboolean bold = FALSE;
gboolean italic = FALSE;
gboolean underline = FALSE;
gboolean strikethrough = FALSE;
int parsing_color = 0;
char fg_color[3];
char bg_color[3];
Expand All @@ -942,6 +955,12 @@ check_attributes (SexySpellEntry *entry, const char *text, int len)
italic = !italic;
goto check_color;

case ATTR_STRIKETHROUGH:
insert_hiddenchar (entry, i, i + 1);
insert_strikethrough (entry, i, strikethrough);
strikethrough = !strikethrough;
goto check_color;

case ATTR_UNDERLINE:
insert_hiddenchar (entry, i, i + 1);
insert_underline (entry, i, underline);
Expand All @@ -954,6 +973,7 @@ check_attributes (SexySpellEntry *entry, const char *text, int len)
bold = FALSE;
italic = FALSE;
underline = FALSE;
strikethrough = FALSE;
goto check_color;

case ATTR_HIDDEN:
Expand Down
17 changes: 17 additions & 0 deletions src/fe-gtk/xtext.c
Expand Up @@ -433,6 +433,7 @@ gtk_xtext_init (GtkXText * xtext)
xtext->nc = 0;
xtext->pixel_offset = 0;
xtext->underline = FALSE;
xtext->strikethrough = FALSE;
xtext->hidden = FALSE;
xtext->font = NULL;
xtext->layout = NULL;
Expand Down Expand Up @@ -2451,6 +2452,7 @@ gtk_xtext_strip_color (unsigned char *text, int len, unsigned char *outbuf,
case ATTR_REVERSE:
case ATTR_BOLD:
case ATTR_UNDERLINE:
case ATTR_STRIKETHROUGH:
case ATTR_ITALICS:
xtext_do_chunk (&c);
if (*text == ATTR_RESET)
Expand Down Expand Up @@ -2627,6 +2629,13 @@ gtk_xtext_render_flush (GtkXText * xtext, int x, int y, unsigned char *str,
g_object_unref (pix);
}

if (xtext->strikethrough)
{
/* pango_attr_strikethrough_new does not render in the custom widget so we need to reinvent the wheel */
y = dest_y + (xtext->fontsize / 2);
gdk_draw_line (xtext->draw_buf, gc, dest_x, y, dest_x + str_width - 1, y);
}

if (xtext->underline)
{
dounder:
Expand All @@ -2651,6 +2660,7 @@ gtk_xtext_reset (GtkXText * xtext, int mark, int attribs)
if (attribs)
{
xtext->underline = FALSE;
xtext->strikethrough = FALSE;
xtext->hidden = FALSE;
}
if (!mark)
Expand Down Expand Up @@ -2961,6 +2971,12 @@ gtk_xtext_render_str (GtkXText * xtext, int y, textentry * ent,
pstr += j + 1;
j = 0;
break;
case ATTR_STRIKETHROUGH:
RENDER_FLUSH;
xtext->strikethrough = !xtext->strikethrough;
pstr += j + 1;
j = 0;
break;
case ATTR_ITALICS:
RENDER_FLUSH;
*emphasis ^= EMPH_ITAL;
Expand Down Expand Up @@ -3191,6 +3207,7 @@ find_next_wrap (GtkXText * xtext, textentry * ent, unsigned char *str,
case ATTR_REVERSE:
case ATTR_BOLD:
case ATTR_UNDERLINE:
case ATTR_STRIKETHROUGH:
case ATTR_ITALICS:
if (*str == ATTR_RESET)
emphasis = 0;
Expand Down
22 changes: 12 additions & 10 deletions src/fe-gtk/xtext.h
Expand Up @@ -29,16 +29,17 @@
#define GTK_IS_XTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_XTEXT))
#define GTK_XTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_XTEXT, GtkXTextClass))

#define ATTR_BOLD '\002'
#define ATTR_COLOR '\003'
#define ATTR_BLINK '\006'
#define ATTR_BEEP '\007'
#define ATTR_HIDDEN '\010'
#define ATTR_ITALICS2 '\011'
#define ATTR_RESET '\017'
#define ATTR_REVERSE '\026'
#define ATTR_ITALICS '\035'
#define ATTR_UNDERLINE '\037'
#define ATTR_BOLD '\002'
#define ATTR_COLOR '\003'
#define ATTR_BLINK '\006'
#define ATTR_BEEP '\007'
#define ATTR_HIDDEN '\010'
#define ATTR_ITALICS2 '\011'
#define ATTR_RESET '\017'
#define ATTR_REVERSE '\026'
#define ATTR_ITALICS '\035'
#define ATTR_STRIKETHROUGH '\036'
#define ATTR_UNDERLINE '\037'

/* these match palette.h */
#define XTEXT_MIRC_COLS 32
Expand Down Expand Up @@ -207,6 +208,7 @@ struct _GtkXText

/* current text states */
unsigned int underline:1;
unsigned int strikethrough:1;
unsigned int hidden:1;

/* text parsing states */
Expand Down

0 comments on commit 55e4f1c

Please sign in to comment.