From: Michael Orlitzky Date: Wed, 11 Oct 2023 19:17:08 +0000 (-0400) Subject: src/svgtiny.c: parse inline stylesheet in svgtiny_parse_paint_attributes() X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=b94bca14bb7cd65bda2a92454a17a2e0d0b7234c;p=libsvgtiny.git src/svgtiny.c: parse inline stylesheet in svgtiny_parse_paint_attributes() ...and do nothing with it, for the moment. We are able to parse the inline style="..." attributes right now but more scaffolding is needed before we can utilize css_select_style(). --- diff --git a/src/svgtiny.c b/src/svgtiny.c index db0d59b..d16a761 100644 --- a/src/svgtiny.c +++ b/src/svgtiny.c @@ -2055,6 +2055,13 @@ void svgtiny_parse_paint_attributes(dom_element *node, dom_string *attr; dom_exception exc; + /* We store the result of svgtiny_parse_style_inline() in + * inline_sheet, and that function returns NULL on error; in + * particular you do not need to css_stylesheet_destroy() the + * result if it is NULL. We initialize inline_sheet to NULL to + * retain the same semantics. */ + css_stylesheet *inline_sheet = NULL; + exc = dom_element_get_attribute(node, state->interned_fill, &attr); if (exc == DOM_NO_ERR && attr != NULL) { svgtiny_parse_color(attr, &state->fill, &state->fill_grad, state); @@ -2076,6 +2083,14 @@ void svgtiny_parse_paint_attributes(dom_element *node, exc = dom_element_get_attribute(node, state->interned_style, &attr); if (exc == DOM_NO_ERR && attr != NULL) { + /* First parse the style attribute into a libcss stylesheet + in case any of its properties are known to libcss. */ + inline_sheet = svgtiny_parse_style_inline( + (uint8_t *)dom_string_data(attr), + dom_string_byte_length(attr)); + + /* Parse any other properties "by hand" until they can + be supported in libcss. */ char *style = strndup(dom_string_data(attr), dom_string_byte_length(attr)); const char *s; @@ -2108,6 +2123,10 @@ void svgtiny_parse_paint_attributes(dom_element *node, free(style); dom_string_unref(attr); } + + if (inline_sheet != NULL) { + css_stylesheet_destroy(inline_sheet); + } }