Code

Avoid crash by uninitialized perspectives.
[inkscape.git] / src / sp-image.cpp
index be4d37909f292e2e028833c3a05b184a633f06a9..daf5e9e88577c98ac51fd2677973a6fb6c78ed39 100644 (file)
@@ -15,6 +15,9 @@
 # include "config.h"
 #endif
 
+// This has to be included prior to anything that includes setjmp.h, it croaks otherwise
+#include <png.h>
+
 #include <cstring>
 #include <string>
 #include <libnr/nr-matrix-fns.h>
 #include <glibmm/i18n.h>
 #include "xml/quote.h"
 #include <xml/repr.h>
-
+#include "snap-candidate.h"
 #include "libnr/nr-matrix-fns.h"
 
 #include "io/sys.h"
-#include <png.h>
 #if ENABLE_LCMS
 #include "color-profile-fns.h"
 #include "color-profile.h"
 //#define DEBUG_LCMS
 #ifdef DEBUG_LCMS
+
+
+#define DEBUG_MESSAGE(key, ...)\
+{\
+    g_message( __VA_ARGS__ );\
+}
+
 #include "preferences.h"
 #include <gtk/gtkmessagedialog.h>
 #endif // DEBUG_LCMS
@@ -71,12 +80,13 @@ static void sp_image_build (SPObject * object, SPDocument * document, Inkscape::
 static void sp_image_release (SPObject * object);
 static void sp_image_set (SPObject *object, unsigned int key, const gchar *value);
 static void sp_image_update (SPObject *object, SPCtx *ctx, unsigned int flags);
+static void sp_image_modified (SPObject *object, unsigned int flags);
 static Inkscape::XML::Node *sp_image_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
 
 static void sp_image_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags);
 static void sp_image_print (SPItem * item, SPPrintContext *ctx);
 static gchar * sp_image_description (SPItem * item);
-static void sp_image_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPreferences const *snapprefs);
+static void sp_image_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
 static NRArenaItem *sp_image_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
 static Geom::Matrix sp_image_set_transform (SPItem *item, Geom::Matrix const &xform);
 static void sp_image_set_curve(SPImage *image);
@@ -102,7 +112,7 @@ extern "C"
 
 #ifdef DEBUG_LCMS
 extern guint update_in_progress;
-#define DEBUG_MESSAGE(key, ...) \
+#define DEBUG_MESSAGE_SCISLAC(key, ...) \
 {\
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();\
     bool dump = prefs->getBool("/options/scislac/" #key);\
@@ -582,6 +592,7 @@ sp_image_class_init (SPImageClass * klass)
     sp_object_class->release = sp_image_release;
     sp_object_class->set = sp_image_set;
     sp_object_class->update = sp_image_update;
+    sp_object_class->modified = sp_image_modified;
     sp_object_class->write = sp_image_write;
 
     item_class->bbox = sp_image_bbox;
@@ -1007,6 +1018,22 @@ sp_image_update (SPObject *object, SPCtx *ctx, unsigned int flags)
     sp_image_update_canvas_image ((SPImage *) object);
 }
 
+static void
+sp_image_modified (SPObject *object, unsigned int flags)
+{
+    SPImage *image = SP_IMAGE (object);
+
+    if (((SPObjectClass *) (parent_class))->modified) {
+      (* ((SPObjectClass *) (parent_class))->modified) (object, flags);
+    }
+
+    if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) {
+        for (SPItemView *v = SP_ITEM (image)->display; v != NULL; v = v->next) {
+            nr_arena_image_set_style (NR_ARENA_IMAGE (v->arenaitem), object->style);
+        }
+    }
+}
+
 static Inkscape::XML::Node *
 sp_image_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
 {
@@ -1305,7 +1332,7 @@ sp_image_update_canvas_image (SPImage *image)
     }
 }
 
-static void sp_image_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::SnapPreferences const */*snapprefs*/)
+static void sp_image_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const */*snapprefs*/)
 {
     /* An image doesn't have any nodes to snap, but still we want to be able snap one image
     to another. Therefore we will create some snappoints at the corner, similar to a rect. If
@@ -1326,11 +1353,11 @@ static void sp_image_snappoints(SPItem const *item, SnapPointsIter p, Inkscape::
         double const y0 = image.y.computed;
         double const x1 = x0 + image.width.computed;
         double const y1 = y0 + image.height.computed;
-        NR::Matrix const i2d (sp_item_i2d_affine (item));
-        *p = NR::Point(x0, y0) * i2d;
-        *p = NR::Point(x0, y1) * i2d;
-        *p = NR::Point(x1, y1) * i2d;
-        *p = NR::Point(x1, y0) * i2d;
+        Geom::Matrix const i2d (sp_item_i2d_affine (item));
+        p.push_back(Inkscape::SnapCandidatePoint(Geom::Point(x0, y0) * i2d, Inkscape::SNAPSOURCE_CORNER, Inkscape::SNAPTARGET_CORNER));
+        p.push_back(Inkscape::SnapCandidatePoint(Geom::Point(x0, y1) * i2d, Inkscape::SNAPSOURCE_CORNER, Inkscape::SNAPTARGET_CORNER));
+        p.push_back(Inkscape::SnapCandidatePoint(Geom::Point(x1, y1) * i2d, Inkscape::SNAPSOURCE_CORNER, Inkscape::SNAPTARGET_CORNER));
+        p.push_back(Inkscape::SnapCandidatePoint(Geom::Point(x1, y0) * i2d, Inkscape::SNAPSOURCE_CORNER, Inkscape::SNAPTARGET_CORNER));
     }
 }
 
@@ -1352,14 +1379,14 @@ sp_image_set_transform(SPItem *item, Geom::Matrix const &xform)
     Geom::Matrix ret(Geom::Matrix(xform).without_translation());
     Geom::Point const scale(hypot(ret[0], ret[1]),
                             hypot(ret[2], ret[3]));
-    if ( scale[NR::X] > MAGIC_EPSILON ) {
+    if ( scale[Geom::X] > MAGIC_EPSILON ) {
         ret[0] /= scale[Geom::X];
         ret[1] /= scale[Geom::X];
     } else {
         ret[0] = 1.0;
         ret[1] = 0.0;
     }
-    if ( scale[NR::Y] > MAGIC_EPSILON ) {
+    if ( scale[Geom::Y] > MAGIC_EPSILON ) {
         ret[2] /= scale[Geom::Y];
         ret[3] /= scale[Geom::Y];
     } else {
@@ -1524,7 +1551,7 @@ sp_image_set_curve(SPImage *image)
         }
     } else {
         NRRect rect;
-        sp_image_bbox(image, &rect, NR::identity(), 0);
+        sp_image_bbox(image, &rect, Geom::identity(), 0);
         Geom::Rect rect2 = to_2geom(*rect.upgrade());
         SPCurve *c = SPCurve::new_from_rect(rect2);