diff --git a/src/sp-clippath.cpp b/src/sp-clippath.cpp
index 35e0738791e825f0d29895f236ef6de43999760a..4bbabc965fbaf3360018461fe9bec96615e81192 100644 (file)
--- a/src/sp-clippath.cpp
+++ b/src/sp-clippath.cpp
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-
+#include <cstring>
+#include <string>
#include "display/nr-arena.h"
#include "display/nr-arena-group.h"
#include "document-private.h"
#include "sp-item.h"
+#include "libnr/nr-matrix-ops.h"
+#include <2geom/transforms.h>
+
#include "sp-clippath.h"
struct SPClipPathView {
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);
@@ -162,13 +166,12 @@ sp_clippath_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::
if (SP_IS_ITEM(ochild)) {
SPClipPath *cp = SP_CLIPPATH(object);
for (SPClipPathView *v = cp->display; v != NULL; v = v->next) {
- NRArenaItem *ac = sp_item_invoke_show(SP_ITEM(ochild),
- NR_ARENA_ITEM_ARENA(v->arenaitem),
- v->key,
+ NRArenaItem *ac = sp_item_invoke_show(SP_ITEM(ochild),
+ NR_ARENA_ITEM_ARENA(v->arenaitem),
+ v->key,
SP_ITEM_REFERENCE_FLAGS);
if (ac) {
nr_arena_item_add_child(v->arenaitem, ac, NULL);
- nr_arena_item_unref(ac);
}
}
}
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);
}
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) {
- repr = sp_repr_new("svg:clipPath");
+ 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;
}
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);
}
}
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*/)
{
- for (SPObject *o = sp_object_first_child(SP_OBJECT(cp)); o != NULL; o = SP_OBJECT_NEXT(o)) {
- if (SP_IS_ITEM(o)) {
- SPItem *child = SP_ITEM(o);
- sp_item_invoke_bbox_full(child, bbox, transform, flags, FALSE);
- }
- }
+ SPObject *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, 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, 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)){};
+ }
}
/* ClipPath views */
// 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));
- Inkscape::XML::Node *repr = sp_repr_new ("svg:clipPath");
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document);
+ Inkscape::XML::Node *repr = xml_doc->createElement("svg:clipPath");
repr->setAttribute("clipPathUnits", "userSpaceOnUse");
-
+
defsrepr->appendChild(repr);
const gchar *id = repr->attribute("id");
SPObject *clip_path_object = document->getObjectById(id);
-
+
for (GSList *it = reprs; it != NULL; it = it->next) {
Inkscape::XML::Node *node = (Inkscape::XML::Node *)(it->data);
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);
}
}
-
+
Inkscape::GC::release(repr);
return id;
}