From bea611a1851164cc99699d985606545842485f06 Mon Sep 17 00:00:00 2001 From: Robert Coup Date: Mon, 31 Jan 2011 09:56:31 +0000 Subject: [PATCH] Fix positioning problem with scale() transforms for SVG symbols. Centering transform applied in the wrong order. Thanks to Toby Collett. --- src/agg/agg_renderer.cpp | 20 ++++++++------------ src/cairo_renderer.cpp | 11 ++++++----- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/agg/agg_renderer.cpp b/src/agg/agg_renderer.cpp index 575b6e92d..9b71136dc 100644 --- a/src/agg/agg_renderer.cpp +++ b/src/agg/agg_renderer.cpp @@ -214,21 +214,20 @@ void agg_renderer::render_marker(const int x, const int y, marker &marker, co renderer_base renb(pixf); 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))); + 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 *= tr; + mtx *= agg::trans_affine_scaling(scale_factor_); + // render the marker at the center of the marker box + mtx.translate(x+0.5 * marker.width(), y+0.5 * marker.height()); vertex_stl_adapter stl_storage((*marker.get_vector_data())->source()); svg_path_adapter svg_path(stl_storage); svg_renderer > svg_renderer(svg_path, (*marker.get_vector_data())->attributes()); - agg::trans_affine mtx = recenter * tr; - mtx *= agg::trans_affine_scaling(scale_factor_); - mtx *= agg::trans_affine_translation(x, y); svg_renderer.render(*ras_ptr, sl, renb, mtx, opacity, bbox); @@ -236,9 +235,6 @@ void agg_renderer::render_marker(const int x, const int y, marker &marker, co } else { - //int px = int(floor(x - 0.5 * marker.width())); - // int py = int(floor(y - 0.5 * marker.height())); - pixmap_.set_rectangle_alpha2(**marker.get_bitmap_data(), x, y, opacity); } } diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index 7c0abe422..dd9df0901 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -917,11 +917,12 @@ void cairo_renderer_base::render_marker(const int x, const int y, marker &marker bbox = (*marker.get_vector_data())->bounding_box(); coord c = bbox.center(); - agg::trans_affine recenter = agg::trans_affine_translation(0.5 * marker.width()-c.x,0.5 * marker.height()-c.y); - - agg::trans_affine mtx = tr; - mtx = recenter * mtx; - mtx *= agg::trans_affine_translation(x, y); + // 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 *= tr; + // render the marker at the center of the marker box + mtx.translate(x+0.5 * marker.width(), y+0.5 * marker.height()); typedef coord_transform2 path_type; mapnik::path_ptr vmarker = *marker.get_vector_data();