attribute-rel-util.cpp revision 2b0e2e6c2dde5d6cb739785016e91189888ff483
/*
*
* Created on: Sep 8, 2011
* Author: tavmjong
*/
/**
* Utility functions for cleaning SVG tree of unneeded attributes and style properties.
*/
#include <fstream>
#include <sstream>
#include <string>
#include <iostream>
#include "preferences.h"
#include "xml/attribute-record.h"
#include "attribute-rel-css.h"
#include "attribute-rel-svg.h"
#include "attribute-rel-util.h"
/**
* Get preferences
*/
unsigned int sp_attribute_clean_get_prefs() {
unsigned int flags = 0;
if( prefs->getBool("/options/svgoutput/incorrect_attributes_warn") ) flags += SP_ATTR_CLEAN_ATTR_WARN;
if( prefs->getBool("/options/svgoutput/incorrect_attributes_remove") ) flags += SP_ATTR_CLEAN_ATTR_REMOVE;
if( prefs->getBool("/options/svgoutput/incorrect_style_properties_warn") ) flags += SP_ATTR_CLEAN_STYLE_WARN;
if( prefs->getBool("/options/svgoutput/incorrect_style_properties_remove" ) ) flags += SP_ATTR_CLEAN_STYLE_REMOVE;
if( prefs->getBool("/options/svgoutput/style_defaults_remove") ) flags += SP_ATTR_CLEAN_DEFAULT_REMOVE;
return flags;
}
/**
* Remove or warn about inappropriate attributes and useless stype properties.
* repr: the root node in a document or any other node.
*/
unsigned int flags = sp_attribute_clean_get_prefs();
if( flags ) {
}
}
/**
* Clean recursively over all elements.
*/
// Only clean elements in svg namespace
}
}
}
}
/**
* Clean attributes on an element
*/
// Clean style: this attribute is unique in that normally we want to change it and not simply
// delete it.
// Clean attributes
//Glib::ustring value = (const char*)iter->value;
bool is_useful = sp_attribute_check_attribute( element, id, attribute, flags & SP_ATTR_CLEAN_ATTR_WARN );
}
}
// Do actual deleting (done after so as not to perturb List iterator).
}
}
/**
* Clean CSS style on an element.
*/
// Find element's style
// 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.
}
/**
* Clean CSS style on an element.
*/
return string_cleaned;
}
/**
* Clean CSS style on an element.
*
* 1. Is a style property appropriate on the given element?
* e.g, font-size is useless on <svg:rect>
* 2. Is the value of the style property useful?
* Is it the same as the parent and it inherits?
* Is it the default value (and the property on the parent is not set or does not inherit)?
*/
// Find parent's style, including properties that are inherited.
// Note, a node may not have a parent if it has not yet been added to tree.
// Loop over all properties in "style" node, keeping track of which to delete.
// Check if a property is applicable to an element (i.e. is font-family useful for a <rect>?).
if( flags & SP_ATTR_CLEAN_STYLE_WARN ) {
g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" is inappropriate.",
}
if( flags & SP_ATTR_CLEAN_STYLE_REMOVE ) {
}
continue;
}
// Find parent value for same property (property)
if( css_parent != NULL ) {
break;
}
}
}
// If parent has same property value and property is inherited, mark for deletion.
if ( flags & SP_ATTR_CLEAN_DEFAULT_WARN ) {
g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" has same value as parent (%s).",
}
if ( flags & SP_ATTR_CLEAN_DEFAULT_REMOVE ) {
}
continue;
}
// If property value is same as default and the parent value not set or property is not inherited,
// mark for deletion.
if ( flags & SP_ATTR_CLEAN_DEFAULT_WARN ) {
g_warning( "<%s id=\"%s\">: CSS Style property: \"%s\" with default value (%s) not needed.",
}
if ( flags & SP_ATTR_CLEAN_DEFAULT_REMOVE ) {
}
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 ) {
}
}
/**
* Check one attribute on an element
*/
bool sp_attribute_check_attribute(Glib::ustring element, Glib::ustring id, Glib::ustring attribute, bool warn) {
bool is_useful = true;
// First check if it is a presentation attribute. Presentation attributes can be applied to
// any element. At the moment, we are only going to check if it is a possibly useful
// attribute. Note, we don't explicitely check against the list of elements where presentation
// attributes are allowed (See SVG1.1 spec, Appendix M.2).
// Non-useful presentation attribute on SVG <element>
if( warn ) {
g_warning( "<%s id=\"%s\">: Non-useful presentation attribute: \"%s\" found.",
}
is_useful = false;
}
} else {
// Second check if it is a valid attribute
// Invalid attribute on SVG <element>
if( warn ) {
g_warning( "<%s id=\"%s\">: Invalid attribute: \"%s\" found.",
}
is_useful = false;
}
}
return is_useful;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :