From 28063ee2e42e7ce47b7bd5326f2d53875a377d57 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 9 Feb 2015 16:41:48 -0800 Subject: textview: add support for underline and strikethrough colors This commit adds the GtkTextTag:underline-rgba and :strikethrough-rgba properties and the necessary plumbing to apply these colors in GtkTextLayout. With this change, you can alter the color of underlines including those of type PANGO_UNDERLINE_ERROR. You might want to alter the underline color to differentiate between spelling and grammer mistakes. In code editors, it is convenient to differentiate between errors and warnings. Note that the GtkTextAppearance struct is public ABI and has no spare room for new fields, so we are resorting to some tricky packing to store the colors in the unused pixel field of the fg_color and bg_color structs. This packing is accomplished by the macros in gtktextattributesprivate.h. Signed-off-by: Christian Hergert https://bugzilla.gnome.org/show_bug.cgi?id=402168 --- gtk/gtktextdisplay.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'gtk/gtktextdisplay.c') diff --git a/gtk/gtktextdisplay.c b/gtk/gtktextdisplay.c index 6be8fe2c8c..f817801880 100644 --- a/gtk/gtktextdisplay.c +++ b/gtk/gtktextdisplay.c @@ -75,6 +75,7 @@ #define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API #include "config.h" +#include "gtktextattributesprivate.h" #include "gtktextdisplay.h" #include "gtkwidgetprivate.h" #include "gtkstylecontextprivate.h" @@ -204,9 +205,25 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer, fg_rgba = appearance->rgba[1]; text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_FOREGROUND, fg_rgba); - text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_STRIKETHROUGH, fg_rgba); - if (appearance->underline == PANGO_UNDERLINE_ERROR) + if (GTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA_SET (appearance)) + { + GdkRGBA rgba; + + GTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA (appearance, &rgba); + text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_STRIKETHROUGH, &rgba); + } + else + text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_STRIKETHROUGH, fg_rgba); + + if (GTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA_SET (appearance)) + { + GdkRGBA rgba; + + GTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA (appearance, &rgba); + text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_UNDERLINE, &rgba); + } + else if (appearance->underline == PANGO_UNDERLINE_ERROR) { if (!text_renderer->error_color) { -- cgit v1.2.1