From: Michael Orlitzky Date: Wed, 4 Oct 2023 04:11:11 +0000 (-0400) Subject: src/svgtiny.c: initialize the libcss context in svgtiny_parse() X-Git-Url: http://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=b95ec8cedeffd1f1050c92bb934751811fa3c6df;p=libsvgtiny.git src/svgtiny.c: initialize the libcss context in svgtiny_parse() Before we begin parsing, we have to initialize our new css_select_ctx by calling css_select_ctx_create(). Later, when parsing is complete, we css_select_ctx_destroy() it. --- diff --git a/src/svgtiny.c b/src/svgtiny.c index 2ca5a58..3b886fe 100644 --- a/src/svgtiny.c +++ b/src/svgtiny.c @@ -17,6 +17,8 @@ #include #include +#include + #include "svgtiny.h" #include "svgtiny_internal.h" @@ -610,6 +612,7 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram, const char *buffer, size_t size, const char *url, int viewport_width, int viewport_height) { + css_error css_code; dom_document *document; dom_exception exc; dom_xml_parser *parser; @@ -695,6 +698,17 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram, state.viewport_width = viewport_width; state.viewport_height = viewport_height; + + /* Initialize CSS context */ + if (state.select_ctx == NULL) { + css_code = css_select_ctx_create(&state.select_ctx); + if (css_code != CSS_OK) { + dom_node_unref(svg); + dom_node_unref(document); + return svgtiny_LIBCSS_ERROR; + } + } + #define SVGTINY_STRING_ACTION2(s,n) \ if (dom_string_create_interned((const uint8_t *) #n, \ strlen(#n), &state.interned_##s) \ @@ -727,6 +741,10 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram, dom_node_unref(svg); dom_node_unref(document); + css_code = css_select_ctx_destroy(state.select_ctx); + if (css_code != CSS_OK) { + code = svgtiny_LIBCSS_ERROR; + } cleanup: svgtiny_cleanup_state_local(&state);