Code

Fix Bug #675309 - crash when unlinking an orphaned clone
[inkscape.git] / src / sp-use.cpp
index 12066f925636db48eaead4199ea447b98012f742..ecb7eb788b137c69537c43312d9950e96ce06518 100644 (file)
@@ -32,7 +32,7 @@
 #include "uri.h"
 #include "print.h"
 #include "xml/repr.h"
-#include "prefs-utils.h"
+#include "preferences.h"
 #include "style.h"
 #include "sp-symbol.h"
 #include "sp-use.h"
@@ -52,7 +52,7 @@ static void sp_use_update(SPObject *object, SPCtx *ctx, guint flags);
 static void sp_use_modified(SPObject *object, guint flags);
 
 static void sp_use_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags);
-static void sp_use_snappoints(SPItem const *item, SnapPointsIter p);
+static void sp_use_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
 static void sp_use_print(SPItem *item, SPPrintContext *ctx);
 static gchar *sp_use_description(SPItem *item);
 static NRArenaItem *sp_use_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags);
@@ -64,7 +64,7 @@ static void sp_use_delete_self(SPObject *deleted, SPUse *self);
 
 static SPItemClass *parent_class;
 
-//void m_print(gchar *say, NR::Matrix m)
+//void m_print(gchar *say, Geom::Matrix m)
 //{ g_print("%s %g %g %g %g %g %g\n", say, m[0], m[1], m[2], m[3], m[4], m[5]); }
 
 GType
@@ -288,7 +288,14 @@ sp_use_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, uns
                              * Geom::Translate(use->x.computed,
                                                use->y.computed)
                              * transform );
-        sp_item_invoke_bbox_full(child, bbox, ct, flags, FALSE);
+        Geom::OptRect optbbox;
+        sp_item_invoke_bbox_full(child, optbbox, ct, flags, FALSE);
+        if (optbbox) {
+            bbox->x0 = (*optbbox)[0][0];
+            bbox->y0 = (*optbbox)[1][0];
+            bbox->x1 = (*optbbox)[0][1];
+            bbox->y1 = (*optbbox)[1][1];
+        }
     }
 }
 
@@ -299,7 +306,7 @@ sp_use_print(SPItem *item, SPPrintContext *ctx)
     SPUse *use = SP_USE(item);
 
     if ((use->x._set && use->x.computed != 0) || (use->y._set && use->y.computed != 0)) {
-        NR::Matrix tp(Geom::Translate(use->x.computed, use->y.computed));
+        Geom::Matrix tp(Geom::Translate(use->x.computed, use->y.computed));
         sp_print_bind(ctx, tp, 1.0);
         translated = true;
     }
@@ -356,7 +363,7 @@ sp_use_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags)
         }
         Geom::Translate t(use->x.computed,
                         use->y.computed);
-        nr_arena_group_set_child_transform(NR_ARENA_GROUP(ai), NR::Matrix(t));
+        nr_arena_group_set_child_transform(NR_ARENA_GROUP(ai), Geom::Matrix(t));
     }
 
     return ai;
@@ -388,10 +395,11 @@ SPItem *
 sp_use_root(SPUse *use)
 {
     SPObject *orig = use->child;
-    while (SP_IS_USE(orig)) {
+    while (orig && SP_IS_USE(orig)) {
         orig = SP_USE(orig)->child;
     }
-    g_return_val_if_fail(SP_IS_ITEM(orig), NULL);
+    if (!orig || !SP_IS_ITEM(orig))
+        return NULL;
     return SP_ITEM(orig);
 }
 
@@ -399,7 +407,7 @@ sp_use_root(SPUse *use)
  * Returns the effective transform that goes from the ultimate original to given SPUse, both ends
  * included.
  */
-NR::Matrix
+Geom::Matrix
 sp_use_get_root_transform(SPUse *use)
 {
     //track the ultimate source of a chain of uses
@@ -414,7 +422,7 @@ sp_use_get_root_transform(SPUse *use)
 
 
     //calculate the accummulated transform, starting from the original
-    NR::Matrix t(NR::identity());
+    Geom::Matrix t(Geom::identity());
     for (GSList *i = chain; i != NULL; i = i->next) {
         SPItem *i_tem = SP_ITEM(i->data);
 
@@ -439,7 +447,7 @@ sp_use_get_root_transform(SPUse *use)
  * Returns the transform that leads to the use from its immediate original.
  * Does not inlcude the original's transform if any.
  */
-NR::Matrix
+Geom::Matrix
 sp_use_get_parent_transform(SPUse *use)
 {
     Geom::Matrix t(Geom::identity());
@@ -471,7 +479,8 @@ sp_use_move_compensate(Geom::Matrix const *mp, SPItem */*original*/, SPUse *self
         return;
     }
 
-    guint mode = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_PARALLEL);
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    guint mode = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_PARALLEL);
     // user wants no compensation
     if (mode == SP_CLONE_COMPENSATION_NONE)
         return;
@@ -556,7 +565,8 @@ sp_use_delete_self(SPObject */*deleted*/, SPUse *self)
         return;
     }
 
-    guint const mode = prefs_get_int_attribute("options.cloneorphans", "value",
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    guint const mode = prefs->getInt("/options/cloneorphans/value",
                                                SP_CLONE_ORPHANS_UNLINK);
 
     if (mode == SP_CLONE_ORPHANS_UNLINK) {
@@ -603,7 +613,7 @@ sp_use_update(SPObject *object, SPCtx *ctx, unsigned flags)
     cctx.vp.y0 = 0.0;
     cctx.vp.x1 = use->width.computed;
     cctx.vp.y1 = use->height.computed;
-    cctx.i2vp = NR::identity();
+    cctx.i2vp = Geom::identity();
     flags&=~SP_OBJECT_USER_MODIFIED_FLAG_B;
 
     if (use->child) {
@@ -623,7 +633,7 @@ sp_use_update(SPObject *object, SPCtx *ctx, unsigned flags)
 
     /* As last step set additional transform of arena group */
     for (SPItemView *v = item->display; v != NULL; v = v->next) {
-        NR::Matrix t(Geom::Translate(use->x.computed, use->y.computed));
+        Geom::Matrix t(Geom::Translate(use->x.computed, use->y.computed));
         nr_arena_group_set_child_transform(NR_ARENA_GROUP(v->arenaitem), t);
     }
 }
@@ -668,7 +678,7 @@ sp_use_unlink(SPUse *use)
 
     // Track the ultimate source of a chain of uses.
     SPItem *orig = sp_use_root(use);
-    g_return_val_if_fail(orig, NULL);
+    if (!orig) return NULL ;
 
     // Calculate the accumulated transform, starting from the original.
     Geom::Matrix t = sp_use_get_root_transform(use);
@@ -739,19 +749,20 @@ sp_use_get_original(SPUse *use)
 }
 
 static void
-sp_use_snappoints(SPItem const *item, SnapPointsIter p)
+sp_use_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs)
 {
     g_assert (item != NULL);
     g_assert (SP_IS_ITEM(item));
     g_assert (SP_IS_USE(item));
-    
+
     SPUse *use = SP_USE(item);
     SPItem *root = sp_use_root(use);
-    g_return_if_fail(root);
-    
+    if (!root)
+        return;
+
     SPItemClass const &item_class = *(SPItemClass const *) G_OBJECT_GET_CLASS(root);
     if (item_class.snappoints) {
-        item_class.snappoints(root, p);
+        item_class.snappoints(root, p, snapprefs);
     }
 }