コード例 #1
0
ファイル: Rectangle.cpp プロジェクト: atria-soft/esvg
bool esvg::Rectangle::parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) {
	if (_element.exist() == false) {
		return false;
	}
	m_position.setValue(0.0f, 0.0f);
	m_size.setValue(0.0f, 0.0f);
	m_roundedCorner.setValue(0.0f, 0.0f);
	
	parseTransform(_element);
	parsePaintAttr(_element);
	
	// add the property of the parrent modifications ...
	m_transformMatrix *= _parentTrans;
	
	parsePosition(_element, m_position, m_size);
	
	std::string content = _element.attributes["rx"];
	if (content.size()!=0) {
		m_roundedCorner.setX(parseLength(content));
	}
	content = _element.attributes["ry"];
	if (content.size()!=0) {
		m_roundedCorner.setY(parseLength(content));
	}
	_sizeMax.setValue(m_position.x() + m_size.x() + m_paint.strokeWidth,
	                  m_position.y() + m_size.y() + m_paint.strokeWidth);
	return true;
}
コード例 #2
0
ファイル: Polyline.cpp プロジェクト: atria-soft/esvg
bool esvg::Polyline::parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) {
	// line must have a minimum size...
	m_paint.strokeWidth = 1;
	if (_element.exist() == false) {
		return false;
	}
	parseTransform(_element);
	parsePaintAttr(_element);
	
	// add the property of the parrent modifications ...
	m_transformMatrix *= _parentTrans;
	
	std::string sss1 = _element.attributes["points"];
	if (sss1.size() == 0) {
		ESVG_ERROR("(l "<<_element.getPos()<<") polyline: missing points attribute");
		return false;
	}
	_sizeMax.setValue(0,0);
	ESVG_VERBOSE("Parse polyline : \"" << sss1 << "\"");
	const char* sss = sss1.c_str();
	while ('\0' != sss[0]) {
		vec2 pos;
		int32_t n;
		if (sscanf(sss, "%f,%f %n", &pos.m_floats[0], &pos.m_floats[1], &n) == 2) {
			m_listPoint.push_back(pos);
			_sizeMax.setValue(std::max(_sizeMax.x(), pos.x()),
			                  std::max(_sizeMax.y(), pos.y()));
			sss += n;
		} else {
			break;
		}
	}
	return true;
}
コード例 #3
0
ファイル: esvg.cpp プロジェクト: chagge/esvg
esvg::Document::Document(const std::string& _fileName) :
  m_renderedElement(nullptr) {
	m_fileName = _fileName;
	m_version = "0.0";
	m_loadOK = true;
	m_paint.fill = (int32_t)0xFF0000FF;
	m_paint.stroke = (int32_t)0xFFFFFF00;
	
	m_paint.strokeWidth = 1.0;
	m_paint.viewPort.setValue(255,255);
	m_paint.flagEvenOdd = false;
	m_paint.lineJoin = esvg::lineJoinMiter;
	m_paint.lineCap = esvg::lineCapButt;
	m_size.setValue(0,0);
	
	exml::Document doc;
	if (false == doc.load(m_fileName)) {
		SVG_ERROR("Error occured when loading XML : " << m_fileName);
		m_loadOK = false;
		return;
	}
	if (0 == doc.size() ) {
		SVG_ERROR("(l ?) No nodes in the xml file ... \"" << m_fileName << "\"");
		m_loadOK = false;
		return;
	}
	std::shared_ptr<exml::Element> root = doc.getNamed("svg" );
	if (root == nullptr) {
		SVG_ERROR("(l ?) main node not find: \"svg\" in \"" << m_fileName << "\"");
		m_loadOK = false;
		return;
	}
	// get the svg version :
	m_version = root->getAttribute("version");
	// parse ...
	vec2 pos(0,0);
	parseTransform(root);
	parsePosition(root, pos, m_size);
	parsePaintAttr(root);
	SVG_VERBOSE("parsed .ROOT trans : (" << m_transformMatrix.sx << "," << m_transformMatrix.shy << "," << m_transformMatrix.shx << "," << m_transformMatrix.sy << "," << m_transformMatrix.tx << "," << m_transformMatrix.ty << ")");
	vec2 maxSize(0,0);
	vec2 size(0,0);
	// parse all sub node :
	for(int32_t iii=0; iii< root->size(); iii++) {
		std::shared_ptr<exml::Element> child = root->getElement(iii);
		if (child == nullptr) {
			// comment trsh here...
			continue;
		}
		esvg::Base *elementParser = nullptr;
		if (child->getValue() == "g") {
			elementParser = new esvg::Group(m_paint);
		} else if (child->getValue() == "a") {
			SVG_INFO("Note : 'a' balise is parsed like a g balise ...");
			elementParser = new esvg::Group(m_paint);
		} else if (child->getValue() == "title") {
			m_title = "TODO : set the title here ...";
			continue;
		} else if (child->getValue() == "path") {
			elementParser = new esvg::Path(m_paint);
		} else if (child->getValue() == "rect") {
			elementParser = new esvg::Rectangle(m_paint);
		} else if (child->getValue() == "circle") {
			elementParser = new esvg::Circle(m_paint);
		} else if (child->getValue() == "ellipse") {
			elementParser = new esvg::Ellipse(m_paint);
		} else if (child->getValue() == "line") {
			elementParser = new esvg::Line(m_paint);
		} else if (child->getValue() == "polyline") {
			elementParser = new esvg::Polyline(m_paint);
		} else if (child->getValue() == "polygon") {
			elementParser = new esvg::Polygon(m_paint);
		} else if (child->getValue() == "text") {
			elementParser = new esvg::Text(m_paint);
		} else if (child->getValue() == "defs") {
			// Node ignore : must implement it later ...
			continue;
		} else if (child->getValue() == "sodipodi:namedview") {
			// Node ignore : generaly inkscape data
			continue;
		} else if (child->getValue() == "metadata") {
			// Node ignore : generaly inkscape data
			continue;
		} else {
			SVG_ERROR("(l "<<child->getPos()<<") node not suported : \""<<child->getValue()<<"\" must be [title,g,a,path,rect,circle,ellipse,line,polyline,polygon,text,metadata]");
		}
		if (NULL == elementParser) {
			SVG_ERROR("(l "<<child->getPos()<<") error on node: \""<<child->getValue()<<"\" allocation error or not supported ...");
			continue;
		}
		if (false == elementParser->parse(child, m_transformMatrix, size)) {
			SVG_ERROR("(l "<<child->getPos()<<") error on node: \""<<child->getValue()<<"\" Sub Parsing ERROR");
			delete(elementParser);
			elementParser = NULL;
			continue;
		}
		if (maxSize.x()<size.x()) {
			maxSize.setX(size.x());
		}
		if (maxSize.y()<size.y()) {
			maxSize.setY(size.y());
		}
		// add element in the system
		m_subElementList.push_back(elementParser);
	}
	if (m_size.x() == 0 || m_size.y()==0) {
		m_size.setValue((int32_t)maxSize.x(), (int32_t)maxSize.y());
	} else {
		m_size.setValue((int32_t)m_size.x(), (int32_t)m_size.y());
	}
	//DisplayDebug();
}