From c1e2bbe2ed5d8b7cddd69b80ee20c7d39ab20c44 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Tue, 25 Nov 2014 22:39:57 +0100 Subject: More c++ string usage. (bzr r13763) --- src/sp-object.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 024fce85a..4e45eb824 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1254,6 +1254,16 @@ void SPObject::setAttribute(gchar const *key, gchar const *value, SPException *e //XML Tree being used here. getRepr()->setAttribute(key, value, false); } +void SPObject::setAttribute(char const *key, Glib::ustring const &value, SPException *ex) +{ + setAttribute(key, value.empty() ? NULL : value.c_str(), ex); +} +void SPObject::setAttribute(Glib::ustring const &key, Glib::ustring const &value, SPException *ex) +{ + setAttribute( key.empty() ? NULL : key.c_str(), + value.empty() ? NULL : value.c_str(), ex); +} + void SPObject::removeAttribute(gchar const *key, SPException *ex) { -- cgit v1.2.3 From 0533bf991e946b09053753566f209940f500d368 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 16 Dec 2014 15:05:47 +0100 Subject: Debugging routines to print out XML, SP Object, and Display Item trees. (bzr r13802) --- src/sp-object.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 4e45eb824..3b09d80e8 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1523,6 +1523,22 @@ char* SPObject::textualContent() const return g_string_free(text, FALSE); } +// For debugging: Print SP tree structure. +void SPObject::recursivePrintTree( unsigned level ) +{ + if (level == 0) { + std::cout << "SP Object Tree" << std::endl; + } + std::cout << "SP: "; + for (unsigned i = 0; i < level; ++i) { + std::cout << " "; + } + std::cout << (getId()?getId():"No object id") << std::endl; + for (SPObject *child = children; child; child = child->next) { + child->recursivePrintTree( level+1 ); + } +} + /* Local Variables: mode:c++ -- cgit v1.2.3 From f01a18216e26fd87a53188018e03527c7fdf8a57 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 23 Dec 2014 10:25:08 +0100 Subject: Use gray for 'context-fill' and 'context-stroke' in marker selector. Fix rendering bug when elements with 'context-fill' and 'context-stroke' are inside groups. (bzr r13822) --- src/sp-object.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 3b09d80e8..776b020d2 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -131,6 +131,7 @@ SPObject::SPObject() // polygon, text, tspan, tref, textPath, altGlyph, glyphRef, marker, linearGradient, radialGradient, // stop, pattern, clipPath, mask, filter, feImage, a, font, glyph, missing-glyph, foreignObject this->style = sp_style_new_from_object(this); + this->context_style = NULL; } SPObject::~SPObject() { -- cgit v1.2.3 From 497b9890e0cb85fced32d6958b465d40212db482 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 24 Dec 2014 10:03:50 +0100 Subject: Remove sp_style_new_from_object() (bzr r13822.1.1) --- src/sp-object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 776b020d2..b0b482cf2 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -130,7 +130,7 @@ SPObject::SPObject() // vg, g, defs, desc, title, symbol, use, image, switch, path, rect, circle, ellipse, line, polyline, // polygon, text, tspan, tref, textPath, altGlyph, glyphRef, marker, linearGradient, radialGradient, // stop, pattern, clipPath, mask, filter, feImage, a, font, glyph, missing-glyph, foreignObject - this->style = sp_style_new_from_object(this); + this->style = new SPStyle( NULL, this ); // Is it necessary to call with "this"? this->context_style = NULL; } -- cgit v1.2.3 From c10ae6598c095b0273672f764f0fe0e684c94b87 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 24 Dec 2014 11:27:30 +0100 Subject: Remove sp_style_read_from_object() (bzr r13822.1.3) --- src/sp-object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index b0b482cf2..124471545 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -915,7 +915,7 @@ void SPObject::set(unsigned int key, gchar const* value) { object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); break; case SP_ATTR_STYLE: - sp_style_read_from_object(object->style, object); + object->style->readFromObject( object ); object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); break; default: -- cgit v1.2.3 From 9a8bd0c8c29161a2fd91ccb48a3a813d4a45ac99 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 25 Dec 2014 12:40:35 +0100 Subject: Remove sp_style_write_string() and sp_style_write_difference(). (bzr r13822.1.4) --- src/sp-object.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 124471545..d492e7817 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1007,9 +1007,8 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML repr->setAttribute("inkscape:collect", NULL); } - SPStyle const *const obj_style = this->style; - if (obj_style) { - gchar *s = sp_style_write_string(obj_style, SP_STYLE_FLAG_IFSET); + if (style) { + Glib::ustring s = style->write(SP_STYLE_FLAG_IFSET); // Check for valid attributes. This may be time consuming. // It is useful, though, for debugging Inkscape code. @@ -1017,17 +1016,14 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML if( prefs->getBool("/options/svgoutput/check_on_editing") ) { unsigned int flags = sp_attribute_clean_get_prefs(); - Glib::ustring s_cleaned = sp_attribute_clean_style( repr, s, flags ); - g_free( s ); - s = (s_cleaned.empty() ? NULL : g_strdup (s_cleaned.c_str())); + Glib::ustring s_cleaned = sp_attribute_clean_style( repr, s.c_str(), flags ); } - if( s == NULL || strcmp(s,"") == 0 ) { + if( s.empty() ) { repr->setAttribute("style", NULL); } else { - repr->setAttribute("style", s); + repr->setAttribute("style", s.c_str()); } - g_free(s); } else { /** \todo I'm not sure what to do in this case. Bug #1165868 -- cgit v1.2.3 From 3598d85ed64693808296324289a2d6e5284d486e Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 25 Dec 2014 17:05:40 +0100 Subject: Remove sp_style_merge_from_parent() and sp_style_merge_from_dying_parent(). (bzr r13822.1.5) --- src/sp-object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index d492e7817..af8855562 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1145,7 +1145,7 @@ void SPObject::updateDisplay(SPCtx *ctx, unsigned int flags) */ if ((flags & SP_OBJECT_STYLE_MODIFIED_FLAG) && (flags & SP_OBJECT_PARENT_MODIFIED_FLAG)) { if (this->style && this->parent) { - sp_style_merge_from_parent(this->style, this->parent->style); + style->cascade( this->parent->style ); } } -- cgit v1.2.3 From 05f2f043bdbadefa4ea435981e1a728420d6b93c Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 25 Dec 2014 20:30:29 +0100 Subject: Remove sp_style_new(). (bzr r13822.1.6) --- src/sp-object.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index af8855562..4f213f943 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -145,6 +145,8 @@ SPObject::~SPObject() { sp_object_unref(this->_successor, NULL); this->_successor = NULL; } + + delete this->style; } // CPPIFY: make pure virtual -- cgit v1.2.3 From c784e87f3b53e823dfb303e296ede834accc9322 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 26 Dec 2014 15:44:07 +0100 Subject: SPStyle ref counting clean up. (bzr r13822.1.7) --- src/sp-object.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 4f213f943..059fa8093 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -146,7 +146,18 @@ SPObject::~SPObject() { this->_successor = NULL; } - delete this->style; + if( style == NULL ) { + // style pointer could be NULL if unreffed too many times. + // Conjecture: style pointer is never NULL. + std::cerr << "SPObject::~SPObject(): style pointer is NULL" << std::endl; + } else if( style->refCount() > 1 ) { + // Several classes ref style. + // Conjecture: style pointer should be unreffed by other classes before reaching here. + std::cerr << "SPObject::~SPObject(): someone else still holding ref to style" << std::endl; + sp_style_unref( this->style ); + } else { + delete this->style; + } } // CPPIFY: make pure virtual @@ -798,9 +809,10 @@ void SPObject::releaseReferences() { g_assert(!this->id); } - if (this->style) { - this->style = sp_style_unref(this->style); - } + // style belongs to SPObject, we should not need to unref here. + // if (this->style) { + // this->style = sp_style_unref(this->style); + // } this->document = NULL; this->repr = NULL; -- cgit v1.2.3 From c2daf6ff5a0ed4ea5d825b48c1e9466e19f0f81d Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 5 Jan 2015 10:47:09 +0100 Subject: Comment out error message about style ref counting and add explanation. (bzr r13838) --- src/sp-object.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 059fa8093..7d24a978e 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -151,9 +151,14 @@ SPObject::~SPObject() { // Conjecture: style pointer is never NULL. std::cerr << "SPObject::~SPObject(): style pointer is NULL" << std::endl; } else if( style->refCount() > 1 ) { - // Several classes ref style. // Conjecture: style pointer should be unreffed by other classes before reaching here. - std::cerr << "SPObject::~SPObject(): someone else still holding ref to style" << std::endl; + // Conjecture is false for SPTSpan where ref is held by InputStreamTextSource. + // As an additional note: + // The outer tspan of a nested tspan will result in a ref count of five: one for the + // TSpan itself, one for the InputStreamTextSource instance before the inner tspan and + // one for the one after, along with one for each corresponding DrawingText instance. + // std::cerr << "SPObject::~SPObject(): someone else still holding ref to style" << std::endl; + // sp_style_unref( this->style ); } else { delete this->style; -- cgit v1.2.3 From 47d7675c0ec6a65e27e9ff69a8bfd34b621effab Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sat, 21 Feb 2015 17:23:30 +0100 Subject: Fix for the performance loss in ungrouping observed by Tavmjong in rev 13933 Added std::list hrefList member to SPObject class. (bzr r13935) --- src/sp-object.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 7d24a978e..1094b88a7 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -115,7 +115,7 @@ static gchar *sp_object_get_unique_id(SPObject *object, SPObject::SPObject() : cloned(0), uflags(0), mflags(0), hrefcount(0), _total_hrefcount(0), document(NULL), parent(NULL), children(NULL), _last_child(NULL), - next(NULL), id(NULL), repr(NULL), refCount(1), + next(NULL), id(NULL), repr(NULL), refCount(1),hrefList(std::list()), _successor(NULL), _collection_policy(SPObject::COLLECT_WITH_PARENT), _label(NULL), _default_label(NULL) { @@ -254,7 +254,7 @@ SPObject *sp_object_unref(SPObject *object, SPObject *owner) return NULL; } -SPObject *sp_object_href(SPObject *object, gpointer /*owner*/) +SPObject *sp_object_href(SPObject *object, SPObject* owner) { g_return_val_if_fail(object != NULL, NULL); g_return_val_if_fail(SP_IS_OBJECT(object), NULL); @@ -262,10 +262,13 @@ SPObject *sp_object_href(SPObject *object, gpointer /*owner*/) object->hrefcount++; object->_updateTotalHRefCount(1); + if(owner) + object->hrefList.push_front(owner); + return object; } -SPObject *sp_object_hunref(SPObject *object, gpointer /*owner*/) +SPObject *sp_object_hunref(SPObject *object, SPObject* owner) { g_return_val_if_fail(object != NULL, NULL); g_return_val_if_fail(SP_IS_OBJECT(object), NULL); @@ -274,6 +277,9 @@ SPObject *sp_object_hunref(SPObject *object, gpointer /*owner*/) object->hrefcount--; object->_updateTotalHRefCount(-1); + if(owner) + object->hrefList.remove(owner); + return NULL; } -- cgit v1.2.3 From df7828a7a8ba0b7e6c2dd892ca5f0a62ef718bf0 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Tue, 24 Feb 2015 19:22:08 -0500 Subject: create SPObject factory (bzr r13939.1.1) --- src/sp-object.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src/sp-object.cpp') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 1094b88a7..343db435e 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -61,14 +61,6 @@ using std::strstr; # define debug(f, a...) /* */ #endif -namespace { - SPObject* createObject() { - return new SPObject(); - } - - bool gridRegistered = SPFactory::instance().registerObject("inkscape:grid", createObject); -} - guint update_in_progress = 0; // guard against update-during-update Inkscape::XML::NodeEventVector object_event_vector = { @@ -629,7 +621,7 @@ void SPObject::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) const std::string type_string = NodeTraits::get_type_string(*child); - SPObject* ochild = SPFactory::instance().createObject(type_string); + SPObject* ochild = SPFactory::createObject(type_string); if (ochild == NULL) { // Currenty, there are many node types that do not have // corresponding classes in the SPObject tree. @@ -688,7 +680,7 @@ void SPObject::build(SPDocument *document, Inkscape::XML::Node *repr) { for (Inkscape::XML::Node *rchild = repr->firstChild() ; rchild != NULL; rchild = rchild->next()) { const std::string typeString = NodeTraits::get_type_string(*rchild); - SPObject* child = SPFactory::instance().createObject(typeString); + SPObject* child = SPFactory::createObject(typeString); if (child == NULL) { // Currenty, there are many node types that do not have // corresponding classes in the SPObject tree. -- cgit v1.2.3