Code

Fixes calligraphy tool so drawing now uses the the correct opacity.
[inkscape.git] / src / svg / svg-color.cpp
index 33b73f0d4c44ed9e51ab91dc1e3a285a3edcee5e..2bae38641b170413e9642e17afe16e96716d966a 100644 (file)
@@ -18,6 +18,7 @@
 #endif
 
 #include "svg-color.h"
+#include "svg-icc-color.h"
 #include <cassert>
 #include <math.h>
 #include <glib/gmem.h>
@@ -26,6 +27,7 @@
 #include <glib/ghash.h>
 #include <glib/gutils.h>
 #include <cstdio> // sprintf
+#include <errno.h>
 #include "strneq.h"
 using std::sprintf;
 
@@ -343,6 +345,10 @@ sp_svg_read_color(gchar const *str, gchar const **end_ptr, guint32 dfl)
         assert(check == ret
                && buf_end - buf == end - str);
         g_free(buf);
+
+        if ( end_ptr ) {
+            *end_ptr = end;
+        }
     }
     return ret;
 }
@@ -435,6 +441,99 @@ sp_svg_create_color_hash()
     return colors;
 }
 
+
+bool sp_svg_read_icc_color( gchar const *str, gchar const **end_ptr, SVGICCColor* dest )
+{
+    bool good = true;
+
+    if ( end_ptr ) {
+        *end_ptr = str;
+    }
+    if ( dest ) {
+        dest->colorProfile.clear();
+        dest->colors.clear();
+    }
+
+    if ( !str ) {
+        // invalid input
+        good = false;
+    } else {
+        while ( g_ascii_isspace(*str) ) {
+            str++;
+        }
+
+        good = strneq( str, "icc-color(", 10 );
+
+        if ( good ) {
+            str += 10;
+            while ( g_ascii_isspace(*str) ) {
+                str++;
+            }
+
+            if ( !g_ascii_isalpha(*str)
+                 && ( !(0x080 & *str) ) ) {
+                // Name must start with a certain type of character
+                good = false;
+            } else {
+                while ( g_ascii_isdigit(*str) || g_ascii_islower(*str) || (*str == '-') ) {
+                    if ( dest ) {
+                        dest->colorProfile += *str;
+                    }
+                    str++;
+                }
+                while ( g_ascii_isspace(*str) || *str == ',' ) {
+                    str++;
+                }
+            }
+        }
+
+        if ( good ) {
+            while ( *str && *str != ')' ) {
+                if ( g_ascii_isdigit(*str) || *str == '.' || *str == '-' || *str == '+') {
+                    gchar* endPtr = 0;
+                    gdouble dbl = g_ascii_strtod( str, &endPtr );
+                    if ( !errno ) {
+                        if ( dest ) {
+                            dest->colors.push_back( dbl );
+                        }
+                        str = endPtr;
+                    } else {
+                        good = false;
+                        break;
+                    }
+
+                    while ( g_ascii_isspace(*str) || *str == ',' ) {
+                        str++;
+                    }
+                } else {
+                    break;
+                }
+            }
+        }
+
+        // We need to have ended on a closing parenthesis
+        if ( good ) {
+            while ( g_ascii_isspace(*str) ) {
+                str++;
+            }
+            good &= *str == ')';
+        }
+    }
+
+    if ( good ) {
+        if ( end_ptr ) {
+            *end_ptr = str;
+        }
+    } else {
+        if ( dest ) {
+            dest->colorProfile.clear();
+            dest->colors.clear();
+        }
+    }
+
+    return good;
+}
+
 /*
   Local Variables:
   mode:c++