From d06782b3f1903cca1518a161b9ff86556b38d865 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Thu, 23 Jan 2020 11:48:00 -0500 Subject: [PATCH] Repair bad regex and copy shape-inside reference correctly. --- src/id-clash.cpp | 18 +++++++++++++++--- src/object/sp-text.cpp | 2 +- src/ui/clipboard.cpp | 17 +++++++++++++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/id-clash.cpp b/src/id-clash.cpp index 328159165da..f008a07e925 100644 --- a/src/id-clash.cpp +++ b/src/id-clash.cpp @@ -24,6 +24,7 @@ #include "object/sp-gradient.h" #include "object/sp-object.h" +#include "object/sp-text.h" #include "object/sp-paint-server.h" #include "object/sp-root.h" #include "style.h" @@ -155,6 +156,16 @@ find_references(SPObject *elem, refmap_type &refmap) } } + /* Special check for shape-inside */ + SPText *text = dynamic_cast(elem); + if (text && style->shape_inside.set) { + std::vector shapes = text->get_shapes(); + for (auto shape: shapes) { + IdReference idref = { REF_STYLE, elem, "shape-inside" }; + refmap[shape.c_str()].push_back(idref); + } + } + /* check for url(#...) references in markers */ const gchar *markers[4] = { "", "marker-start", "marker-mid", "marker-end" }; for (unsigned i = SP_MARKER_LOC_START; i < SP_MARKER_LOC_QTY; i++) { @@ -228,9 +239,10 @@ change_clashing_ids(SPDocument *imported_doc, SPDocument *current_doc, // Change to the new ID elem->setAttribute("id", new_id); - // Make a note of this change, if we need to fix up refs to it - if (refmap.find(old_id) != refmap.end()) - id_changes->push_back(id_changeitem_type(elem, old_id)); + // Make a note of this change, if we need to fix up refs to it + if (refmap.find(old_id) != refmap.end()) { + id_changes->push_back(id_changeitem_type(elem, old_id)); + } } } diff --git a/src/object/sp-text.cpp b/src/object/sp-text.cpp index 63e1352d602..41e83ce5c95 100644 --- a/src/object/sp-text.cpp +++ b/src/object/sp-text.cpp @@ -1060,7 +1060,7 @@ std::vector SPText::get_shapes() const std::vector shapes; char const *val; if (style->shape_inside.set && (val = style->shape_inside.value())) { - static Glib::RefPtr regex = Glib::Regex::create("url\\(#([A-z0-9#]*)\\)"); + static Glib::RefPtr regex = Glib::Regex::create("url\\(#([^\\)]*)\\)"); Glib::MatchInfo matchInfo; // Glib::Regex::match stack-use-after-scope workaround diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 733f1c01870..bcb753ca00a 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -867,15 +867,24 @@ void ClipboardManagerImpl::_copyUsedDefs(SPItem *item) } } - // Copy text paths + // Copy text elements { SPText *text = dynamic_cast(item); - SPTextPath *textpath = (text) ? dynamic_cast(text->firstChild()) : nullptr; - if (textpath) { - _copyTextPath(textpath); + if (text) { + // Copy text paths + SPTextPath *textpath = dynamic_cast(text->firstChild()); + if (textpath) { + _copyTextPath(textpath); + } + // Copy text shape-inside + Inkscape::XML::Node* rectangle = text->get_first_rectangle(); + if (rectangle) { + _copyNode(rectangle, _doc, _defs); + } } } + // Copy clipping objects if (SPObject *clip = item->getClipObject()) { _copyNode(clip->getRepr(), _doc, _defs); -- GitLab