Code

NR => Geom for (almost all of) event-context.h/.cpp
[inkscape.git] / src / sp-item.cpp
index b0b6d8137f4cb9ba9109b7168886c6c09bc7f4ad..0d285c3f0f3c970b5b80548d4734282bf21e6df6 100644 (file)
@@ -55,6 +55,8 @@
 #include "sp-filter-reference.h"
 #include "filter-chemistry.h"
 #include "sp-guide.h"
+#include "sp-title.h"
+#include "sp-desc.h"
 
 #include "libnr/nr-matrix-fns.h"
 #include "libnr/nr-matrix-scale-ops.h"
@@ -287,7 +289,7 @@ SPItem::setExplicitlyHidden(bool const val) {
  */
 void
 SPItem::setCenter(NR::Point object_centre) {
-    boost::optional<NR::Rect> bbox = getBounds(from_2geom(sp_item_i2d_affine(this)));
+    boost::optional<NR::Rect> bbox = getBounds(sp_item_i2d_affine(this));
     if (bbox) {
         transform_center_x = object_centre[NR::X] - bbox->midpoint()[NR::X];
         if (fabs(transform_center_x) < 1e-5) // rounding error
@@ -309,7 +311,7 @@ bool SPItem::isCenterSet() {
 }
 
 NR::Point SPItem::getCenter() const {
-    boost::optional<NR::Rect> bbox = getBounds(from_2geom(sp_item_i2d_affine(this)));
+    boost::optional<NR::Rect> bbox = getBounds(sp_item_i2d_affine(this));
     if (bbox) {
         return bbox->midpoint() + NR::Point (this->transform_center_x, this->transform_center_y);
     } else {
@@ -657,8 +659,32 @@ sp_item_update(SPObject *object, SPCtx *ctx, guint flags)
 static Inkscape::XML::Node *
 sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
 {
+    SPObject *child;
     SPItem *item = SP_ITEM(object);
 
+    // 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;
+        GSList *l;
+        l = NULL;
+        for (child = sp_object_first_child(object); child != NULL; child = SP_OBJECT_NEXT(child) ) {
+            if (!SP_IS_TITLE(child) && !SP_IS_DESC(child)) continue;
+            crepr = child->updateRepr(xml_doc, NULL, flags);
+            if (crepr) l = g_slist_prepend (l, crepr);
+        }
+        while (l) {
+            repr->addChild((Inkscape::XML::Node *) l->data, NULL);
+            Inkscape::GC::release((Inkscape::XML::Node *) l->data);
+            l = g_slist_remove (l, l->data);
+        }
+    } else {
+        for (child = sp_object_first_child(object) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
+            if (!SP_IS_TITLE(child) && !SP_IS_DESC(child)) continue;
+            child->updateRepr(flags);
+        }
+    }
+
     gchar *c = sp_svg_transform_write(item->transform);
     repr->setAttribute("transform", c);
     g_free(c);
@@ -702,22 +728,6 @@ boost::optional<NR::Rect> SPItem::getBounds(NR::Matrix const &transform,
     return r;
 }
 
-/*
- * If the item is empty, or has an empty boundingbox for another reason, this method will
- * return an empty rectangle. I.e. "getBounds(...).isEmpty() == true".
- */
-Geom::Rect
-SPItem::getBounds(Geom::Matrix const &transform, SPItem::BBoxType type, unsigned int /*dkey*/)
-const
-{
-    boost::optional<NR::Rect> r;
-    sp_item_invoke_bbox_full(this, &r, from_2geom(transform), type, TRUE);
-    if (r)
-        return to_2geom(*r);
-    else
-        return Geom::Rect(); // return empty rectangle
-}
-
 void
 sp_item_invoke_bbox(SPItem const *item, boost::optional<NR::Rect> *bbox, NR::Matrix const &transform, unsigned const clear, SPItem::BBoxType type)
 {
@@ -800,7 +810,7 @@ sp_item_invoke_bbox_full(SPItem const *item, boost::optional<NR::Rect> *bbox, NR
                 }
 
                 // transform the expansions by the item's transform:
-                NR::Matrix i2d = from_2geom(sp_item_i2d_affine (item));
+                NR::Matrix i2d(sp_item_i2d_affine (item));
                 dx0 *= NR::expansionX(i2d);
                 dx1 *= NR::expansionX(i2d);
                 dy0 *= NR::expansionY(i2d);
@@ -910,19 +920,19 @@ sp_item_bbox_desktop(SPItem *item, NRRect *bbox, SPItem::BBoxType type)
     g_assert(SP_IS_ITEM(item));
     g_assert(bbox != NULL);
 
-    sp_item_invoke_bbox(item, bbox, from_2geom(sp_item_i2d_affine(item)), TRUE, type);
+    sp_item_invoke_bbox(item, bbox, sp_item_i2d_affine(item), TRUE, type);
 }
 
 boost::optional<NR::Rect> sp_item_bbox_desktop(SPItem *item, SPItem::BBoxType type)
 {
     boost::optional<NR::Rect> rect = boost::optional<NR::Rect>();
-    sp_item_invoke_bbox(item, &rect, from_2geom(sp_item_i2d_affine(item)), TRUE, type);
+    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)
 {
-    boost::optional<NR::Rect> bbox = item->getBounds(from_2geom(sp_item_i2d_affine(item)));
+    boost::optional<NR::Rect> bbox = item->getBounds(sp_item_i2d_affine(item));
     /* Just the corners of the bounding box suffices given that we don't yet
        support angled guide lines. */
 
@@ -971,7 +981,7 @@ void sp_item_snappoints(SPItem const *item, bool includeItemCenter, SnapPointsIt
                        for (std::vector<NR::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) * from_2geom(matrix_to_desktop (matrix_from_desktop (to_2geom(item->transform), item), item));
+                               *p = (*p_orig) * from_2geom(matrix_to_desktop (matrix_from_desktop (item->transform, item), item));
                    }
                    }
                }
@@ -1351,7 +1361,7 @@ sp_item_adjust_livepatheffect (SPItem *item, NR::Matrix const &postmul, bool set
         
                 if (lpeobj->lpe) {
                     Inkscape::LivePathEffect::Effect * effect = lpeobj->lpe;
-                    effect->transform_multiply(to_2geom(postmul), set);
+                    effect->transform_multiply(postmul, set);
                 }
             }
         }
@@ -1508,9 +1518,9 @@ i2anc_affine(SPObject const *object, SPObject const *const ancestor) {
     /* stop at first non-renderable ancestor */
     while ( object != ancestor && SP_IS_ITEM(object) ) {
         if (SP_IS_ROOT(object)) {
-            ret *= to_2geom(SP_ROOT(object)->c2p);
+            ret *= SP_ROOT(object)->c2p;
         }
-        ret *= to_2geom(SP_ITEM(object)->transform);
+        ret *= SP_ITEM(object)->transform;
         object = SP_OBJECT_PARENT(object);
     }
     return ret;
@@ -1524,7 +1534,7 @@ i2i_affine(SPObject const *src, SPObject const *dest) {
 }
 
 NR::Matrix SPItem::getRelativeTransform(SPObject const *dest) const {
-    return from_2geom(i2i_affine(this, dest));
+    return i2i_affine(this, dest);
 }
 
 /**
@@ -1549,12 +1559,12 @@ Geom::Matrix sp_item_i2root_affine(SPItem const *item)
     Geom::Matrix ret(Geom::identity());
     g_assert(ret.isIdentity());
     while ( NULL != SP_OBJECT_PARENT(item) ) {
-        ret *= to_2geom(item->transform);
+        ret *= item->transform;
         item = SP_ITEM(SP_OBJECT_PARENT(item));
     }
     g_assert(SP_IS_ROOT(item));
 
-    ret *= to_2geom(item->transform);
+    ret *= item->transform;
 
     return ret;
 }
@@ -1622,7 +1632,7 @@ void sp_item_set_i2d_affine(SPItem *item, Geom::Matrix const &i2dt)
     }
 
     Geom::Matrix const i2p( i2dt * dt2p );
-    sp_item_set_item_transform(item, from_2geom(i2p));
+    sp_item_set_item_transform(item, i2p);
 }