[librsvg/rustify-rsvg-convert: 58/78] rsvg-convert: shorten code




commit 666d4a81bf84760967bba2389a2d6e12571536db
Author: Paolo Borelli <pborelli gnome org>
Date:   Mon Jan 18 14:30:36 2021 +0100

    rsvg-convert: shorten code

 src/bin/rsvg-convert.rs | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)
---
diff --git a/src/bin/rsvg-convert.rs b/src/bin/rsvg-convert.rs
index d6e7bd79..77f06678 100644
--- a/src/bin/rsvg-convert.rs
+++ b/src/bin/rsvg-convert.rs
@@ -439,7 +439,11 @@ impl Converter {
         };
 
         Surface::new(self.format, size, output_stream).unwrap_or_else(|e| match e {
-            cairo::Status::InvalidSize => size_limit_exceeded(),
+            cairo::Status::InvalidSize => exit!(concat!(
+                "The resulting image would be larger than 32767 pixels on either dimension.\n",
+                "Librsvg currently cannot render to images bigger than that.\n",
+                "Please specify a smaller size."
+            )),
             e => exit!("Error creating output surface: {}", e),
         })
     }
@@ -615,16 +619,11 @@ fn parse_args() -> Result<Converter, clap::Error> {
         None => vec![Input::Stdin],
     };
 
-    if input.len() > 1 {
-        match format {
-            Format::Ps | Format::Eps | Format::Pdf => (),
-            _ => {
-                return Err(clap::Error::with_description(
-                    "Multiple SVG files are only allowed for PDF and (E)PS output.",
-                    clap::ErrorKind::TooManyValues,
-                ))
-            }
-        }
+    if input.len() > 1 && !matches!(format, Format::Ps | Format::Eps | Format::Pdf) {
+        return Err(clap::Error::with_description(
+            "Multiple SVG files are only allowed for PDF and (E)PS output.",
+            clap::ErrorKind::TooManyValues,
+        ));
     }
 
     Ok(Converter {
@@ -724,14 +723,6 @@ macro_rules! exit {
     })
 }
 
-fn size_limit_exceeded() -> ! {
-    exit!(
-        "The resulting image would be larger than 32767 pixels on either dimension.\n\
-           Librsvg currently cannot render to images bigger than that.\n\
-           Please specify a smaller size."
-    );
-}
-
 fn main() {
     parse_args().map_or_else(|e| e.exit(), |converter| converter.convert());
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]