Skip to content

Commit cbc9f3c

Browse files
Fixed zoom, width and height (#74)
Merging as is, lets implement the testing later
1 parent c0bf0a7 commit cbc9f3c

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/rust/lib.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,32 @@ fn svg_to_skia_color(color: svgtypes::Color) -> resvg::tiny_skia::Color {
132132
resvg::tiny_skia::Color::from_rgba8(color.red, color.green, color.blue, color.alpha)
133133
}
134134

135-
fn render_svg(background: Option<svgtypes::Color>, fit_to: FitTo, tree: &resvg::usvg::Tree) -> Result<resvg::tiny_skia::Pixmap, String> {
135+
fn render_svg(
136+
background: Option<svgtypes::Color>,
137+
fit_to: FitTo,
138+
tree: &resvg::usvg::Tree
139+
) -> Result<resvg::tiny_skia::Pixmap, String> {
140+
let original_size = tree.size().to_int_size();
141+
142+
let final_size = fit_to.fit_to_size(original_size)
143+
.ok_or("Failed to calculate scaled size")?;
144+
136145
let mut pixmap = resvg::tiny_skia::Pixmap::new(
137-
tree.size().to_int_size().width(),
138-
tree.size().to_int_size().height(),
139-
)
140-
.unwrap();
146+
final_size.width(),
147+
final_size.height(),
148+
).ok_or("Failed to create pixmap")?;
141149

142150
if let Some(background) = background {
143151
pixmap.fill(svg_to_skia_color(background));
144152
}
145-
let ts = fit_to.fit_to_transform(tree.size().to_int_size());
153+
154+
let ts = fit_to.fit_to_transform(original_size);
146155
resvg::render(tree, ts, &mut pixmap.as_mut());
147156

148157
Ok(pixmap)
149158
}
150159

160+
151161
fn resvg_magic(mut options: Opts, svg_string: String) -> Result<Vec<u8>, String> {
152162
let xml_tree = {
153163
let xml_opt = resvg::usvg::roxmltree::ParsingOptions {

0 commit comments

Comments
 (0)