From a6bc69359af397e969997162418630eacb8fdf6f Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 21 Jun 2017 17:31:07 +0200 Subject: [PATCH] use SVG viewport as bounding box --- utils/svg2png/svg2png.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/utils/svg2png/svg2png.cpp b/utils/svg2png/svg2png.cpp index 3faff4c6c..7069d76a7 100644 --- a/utils/svg2png/svg2png.cpp +++ b/utils/svg2png/svg2png.cpp @@ -69,11 +69,11 @@ struct main_marker_visitor agg::scanline_u8 sl; double opacity = 1; - int w = marker.width(); - int h = marker.height(); + double w = 0;//marker.width(); + double h = 0;//marker.height(); if (w == 0 || h == 0) { - // fallback to svg width/height or viewBox + // fallback to svg width/height and/or viewBox std::tie(w, h) = marker.dimensions(); } if (verbose_) @@ -81,17 +81,19 @@ struct main_marker_visitor std::clog << "found width of '" << w << "' and height of '" << h << "'\n"; } // 10 pixel buffer to avoid edge clipping of 100% svg's - mapnik::image_rgba8 im(w+0,h+0); + mapnik::image_rgba8 im(static_cast(w + 0.5), static_cast(h + 0.5)); agg::rendering_buffer buf(im.bytes(), im.width(), im.height(), im.row_size()); pixfmt pixf(buf); renderer_base renb(pixf); - mapnik::box2d const& bbox = marker.get_data()->bounding_box(); + //mapnik::box2d const& bbox = marker.get_data()->bounding_box(); + mapnik::box2d const& bbox = {0, 0, w, h}; + std::cerr << "BBOX:" << bbox << std::endl; mapnik::coord c = bbox.center(); // center the svg marker on '0,0' - agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y); + agg::trans_affine mtx = {};//agg::trans_affine_translation(-c.x,-c.y); // render the marker at the center of the marker box - mtx.translate(0.5 * im.width(), 0.5 * im.height()); + //mtx.translate(0.5 * im.width(), 0.5 * im.height()); mapnik::svg::vertex_stl_adapter stl_storage(marker.get_data()->source()); mapnik::svg::svg_path_adapter svg_path(stl_storage);