Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,32 @@ fn svg_to_skia_color(color: svgtypes::Color) -> resvg::tiny_skia::Color {
resvg::tiny_skia::Color::from_rgba8(color.red, color.green, color.blue, color.alpha)
}

fn render_svg(background: Option<svgtypes::Color>, fit_to: FitTo, tree: &resvg::usvg::Tree) -> Result<resvg::tiny_skia::Pixmap, String> {
fn render_svg(
background: Option<svgtypes::Color>,
fit_to: FitTo,
tree: &resvg::usvg::Tree
) -> Result<resvg::tiny_skia::Pixmap, String> {
let original_size = tree.size().to_int_size();

let final_size = fit_to.fit_to_size(original_size)
.ok_or("Failed to calculate scaled size")?;

let mut pixmap = resvg::tiny_skia::Pixmap::new(
tree.size().to_int_size().width(),
tree.size().to_int_size().height(),
)
.unwrap();
final_size.width(),
final_size.height(),
).ok_or("Failed to create pixmap")?;

if let Some(background) = background {
pixmap.fill(svg_to_skia_color(background));
}
let ts = fit_to.fit_to_transform(tree.size().to_int_size());

let ts = fit_to.fit_to_transform(original_size);
resvg::render(tree, ts, &mut pixmap.as_mut());

Ok(pixmap)
}


fn resvg_magic(mut options: Opts, svg_string: String) -> Result<Vec<u8>, String> {
let xml_tree = {
let xml_opt = resvg::usvg::roxmltree::ParsingOptions {
Expand Down