Code

Translations. French translation minor update.
[inkscape.git] / src / color.cpp
index 8dc4c865762af724607a92ef5149ffabed55e004..54af89ae5d5c92665b458a5cf5666d11179a7d5b 100644 (file)
 #include <math.h>
 #include "color.h"
 #include "svg/svg-icc-color.h"
+#include "svg/svg-color.h"
+
+#include "svg/css-ostringstream.h"
+
+using Inkscape::CSSOStringStream;
+using std::vector;
 
 static bool profileMatches( SVGICCColor const* first, SVGICCColor const* second );
 
@@ -57,14 +63,15 @@ SPColor::~SPColor()
 
 SPColor& SPColor::operator= (SPColor const& other)
 {
-    SVGICCColor* tmp = other.icc ? new SVGICCColor(*other.icc) : 0;
+    SVGICCColor* tmp_icc = other.icc ? new SVGICCColor(*other.icc) : 0;
+
     v.c[0] = other.v.c[0];
     v.c[1] = other.v.c[1];
     v.c[2] = other.v.c[2];
     if ( icc ) {
         delete icc;
     }
-    icc = tmp;
+    icc = tmp_icc;
 
     return *this;
 }
@@ -96,8 +103,7 @@ bool SPColor::isClose( SPColor const& other, float epsilon ) const
         && (fabs((v.c[1]) - (other.v.c[1])) < epsilon)
         && (fabs((v.c[2]) - (other.v.c[2])) < epsilon);
 
-    // TODO uncomment once we start using that profile.  Will be RSN
-    //match &= profileMatches( icc, other.icc );
+    match &= profileMatches( icc, other.icc );
 
     return match;
 }
@@ -176,6 +182,33 @@ guint32 SPColor::toRGBA32( gdouble alpha ) const
     return toRGBA32( static_cast<gint>(SP_COLOR_F_TO_U(alpha)) );
 }
 
+std::string SPColor::toString() const
+{
+    CSSOStringStream css;
+
+    std::string result;
+    char tmp[64] = {0};
+
+    sp_svg_write_color(tmp, sizeof(tmp), toRGBA32(0x0ff));
+    css << tmp;
+
+    if ( icc ) {
+        if ( !css.str().empty() ) {
+            css << " ";
+        }
+        css << "icc-color(" << icc->colorProfile;
+        for (vector<double>::const_iterator i(icc->colors.begin()),
+                 iEnd(icc->colors.end());
+             i != iEnd; ++i) {
+            css << ", " << *i;
+        }
+        css << ')';
+    }
+
+    return css.str();
+}
+
+
 /**
  * Fill rgb float array with values from SPColor.
  * \pre color != NULL && rgb != NULL && rgb[0-2] is meaningful
@@ -419,4 +452,4 @@ sp_color_cmyk_to_rgb_floatv (float *rgb, float c, float m, float y, float k)
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :