From cca66b9ec4e494c1d919bff0f71a820d8afab1fa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:24:48 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- src/object/sp-shape-reference.cpp | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/object/sp-shape-reference.cpp (limited to 'src/object/sp-shape-reference.cpp') 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(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 : -- cgit v1.2.3