Exemple #1
0
void ofxSVG::load(string path){
	path = ofToDataPath(path);

	if(path.compare("") == 0){
		ofLogError("ofxSVG") << "load(): path does not exist: \"" << path << "\"";
		return;
	}

	ofBuffer buffer = ofBufferFromFile(path);
	size_t size = buffer.size();

	struct svgtiny_diagram * diagram = svgtiny_create();
	svgtiny_code code = svgtiny_parse(diagram, buffer.getText().c_str(), size, path.c_str(), 0, 0);

	if(code != svgtiny_OK){
		string msg;
		switch(code){
		 case svgtiny_OUT_OF_MEMORY:
			 msg = "svgtiny_OUT_OF_MEMORY";
			 break;

		 case svgtiny_LIBXML_ERROR:
			 msg = "svgtiny_LIBXML_ERROR";
			 break;

		 case svgtiny_NOT_SVG:
			 msg = "svgtiny_NOT_SVG";
			 break;

		 case svgtiny_SVG_ERROR:
			 msg = "svgtiny_SVG_ERROR: line " + ofToString(diagram->error_line) + ": " + diagram->error_message;
			 break;

		 default:
			 msg = "unknown svgtiny_code " + ofToString(code);
			 break;
		}
		ofLogError("ofxSVG") << "load(): couldn't parse \"" << path << "\": " << msg;
	}

	setupDiagram(diagram);

	svgtiny_free(diagram);
}
Exemple #2
0
//--------------------------------------------------------------
void Svg::loadData(string aFormat, string aData){

	string dummy = "smth";

	// string xml = "<svg><path fill=\"#FF00FF\" stroke=\"#00FF00\" stroke-width=\"0.172\" d=\"" + aData + "\"/></svg>";
	string xml = "<svg><path " + aFormat + " d=\"" + aData + "\"/></svg>";
	// string xml = "<svg><path " + aFormat + " stroke-width=\"1\" d=\"" + aData + "\"/></svg>";

	// struct svgtiny_diagram * diagram = svgtiny_create();
	auto diagram = svgtiny_create();

	auto code = svgtiny_parse(diagram, xml.c_str(), xml.size(), dummy.c_str(), 0, 0);

	if (code == svgtiny_OK){

		setupDiagram(diagram);

		svgtiny_free(diagram);

		// ofLogVerbose() << "loaded";
	}
}
Exemple #3
0
static void svg_reformat(struct content *c, int width, int height)
{
	svg_content *svg = (svg_content *) c;
	const char *source_data;
	unsigned long source_size;

	assert(svg->diagram);

	/* Avoid reformats to same width/height as we already reformatted to */
	if (width != svg->current_width || height != svg->current_height) {
		source_data = content__get_source_data(c, &source_size);

		svgtiny_parse(svg->diagram, source_data, source_size,
				nsurl_access(content_get_url(c)),
				width, height);

		svg->current_width = width;
		svg->current_height = height;
	}

	c->width = svg->diagram->width;
	c->height = svg->diagram->height;
}