[gimp] app: fix gimp_text_buffer_get_color_tag()



commit 7dbaf348c5931db6be4444124e982f184ff6b807
Author: Michael Natterer <mitch gimp org>
Date:   Sat Oct 2 19:53:39 2010 +0200

    app: fix gimp_text_buffer_get_color_tag()
    
    Change the generated tag names to use #rrggbb notation and compare the
    colors on an 8 bit basis to make sure the comparison and the tag names
    exist in the same set of values (otherwise the text buffer gets into
    an inconsistent state that can even lead to crashes).

 app/widgets/gimptextbuffer.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/app/widgets/gimptextbuffer.c b/app/widgets/gimptextbuffer.c
index 76e17cc..9dd257f 100644
--- a/app/widgets/gimptextbuffer.c
+++ b/app/widgets/gimptextbuffer.c
@@ -947,26 +947,32 @@ gimp_text_buffer_get_color_tag (GimpTextBuffer *buffer,
   GtkTextTag *tag;
   gchar       name[256];
   GdkColor    gdk_color;
+  guchar      r, g, b;
+
+  gimp_rgb_get_uchar (color, &r, &g, &b);
 
   for (list = buffer->color_tags; list; list = g_list_next (list))
     {
       GimpRGB tag_color;
+      guchar  tag_r, tag_g, tag_b;
 
       tag = list->data;
 
       gimp_text_tag_get_color (tag, &tag_color);
 
+      gimp_rgb_get_uchar (&tag_color, &tag_r, &tag_g, &tag_b);
+
       /* Do not compare the alpha channel, since it's unused */
-      if (tag_color.r == color->r &&
-          tag_color.g == color->g &&
-          tag_color.b == color->b)
+      if (tag_r == r &&
+          tag_g == g &&
+          tag_b == b)
         {
           return tag;
         }
     }
 
-  g_snprintf (name, sizeof (name), "color-(%0.f,%0.f,%0.f)",
-              color->r, color->g, color->b);
+  g_snprintf (name, sizeof (name), "color-#%02x%02x%02x",
+              r, g, b);
 
   gimp_rgb_get_gdk_color (color, &gdk_color);
 



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