summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2016-09-20 11:18:06 +0000
committertavmjong-free <tavmjong@free.fr>2016-09-20 11:18:06 +0000
commitd48547bafeeaf93e805fac07208a457ef8162a2a (patch)
treede92a4d70b6f71f309d6a9a5bb8aa1702299f0f1 /src
parentUpdate CSS tables (font-variants, etc.). (diff)
downloadinkscape-d48547bafeeaf93e805fac07208a457ef8162a2a.tar.gz
inkscape-d48547bafeeaf93e805fac07208a457ef8162a2a.zip
Add new function that removes properties with default values from SPCSSAttr.
(bzr r15122)
Diffstat (limited to 'src')
-rw-r--r--src/attribute-rel-util.cpp36
-rw-r--r--src/attribute-rel-util.h5
2 files changed, 41 insertions, 0 deletions
diff --git a/src/attribute-rel-util.cpp b/src/attribute-rel-util.cpp
index cf1140219..5e770d4ae 100644
--- a/src/attribute-rel-util.cpp
+++ b/src/attribute-rel-util.cpp
@@ -263,6 +263,42 @@ void sp_attribute_clean_style(Node* repr, SPCSSAttr *css, unsigned int flags) {
}
/**
+ * Remove CSS style properties with default values.
+ */
+void sp_attribute_purge_default_style(SPCSSAttr *css, unsigned int flags) {
+
+ g_return_if_fail (css != NULL);
+
+ // Loop over all properties in "style" node, keeping track of which to delete.
+ std::set<Glib::ustring> toDelete;
+ for ( List<AttributeRecord const> iter = css->attributeList() ; iter ; ++iter ) {
+
+ gchar const * property = g_quark_to_string(iter->key);
+ gchar const * value = iter->value;
+
+ // If property value is same as default mark for deletion.
+ if ( SPAttributeRelCSS::findIfDefault( property, value ) ) {
+
+ if ( flags & SP_ATTR_CLEAN_DEFAULT_WARN ) {
+ g_warning( "Preferences CSS Style property: \"%s\" with default value (%s) not needed.",
+ property, value );
+ }
+ if ( flags & SP_ATTR_CLEAN_DEFAULT_REMOVE ) {
+ toDelete.insert( property );
+ }
+ continue;
+ }
+
+ } // End loop over style properties
+
+ // Delete unneeded style properties. Do this at the end so as to not perturb List iterator.
+ for( std::set<Glib::ustring>::const_iterator iter_d = toDelete.begin(); iter_d != toDelete.end(); ++iter_d ) {
+ sp_repr_css_set_property( css, (*iter_d).c_str(), NULL );
+ }
+
+}
+
+/**
* Check one attribute on an element
*/
bool sp_attribute_check_attribute(Glib::ustring element, Glib::ustring id, Glib::ustring attribute, bool warn) {
diff --git a/src/attribute-rel-util.h b/src/attribute-rel-util.h
index 604987779..b8b1f6875 100644
--- a/src/attribute-rel-util.h
+++ b/src/attribute-rel-util.h
@@ -68,6 +68,11 @@ Glib::ustring sp_attribute_clean_style(Node *repr, gchar const *string, unsigned
void sp_attribute_clean_style(Node* repr, SPCSSAttr *css, unsigned int flags);
/**
+ * Remove CSS style properties with default values.
+ */
+void sp_attribute_purge_default_style(SPCSSAttr *css, unsigned int flags);
+
+/**
* Check one attribute on an element
*/
bool sp_attribute_check_attribute(Glib::ustring element, Glib::ustring id, Glib::ustring attribute, bool warn);