X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fsvgtiny.c;h=0bcfe7daf94412c899f04b082062680553e67549;hb=15d5208a999e91c0f1edf511fd9c2b4a726aa537;hp=18884a11f45012ab3ca2940971b2da829d736691;hpb=4f6c3034252830b3f4c0a03cbb03a661fdb1d8e8;p=libsvgtiny.git diff --git a/src/svgtiny.c b/src/svgtiny.c index 18884a1..0bcfe7d 100644 --- a/src/svgtiny.c +++ b/src/svgtiny.c @@ -42,12 +42,12 @@ static svgtiny_code svgtiny_parse_poly(dom_element *poly, struct svgtiny_parse_state state, bool polygon); static svgtiny_code svgtiny_parse_text(dom_element *text, struct svgtiny_parse_state state); -static void svgtiny_parse_position_attributes(const dom_element *node, +static void svgtiny_parse_position_attributes(dom_element *node, const struct svgtiny_parse_state state, float *x, float *y, float *width, float *height); -static void svgtiny_parse_paint_attributes(const dom_element *node, +static void svgtiny_parse_paint_attributes(dom_element *node, struct svgtiny_parse_state *state); -static void svgtiny_parse_font_attributes(const dom_element *node, +static void svgtiny_parse_font_attributes(dom_element *node, struct svgtiny_parse_state *state); static void svgtiny_parse_transform_attributes(dom_element *node, struct svgtiny_parse_state *state); @@ -205,10 +205,18 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram, dom_node_unref(document); cleanup: + if (state.gradient_x1 != NULL) + dom_string_unref(state.gradient_x1); + if (state.gradient_x2 != NULL) + dom_string_unref(state.gradient_x2); + if (state.gradient_y1 != NULL) + dom_string_unref(state.gradient_y1); + if (state.gradient_y2 != NULL) + dom_string_unref(state.gradient_y2); #define SVGTINY_STRING_ACTION2(s,n) \ if (state.interned_##s != NULL) \ dom_string_unref(state.interned_##s); -//#include "svgtiny_strings.h" +#include "svgtiny_strings.h" #undef SVGTINY_STRING_ACTION2 return code; } @@ -238,7 +246,7 @@ svgtiny_code svgtiny_parse_svg(dom_element *svg, if (view_box) { char *s = strndup(dom_string_data(view_box), - dom_string_length(view_box)); + dom_string_byte_length(view_box)); float min_x, min_y, vwidth, vheight; if (sscanf(s, "%f,%f,%f,%f", &min_x, &min_y, &vwidth, &vheight) == 4 || @@ -255,7 +263,7 @@ svgtiny_code svgtiny_parse_svg(dom_element *svg, svgtiny_parse_transform_attributes(svg, &state); - exc = dom_node_get_first_child(svg, &child); + exc = dom_node_get_first_child(svg, (dom_node **) (void *) &child); if (exc != DOM_NO_ERR) { return svgtiny_LIBDOM_ERROR; } @@ -315,7 +323,8 @@ svgtiny_code svgtiny_parse_svg(dom_element *svg, dom_node_unref(child); return code; } - exc = dom_node_get_next_sibling(child, &next); + exc = dom_node_get_next_sibling(child, + (dom_node **) (void *) &next); dom_node_unref(child); if (exc != DOM_NO_ERR) { return svgtiny_LIBDOM_ERROR; @@ -364,7 +373,7 @@ svgtiny_code svgtiny_parse_path(dom_element *path, } s = path_d = strndup(dom_string_data(path_d_str), - dom_string_length(path_d_str)); + dom_string_byte_length(path_d_str)); dom_string_unref(path_d_str); if (s == NULL) { return svgtiny_OUT_OF_MEMORY; @@ -895,7 +904,7 @@ svgtiny_code svgtiny_parse_poly(dom_element *poly, } s = points = strndup(dom_string_data(points_str), - dom_string_length(points_str)); + dom_string_byte_length(points_str)); dom_string_unref(points_str); /* read points attribute */ if (s == NULL) @@ -999,9 +1008,13 @@ svgtiny_code svgtiny_parse_text(dom_element *text, dom_node_unref(child); return svgtiny_LIBDOM_ERROR; } - shape->text = strndup(dom_string_data(content), - dom_string_length(content)); - dom_string_unref(content); + if (content != NULL) { + shape->text = strndup(dom_string_data(content), + dom_string_byte_length(content)); + dom_string_unref(content); + } else { + shape->text = strdup(""); + } shape->text_x = px; shape->text_y = py; state.diagram->shape_count++; @@ -1026,7 +1039,7 @@ svgtiny_code svgtiny_parse_text(dom_element *text, * Parse x, y, width, and height attributes, if present. */ -void svgtiny_parse_position_attributes(const dom_element *node, +void svgtiny_parse_position_attributes(dom_element *node, const struct svgtiny_parse_state state, float *x, float *y, float *width, float *height) { @@ -1108,7 +1121,7 @@ static float _svgtiny_parse_length(const char *s, int viewport_size, float svgtiny_parse_length(dom_string *s, int viewport_size, const struct svgtiny_parse_state state) { - char *ss = strndup(dom_string_data(s), dom_string_length(s)); + char *ss = strndup(dom_string_data(s), dom_string_byte_length(s)); float ret = _svgtiny_parse_length(ss, viewport_size, state); free(ss); return ret; @@ -1118,7 +1131,7 @@ float svgtiny_parse_length(dom_string *s, int viewport_size, * Parse paint attributes, if present. */ -void svgtiny_parse_paint_attributes(const dom_element *node, +void svgtiny_parse_paint_attributes(dom_element *node, struct svgtiny_parse_state *state) { dom_string *attr; @@ -1146,7 +1159,7 @@ void svgtiny_parse_paint_attributes(const dom_element *node, exc = dom_element_get_attribute(node, state->interned_style, &attr); if (exc == DOM_NO_ERR && attr != NULL) { char *style = strndup(dom_string_data(attr), - dom_string_length(attr)); + dom_string_byte_length(attr)); const char *s; char *value; if ((s = strstr(style, "fill:"))) { @@ -1246,7 +1259,7 @@ static void _svgtiny_parse_color(const char *s, svgtiny_colour *c, void svgtiny_parse_color(dom_string *s, svgtiny_colour *c, struct svgtiny_parse_state *state) { - char *ss = strndup(dom_string_data(s), dom_string_length(s)); + char *ss = strndup(dom_string_data(s), dom_string_byte_length(s)); _svgtiny_parse_color(ss, c, state); free(ss); } @@ -1255,7 +1268,7 @@ void svgtiny_parse_color(dom_string *s, svgtiny_colour *c, * Parse font attributes, if present. */ -void svgtiny_parse_font_attributes(const dom_element *node, +void svgtiny_parse_font_attributes(dom_element *node, struct svgtiny_parse_state *state) { /* TODO: Implement this, it never used to be */ @@ -1298,7 +1311,7 @@ void svgtiny_parse_transform_attributes(dom_element *node, &attr); if (exc == DOM_NO_ERR && attr != NULL) { transform = strndup(dom_string_data(attr), - dom_string_length(attr)); + dom_string_byte_length(attr)); svgtiny_parse_transform(transform, &state->ctm.a, &state->ctm.b, &state->ctm.c, &state->ctm.d, &state->ctm.e, &state->ctm.f);