summaryrefslogtreecommitdiffstats
path: root/src/object/sp-shape-reference.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
commitcca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch)
tree146f39ded1c938019e1ed42d30923c2ac9e86789 /src/object/sp-shape-reference.cpp
parentInitial commit. (diff)
downloadinkscape-upstream.tar.xz
inkscape-upstream.zip
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/object/sp-shape-reference.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/object/sp-shape-reference.cpp b/src/object/sp-shape-reference.cpp
new file mode 100644
index 0000000..1e302b4
--- /dev/null
+++ b/src/object/sp-shape-reference.cpp
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Reference class for shapes (SVG 2 text).
+ *
+ * Copyright (C) 2020 Authors
+ */
+
+#include "sp-shape-reference.h"
+#include "object/sp-text.h"
+
+SPShapeReference::SPShapeReference(SPObject *obj)
+ : URIReference(obj)
+{
+ // The text object can be detached from the document but still be
+ // referenced, and its style (who's the owner of the SPShapeReference)
+ // can also still be referenced even after the object got destroyed.
+ _owner_release_connection = obj->connectRelease([this](SPObject *text_object) {
+ assert(text_object == this->getOwner());
+
+ // Fully detach to prevent reconnecting with a shape's modified signal
+ this->detach();
+
+ this->_owner_release_connection.disconnect();
+ });
+
+ // https://www.w3.org/TR/SVG/text.html#TextShapeInside
+ // Applies to: 'text' elements
+ // Inherited: no
+ if (!dynamic_cast<SPText *>(obj)) {
+ g_warning("shape reference on non-text object: %s", typeid(*obj).name());
+ return;
+ }
+
+ // Listen to the shape's modified event to keep the text layout updated
+ changedSignal().connect([this](SPObject *, SPObject *shape_object) {
+ this->_shape_modified_connection.disconnect();
+
+ if (shape_object) {
+ this->_shape_modified_connection =
+ shape_object->connectModified(sigc::mem_fun(*this, &SPShapeReference::on_shape_modified));
+ }
+ });
+}
+
+SPShapeReference::~SPShapeReference()
+{ //
+ _shape_modified_connection.disconnect();
+ _owner_release_connection.disconnect();
+}
+
+/**
+ * Slot to connect to the shape's modified signal. Requests display update of the text object.
+ */
+void SPShapeReference::on_shape_modified(SPObject *shape_object, unsigned flags)
+{
+ auto *text_object = getOwner();
+
+ assert(text_object);
+ assert(shape_object == getObject());
+
+ if ((flags & SP_OBJECT_MODIFIED_FLAG)) {
+ text_object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
+ }
+}
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:softtabstop=4:fileencoding=utf-8:textwidth=99 :