[DEV] update new xml interface

This commit is contained in:
Edouard DUPIN 2015-01-14 20:01:05 +01:00
parent 738ee25fb8
commit d61f0b9607
21 changed files with 52 additions and 54 deletions

View File

@ -20,8 +20,8 @@ esvg::Base::Base(PaintState _parentPaintState) {
m_paint = _parentPaintState; m_paint = _parentPaintState;
} }
void esvg::Base::parseTransform(exml::Element* _element) { void esvg::Base::parseTransform(const std::shared_ptr<exml::Element>& _element) {
if (NULL == _element) { if (_element == nullptr) {
return; return;
} }
std::string inputString = _element->getAttribute("transform"); std::string inputString = _element->getAttribute("transform");
@ -85,11 +85,11 @@ void esvg::Base::parseTransform(exml::Element* _element) {
* @param[out] _pos parsed position * @param[out] _pos parsed position
* @param[out] _size parsed dimention * @param[out] _size parsed dimention
*/ */
void esvg::Base::parsePosition(const exml::Element *_element, etk::Vector2D<float> &_pos, etk::Vector2D<float> &_size) { void esvg::Base::parsePosition(const std::shared_ptr<const exml::Element>& _element, etk::Vector2D<float> &_pos, etk::Vector2D<float> &_size) {
_pos.setValue(0,0); _pos.setValue(0,0);
_size.setValue(0,0); _size.setValue(0,0);
if (NULL == _element) { if (_element == nullptr) {
return; return;
} }
std::string content = _element->getAttribute("x"); std::string content = _element->getAttribute("x");
@ -194,8 +194,8 @@ int32_t extractPartOfStyle(const std::string& _data, std::string& _outputType, s
* @brief parse a Painting attribute of a specific node * @brief parse a Painting attribute of a specific node
* @param[in] _element Basic node of the XML that might be parsed * @param[in] _element Basic node of the XML that might be parsed
*/ */
void esvg::Base::parsePaintAttr(const exml::Element *_element) { void esvg::Base::parsePaintAttr(const std::shared_ptr<const exml::Element>& _element) {
if (_element == NULL) { if (_element == nullptr) {
return; return;
} }
bool fillNone = false; bool fillNone = false;
@ -389,7 +389,7 @@ draw::Color esvg::Base::parseColor(const std::string& _inputData) {
* @param[in] _element standart XML node * @param[in] _element standart XML node
* @return true if no problem arrived * @return true if no problem arrived
*/ */
bool esvg::Base::parse(exml::Element* _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) { bool esvg::Base::parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) {
SVG_ERROR("NOT IMPLEMENTED"); SVG_ERROR("NOT IMPLEMENTED");
_sizeMax.setValue(0,0); _sizeMax.setValue(0,0);
return false; return false;

View File

@ -38,15 +38,15 @@ namespace esvg {
Base() {}; Base() {};
Base(PaintState _parentPaintState); Base(PaintState _parentPaintState);
virtual ~Base() { }; virtual ~Base() { };
virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax); virtual bool parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax);
//specific drawing for AAG librairy ... //specific drawing for AAG librairy ...
virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans) { }; virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans) { };
virtual void display(int32_t _spacing) { }; virtual void display(int32_t _spacing) { };
void parseTransform(exml::Element *_element); void parseTransform(const std::shared_ptr<exml::Element>& _element);
void parsePosition(const exml::Element *_element, etk::Vector2D<float> &_pos, etk::Vector2D<float> &_size); void parsePosition(const std::shared_ptr<const exml::Element>& _element, etk::Vector2D<float> &_pos, etk::Vector2D<float> &_size);
float parseLength(const std::string& _dataInput); float parseLength(const std::string& _dataInput);
void parsePaintAttr(const exml::Element *_element); void parsePaintAttr(const std::shared_ptr<const exml::Element>& _element);
draw::Color parseColor(const std::string& _inputData); draw::Color parseColor(const std::string& _inputData);
}; };
}; };

View File

@ -22,10 +22,10 @@ esvg::Circle::~Circle() {
} }
bool esvg::Circle::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) { bool esvg::Circle::parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) {
m_radius = 0.0; m_radius = 0.0;
m_position.setValue(0,0); m_position.setValue(0,0);
if (NULL == _element) { if (_element == nullptr) {
return false; return false;
} }
parseTransform(_element); parseTransform(_element);

View File

@ -19,7 +19,7 @@ namespace esvg {
public: public:
Circle(PaintState _parentPaintState); Circle(PaintState _parentPaintState);
~Circle(); ~Circle();
virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax); virtual bool parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax);
virtual void display(int32_t _spacing); virtual void display(int32_t _spacing);
virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans);
}; };

View File

@ -22,8 +22,8 @@ esvg::Ellipse::~Ellipse() {
} }
bool esvg::Ellipse::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) { bool esvg::Ellipse::parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) {
if (NULL == _element) { if (_element == nullptr) {
return false; return false;
} }
parseTransform(_element); parseTransform(_element);

View File

@ -19,7 +19,7 @@ namespace esvg {
public: public:
Ellipse(PaintState _parentPaintState); Ellipse(PaintState _parentPaintState);
~Ellipse(); ~Ellipse();
virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax); virtual bool parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax);
virtual void display(int32_t _spacing); virtual void display(int32_t _spacing);
virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans);
}; };

View File

@ -31,8 +31,8 @@ esvg::Group::~Group() {
} }
bool esvg::Group::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) { bool esvg::Group::parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) {
if (NULL == _element) { if (_element == nullptr) {
return false; return false;
} }
// parse ... // parse ...
@ -52,12 +52,12 @@ bool esvg::Group::parse(exml::Element * _element, agg::trans_affine& _parentTran
vec2 tmpPos(0,0); vec2 tmpPos(0,0);
// parse all sub node : // parse all sub node :
for(int32_t iii=0; iii<_element->size() ; iii++) { for(int32_t iii=0; iii<_element->size() ; iii++) {
exml::Element* child = _element->getElement(iii); std::shared_ptr<exml::Element> child = _element->getElement(iii);
if (NULL == child) { if (child == nullptr) {
// can be a comment ... // can be a comment ...
continue; continue;
} }
esvg::Base *elementParser = NULL; esvg::Base *elementParser = nullptr;
if (child->getValue() == "g") { if (child->getValue() == "g") {
elementParser = new esvg::Group(m_paint); elementParser = new esvg::Group(m_paint);
} else if (child->getValue() == "a") { } else if (child->getValue() == "a") {
@ -81,13 +81,13 @@ bool esvg::Group::parse(exml::Element * _element, agg::trans_affine& _parentTran
} else { } else {
SVG_ERROR("(l "<<child->getPos()<<") node not suported : \""<<child->getValue()<<"\" must be [g,a,path,rect,circle,ellipse,line,polyline,polygon,text]"); SVG_ERROR("(l "<<child->getPos()<<") node not suported : \""<<child->getValue()<<"\" must be [g,a,path,rect,circle,ellipse,line,polyline,polygon,text]");
} }
if (NULL == elementParser) { if (elementParser == nullptr) {
SVG_ERROR("(l "<<child->getPos()<<") error on node: \""<<child->getValue()<<"\" allocation error or not supported ..."); SVG_ERROR("(l "<<child->getPos()<<") error on node: \""<<child->getValue()<<"\" allocation error or not supported ...");
} else { } else {
if (false == elementParser->parse(child, m_transformMatrix, tmpPos)) { if (false == elementParser->parse(child, m_transformMatrix, tmpPos)) {
SVG_ERROR("(l "<<child->getPos()<<") error on node: \""<<child->getValue()<<"\" Sub Parsing ERROR"); SVG_ERROR("(l "<<child->getPos()<<") error on node: \""<<child->getValue()<<"\" Sub Parsing ERROR");
delete(elementParser); delete(elementParser);
elementParser = NULL; elementParser = nullptr;
} else { } else {
_sizeMax.setValue(std::max(_sizeMax.x(), tmpPos.x()), _sizeMax.setValue(std::max(_sizeMax.x(), tmpPos.x()),
std::max(_sizeMax.y(), tmpPos.y())); std::max(_sizeMax.y(), tmpPos.y()));

View File

@ -19,7 +19,7 @@ namespace esvg {
public: public:
Group(PaintState _parentPaintState); Group(PaintState _parentPaintState);
~Group(); ~Group();
virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax); virtual bool parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax);
virtual void display(int32_t spacing); virtual void display(int32_t spacing);
virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans);
}; };

View File

@ -23,10 +23,10 @@ esvg::Line::~Line() {
} }
bool esvg::Line::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) { bool esvg::Line::parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) {
// line must have a minimum size... // line must have a minimum size...
m_paint.strokeWidth = 1; m_paint.strokeWidth = 1;
if (NULL == _element) { if (_element == nullptr) {
return false; return false;
} }
parseTransform(_element); parseTransform(_element);

View File

@ -19,7 +19,7 @@ namespace esvg {
public: public:
Line(PaintState _parentPaintState); Line(PaintState _parentPaintState);
~Line(); ~Line();
virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax); virtual bool parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax);
virtual void display(int32_t _spacing); virtual void display(int32_t _spacing);
virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans);
}; };

View File

@ -29,17 +29,17 @@ esvg::Path::~Path() {
// return the next char position ... (after 'X' or NULL) // return the next char position ... (after 'X' or NULL)
const char * extractCmd(const char* _input, char& _cmd, std::vector<float>& _outputList) { const char * extractCmd(const char* _input, char& _cmd, std::vector<float>& _outputList) {
if (*_input == '\0') { if (*_input == '\0') {
return NULL; return nullptr;
} }
_outputList.clear(); _outputList.clear();
_cmd = '\0'; _cmd = '\0';
const char * outputPointer = NULL; const char * outputPointer = nullptr;
if (!( ( _input[0] <= 'Z' if (!( ( _input[0] <= 'Z'
&& _input[0] >= 'A') && _input[0] >= 'A')
|| ( _input[0] <= 'z' || ( _input[0] <= 'z'
&& _input[0] >= 'a') ) ) { && _input[0] >= 'a') ) ) {
SVG_ERROR("Error in the SVG Path : \"" << _input << "\""); SVG_ERROR("Error in the SVG Path : \"" << _input << "\"");
return NULL; return nullptr;
} }
_cmd = _input[0]; _cmd = _input[0];
SVG_VERBOSE("Find command : " << _cmd); SVG_VERBOSE("Find command : " << _cmd);
@ -65,8 +65,8 @@ const char * extractCmd(const char* _input, char& _cmd, std::vector<float>& _out
return outputPointer; return outputPointer;
} }
bool esvg::Path::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) { bool esvg::Path::parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) {
if (NULL == _element) { if (_element == nullptr) {
return false; return false;
} }
parseTransform(_element); parseTransform(_element);
@ -89,7 +89,7 @@ bool esvg::Path::parse(exml::Element * _element, agg::trans_affine& _parentTrans
const char* elementXML = elementXML1.c_str(); const char* elementXML = elementXML1.c_str();
for( const char *sss=extractCmd(elementXML, command, listDot); for( const char *sss=extractCmd(elementXML, command, listDot);
NULL != sss; sss != nullptr;
sss=extractCmd(sss, command, listDot) ) { sss=extractCmd(sss, command, listDot) ) {
PathBasic pathElement; PathBasic pathElement;
switch(command) { switch(command) {

View File

@ -42,7 +42,7 @@ namespace esvg {
public: public:
Path(PaintState _parentPaintState); Path(PaintState _parentPaintState);
~Path(); ~Path();
virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax); virtual bool parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax);
virtual void display(int32_t _spacing); virtual void display(int32_t _spacing);
virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans);
private: private:

View File

@ -22,8 +22,8 @@ esvg::Polygon::~Polygon() {
} }
bool esvg::Polygon::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) { bool esvg::Polygon::parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) {
if (NULL == _element) { if (_element == nullptr) {
return false; return false;
} }
parseTransform(_element); parseTransform(_element);

View File

@ -26,7 +26,7 @@ namespace esvg {
public: public:
Polygon(PaintState parentPaintState); Polygon(PaintState parentPaintState);
~Polygon(); ~Polygon();
virtual bool parse(exml::Element * _element, agg::trans_affine& parentTrans, etk::Vector2D<float>& sizeMax); virtual bool parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& parentTrans, etk::Vector2D<float>& sizeMax);
virtual void display(int32_t spacing); virtual void display(int32_t spacing);
virtual void aggDraw(esvg::Renderer& myRenderer, agg::trans_affine& basicTrans); virtual void aggDraw(esvg::Renderer& myRenderer, agg::trans_affine& basicTrans);
}; };

View File

@ -19,10 +19,10 @@ esvg::Polyline::~Polyline() {
} }
bool esvg::Polyline::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) { bool esvg::Polyline::parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) {
// line must have a minimum size... // line must have a minimum size...
m_paint.strokeWidth = 1; m_paint.strokeWidth = 1;
if (NULL == _element) { if (_element == nullptr) {
return false; return false;
} }
parseTransform(_element); parseTransform(_element);

View File

@ -19,7 +19,7 @@ namespace esvg {
public: public:
Polyline(PaintState _parentPaintState); Polyline(PaintState _parentPaintState);
~Polyline(); ~Polyline();
virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax); virtual bool parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax);
virtual void display(int32_t _spacing); virtual void display(int32_t _spacing);
virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans);
}; };

View File

@ -25,8 +25,8 @@ esvg::Rectangle::~Rectangle() {
} }
bool esvg::Rectangle::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) { bool esvg::Rectangle::parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) {
if (NULL == _element) { if (_element == nullptr) {
return false; return false;
} }
m_position.setValue(0,0); m_position.setValue(0,0);

View File

@ -20,7 +20,7 @@ namespace esvg {
public: public:
Rectangle(PaintState _parentPaintState); Rectangle(PaintState _parentPaintState);
~Rectangle(); ~Rectangle();
virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax); virtual bool parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax);
virtual void display(int32_t _spacing); virtual void display(int32_t _spacing);
virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans); virtual void aggDraw(esvg::Renderer& _myRenderer, agg::trans_affine& _basicTrans);
}; };

View File

@ -20,7 +20,7 @@ esvg::Text::~Text() {
} }
bool esvg::Text::parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) { bool esvg::Text::parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax) {
_sizeMax.setValue(0,0); _sizeMax.setValue(0,0);
SVG_ERROR("NOT IMPLEMENTED"); SVG_ERROR("NOT IMPLEMENTED");
return false; return false;

View File

@ -16,7 +16,7 @@ namespace esvg {
public: public:
Text(PaintState _parentPaintState); Text(PaintState _parentPaintState);
~Text(); ~Text();
virtual bool parse(exml::Element * _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax); virtual bool parse(const std::shared_ptr<exml::Element>& _element, agg::trans_affine& _parentTrans, etk::Vector2D<float>& _sizeMax);
virtual void display(int32_t _spacing); virtual void display(int32_t _spacing);
}; };
}; };

View File

@ -36,7 +36,7 @@
esvg::Document::Document(const std::string& _fileName) : esvg::Document::Document(const std::string& _fileName) :
m_renderedElement(NULL) { m_renderedElement(nullptr) {
m_fileName = _fileName; m_fileName = _fileName;
m_version = "0.0"; m_version = "0.0";
m_loadOK = true; m_loadOK = true;
@ -56,15 +56,13 @@ esvg::Document::Document(const std::string& _fileName) :
m_loadOK = false; m_loadOK = false;
return; return;
} }
if (0 == doc.size() ) { if (0 == doc.size() ) {
SVG_ERROR("(l ?) No nodes in the xml file ... \"" << m_fileName << "\""); SVG_ERROR("(l ?) No nodes in the xml file ... \"" << m_fileName << "\"");
m_loadOK = false; m_loadOK = false;
return; return;
} }
std::shared_ptr<exml::Element> root = doc.getNamed("svg" );
exml::Element* root = (exml::Element*)doc.getNamed("svg" ); if (root == nullptr) {
if (NULL == root ) {
SVG_ERROR("(l ?) main node not find: \"svg\" in \"" << m_fileName << "\""); SVG_ERROR("(l ?) main node not find: \"svg\" in \"" << m_fileName << "\"");
m_loadOK = false; m_loadOK = false;
return; return;
@ -81,12 +79,12 @@ esvg::Document::Document(const std::string& _fileName) :
vec2 size(0,0); vec2 size(0,0);
// parse all sub node : // parse all sub node :
for(int32_t iii=0; iii< root->size(); iii++) { for(int32_t iii=0; iii< root->size(); iii++) {
exml::Element* child = root->getElement(iii); std::shared_ptr<exml::Element> child = root->getElement(iii);
if (child == NULL) { if (child == nullptr) {
// comment trsh here... // comment trsh here...
continue; continue;
} }
esvg::Base *elementParser = NULL; esvg::Base *elementParser = nullptr;
if (child->getValue() == "g") { if (child->getValue() == "g") {
elementParser = new esvg::Group(m_paint); elementParser = new esvg::Group(m_paint);
} else if (child->getValue() == "a") { } else if (child->getValue() == "a") {