summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--makefile2
-rw-r--r--svgtiny.c27
-rw-r--r--svgtiny.h3
-rw-r--r--svgtiny_test.c6
4 files changed, 26 insertions, 12 deletions
diff --git a/makefile b/makefile
index ef3d27c..c4ca3f6 100644
--- a/makefile
+++ b/makefile
@@ -29,7 +29,7 @@ svgtiny_test$(EXEEXT): svgtiny_test.c libsvgtiny.a
$(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=$@ $<
diff --git a/svgtiny.c b/svgtiny.c
index 21a23b8..ad2e8a5 100644
--- a/svgtiny.c
+++ b/svgtiny.c
@@ -75,8 +75,6 @@ struct svgtiny_diagram *svgtiny_create(void)
if (!diagram)
return 0;
- diagram->doc = 0;
- diagram->svg = 0;
diagram->shape = 0;
diagram->shape_count = 0;
@@ -102,7 +100,6 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram,
XML_PARSE_DTDVALID /* needed for xmlGetID to work */);
if (!document)
return svgtiny_LIBXML_ERROR;
- diagram->doc = document;
/*xmlDebugDumpDocument(stderr, document);*/
@@ -112,12 +109,11 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram,
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);
@@ -138,7 +134,11 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram,
state.stroke = svgtiny_TRANSPARENT;
state.stroke_width = 1;
- return svgtiny_parse_svg(svg, state);
+ svgtiny_parse_svg(svg, state);
+
+ xmlFreeDoc(document);
+
+ return svgtiny_OK;
}
@@ -1072,3 +1072,18 @@ void svgtiny_transform_path(float *p, unsigned int n,
}
}
+
+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);
+}
+
diff --git a/svgtiny.h b/svgtiny.h
index a5017d1..534da2d 100644
--- a/svgtiny.h
+++ b/svgtiny.h
@@ -25,9 +25,6 @@ struct svgtiny_shape {
};
struct svgtiny_diagram {
- xmlDoc *doc;
- xmlNode *svg;
-
int width, height;
struct svgtiny_shape *shape;
diff --git a/svgtiny_test.c b/svgtiny_test.c
index 9bb7e2e..8d485d3 100644
--- a/svgtiny_test.c
+++ b/svgtiny_test.c
@@ -40,8 +40,6 @@ int main(int argc, char *argv[])
}
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",
@@ -69,6 +67,8 @@ int main(int argc, char *argv[])
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++) {
@@ -126,6 +126,8 @@ int main(int argc, char *argv[])
printf("\n");
}
+ svgtiny_free(diagram);
+
return 0;
}