[DEV] Add parsing of Id of elements

This commit is contained in:
Edouard DUPIN 2015-12-03 22:36:13 +01:00
parent 7bf04979a7
commit 0a5749bd3a
3 changed files with 58 additions and 33 deletions

View File

@ -109,13 +109,6 @@ void esvg::Base::parseTransform(const std::shared_ptr<exml::Element>& _element)
} }
} }
/**
* @brief parse x, y, width, height attribute of the xml node
* @param[in] _element XML node
* @param[out] _pos parsed position
* @param[out] _size parsed dimention
*/
void esvg::Base::parsePosition(const std::shared_ptr<const exml::Element>& _element, vec2 &_pos, vec2 &_size) { void esvg::Base::parsePosition(const std::shared_ptr<const exml::Element>& _element, vec2 &_pos, vec2 &_size) {
_pos.setValue(0,0); _pos.setValue(0,0);
_size.setValue(0,0); _size.setValue(0,0);
@ -141,12 +134,6 @@ void esvg::Base::parsePosition(const std::shared_ptr<const exml::Element>& _elem
} }
} }
/**
* @brief parse a lenght of the xml element
* @param[in] _dataInput Data C String with the printed lenght
* @return standart number of pixels
*/
float esvg::Base::parseLength(const std::string& _dataInput) { float esvg::Base::parseLength(const std::string& _dataInput) {
SVG_VERBOSE(" lenght : '" << _dataInput << "'"); SVG_VERBOSE(" lenght : '" << _dataInput << "'");
float n = stof(_dataInput); float n = stof(_dataInput);
@ -229,10 +216,6 @@ int32_t extractPartOfStyle(const std::string& _data, std::string& _outputType, s
return -1; return -1;
} }
/**
* @brief parse a Painting attribute of a specific node
* @param[in] _element Basic node of the XML that might be parsed
*/
void esvg::Base::parsePaintAttr(const std::shared_ptr<const exml::Element>& _element) { void esvg::Base::parsePaintAttr(const std::shared_ptr<const exml::Element>& _element) {
if (_element == nullptr) { if (_element == nullptr) {
return; return;
@ -240,6 +223,8 @@ void esvg::Base::parsePaintAttr(const std::shared_ptr<const exml::Element>& _ele
bool fillNone = false; bool fillNone = false;
bool strokeNone = false; bool strokeNone = false;
std::string content; std::string content;
// ---------------- get unique ID ----------------
m_id = _element->getAttribute("id");
// ---------------- stroke ---------------- // ---------------- stroke ----------------
content = _element->getAttribute("stroke"); content = _element->getAttribute("stroke");
if (content.size()!=0) { if (content.size()!=0) {
@ -422,11 +407,6 @@ void esvg::Base::parsePaintAttr(const std::shared_ptr<const exml::Element>& _ele
} }
} }
/**
* @brief parse a color specification from the svg file
* @param[in] _inputData Data C String with the xml definition
* @return the parsed color
*/
etk::Color<uint8_t,4> esvg::Base::parseColor(const std::string& _inputData) { etk::Color<uint8_t,4> esvg::Base::parseColor(const std::string& _inputData) {
etk::Color<uint8_t,4> localColor = etk::color::white; etk::Color<uint8_t,4> localColor = etk::color::white;
@ -446,15 +426,11 @@ etk::Color<uint8_t,4> esvg::Base::parseColor(const std::string& _inputData) {
return localColor; return localColor;
} }
/**
* @brief parse all the element needed in the basic node
* @param[in] _element standart XML node
* @return true if no problem arrived
*/
bool esvg::Base::parseXML(const std::shared_ptr<exml::Element>& _element, mat2& _parentTrans, vec2& _sizeMax) { bool esvg::Base::parseXML(const std::shared_ptr<exml::Element>& _element, mat2& _parentTrans, vec2& _sizeMax) {
SVG_ERROR("NOT IMPLEMENTED"); // TODO : UNDERSTAND why nothing is done here ...
_sizeMax.setValue(0,0); // Parse basic elements (ID...):
m_id = _element->getAttribute("id");
_sizeMax = vec2(0.0f, 0.0f);
return false; return false;
} }
@ -469,4 +445,16 @@ const char * esvg::Base::spacingDist(int32_t _spacing) {
void esvg::Base::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) { void esvg::Base::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) {
SVG_WARNING(spacingDist(_level) << "DRAW esvg::Base ... ==> No drawing availlable"); SVG_WARNING(spacingDist(_level) << "DRAW esvg::Base ... ==> No drawing availlable");
} }
const std::string& getId() const {
return m_id;
}
void setId(const std::string& _newId) {
// TODO : Check if it is UNIQUE ...
m_id = _newId;
}

View File

@ -67,16 +67,54 @@ namespace esvg {
Base() {}; Base() {};
Base(PaintState _parentPaintState); Base(PaintState _parentPaintState);
virtual ~Base() { }; virtual ~Base() { };
/**
* @brief parse all the element needed in the basic node
* @param[in] _element standart XML node
* @return true if no problem arrived
*/
virtual bool parseXML(const std::shared_ptr<exml::Element>& _element, mat2& _parentTrans, vec2& _sizeMax); virtual bool parseXML(const std::shared_ptr<exml::Element>& _element, mat2& _parentTrans, vec2& _sizeMax);
virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level=1); virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level=1);
virtual void display(int32_t _spacing) { }; virtual void display(int32_t _spacing) { };
void parseTransform(const std::shared_ptr<exml::Element>& _element); void parseTransform(const std::shared_ptr<exml::Element>& _element);
/**
* @brief parse x, y, width, height attribute of the xml node
* @param[in] _element XML node
* @param[out] _pos parsed position
* @param[out] _size parsed dimention
*/
void parsePosition(const std::shared_ptr<const exml::Element>& _element, vec2 &_pos, vec2 &_size); void parsePosition(const std::shared_ptr<const exml::Element>& _element, vec2 &_pos, vec2 &_size);
/**
* @brief parse a lenght of the xml element
* @param[in] _dataInput Data C String with the printed lenght
* @return standart number of pixels
*/
float parseLength(const std::string& _dataInput); float parseLength(const std::string& _dataInput);
/**
* @brief parse a Painting attribute of a specific node
* @param[in] _element Basic node of the XML that might be parsed
*/
void parsePaintAttr(const std::shared_ptr<const exml::Element>& _element); void parsePaintAttr(const std::shared_ptr<const exml::Element>& _element);
/**
* @brief parse a color specification from the svg file
* @param[in] _inputData Data C String with the xml definition
* @return the parsed color
*/
etk::Color<uint8_t,4> parseColor(const std::string& _inputData); etk::Color<uint8_t,4> parseColor(const std::string& _inputData);
protected:
std::string m_id; //!< unique ID of the element.
public:
/**
* @brief Get the ID of the Element
* @return UniqueId in the svg file
*/
const std::string& getId() const;
/**
* @brief Set the ID of the Element
* @param[in] _newId New Id of the element
*/
void setId(const std::string& _newId);
}; };
}; };

View File

@ -243,8 +243,7 @@ bool esvg::Document::parseXMLData(const std::shared_ptr<exml::Element>& _root) {
} else if (child->getValue() == "text") { } else if (child->getValue() == "text") {
elementParser = new esvg::Text(m_paint); elementParser = new esvg::Text(m_paint);
} else if (child->getValue() == "defs") { } else if (child->getValue() == "defs") {
// Node ignore : must implement it later ... SVG_TODO("Need to parse Reference ==> big modification ...");
continue;
} else if (child->getValue() == "sodipodi:namedview") { } else if (child->getValue() == "sodipodi:namedview") {
// Node ignore : generaly inkscape data // Node ignore : generaly inkscape data
continue; continue;