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
25 changes: 13 additions & 12 deletions crates/resvg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,16 @@ fn render_svg(args: &Args, tree: &usvg::Tree) -> Result<tiny_skia::Pixmap, Strin
None => return Err(format!("SVG doesn't have '{}' ID", id)),
};

let bbox = node
.abs_layer_bounding_box()
.ok_or_else(|| "node has zero size".to_string())?;
let bbox = node.abs_layer_bounding_box().ok_or("node has zero size")?;

let size = args
.fit_to
.fit_to_size(bbox.size().to_int_size())
.ok_or_else(|| "target size is zero".to_string())?;
.ok_or("target size is zero")?;

// Unwrap is safe, because `size` is already valid.
let mut pixmap = tiny_skia::Pixmap::new(size.width(), size.height()).unwrap();
// Pixmap's width is limited by i32::MAX/4, we handle the creation error.
let mut pixmap =
tiny_skia::Pixmap::new(size.width(), size.height()).ok_or("cannot create pixmap")?;

if !args.export_area_page {
if let Some(background) = args.background {
Expand All @@ -703,10 +702,11 @@ fn render_svg(args: &Args, tree: &usvg::Tree) -> Result<tiny_skia::Pixmap, Strin
let size = args
.fit_to
.fit_to_size(tree.size().to_int_size())
.ok_or_else(|| "target size is zero".to_string())?;
.ok_or("target size is zero")?;

// Unwrap is safe, because `size` is already valid.
let mut page_pixmap = tiny_skia::Pixmap::new(size.width(), size.height()).unwrap();
// Pixmap's width is limited by i32::MAX/4, we handle the creation error.
let mut page_pixmap = tiny_skia::Pixmap::new(size.width(), size.height())
.ok_or("cannot create pixmap")?;

if let Some(background) = args.background {
page_pixmap.fill(svg_to_skia_color(background));
Expand All @@ -728,10 +728,11 @@ fn render_svg(args: &Args, tree: &usvg::Tree) -> Result<tiny_skia::Pixmap, Strin
let size = args
.fit_to
.fit_to_size(tree.size().to_int_size())
.ok_or_else(|| "target size is zero".to_string())?;
.ok_or("target size is zero")?;

// Unwrap is safe, because `size` is already valid.
let mut pixmap = tiny_skia::Pixmap::new(size.width(), size.height()).unwrap();
// Pixmap's width is limited by i32::MAX/4, we handle the creation error.
let mut pixmap =
tiny_skia::Pixmap::new(size.width(), size.height()).ok_or("cannot create pixmap")?;

if let Some(background) = args.background {
pixmap.fill(svg_to_skia_color(background));
Expand Down