From: Michael Orlitzky Date: Sat, 7 Jun 2025 13:51:16 +0000 (-0400) Subject: src/svgtiny.c: initialise/finalise the libcss context X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=aea9d4928943578b10986628ab2a7ef70aab09e8;p=libsvgtiny.git src/svgtiny.c: initialise/finalise the libcss context 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 44ca0fe..a3080ea 100644 --- a/src/svgtiny.c +++ b/src/svgtiny.c @@ -18,6 +18,8 @@ #include #include +#include + #include "svgtiny.h" #include "svgtiny_internal.h" @@ -1077,7 +1079,9 @@ initialise_parse_state(struct svgtiny_parse_state *state, int viewport_height) { float x, y, width, height; + css_error css_code; + /* initialize the state struct with zeros */ memset(state, 0, sizeof(*state)); state->diagram = diagram; @@ -1112,12 +1116,22 @@ initialise_parse_state(struct svgtiny_parse_state *state, state->fill = 0x000000; state->stroke = svgtiny_TRANSPARENT; state->stroke_width = 1; + + /* Initialize the CSS context */ + 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; + } + return svgtiny_OK; } static svgtiny_code finalise_parse_state(struct svgtiny_parse_state *state) { + css_error css_code; svgtiny_cleanup_state_local(state); #define SVGTINY_STRING_ACTION2(s,n) \ @@ -1125,6 +1139,12 @@ static svgtiny_code finalise_parse_state(struct svgtiny_parse_state *state) dom_string_unref(state->interned_##s); #include "svgtiny_strings.h" #undef SVGTINY_STRING_ACTION2 + + css_code = css_select_ctx_destroy(state->select_ctx); + if (css_code != CSS_OK) { + return svgtiny_LIBCSS_ERROR; + } + return svgtiny_OK; }