[dia] svg: named color fixes (no more pango_color_parse())



commit 885648bb2a8c7bc0da1f28d0cd5ca1aa6e0360ce
Author: Hans Breuer <hans breuer org>
Date:   Wed Aug 28 09:36:58 2013 +0200

    svg: named color fixes (no more pango_color_parse())
    
     - get rid of pango_color_parse(), at least for green the color
       value is wrong, also the fallback was hiding bugs with the
       internal list of named colors
     - _svg_named_colors array needs to be sorted on the color name.
       The lookup of green failed because of grey being before green
     - move color name termination logic to be in use for
       svg_named_color() - names from style string might be terminated
       by [; ]

 lib/dia_svg.c |   22 +++++++---------------
 1 files changed, 7 insertions(+), 15 deletions(-)
---
diff --git a/lib/dia_svg.c b/lib/dia_svg.c
index b16c171..49884ca 100644
--- a/lib/dia_svg.c
+++ b/lib/dia_svg.c
@@ -155,9 +155,9 @@ static const struct _SvgNamedColor {
        { 0xFFD700, "gold" },
        { 0xDAA520, "goldenrod" },
        { 0x808080, "gray" },
-       { 0x808080, "grey" },
        { 0x008000, "green" },
        { 0xADFF2F, "greenyellow" },
+       { 0x808080, "grey" },
        { 0xF0FFF0, "honeydew" },
        { 0xFF69B4, "hotpink" },
        { 0xCD5C5C, "indianred" },
@@ -353,27 +353,19 @@ _parse_color(gint32 *color, const char *str)
       *color = ((a<<24) & 0xFF000000) | ((r<<16) & 0xFF0000) | ((g<<8) & 0xFF00) | (b & 0xFF);
     else
       return FALSE;
-  } else if (svg_named_color (str, color)) {
-    return TRUE;
   } else {
-    /* Pango needs null terminated strings, so we just use it as a fallback */
-    PangoColor pc;
     char* se = strchr (str, ';');
     if (!se) /* style might have trailign space */
       se = strchr (str, ' ');
 
     if (!se) {
-      if (pango_color_parse (&pc, str))
-       *color = ((0xFF<<24) & 0xFF000000) | ((pc.red >> 8) << 16) | ((pc.green >> 8) << 8) | (pc.blue >> 8);
-      else
-       return FALSE;
+      return svg_named_color (str, color);
     } else {
-      gchar* sz = g_strndup (str, se - str);
-      gboolean ret = pango_color_parse (&pc, sz);
-
-      if (ret)
-       *color = ((0xFF<<24) & 0xFF000000) | ((pc.red >> 8) << 16) | ((pc.green >> 8) << 8) | (pc.blue >> 8);
-      g_free (sz);
+      /* need to make a copy of the color only */
+      gboolean ret;
+      gchar *sc = g_strndup (str, se - str);
+      ret = svg_named_color (sc, color);
+      g_free (sc);
       return ret;
     }
   }


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