avoid captures in displacement_evaluator

This commit is contained in:
artemp 2014-07-17 16:33:41 +01:00
parent 8eab2d31de
commit 79c1ac96b4
5 changed files with 18 additions and 37 deletions

View file

@ -80,7 +80,7 @@ struct MAPNIK_DECL text_layout_properties
// Get a list of all expressions used in any placement.
// This function is used to collect attributes.
void add_expressions(expression_set &output) const;
void add_expressions(expression_set & output) const;
//Per layout options
symbolizer_base::value_type dx;
@ -93,12 +93,9 @@ struct MAPNIK_DECL text_layout_properties
horizontal_alignment_e halign;
justify_alignment_e jalign;
vertical_alignment_e valign;
std::function<pixel_position(feature_impl const& feature, attributes const& attrs)> displacement_evaluator_ =
[this](feature_impl const& feature, attributes const& attrs)
{ double dx_ = boost::apply_visitor(extract_value<value_double>(feature,attrs), dx);
double dy_ = boost::apply_visitor(extract_value<value_double>(feature,attrs), dy);
return pixel_position(dx_,dy_);};
;
std::function<pixel_position(double,double)> displacement_evaluator_ =
[](double dx, double dy) { return pixel_position(dx,dy);};
};
class text_layout;

View file

@ -233,7 +233,9 @@ void text_layout::shape_text(text_line & line)
void text_layout::evaluate_properties(feature_impl const& feature, attributes const& attrs)
{
// dx,dy
displacement_ = properties_.displacement_evaluator_(feature, attrs);
double dx = boost::apply_visitor(extract_value<value_double>(feature,attrs), properties_.dx);
double dy = boost::apply_visitor(extract_value<value_double>(feature,attrs), properties_.dy);
displacement_ = properties_.displacement_evaluator_(dx,dy);
wrap_width_ = boost::apply_visitor(extract_value<value_double>(feature,attrs), properties_.wrap_width);

View file

@ -76,8 +76,8 @@ bool placement_finder::next_position()
}
text_layout_ptr layout = std::make_shared<text_layout>(font_manager_, scale_factor_, info_.properties.layout_defaults);
layout->evaluate_properties(feature_, attr_);
info_.properties.process(*layout, feature_, attr_);
layout->evaluate_properties(feature_, attr_);
layouts_.clear();
layouts_.add(layout);

View file

@ -40,12 +40,8 @@ bool text_placement_info_list::next()
{
if (state >= parent_->list_.size() + 1) return false;
properties = parent_->list_[state-1];
properties.layout_defaults.displacement_evaluator_ = [this](feature_impl const& feature, attributes const& attrs)
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
{
double dx = boost::apply_visitor(extract_value<value_double>(feature,attrs),
parent_->list_[state-1].layout_defaults.dx);
double dy = boost::apply_visitor(extract_value<value_double>(feature,attrs),
parent_->list_[state-1].layout_defaults.dy);
return pixel_position(dx,dy);
};
}

View file

@ -68,70 +68,56 @@ bool text_placement_info_simple::next_position_only()
switch (dir)
{
case EXACT_POSITION:
properties.layout_defaults.displacement_evaluator_ = [this](feature_impl const& feature, attributes const& attrs)
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
{
double dx = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dx);
double dy = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dy);
return pixel_position(dx,dy);
};
break;
case NORTH:
properties.layout_defaults.displacement_evaluator_ = [this](feature_impl const& feature, attributes const& attrs)
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
{
double dy = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dy);
return pixel_position(0,-std::abs(dy));
};
break;
case EAST:
properties.layout_defaults.displacement_evaluator_ = [this](feature_impl const& feature, attributes const& attrs)
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
{
double dx = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dx);
return pixel_position(std::abs(dx),0);
};
break;
case SOUTH:
properties.layout_defaults.displacement_evaluator_ = [this](feature_impl const& feature, attributes const& attrs)
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
{
double dy = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dy);
return pixel_position(0,std::abs(dy));
};
break;
case WEST:
properties.layout_defaults.displacement_evaluator_ = [this](feature_impl const& feature, attributes const& attrs)
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
{
double dx = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dx);
return pixel_position(-std::abs(dx),0);
};
break;
case NORTHEAST:
properties.layout_defaults.displacement_evaluator_ = [this](feature_impl const& feature, attributes const& attrs)
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
{
double dx = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dx);
double dy = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dy);
return pixel_position(std::abs(dx),-std::abs(dy));
};
break;
case SOUTHEAST:
properties.layout_defaults.displacement_evaluator_ = [this](feature_impl const& feature, attributes const& attrs)
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
{
double dx = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dx);
double dy = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dy);
return pixel_position(std::abs(dx),std::abs(dy));
};
break;
case NORTHWEST:
properties.layout_defaults.displacement_evaluator_ = [this](feature_impl const& feature, attributes const& attrs)
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
{
double dx = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dx);
double dy = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dy);
return pixel_position(-std::abs(dx),-std::abs(dy));
};
break;
case SOUTHWEST:
properties.layout_defaults.displacement_evaluator_ = [this](feature_impl const& feature, attributes const& attrs)
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
{
double dx = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dx);
double dy = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->parent_->defaults.layout_defaults.dy);
return pixel_position(-std::abs(dx),std::abs(dy));
};
break;