$(CC) $(CFLAGS) $(LIBS) -o $@ $^
clean:
- -rm *.o libsvgtiny.a svgtiny_test$(EXEEXT)
+ -rm *.o libsvgtiny.a svgtiny_test$(EXEEXT) colors.c
colors.c: colors.gperf
gperf --output-file=$@ $<
if (!diagram)
return 0;
- diagram->doc = 0;
- diagram->svg = 0;
diagram->shape = 0;
diagram->shape_count = 0;
XML_PARSE_DTDVALID /* needed for xmlGetID to work */);
if (!document)
return svgtiny_LIBXML_ERROR;
- diagram->doc = document;
/*xmlDebugDumpDocument(stderr, document);*/
return svgtiny_NOT_SVG;
if (strcmp((const char *) svg->name, "svg") != 0)
return svgtiny_NOT_SVG;
- diagram->svg = svg;
/* get graphic dimensions */
float x, y, width, height;
state.diagram = diagram;
- state.document = diagram->doc;
+ state.document = document;
state.viewport_width = viewport_width;
state.viewport_height = viewport_height;
svgtiny_parse_position_attributes(svg, state, &x, &y, &width, &height);
state.stroke = svgtiny_TRANSPARENT;
state.stroke_width = 1;
- return svgtiny_parse_svg(svg, state);
+ svgtiny_parse_svg(svg, state);
+
+ xmlFreeDoc(document);
+
+ return svgtiny_OK;
}
}
}
+
+void svgtiny_free(struct svgtiny_diagram *svg)
+{
+ assert(svg);
+
+ for (unsigned int i = 0; i != svg->shape_count; i++) {
+ free(svg->shape[i].path);
+ free(svg->shape[i].text);
+ }
+
+ free(svg->shape);
+
+ free(svg);
+}
+
}
size = sb.st_size;
- fprintf(stderr, "size: %lld bytes\n", (long long) size);
-
buffer = malloc(size);
if (!buffer) {
fprintf(stderr, "Unable to allocate %lld bytes\n",
if (code != svgtiny_OK)
fprintf(stderr, "svgtiny_parse failed: %i\n", code);
+ free(buffer);
+
printf("viewbox 0 0 %i %i\n", diagram->width, diagram->height);
for (unsigned int i = 0; i != diagram->shape_count; i++) {
printf("\n");
}
+ svgtiny_free(diagram);
+
return 0;
}