Permalink
Browse files

new feature: transform expressions are now dynamic

  • Loading branch information...
1 parent f0976aa commit 173c402b5c142310087246b0ea54dbec54edcac8 @lightmare lightmare committed May 27, 2012
@@ -23,10 +23,14 @@
#define MAPNIK_PYTHON_BINDING_SVG_INCLUDED
// mapnik
+#include <mapnik/parse_transform.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/svg/svg_path_parser.hpp>
#include <mapnik/value_error.hpp>
+// boost
+#include <boost/make_shared.hpp>
+
// agg
#include "agg_trans_affine.h"
@@ -51,9 +55,9 @@ void set_svg_transform(T& symbolizer, std::string const& transform_wkt)
<< "', expected SVG transform attribute";
throw mapnik::value_error(ss.str());
}
- mapnik::transform_type matrix;
- tr.store_to(&matrix[0]);
- symbolizer.set_image_transform(matrix);
+ transform_list_ptr trans = boost::make_shared<transform_list>();
+ trans->push_back(matrix_node(tr));
+ symbolizer.set_image_transform(trans);
}
} // end of namespace mapnik
@@ -115,6 +115,13 @@ class MAPNIK_DECL agg_renderer : public feature_style_processor<agg_renderer<T>
void painted(bool painted);
+protected:
+ template <typename R>
+ void debug_draw_box(R& buf, box2d<double> const& extent,
+ double x, double y, double angle = 0.0);
+ void debug_draw_box(box2d<double> const& extent,
+ double x, double y, double angle = 0.0);
+
private:
buffer_type & pixmap_;
boost::shared_ptr<buffer_type> internal_buffer_;
@@ -25,6 +25,7 @@
// mapnik
#include <mapnik/rule.hpp>
+#include <mapnik/parse_transform.hpp>
// boost
#include <boost/utility.hpp>
#include <boost/variant.hpp>
@@ -35,9 +36,10 @@
namespace mapnik {
+template <typename Container>
struct expression_attributes : boost::static_visitor<void>
{
- explicit expression_attributes(std::set<std::string> & names)
+ explicit expression_attributes(Container& names)
: names_(names) {}
void operator() (value_type const& x) const
@@ -53,35 +55,35 @@ struct expression_attributes : boost::static_visitor<void>
template <typename Tag>
void operator() (binary_node<Tag> const& x) const
{
- boost::apply_visitor(expression_attributes(names_),x.left);
- boost::apply_visitor(expression_attributes(names_),x.right);
+ boost::apply_visitor(*this, x.left);
+ boost::apply_visitor(*this, x.right);
}
template <typename Tag>
void operator() (unary_node<Tag> const& x) const
{
- boost::apply_visitor(expression_attributes(names_),x.expr);
+ boost::apply_visitor(*this, x.expr);
}
void operator() (regex_match_node const& x) const
{
- boost::apply_visitor(expression_attributes(names_),x.expr);
+ boost::apply_visitor(*this, x.expr);
}
void operator() (regex_replace_node const& x) const
{
- boost::apply_visitor(expression_attributes(names_),x.expr);
+ boost::apply_visitor(*this, x.expr);
}
private:
- std::set<std::string>& names_;
+ Container& names_;
};
struct symbolizer_attributes : public boost::static_visitor<>
{
symbolizer_attributes(std::set<std::string>& names)
- : names_(names) {}
+ : names_(names), f_attr(names) {}
template <typename T>
void operator () (T const&) const {}
@@ -91,12 +93,12 @@ struct symbolizer_attributes : public boost::static_visitor<>
expression_set::const_iterator it;
expression_set expressions;
sym.get_placement_options()->add_expressions(expressions);
- expression_attributes f_attr(names_);
for (it=expressions.begin(); it != expressions.end(); it++)
{
if (*it) boost::apply_visitor(f_attr, **it);
}
collect_metawriter(sym);
+ collect_transform(sym.get_transform());
}
void operator () (point_symbolizer const& sym)
@@ -107,12 +109,14 @@ struct symbolizer_attributes : public boost::static_visitor<>
path_processor_type::collect_attributes(*filename_expr,names_);
}
collect_metawriter(sym);
-
+ collect_transform(sym.get_image_transform());
+ collect_transform(sym.get_transform());
}
void operator () (line_symbolizer const& sym)
{
collect_metawriter(sym);
+ collect_transform(sym.get_transform());
}
void operator () (line_pattern_symbolizer const& sym)
@@ -123,11 +127,14 @@ struct symbolizer_attributes : public boost::static_visitor<>
path_processor_type::collect_attributes(*filename_expr,names_);
}
collect_metawriter(sym);
+ collect_transform(sym.get_image_transform());
+ collect_transform(sym.get_transform());
}
void operator () (polygon_symbolizer const& sym)
{
collect_metawriter(sym);
+ collect_transform(sym.get_transform());
}
void operator () (polygon_pattern_symbolizer const& sym)
@@ -138,14 +145,15 @@ struct symbolizer_attributes : public boost::static_visitor<>
path_processor_type::collect_attributes(*filename_expr,names_);
}
collect_metawriter(sym);
+ collect_transform(sym.get_image_transform());
+ collect_transform(sym.get_transform());
}
void operator () (shield_symbolizer const& sym)
{
expression_set::const_iterator it;
expression_set expressions;
sym.get_placement_options()->add_expressions(expressions);
- expression_attributes f_attr(names_);
for (it=expressions.begin(); it != expressions.end(); it++)
{
if (*it) boost::apply_visitor(f_attr, **it);
@@ -157,43 +165,56 @@ struct symbolizer_attributes : public boost::static_visitor<>
path_processor_type::collect_attributes(*filename_expr,names_);
}
collect_metawriter(sym);
+ collect_transform(sym.get_image_transform());
+ collect_transform(sym.get_transform());
}
void operator () (markers_symbolizer const& sym)
{
collect_metawriter(sym);
+ collect_transform(sym.get_image_transform());
+ collect_transform(sym.get_transform());
}
void operator () (building_symbolizer const& sym)
{
expression_ptr const& height_expr = sym.height();
if (height_expr)
{
- expression_attributes f_attr(names_);
boost::apply_visitor(f_attr,*height_expr);
}
collect_metawriter(sym);
+ collect_transform(sym.get_transform());
}
// TODO - support remaining syms
private:
std::set<std::string>& names_;
+ expression_attributes<std::set<std::string> > f_attr;
void collect_metawriter(symbolizer_base const& sym)
{
metawriter_properties const& properties = sym.get_metawriter_properties();
names_.insert(properties.begin(), properties.end());
}
+ void collect_transform(transform_list_ptr const& trans_expr)
+ {
+ if (trans_expr)
+ {
+ transform_processor_type::collect_attributes(names_, *trans_expr);
+ }
+ }
};
class attribute_collector : public boost::noncopyable
{
private:
std::set<std::string>& names_;
+ expression_attributes<std::set<std::string> > f_attr;
public:
attribute_collector(std::set<std::string>& names)
- : names_(names) {}
+ : names_(names), f_attr(names) {}
template <typename RuleType>
void operator() (RuleType const& r)
@@ -207,7 +228,6 @@ class attribute_collector : public boost::noncopyable
}
expression_ptr const& expr = r.get_filter();
- expression_attributes f_attr(names_);
boost::apply_visitor(f_attr,*expr);
}
};
@@ -79,6 +79,21 @@ class marker
{
}
+ box2d<double> bounding_box() const
+ {
+ if (is_vector())
+ {
+ return (*vector_data_)->bounding_box();
+ }
+ if (is_bitmap())
+ {
+ double width = (*bitmap_data_)->width();
+ double height = (*bitmap_data_)->height();
+ return box2d<double>(0, 0, width, height);
+ }
+ return box2d<double>();
+ }
+
inline double width() const
{
if (is_bitmap())
Oops, something went wrong. Retry.

0 comments on commit 173c402

Please sign in to comment.