diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2011-11-29 11:27:10 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2011-11-29 11:27:10 +0000 |
| commit | 771029025214cffd0bc9783656c29e08ad208743 (patch) | |
| tree | f8571540680f4aa0138798f87222263df20c278a /src/attribute-rel-svg.cpp | |
| parent | preferences read out: when no unit is specified, assume it is in the requeste... (diff) | |
| download | inkscape-771029025214cffd0bc9783656c29e08ad208743.tar.gz inkscape-771029025214cffd0bc9783656c29e08ad208743.zip | |
Add possibility to check validity of attributes and usefulness of properties.
This code adds the ability to check for every elment in an SVG document if its
attributes are valid and the styling properties are useful. Options under the
SVG Output section of the Inkscape Preferences dialog control what should
be checked when, and what actions should be taken if invalid attributes
or non-useful properties are found.
(bzr r10753)
Diffstat (limited to 'src/attribute-rel-svg.cpp')
| -rw-r--r-- | src/attribute-rel-svg.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/attribute-rel-svg.cpp b/src/attribute-rel-svg.cpp new file mode 100644 index 000000000..3f5ce9395 --- /dev/null +++ b/src/attribute-rel-svg.cpp @@ -0,0 +1,120 @@ +/* + * attribute-rel-svg.cpp + * + * Created on: Jul 25, 2011 + * Author: abhishek + */ + +/** \class SPAttributeRelSVG + * + * SPAttributeRelSVG class stores the mapping of element->attribute + * relationship and provides a static function to access that + * mapping indirectly(only reading). + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <fstream> +#include <sstream> +#include <string> + +#include "attribute-rel-svg.h" + +#include "path-prefix.h" +#include "preferences.h" + +SPAttributeRelSVG * SPAttributeRelSVG::instance = NULL; + +/* + * This functions checks whether an element -> attribute pair is allowed or not + */ +bool SPAttributeRelSVG::findIfValid(Glib::ustring attribute, Glib::ustring element) +{ + if (SPAttributeRelSVG::instance == NULL) { + SPAttributeRelSVG::instance = new SPAttributeRelSVG(); + } + + // Strip of "svg:" from the element's name + Glib::ustring temp = element; + if ( temp.find("svg:") != std::string::npos ) { + temp.erase( temp.find("svg:"), 4 ); + } + + // Check for attributes with -, role, aria etc. to allow for more accessbility + if (attribute[0] == '-' + || attribute.substr(0,4) == "role" + || attribute.substr(0,4) == "aria" + || attribute.substr(0,5) == "xmlns" + || attribute.substr(0,9) == "inkscape:" + || attribute.substr(0,9) == "sodipodi:" + || attribute.substr(0,4) == "rdf:" + || attribute.substr(0,3) == "cc:" + || (SPAttributeRelSVG::instance->attributesOfElements[temp].find(attribute) + != SPAttributeRelSVG::instance->attributesOfElements[temp].end()) ) { + return true; + } else { + //g_warning( "Invalid attribute: %s used on <%s>", attribute.c_str(), element.c_str() ); + return false; + } +} + +/* + * One timer singleton constructor, to load the element -> attributes data + * into memory. + */ +SPAttributeRelSVG::SPAttributeRelSVG() +{ + std::fstream f; + + // Read data from standard path + std::string filepath = INKSCAPE_ATTRRELDIR; + filepath += "/svgprops"; + + f.open(filepath.c_str(), std::ios::in); + + if (!f.is_open()) { + // Set the default preference of attribute checking to ignore + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setInt("/options/svgoutput/incorrect_attributes", 3); + + // Display warning for file not open + g_warning("Could not open the data file for XML attribute-element map construction: %s", filepath.c_str()); + f.close(); + return ; + } + + while (!f.eof()){ + std::stringstream ss; + std::string s; + + std::getline(f,s,'"'); + std::getline(f,s,'"'); + if(s.size() > 0 && s[0] != '\n'){ + std::string prop = s; + getline(f,s); + ss << s; + + while(std::getline(ss,s,'"')){ + std::string element; + std::getline(ss,s,'"'); + element = s; + attributesOfElements[element].insert(prop); + } + } + } + + f.close(); +} + +/* + 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 : |
