[pango/markup-parse-fixes: 4/5] markup: Fix two bugs




commit efa9be1c88acbef3f112a125622647e7d79a7ece
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Mar 2 20:58:15 2021 -0500

    markup: Fix two bugs
    
    The docs state that all chars marked with the accel
    marker get an underline. But we were only underlining
    the first in each text chunk.
    
    Second, if an underline appears at the end of a text
    chunk, or at the end of the text, we would just eat
    it, which is unexpected.

 pango/pango-markup.c | 50 ++++++++++++++++++++------------------------------
 1 file changed, 20 insertions(+), 30 deletions(-)
---
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index b74c1ad4..d0b47016 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -677,8 +677,21 @@ text_handler           (GMarkupParseContext *context G_GNUC_UNUSED,
                  /* The underline should go underneath the char
                   * we're setting as the next range_start
                   */
-                 uline_index = md->index;
-                 uline_len = g_utf8_next_char (p) - p;
+                  if (md->attr_list != NULL)
+                    {
+                      /* Add the underline indicating the accelerator */
+                      PangoAttribute *attr;
+
+                      attr = pango_attr_underline_new (PANGO_UNDERLINE_LOW);
+
+                      uline_index = md->index;
+                      uline_len = g_utf8_next_char (p) - p;
+
+                      attr->start_index = uline_index;
+                      attr->end_index = uline_index + uline_len;
+
+                      pango_attr_list_change (md->attr_list, attr);
+                    }
 
                  /* set next range_start to include this char */
                  range_start = p;
@@ -693,35 +706,12 @@ text_handler           (GMarkupParseContext *context G_GNUC_UNUSED,
            }
 
          p = g_utf8_next_char (p);
-       }
-
-      if (range_end)
-       {
-         g_string_append_len (md->text,
-                              range_start,
-                              range_end - range_start);
-         md->index += range_end - range_start;
-       }
-      else
-       {
-         g_string_append_len (md->text,
-                              range_start,
-                              end - range_start);
-         md->index += end - range_start;
-       }
-
-      if (md->attr_list != NULL && uline_index >= 0)
-       {
-         /* Add the underline indicating the accelerator */
-         PangoAttribute *attr;
-
-         attr = pango_attr_underline_new (PANGO_UNDERLINE_LOW);
-
-         attr->start_index = uline_index;
-         attr->end_index = uline_index + uline_len;
+        }
 
-         pango_attr_list_change (md->attr_list, attr);
-       }
+      g_string_append_len (md->text,
+                           range_start,
+                           end - range_start);
+                           md->index += end - range_start;
     }
 }
 


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