remove std::function usage in text_properties
This commit is contained in:
parent
f81fc53cbc
commit
e8b3083a6a
4 changed files with 51 additions and 79 deletions
|
@ -30,19 +30,6 @@ namespace mapnik {
|
|||
|
||||
class text_placement_info_simple;
|
||||
|
||||
enum directions_e
|
||||
{
|
||||
NORTH,
|
||||
EAST,
|
||||
SOUTH,
|
||||
WEST,
|
||||
NORTHEAST,
|
||||
SOUTHEAST,
|
||||
NORTHWEST,
|
||||
SOUTHWEST,
|
||||
EXACT_POSITION
|
||||
};
|
||||
|
||||
// Automatically generates placement options from a user selected list of directions and text sizes.
|
||||
class text_placements_simple: public text_placements
|
||||
{
|
||||
|
|
|
@ -35,10 +35,8 @@
|
|||
#include <mapnik/symbolizer_base.hpp>
|
||||
#include <mapnik/symbolizer_enumerations.hpp>
|
||||
#include <mapnik/noncopyable.hpp>
|
||||
|
||||
// stl
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
// boost
|
||||
#include <boost/optional.hpp>
|
||||
|
@ -81,6 +79,19 @@ struct evaluated_format_properties
|
|||
|
||||
}
|
||||
|
||||
enum directions_e
|
||||
{
|
||||
NORTH,
|
||||
EAST,
|
||||
SOUTH,
|
||||
WEST,
|
||||
NORTHEAST,
|
||||
SOUTHEAST,
|
||||
NORTHWEST,
|
||||
SOUTHWEST,
|
||||
EXACT_POSITION
|
||||
};
|
||||
|
||||
using fontset_map = std::map<std::string, font_set>;
|
||||
|
||||
struct MAPNIK_DECL format_properties
|
||||
|
@ -137,9 +148,7 @@ struct MAPNIK_DECL text_layout_properties
|
|||
symbolizer_base::value_type halign;
|
||||
symbolizer_base::value_type jalign;
|
||||
symbolizer_base::value_type valign;
|
||||
|
||||
std::function<pixel_position(double,double)> displacement_evaluator_ =
|
||||
[](double dx, double dy) { return pixel_position(dx,dy);};
|
||||
directions_e dir = EXACT_POSITION;
|
||||
};
|
||||
|
||||
struct text_properties_expressions
|
||||
|
|
|
@ -64,66 +64,8 @@ bool text_placement_info_simple::next()
|
|||
bool text_placement_info_simple::next_position_only()
|
||||
{
|
||||
if (position_state >= parent_->direction_.size()) return false;
|
||||
directions_e dir = parent_->direction_[position_state];
|
||||
switch (dir)
|
||||
{
|
||||
case EXACT_POSITION:
|
||||
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
|
||||
{
|
||||
return pixel_position(dx,dy);
|
||||
};
|
||||
break;
|
||||
case NORTH:
|
||||
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
|
||||
{
|
||||
return pixel_position(0,-std::abs(dy));
|
||||
};
|
||||
break;
|
||||
case EAST:
|
||||
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
|
||||
{
|
||||
return pixel_position(std::abs(dx),0);
|
||||
};
|
||||
break;
|
||||
case SOUTH:
|
||||
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
|
||||
{
|
||||
return pixel_position(0,std::abs(dy));
|
||||
};
|
||||
break;
|
||||
case WEST:
|
||||
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
|
||||
{
|
||||
return pixel_position(-std::abs(dx),0);
|
||||
};
|
||||
break;
|
||||
case NORTHEAST:
|
||||
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
|
||||
{
|
||||
return pixel_position(std::abs(dx),-std::abs(dy));
|
||||
};
|
||||
break;
|
||||
case SOUTHEAST:
|
||||
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
|
||||
{
|
||||
return pixel_position(std::abs(dx),std::abs(dy));
|
||||
};
|
||||
break;
|
||||
case NORTHWEST:
|
||||
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
|
||||
{
|
||||
return pixel_position(-std::abs(dx),-std::abs(dy));
|
||||
};
|
||||
break;
|
||||
case SOUTHWEST:
|
||||
properties.layout_defaults.displacement_evaluator_ = [](double dx, double dy)
|
||||
{
|
||||
return pixel_position(-std::abs(dx),std::abs(dy));
|
||||
};
|
||||
break;
|
||||
default:
|
||||
MAPNIK_LOG_WARN(text_placements) << "Unknown placement";
|
||||
}
|
||||
//directions_e dir = parent_->direction_[position_state];
|
||||
properties.layout_defaults.dir = parent_->direction_[position_state];
|
||||
++position_state;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -340,12 +340,46 @@ void text_layout::shape_text(text_line & line)
|
|||
harfbuzz_shaper::shape_text(line, itemizer_, width_map_, font_manager_, scale_factor_);
|
||||
}
|
||||
|
||||
pixel_position evaluate_displacement(double dx, double dy, directions_e dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case EXACT_POSITION:
|
||||
return pixel_position(dx,dy);
|
||||
break;
|
||||
case NORTH:
|
||||
return pixel_position(0,-std::abs(dy));
|
||||
break;
|
||||
case EAST:
|
||||
return pixel_position(std::abs(dx),0);
|
||||
break;
|
||||
case SOUTH:
|
||||
return pixel_position(0,std::abs(dy));
|
||||
break;
|
||||
case WEST:
|
||||
return pixel_position(-std::abs(dx),0);
|
||||
break;
|
||||
case NORTHEAST:
|
||||
return pixel_position(std::abs(dx),-std::abs(dy));
|
||||
break;
|
||||
case SOUTHEAST:
|
||||
return pixel_position(std::abs(dx),std::abs(dy));
|
||||
break;
|
||||
case NORTHWEST:
|
||||
return pixel_position(-std::abs(dx),-std::abs(dy));
|
||||
break;
|
||||
case SOUTHWEST:
|
||||
return pixel_position(-std::abs(dx),std::abs(dy));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void text_layout::evaluate_properties(feature_impl const& feature, attributes const& attrs)
|
||||
{
|
||||
// dx,dy
|
||||
double dx = util::apply_visitor(extract_value<value_double>(feature,attrs), properties_.dx);
|
||||
double dy = util::apply_visitor(extract_value<value_double>(feature,attrs), properties_.dy);
|
||||
displacement_ = properties_.displacement_evaluator_(dx,dy);
|
||||
displacement_ = evaluate_displacement(dx,dy, properties_.dir);
|
||||
std::string wrap_str = util::apply_visitor(extract_value<std::string>(feature,attrs), properties_.wrap_char);
|
||||
if (!wrap_str.empty()) wrap_char_ = wrap_str[0];
|
||||
wrap_width_ = util::apply_visitor(extract_value<value_double>(feature,attrs), properties_.wrap_width);
|
||||
|
|
Loading…
Reference in a new issue