Code

Connector tool: make connectors avoid the convex hull of shapes.
[inkscape.git] / src / sp-clippath.cpp
index 881605a13c3dfc7cdc16fd4cddc9135ad7f2fa03..4bbabc965fbaf3360018461fe9bec96615e81192 100644 (file)
@@ -26,6 +26,7 @@
 #include "sp-item.h"
 
 #include "libnr/nr-matrix-ops.h"
+#include <2geom/transforms.h>
 
 #include "sp-clippath.h"
 
@@ -45,7 +46,7 @@ static void sp_clippath_set(SPObject *object, unsigned int key, gchar const *val
 static void sp_clippath_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
 static void sp_clippath_update(SPObject *object, SPCtx *ctx, guint flags);
 static void sp_clippath_modified(SPObject *object, guint flags);
-static Inkscape::XML::Node *sp_clippath_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
+static Inkscape::XML::Node *sp_clippath_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
 
 SPClipPathView *sp_clippath_view_new_prepend(SPClipPathView *list, unsigned int key, NRArenaItem *arenaitem);
 SPClipPathView *sp_clippath_view_list_remove(SPClipPathView *list, SPClipPathView *view);
@@ -171,7 +172,6 @@ sp_clippath_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::
                                                   SP_ITEM_REFERENCE_FLAGS);
             if (ac) {
                 nr_arena_item_add_child(v->arenaitem, ac, NULL);
-                nr_arena_item_unref(ac);
             }
         }
     }
@@ -205,10 +205,9 @@ sp_clippath_update(SPObject *object, SPCtx *ctx, guint flags)
     SPClipPath *cp = SP_CLIPPATH(object);
     for (SPClipPathView *v = cp->display; v != NULL; v = v->next) {
         if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) {
-            NRMatrix t;
-            nr_matrix_set_scale(&t, v->bbox.x1 - v->bbox.x0, v->bbox.y1 - v->bbox.y0);
-            t.c[4] = v->bbox.x0;
-            t.c[5] = v->bbox.y0;
+            Geom::Matrix t(Geom::Scale(v->bbox.x1 - v->bbox.x0, v->bbox.y1 - v->bbox.y0));
+            t[4] = v->bbox.x0;
+            t[5] = v->bbox.y0;
             nr_arena_group_set_child_transform(NR_ARENA_GROUP(v->arenaitem), &t);
         } else {
             nr_arena_group_set_child_transform(NR_ARENA_GROUP(v->arenaitem), NULL);
@@ -243,15 +242,14 @@ sp_clippath_modified(SPObject *object, guint flags)
 }
 
 static Inkscape::XML::Node *
-sp_clippath_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
+sp_clippath_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
 {
     if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
-        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
         repr = xml_doc->createElement("svg:clipPath");
     }
 
     if (((SPObjectClass *) (parent_class))->write)
-        ((SPObjectClass *) (parent_class))->write(object, repr, flags);
+        ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags);
 
     return repr;
 }
@@ -273,16 +271,14 @@ sp_clippath_show(SPClipPath *cp, NRArena *arena, unsigned int key)
             if (ac) {
                 /* The order is not important in clippath */
                 nr_arena_item_add_child(ai, ac, NULL);
-                nr_arena_item_unref(ac);
             }
         }
     }
 
     if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) {
-        NRMatrix t;
-        nr_matrix_set_scale(&t, cp->display->bbox.x1 - cp->display->bbox.x0, cp->display->bbox.y1 - cp->display->bbox.y0);
-        t.c[4] = cp->display->bbox.x0;
-        t.c[5] = cp->display->bbox.y0;
+        Geom::Matrix t(Geom::Scale(cp->display->bbox.x1 - cp->display->bbox.x0, cp->display->bbox.y1 - cp->display->bbox.y0));
+        t[4] = cp->display->bbox.x0;
+        t[5] = cp->display->bbox.y0;
         nr_arena_group_set_child_transform(NR_ARENA_GROUP(ai), &t);
     }
 
@@ -329,23 +325,23 @@ sp_clippath_set_bbox(SPClipPath *cp, unsigned int key, NRRect *bbox)
 }
 
 void
-sp_clippath_get_bbox(SPClipPath *cp, NRRect *bbox, NR::Matrix const &transform, unsigned const /*flags*/)
+sp_clippath_get_bbox(SPClipPath *cp, NRRect *bbox, Geom::Matrix const &transform, unsigned const /*flags*/)
 {
     SPObject *i;
-    for (i = sp_object_first_child(SP_OBJECT(cp)); i && !SP_IS_ITEM(i); i = SP_OBJECT_NEXT(i));
+    for (i = sp_object_first_child(SP_OBJECT(cp)); i && !SP_IS_ITEM(i); i = SP_OBJECT_NEXT(i)){};
     if (!i) return;
 
-    sp_item_invoke_bbox_full(SP_ITEM(i), bbox, NR::Matrix(SP_ITEM(i)->transform) * transform, SPItem::GEOMETRIC_BBOX, FALSE);
+    sp_item_invoke_bbox_full(SP_ITEM(i), bbox, Geom::Matrix(SP_ITEM(i)->transform) * transform, SPItem::GEOMETRIC_BBOX, FALSE);
     SPObject *i_start = i;
 
     while (i != NULL) {
         if (i != i_start) {
             NRRect i_box;
-            sp_item_invoke_bbox_full(SP_ITEM(i), &i_box, NR::Matrix(SP_ITEM(i)->transform) * transform, SPItem::GEOMETRIC_BBOX, FALSE);
+            sp_item_invoke_bbox_full(SP_ITEM(i), &i_box, Geom::Matrix(SP_ITEM(i)->transform) * transform, SPItem::GEOMETRIC_BBOX, FALSE);
             nr_rect_d_union (bbox, bbox, &i_box);
         }
         i = SP_OBJECT_NEXT(i);
-        for (; i && !SP_IS_ITEM(i); i = SP_OBJECT_NEXT(i));
+        for (; i && !SP_IS_ITEM(i); i = SP_OBJECT_NEXT(i)){};
     }
 }
 
@@ -385,7 +381,7 @@ sp_clippath_view_list_remove(SPClipPathView *list, SPClipPathView *view)
 
 // Create a mask element (using passed elements), add it to <defs>
 const gchar *
-sp_clippath_create (GSList *reprs, SPDocument *document, NR::Matrix const* applyTransform)
+sp_clippath_create (GSList *reprs, SPDocument *document, Geom::Matrix const* applyTransform)
 {
     Inkscape::XML::Node *defsrepr = SP_OBJECT_REPR (SP_DOCUMENT_DEFS (document));
 
@@ -402,7 +398,7 @@ sp_clippath_create (GSList *reprs, SPDocument *document, NR::Matrix const* apply
         SPItem *item = SP_ITEM(clip_path_object->appendChildRepr(node));
 
         if (NULL != applyTransform) {
-            NR::Matrix transform (item->transform);
+            Geom::Matrix transform (item->transform);
             transform *= (*applyTransform);
             sp_item_write_transform(item, SP_OBJECT_REPR(item), transform);
         }