[gspell/wip/underline-single: 1/2] InlineCheckerTextBuffer: change underline to PANGO_UNDERLINE_SINGLE



commit 6b35739d059e25d7a66737197696cfc047b421bb
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Mar 31 17:33:35 2017 +0200

    InlineCheckerTextBuffer: change underline to PANGO_UNDERLINE_SINGLE
    
    Because PANGO_UNDERLINE_ERROR is buggy:
    https://bugzilla.gnome.org/show_bug.cgi?id=763741
    
    It'll permit to remove a hack in gspell that tries to work around the
    bug (but doesn't work in all cases).
    
    KWrite (KDE text editor) also inserts the equivalent of
    PANGO_UNDERLINE_SINGLE. They maybe have the same bug with wavy
    underlines.
    
    The color is defined in gspell-utils.h, because it'll be useful to have
    a common place to define the color for both GtkTextView and GtkEntry.

 gspell/gspell-inline-checker-text-buffer.c |    8 ++++++--
 gspell/gspell-text-view.c                  |   13 ++++++++-----
 gspell/gspell-utils.c                      |   19 ++++++++++++++++++-
 gspell/gspell-utils.h                      |    5 ++++-
 4 files changed, 36 insertions(+), 9 deletions(-)
---
diff --git a/gspell/gspell-inline-checker-text-buffer.c b/gspell/gspell-inline-checker-text-buffer.c
index 73997e4..f00b251 100644
--- a/gspell/gspell-inline-checker-text-buffer.c
+++ b/gspell/gspell-inline-checker-text-buffer.c
@@ -2,7 +2,7 @@
  * This file is part of gspell, a spell-checking library.
  *
  * Copyright 2002 - Paolo Maggi
- * Copyright 2015, 2016 - Sébastien Wilmet
+ * Copyright 2015, 2016, 2017 - Sébastien Wilmet
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1060,6 +1060,7 @@ set_buffer (GspellInlineCheckerTextBuffer *spell,
        GtkTextIter start;
        GspellTextBuffer *gspell_buffer;
        GspellChecker *checker;
+       GdkRGBA underline_color;
 
        g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
        g_return_if_fail (spell->buffer == NULL);
@@ -1115,8 +1116,11 @@ set_buffer (GspellInlineCheckerTextBuffer *spell,
                                 spell,
                                 G_CONNECT_AFTER);
 
+       _gspell_utils_init_underline_rgba (&underline_color);
+
        spell->highlight_tag = gtk_text_buffer_create_tag (spell->buffer, NULL,
-                                                          "underline", PANGO_UNDERLINE_ERROR,
+                                                          "underline", PANGO_UNDERLINE_SINGLE,
+                                                          "underline-rgba", &underline_color,
                                                           NULL);
        g_object_ref (spell->highlight_tag);
 
diff --git a/gspell/gspell-text-view.c b/gspell/gspell-text-view.c
index 453f6e8..f21d89c 100644
--- a/gspell/gspell-text-view.c
+++ b/gspell/gspell-text-view.c
@@ -32,11 +32,11 @@
  * @Short_description: Spell checking support for GtkTextView
  *
  * #GspellTextView extends the #GtkTextView class with inline spell checking.
- * Misspelled words are highlighted with a %PANGO_UNDERLINE_ERROR, usually a red
- * wavy underline. Right-clicking a misspelled word pops up a context menu of
- * suggested replacements. The context menu also contains an “Ignore All” item
- * to add the misspelled word to the session dictionary. And an “Add” item to
- * add the word to the personal dictionary.
+ * Misspelled words are highlighted with a red %PANGO_UNDERLINE_SINGLE.
+ * Right-clicking a misspelled word pops up a context menu of suggested
+ * replacements. The context menu also contains an “Ignore All” item to add the
+ * misspelled word to the session dictionary. And an “Add” item to add the word
+ * to the personal dictionary.
  *
  * For a basic use-case, there is the gspell_text_view_basic_setup() convenience
  * function.
@@ -53,6 +53,9 @@
  * Note that #GspellTextView extends the #GtkTextView class but without
  * subclassing it, because the GtkSourceView library has already a #GtkTextView
  * subclass.
+ *
+ * If you want a %PANGO_UNDERLINE_ERROR instead (a wavy underline), please fix
+ * [this bug](https://bugzilla.gnome.org/show_bug.cgi?id=763741) first.
  */
 
 typedef struct _GspellTextViewPrivate GspellTextViewPrivate;
diff --git a/gspell/gspell-utils.c b/gspell/gspell-utils.c
index c2be3e8..4582b1c 100644
--- a/gspell/gspell-utils.c
+++ b/gspell/gspell-utils.c
@@ -2,7 +2,7 @@
  * This file is part of gspell, a spell-checking library.
  *
  * Copyright 2010 - Jesse van den Kieboom
- * Copyright 2015, 2016 - Sébastien Wilmet
+ * Copyright 2015, 2016, 2017 - Sébastien Wilmet
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -202,4 +202,21 @@ _gspell_utils_is_apostrophe_or_dash (gunichar ch)
                ch == _GSPELL_RIGHT_SINGLE_QUOTATION_MARK);
 }
 
+/* Not the full intensity for the red, it's more readable with the red a bit
+ * darker for PANGO_UNDERLINE_SINGLE.
+ * For PANGO_UNDERLINE_ERROR, the full red intensity was used.
+ */
+#define UNDERLINE_COLOR_RED_INTENSITY (0.8)
+
+void
+_gspell_utils_init_underline_rgba (GdkRGBA *underline_color)
+{
+       g_return_if_fail (underline_color != NULL);
+
+       underline_color->red = UNDERLINE_COLOR_RED_INTENSITY;
+       underline_color->green = 0.0;
+       underline_color->blue = 0.0;
+       underline_color->alpha = 1.0;
+}
+
 /* ex:set ts=8 noet: */
diff --git a/gspell/gspell-utils.h b/gspell/gspell-utils.h
index 89f6909..63f482b 100644
--- a/gspell/gspell-utils.h
+++ b/gspell/gspell-utils.h
@@ -2,7 +2,7 @@
  * This file is part of gspell, a spell-checking library.
  *
  * Copyright 2010 - Jesse van den Kieboom
- * Copyright 2015, 2016 - Sébastien Wilmet
+ * Copyright 2015, 2016, 2017 - Sébastien Wilmet
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -54,6 +54,9 @@ gboolean      _gspell_utils_str_to_ascii_apostrophe   (const gchar  *word,
 G_GNUC_INTERNAL
 gboolean       _gspell_utils_is_apostrophe_or_dash     (gunichar ch);
 
+G_GNUC_INTERNAL
+void           _gspell_utils_init_underline_rgba       (GdkRGBA *underline_color);
+
 G_END_DECLS
 
 #endif /* GSPELL_UTILS_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]