#664 enable svg-style transforms to be set via python bindings. eg sym.transform = 'scale(0.4, 1.0) rotate(0.3)'

This commit is contained in:
Robert Coup 2010-11-29 20:58:30 +00:00
parent b24dd5df91
commit 91a0719778
6 changed files with 75 additions and 5 deletions

View file

@ -26,6 +26,7 @@
#include <mapnik/line_pattern_symbolizer.hpp> #include <mapnik/line_pattern_symbolizer.hpp>
#include <mapnik/parse_path.hpp> #include <mapnik/parse_path.hpp>
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include "mapnik_svg.hpp"
using mapnik::line_pattern_symbolizer; using mapnik::line_pattern_symbolizer;
using mapnik::path_processor_type; using mapnik::path_processor_type;
@ -52,5 +53,8 @@ void export_line_pattern_symbolizer()
init<path_expression_ptr> init<path_expression_ptr>
("<image file expression>")) ("<image file expression>"))
//.def_pickle(line_pattern_symbolizer_pickle_suite()) //.def_pickle(line_pattern_symbolizer_pickle_suite())
.add_property("transform",
mapnik::get_svg_transform<line_pattern_symbolizer>,
mapnik::set_svg_transform<line_pattern_symbolizer>)
; ;
} }

View file

@ -26,6 +26,7 @@
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/markers_symbolizer.hpp> #include <mapnik/markers_symbolizer.hpp>
#include <mapnik/parse_path.hpp> #include <mapnik/parse_path.hpp>
#include "mapnik_svg.hpp"
using mapnik::markers_symbolizer; using mapnik::markers_symbolizer;
using mapnik::symbolizer_with_image; using mapnik::symbolizer_with_image;
@ -107,5 +108,8 @@ void export_markers_symbolizer()
&markers_symbolizer::get_opacity, &markers_symbolizer::get_opacity,
&markers_symbolizer::set_opacity, &markers_symbolizer::set_opacity,
"Set/get the text opacity") "Set/get the text opacity")
.add_property("transform",
mapnik::get_svg_transform<markers_symbolizer>,
mapnik::set_svg_transform<markers_symbolizer>)
; ;
} }

View file

@ -26,6 +26,7 @@
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/point_symbolizer.hpp> #include <mapnik/point_symbolizer.hpp>
#include <mapnik/parse_path.hpp> #include <mapnik/parse_path.hpp>
#include "mapnik_svg.hpp"
using mapnik::point_symbolizer; using mapnik::point_symbolizer;
using mapnik::symbolizer_with_image; using mapnik::symbolizer_with_image;
@ -70,6 +71,7 @@ struct point_symbolizer_pickle_suite : boost::python::pickle_suite
namespace namespace
{ {
using namespace boost::python; using namespace boost::python;
const std::string get_filename(mapnik::point_symbolizer& symbolizer) const std::string get_filename(mapnik::point_symbolizer& symbolizer)
{ {
return path_processor_type::to_string(*symbolizer.get_filename()); return path_processor_type::to_string(*symbolizer.get_filename());
@ -99,5 +101,8 @@ void export_point_symbolizer()
.add_property("ignore_placement", .add_property("ignore_placement",
&point_symbolizer::get_ignore_placement, &point_symbolizer::get_ignore_placement,
&point_symbolizer::set_ignore_placement) &point_symbolizer::set_ignore_placement)
.add_property("transform",
mapnik::get_svg_transform<point_symbolizer>,
mapnik::set_svg_transform<point_symbolizer>)
; ;
} }

View file

@ -26,6 +26,7 @@
#include <mapnik/polygon_pattern_symbolizer.hpp> #include <mapnik/polygon_pattern_symbolizer.hpp>
#include "mapnik_enumeration.hpp" #include "mapnik_enumeration.hpp"
#include <mapnik/parse_path.hpp> #include <mapnik/parse_path.hpp>
#include "mapnik_svg.hpp"
using namespace mapnik; using namespace mapnik;
using mapnik::polygon_pattern_symbolizer; using mapnik::polygon_pattern_symbolizer;
@ -82,6 +83,8 @@ void export_polygon_pattern_symbolizer()
&polygon_pattern_symbolizer::get_alignment, &polygon_pattern_symbolizer::get_alignment,
&polygon_pattern_symbolizer::set_alignment, &polygon_pattern_symbolizer::set_alignment,
"Set/get the alignment of the pattern") "Set/get the alignment of the pattern")
.add_property("transform",
mapnik::get_svg_transform<polygon_pattern_symbolizer>,
mapnik::set_svg_transform<polygon_pattern_symbolizer>)
; ;
} }

View file

@ -26,6 +26,7 @@
#include <mapnik/shield_symbolizer.hpp> #include <mapnik/shield_symbolizer.hpp>
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/path_expression_grammar.hpp> #include <mapnik/path_expression_grammar.hpp>
#include "mapnik_svg.hpp"
using mapnik::color; using mapnik::color;
using mapnik::shield_symbolizer; using mapnik::shield_symbolizer;
@ -218,9 +219,9 @@ void export_shield_symbolizer()
.add_property("filename", .add_property("filename",
get_filename, get_filename,
&shield_symbolizer::set_filename) &shield_symbolizer::set_filename)
//.add_property("transform", .add_property("transform",
// &shield_symbolizer::get_transform, mapnik::get_svg_transform<shield_symbolizer>,
// &shield_symbolizer::set_transform) mapnik::set_svg_transform<shield_symbolizer>)
; ;

View file

@ -0,0 +1,53 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2010 Robert Coup
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MAPNIK_PYTHON_BINDING_SVG_INCLUDED
#define MAPNIK_PYTHON_BINDING_SVG_INCLUDED
#include <mapnik/symbolizer.hpp>
#include <mapnik/svg/svg_path_parser.hpp>
#include <boost/format.hpp>
#include "agg_trans_affine.h"
namespace mapnik {
using namespace boost::python;
template <class T>
const std::string get_svg_transform(T& symbolizer)
{
mapnik::transform_type matrix = symbolizer.get_transform();
std::string s = (boost::format("matrix(%f, %f, %f, %f, %f, %f)") % matrix[0] % matrix[1] % matrix[2] % matrix[3] % matrix[4] % matrix[5]).str();
return s;
};
template <class T>
void set_svg_transform(T& symbolizer, std::string const& transform_wkt)
{
agg::trans_affine tr;
mapnik::svg::parse_transform(transform_wkt, tr);
mapnik::transform_type matrix;
tr.store_to(&matrix[0]);
symbolizer.set_transform(matrix);
};
} // end of namespace mapnik
#endif // MAPNIK_PYTHON_BINDING_SVG_INCLUDED