/** * @author Edouard DUPIN * * @copyright 2011, Edouard DUPIN, all right reserved * * @license APACHE v2.0 (see license file) */ #include #include #include #include #include #include #include #include #include #include #include #include #include #undef __class__ #define __class__ "Group" esvg::Group::Group(PaintState _parentPaintState) : esvg::Base(_parentPaintState) { } esvg::Group::~Group() { } bool esvg::Group::parseXML(const std::shared_ptr& _element, mat2& _parentTrans, vec2& _sizeMax) { if (_element == nullptr) { return false; } // parse ... vec2 pos(0,0); vec2 size(0,0); parseTransform(_element); parsePosition(_element, pos, size); parsePaintAttr(_element); ESVG_VERBOSE("parsed G1. trans : " << m_transformMatrix); // add the property of the parrent modifications ... m_transformMatrix *= _parentTrans; ESVG_VERBOSE("parsed G2. trans : " << m_transformMatrix); _sizeMax.setValue(0,0); vec2 tmpPos(0,0); // parse all sub node : for(int32_t iii=0; iii<_element->size() ; iii++) { std::shared_ptr child = _element->getElement(iii); if (child == nullptr) { // can be a comment ... continue; } std::shared_ptr elementParser; if (child->getValue() == "g") { elementParser = std::make_shared(m_paint); } else if (child->getValue() == "a") { // TODO ... } else if (child->getValue() == "path") { elementParser = std::make_shared(m_paint); } else if (child->getValue() == "rect") { elementParser = std::make_shared(m_paint); } else if (child->getValue() == "circle") { elementParser = std::make_shared(m_paint); } else if (child->getValue() == "ellipse") { elementParser = std::make_shared(m_paint); } else if (child->getValue() == "line") { elementParser = std::make_shared(m_paint); } else if (child->getValue() == "polyline") { elementParser = std::make_shared(m_paint); } else if (child->getValue() == "polygon") { elementParser = std::make_shared(m_paint); } else if (child->getValue() == "text") { elementParser = std::make_shared(m_paint); } else { ESVG_ERROR("(l "<getPos()<<") node not suported : \""<getValue()<<"\" must be [g,a,path,rect,circle,ellipse,line,polyline,polygon,text]"); } if (elementParser == nullptr) { ESVG_ERROR("(l "<getPos()<<") error on node: \""<getValue()<<"\" allocation error or not supported ..."); continue; } if (elementParser->parseXML(child, m_transformMatrix, tmpPos) == false) { ESVG_ERROR("(l "<getPos()<<") error on node: \""<getValue()<<"\" Sub Parsing ERROR"); elementParser.reset(); continue; } _sizeMax.setValue(std::max(_sizeMax.x(), tmpPos.x()), std::max(_sizeMax.y(), tmpPos.y())); // add element in the system m_subElementList.push_back(elementParser); } return true; } void esvg::Group::display(int32_t _spacing) { ESVG_DEBUG(spacingDist(_spacing) << "Group (START) fill=" << m_paint.fill.first << "/" << m_paint.fill.second << " stroke=" << m_paint.stroke.first << "/" << m_paint.stroke.second << " stroke-width=" << m_paint.strokeWidth ); for (size_t iii=0; iiidisplay(_spacing+1); } } ESVG_DEBUG(spacingDist(_spacing) << "Group (STOP)"); } void esvg::Group::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) { ESVG_VERBOSE(spacingDist(_level) << "DRAW esvg::group"); for (size_t iii=0; iiidraw(_myRenderer, _basicTrans, _level+1); } } }