From c3aec439a7c70ddd345ba5638563f4d9313d341b Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Thu, 24 Nov 2022 10:25:09 +0000 Subject: [PATCH] svg2png - check for valid `opacity` range 0..1 [WIP] [skip ci] --- utils/svg2png/svg2png.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/utils/svg2png/svg2png.cpp b/utils/svg2png/svg2png.cpp index 079f270d5..cfb73e1a3 100644 --- a/utils/svg2png/svg2png.cpp +++ b/utils/svg2png/svg2png.cpp @@ -161,6 +161,15 @@ struct main_marker_visitor bool auto_open_; }; +void check_opacity_range(double opacity) +{ + using namespace boost::program_options; + if (opacity < 0.0 || opacity > 1.0) + { + throw invalid_option_value(std::to_string(opacity)); + } +} + int main(int argc, char** argv) { namespace po = boost::program_options; @@ -171,8 +180,8 @@ int main(int argc, char** argv) int status = 0; std::vector svg_files; mapnik::logger::instance().set_severity(mapnik::logger::error); - double scale_factor = 1.0; - double opacity = 1.0; + double scale_factor; + double opacity; std::string usage = "Usage: svg2png [options] "; try { @@ -184,8 +193,8 @@ int main(int argc, char** argv) ("verbose,v","verbose output") ("open,o","automatically open the file after rendering (os x only)") ("strict,s","enables strict SVG parsing") - ("scale-factor", po::value(), "provide scaling factor (default: 1.0)") - ("opacity", po::value(), "top level opacity (default: 1.0)") + ("scale-factor", po::value()->default_value(1.0), "provide scaling factor (default: 1.0)") + ("opacity", po::value()->default_value(1.0)->notifier(&check_opacity_range), "top level opacity (default: 1.0)") ("svg",po::value >(),"svg file to read") ; // clang-format on