Code

remove many unnecessary to_2geom and from_2geom calls
[inkscape.git] / src / gradient-chemistry.cpp
index 057877daf61ee76272b084c79443f22fb84d63b8..afbf1600944cbaef69ff4e1ab7461e8a9d860cfd 100644 (file)
@@ -75,7 +75,7 @@ sp_gradient_ensure_vector_normalized(SPGradient *gr)
     /* If gr hrefs some other gradient, remove the href */
     if (gr->ref->getObject()) {
         /* We are hrefing someone, so require flattening */
-        SP_OBJECT(gr)->updateRepr(((SPObject *) gr)->repr, SP_OBJECT_WRITE_EXT | SP_OBJECT_WRITE_ALL);
+        SP_OBJECT(gr)->updateRepr(SP_OBJECT_WRITE_EXT | SP_OBJECT_WRITE_ALL);
         sp_gradient_repr_set_link(SP_OBJECT_REPR(gr), NULL);
     }
 
@@ -281,7 +281,7 @@ sp_gradient_reset_to_userspace (SPGradient *gr, SPItem *item)
 
     // calculate the bbox of the item
     sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
-    NR::Maybe<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
+    boost::optional<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
 
     if ( !bbox || bbox->isEmpty() )
         return gr;
@@ -342,7 +342,7 @@ sp_gradient_convert_to_userspace(SPGradient *gr, SPItem *item, gchar const *prop
         // calculate the bbox of the item
         sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
         NR::Matrix bbox2user;
-        NR::Maybe<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
+        boost::optional<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
         if ( bbox && !bbox->isEmpty() ) {
             bbox2user = NR::Matrix(bbox->dimensions()[NR::X], 0,
                                    0, bbox->dimensions()[NR::Y],
@@ -555,6 +555,12 @@ SPStop*
 sp_get_stop_i(SPGradient *gradient, guint stop_i)
 {            
     SPStop *stop = sp_first_stop (gradient);
+
+    // if this is valid but weird gradient without an offset-zero stop element,  
+    // inkscape has created a handle for the start of gradient anyway,
+    // so when it asks for stop N that corresponds to stop element N-1
+    if (stop->offset != 0)
+        stop_i --;
   
     for (guint i=0; i < stop_i; i++) {
         if (!stop) return NULL;  
@@ -818,7 +824,7 @@ sp_item_gradient_set_coords (SPItem *item, guint point_type, guint point_i, NR::
 
     gradient = sp_gradient_convert_to_userspace (gradient, item, fill_or_stroke? "fill" : "stroke");
 
-    NR::Matrix i2d = sp_item_i2d_affine (item);
+    NR::Matrix i2d (sp_item_i2d_affine (item));
     NR::Point p = p_w * i2d.inverse();
     p *= (gradient->gradientTransform).inverse();
     // now p is in gradient's original coordinates
@@ -1088,14 +1094,14 @@ sp_item_gradient_get_coords (SPItem *item, guint point_type, guint point_i, bool
 
     if (SP_GRADIENT(gradient)->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
         sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(item));
-        NR::Maybe<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
+        boost::optional<NR::Rect> bbox = item->getBounds(NR::identity()); // we need "true" bbox without item_i2d_affine
         if (bbox) {
             p *= NR::Matrix(bbox->dimensions()[NR::X], 0,
                             0, bbox->dimensions()[NR::Y],
                             bbox->min()[NR::X], bbox->min()[NR::Y]);
         }
     }
-    p *= NR::Matrix(gradient->gradientTransform) * sp_item_i2d_affine(item);
+    p *= NR::Matrix(gradient->gradientTransform) * (NR::Matrix)sp_item_i2d_affine(item);
     return p;
 }