diff --git a/include/mapnik/text/formatting/base.hpp b/include/mapnik/text/formatting/base.hpp index bea75ce79..d63e99586 100644 --- a/include/mapnik/text/formatting/base.hpp +++ b/include/mapnik/text/formatting/base.hpp @@ -44,10 +44,10 @@ class MAPNIK_DECL node { public: virtual ~node() {} - virtual void to_xml(boost::property_tree::ptree &xml) const = 0; + virtual void to_xml(boost::property_tree::ptree & xml) const = 0; static node_ptr from_xml(xml_node const& xml); - virtual void apply(char_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout &output) const = 0; - virtual void add_expressions(expression_set &output) const = 0; + virtual void apply(char_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout & output) const = 0; + virtual void add_expressions(expression_set & output) const = 0; }; } //ns formatting } //ns mapnik diff --git a/include/mapnik/text/formatting/layout.hpp b/include/mapnik/text/formatting/layout.hpp index 30397d4d3..98d45c961 100644 --- a/include/mapnik/text/formatting/layout.hpp +++ b/include/mapnik/text/formatting/layout.hpp @@ -28,9 +28,10 @@ #include -namespace mapnik { -namespace formatting { -class MAPNIK_DECL layout_node: public node { +namespace mapnik { namespace formatting { + +class MAPNIK_DECL layout_node: public node +{ public: void to_xml(boost::property_tree::ptree &xml) const; static node_ptr from_xml(xml_node const& xml); @@ -38,16 +39,19 @@ public: virtual void add_expressions(expression_set &output) const; void set_child(node_ptr child); node_ptr get_child() const; + // + boost::optional dx; + boost::optional dy; - boost::optional dx; - boost::optional dy; boost::optional halign; boost::optional valign; boost::optional jalign; - boost::optional text_ratio; - boost::optional wrap_width; - boost::optional wrap_before; - boost::optional rotate_displacement; + + boost::optional text_ratio; + boost::optional wrap_width; + boost::optional wrap_before; + boost::optional rotate_displacement; + boost::optional orientation; private: diff --git a/src/text/formatting/layout.cpp b/src/text/formatting/layout.cpp index c947bfe0e..e31d94b6a 100644 --- a/src/text/formatting/layout.cpp +++ b/src/text/formatting/layout.cpp @@ -31,7 +31,7 @@ #include #include #include - +#include // boost #include @@ -44,15 +44,15 @@ void layout_node::to_xml(ptree &xml) const { ptree &new_node = xml.push_back(ptree::value_type("Layout", ptree()))->second; - if (dx) set_attr(new_node, "dx", *dx); - if (dy) set_attr(new_node, "dy", *dy); + //if (dx) set_attr(new_node, "dx", *dx); + //if (dy) set_attr(new_node, "dy", *dy); if (halign) set_attr(new_node, "horizontal-alignment", *halign); if (valign) set_attr(new_node, "vertical-alignment", *valign); if (jalign) set_attr(new_node, "justify-alignment", *jalign); - if (text_ratio) set_attr(new_node, "text-ratio", *text_ratio); - if (wrap_width) set_attr(new_node, "wrap-width", *wrap_width); - if (wrap_before) set_attr(new_node, "wrap-before", *wrap_before); - if (rotate_displacement) set_attr(new_node, "rotate-displacement", *rotate_displacement); + //if (text_ratio) set_attr(new_node, "text-ratio", *text_ratio); + //if (wrap_width) set_attr(new_node, "wrap-width", *wrap_width); + //if (wrap_before) set_attr(new_node, "wrap-before", *wrap_before); + //if (rotate_displacement) set_attr(new_node, "rotate-displacement", *rotate_displacement); if (orientation) set_attr(new_node, "orientation", to_expression_string(**orientation)); if (child_) child_->to_xml(new_node); @@ -65,15 +65,23 @@ node_ptr layout_node::from_xml(xml_node const& xml) node_ptr child = node::from_xml(xml); n->set_child(child); - n->dx = xml.get_opt_attr("dx"); - n->dy = xml.get_opt_attr("dy"); + if (xml.has_attribute("dx")) set_property_from_xml(n->dx, "dx", xml); + if (xml.has_attribute("dy")) set_property_from_xml(n->dy, "dy", xml); + if (xml.has_attribute("text-ratio")) set_property_from_xml(n->text_ratio, "text-ratio", xml); + if (xml.has_attribute("wrap-width")) set_property_from_xml(n->wrap_width, "wrap-width", xml); + if (xml.has_attribute("wrap-before")) set_property_from_xml(n->wrap_before, "wrap-before", xml); + if (xml.has_attribute("rotate-displacement")) set_property_from_xml(n->rotate_displacement, "rotate-displacement", xml); + + //if (xml.has_attribute("orientation")) set_property_from_xml(n->orientation, "orientation", xml); + //n->dx = xml.get_opt_attr("dx"); + //n->dy = xml.get_opt_attr("dy"); n->halign = xml.get_opt_attr("horizontal-alignment"); n->valign = xml.get_opt_attr("vertical-alignment"); n->jalign = xml.get_opt_attr("justify-alignment"); - n->text_ratio = xml.get_opt_attr("text-ratio"); - n->wrap_width = xml.get_opt_attr("wrap-width"); - n->wrap_before = xml.get_opt_attr("wrap-before"); - n->rotate_displacement = xml.get_opt_attr("rotate-displacement"); + //n->text_ratio = xml.get_opt_attr("text-ratio"); + //n->wrap_width = xml.get_opt_attr("wrap-width"); + //n->wrap_before = xml.get_opt_attr("wrap-before"); + //n->rotate_displacement = xml.get_opt_attr("rotate-displacement"); n->orientation = xml.get_opt_attr("orientation"); return n; @@ -93,14 +101,17 @@ void layout_node::apply(char_properties_ptr p, feature_impl const& feature, attr if (rotate_displacement) new_properties.rotate_displacement = *rotate_displacement; if (orientation) new_properties.orientation = *orientation; -// starting a new offset child with the new displacement value + // starting a new offset child with the new displacement value text_layout_ptr child_layout = std::make_shared(output.get_font_manager(), output.get_scale_factor(), new_properties); child_layout->evaluate_properties(feature,vars); // process contained format tree into the child node - if (child_) { + if (child_) + { child_->apply(p, feature, vars, *child_layout); - } else { + } + else + { MAPNIK_LOG_WARN(format) << "Useless layout node: Contains no text"; } output.add_child(child_layout); @@ -116,8 +127,16 @@ node_ptr layout_node::get_child() const return child_; } -void layout_node::add_expressions(expression_set &output) const +void layout_node::add_expressions(expression_set & output) const { + if (dx && is_expression(*dx)) output.insert(boost::get(*dx)); + if (dy && is_expression(*dy)) output.insert(boost::get(*dy)); + //if (orientation && is_expression(*orientation)) output.insert(boost::get(*orientation)); + if (wrap_width && is_expression(*wrap_width)) output.insert(boost::get(*wrap_width)); + if (wrap_before && is_expression(*wrap_before)) output.insert(boost::get(*wrap_before)); + if (rotate_displacement && is_expression(*rotate_displacement)) output.insert(boost::get(*rotate_displacement)); + if (text_ratio && is_expression(*text_ratio)) output.insert(boost::get(*text_ratio)); + // if (child_) child_->add_expressions(output); } diff --git a/src/text/placements/base.cpp b/src/text/placements/base.cpp index 13b1b697c..c46d54cbb 100644 --- a/src/text/placements/base.cpp +++ b/src/text/placements/base.cpp @@ -27,7 +27,7 @@ namespace mapnik { text_placements::text_placements() : defaults() {} -void text_placements::add_expressions(expression_set &output) const +void text_placements::add_expressions(expression_set & output) const { defaults.add_expressions(output); } diff --git a/src/text/text_properties.cpp b/src/text/text_properties.cpp index 0af551401..c63a500ec 100644 --- a/src/text/text_properties.cpp +++ b/src/text/text_properties.cpp @@ -32,7 +32,6 @@ #include // boost - #include namespace mapnik @@ -73,7 +72,7 @@ formatting::node_ptr text_symbolizer_properties::format_tree() const return tree_; } -void text_symbolizer_properties::placement_properties_from_xml(xml_node const &sym) +void text_symbolizer_properties::placement_properties_from_xml(xml_node const& sym) { optional placement_ = sym.get_opt_attr("placement"); if (placement_) label_placement = *placement_; @@ -179,7 +178,7 @@ void text_symbolizer_properties::to_xml(boost::property_tree::ptree &node, } -void text_symbolizer_properties::add_expressions(expression_set &output) const +void text_symbolizer_properties::add_expressions(expression_set & output) const { layout_defaults.add_expressions(output); if (tree_) tree_->add_expressions(output);