Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-shape-reference.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Reference class for shapes (SVG 2 text).
4 *
5 * Copyright (C) 2020 Authors
6 */
7
9#include "object/sp-text.h"
10
12 : URIReference(obj)
13{
14 // The text object can be detached from the document but still be
15 // referenced, and its style (who's the owner of the SPShapeReference)
16 // can also still be referenced even after the object got destroyed.
17 _owner_release_connection = obj->connectRelease([this](SPObject *text_object) {
18 assert(text_object == this->getOwner());
19
20 // Fully detach to prevent reconnecting with a shape's modified signal
21 this->detach();
22
23 this->_owner_release_connection.disconnect();
24 });
25
26 // https://www.w3.org/TR/SVG/text.html#TextShapeInside
27 // Applies to: 'text' elements
28 // Inherited: no
29 if (!is<SPText>(obj)) {
30 g_warning("shape reference on non-text object: %s", typeid(*obj).name());
31 return;
32 }
33
34 // Listen to the shape's modified event to keep the text layout updated
35 changedSignal().connect([this](SPObject *, SPObject *shape_object) {
36 this->_shape_modified_connection.disconnect();
37
38 if (shape_object) {
40 shape_object->connectModified(sigc::mem_fun(*this, &SPShapeReference::on_shape_modified));
41 }
42 });
43}
44
50
54void SPShapeReference::on_shape_modified(SPObject *shape_object, unsigned flags)
55{
56 auto *text_object = getOwner();
57
58 assert(text_object);
59 assert(shape_object == getObject());
60
61 if ((flags & SP_OBJECT_MODIFIED_FLAG)) {
62 text_object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
63 }
64}
65
66// vim: filetype=cpp:expandtab:shiftwidth=4:softtabstop=4:fileencoding=utf-8:textwidth=99 :
void detach()
Detaches from the currently attached URI target, if any; the current referrent is signaled as NULL.
SPObject * getOwner() const
Returns a pointer to the URIReference's owner.
sigc::signal< void(SPObject *, SPObject *)> changedSignal()
Accessor for the referrent change notification signal; this signal is emitted whenever the URIReferen...
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
sigc::connection connectRelease(sigc::slot< void(SPObject *)> slot)
Connects to the release request signal.
Definition sp-object.h:237
sigc::connection connectModified(sigc::slot< void(SPObject *, unsigned int)> slot)
Connects to the modification notification signal.
Definition sp-object.h:705
sigc::connection _owner_release_connection
void on_shape_modified(SPObject *, unsigned flags)
Slot to connect to the shape's modified signal.
sigc::connection _shape_modified_connection
SPShape * getObject() const
SPShapeReference(SPObject *obj)