diff --git a/include/mapnik/text/placements/simple.hpp b/include/mapnik/text/placements/simple.hpp index ca2b13c8d..b84b4f8cf 100644 --- a/include/mapnik/text/placements/simple.hpp +++ b/include/mapnik/text/placements/simple.hpp @@ -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 { diff --git a/include/mapnik/text/text_properties.hpp b/include/mapnik/text/text_properties.hpp index 20a0b23fa..cd5af9726 100644 --- a/include/mapnik/text/text_properties.hpp +++ b/include/mapnik/text/text_properties.hpp @@ -35,10 +35,8 @@ #include #include #include - // stl #include -#include // boost #include @@ -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; 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 displacement_evaluator_ = - [](double dx, double dy) { return pixel_position(dx,dy);}; + directions_e dir = EXACT_POSITION; }; struct text_properties_expressions diff --git a/src/text/placements/simple.cpp b/src/text/placements/simple.cpp index ba1660d6d..2b89d9211 100644 --- a/src/text/placements/simple.cpp +++ b/src/text/placements/simple.cpp @@ -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; } diff --git a/src/text/text_layout.cpp b/src/text/text_layout.cpp index cf8ebca75..a1d8ff9ba 100644 --- a/src/text/text_layout.cpp +++ b/src/text/text_layout.cpp @@ -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(feature,attrs), properties_.dx); double dy = util::apply_visitor(extract_value(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(feature,attrs), properties_.wrap_char); if (!wrap_str.empty()) wrap_char_ = wrap_str[0]; wrap_width_ = util::apply_visitor(extract_value(feature,attrs), properties_.wrap_width);