From 502591a5646eaa31758b2e47b67e393eebee75ca Mon Sep 17 00:00:00 2001 From: michabay05 Date: Wed, 25 Dec 2024 20:26:33 -0500 Subject: [PATCH] Added the stylesheet option to the C API --- crates/c-api/lib.rs | 14 ++++++++++++++ crates/c-api/resvg.h | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/crates/c-api/lib.rs b/crates/c-api/lib.rs index c7ff2843..b7376656 100644 --- a/crates/c-api/lib.rs +++ b/crates/c-api/lib.rs @@ -158,6 +158,20 @@ pub extern "C" fn resvg_options_set_dpi(opt: *mut resvg_options, dpi: f32) { cast_opt(opt).dpi = dpi as f32; } +/// @brief Sets a stylesheet path that will be used when resolving CSS attributes. +/// +/// Must be UTF-8. Can be set to NULL. +/// +/// Default: NULL +#[no_mangle] +pub extern "C" fn resvg_options_set_stylesheet(opt: *mut resvg_options, path: *const c_char) { + if path.is_null() { + cast_opt(opt).style_sheet = None; + } else { + cast_opt(opt).style_sheet = Some(cstr_to_str(path).unwrap().into()); + } +} + /// @brief Sets the default font family. /// /// Will be used when no `font-family` attribute is set in the SVG. diff --git a/crates/c-api/resvg.h b/crates/c-api/resvg.h index 271b7fe8..c4d8cafb 100644 --- a/crates/c-api/resvg.h +++ b/crates/c-api/resvg.h @@ -173,6 +173,15 @@ void resvg_options_set_resources_dir(resvg_options *opt, const char *path); */ void resvg_options_set_dpi(resvg_options *opt, float dpi); +/** + * @brief Sets a stylesheet path that will be used when resolving CSS attributes. + * + * Must be UTF-8. Can be set to NULL. + * + * Default: NULL + */ +void resvg_options_set_stylesheet(resvg_options *opt, const char *path); + /** * @brief Sets the default font family. *