expressions in text/formatting/layout (work-in-progress)

This commit is contained in:
artemp 2014-07-18 11:18:54 +01:00
parent f9ed5d4027
commit 594470ee17
5 changed files with 55 additions and 33 deletions

View file

@ -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

View file

@ -28,9 +28,10 @@
#include <boost/optional.hpp>
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<symbolizer_base::value_type> dx;
boost::optional<symbolizer_base::value_type> dy;
boost::optional<double> dx;
boost::optional<double> dy;
boost::optional<horizontal_alignment_e> halign;
boost::optional<vertical_alignment_e> valign;
boost::optional<justify_alignment_e> jalign;
boost::optional<double> text_ratio;
boost::optional<double> wrap_width;
boost::optional<bool> wrap_before;
boost::optional<bool> rotate_displacement;
boost::optional<symbolizer_base::value_type> text_ratio;
boost::optional<symbolizer_base::value_type> wrap_width;
boost::optional<symbolizer_base::value_type> wrap_before;
boost::optional<symbolizer_base::value_type> rotate_displacement;
boost::optional<expression_ptr> orientation;
private:

View file

@ -31,7 +31,7 @@
#include <mapnik/xml_node.hpp>
#include <mapnik/config_error.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/text/properties_util.hpp>
// boost
#include <boost/property_tree/ptree.hpp>
@ -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<double>("dx");
n->dy = xml.get_opt_attr<double>("dy");
if (xml.has_attribute("dx")) set_property_from_xml<double>(n->dx, "dx", xml);
if (xml.has_attribute("dy")) set_property_from_xml<double>(n->dy, "dy", xml);
if (xml.has_attribute("text-ratio")) set_property_from_xml<double>(n->text_ratio, "text-ratio", xml);
if (xml.has_attribute("wrap-width")) set_property_from_xml<double>(n->wrap_width, "wrap-width", xml);
if (xml.has_attribute("wrap-before")) set_property_from_xml<boolean>(n->wrap_before, "wrap-before", xml);
if (xml.has_attribute("rotate-displacement")) set_property_from_xml<boolean>(n->rotate_displacement, "rotate-displacement", xml);
//if (xml.has_attribute("orientation")) set_property_from_xml<double>(n->orientation, "orientation", xml);
//n->dx = xml.get_opt_attr<double>("dx");
//n->dy = xml.get_opt_attr<double>("dy");
n->halign = xml.get_opt_attr<horizontal_alignment_e>("horizontal-alignment");
n->valign = xml.get_opt_attr<vertical_alignment_e>("vertical-alignment");
n->jalign = xml.get_opt_attr<justify_alignment_e>("justify-alignment");
n->text_ratio = xml.get_opt_attr<double>("text-ratio");
n->wrap_width = xml.get_opt_attr<double>("wrap-width");
n->wrap_before = xml.get_opt_attr<boolean>("wrap-before");
n->rotate_displacement = xml.get_opt_attr<boolean>("rotate-displacement");
//n->text_ratio = xml.get_opt_attr<double>("text-ratio");
//n->wrap_width = xml.get_opt_attr<double>("wrap-width");
//n->wrap_before = xml.get_opt_attr<boolean>("wrap-before");
//n->rotate_displacement = xml.get_opt_attr<boolean>("rotate-displacement");
n->orientation = xml.get_opt_attr<expression_ptr>("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<text_layout>(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<expression_ptr>(*dx));
if (dy && is_expression(*dy)) output.insert(boost::get<expression_ptr>(*dy));
//if (orientation && is_expression(*orientation)) output.insert(boost::get<expression_ptr>(*orientation));
if (wrap_width && is_expression(*wrap_width)) output.insert(boost::get<expression_ptr>(*wrap_width));
if (wrap_before && is_expression(*wrap_before)) output.insert(boost::get<expression_ptr>(*wrap_before));
if (rotate_displacement && is_expression(*rotate_displacement)) output.insert(boost::get<expression_ptr>(*rotate_displacement));
if (text_ratio && is_expression(*text_ratio)) output.insert(boost::get<expression_ptr>(*text_ratio));
//
if (child_) child_->add_expressions(output);
}

View file

@ -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);
}

View file

@ -32,7 +32,6 @@
#include <mapnik/text/properties_util.hpp>
// boost
#include <boost/property_tree/ptree.hpp>
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<label_placement_e> placement_ = sym.get_opt_attr<label_placement_e>("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);