From fd0a5dfa4cb237f8e5232c785693cc3e676336e8 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sun, 2 Sep 2012 21:32:59 +0200 Subject: converted some c-string usage to c++ string class usage: should fix some memory leaks (bzr r11646) --- src/attribute-rel-util.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/attribute-rel-util.cpp') diff --git a/src/attribute-rel-util.cpp b/src/attribute-rel-util.cpp index 239e359e2..cf94c0c1e 100644 --- a/src/attribute-rel-util.cpp +++ b/src/attribute-rel-util.cpp @@ -128,17 +128,13 @@ void sp_attribute_clean_style(Node *repr, unsigned int flags) { // Find element's style SPCSSAttr *css = sp_repr_css_attr( repr, "style" ); - sp_attribute_clean_style(repr, css, flags); - // g_warning( "sp_repr_write_stream_element(): Final style:" ); - //sp_repr_css_print( css ); - // Convert css node's properties data to string and set repr node's attribute "style" to that string. // sp_repr_css_set( repr, css, "style"); // Don't use as it will cause loop. - gchar *value = sp_repr_css_write_string(css); - repr->setAttribute("style", value); - if (value) g_free (value); + Glib::ustring value; + sp_repr_css_write_string(css, value); + repr->setAttribute("style", value.c_str()); sp_repr_css_attr_unref( css ); } @@ -147,7 +143,7 @@ void sp_attribute_clean_style(Node *repr, unsigned int flags) { /** * Clean CSS style on an element. */ -gchar * sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int flags) { +Glib::ustring sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int flags) { g_return_val_if_fail (repr != NULL, NULL); g_return_val_if_fail (repr->type() == Inkscape::XML::ELEMENT_NODE, NULL); @@ -155,11 +151,12 @@ gchar * sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int f SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string( css, string ); sp_attribute_clean_style(repr, css, flags); - gchar* string_cleaned = sp_repr_css_write_string( css ); + Glib::ustring string_cleaned; + sp_repr_css_write_string (css, string_cleaned); sp_repr_css_attr_unref( css ); - return string_cleaned; + return string_cleaned; } -- cgit v1.2.3 From d4f5006264e2e19a9fe50968a2e422b83785821c Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Mon, 3 Sep 2012 08:35:01 +0200 Subject: revert rev 11646: build issue with dbus (forgot to adapt some more, dbus was not enabled) and other issues (bzr r11649) --- src/attribute-rel-util.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/attribute-rel-util.cpp') diff --git a/src/attribute-rel-util.cpp b/src/attribute-rel-util.cpp index cf94c0c1e..239e359e2 100644 --- a/src/attribute-rel-util.cpp +++ b/src/attribute-rel-util.cpp @@ -128,13 +128,17 @@ void sp_attribute_clean_style(Node *repr, unsigned int flags) { // Find element's style SPCSSAttr *css = sp_repr_css_attr( repr, "style" ); + sp_attribute_clean_style(repr, css, flags); + // g_warning( "sp_repr_write_stream_element(): Final style:" ); + //sp_repr_css_print( css ); + // Convert css node's properties data to string and set repr node's attribute "style" to that string. // sp_repr_css_set( repr, css, "style"); // Don't use as it will cause loop. - Glib::ustring value; - sp_repr_css_write_string(css, value); - repr->setAttribute("style", value.c_str()); + gchar *value = sp_repr_css_write_string(css); + repr->setAttribute("style", value); + if (value) g_free (value); sp_repr_css_attr_unref( css ); } @@ -143,7 +147,7 @@ void sp_attribute_clean_style(Node *repr, unsigned int flags) { /** * Clean CSS style on an element. */ -Glib::ustring sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int flags) { +gchar * sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int flags) { g_return_val_if_fail (repr != NULL, NULL); g_return_val_if_fail (repr->type() == Inkscape::XML::ELEMENT_NODE, NULL); @@ -151,12 +155,11 @@ Glib::ustring sp_attribute_clean_style(Node *repr, gchar const *string, unsigned SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string( css, string ); sp_attribute_clean_style(repr, css, flags); - Glib::ustring string_cleaned; - sp_repr_css_write_string (css, string_cleaned); + gchar* string_cleaned = sp_repr_css_write_string( css ); sp_repr_css_attr_unref( css ); - return string_cleaned; + return string_cleaned; } -- cgit v1.2.3 From bac4df147de363a0774548acd63d367a09ab50d3 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Thu, 20 Sep 2012 22:40:55 +0200 Subject: some memleak fixes (Bug #1043571) (bzr r11686) --- src/attribute-rel-util.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/attribute-rel-util.cpp') diff --git a/src/attribute-rel-util.cpp b/src/attribute-rel-util.cpp index 239e359e2..cf94c0c1e 100644 --- a/src/attribute-rel-util.cpp +++ b/src/attribute-rel-util.cpp @@ -128,17 +128,13 @@ void sp_attribute_clean_style(Node *repr, unsigned int flags) { // Find element's style SPCSSAttr *css = sp_repr_css_attr( repr, "style" ); - sp_attribute_clean_style(repr, css, flags); - // g_warning( "sp_repr_write_stream_element(): Final style:" ); - //sp_repr_css_print( css ); - // Convert css node's properties data to string and set repr node's attribute "style" to that string. // sp_repr_css_set( repr, css, "style"); // Don't use as it will cause loop. - gchar *value = sp_repr_css_write_string(css); - repr->setAttribute("style", value); - if (value) g_free (value); + Glib::ustring value; + sp_repr_css_write_string(css, value); + repr->setAttribute("style", value.c_str()); sp_repr_css_attr_unref( css ); } @@ -147,7 +143,7 @@ void sp_attribute_clean_style(Node *repr, unsigned int flags) { /** * Clean CSS style on an element. */ -gchar * sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int flags) { +Glib::ustring sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int flags) { g_return_val_if_fail (repr != NULL, NULL); g_return_val_if_fail (repr->type() == Inkscape::XML::ELEMENT_NODE, NULL); @@ -155,11 +151,12 @@ gchar * sp_attribute_clean_style(Node *repr, gchar const *string, unsigned int f SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string( css, string ); sp_attribute_clean_style(repr, css, flags); - gchar* string_cleaned = sp_repr_css_write_string( css ); + Glib::ustring string_cleaned; + sp_repr_css_write_string (css, string_cleaned); sp_repr_css_attr_unref( css ); - return string_cleaned; + return string_cleaned; } -- cgit v1.2.3 From 9bffe44ca5eef802c58c1ccf8e41800f987d6697 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sat, 3 Nov 2012 10:21:27 +0100 Subject: Don't remove default css values if element is in or is a . (bzr r11860) --- src/attribute-rel-util.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/attribute-rel-util.cpp') diff --git a/src/attribute-rel-util.cpp b/src/attribute-rel-util.cpp index cf94c0c1e..38327b413 100644 --- a/src/attribute-rel-util.cpp +++ b/src/attribute-rel-util.cpp @@ -76,7 +76,14 @@ void sp_attribute_clean_recursive(Node *repr, unsigned int flags) { } for(Node *child=repr->firstChild() ; child ; child = child->next()) { - sp_attribute_clean_recursive( child, flags ); + + // Don't remove default css values if element is in or is a + Glib::ustring element = child->name(); + unsigned int flags_temp = flags; + if( element.compare( "svg:defs" ) == 0 || element.compare( "svg:symbol" ) == 0 ) { + flags_temp &= ~(SP_ATTR_CLEAN_DEFAULT_WARN|SP_ATTR_CLEAN_DEFAULT_REMOVE); + } + sp_attribute_clean_recursive( child, flags_temp ); } } -- cgit v1.2.3 From 4d368c0ed0441dfd9e0cda7fa1c0f370180fa4ae Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 23 Jan 2013 19:45:08 +0100 Subject: cppcheck: style and performance (bzr r12056) --- src/attribute-rel-util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/attribute-rel-util.cpp') diff --git a/src/attribute-rel-util.cpp b/src/attribute-rel-util.cpp index 38327b413..0527dad4e 100644 --- a/src/attribute-rel-util.cpp +++ b/src/attribute-rel-util.cpp @@ -209,9 +209,9 @@ void sp_attribute_clean_style(Node* repr, SPCSSAttr *css, unsigned int flags) { } // Find parent value for same property (property) - gchar const * property_p = NULL; gchar const * value_p = NULL; if( css_parent != NULL ) { + gchar const * property_p = NULL; for ( List iter_p = css_parent->attributeList() ; iter_p ; ++iter_p ) { property_p = g_quark_to_string(iter_p->key); -- cgit v1.2.3 From dd957026bd798ebe34eff033b4a839d63b790b04 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sun, 4 Aug 2013 16:27:59 +0200 Subject: cppcheck (bzr r12467) --- src/attribute-rel-util.cpp | 55 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 28 deletions(-) (limited to 'src/attribute-rel-util.cpp') diff --git a/src/attribute-rel-util.cpp b/src/attribute-rel-util.cpp index 0527dad4e..933339632 100644 --- a/src/attribute-rel-util.cpp +++ b/src/attribute-rel-util.cpp @@ -198,23 +198,22 @@ void sp_attribute_clean_style(Node* repr, SPCSSAttr *css, unsigned int flags) { // Check if a property is applicable to an element (i.e. is font-family useful for a ?). if( !SPAttributeRelCSS::findIfValid( property, element ) ) { - if( flags & SP_ATTR_CLEAN_STYLE_WARN ) { - g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" is inappropriate.", - element.c_str(), id.c_str(), property ); - } - if( flags & SP_ATTR_CLEAN_STYLE_REMOVE ) { - toDelete.insert(property); - } - continue; + if( flags & SP_ATTR_CLEAN_STYLE_WARN ) { + g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" is inappropriate.", + element.c_str(), id.c_str(), property ); + } + if( flags & SP_ATTR_CLEAN_STYLE_REMOVE ) { + toDelete.insert(property); + } + continue; } // Find parent value for same property (property) gchar const * value_p = NULL; if( css_parent != NULL ) { - gchar const * property_p = NULL; for ( List iter_p = css_parent->attributeList() ; iter_p ; ++iter_p ) { - property_p = g_quark_to_string(iter_p->key); + gchar const * property_p = g_quark_to_string(iter_p->key); if( !g_strcmp0( property, property_p ) ) { value_p = iter_p->value; @@ -226,29 +225,29 @@ void sp_attribute_clean_style(Node* repr, SPCSSAttr *css, unsigned int flags) { // If parent has same property value and property is inherited, mark for deletion. if ( !g_strcmp0( value, value_p ) && SPAttributeRelCSS::findIfInherit( property ) ) { - if ( flags & SP_ATTR_CLEAN_DEFAULT_WARN ) { - g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" has same value as parent (%s).", - element.c_str(), id.c_str(), property, value ); - } - if ( flags & SP_ATTR_CLEAN_DEFAULT_REMOVE ) { - toDelete.insert( property ); - } - continue; + if ( flags & SP_ATTR_CLEAN_DEFAULT_WARN ) { + g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" has same value as parent (%s).", + element.c_str(), id.c_str(), property, value ); + } + if ( flags & SP_ATTR_CLEAN_DEFAULT_REMOVE ) { + toDelete.insert( property ); + } + continue; } // If property value is same as default and the parent value not set or property is not inherited, // mark for deletion. if ( SPAttributeRelCSS::findIfDefault( property, value ) && - ( (css_parent != NULL && value_p == NULL) || !SPAttributeRelCSS::findIfInherit( property ) ) ) { - - if ( flags & SP_ATTR_CLEAN_DEFAULT_WARN ) { - g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" with default value (%s) not needed.", - element.c_str(), id.c_str(), property, value ); - } - if ( flags & SP_ATTR_CLEAN_DEFAULT_REMOVE ) { - toDelete.insert( property ); - } - continue; + ( (css_parent != NULL && value_p == NULL) || !SPAttributeRelCSS::findIfInherit( property ) ) ) { + + if ( flags & SP_ATTR_CLEAN_DEFAULT_WARN ) { + g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" with default value (%s) not needed.", + element.c_str(), id.c_str(), property, value ); + } + if ( flags & SP_ATTR_CLEAN_DEFAULT_REMOVE ) { + toDelete.insert( property ); + } + continue; } } // End loop over style properties -- cgit v1.2.3 From 451210ce988fb6e6964bd4869f74ffa7fb2c462d Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 15 Aug 2013 21:13:44 +0200 Subject: Prevent writing out empty style strings. (bzr r12481) --- src/attribute-rel-util.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/attribute-rel-util.cpp') diff --git a/src/attribute-rel-util.cpp b/src/attribute-rel-util.cpp index 933339632..15c71daa7 100644 --- a/src/attribute-rel-util.cpp +++ b/src/attribute-rel-util.cpp @@ -141,7 +141,11 @@ void sp_attribute_clean_style(Node *repr, unsigned int flags) { // sp_repr_css_set( repr, css, "style"); // Don't use as it will cause loop. Glib::ustring value; sp_repr_css_write_string(css, value); - repr->setAttribute("style", value.c_str()); + if( value.empty() ) { + repr->setAttribute("style", NULL ); + } else { + repr->setAttribute("style", value.c_str()); + } sp_repr_css_attr_unref( css ); } -- cgit v1.2.3