1 #define __SP_USE_C__
3 /*
4 * SVG <use> implementation
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * bulia byak <buliabyak@users.sf.net>
9 *
10 * Copyright (C) 1999-2005 authors
11 * Copyright (C) 2000-2001 Ximian, Inc.
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #ifdef HAVE_CONFIG_H
17 # include <config.h>
18 #endif
19 #include <libnr/nr-matrix-ops.h>
20 #include <libnr/nr-matrix-fns.h>
21 #include "libnr/nr-matrix-translate-ops.h"
22 #include <glibmm/i18n.h>
23 #include "display/nr-arena-group.h"
24 #include "attributes.h"
25 #include "document.h"
26 #include "sp-object-repr.h"
27 #include "sp-flowregion.h"
28 #include "uri.h"
29 #include "xml/repr.h"
30 #include "prefs-utils.h"
31 #include "style.h"
32 #include "sp-symbol.h"
33 #include "sp-use.h"
34 #include "sp-use-reference.h"
36 /* fixme: */
38 static void sp_use_class_init(SPUseClass *classname);
39 static void sp_use_init(SPUse *use);
40 static void sp_use_finalize(GObject *obj);
42 static void sp_use_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
43 static void sp_use_release(SPObject *object);
44 static void sp_use_set(SPObject *object, unsigned key, gchar const *value);
45 static Inkscape::XML::Node *sp_use_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
46 static void sp_use_update(SPObject *object, SPCtx *ctx, guint flags);
47 static void sp_use_modified(SPObject *object, guint flags);
49 static void sp_use_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
50 static void sp_use_print(SPItem *item, SPPrintContext *ctx);
51 static gchar *sp_use_description(SPItem *item);
52 static NRArenaItem *sp_use_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags);
53 static void sp_use_hide(SPItem *item, unsigned key);
55 static void sp_use_href_changed(SPObject *old_ref, SPObject *ref, SPUse *use);
57 static void sp_use_delete_self(SPObject *deleted, SPUse *self);
59 static SPItemClass *parent_class;
61 //void m_print(gchar *say, NR::Matrix m)
62 //{ g_print("%s %g %g %g %g %g %g\n", say, m[0], m[1], m[2], m[3], m[4], m[5]); }
64 GType
65 sp_use_get_type(void)
66 {
67 static GType use_type = 0;
68 if (!use_type) {
69 GTypeInfo use_info = {
70 sizeof(SPUseClass),
71 NULL, /* base_init */
72 NULL, /* base_finalize */
73 (GClassInitFunc) sp_use_class_init,
74 NULL, /* class_finalize */
75 NULL, /* class_data */
76 sizeof(SPUse),
77 16, /* n_preallocs */
78 (GInstanceInitFunc) sp_use_init,
79 NULL, /* value_table */
80 };
81 use_type = g_type_register_static(SP_TYPE_ITEM, "SPUse", &use_info, (GTypeFlags)0);
82 }
83 return use_type;
84 }
86 static void
87 sp_use_class_init(SPUseClass *classname)
88 {
89 GObjectClass *gobject_class = (GObjectClass *) classname;
90 SPObjectClass *sp_object_class = (SPObjectClass *) classname;
91 SPItemClass *item_class = (SPItemClass *) classname;
93 parent_class = (SPItemClass*) g_type_class_ref(SP_TYPE_ITEM);
95 gobject_class->finalize = sp_use_finalize;
97 sp_object_class->build = sp_use_build;
98 sp_object_class->release = sp_use_release;
99 sp_object_class->set = sp_use_set;
100 sp_object_class->write = sp_use_write;
101 sp_object_class->update = sp_use_update;
102 sp_object_class->modified = sp_use_modified;
104 item_class->bbox = sp_use_bbox;
105 item_class->description = sp_use_description;
106 item_class->print = sp_use_print;
107 item_class->show = sp_use_show;
108 item_class->hide = sp_use_hide;
109 }
111 static void
112 sp_use_init(SPUse *use)
113 {
114 use->x.unset();
115 use->y.unset();
116 use->width.unset(SVGLength::PERCENT, 1.0, 1.0);
117 use->height.unset(SVGLength::PERCENT, 1.0, 1.0);
118 use->href = NULL;
120 new (&use->_delete_connection) sigc::connection();
121 new (&use->_changed_connection) sigc::connection();
123 new (&use->_transformed_connection) sigc::connection();
125 use->ref = new SPUseReference(SP_OBJECT(use));
127 use->_changed_connection = use->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_use_href_changed), use));
128 }
130 static void
131 sp_use_finalize(GObject *obj)
132 {
133 SPUse *use = (SPUse *) obj;
135 delete use->ref;
137 use->_delete_connection.~connection();
138 use->_changed_connection.~connection();
140 use->_transformed_connection.~connection();
141 }
143 static void
144 sp_use_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
145 {
146 if (((SPObjectClass *) parent_class)->build) {
147 (* ((SPObjectClass *) parent_class)->build)(object, document, repr);
148 }
150 sp_object_read_attr(object, "x");
151 sp_object_read_attr(object, "y");
152 sp_object_read_attr(object, "width");
153 sp_object_read_attr(object, "height");
154 sp_object_read_attr(object, "xlink:href");
156 // We don't need to create child here:
157 // reading xlink:href will attach ref, and that will cause the changed signal to be emitted,
158 // which will call sp_use_href_changed, and that will take care of the child
159 }
161 static void
162 sp_use_release(SPObject *object)
163 {
164 SPUse *use = SP_USE(object);
166 use->child = NULL;
168 use->_delete_connection.disconnect();
169 use->_changed_connection.disconnect();
170 use->_transformed_connection.disconnect();
172 g_free(use->href);
173 use->href = NULL;
175 use->ref->detach();
177 if (((SPObjectClass *) parent_class)->release) {
178 ((SPObjectClass *) parent_class)->release(object);
179 }
180 }
182 static void
183 sp_use_set(SPObject *object, unsigned key, gchar const *value)
184 {
185 SPUse *use = SP_USE(object);
187 switch (key) {
188 case SP_ATTR_X:
189 use->x.readOrUnset(value);
190 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
191 break;
192 case SP_ATTR_Y:
193 use->y.readOrUnset(value);
194 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
195 break;
196 case SP_ATTR_WIDTH:
197 use->width.readOrUnset(value, SVGLength::PERCENT, 1.0, 1.0);
198 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
199 break;
200 case SP_ATTR_HEIGHT:
201 use->height.readOrUnset(value, SVGLength::PERCENT, 1.0, 1.0);
202 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
203 break;
205 case SP_ATTR_XLINK_HREF: {
206 if ( value && use->href && ( strcmp(value, use->href) == 0 ) ) {
207 /* No change, do nothing. */
208 } else {
209 g_free(use->href);
210 use->href = NULL;
211 if (value) {
212 // First, set the href field, because sp_use_href_changed will need it.
213 use->href = g_strdup(value);
215 // Now do the attaching, which emits the changed signal.
216 try {
217 use->ref->attach(Inkscape::URI(value));
218 } catch (Inkscape::BadURIException &e) {
219 g_warning("%s", e.what());
220 use->ref->detach();
221 }
222 } else {
223 use->ref->detach();
224 }
225 }
226 break;
227 }
229 default:
230 if (((SPObjectClass *) parent_class)->set) {
231 ((SPObjectClass *) parent_class)->set(object, key, value);
232 }
233 break;
234 }
235 }
237 static Inkscape::XML::Node *
238 sp_use_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
239 {
240 SPUse *use = SP_USE(object);
242 if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
243 repr = sp_repr_new("svg:use");
244 }
246 if (((SPObjectClass *) (parent_class))->write) {
247 ((SPObjectClass *) (parent_class))->write(object, repr, flags);
248 }
250 sp_repr_set_svg_double(repr, "x", use->x.computed);
251 sp_repr_set_svg_double(repr, "y", use->y.computed);
252 sp_repr_set_svg_double(repr, "width", use->width.computed);
253 sp_repr_set_svg_double(repr, "height", use->height.computed);
255 if (use->ref->getURI()) {
256 gchar *uri_string = use->ref->getURI()->toString();
257 repr->setAttribute("xlink:href", uri_string);
258 g_free(uri_string);
259 }
261 return repr;
262 }
264 static void
265 sp_use_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
266 {
267 SPUse const *use = SP_USE(item);
269 if (use->child && SP_IS_ITEM(use->child)) {
270 SPItem *child = SP_ITEM(use->child);
271 NR::Matrix const ct( child->transform
272 * NR::translate(use->x.computed,
273 use->y.computed)
274 * transform );
275 sp_item_invoke_bbox_full(child, bbox, ct, flags, FALSE);
276 }
277 }
279 static void
280 sp_use_print(SPItem *item, SPPrintContext *ctx)
281 {
282 SPUse *use = SP_USE(item);
284 if (use->child && SP_IS_ITEM(use->child)) {
285 sp_item_invoke_print(SP_ITEM(use->child), ctx);
286 }
287 }
289 static gchar *
290 sp_use_description(SPItem *item)
291 {
292 SPUse *use = SP_USE(item);
294 char *ret;
295 if (use->child) {
296 static unsigned recursion_depth = 0;
297 if (recursion_depth >= 4) {
298 /* TRANSLATORS: Used for statusbar description for long <use> chains:
299 * "Clone of: Clone of: ... in Layer 1". */
300 return g_strdup(_("..."));
301 /* We could do better, e.g. chasing the href chain until we reach something other than
302 * a <use>, and giving its description. */
303 }
304 ++recursion_depth;
305 char *child_desc = sp_item_description(SP_ITEM(use->child));
306 --recursion_depth;
308 ret = g_strdup_printf(_("<b>Clone</b> of: %s"), child_desc);
309 g_free(child_desc);
310 return ret;
311 } else {
312 return g_strdup(_("<b>Orphaned clone</b>"));
313 }
314 }
316 static NRArenaItem *
317 sp_use_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags)
318 {
319 SPUse *use = SP_USE(item);
321 NRArenaItem *ai = NRArenaGroup::create(arena);
322 nr_arena_group_set_transparent(NR_ARENA_GROUP(ai), FALSE);
324 if (use->child) {
325 NRArenaItem *ac = sp_item_invoke_show(SP_ITEM(use->child), arena, key, flags);
326 if (ac) {
327 nr_arena_item_add_child(ai, ac, NULL);
328 nr_arena_item_unref(ac);
329 }
330 NR::translate t(use->x.computed,
331 use->y.computed);
332 nr_arena_group_set_child_transform(NR_ARENA_GROUP(ai), NR::Matrix(t));
333 }
335 return ai;
336 }
338 static void
339 sp_use_hide(SPItem *item, unsigned key)
340 {
341 SPUse *use = SP_USE(item);
343 if (use->child) {
344 sp_item_invoke_hide(SP_ITEM(use->child), key);
345 }
347 if (((SPItemClass *) parent_class)->hide) {
348 ((SPItemClass *) parent_class)->hide(item, key);
349 }
350 }
352 /**
353 * Returns the ultimate original of a SPUse (i.e. the first object in the chain of its originals
354 * which is not an SPUse).
355 *
356 * Note that the returned is the clone object, i.e. the child of an SPUse (of the argument one for
357 * the trivial case) and not the "true original".
358 */
359 SPItem *
360 sp_use_root(SPUse *use)
361 {
362 SPObject *orig = use->child;
363 while (SP_IS_USE(orig)) {
364 orig = SP_USE(orig)->child;
365 }
366 g_assert(SP_IS_ITEM(orig));
367 return SP_ITEM(orig);
368 }
370 /**
371 * Returns the effective transform that goes from the ultimate original to given SPUse, both ends
372 * included.
373 */
374 NR::Matrix
375 sp_use_get_root_transform(SPUse *use)
376 {
377 //track the ultimate source of a chain of uses
378 SPObject *orig = use->child;
379 GSList *chain = NULL;
380 chain = g_slist_prepend(chain, use);
381 while (SP_IS_USE(orig)) {
382 chain = g_slist_prepend(chain, orig);
383 orig = SP_USE(orig)->child;
384 }
385 chain = g_slist_prepend(chain, orig);
388 //calculate the accummulated transform, starting from the original
389 NR::Matrix t(NR::identity());
390 for (GSList *i = chain; i != NULL; i = i->next) {
391 SPItem *i_tem = SP_ITEM(i->data);
393 // "An additional transformation translate(x,y) is appended to the end (i.e.,
394 // right-side) of the transform attribute on the generated 'g', where x and y
395 // represent the values of the x and y attributes on the 'use' element." - http://www.w3.org/TR/SVG11/struct.html#UseElement
396 if (SP_IS_USE(i_tem)) {
397 SPUse *i_use = SP_USE(i_tem);
398 if ((i_use->x._set && i_use->x.computed != 0) || (i_use->y._set && i_use->y.computed != 0)) {
399 t = t * NR::translate(i_use->x._set ? i_use->x.computed : 0, i_use->y._set ? i_use->y.computed : 0);
400 }
401 }
403 t *= i_tem->transform;
404 }
406 g_slist_free(chain);
407 return t;
408 }
410 /**
411 * Returns the transform that leads to the use from its immediate original.
412 * Does not inlcude the original's transform if any.
413 */
414 NR::Matrix
415 sp_use_get_parent_transform(SPUse *use)
416 {
417 NR::Matrix t(NR::identity());
418 if ((use->x._set && use->x.computed != 0) || (use->y._set && use->y.computed != 0)) {
419 t *= NR::translate(use->x._set ? use->x.computed : 0,
420 use->y._set ? use->y.computed : 0);
421 }
423 t *= SP_ITEM(use)->transform;
424 return t;
425 }
427 /**
428 * Sensing a movement of the original, this function attempts to compensate for it in such a way
429 * that the clone stays unmoved or moves in parallel (depending on user setting) regardless of the
430 * clone's transform.
431 */
432 static void
433 sp_use_move_compensate(NR::Matrix const *mp, SPItem *original, SPUse *self)
434 {
435 // the clone is orphaned; or this is not a real use, but a clone of another use;
436 // we skip it, otherwise duplicate compensation will occur
437 if (SP_OBJECT_IS_CLONED(self)) {
438 return;
439 }
441 // never compensate uses which are used in flowtext
442 if (SP_OBJECT_PARENT(self) && SP_IS_FLOWREGION(SP_OBJECT_PARENT(self))) {
443 return;
444 }
446 guint mode = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_PARALLEL);
447 // user wants no compensation
448 if (mode == SP_CLONE_COMPENSATION_NONE)
449 return;
451 NR::Matrix m(*mp);
453 // this is not a simple move, do not try to compensate
454 if (!(m.is_translation()))
455 return;
457 // restore item->transform field from the repr, in case it was changed by seltrans
458 sp_object_read_attr (SP_OBJECT (self), "transform");
460 NR::Matrix t = sp_use_get_parent_transform(self);
461 NR::Matrix clone_move = t.inverse() * m * t;
463 // calculate the compensation matrix and the advertized movement matrix
464 NR::Matrix advertized_move;
465 if (mode == SP_CLONE_COMPENSATION_PARALLEL) {
466 clone_move = clone_move.inverse() * m;
467 advertized_move = m;
468 } else if (mode == SP_CLONE_COMPENSATION_UNMOVED) {
469 clone_move = clone_move.inverse();
470 advertized_move.set_identity();
471 } else {
472 g_assert_not_reached();
473 }
475 // commit the compensation
476 SPItem *item = SP_ITEM(self);
477 item->transform *= clone_move;
478 sp_item_write_transform(item, SP_OBJECT_REPR(item), item->transform, &advertized_move);
479 SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
480 }
482 static void
483 sp_use_href_changed(SPObject *old_ref, SPObject *ref, SPUse *use)
484 {
485 SPItem *item = SP_ITEM(use);
487 use->_delete_connection.disconnect();
488 use->_transformed_connection.disconnect();
490 if (use->child) {
491 sp_object_detach(SP_OBJECT(use), use->child);
492 use->child = NULL;
493 }
495 if (use->href) {
496 SPItem *refobj = use->ref->getObject();
497 if (refobj) {
498 Inkscape::XML::Node *childrepr = SP_OBJECT_REPR(refobj);
499 GType type = sp_repr_type_lookup(childrepr);
500 g_return_if_fail(type > G_TYPE_NONE);
501 if (g_type_is_a(type, SP_TYPE_ITEM)) {
502 use->child = (SPObject*) g_object_new(type, 0);
503 sp_object_attach(SP_OBJECT(use), use->child, use->lastChild());
504 sp_object_unref(use->child, SP_OBJECT(use));
505 sp_object_invoke_build(use->child, SP_OBJECT(use)->document, childrepr, TRUE);
507 for (SPItemView *v = item->display; v != NULL; v = v->next) {
508 NRArenaItem *ai;
509 ai = sp_item_invoke_show(SP_ITEM(use->child), NR_ARENA_ITEM_ARENA(v->arenaitem), v->key, v->flags);
510 if (ai) {
511 nr_arena_item_add_child(v->arenaitem, ai, NULL);
512 nr_arena_item_unref(ai);
513 }
514 }
516 }
517 use->_delete_connection = SP_OBJECT(refobj)->connectDelete(sigc::bind(sigc::ptr_fun(&sp_use_delete_self), use));
518 use->_transformed_connection = SP_ITEM(refobj)->connectTransformed(sigc::bind(sigc::ptr_fun(&sp_use_move_compensate), use));
519 }
520 }
521 }
523 static void
524 sp_use_delete_self(SPObject *deleted, SPUse *self)
525 {
526 // always delete uses which are used in flowtext
527 if (SP_OBJECT_PARENT(self) && SP_IS_FLOWREGION(SP_OBJECT_PARENT(self))) {
528 SP_OBJECT(self)->deleteObject();
529 return;
530 }
532 guint const mode = prefs_get_int_attribute("options.cloneorphans", "value",
533 SP_CLONE_ORPHANS_UNLINK);
535 if (mode == SP_CLONE_ORPHANS_UNLINK) {
536 sp_use_unlink(self);
537 } else if (mode == SP_CLONE_ORPHANS_DELETE) {
538 SP_OBJECT(self)->deleteObject();
539 }
540 }
542 static void
543 sp_use_update(SPObject *object, SPCtx *ctx, unsigned flags)
544 {
545 SPItem *item = SP_ITEM(object);
546 SPUse *use = SP_USE(object);
547 SPItemCtx *ictx = (SPItemCtx *) ctx;
548 SPItemCtx cctx = *ictx;
550 if (((SPObjectClass *) (parent_class))->update)
551 ((SPObjectClass *) (parent_class))->update(object, ctx, flags);
553 if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
554 flags &= SP_OBJECT_MODIFIED_CASCADE;
556 /* Set up child viewport */
557 if (use->x.unit == SVGLength::PERCENT) {
558 use->x.computed = use->x.value * (ictx->vp.x1 - ictx->vp.x0);
559 }
560 if (use->y.unit == SVGLength::PERCENT) {
561 use->y.computed = use->y.value * (ictx->vp.y1 - ictx->vp.y0);
562 }
563 if (use->width.unit == SVGLength::PERCENT) {
564 use->width.computed = use->width.value * (ictx->vp.x1 - ictx->vp.x0);
565 }
566 if (use->height.unit == SVGLength::PERCENT) {
567 use->height.computed = use->height.value * (ictx->vp.y1 - ictx->vp.y0);
568 }
569 cctx.vp.x0 = 0.0;
570 cctx.vp.y0 = 0.0;
571 cctx.vp.x1 = use->width.computed;
572 cctx.vp.y1 = use->height.computed;
573 cctx.i2vp = NR::identity();
574 flags&=~SP_OBJECT_USER_MODIFIED_FLAG_B;
576 if (use->child) {
577 g_object_ref(G_OBJECT(use->child));
578 if (flags || (use->child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
579 if (SP_IS_ITEM(use->child)) {
580 SPItem const &chi = *SP_ITEM(use->child);
581 cctx.i2doc = chi.transform * ictx->i2doc;
582 cctx.i2vp = chi.transform * ictx->i2vp;
583 use->child->updateDisplay((SPCtx *)&cctx, flags);
584 } else {
585 use->child->updateDisplay(ctx, flags);
586 }
587 }
588 g_object_unref(G_OBJECT(use->child));
589 }
591 /* As last step set additional transform of arena group */
592 for (SPItemView *v = item->display; v != NULL; v = v->next) {
593 NRMatrix t;
594 nr_matrix_set_translate(&t, use->x.computed, use->y.computed);
595 nr_arena_group_set_child_transform(NR_ARENA_GROUP(v->arenaitem), &t);
596 }
597 }
599 static void
600 sp_use_modified(SPObject *object, guint flags)
601 {
602 SPUse *use_obj = SP_USE(object);
604 if (flags & SP_OBJECT_MODIFIED_FLAG) {
605 flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
606 }
607 flags &= SP_OBJECT_MODIFIED_CASCADE;
609 SPObject *child = use_obj->child;
610 if (child) {
611 g_object_ref(G_OBJECT(child));
612 if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
613 child->emitModified(flags);
614 }
615 g_object_unref(G_OBJECT(child));
616 }
617 }
619 SPItem *
620 sp_use_unlink(SPUse *use)
621 {
622 if (!use) return NULL;
624 Inkscape::XML::Node *repr = SP_OBJECT_REPR(use);
625 if (!repr) return NULL;
627 Inkscape::XML::Node *parent = sp_repr_parent(repr);
628 SPDocument *document = SP_OBJECT(use)->document;
630 // Track the ultimate source of a chain of uses.
631 SPItem *orig = sp_use_root(use);
633 // Calculate the accumulated transform, starting from the original.
634 NR::Matrix t = sp_use_get_root_transform(use);
636 Inkscape::XML::Node *copy = NULL;
637 if (SP_IS_SYMBOL(orig)) { // make a group, copy children
638 copy = sp_repr_new("svg:g");
639 for (Inkscape::XML::Node *child = SP_OBJECT_REPR(orig)->firstChild() ; child != NULL; child = child->next()) {
640 Inkscape::XML::Node *newchild = child->duplicate();
641 copy->appendChild(newchild);
642 }
643 } else { // just copy
644 copy = SP_OBJECT_REPR(orig)->duplicate();
645 }
647 // Add the duplicate repr just after the existing one.
648 parent->addChild(copy, repr);
650 // Retrieve the SPItem of the resulting repr.
651 SPObject *unlinked = document->getObjectByRepr(copy);
653 // Merge style from the use.
654 SPStyle *unli_sty = SP_OBJECT_STYLE(unlinked);
655 SPStyle const *use_sty = SP_OBJECT_STYLE(use);
656 sp_style_merge_from_dying_parent(unli_sty, use_sty);
657 sp_style_merge_from_parent(unli_sty, unlinked->parent->style);
659 SP_OBJECT(unlinked)->updateRepr();
661 // Hold onto our SPObject and repr for now.
662 sp_object_ref(SP_OBJECT(use), NULL);
663 Inkscape::GC::anchor(repr);
665 // Remove ourselves, not propagating delete events to avoid a
666 // chain-reaction with other elements that might reference us.
667 SP_OBJECT(use)->deleteObject(false);
669 // Give the copy our old id and let go of our old repr.
670 copy->setAttribute("id", repr->attribute("id"));
671 Inkscape::GC::release(repr);
673 // Remove tiled clone attrs.
674 copy->setAttribute("inkscape:tiled-clone-of", NULL);
675 copy->setAttribute("inkscape:tile-w", NULL);
676 copy->setAttribute("inkscape:tile-h", NULL);
677 copy->setAttribute("inkscape:tile-cx", NULL);
678 copy->setAttribute("inkscape:tile-cy", NULL);
680 // Establish the succession and let go of our object.
681 SP_OBJECT(use)->setSuccessor(unlinked);
682 sp_object_unref(SP_OBJECT(use), NULL);
684 SPItem *item = SP_ITEM(unlinked);
685 // Set the accummulated transform.
686 {
687 NR::Matrix nomove(NR::identity());
688 NRMatrix ctrans = t.operator const NRMatrix&();
689 // Advertise ourselves as not moving.
690 sp_item_write_transform(item, SP_OBJECT_REPR(item), &ctrans, &nomove);
691 }
692 return item;
693 }
695 SPItem *
696 sp_use_get_original(SPUse *use)
697 {
698 SPItem *ref = use->ref->getObject();
699 return ref;
700 }
703 /*
704 Local Variables:
705 mode:c++
706 c-file-style:"stroustrup"
707 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
708 indent-tabs-mode:nil
709 fill-column:99
710 End:
711 */
712 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :