Beispiel #1
0
void esvg::Document::generateAnImage(int32_t _sizeX, int32_t _sizeY)
{
	int32_t sizeX = _sizeX;
	if (sizeX == 0) {
		SVG_ERROR("SizeX == 0 ==> set 64");
		sizeX = 64;
	}
	int32_t sizeY = _sizeY;
	if (sizeY == 0) {
		SVG_ERROR("SizeY == 0 ==> set 64");
		sizeY = 64;
	}
	SVG_INFO("Generate size (" << sizeX << "," << sizeY << ")");
	if(NULL != m_renderedElement) {
		delete(m_renderedElement);
		m_renderedElement = NULL;
	}
	
	m_renderedElement = new esvg::Renderer(sizeX, sizeY);
	// create the first element matrix modification ...
	agg::trans_affine basicTrans;
	//basicTrans *= agg::trans_affine_translation(-g_base_dx, -g_base_dy);
	basicTrans *= agg::trans_affine_scaling(sizeX/m_size.x(), sizeY/m_size.y());
	//basicTrans *= agg::trans_affine_rotation(g_angle);// + agg::pi);
	//basicTrans *= agg::trans_affine_skewing(2.0, 5.0);
	//basicTrans *= agg::trans_affine_translation(width*0.3, height/2);
	//basicTrans *= agg::trans_affine_translation(width/3, height/3);
	
	aggDraw(*m_renderedElement, basicTrans);
	/*
	std::string tmpFileOut = "zzz_out_test.ppm";
	m_renderedElement->WritePpm(tmpFileOut);
	*/
}
Beispiel #2
0
esvg::Renderer::Renderer(uint32_t width, uint32_t height) {
	m_allocatedSize = 0;
	m_size.setValue(width, height);
	
	int32_t dataSize = ((int32_t)width * (int32_t)height * DATA_ALLOCATION_ELEMENT);
	m_allocatedSize = dataSize;
	
	// allocate Data
	SVG_VERBOSE("Allocate buffer : " << dataSize);
	
	m_buffer = new uint8_t[dataSize];
	if (NULL == m_buffer) {
		SVG_ERROR("Allocation of the output buffer for SVG drawing error");
		m_allocatedSize = 0;
		return;
	}
	
	memset(m_buffer, 0x00, dataSize * sizeof(uint8_t) );

	m_renderingBuffer = new agg::rendering_buffer(m_buffer, m_size.x(), m_size.y(), m_size.x() * DATA_ALLOCATION_ELEMENT);
	if (NULL == m_renderingBuffer) {
		SVG_ERROR("Allocation of the m_renderingBuffer for SVG drawing error");
		return;
	}
	
	m_pixFrame        = new agg::pixfmt_rgba32(*m_renderingBuffer);
	if (NULL == m_pixFrame) {
		SVG_ERROR("Allocation of the m_pixFrame for SVG drawing error");
		return;
	}
	
	m_renderBase      = new rendererBase_t(*m_pixFrame);
	if (NULL == m_renderBase) {
		SVG_ERROR("Allocation of the m_renderBase for SVG drawing error");
		return;
	}
	
	m_renderArea      = new rendererSolid_t(*m_renderBase);
	if (NULL == m_renderArea) {
		SVG_ERROR("Allocation of the m_renderArea for SVG drawing error");
		return;
	}
	
	//m_basicMatrix *= agg::trans_affine_translation(-g_base_dx2, -g_base_dy2);
	//m_basicMatrix *= agg::trans_affine_scaling(g_scale*coefmult, g_scale*coefmult);
	//m_basicMatrix *= agg::trans_affine_rotation(g_angle);// + agg::pi);
	//m_basicMatrix *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0);
	//m_basicMatrix *= agg::trans_affine_translation(m_size.x*0.7, m_size.y/2);
}
Beispiel #3
0
svg_status_t
_svg_group_drop_element (svg_group_t *group, svg_element_t *element) {
	int k;
	if(group->element == NULL) {
		SVG_ERROR("group %p has a NULL pointer for an element buffer. num_elements is %d\n",
			  group, group->num_elements);
		exit(0);
	}
	
	SVG_DEBUG(" will scan for %p in %d number of elements....\n", element, group->num_elements);
	for(k = 0; k < group->num_elements; k++) {
		SVG_DEBUG("   compare: %p == %p ?\n", group->element[k], element);
		
		if(group->element[k] == element) {
			SVG_DEBUG("   matched! will dereference %p\n", element);
			_svg_element_dereference(element);

			element->parent = NULL;
			
			group->num_elements--;

			for(; k < group->num_elements; k++) {
				group->element[k] =
					group->element[k + 1];
			}
			group->element[k] = NULL;

			return SVG_STATUS_SUCCESS;
		}
	}
	return SVG_STATUS_NO_SUCH_ELEMENT;
}
Beispiel #4
0
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();
}