From e49f63730e7f1330db4332fc89ca40d9e7b0a107 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 27 Feb 2014 11:55:58 -0800 Subject: [PATCH] support scale_factor in geometry-transform translate and scale - refs #1926 --- include/mapnik/symbolizer.hpp | 2 +- include/mapnik/transform_processor.hpp | 31 ++++++++++-------- src/agg/process_line_pattern_symbolizer.cpp | 2 +- src/agg/process_line_symbolizer.cpp | 2 +- .../process_polygon_pattern_symbolizer.cpp | 2 +- src/agg/process_polygon_symbolizer.cpp | 2 +- src/cairo_renderer.cpp | 8 ++--- src/grid/process_line_pattern_symbolizer.cpp | 2 +- src/grid/process_line_symbolizer.cpp | 2 +- src/grid/process_markers_symbolizer.cpp | 2 +- .../process_polygon_pattern_symbolizer.cpp | 2 +- src/grid/process_polygon_symbolizer.cpp | 2 +- src/symbolizer.cpp | 4 +-- ...rm-translate-200-200-2.0-agg-reference.png | Bin 1101 -> 1087 bytes 14 files changed, 34 insertions(+), 29 deletions(-) diff --git a/include/mapnik/symbolizer.hpp b/include/mapnik/symbolizer.hpp index 3e9f58fd3..17e268b1e 100644 --- a/include/mapnik/symbolizer.hpp +++ b/include/mapnik/symbolizer.hpp @@ -50,7 +50,7 @@ typedef transform_list_ptr transform_type; class feature_impl; MAPNIK_DECL void evaluate_transform(agg::trans_affine& tr, feature_impl const& feature, - transform_type const& trans_expr); + transform_type const& trans_expr, double scale_factor=1.0); class MAPNIK_DECL symbolizer_base { diff --git a/include/mapnik/transform_processor.hpp b/include/mapnik/transform_processor.hpp index d720c4350..89f3f7949 100644 --- a/include/mapnik/transform_processor.hpp +++ b/include/mapnik/transform_processor.hpp @@ -107,8 +107,12 @@ struct transform_processor struct node_evaluator : boost::static_visitor { - node_evaluator(transform_type& tr, feature_type const& feat) - : transform_(tr), feature_(feat) {} + node_evaluator(transform_type& tr, + feature_type const& feat, + double scale_factor) + : transform_(tr), + feature_(feat), + scale_factor_(scale_factor) {} void operator() (identity_node const& node) { @@ -117,26 +121,26 @@ struct transform_processor void operator() (matrix_node const& node) { - double a = eval(node.a_); + double a = eval(node.a_) * scale_factor_; // scale x; double b = eval(node.b_); double c = eval(node.c_); - double d = eval(node.d_); - double e = eval(node.e_); - double f = eval(node.f_); + double d = eval(node.d_) * scale_factor_; // scale y; + double e = eval(node.e_) * scale_factor_; // translate x + double f = eval(node.f_) * scale_factor_; // translate y transform_.multiply(agg::trans_affine(a, b, c, d, e, f)); } void operator() (translate_node const& node) { - double tx = eval(node.tx_); - double ty = eval(node.ty_, 0.0); + double tx = eval(node.tx_) * scale_factor_; + double ty = eval(node.ty_, 0.0) * scale_factor_; transform_.translate(tx, ty); } void operator() (scale_node const& node) { - double sx = eval(node.sx_); - double sy = eval(node.sy_, sx); + double sx = eval(node.sx_) * scale_factor_; + double sy = eval(node.sy_, sx) * scale_factor_; transform_.scale(sx, sy); } @@ -172,7 +176,7 @@ struct transform_processor double eval(expr_node const& x) const { mapnik::evaluate e(feature_); - return boost::apply_visitor(e, x).to_double(); + return boost::apply_visitor(e, x).to_double() * scale_factor_; } double eval(expr_node const& x, double def) const @@ -182,6 +186,7 @@ struct transform_processor transform_type& transform_; feature_type const& feature_; + double scale_factor_; }; template @@ -197,9 +202,9 @@ struct transform_processor } static void evaluate(transform_type& tr, feature_type const& feat, - transform_list const& list) + transform_list const& list, double scale_factor) { - node_evaluator eval(tr, feat); + node_evaluator eval(tr, feat, scale_factor); #ifdef MAPNIK_LOG MAPNIK_LOG_DEBUG(transform) << "transform: begin with " << to_string(matrix_node(tr)); diff --git a/src/agg/process_line_pattern_symbolizer.cpp b/src/agg/process_line_pattern_symbolizer.cpp index c2e466375..7259a3a86 100644 --- a/src/agg/process_line_pattern_symbolizer.cpp +++ b/src/agg/process_line_pattern_symbolizer.cpp @@ -125,7 +125,7 @@ void agg_renderer::process(line_pattern_symbolizer const& sym, rasterizer_type ras(ren); agg::trans_affine tr; - evaluate_transform(tr, feature, sym.get_transform()); + evaluate_transform(tr, feature, sym.get_transform(), scale_factor_); box2d clip_box = clipping_extent(); if (sym.clip()) diff --git a/src/agg/process_line_symbolizer.cpp b/src/agg/process_line_symbolizer.cpp index b4290ffce..f35a3405b 100644 --- a/src/agg/process_line_symbolizer.cpp +++ b/src/agg/process_line_symbolizer.cpp @@ -90,7 +90,7 @@ void agg_renderer::process(line_symbolizer const& sym, renderer_base renb(pixf); agg::trans_affine tr; - evaluate_transform(tr, feature, sym.get_transform()); + evaluate_transform(tr, feature, sym.get_transform(), scale_factor_); box2d clip_box = clipping_extent(); if (sym.clip()) diff --git a/src/agg/process_polygon_pattern_symbolizer.cpp b/src/agg/process_polygon_pattern_symbolizer.cpp index ae82660d0..20c70c806 100644 --- a/src/agg/process_polygon_pattern_symbolizer.cpp +++ b/src/agg/process_polygon_pattern_symbolizer.cpp @@ -146,7 +146,7 @@ void agg_renderer::process(polygon_pattern_symbolizer const& sym, renderer_type rp(renb,sa, sg, unsigned(sym.get_opacity()*255)); agg::trans_affine tr; - evaluate_transform(tr, feature, sym.get_transform()); + evaluate_transform(tr, feature, sym.get_transform(), scale_factor_); typedef boost::mpl::vector conv_types; vertex_converter, rasterizer, polygon_pattern_symbolizer, diff --git a/src/agg/process_polygon_symbolizer.cpp b/src/agg/process_polygon_symbolizer.cpp index 6e168aae6..2c86a8a4e 100644 --- a/src/agg/process_polygon_symbolizer.cpp +++ b/src/agg/process_polygon_symbolizer.cpp @@ -57,7 +57,7 @@ void agg_renderer::process(polygon_symbolizer const& sym, gamma_ = sym.get_gamma(); } agg::trans_affine tr; - evaluate_transform(tr, feature, sym.get_transform()); + evaluate_transform(tr, feature, sym.get_transform(), scale_factor_); box2d clip_box = clipping_extent(); typedef boost::mpl::vector conv_types; vertex_converter, rasterizer, polygon_symbolizer, diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index 5539939df..ce51fc304 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -315,7 +315,7 @@ void cairo_renderer_base::process(polygon_symbolizer const& sym, context_.set_color(sym.get_fill(), sym.get_opacity()); agg::trans_affine tr; - evaluate_transform(tr, feature, sym.get_transform()); + evaluate_transform(tr, feature, sym.get_transform(), scale_factor_); typedef boost::mpl::vector conv_types; vertex_converter, cairo_context, polygon_symbolizer, @@ -466,7 +466,7 @@ void cairo_renderer_base::process(line_symbolizer const& sym, } agg::trans_affine tr; - evaluate_transform(tr, feature, sym.get_transform()); + evaluate_transform(tr, feature, sym.get_transform(), scale_factor_); box2d clipping_extent = query_extent_; if (sym.clip()) @@ -853,7 +853,7 @@ void cairo_renderer_base::process(polygon_pattern_symbolizer const& sym, //} agg::trans_affine tr; - evaluate_transform(tr, feature, sym.get_transform()); + evaluate_transform(tr, feature, sym.get_transform(), scale_factor_); typedef boost::mpl::vector conv_types; vertex_converter, cairo_context, polygon_pattern_symbolizer, @@ -1161,7 +1161,7 @@ void cairo_renderer_base::process(markers_symbolizer const& sym, if (mark && *mark) { agg::trans_affine geom_tr; - evaluate_transform(geom_tr, feature, sym.get_transform()); + evaluate_transform(geom_tr, feature, sym.get_transform(), scale_factor_); box2d const& bbox = (*mark)->bounding_box(); setup_transform_scaling(tr, bbox.width(), bbox.height(), feature, sym); evaluate_transform(tr, feature, sym.get_image_transform()); diff --git a/src/grid/process_line_pattern_symbolizer.cpp b/src/grid/process_line_pattern_symbolizer.cpp index eeaa700a9..42684e57a 100644 --- a/src/grid/process_line_pattern_symbolizer.cpp +++ b/src/grid/process_line_pattern_symbolizer.cpp @@ -83,7 +83,7 @@ void grid_renderer::process(line_pattern_symbolizer const& sym, int stroke_width = (*pat)->width(); agg::trans_affine tr; - evaluate_transform(tr, feature, sym.get_transform()); + evaluate_transform(tr, feature, sym.get_transform(), scale_factor_); box2d clipping_extent = query_extent_; if (sym.clip()) diff --git a/src/grid/process_line_symbolizer.cpp b/src/grid/process_line_symbolizer.cpp index c188b6473..737d92def 100644 --- a/src/grid/process_line_symbolizer.cpp +++ b/src/grid/process_line_symbolizer.cpp @@ -69,7 +69,7 @@ void grid_renderer::process(line_symbolizer const& sym, stroke const& stroke_ = sym.get_stroke(); agg::trans_affine tr; - evaluate_transform(tr, feature, sym.get_transform()); + evaluate_transform(tr, feature, sym.get_transform(), scale_factor_); box2d clipping_extent = query_extent_; if (sym.clip()) diff --git a/src/grid/process_markers_symbolizer.cpp b/src/grid/process_markers_symbolizer.cpp index 81180f481..1bc66ca36 100644 --- a/src/grid/process_markers_symbolizer.cpp +++ b/src/grid/process_markers_symbolizer.cpp @@ -96,7 +96,7 @@ void grid_renderer::process(markers_symbolizer const& sym, { ras_ptr->reset(); agg::trans_affine geom_tr; - evaluate_transform(geom_tr, feature, sym.get_transform()); + evaluate_transform(geom_tr, feature, sym.get_transform(), scale_factor_); agg::trans_affine tr = agg::trans_affine_scaling(scale_factor_*(1.0/pixmap_.get_resolution())); if ((*mark)->is_vector()) diff --git a/src/grid/process_polygon_pattern_symbolizer.cpp b/src/grid/process_polygon_pattern_symbolizer.cpp index da012dada..ec75b42b2 100644 --- a/src/grid/process_polygon_pattern_symbolizer.cpp +++ b/src/grid/process_polygon_pattern_symbolizer.cpp @@ -68,7 +68,7 @@ void grid_renderer::process(polygon_pattern_symbolizer const& sym, ras_ptr->reset(); agg::trans_affine tr; - evaluate_transform(tr, feature, sym.get_transform()); + evaluate_transform(tr, feature, sym.get_transform(), scale_factor_); typedef boost::mpl::vector conv_types; vertex_converter, grid_rasterizer, polygon_pattern_symbolizer, diff --git a/src/grid/process_polygon_symbolizer.cpp b/src/grid/process_polygon_symbolizer.cpp index 5195760f9..f6508fd2f 100644 --- a/src/grid/process_polygon_symbolizer.cpp +++ b/src/grid/process_polygon_symbolizer.cpp @@ -55,7 +55,7 @@ void grid_renderer::process(polygon_symbolizer const& sym, ras_ptr->reset(); agg::trans_affine tr; - evaluate_transform(tr, feature, sym.get_transform()); + evaluate_transform(tr, feature, sym.get_transform(), scale_factor_); typedef boost::mpl::vector conv_types; vertex_converter, grid_rasterizer, polygon_symbolizer, diff --git a/src/symbolizer.cpp b/src/symbolizer.cpp index 1a09e0ce8..31ac0dd5c 100644 --- a/src/symbolizer.cpp +++ b/src/symbolizer.cpp @@ -29,7 +29,7 @@ namespace mapnik { void evaluate_transform(agg::trans_affine& tr, feature_impl const& feature, - transform_list_ptr const& trans_expr) + transform_list_ptr const& trans_expr, double scale_factor) { if (trans_expr) { @@ -37,7 +37,7 @@ void evaluate_transform(agg::trans_affine& tr, feature_impl const& feature, MAPNIK_LOG_DEBUG(transform) << "transform: evaluate " << transform_processor_type::to_string(*trans_expr); #endif - transform_processor_type::evaluate(tr, feature, *trans_expr); + transform_processor_type::evaluate(tr, feature, *trans_expr, scale_factor); } } diff --git a/tests/visual_tests/images/geometry-transform-translate-200-200-2.0-agg-reference.png b/tests/visual_tests/images/geometry-transform-translate-200-200-2.0-agg-reference.png index c20472cfb4e3a8e5fc88a555c9008efa80924a96..29338b517aa65c3dd83a9a0aaf3a1b25931a8f4c 100644 GIT binary patch delta 1018 zcmVcK# z#9KPVTROyBI>cK##9KPVEaxlvG92U_0x3a*jE)e#hznqlyMvTqL4F+J^Aufzf;=4C ze<6|}L7p7L$MPZ&B3qv$~WWEXd_&m|#U=I2e#? zcnZDq6b{ExhRhr$5|*P335&$L9O3XBMaX#xIVww-jv{2~2;r^eG>hRnN|0*|*=NUV z9JZqbxx|pe&~T!K@Es*c><~aBx0YogVkZVO&?kr>bLI z0sqnfay#t~f5zMyig)_m5n4iSw~uMKz3#et4~-!s zhhIpg!!4xN;T2Nta0;n+_=K!*f4GFKao9tMA!a?Y2IE;l=6yI^$fDN=3t9FPQ6W*! z5)=~mMKK{n?-de4^>+~=WDgk-LiefhAc^p+=G+7nBzOJ; z36ed>0tCsQ$H9RV&K03Rwx#n?AduPj3}jCq15$QiKo|}P2*-f{VL1RGe>{hO2-D#o z!gTnDFdZn6@_9832;j>t;6s+($--HY3;CrGLmMLIP=?4kbRmKcRfwcR6C&zRgvdJdAi@qch_pis zBJNOv$UAf(3Jw*BhC>6Qf8tPp=s4sdN)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