]> gitweb.michael.orlitzky.com - libsvgtiny.git/commitdiff
src/svgtiny_css.c: new function svgtiny_create_stylesheet()
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 11 Oct 2023 12:27:22 +0000 (08:27 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 8 Jun 2025 02:18:20 +0000 (22:18 -0400)
We add a function to handle the creation of a new stylesheet with the
default set of parameters. This is in preparation for parsing the
inline styles, which a priori would involve copy/pasting a lot of

  params.foo = bar;

lines from svgtiny_parse_style_element(). The goal is to factor the
common bits out of both the <style> and style= implementations.

src/svgtiny_css.c

index 06383765b6380c0b0bb922c41bd969a3f61ecd66..abc2515ed1026d54e5d1a93ba306c795b7932017 100644 (file)
@@ -19,3 +19,37 @@ static css_error svgtiny_resolve_url(void *pw,
        *abs = lwc_string_ref(rel);
        return CSS_OK;
 }
+
+/**
+ * Create a stylesheet with the default set of params.
+ *
+ * \param sheet A stylesheet pointer, passed in by reference, that
+ * we use to store the newly-created stylesheet.
+ * \param inline_style True if this stylesheet represents an inline
+ * style, and false otherwise.
+ *
+ * \return The return value from css_stylesheet_create() is returned.
+ */
+css_error svgtiny_create_stylesheet(css_stylesheet **sheet,
+               bool inline_style)
+{
+       css_stylesheet_params params;
+
+       params.params_version = CSS_STYLESHEET_PARAMS_VERSION_1;
+       params.level = CSS_LEVEL_DEFAULT;
+       params.charset = NULL;
+       params.url = "";
+       params.title = NULL;
+       params.allow_quirks = false;
+       params.inline_style = inline_style;
+       params.resolve = svgtiny_resolve_url;
+       params.resolve_pw = NULL;
+       params.import = NULL;
+       params.import_pw = NULL;
+       params.color = NULL;
+       params.color_pw = NULL;
+       params.font = NULL;
+       params.font_pw = NULL;
+
+       return css_stylesheet_create(&params, sheet);
+}