[pango/pango-1-44: 27/31] markup: Fix two bugs




commit 2b40c8ec42e5c9af9f37147adc632b88d6bbaad3
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.
    
    (cherry-picked from commit 8d1ea2ae)

 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 6dce1b2e..da281a62 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -665,8 +665,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;
@@ -681,35 +694,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]