Code

Avoid crash by uninitialized perspectives.
[inkscape.git] / src / desktop-style.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;