From 77dfac5622843c9056c6f13196bd0ba2a92c9e5d Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Tue, 1 May 2012 16:47:33 +0100 Subject: [PATCH] + re-introduce transform on symbolizer_with_image --- bindings/python/mapnik_svg.hpp | 8 +++-- include/mapnik/symbolizer.hpp | 4 +++ include/mapnik/symbolizer_helpers.hpp | 5 ++- src/agg/process_markers_symbolizer.cpp | 2 +- src/agg/process_point_symbolizer.cpp | 2 +- src/agg/process_shield_symbolizer.cpp | 2 +- src/cairo_renderer.cpp | 6 ++-- src/grid/process_markers_symbolizer.cpp | 2 +- src/grid/process_point_symbolizer.cpp | 2 +- src/grid/process_shield_symbolizer.cpp | 2 +- src/load_map.cpp | 48 +++++++++++-------------- src/symbolizer.cpp | 33 +++++++++++++++-- src/symbolizer_helpers.cpp | 4 +-- 13 files changed, 73 insertions(+), 47 deletions(-) diff --git a/bindings/python/mapnik_svg.hpp b/bindings/python/mapnik_svg.hpp index fc9e605e7..123abed19 100644 --- a/bindings/python/mapnik_svg.hpp +++ b/bindings/python/mapnik_svg.hpp @@ -36,7 +36,7 @@ using namespace boost::python; template const std::string get_svg_transform(T& symbolizer) { - return symbolizer.get_transform_string(); + return symbolizer.get_image_transform_string(); } template @@ -46,12 +46,14 @@ void set_svg_transform(T& symbolizer, std::string const& transform_wkt) if (!mapnik::svg::parse_transform(transform_wkt.c_str(), tr)) { std::stringstream ss; - ss << "Could not parse transform from '" << transform_wkt << "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'"; + ss << "Could not parse transform from '" + << transform_wkt + << "', expected SVG transform attribute"; throw mapnik::value_error(ss.str()); } mapnik::transform_type matrix; tr.store_to(&matrix[0]); - symbolizer.set_transform(matrix); + symbolizer.set_image_transform(matrix); } } // end of namespace mapnik diff --git a/include/mapnik/symbolizer.hpp b/include/mapnik/symbolizer.hpp index 0e29f4b7e..42707854f 100644 --- a/include/mapnik/symbolizer.hpp +++ b/include/mapnik/symbolizer.hpp @@ -121,11 +121,15 @@ public: void set_filename(path_expression_ptr filename); void set_opacity(float opacity); float get_opacity() const; + void set_image_transform(transform_type const& tr); + transform_type const& get_image_transform() const; + std::string get_image_transform_string() const; protected: symbolizer_with_image(path_expression_ptr filename = path_expression_ptr()); symbolizer_with_image(symbolizer_with_image const& rhs); path_expression_ptr image_filename_; float image_opacity_; + transform_type image_transform_; }; } diff --git a/include/mapnik/symbolizer_helpers.hpp b/include/mapnik/symbolizer_helpers.hpp index 58063b6ab..2de2de4c1 100644 --- a/include/mapnik/symbolizer_helpers.hpp +++ b/include/mapnik/symbolizer_helpers.hpp @@ -153,7 +153,7 @@ public: bool next(); pixel_position get_marker_position(text_path const& p); marker & get_marker() const; - agg::trans_affine const& get_transform() const; + agg::trans_affine const& get_image_transform() const; protected: bool next_point_placement(); bool next_line_placement(); @@ -166,8 +166,7 @@ protected: double marker_h_; double marker_x_; double marker_y_; - // F***ing templates... - // http://womble.decadent.org.uk/c++/template-faq.html#base-lookup + using text_symbolizer_helper::geometries_to_process_; using text_symbolizer_helper::placement_; using text_symbolizer_helper::next_placement; diff --git a/src/agg/process_markers_symbolizer.cpp b/src/agg/process_markers_symbolizer.cpp index e42b69e5d..581933a2c 100644 --- a/src/agg/process_markers_symbolizer.cpp +++ b/src/agg/process_markers_symbolizer.cpp @@ -68,7 +68,7 @@ void agg_renderer::process(markers_symbolizer const& sym, renderer_base renb(pixf); renderer_solid ren(renb); agg::trans_affine tr; - boost::array const& m = sym.get_transform(); + boost::array const& m = sym.get_image_transform(); tr.load_from(&m[0]); tr = agg::trans_affine_scaling(scale_factor_) * tr; std::string filename = path_processor_type::evaluate(*sym.get_filename(), *feature); diff --git a/src/agg/process_point_symbolizer.cpp b/src/agg/process_point_symbolizer.cpp index 95f1eb490..4e98e1e28 100644 --- a/src/agg/process_point_symbolizer.cpp +++ b/src/agg/process_point_symbolizer.cpp @@ -66,7 +66,7 @@ void agg_renderer::process(point_symbolizer const& sym, double w = (*marker)->width(); double h = (*marker)->height(); agg::trans_affine tr; - boost::array const& m = sym.get_transform(); + boost::array const& m = sym.get_image_transform(); tr.load_from(&m[0]); double px0 = - 0.5 * w; double py0 = - 0.5 * h; diff --git a/src/agg/process_shield_symbolizer.cpp b/src/agg/process_shield_symbolizer.cpp index 5bbde8462..4cd416c74 100644 --- a/src/agg/process_shield_symbolizer.cpp +++ b/src/agg/process_shield_symbolizer.cpp @@ -54,7 +54,7 @@ void agg_renderer::process(shield_symbolizer const& sym, { render_marker(helper.get_marker_position(placements[ii]), helper.get_marker(), - helper.get_transform(), + helper.get_image_transform(), sym.get_opacity()); ren.prepare_glyphs(&(placements[ii])); diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index d1590c10f..f9ff96e52 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -1062,7 +1062,7 @@ void cairo_renderer_base::start_map_processing(Map const& map) detector_.has_placement(label_ext)) { agg::trans_affine mtx; - boost::array const& m = sym.get_transform(); + boost::array const& m = sym.get_image_transform(); mtx.load_from(&m[0]); render_marker(pixel_position(px,py),**marker, mtx, sym.get_opacity()); @@ -1097,7 +1097,7 @@ void cairo_renderer_base::start_map_processing(Map const& map) { pixel_position marker_pos = helper.get_marker_position(placements[ii]); render_marker(marker_pos, - helper.get_marker(), helper.get_transform(), + helper.get_marker(), helper.get_image_transform(), sym.get_opacity()); context.add_text(placements[ii], face_manager_, font_manager_); } @@ -1266,7 +1266,7 @@ void cairo_renderer_base::start_map_processing(Map const& map) typedef coord_transform2 path_type; agg::trans_affine tr; - boost::array const& m = sym.get_transform(); + boost::array const& m = sym.get_image_transform(); tr.load_from(&m[0]); // TODO - use this? //tr = agg::trans_affine_scaling(scale_factor_) * tr; diff --git a/src/grid/process_markers_symbolizer.cpp b/src/grid/process_markers_symbolizer.cpp index 7c57b80b4..6145c402d 100644 --- a/src/grid/process_markers_symbolizer.cpp +++ b/src/grid/process_markers_symbolizer.cpp @@ -69,7 +69,7 @@ void grid_renderer::process(markers_symbolizer const& sym, ras_ptr->reset(); agg::trans_affine tr; - boost::array const& m = sym.get_transform(); + boost::array const& m = sym.get_image_transform(); tr.load_from(&m[0]); tr = agg::trans_affine_scaling(scale_factor_*(1.0/pixmap_.get_resolution())) * tr; std::string filename = path_processor_type::evaluate(*sym.get_filename(), *feature); diff --git a/src/grid/process_point_symbolizer.cpp b/src/grid/process_point_symbolizer.cpp index 03d620e58..b5667469e 100644 --- a/src/grid/process_point_symbolizer.cpp +++ b/src/grid/process_point_symbolizer.cpp @@ -79,7 +79,7 @@ void grid_renderer::process(point_symbolizer const& sym, detector_.has_placement(label_ext)) { agg::trans_affine tr; - boost::array const& m = sym.get_transform(); + boost::array const& m = sym.get_image_transform(); tr.load_from(&m[0]); render_marker(feature, pixmap_.get_resolution(), diff --git a/src/grid/process_shield_symbolizer.cpp b/src/grid/process_shield_symbolizer.cpp index 91ad59c4d..bad6224c9 100644 --- a/src/grid/process_shield_symbolizer.cpp +++ b/src/grid/process_shield_symbolizer.cpp @@ -61,7 +61,7 @@ void grid_renderer::process(shield_symbolizer const& sym, { render_marker(feature, pixmap_.get_resolution(), helper.get_marker_position(placements[ii]), - helper.get_marker(), helper.get_transform(), + helper.get_marker(), helper.get_image_transform(), sym.get_opacity()); ren.prepare_glyphs(&(placements[ii])); diff --git a/src/load_map.cpp b/src/load_map.cpp index 57a33a5c5..da17cba8f 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -842,7 +842,7 @@ void map_parser::parse_metawriter_in_symbolizer(symbolizer_base &sym, xml_node c if (!mapnik::svg::parse_transform((*transform_wkt).c_str(),tr)) { std::stringstream ss; - ss << "Could not parse transform from '" << transform_wkt << "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'"; + ss << "Could not parse transform from '" << transform_wkt << "', expected SVG transform attribute"; if (strict_) throw config_error(ss.str()); // value_error here? else @@ -872,8 +872,6 @@ void map_parser::parse_point_symbolizer(rule & rule, xml_node const & sym) optional ignore_placement = sym.get_opt_attr("ignore-placement"); optional opacity = sym.get_opt_attr("opacity"); - //optional transform_wkt = sym.get_opt_attr("transform"); - point_symbolizer symbol; if (allow_overlap) { @@ -914,15 +912,15 @@ void map_parser::parse_point_symbolizer(rule & rule, xml_node const & sym) symbol.set_filename(expr); -#if 0 - if (transform_wkt) + optional image_transform_wkt = sym.get_opt_attr("image-transform"); + if (image_transform_wkt) { agg::trans_affine tr; - if (!mapnik::svg::parse_transform((*transform_wkt).c_str(),tr)) + if (!mapnik::svg::parse_transform((*image_transform_wkt).c_str(),tr)) { std::stringstream ss; - ss << "Could not parse transform from '" << transform_wkt - << "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'"; + ss << "Could not parse transform from '" << *image_transform_wkt + << "', expected SVG transform attribute"; if (strict_) { throw config_error(ss.str()); // value_error here? @@ -936,8 +934,6 @@ void map_parser::parse_point_symbolizer(rule & rule, xml_node const & sym) tr.store_to(&matrix[0]); symbol.set_transform(matrix); } -#endif - } catch (image_reader_exception const & ex) { @@ -971,7 +967,6 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym) std::string filename(""); optional file = sym.get_opt_attr("file"); optional base = sym.get_opt_attr("base"); - //optional transform_wkt = sym.get_opt_attr("transform"); if (file) { @@ -1011,15 +1006,16 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym) optional opacity = sym.get_opt_attr("opacity"); if (opacity) symbol.set_opacity(*opacity); -#if 0 - if (transform_wkt) + + optional image_transform_wkt = sym.get_opt_attr("image-transform"); + if (image_transform_wkt) { agg::trans_affine tr; - if (!mapnik::svg::parse_transform((*transform_wkt).c_str(),tr)) + if (!mapnik::svg::parse_transform((*image_transform_wkt).c_str(),tr)) { std::stringstream ss; - ss << "Could not parse transform from '" << transform_wkt - << "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'"; + ss << "Could not parse transform from '" << *image_transform_wkt + << "', expected SVG transform attribute"; if (strict_) { throw config_error(ss.str()); // value_error here? @@ -1033,8 +1029,7 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym) tr.store_to(&matrix[0]); symbol.set_transform(matrix); } -#endif - + optional c = sym.get_opt_attr("fill"); if (c) symbol.set_fill(*c); optional spacing = sym.get_opt_attr("spacing"); @@ -1256,16 +1251,16 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& sym) } shield_symbolizer shield_symbol = shield_symbolizer(placement_finder); - /* Symbolizer specific attributes. */ -#if 0 - optional transform_wkt = sym.get_opt_attr("transform"); - if (transform_wkt) + + optional image_transform_wkt = sym.get_opt_attr("image-transform"); + if (image_transform_wkt) { agg::trans_affine tr; - if (!mapnik::svg::parse_transform((*transform_wkt).c_str(),tr)) + if (!mapnik::svg::parse_transform((*image_transform_wkt).c_str(),tr)) { std::stringstream ss; - ss << "Could not parse transform from '" << transform_wkt << "', expected string like: 'matrix(1, 0, 0, 1, 0, 0)'"; + ss << "Could not parse transform from '" << *image_transform_wkt + << "', expected SVG transform attribute"; if (strict_) { throw config_error(ss.str()); // value_error here? @@ -1277,10 +1272,9 @@ void map_parser::parse_shield_symbolizer(rule & rule, xml_node const& sym) } boost::array matrix; tr.store_to(&matrix[0]); - shield_symbol.set_transform(matrix); + shield_symbol.set_image_transform(matrix); } -#endif - + // shield displacement double shield_dx = sym.get_attr("shield-dx", 0.0); double shield_dy = sym.get_attr("shield-dy", 0.0); diff --git a/src/symbolizer.cpp b/src/symbolizer.cpp index 95e2a615a..e8d43f90d 100644 --- a/src/symbolizer.cpp +++ b/src/symbolizer.cpp @@ -113,14 +113,22 @@ bool symbolizer_base::clip() const symbolizer_with_image::symbolizer_with_image(path_expression_ptr file) : image_filename_( file ), - image_opacity_(1.0f) - + image_opacity_(1.0f) { + image_transform_[0] = 1.0; + image_transform_[1] = 0.0; + image_transform_[2] = 0.0; + image_transform_[3] = 1.0; + image_transform_[4] = 0.0; + image_transform_[5] = 0.0; } symbolizer_with_image::symbolizer_with_image( symbolizer_with_image const& rhs) : image_filename_(rhs.image_filename_), - image_opacity_(rhs.image_opacity_) {} + image_opacity_(rhs.image_opacity_), + image_transform_(rhs.image_transform_) +{ +} path_expression_ptr symbolizer_with_image::get_filename() const { @@ -142,6 +150,25 @@ float symbolizer_with_image::get_opacity() const return image_opacity_; } +void symbolizer_with_image::set_image_transform(transform_type const& tr) +{ + image_transform_ = tr; +} + +transform_type const& symbolizer_with_image::get_image_transform() const +{ + return image_transform_; +} + +std::string symbolizer_with_image::get_image_transform_string() const +{ + std::stringstream ss; + ss << "matrix(" << image_transform_[0] << ", " << image_transform_[1] << ", " + << image_transform_[2] << ", " << image_transform_[3] << ", " + << image_transform_[4] << ", " << image_transform_[5] << ")"; + return ss.str(); +} + } // end of namespace mapnik diff --git a/src/symbolizer_helpers.cpp b/src/symbolizer_helpers.cpp index c468b6fea..85a27b088 100644 --- a/src/symbolizer_helpers.cpp +++ b/src/symbolizer_helpers.cpp @@ -350,7 +350,7 @@ template void shield_symbolizer_helper::init_marker() { std::string filename = path_processor_type::evaluate(*sym_.get_filename(), this->feature_); - boost::array const& m = sym_.get_transform(); + boost::array const& m = sym_.get_image_transform(); transform_.load_from(&m[0]); marker_.reset(); if (!filename.empty()) @@ -410,7 +410,7 @@ marker& shield_symbolizer_helper::get_marker() const } template -agg::trans_affine const& shield_symbolizer_helper::get_transform() const +agg::trans_affine const& shield_symbolizer_helper::get_image_transform() const { return transform_; }