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 "print.h"
30 #include "xml/repr.h"
31 #include "prefs-utils.h"
32 #include "style.h"
33 #include "sp-symbol.h"
34 #include "sp-use.h"
35 #include "sp-use-reference.h"
37 /* fixme: */
39 static void sp_use_class_init(SPUseClass *classname);
40 static void sp_use_init(SPUse *use);
41 static void sp_use_finalize(GObject *obj);
43 static void sp_use_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
44 static void sp_use_release(SPObject *object);
45 static void sp_use_set(SPObject *object, unsigned key, gchar const *value);
46 static Inkscape::XML::Node *sp_use_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
47 static void sp_use_update(SPObject *object, SPCtx *ctx, guint flags);
48 static void sp_use_modified(SPObject *object, guint flags);
50 static void sp_use_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
51 static void sp_use_print(SPItem *item, SPPrintContext *ctx);
52 static gchar *sp_use_description(SPItem *item);
53 static NRArenaItem *sp_use_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags);
54 static void sp_use_hide(SPItem *item, unsigned key);
56 static void sp_use_href_changed(SPObject *old_ref, SPObject *ref, SPUse *use);
58 static void sp_use_delete_self(SPObject *deleted, SPUse *self);
60 static SPItemClass *parent_class;
62 //void m_print(gchar *say, NR::Matrix m)
63 //{ g_print("%s %g %g %g %g %g %g\n", say, m[0], m[1], m[2], m[3], m[4], m[5]); }
65 GType
66 sp_use_get_type(void)
67 {
68 static GType use_type = 0;
69 if (!use_type) {
70 GTypeInfo use_info = {
71 sizeof(SPUseClass),
72 NULL, /* base_init */
73 NULL, /* base_finalize */
74 (GClassInitFunc) sp_use_class_init,
75 NULL, /* class_finalize */
76 NULL, /* class_data */
77 sizeof(SPUse),
78 16, /* n_preallocs */
79 (GInstanceInitFunc) sp_use_init,
80 NULL, /* value_table */
81 };
82 use_type = g_type_register_static(SP_TYPE_ITEM, "SPUse", &use_info, (GTypeFlags)0);
83 }
84 return use_type;
85 }
87 static void
88 sp_use_class_init(SPUseClass *classname)
89 {
90 GObjectClass *gobject_class = (GObjectClass *) classname;
91 SPObjectClass *sp_object_class = (SPObjectClass *) classname;
92 SPItemClass *item_class = (SPItemClass *) classname;
94 parent_class = (SPItemClass*) g_type_class_ref(SP_TYPE_ITEM);
96 gobject_class->finalize = sp_use_finalize;
98 sp_object_class->build = sp_use_build;
99 sp_object_class->release = sp_use_release;
100 sp_object_class->set = sp_use_set;
101 sp_object_class->write = sp_use_write;
102 sp_object_class->update = sp_use_update;
103 sp_object_class->modified = sp_use_modified;
105 item_class->bbox = sp_use_bbox;
106 item_class->description = sp_use_description;
107 item_class->print = sp_use_print;
108 item_class->show = sp_use_show;
109 item_class->hide = sp_use_hide;
110 }
112 static void
113 sp_use_init(SPUse *use)
114 {
115 use->x.unset();
116 use->y.unset();
117 use->width.unset(SVGLength::PERCENT, 1.0, 1.0);
118 use->height.unset(SVGLength::PERCENT, 1.0, 1.0);
119 use->href = NULL;
121 new (&use->_delete_connection) sigc::connection();
122 new (&use->_changed_connection) sigc::connection();
124 new (&use->_transformed_connection) sigc::connection();
126 use->ref = new SPUseReference(SP_OBJECT(use));
128 use->_changed_connection = use->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_use_href_changed), use));
129 }
131 static void
132 sp_use_finalize(GObject *obj)
133 {
134 SPUse *use = (SPUse *) obj;
136 delete use->ref;
138 use->_delete_connection.~connection();
139 use->_changed_connection.~connection();
141 use->_transformed_connection.~connection();
142 }
144 static void
145 sp_use_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
146 {
147 if (((SPObjectClass *) parent_class)->build) {
148 (* ((SPObjectClass *) parent_class)->build)(object, document, repr);
149 }
151 sp_object_read_attr(object, "x");
152 sp_object_read_attr(object, "y");
153 sp_object_read_attr(object, "width");
154 sp_object_read_attr(object, "height");
155 sp_object_read_attr(object, "xlink:href");
157 // We don't need to create child here:
158 // reading xlink:href will attach ref, and that will cause the changed signal to be emitted,
159 // which will call sp_use_href_changed, and that will take care of the child
160 }
162 static void
163 sp_use_release(SPObject *object)
164 {
165 SPUse *use = SP_USE(object);
167 use->child = NULL;
169 use->_delete_connection.disconnect();
170 use->_changed_connection.disconnect();
171 use->_transformed_connection.disconnect();
173 g_free(use->href);
174 use->href = NULL;
176 use->ref->detach();
178 if (((SPObjectClass *) parent_class)->release) {
179 ((SPObjectClass *) parent_class)->release(object);
180 }
181 }
183 static void
184 sp_use_set(SPObject *object, unsigned key, gchar const *value)
185 {
186 SPUse *use = SP_USE(object);
188 switch (key) {
189 case SP_ATTR_X:
190 use->x.readOrUnset(value);
191 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
192 break;
193 case SP_ATTR_Y:
194 use->y.readOrUnset(value);
195 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
196 break;
197 case SP_ATTR_WIDTH:
198 use->width.readOrUnset(value, SVGLength::PERCENT, 1.0, 1.0);
199 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
200 break;
201 case SP_ATTR_HEIGHT:
202 use->height.readOrUnset(value, SVGLength::PERCENT, 1.0, 1.0);
203 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
204 break;
206 case SP_ATTR_XLINK_HREF: {
207 if ( value && use->href && ( strcmp(value, use->href) == 0 ) ) {
208 /* No change, do nothing. */
209 } else {
210 g_free(use->href);
211 use->href = NULL;
212 if (value) {
213 // First, set the href field, because sp_use_href_changed will need it.
214 use->href = g_strdup(value);
216 // Now do the attaching, which emits the changed signal.
217 try {
218 use->ref->attach(Inkscape::URI(value));
219 } catch (Inkscape::BadURIException &e) {
220 g_warning("%s", e.what());
221 use->ref->detach();
222 }
223 } else {
224 use->ref->detach();
225 }
226 }
227 break;
228 }
230 default:
231 if (((SPObjectClass *) parent_class)->set) {
232 ((SPObjectClass *) parent_class)->set(object, key, value);
233 }
234 break;
235 }
236 }
238 static Inkscape::XML::Node *
239 sp_use_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
240 {
241 SPUse *use = SP_USE(object);
243 if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
244 repr = sp_repr_new("svg:use");
245 }
247 if (((SPObjectClass *) (parent_class))->write) {
248 ((SPObjectClass *) (parent_class))->write(object, repr, flags);
249 }
251 sp_repr_set_svg_double(repr, "x", use->x.computed);
252 sp_repr_set_svg_double(repr, "y", use->y.computed);
253 sp_repr_set_svg_double(repr, "width", use->width.computed);
254 sp_repr_set_svg_double(repr, "height", use->height.computed);
256 if (use->ref->getURI()) {
257 gchar *uri_string = use->ref->getURI()->toString();
258 repr->setAttribute("xlink:href", uri_string);
259 g_free(uri_string);
260 }
262 return repr;
263 }
265 static void
266 sp_use_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags)
267 {
268 SPUse const *use = SP_USE(item);
270 if (use->child && SP_IS_ITEM(use->child)) {
271 SPItem *child = SP_ITEM(use->child);
272 NR::Matrix const ct( child->transform
273 * NR::translate(use->x.computed,
274 use->y.computed)
275 * transform );
276 sp_item_invoke_bbox_full(child, bbox, ct, flags, FALSE);
277 }
278 }
280 static void
281 sp_use_print(SPItem *item, SPPrintContext *ctx)
282 {
283 bool translated = false;
284 NRMatrix tp;
285 SPUse *use = SP_USE(item);
287 if ((use->x._set && use->x.computed != 0) || (use->y._set && use->y.computed != 0)) {
288 nr_matrix_set_translate(&tp, use->x.computed, use->y.computed);
289 sp_print_bind(ctx, &tp, 1.0);
290 translated = true;
291 }
293 if (use->child && SP_IS_ITEM(use->child)) {
294 sp_item_invoke_print(SP_ITEM(use->child), ctx);
295 }
297 if (translated) {
298 sp_print_release(ctx);
299 }
300 }
302 static gchar *
303 sp_use_description(SPItem *item)
304 {
305 SPUse *use = SP_USE(item);
307 char *ret;
308 if (use->child) {
309 static unsigned recursion_depth = 0;
310 if (recursion_depth >= 4) {
311 /* TRANSLATORS: Used for statusbar description for long <use> chains:
312 * "Clone of: Clone of: ... in Layer 1". */
313 return g_strdup(_("..."));
314 /* We could do better, e.g. chasing the href chain until we reach something other than
315 * a <use>, and giving its description. */
316 }
317 ++recursion_depth;
318 char *child_desc = sp_item_description(SP_ITEM(use->child));
319 --recursion_depth;
321 ret = g_strdup_printf(_("<b>Clone</b> of: %s"), child_desc);
322 g_free(child_desc);
323 return ret;
324 } else {
325 return g_strdup(_("<b>Orphaned clone</b>"));
326 }
327 }
329 static NRArenaItem *
330 sp_use_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags)
331 {
332 SPUse *use = SP_USE(item);
334 NRArenaItem *ai = NRArenaGroup::create(arena);
335 nr_arena_group_set_transparent(NR_ARENA_GROUP(ai), FALSE);
337 if (use->child) {
338 NRArenaItem *ac = sp_item_invoke_show(SP_ITEM(use->child), arena, key, flags);
339 if (ac) {
340 nr_arena_item_add_child(ai, ac, NULL);
341 nr_arena_item_unref(ac);
342 }
343 NR::translate t(use->x.computed,
344 use->y.computed);
345 nr_arena_group_set_child_transform(NR_ARENA_GROUP(ai), NR::Matrix(t));
346 }
348 return ai;
349 }
351 static void
352 sp_use_hide(SPItem *item, unsigned key)
353 {
354 SPUse *use = SP_USE(item);
356 if (use->child) {
357 sp_item_invoke_hide(SP_ITEM(use->child), key);
358 }
360 if (((SPItemClass *) parent_class)->hide) {
361 ((SPItemClass *) parent_class)->hide(item, key);
362 }
363 }
365 /**
366 * Returns the ultimate original of a SPUse (i.e. the first object in the chain of its originals
367 * which is not an SPUse).
368 *
369 * Note that the returned is the clone object, i.e. the child of an SPUse (of the argument one for
370 * the trivial case) and not the "true original".
371 */
372 SPItem *
373 sp_use_root(SPUse *use)
374 {
375 SPObject *orig = use->child;
376 while (SP_IS_USE(orig)) {
377 orig = SP_USE(orig)->child;
378 }
379 g_assert(SP_IS_ITEM(orig));
380 return SP_ITEM(orig);
381 }
383 /**
384 * Returns the effective transform that goes from the ultimate original to given SPUse, both ends
385 * included.
386 */
387 NR::Matrix
388 sp_use_get_root_transform(SPUse *use)
389 {
390 //track the ultimate source of a chain of uses
391 SPObject *orig = use->child;
392 GSList *chain = NULL;
393 chain = g_slist_prepend(chain, use);
394 while (SP_IS_USE(orig)) {
395 chain = g_slist_prepend(chain, orig);
396 orig = SP_USE(orig)->child;
397 }
398 chain = g_slist_prepend(chain, orig);
401 //calculate the accummulated transform, starting from the original
402 NR::Matrix t(NR::identity());
403 for (GSList *i = chain; i != NULL; i = i->next) {
404 SPItem *i_tem = SP_ITEM(i->data);
406 // "An additional transformation translate(x,y) is appended to the end (i.e.,
407 // right-side) of the transform attribute on the generated 'g', where x and y
408 // represent the values of the x and y attributes on the 'use' element." - http://www.w3.org/TR/SVG11/struct.html#UseElement
409 if (SP_IS_USE(i_tem)) {
410 SPUse *i_use = SP_USE(i_tem);
411 if ((i_use->x._set && i_use->x.computed != 0) || (i_use->y._set && i_use->y.computed != 0)) {
412 t = t * NR::translate(i_use->x._set ? i_use->x.computed : 0, i_use->y._set ? i_use->y.computed : 0);
413 }
414 }
416 t *= i_tem->transform;
417 }
419 g_slist_free(chain);
420 return t;
421 }
423 /**
424 * Returns the transform that leads to the use from its immediate original.
425 * Does not inlcude the original's transform if any.
426 */
427 NR::Matrix
428 sp_use_get_parent_transform(SPUse *use)
429 {
430 NR::Matrix t(NR::identity());
431 if ((use->x._set && use->x.computed != 0) || (use->y._set && use->y.computed != 0)) {
432 t *= NR::translate(use->x._set ? use->x.computed : 0,
433 use->y._set ? use->y.computed : 0);
434 }
436 t *= SP_ITEM(use)->transform;
437 return t;
438 }
440 /**
441 * Sensing a movement of the original, this function attempts to compensate for it in such a way
442 * that the clone stays unmoved or moves in parallel (depending on user setting) regardless of the
443 * clone's transform.
444 */
445 static void
446 sp_use_move_compensate(NR::Matrix const *mp, SPItem *original, SPUse *self)
447 {
448 // the clone is orphaned; or this is not a real use, but a clone of another use;
449 // we skip it, otherwise duplicate compensation will occur
450 if (SP_OBJECT_IS_CLONED(self)) {
451 return;
452 }
454 // never compensate uses which are used in flowtext
455 if (SP_OBJECT_PARENT(self) && SP_IS_FLOWREGION(SP_OBJECT_PARENT(self))) {
456 return;
457 }
459 guint mode = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_PARALLEL);
460 // user wants no compensation
461 if (mode == SP_CLONE_COMPENSATION_NONE)
462 return;
464 NR::Matrix m(*mp);
466 // this is not a simple move, do not try to compensate
467 if (!(m.is_translation()))
468 return;
470 // restore item->transform field from the repr, in case it was changed by seltrans
471 sp_object_read_attr (SP_OBJECT (self), "transform");
473 NR::Matrix t = sp_use_get_parent_transform(self);
474 NR::Matrix clone_move = t.inverse() * m * t;
476 // calculate the compensation matrix and the advertized movement matrix
477 NR::Matrix advertized_move;
478 if (mode == SP_CLONE_COMPENSATION_PARALLEL) {
479 clone_move = clone_move.inverse() * m;
480 advertized_move = m;
481 } else if (mode == SP_CLONE_COMPENSATION_UNMOVED) {
482 clone_move = clone_move.inverse();
483 advertized_move.set_identity();
484 } else {
485 g_assert_not_reached();
486 }
488 // commit the compensation
489 SPItem *item = SP_ITEM(self);
490 item->transform *= clone_move;
491 sp_item_write_transform(item, SP_OBJECT_REPR(item), item->transform, &advertized_move);
492 SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
493 }
495 static void
496 sp_use_href_changed(SPObject *old_ref, SPObject *ref, SPUse *use)
497 {
498 SPItem *item = SP_ITEM(use);
500 use->_delete_connection.disconnect();
501 use->_transformed_connection.disconnect();
503 if (use->child) {
504 sp_object_detach(SP_OBJECT(use), use->child);
505 use->child = NULL;
506 }
508 if (use->href) {
509 SPItem *refobj = use->ref->getObject();
510 if (refobj) {
511 Inkscape::XML::Node *childrepr = SP_OBJECT_REPR(refobj);
512 GType type = sp_repr_type_lookup(childrepr);
513 g_return_if_fail(type > G_TYPE_NONE);
514 if (g_type_is_a(type, SP_TYPE_ITEM)) {
515 use->child = (SPObject*) g_object_new(type, 0);
516 sp_object_attach(SP_OBJECT(use), use->child, use->lastChild());
517 sp_object_unref(use->child, SP_OBJECT(use));
518 sp_object_invoke_build(use->child, SP_OBJECT(use)->document, childrepr, TRUE);
520 for (SPItemView *v = item->display; v != NULL; v = v->next) {
521 NRArenaItem *ai;
522 ai = sp_item_invoke_show(SP_ITEM(use->child), NR_ARENA_ITEM_ARENA(v->arenaitem), v->key, v->flags);
523 if (ai) {
524 nr_arena_item_add_child(v->arenaitem, ai, NULL);
525 nr_arena_item_unref(ai);
526 }
527 }
529 }
530 use->_delete_connection = SP_OBJECT(refobj)->connectDelete(sigc::bind(sigc::ptr_fun(&sp_use_delete_self), use));
531 use->_transformed_connection = SP_ITEM(refobj)->connectTransformed(sigc::bind(sigc::ptr_fun(&sp_use_move_compensate), use));
532 }
533 }
534 }
536 static void
537 sp_use_delete_self(SPObject *deleted, SPUse *self)
538 {
539 // always delete uses which are used in flowtext
540 if (SP_OBJECT_PARENT(self) && SP_IS_FLOWREGION(SP_OBJECT_PARENT(self))) {
541 SP_OBJECT(self)->deleteObject();
542 return;
543 }
545 guint const mode = prefs_get_int_attribute("options.cloneorphans", "value",
546 SP_CLONE_ORPHANS_UNLINK);
548 if (mode == SP_CLONE_ORPHANS_UNLINK) {
549 sp_use_unlink(self);
550 } else if (mode == SP_CLONE_ORPHANS_DELETE) {
551 SP_OBJECT(self)->deleteObject();
552 }
553 }
555 static void
556 sp_use_update(SPObject *object, SPCtx *ctx, unsigned flags)
557 {
558 SPItem *item = SP_ITEM(object);
559 SPUse *use = SP_USE(object);
560 SPItemCtx *ictx = (SPItemCtx *) ctx;
561 SPItemCtx cctx = *ictx;
563 if (((SPObjectClass *) (parent_class))->update)
564 ((SPObjectClass *) (parent_class))->update(object, ctx, flags);
566 if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
567 flags &= SP_OBJECT_MODIFIED_CASCADE;
569 /* Set up child viewport */
570 if (use->x.unit == SVGLength::PERCENT) {
571 use->x.computed = use->x.value * (ictx->vp.x1 - ictx->vp.x0);
572 }
573 if (use->y.unit == SVGLength::PERCENT) {
574 use->y.computed = use->y.value * (ictx->vp.y1 - ictx->vp.y0);
575 }
576 if (use->width.unit == SVGLength::PERCENT) {
577 use->width.computed = use->width.value * (ictx->vp.x1 - ictx->vp.x0);
578 }
579 if (use->height.unit == SVGLength::PERCENT) {
580 use->height.computed = use->height.value * (ictx->vp.y1 - ictx->vp.y0);
581 }
582 cctx.vp.x0 = 0.0;
583 cctx.vp.y0 = 0.0;
584 cctx.vp.x1 = use->width.computed;
585 cctx.vp.y1 = use->height.computed;
586 cctx.i2vp = NR::identity();
587 flags&=~SP_OBJECT_USER_MODIFIED_FLAG_B;
589 if (use->child) {
590 g_object_ref(G_OBJECT(use->child));
591 if (flags || (use->child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
592 if (SP_IS_ITEM(use->child)) {
593 SPItem const &chi = *SP_ITEM(use->child);
594 cctx.i2doc = chi.transform * ictx->i2doc;
595 cctx.i2vp = chi.transform * ictx->i2vp;
596 use->child->updateDisplay((SPCtx *)&cctx, flags);
597 } else {
598 use->child->updateDisplay(ctx, flags);
599 }
600 }
601 g_object_unref(G_OBJECT(use->child));
602 }
604 /* As last step set additional transform of arena group */
605 for (SPItemView *v = item->display; v != NULL; v = v->next) {
606 NRMatrix t;
607 nr_matrix_set_translate(&t, use->x.computed, use->y.computed);
608 nr_arena_group_set_child_transform(NR_ARENA_GROUP(v->arenaitem), &t);
609 }
610 }
612 static void
613 sp_use_modified(SPObject *object, guint flags)
614 {
615 SPUse *use_obj = SP_USE(object);
617 if (flags & SP_OBJECT_MODIFIED_FLAG) {
618 flags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
619 }
620 flags &= SP_OBJECT_MODIFIED_CASCADE;
622 SPObject *child = use_obj->child;
623 if (child) {
624 g_object_ref(G_OBJECT(child));
625 if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
626 child->emitModified(flags);
627 }
628 g_object_unref(G_OBJECT(child));
629 }
630 }
632 SPItem *
633 sp_use_unlink(SPUse *use)
634 {
635 if (!use) return NULL;
637 Inkscape::XML::Node *repr = SP_OBJECT_REPR(use);
638 if (!repr) return NULL;
640 Inkscape::XML::Node *parent = sp_repr_parent(repr);
641 SPDocument *document = SP_OBJECT(use)->document;
643 // Track the ultimate source of a chain of uses.
644 SPItem *orig = sp_use_root(use);
646 // Calculate the accumulated transform, starting from the original.
647 NR::Matrix t = sp_use_get_root_transform(use);
649 Inkscape::XML::Node *copy = NULL;
650 if (SP_IS_SYMBOL(orig)) { // make a group, copy children
651 copy = sp_repr_new("svg:g");
652 for (Inkscape::XML::Node *child = SP_OBJECT_REPR(orig)->firstChild() ; child != NULL; child = child->next()) {
653 Inkscape::XML::Node *newchild = child->duplicate();
654 copy->appendChild(newchild);
655 }
656 } else { // just copy
657 copy = SP_OBJECT_REPR(orig)->duplicate();
658 }
660 // Add the duplicate repr just after the existing one.
661 parent->addChild(copy, repr);
663 // Retrieve the SPItem of the resulting repr.
664 SPObject *unlinked = document->getObjectByRepr(copy);
666 // Merge style from the use.
667 SPStyle *unli_sty = SP_OBJECT_STYLE(unlinked);
668 SPStyle const *use_sty = SP_OBJECT_STYLE(use);
669 sp_style_merge_from_dying_parent(unli_sty, use_sty);
670 sp_style_merge_from_parent(unli_sty, unlinked->parent->style);
672 SP_OBJECT(unlinked)->updateRepr();
674 // Hold onto our SPObject and repr for now.
675 sp_object_ref(SP_OBJECT(use), NULL);
676 Inkscape::GC::anchor(repr);
678 // Remove ourselves, not propagating delete events to avoid a
679 // chain-reaction with other elements that might reference us.
680 SP_OBJECT(use)->deleteObject(false);
682 // Give the copy our old id and let go of our old repr.
683 copy->setAttribute("id", repr->attribute("id"));
684 Inkscape::GC::release(repr);
686 // Remove tiled clone attrs.
687 copy->setAttribute("inkscape:tiled-clone-of", NULL);
688 copy->setAttribute("inkscape:tile-w", NULL);
689 copy->setAttribute("inkscape:tile-h", NULL);
690 copy->setAttribute("inkscape:tile-cx", NULL);
691 copy->setAttribute("inkscape:tile-cy", NULL);
693 // Establish the succession and let go of our object.
694 SP_OBJECT(use)->setSuccessor(unlinked);
695 sp_object_unref(SP_OBJECT(use), NULL);
697 SPItem *item = SP_ITEM(unlinked);
698 // Set the accummulated transform.
699 {
700 NR::Matrix nomove(NR::identity());
701 NRMatrix ctrans = t.operator const NRMatrix&();
702 // Advertise ourselves as not moving.
703 sp_item_write_transform(item, SP_OBJECT_REPR(item), &ctrans, &nomove);
704 }
705 return item;
706 }
708 SPItem *
709 sp_use_get_original(SPUse *use)
710 {
711 SPItem *ref = use->ref->getObject();
712 return ref;
713 }
716 /*
717 Local Variables:
718 mode:c++
719 c-file-style:"stroustrup"
720 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
721 indent-tabs-mode:nil
722 fill-column:99
723 End:
724 */
725 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :