Code

glib/gtestutils.h is not available on gutsy, so switching to include of
[inkscape.git] / src / svg / svg-color.cpp
index 2bae38641b170413e9642e17afe16e96716d966a..fe79736dc809d32ebb2f172532b469a3808973cd 100644 (file)
 # include "config.h"
 #endif
 
+#include "prefs-utils.h"
 #include "svg-color.h"
 #include "svg-icc-color.h"
 #include <cassert>
 #include <math.h>
 #include <glib/gmem.h>
+#include <glib.h> // g_assert
 #include <glib/gmessages.h>
 #include <glib/gstrfuncs.h>
 #include <glib/ghash.h>
@@ -235,22 +237,22 @@ internal_sp_svg_read_color(gchar const *str, gchar const **end_ptr, guint32 def)
             *end_ptr = str + i;
         }
     } else if (strneq(str, "rgb(", 4)) {
-        gboolean hasp, hasd;
+        bool hasp, hasd;
         gchar *s, *e;
         gdouble r, g, b;
 
         s = (gchar *) str + 4;
-        hasp = FALSE;
-        hasd = FALSE;
+        hasp = false;
+        hasd = false;
 
         r = g_ascii_strtod(s, &e);
         if (s == e) return def;
         s = e;
         if (*s == '%') {
-            hasp = TRUE;
+            hasp = true;
             s += 1;
         } else {
-            hasd = TRUE;
+            hasd = true;
         }
         while (*s && g_ascii_isspace(*s)) s += 1;
         if (*s != ',') return def;
@@ -260,10 +262,10 @@ internal_sp_svg_read_color(gchar const *str, gchar const **end_ptr, guint32 def)
         if (s == e) return def;
         s = e;
         if (*s == '%') {
-            hasp = TRUE;
+            hasp = true;
             s += 1;
         } else {
-            hasd = TRUE;
+            hasd = true;
         }
         while (*s && g_ascii_isspace(*s)) s += 1;
         if (*s != ',') return def;
@@ -273,9 +275,10 @@ internal_sp_svg_read_color(gchar const *str, gchar const **end_ptr, guint32 def)
         if (s == e) return def;
         s = e;
         if (*s == '%') {
-            hasp = TRUE;
+            hasp = true;
+            s += 1;
         } else {
-            hasd = TRUE;
+            hasd = true;
         }
         while(*s && g_ascii_isspace(*s)) s += 1;
         if (*s != ')') {
@@ -408,7 +411,7 @@ rgb24_to_css(char *const buf, unsigned const rgb24)
         strcpy(buf, src);
     }
 
-    assert(sp_svg_read_color(buf, 0xff) == (rgb24 << 8));
+    // assert(sp_svg_read_color(buf, 0xff) == (rgb24 << 8));
 }
 
 /**
@@ -424,7 +427,11 @@ sp_svg_write_color(gchar *buf, unsigned const buflen, guint32 const rgba32)
     g_assert(8 <= buflen);
 
     unsigned const rgb24 = rgba32 >> 8;
-    rgb24_to_css(buf, rgb24);
+    if (prefs_get_int_attribute("options.svgoutput", "usenamedcolors", 0)) {
+        rgb24_to_css(buf, rgb24);
+    } else {
+        g_snprintf(buf, buflen, "#%06x", rgb24);
+    }
 }
 
 static GHashTable *
@@ -475,7 +482,7 @@ bool sp_svg_read_icc_color( gchar const *str, gchar const **end_ptr, SVGICCColor
                 // Name must start with a certain type of character
                 good = false;
             } else {
-                while ( g_ascii_isdigit(*str) || g_ascii_islower(*str) || (*str == '-') ) {
+                while ( g_ascii_isdigit(*str) || g_ascii_isalpha(*str) || (*str == '-') ) {
                     if ( dest ) {
                         dest->colorProfile += *str;
                     }