diff --git a/utils/svg2png/svg2png.cpp b/utils/svg2png/svg2png.cpp index 7e3aca532..0dc8efca0 100644 --- a/utils/svg2png/svg2png.cpp +++ b/utils/svg2png/svg2png.cpp @@ -52,28 +52,26 @@ struct main_marker_visitor { - main_marker_visitor(std::string & svg_name, - int & return_value, + main_marker_visitor(std::string const& svg_name, bool verbose, bool auto_open) : svg_name_(svg_name), - return_value_(return_value), verbose_(verbose), auto_open_(auto_open) {} - void operator() (mapnik::marker_null const&) + int operator() (mapnik::marker_null const&) { std::clog << "svg2png error: '" << svg_name_ << "' is not a valid vector!\n"; - return_value_ = -1; + return -1; } - void operator() (mapnik::marker_rgba8 const&) + int operator() (mapnik::marker_rgba8 const&) { std::clog << "svg2png error: '" << svg_name_ << "' is not a valid vector!\n"; - return_value_ = -1; + return -1; } - void operator() (mapnik::marker_svg const& marker) + int operator() (mapnik::marker_svg const& marker) { using pixfmt = agg::pixfmt_rgba32_pre; using renderer_base = agg::renderer_base; @@ -111,28 +109,29 @@ struct main_marker_visitor svg_renderer_this.render(ras_ptr, sl, renb, mtx, opacity, bbox); - boost::algorithm::ireplace_last(svg_name_,".svg",".png"); + std::string png_name(svg_name_); + boost::algorithm::ireplace_last(png_name,".svg",".png"); demultiply_alpha(im); - mapnik::save_to_file(im,svg_name_,"png"); + mapnik::save_to_file(im,png_name,"png"); + int status = 0; if (auto_open_) { std::ostringstream s; #ifdef DARWIN - s << "open " << svg_name_; + s << "open " << png_name; #else - s << "xdg-open " << svg_name_; + s << "xdg-open " << png_name; #endif int ret = system(s.str().c_str()); if (ret != 0) - return_value_ = ret; + status = ret; } std::clog << "rendered to: " << svg_name_ << "\n"; - + return status; } private: - std::string & svg_name_; - int & return_value_; + std::string const& svg_name_; bool verbose_; bool auto_open_; }; @@ -143,7 +142,7 @@ int main (int argc,char** argv) bool verbose = false; bool auto_open = false; - int return_value = 0; + int status = 0; std::vector svg_files; mapnik::logger::instance().set_severity(mapnik::logger::error); @@ -214,8 +213,8 @@ int main (int argc,char** argv) } std::shared_ptr marker = mapnik::marker_cache::instance().find(svg_name, false); - main_marker_visitor visitor(svg_name, return_value, verbose, auto_open); - mapnik::util::apply_visitor(visitor, *marker); + main_marker_visitor visitor(svg_name, verbose, auto_open); + status = mapnik::util::apply_visitor(visitor, *marker); } } catch (...) @@ -229,5 +228,5 @@ int main (int argc,char** argv) // to make sure valgrind output is clean // http://xmlsoft.org/xmlmem.html xmlCleanupParser(); - return return_value; + return status; }