Code

This commit hooks device-cmyk handling to color pickers. Now we have basic initial...
authorFelipe C. da S. Sanches <juca@members.fsf.org>
Mon, 7 Dec 2009 03:19:44 +0000 (01:19 -0200)
committerFelipe C. da S. Sanches <juca@members.fsf.org>
Mon, 7 Dec 2009 03:19:44 +0000 (01:19 -0200)
http://www.w3.org/TR/2009/WD-SVGColor12-20091001/#device

src/desktop-style.cpp
src/svg/svg-color.cpp
src/widgets/sp-color-scales.cpp

index c8782051bef6772088cef4d5b985488a00f16381..2afcd610958061c993ea5ee53304a946cadd41ba 100644 (file)
@@ -44,6 +44,7 @@
 
 #include "desktop-style.h"
 #include "svg/svg-icc-color.h"
+#include "svg/svg-device-color.h"
 #include "box3d-side.h"
 
 /**
@@ -432,6 +433,8 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill
     paint_res->set = TRUE;
 
     SVGICCColor* iccColor = 0;
+    SVGDeviceColor* devColor = 0;
+
     bool iccSeen = false;
     gfloat c[4];
     c[0] = c[1] = c[2] = c[3] = 0.0;
@@ -529,6 +532,23 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill
             c[1] += d[1];
             c[2] += d[2];
             c[3] += SP_SCALE24_TO_FLOAT (isfill? style->fill_opacity.value : style->stroke_opacity.value);
+
+            // average device color
+            unsigned int it;
+            if (i==objects /*if this is the first object in the GList*/
+                && paint->value.color.device){
+                devColor = new SVGDeviceColor(*paint->value.color.device);
+                for (it=0; it < paint->value.color.device->colors.size(); it++){
+                    devColor->colors[it] = 0;
+                }
+            }
+
+            if (devColor && paint->value.color.device && paint->value.color.device->type == devColor->type){
+                for (it=0; it < paint->value.color.device->colors.size(); it++){
+                    devColor->colors[it] += paint->value.color.device->colors[it];
+                }
+            }
+
             num ++;
         }
 
@@ -568,6 +588,14 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill
             paint_res->value.color.icc = tmp;
         }
 
+        // divide and store the device-color
+        if (devColor){
+            for (unsigned int it=0; it < devColor->colors.size(); it++){
+                devColor->colors[it] /= num;
+            }
+            paint_res->value.color.device = devColor;
+        }
+
         if (num > 1) {
             if (same_color)
                 return QUERY_STYLE_MULTIPLE_SAME;
index 0eaa4431a1e59a265e0eb258443a7bf2d1454fae..46779311e74ec741452acfadff9382521eb228ad 100644 (file)
@@ -559,7 +559,6 @@ bool sp_svg_read_icc_color( gchar const *str, gchar const **end_ptr, SVGICCColor
                     if ( !errno ) {
                         if ( dest ) {
                             dest->colors.push_back( dbl );
-g_message("color: %f", dbl);
                         }
                         str = endPtr;
                     } else {
@@ -662,7 +661,6 @@ bool sp_svg_read_device_color( gchar const *str, gchar const **end_ptr, SVGDevic
                     if ( !errno ) {
                         if ( dest ) {
                             dest->colors.push_back( dbl );
-g_message("color: %f", dbl);
                         }
                         str = endPtr;
                     } else {
index a09a3a2edc5a572b6448c5d3e0a597091c7dd6b9..e41b81e5c327f0724f5e165de7ce3653ee12c1e0 100644 (file)
@@ -11,6 +11,7 @@
 #include "../dialogs/dialog-events.h"
 #include "sp-color-scales.h"
 #include "svg/svg-icc-color.h"
+#include "svg/svg-device-color.h"
 
 #define CSC_CHANNEL_R (1 << 0)
 #define CSC_CHANNEL_G (1 << 1)
@@ -231,6 +232,12 @@ void ColorScales::_recalcColor( gboolean changing )
         case SP_COLOR_SCALES_MODE_CMYK:
         {
             _getCmykaFloatv( c );
+            color.device = new SVGDeviceColor();
+            color.device->type=DEVICE_CMYK;
+            color.device->colors.clear();
+            for (int i=0;i<4;i++){
+              color.device->colors.push_back(c[i]);
+            }
 
             float rgb[3];
             sp_color_cmyk_to_rgb_floatv( rgb, c[0], c[1], c[2], c[3] );
@@ -475,11 +482,20 @@ void ColorScales::setMode(SPColorScalesMode mode)
                gtk_widget_show (_s[4]);
                gtk_widget_show (_b[4]);
                _updating = TRUE;
-               sp_color_rgb_to_cmyk_floatv (c, rgba[0], rgba[1], rgba[2]);
-               setScaled( _a[0], c[0] );
-               setScaled( _a[1], c[1] );
-               setScaled( _a[2], c[2] );
-               setScaled( _a[3], c[3] );
+
+    if (_color.device && _color.device->type == DEVICE_CMYK){
+                 setScaled( _a[0], _color.device->colors[0] );
+                 setScaled( _a[1], _color.device->colors[1] );
+                 setScaled( _a[2], _color.device->colors[2] );
+                 setScaled( _a[3], _color.device->colors[3] );
+    } else {
+      //If we still dont have a device-color, convert from rbga
+                 sp_color_rgb_to_cmyk_floatv (c, rgba[0], rgba[1], rgba[2]);
+                 setScaled( _a[0], c[0] );
+                 setScaled( _a[1], c[1] );
+                 setScaled( _a[2], c[2] );
+                 setScaled( _a[3], c[3] );
+    }
                setScaled( _a[4], rgba[3] );
                _updating = FALSE;
                _updateSliders( CSC_CHANNELS_ALL );