diff --git a/utils/svg2png/svg2png.cpp b/utils/svg2png/svg2png.cpp index 4bc830e8e..8fb83e442 100644 --- a/utils/svg2png/svg2png.cpp +++ b/utils/svg2png/svg2png.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +//#include #include #include @@ -33,11 +33,9 @@ #include #include -#include #include #include #include -#include #include "agg_rasterizer_scanline_aa.h" #include "agg_basics.h" @@ -69,7 +67,7 @@ int main (int argc,char** argv) po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); po::notify(vm); - + if (vm.count("version")) { std::clog<<"version 0.3.0" << std::endl; @@ -85,7 +83,7 @@ int main (int argc,char** argv) { verbose = true; } - + if (vm.count("svg")) { svg_files=vm["svg"].as< std::vector >(); @@ -104,61 +102,54 @@ int main (int argc,char** argv) } while (itr != svg_files.end()) { - + std::string svg_name (*itr++); - + boost::optional marker_ptr = mapnik::marker_cache::instance()->find(svg_name, false); if (marker_ptr) { mapnik::marker marker = **marker_ptr; if (marker.is_vector()) { - int width_ = marker.width(); - int height_ = marker.height(); - mapnik::image_32 pixmap_(width_,height_); - agg::rasterizer_scanline_aa<> ras_ptr; typedef agg::pixfmt_rgba32_plain pixfmt; typedef agg::renderer_base renderer_base; - - ras_ptr.reset(); - ras_ptr.gamma(agg::gamma_linear()); + agg::rasterizer_scanline_aa<> ras_ptr; agg::scanline_u8 sl; - agg::rendering_buffer buf(pixmap_.raw_data(), width_, height_, width_ * 4); + + double opacity = 1; + double scale_factor_ = .95; + int w = marker.width(); + int h = marker.height(); + mapnik::image_32 im(w,h); + agg::rendering_buffer buf(im.raw_data(), w, h, w * 4); pixfmt pixf(buf); renderer_base renb(pixf); - + mapnik::box2d const& bbox = (*marker.get_vector_data())->bounding_box(); - double x1 = bbox.minx(); - double y1 = bbox.miny(); - double x2 = bbox.maxx(); - double y2 = bbox.maxy(); - - agg::trans_affine recenter = agg::trans_affine_translation(0.5*(marker.width()-(x1+x2)),0.5*(marker.height()-(y1+y2))); - + mapnik::coord c = bbox.center(); + // center the svg marker on '0,0' + agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y); + // apply symbol transformation to get to map space + mtx *= agg::trans_affine_scaling(scale_factor_); + // render the marker at the center of the marker box + mtx.translate(0.5 * w, 0.5 * h); + mapnik::svg::vertex_stl_adapter stl_storage((*marker.get_vector_data())->source()); - mapnik::svg::svg_path_adapter svg_path(stl_storage); mapnik::svg::svg_renderer > svg_renderer_this(svg_path, (*marker.get_vector_data())->attributes()); - agg::trans_affine tr; - - agg::trans_affine mtx = recenter * tr; - double scale_factor_ = 1; - double opacity = 1; - mtx *= agg::trans_affine_scaling(scale_factor_); + svg_renderer_this.render(ras_ptr, sl, renb, mtx, opacity, bbox); - + boost::algorithm::ireplace_last(svg_name,".svg",".png"); - mapnik::save_to_file(pixmap_.data(),svg_name,"png"); + mapnik::save_to_file(im.data(),svg_name,"png"); std::ostringstream s; s << "open " << svg_name; system(s.str().c_str()); } } } - - } catch (...) {