X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fsvgtiny.c;h=f6319305c3d2f1c76504766879b9ef55a9e219ea;hb=545123c6ec9a3d3903e713c1c2919762417538dd;hp=3b886fe770502d384e17cf7ffb8e5b4e075a693b;hpb=b95ec8cedeffd1f1050c92bb934751811fa3c6df;p=libsvgtiny.git diff --git a/src/svgtiny.c b/src/svgtiny.c index 3b886fe..f631930 100644 --- a/src/svgtiny.c +++ b/src/svgtiny.c @@ -40,6 +40,12 @@ #define degToRad(angleInDegrees) ((angleInDegrees) * M_PI / 180.0) #define radToDeg(angleInRadians) ((angleInRadians) * 180.0 / M_PI) +static svgtiny_code svgtiny_parse_style_element(dom_element *style, + struct svgtiny_parse_state state); +static css_stylesheet *svgtiny_parse_style_inline(const uint8_t *data, + size_t len); +static svgtiny_code svgtiny_preparse_styles(dom_element *svg, + struct svgtiny_parse_state state); static svgtiny_code svgtiny_parse_svg(dom_element *svg, struct svgtiny_parse_state state); static svgtiny_code svgtiny_parse_path(dom_element *path, @@ -719,6 +725,19 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram, #include "svgtiny_strings.h" #undef SVGTINY_STRING_ACTION2 + /* Intern SVG's xmlns separately because it's an lwc_string + * and not a dom_string. We initialize its pointer to NULL + * because the "cleanup:" test to see if it needs to be free'd + * looks for NULL. Returning a LIBDOM_ERROR on failure is not + * perfect but it's the closest of the available options. */ + state.interned_svg_xmlns = NULL; + if (lwc_intern_string("http://www.w3.org/2000/svg", + 26, + &state.interned_svg_xmlns) != lwc_error_ok) { + code = svgtiny_LIBDOM_ERROR; + goto cleanup; + } + svgtiny_parse_position_attributes(svg, state, &x, &y, &width, &height); diagram->width = width; diagram->height = height; @@ -737,7 +756,10 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram, state.stroke_width = 1; /* parse tree */ - code = svgtiny_parse_svg(svg, state); + code = svgtiny_preparse_styles(svg, state); + if (code == svgtiny_OK) { + code = svgtiny_parse_svg(svg, state); + } dom_node_unref(svg); dom_node_unref(document); @@ -753,10 +775,181 @@ cleanup: dom_string_unref(state.interned_##s); #include "svgtiny_strings.h" #undef SVGTINY_STRING_ACTION2 + + if (state.interned_svg_xmlns != NULL) { + lwc_string_unref(state.interned_svg_xmlns); + } + return code; } +/** + * Parse a single