2
* attribute-rel-css.cpp
4
* Created on: Jul 25, 2011
8
/** \class SPAttributeRelCSS
10
* SPAttributeRelCSS class stores the mapping of element->style_properties
11
* relationship and provides a static function to access that
12
* mapping indirectly(only reading).
24
#include "attribute-rel-css.h"
26
#include "path-prefix.h"
27
#include "preferences.h"
29
SPAttributeRelCSS * SPAttributeRelCSS::instance = NULL;
32
* This function checks whether an element -> CSS property pair
35
bool SPAttributeRelCSS::findIfValid(Glib::ustring property, Glib::ustring element)
37
if (SPAttributeRelCSS::instance == NULL) {
38
SPAttributeRelCSS::instance = new SPAttributeRelCSS();
41
// Strip of "svg:" from the element's name
42
Glib::ustring temp = element;
43
if ( temp.find("svg:") != std::string::npos ) {
44
temp.erase( temp.find("svg:"), 4 );
47
// Don't check for properties with -, role, aria etc. to allow for more accessbility
48
// FixMe: Name space list should be created when file read in.
49
if (property[0] == '-'
50
|| property.substr(0,4) == "role"
51
|| property.substr(0,4) == "aria"
52
|| property.substr(0,5) == "xmlns"
53
|| property.substr(0,8) == "inkscape:"
54
|| property.substr(0,9) == "sodipodi:"
55
|| property.substr(0,4) == "rdf:"
56
|| property.substr(0,3) == "cc:"
57
|| (SPAttributeRelCSS::instance->propertiesOfElements[temp].find(property)
58
!= SPAttributeRelCSS::instance->propertiesOfElements[temp].end()) ) {
61
//g_warning( "Invalid attribute: %s used on <%s>", property.c_str(), element.c_str() );
67
* This function checks whether an CSS property -> default value
68
* pair is allowed or not
70
bool SPAttributeRelCSS::findIfDefault(Glib::ustring property, Glib::ustring value)
72
if (SPAttributeRelCSS::instance == NULL) {
73
SPAttributeRelCSS::instance = new SPAttributeRelCSS();
76
if( instance->defaultValuesOfProps[property] == value) {
84
* Check if property can be inherited.
86
bool SPAttributeRelCSS::findIfInherit(Glib::ustring property)
88
if (SPAttributeRelCSS::instance == NULL) {
89
SPAttributeRelCSS::instance = new SPAttributeRelCSS();
92
return instance->inheritProps[property];
96
* Check if attribute is a property.
98
bool SPAttributeRelCSS::findIfProperty(Glib::ustring property)
100
if (SPAttributeRelCSS::instance == NULL) {
101
SPAttributeRelCSS::instance = new SPAttributeRelCSS();
104
return ( instance->defaultValuesOfProps.find( property )
105
!= instance->defaultValuesOfProps.end() );
108
SPAttributeRelCSS::SPAttributeRelCSS()
110
// Read data from standard path
111
std::string filepath = INKSCAPE_ATTRRELDIR;
112
filepath += "/cssprops";
114
// Try and load data from filepath
115
if (!readDataFromFileIn(filepath, SPAttributeRelCSS::prop_element_pair)) {
116
// Set default preference for CSS property checking to ignore
117
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
118
prefs->setInt("/options/svgoutput/incorrect_style_properties", 3);
121
// Read data from standard path
122
filepath = INKSCAPE_ATTRRELDIR;
123
filepath += "/css_defaults";
125
// Try and load data from filepath
126
if (!readDataFromFileIn(filepath, SPAttributeRelCSS::prop_defValue_pair)) {
127
// Set default preference for CSS defaults checking to ignore
128
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
129
prefs->setInt("/options/svgoutput/style_defaults", 3);
133
bool SPAttributeRelCSS::readDataFromFileIn(Glib::ustring fileName, storageType type)
136
file.open(fileName.c_str(), std::ios::in);
138
if (!file.is_open()) {
139
// Display warning for file not open
140
g_warning("Could not open the data file for CSS attribute-element map construction: %s", fileName.c_str());
145
while (!file.eof()) {
146
std::stringstream ss;
149
std::getline(file,s,'"');
150
std::getline(file,s,'"');
151
if (s.size() > 0 && s[0] != '\n') {
152
std::string prop = s;
156
// Load data to structure that holds element -> set of CSS props
157
if (type == SPAttributeRelCSS::prop_element_pair) {
158
while (std::getline(ss,s,'"')) {
160
std::getline(ss,s,'"');
162
propertiesOfElements[element].insert(prop);
164
// Load data to structure that holds CSS prop -> default value
165
} else if (type == SPAttributeRelCSS::prop_defValue_pair) {
167
std::getline(ss,s,'"');
168
std::getline(ss,s,'"');
170
defaultValuesOfProps[prop] = value;
171
std::getline(ss,s,'"');
172
std::getline(ss,s,'"');
173
gboolean inherit = false;
174
if ( s.find( "yes" ) != std::string::npos ) {
177
inheritProps[prop] = inherit;
189
c-file-style:"stroustrup"
190
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
195
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :