diff --git a/include/mapnik/text/text_properties.hpp b/include/mapnik/text/text_properties.hpp index cb0ea6754..e4015f9c0 100644 --- a/include/mapnik/text/text_properties.hpp +++ b/include/mapnik/text/text_properties.hpp @@ -93,7 +93,12 @@ struct MAPNIK_DECL text_layout_properties horizontal_alignment_e halign; justify_alignment_e jalign; vertical_alignment_e valign; - std::function displacement_evaluator_; + std::function displacement_evaluator_ = + [this](feature_impl const& feature, attributes const& attrs) + { double dx_ = boost::apply_visitor(extract_value(feature,attrs), dx); + double dy_ = boost::apply_visitor(extract_value(feature,attrs), dy); + return pixel_position(dx_,dy_);}; +; }; using text_layout_properties_ptr = std::shared_ptr; @@ -107,9 +112,9 @@ struct MAPNIK_DECL text_symbolizer_properties // Load only placement related values from XML ptree. void placement_properties_from_xml(xml_node const& sym); // Load all values from XML ptree. - void from_xml(xml_node const &sym, fontset_map const& fontsets); + void from_xml(xml_node const& node, fontset_map const& fontsets); // Save all values to XML ptree (but does not create a new parent node!). - void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, + void to_xml(boost::property_tree::ptree & node, bool explicit_defaults, text_symbolizer_properties const& dfl = text_symbolizer_properties()) const; // Takes a feature and produces formated text as output. @@ -123,7 +128,7 @@ struct MAPNIK_DECL text_symbolizer_properties formatting::node_ptr format_tree() const; // 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 symbolizer options label_placement_e label_placement; diff --git a/src/text/layout.cpp b/src/text/layout.cpp index 9d05e8fb5..772be2574 100644 --- a/src/text/layout.cpp +++ b/src/text/layout.cpp @@ -92,7 +92,6 @@ void text_layout::layout() init_alignment(); // Find text origin. - std::cerr << displacement_.x << "," << displacement_.y << " " << this << std::endl; displacement_ = scale_factor_ * displacement_ + alignment_offset(); if (rotate_displacement_) displacement_ = displacement_.rotate(!orientation_); // Find layout bounds, expanded for rotation diff --git a/src/text/placement_finder.cpp b/src/text/placement_finder.cpp index 871e6eaf4..0902428e5 100644 --- a/src/text/placement_finder.cpp +++ b/src/text/placement_finder.cpp @@ -354,12 +354,8 @@ bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e or void placement_finder::path_move_dx(vertex_cache & pp, double dx) { - //double dx = 0.0;// FIXME info_.properties.layout_defaults.displacement.x * scale_factor_; -// if (dx != 0.0) - // { - vertex_cache::state state = pp.save_state(); - if (!pp.move(dx)) pp.restore_state(state); - //} + vertex_cache::state state = pp.save_state(); + if (!pp.move(dx)) pp.restore_state(state); } double placement_finder::normalize_angle(double angle) diff --git a/src/text/placements/list.cpp b/src/text/placements/list.cpp index 96475881a..3e94a44eb 100644 --- a/src/text/placements/list.cpp +++ b/src/text/placements/list.cpp @@ -32,11 +32,22 @@ namespace mapnik bool text_placement_info_list::next() { - if (state == 0) { + if (state == 0) + { properties = parent_->defaults; - } else { - if (state >= parent_->list_.size() + 1) return false; + } + else + { + 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) + { + double dx = boost::apply_visitor(extract_value(feature,attrs), + parent_->list_[state-1].layout_defaults.dx); + double dy = boost::apply_visitor(extract_value(feature,attrs), + parent_->list_[state-1].layout_defaults.dy); + return pixel_position(dx,dy); + }; } ++state; return true; @@ -71,11 +82,9 @@ text_placements_list::text_placements_list() void text_placements_list::add_expressions(expression_set & output) const { defaults.add_expressions(output); - - std::vector::const_iterator it; - for (it=list_.begin(); it != list_.end(); it++) + for (auto & prop : list_) { - it->add_expressions(output); + prop.add_expressions(output); } } @@ -87,24 +96,24 @@ unsigned text_placements_list::size() const text_placements_ptr text_placements_list::from_xml(xml_node const& xml, fontset_map const & fontsets) { using boost::property_tree::ptree; - text_placements_list *list = new text_placements_list; - text_placements_ptr ptr = text_placements_ptr(list); + auto list = std::make_shared(); + list->defaults.from_xml(xml, fontsets); - xml_node::const_iterator itr = xml.begin(); - xml_node::const_iterator end = xml.end(); - for( ;itr != end; ++itr) + for (auto const& node : xml) { - if (itr->is_text() || !itr->is("Placement")) continue; + if (node.is_text() || !node.is("Placement")) continue; text_symbolizer_properties & p = list->add(); - p.format = std::make_shared(*(p.format)); //Make a deep copy + p.format = std::make_shared(*(p.format)); //Make a deep copy <-- FIXME + //p.layout_defaults = std::make_shared(*(p.layout_defaults)); //TODO: This needs a real copy constructor for text_symbolizer_properties - p.from_xml(*itr, fontsets); -//TODO: if (strict_ && + p.from_xml(node, fontsets); + +//TODO: if (strict_ && // !p.format.fontset.size()) // ensure_font_face(p.format.face_name); } - return ptr; + return list; } } //ns mapnik diff --git a/src/text/text_properties.cpp b/src/text/text_properties.cpp index 3feae7af7..d3774d976 100644 --- a/src/text/text_properties.cpp +++ b/src/text/text_properties.cpp @@ -200,7 +200,6 @@ void set_property_from_xml(symbolizer_base::value_type & val, char const* name, try { optional val_ = node.get_opt_attr(name); - if (val_) std::cerr << std::string(name) << ":" << *val_ << std::endl; if (val_) val = *val_; } catch (config_error const& ex) @@ -218,31 +217,24 @@ text_layout_properties::text_layout_properties() : halign(H_AUTO), jalign(J_AUTO), valign(V_AUTO) -{ - displacement_evaluator_ = [this](feature_impl const& feature, attributes const& attrs) - { double dx_ = boost::apply_visitor(extract_value(feature,attrs), this->dx); - double dy_ = boost::apply_visitor(extract_value(feature,attrs), this->dy); - std::cerr << dx_ << "," << dy_ << std::endl; - return pixel_position(dx_,dy_);}; - -} +{} void text_layout_properties::from_xml(xml_node const &node) { set_property_from_xml(dx, "dx", node); set_property_from_xml(dy, "dy", node); + set_property_from_xml(text_ratio, "text-ratio", node); + set_property_from_xml(wrap_width, "wrap-width", node); + set_property_from_xml(wrap_before, "wrap-before", node); + set_property_from_xml(rotate_displacement, "rotate-displacement", node); + set_property_from_xml(orientation, "orientation", node); + // optional valign_ = node.get_opt_attr("vertical-alignment"); if (valign_) valign = *valign_; optional halign_ = node.get_opt_attr("horizontal-alignment"); if (halign_) halign = *halign_; optional jalign_ = node.get_opt_attr("justify-alignment"); if (jalign_) jalign = *jalign_; - - set_property_from_xml(text_ratio, "text-ratio", node); - set_property_from_xml(wrap_width, "wrap-width", node); - set_property_from_xml(wrap_before, "wrap-before", node); - set_property_from_xml(rotate_displacement, "rotate-displacement", node); - set_property_from_xml(orientation, "orientation", node); } void text_layout_properties::to_xml(boost::property_tree::ptree & node,