Code

Use cursor-tweak-move.xpm for all object modes and cursor-color.xpm
[inkscape.git] / src / sp-item.cpp
index c993a6163a9ca6ba44e744f0d0a5fa6323f8e3ac..662dc1cac7370d3007ac135aace282407e0905d5 100644 (file)
@@ -1,5 +1,3 @@
-#define __SP_ITEM_C__
-
 /** \file
  * Base class for visual SVG elements
  */
@@ -35,6 +33,7 @@
 #include "document.h"
 #include "uri.h"
 #include "inkscape.h"
+#include "desktop.h"
 #include "desktop-handles.h"
 
 #include "style.h"
@@ -48,8 +47,9 @@
 #include "sp-item-rm-unsatisfied-cns.h"
 #include "sp-pattern.h"
 #include "sp-switch.h"
+#include "sp-guide-constraint.h"
 #include "gradient-chemistry.h"
-#include "prefs-utils.h"
+#include "preferences.h"
 #include "conn-avoid-ref.h"
 #include "conditions.h"
 #include "sp-filter-reference.h"
@@ -90,7 +90,7 @@ static void sp_item_update(SPObject *object, SPCtx *ctx, guint flags);
 static Inkscape::XML::Node *sp_item_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
 
 static gchar *sp_item_private_description(SPItem *item);
-static void sp_item_private_snappoints(SPItem const *item, SnapPointsIter p);
+static void sp_item_private_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs);
 
 static SPItemView *sp_item_view_new_prepend(SPItemView *list, SPItem *item, unsigned flags, unsigned key, NRArenaItem *arenaitem);
 static SPItemView *sp_item_view_list_remove(SPItemView *list, SPItemView *view);
@@ -166,17 +166,19 @@ void SPItem::init() {
     this->display = NULL;
 
     this->clip_ref = new SPClipPathReference(this);
-               sigc::signal<void, SPObject *, SPObject *> cs1=this->clip_ref->changedSignal();
-               sigc::slot2<void,SPObject*, SPObject *> sl1=sigc::bind(sigc::ptr_fun(clip_ref_changed), this);
+    sigc::signal<void, SPObject *, SPObject *> cs1=this->clip_ref->changedSignal();
+    sigc::slot2<void,SPObject*, SPObject *> sl1=sigc::bind(sigc::ptr_fun(clip_ref_changed), this);
     _clip_ref_connection = cs1.connect(sl1);
 
     this->mask_ref = new SPMaskReference(this);
-               sigc::signal<void, SPObject *, SPObject *> cs2=this->mask_ref->changedSignal();
-               sigc::slot2<void,SPObject*, SPObject *> sl2=sigc::bind(sigc::ptr_fun(mask_ref_changed), this);
+    sigc::signal<void, SPObject *, SPObject *> cs2=this->mask_ref->changedSignal();
+    sigc::slot2<void,SPObject*, SPObject *> sl2=sigc::bind(sigc::ptr_fun(mask_ref_changed), this);
     _mask_ref_connection = cs2.connect(sl2);
 
     this->avoidRef = new SPAvoidRef(this);
 
+    new (&this->constraints) std::vector<SPGuideConstraint>();
+
     new (&this->_transformed_signal) sigc::signal<void, Geom::Matrix const *, SPItem *>();
 }
 
@@ -271,7 +273,7 @@ bool
 SPItem::isExplicitlyHidden() const
 {
     return (this->style->display.set
-           && this->style->display.value == SP_CSS_DISPLAY_NONE);
+            && this->style->display.value == SP_CSS_DISPLAY_NONE);
 }
 
 /**
@@ -291,7 +293,10 @@ SPItem::setExplicitlyHidden(bool const val) {
  */
 void
 SPItem::setCenter(Geom::Point object_centre) {
-    boost::optional<Geom::Rect> bbox = getBounds(sp_item_i2d_affine(this));
+    // for getBounds() to work
+    sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(this));
+
+    Geom::OptRect bbox = getBounds(sp_item_i2d_affine(this));
     if (bbox) {
         transform_center_x = object_centre[Geom::X] - bbox->midpoint()[Geom::X];
         if (fabs(transform_center_x) < 1e-5) // rounding error
@@ -313,7 +318,10 @@ bool SPItem::isCenterSet() {
 }
 
 Geom::Point SPItem::getCenter() const {
-    boost::optional<Geom::Rect> bbox = getBounds(sp_item_i2d_affine(this));
+    // for getBounds() to work
+    sp_document_ensure_up_to_date(SP_OBJECT_DOCUMENT(this));
+
+    Geom::OptRect bbox = getBounds(sp_item_i2d_affine(this));
     if (bbox) {
         return to_2geom(bbox->midpoint()) + Geom::Point (this->transform_center_x, this->transform_center_y);
     } else {
@@ -642,14 +650,13 @@ sp_item_update(SPObject *object, SPCtx *ctx, guint flags)
 
     /* Update bounding box data used by filters */
     if (item->style->filter.set && item->display) {
-        NRRect item_bbox;
-        sp_item_invoke_bbox(item, &item_bbox, Geom::identity(), TRUE, SPItem::GEOMETRIC_BBOX);
-        boost::optional<Geom::Rect> i_bbox = item_bbox;
+        Geom::OptRect item_bbox;
+        sp_item_invoke_bbox(item, item_bbox, Geom::identity(), TRUE, SPItem::GEOMETRIC_BBOX);
 
         SPItemView *itemview = item->display;
         do {
             if (itemview->arenaitem)
-                nr_arena_item_set_item_bbox(itemview->arenaitem, i_bbox);
+                nr_arena_item_set_item_bbox(itemview->arenaitem, item_bbox);
         } while ( (itemview = itemview->next) );
     }
 
@@ -664,7 +671,7 @@ sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape
     SPObject *child;
     SPItem *item = SP_ITEM(object);
 
-    // in the case of SP_OBJECT_WRITE_BUILD, the item should always be newly created, 
+    // in the case of SP_OBJECT_WRITE_BUILD, the item should always be newly created,
     // so we need to add any children from the underlying object to the new repr
     if (flags & SP_OBJECT_WRITE_BUILD) {
         Inkscape::XML::Node *crepr;
@@ -721,22 +728,26 @@ sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape
     return repr;
 }
 
-boost::optional<Geom::Rect> SPItem::getBounds(Geom::Matrix const &transform,
+/**
+ * \return  There is no guarantee that the return value will contain a rectangle.
+            If this item does not have a boundingbox, it might well be empty.
+ */
+Geom::OptRect SPItem::getBounds(Geom::Matrix const &transform,
                                       SPItem::BBoxType type,
                                       unsigned int /*dkey*/) const
 {
-    boost::optional<Geom::Rect> r;
+    Geom::OptRect r;
     sp_item_invoke_bbox_full(this, r, transform, type, TRUE);
     return r;
 }
 
 void
-sp_item_invoke_bbox(SPItem const *item, boost::optional<Geom::Rect> &bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
+sp_item_invoke_bbox(SPItem const *item, Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
 {
     sp_item_invoke_bbox_full(item, bbox, transform, type, clear);
 }
 
-// DEPRECATED to phase out the use of NRRect in favor of boost::optional<Geom::Rect>
+// DEPRECATED to phase out the use of NRRect in favor of Geom::OptRect
 void
 sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
 {
@@ -746,15 +757,18 @@ sp_item_invoke_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transf
 /** Calls \a item's subclass' bounding box method; clips it by the bbox of clippath, if any; and
  * unions the resulting bbox with \a bbox. If \a clear is true, empties \a bbox first. Passes the
  * transform and the flags to the actual bbox methods. Note that many of subclasses (e.g. groups,
- * clones), in turn, call this function in their bbox methods. */
+ * clones), in turn, call this function in their bbox methods.
+ * \retval bbox  Note that there is no guarantee that bbox will contain a rectangle when the
+ *               function returns. If this item does not have a boundingbox, this might well be empty.
+ */
 void
-sp_item_invoke_bbox_full(SPItem const *item, boost::optional<Geom::Rect> &bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear)
+sp_item_invoke_bbox_full(SPItem const *item, Geom::OptRect &bbox, Geom::Matrix const &transform, unsigned const flags, unsigned const clear)
 {
     g_assert(item != NULL);
     g_assert(SP_IS_ITEM(item));
 
     if (clear) {
-        bbox = boost::optional<Geom::Rect>();
+        bbox = Geom::OptRect();
     }
 
     // TODO: replace NRRect by Geom::Rect, for all SPItemClasses, and for SP_CLIPPATH
@@ -786,7 +800,7 @@ sp_item_invoke_bbox_full(SPItem const *item, boost::optional<Geom::Rect> &bbox,
                     y = SP_FILTER(filter)->y.computed;
                 if (SP_FILTER(filter)->width._set)
                     w = SP_FILTER(filter)->width.computed;
-                if (SP_FILTER(filter)->height._set) 
+                if (SP_FILTER(filter)->height._set)
                     h = SP_FILTER(filter)->height.computed;
 
                 double dx0 = 0;
@@ -794,7 +808,7 @@ sp_item_invoke_bbox_full(SPItem const *item, boost::optional<Geom::Rect> &bbox,
                 double dy0 = 0;
                 double dy1 = 0;
                 if (filter_is_single_gaussian_blur(SP_FILTER(filter))) {
-                    // if this is a single blur, use 2.4*radius 
+                    // if this is a single blur, use 2.4*radius
                     // which may be smaller than the default area;
                     // see set_filter_area for why it's 2.4
                     double r = get_single_gaussian_blur_radius (SP_FILTER(filter));
@@ -832,25 +846,25 @@ sp_item_invoke_bbox_full(SPItem const *item, boost::optional<Geom::Rect> &bbox,
     }
 
     if (temp_bbox.x0 > temp_bbox.x1 || temp_bbox.y0 > temp_bbox.y1) {
-        // Either the bbox hasn't been touched by the SPItemClass' bbox method 
+        // Either the bbox hasn't been touched by the SPItemClass' bbox method
         // (it still has its initial values, see above: x0 = y0 = NR_HUGE and x1 = y1 = -NR_HUGE)
         // or it has explicitely been set to be like this (e.g. in sp_shape_bbox)
-        
-        // When x0 > x1 or y0 > y1, the bbox is considered to be "nothing", although it has not been 
-        // explicitely defined this way for NRRects (as opposed to boost::optional<Geom::Rect>)
+
+        // When x0 > x1 or y0 > y1, the bbox is considered to be "nothing", although it has not been
+        // explicitely defined this way for NRRects (as opposed to Geom::OptRect)
         // So union bbox with nothing = do nothing, just return
         return;
     }
 
-    // Do not use temp_bbox.upgrade() here, because it uses a test that returns an empty boost::optional<Geom::Rect>()
+    // Do not use temp_bbox.upgrade() here, because it uses a test that returns an empty Geom::OptRect()
     // for any rectangle with zero area. The geometrical bbox of for example a vertical line
-    // would therefore be translated into empty boost::optional<Geom::Rect>() (see bug https://bugs.launchpad.net/inkscape/+bug/168684)
-    boost::optional<Geom::Rect> temp_bbox_new = Geom::Rect(Geom::Point(temp_bbox.x0, temp_bbox.y0), Geom::Point(temp_bbox.x1, temp_bbox.y1));
+    // would therefore be translated into empty Geom::OptRect() (see bug https://bugs.launchpad.net/inkscape/+bug/168684)
+    Geom::OptRect temp_bbox_new = Geom::Rect(Geom::Point(temp_bbox.x0, temp_bbox.y0), Geom::Point(temp_bbox.x1, temp_bbox.y1));
 
     bbox = Geom::unify(bbox, temp_bbox_new);
 }
 
-// DEPRECATED to phase out the use of NRRect in favor of boost::optional<Geom::Rect>
+// DEPRECATED to phase out the use of NRRect in favor of Geom::OptRect
 /** Calls \a item's subclass' bounding box method; clips it by the bbox of clippath, if any; and
  * unions the resulting bbox with \a bbox. If \a clear is true, empties \a bbox first. Passes the
  * transform and the flags to the actual bbox methods. Note that many of subclasses (e.g. groups,
@@ -924,73 +938,76 @@ sp_item_bbox_desktop(SPItem *item, NRRect *bbox, SPItem::BBoxType type)
     sp_item_invoke_bbox(item, bbox, sp_item_i2d_affine(item), TRUE, type);
 }
 
-boost::optional<Geom::Rect> sp_item_bbox_desktop(SPItem *item, SPItem::BBoxType type)
+Geom::OptRect sp_item_bbox_desktop(SPItem *item, SPItem::BBoxType type)
 {
-    boost::optional<Geom::Rect> rect = boost::optional<Geom::Rect>();
+    Geom::OptRect rect = Geom::OptRect();
     sp_item_invoke_bbox(item, rect, sp_item_i2d_affine(item), TRUE, type);
     return rect;
 }
 
-static void sp_item_private_snappoints(SPItem const *item, SnapPointsIter p)
+static void sp_item_private_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const */*snapprefs*/)
 {
-       /* This will only be called if the derived class doesn't override this.
-        * see for example sp_genericellipse_snappoints in sp-ellipse.cpp        
-        * We don't know what shape we could be dealing with here, so we'll just
-        * return the corners of the bounding box */
+    /* This will only be called if the derived class doesn't override this.
+     * see for example sp_genericellipse_snappoints in sp-ellipse.cpp
+     * We don't know what shape we could be dealing with here, so we'll just
+     * return the corners of the bounding box */
+
+    Geom::OptRect bbox = item->getBounds(sp_item_i2d_affine(item));
 
-       boost::optional<Geom::Rect> bbox = item->getBounds(sp_item_i2d_affine(item));
-    
     if (bbox) {
         Geom::Point p1, p2;
         p1 = bbox->min();
         p2 = bbox->max();
-        *p = p1;
-        *p = Geom::Point(p1[Geom::X], p2[Geom::Y]);
-        *p = p2;
-        *p = Geom::Point(p1[Geom::Y], p2[Geom::X]);
+        int type = target ? int(Inkscape::SNAPSOURCE_CONVEX_HULL_CORNER) : int(Inkscape::SNAPSOURCE_CONVEX_HULL_CORNER);
+        p.push_back(std::make_pair(p1, type));
+        p.push_back(std::make_pair(Geom::Point(p1[Geom::X], p2[Geom::Y]), type));
+        p.push_back(std::make_pair(p2, type));
+        p.push_back(std::make_pair(Geom::Point(p1[Geom::Y], p2[Geom::X]), type));
     }
-      
+
 }
 
-void sp_item_snappoints(SPItem const *item, bool includeItemCenter, SnapPointsIter p)
+void sp_item_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs)
 {
-       g_assert (item != NULL);
+    g_assert (item != NULL);
     g_assert (SP_IS_ITEM(item));
 
     // Get the snappoints of the item
     SPItemClass const &item_class = *(SPItemClass const *) G_OBJECT_GET_CLASS(item);
     if (item_class.snappoints) {
-        item_class.snappoints(item, p);
+        item_class.snappoints(item, target, p, snapprefs);
     }
 
     // Get the snappoints at the item's center
-    if (includeItemCenter) {
-       *p = item->getCenter();
-    }    
-    
+    if (snapprefs != NULL && snapprefs->getIncludeItemCenter()) {
+       p.push_back(std::make_pair(item->getCenter(), target ? int(Inkscape::SNAPTARGET_ROTATION_CENTER) : int(Inkscape::SNAPSOURCE_ROTATION_CENTER)));
+    }
+
     // Get the snappoints of clipping paths and mask, if any
     std::list<SPObject const *> clips_and_masks;
-    
+
     clips_and_masks.push_back(SP_OBJECT(item->clip_ref->getObject()));
     clips_and_masks.push_back(SP_OBJECT(item->mask_ref->getObject()));
-    
+
+    SPDesktop *desktop = inkscape_active_desktop();
     for (std::list<SPObject const *>::const_iterator o = clips_and_masks.begin(); o != clips_and_masks.end(); o++) {
-       if (*o) {
-               // obj is a group object, the children are the actual clippers
-               for (SPObject *child = (*o)->children ; child ; child = child->next) {
-                   if (SP_IS_ITEM(child)) {
-                       std::vector<Geom::Point> p_clip_or_mask;                            
-                       // Please note the recursive call here!
-                       sp_item_snappoints(SP_ITEM(child), includeItemCenter, SnapPointsIter(p_clip_or_mask));
-                       // Take into account the transformation of the item being clipped or masked
-                       for (std::vector<Geom::Point>::const_iterator p_orig = p_clip_or_mask.begin(); p_orig != p_clip_or_mask.end(); p_orig++) {
-                       // All snappoints are in desktop coordinates, but the item's transformation is
-                               // in document coordinates. Hence the awkward construction below
-                               *p = (*p_orig) * matrix_to_desktop (matrix_from_desktop (item->transform, item), item);
-                   }
-                   }
-               }
-       }
+        if (*o) {
+            // obj is a group object, the children are the actual clippers
+            for (SPObject *child = (*o)->children ; child ; child = child->next) {
+                if (SP_IS_ITEM(child)) {
+                       SnapPointsWithType p_clip_or_mask;
+                    // Please note the recursive call here!
+                    sp_item_snappoints(SP_ITEM(child), target, p_clip_or_mask, snapprefs);
+                    // Take into account the transformation of the item being clipped or masked
+                    for (SnapPointsWithType::const_iterator p_orig = p_clip_or_mask.begin(); p_orig != p_clip_or_mask.end(); p_orig++) {
+                        // All snappoints are in desktop coordinates, but the item's transformation is
+                        // in document coordinates. Hence the awkward construction below
+                        Geom::Point pt = desktop->dt2doc((*p_orig).first) * sp_item_i2d_affine(item);
+                        p.push_back(std::make_pair(pt, (*p_orig).second));
+                    }
+                }
+            }
+        }
     }
 }
 
@@ -1041,8 +1058,14 @@ sp_item_description(SPItem *item)
             g_free (s);
             s = snew;
         }
-        if (SP_OBJECT_STYLE(item) && SP_OBJECT_STYLE(item)->filter.href) {
-            gchar *snew = g_strdup_printf (_("%s; <i>filtered</i>"), s);
+        if (SP_OBJECT_STYLE(item) && SP_OBJECT_STYLE(item)->filter.href && SP_OBJECT_STYLE(item)->filter.href->getObject()) {
+            const gchar *label = SP_OBJECT_STYLE(item)->filter.href->getObject()->label();
+            gchar *snew;
+            if (label) {
+                snew = g_strdup_printf (_("%s; <i>filtered (%s)</i>"), s, label);
+            } else {
+                snew = g_strdup_printf (_("%s; <i>filtered</i>"), s);
+            }
             g_free (s);
             s = snew;
         }
@@ -1127,10 +1150,9 @@ sp_item_invoke_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags)
             SP_OBJECT(mask)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
         }
         NR_ARENA_ITEM_SET_DATA(ai, item);
-        NRRect item_bbox;
-        sp_item_invoke_bbox(item, &item_bbox, Geom::identity(), TRUE, SPItem::GEOMETRIC_BBOX);
-        boost::optional<Geom::Rect> i_bbox = item_bbox;
-        nr_arena_item_set_item_bbox(ai, i_bbox);
+        Geom::OptRect item_bbox;
+        sp_item_invoke_bbox(item, item_bbox, Geom::identity(), TRUE, SPItem::GEOMETRIC_BBOX);
+        nr_arena_item_set_item_bbox(ai, item_bbox);
     }
 
     return ai;
@@ -1363,7 +1385,7 @@ sp_item_adjust_livepatheffect (SPItem *item, Geom::Matrix const &postmul, bool s
                 if (new_lpeobj != lpeobj) {
                     sp_lpe_item_replace_path_effect(lpeitem, lpeobj, new_lpeobj);
                 }
-        
+
                 if (lpeobj->get_lpe()) {
                     Inkscape::LivePathEffect::Effect * effect = lpeobj->get_lpe();
                     effect->transform_multiply(postmul, set);
@@ -1373,19 +1395,6 @@ sp_item_adjust_livepatheffect (SPItem *item, Geom::Matrix const &postmul, bool s
     }
 }
 
-/**
- * A temporary wrapper for the next function accepting the Geom::Matrix
- * instead of Geom::Matrix
- */
-void
-sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, Geom::Matrix const *transform, Geom::Matrix const *adv)
-{
-    if (transform == NULL)
-        sp_item_write_transform(item, repr, Geom::identity(), adv);
-    else
-        sp_item_write_transform(item, repr, *transform, adv);
-}
-
 /**
  * Set a new transform on an object.
  *
@@ -1409,26 +1418,27 @@ sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, Geom::Matrix co
         advertized_transform = sp_item_transform_repr (item).inverse() * transform;
     }
 
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
     if (compensate) {
 
          // recursively compensate for stroke scaling, depending on user preference
-        if (prefs_get_int_attribute("options.transform", "stroke", 1) == 0) {
+        if (!prefs->getBool("/options/transform/stroke", true)) {
             double const expansion = 1. / advertized_transform.descrim();
             sp_item_adjust_stroke_width_recursive(item, expansion);
         }
 
         // recursively compensate rx/ry of a rect if requested
-        if (prefs_get_int_attribute("options.transform", "rectcorners", 1) == 0) {
+        if (!prefs->getBool("/options/transform/rectcorners", true)) {
             sp_item_adjust_rects_recursive(item, advertized_transform);
         }
 
         // recursively compensate pattern fill if it's not to be transformed
-        if (prefs_get_int_attribute("options.transform", "pattern", 1) == 0) {
+        if (!prefs->getBool("/options/transform/pattern", true)) {
             sp_item_adjust_paint_recursive (item, advertized_transform.inverse(), Geom::identity(), true);
         }
         /// \todo FIXME: add the same else branch as for gradients below, to convert patterns to userSpaceOnUse as well
         /// recursively compensate gradient fill if it's not to be transformed
-        if (prefs_get_int_attribute("options.transform", "gradient", 1) == 0) {
+        if (!prefs->getBool("/options/transform/gradient", true)) {
             sp_item_adjust_paint_recursive (item, advertized_transform.inverse(), Geom::identity(), false);
         } else {
             // this converts the gradient/pattern fill/stroke, if any, to userSpaceOnUse; we need to do
@@ -1438,7 +1448,7 @@ sp_item_write_transform(SPItem *item, Inkscape::XML::Node *repr, Geom::Matrix co
 
     } // endif(compensate)
 
-    gint preserve = prefs_get_int_attribute("options.preservetransform", "value", 0);
+    gint preserve = prefs->getBool("/options/preservetransform/value", 0);
     Geom::Matrix transform_attr (transform);
     if ( // run the object's set_transform (i.e. embed transform) only if:
          ((SPItemClass *) G_OBJECT_GET_CLASS(item))->set_transform && // it does have a set_transform method
@@ -1524,8 +1534,9 @@ i2anc_affine(SPObject const *object, SPObject const *const ancestor) {
     while ( object != ancestor && SP_IS_ITEM(object) ) {
         if (SP_IS_ROOT(object)) {
             ret *= SP_ROOT(object)->c2p;
+        } else {
+            ret *= SP_ITEM(object)->transform;
         }
-        ret *= SP_ITEM(object)->transform;
         object = SP_OBJECT_PARENT(object);
     }
     return ret;
@@ -1552,30 +1563,8 @@ Geom::Matrix sp_item_i2doc_affine(SPItem const *item)
 }
 
 /**
- * Returns the accumulated transformation of the item and all its ancestors, but excluding root's viewport.
- * Used in path operations mostly.
- * \pre (item != NULL) and SP_IS_ITEM(item).
+ * Returns the transformation from item to desktop coords
  */
-Geom::Matrix sp_item_i2root_affine(SPItem const *item)
-{
-    g_assert(item != NULL);
-    g_assert(SP_IS_ITEM(item));
-
-    Geom::Matrix ret(Geom::identity());
-    g_assert(ret.isIdentity());
-    while ( NULL != SP_OBJECT_PARENT(item) ) {
-        ret *= item->transform;
-        item = SP_ITEM(SP_OBJECT_PARENT(item));
-    }
-    g_assert(SP_IS_ROOT(item));
-
-    ret *= item->transform;
-
-    return ret;
-}
-
-/* fixme: This is EVIL!!! */
-// fix this note: why/what evil? :)
 Geom::Matrix sp_item_i2d_affine(SPItem const *item)
 {
     g_assert(item != NULL);
@@ -1587,42 +1576,6 @@ Geom::Matrix sp_item_i2d_affine(SPItem const *item)
     return ret;
 }
 
-// same as i2d but with i2root instead of i2doc
-Geom::Matrix sp_item_i2r_affine(SPItem const *item)
-{
-    g_assert(item != NULL);
-    g_assert(SP_IS_ITEM(item));
-
-    Geom::Matrix const ret( sp_item_i2root_affine(item)
-                          * Geom::Scale(1, -1)
-                          * Geom::Translate(0, sp_document_height(SP_OBJECT_DOCUMENT(item))) );
-    return ret;
-}
-
-/**
- * Converts a matrix \a m into the desktop coords of the \a item.
- * Will become a noop when we eliminate the coordinate flipping.
- */
-Geom::Matrix matrix_to_desktop(Geom::Matrix const m, SPItem const *item)
-{
-    Geom::Matrix const ret(m
-                         * Geom::Translate(0, -sp_document_height(SP_OBJECT_DOCUMENT(item)))
-                         * Geom::Scale(1, -1));
-    return ret;
-}
-
-/**
- * Converts a matrix \a m from the desktop coords of the \a item.
- * Will become a noop when we eliminate the coordinate flipping.
- */
-Geom::Matrix matrix_from_desktop(Geom::Matrix const m, SPItem const *item)
-{
-    Geom::Matrix const ret(Geom::Scale(1, -1)
-                         * Geom::Translate(0, sp_document_height(SP_OBJECT_DOCUMENT(item)))
-                         * m);
-    return ret;
-}
-
 void sp_item_set_i2d_affine(SPItem *item, Geom::Matrix const &i2dt)
 {
     g_return_if_fail( item != NULL );
@@ -1641,6 +1594,9 @@ void sp_item_set_i2d_affine(SPItem *item, Geom::Matrix const &i2dt)
 }
 
 
+/**
+ * should rather be named "sp_item_d2i_affine" to match "sp_item_i2d_affine" (or vice versa)
+ */
 Geom::Matrix
 sp_item_dt2i_affine(SPItem const *item)
 {
@@ -1727,11 +1683,12 @@ sp_item_convert_to_guides(SPItem *item) {
     SPNamedView *nv = sp_desktop_namedview(dt);
     (void)nv;
 
-    int prefs_bbox = prefs_get_int_attribute("tools", "bounding_box", 0);
-    SPItem::BBoxType bbox_type = (prefs_bbox ==0)? 
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    int prefs_bbox = prefs->getInt("/tools/bounding_box", 0);
+    SPItem::BBoxType bbox_type = (prefs_bbox ==0)?
         SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
 
-    boost::optional<Geom::Rect> bbox = sp_item_bbox_desktop(item, bbox_type);
+    Geom::OptRect bbox = sp_item_bbox_desktop(item, bbox_type);
     if (!bbox) {
         g_warning ("Cannot determine item's bounding box during conversion to guides.\n");
         return;