move displacement_evaluator_ initialisation
c++ style fixes
This commit is contained in:
parent
4166fcdd5d
commit
8a01cce2f7
5 changed files with 44 additions and 43 deletions
|
@ -93,7 +93,12 @@ struct MAPNIK_DECL text_layout_properties
|
||||||
horizontal_alignment_e halign;
|
horizontal_alignment_e halign;
|
||||||
justify_alignment_e jalign;
|
justify_alignment_e jalign;
|
||||||
vertical_alignment_e valign;
|
vertical_alignment_e valign;
|
||||||
std::function<pixel_position(feature_impl const& feature, attributes const& attrs)> displacement_evaluator_;
|
std::function<pixel_position(feature_impl const& feature, attributes const& attrs)> displacement_evaluator_ =
|
||||||
|
[this](feature_impl const& feature, attributes const& attrs)
|
||||||
|
{ double dx_ = boost::apply_visitor(extract_value<value_double>(feature,attrs), dx);
|
||||||
|
double dy_ = boost::apply_visitor(extract_value<value_double>(feature,attrs), dy);
|
||||||
|
return pixel_position(dx_,dy_);};
|
||||||
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
using text_layout_properties_ptr = std::shared_ptr<text_layout_properties>;
|
using text_layout_properties_ptr = std::shared_ptr<text_layout_properties>;
|
||||||
|
@ -107,7 +112,7 @@ struct MAPNIK_DECL text_symbolizer_properties
|
||||||
// Load only placement related values from XML ptree.
|
// Load only placement related values from XML ptree.
|
||||||
void placement_properties_from_xml(xml_node const& sym);
|
void placement_properties_from_xml(xml_node const& sym);
|
||||||
// Load all values from XML ptree.
|
// 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!).
|
// 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;
|
text_symbolizer_properties const& dfl = text_symbolizer_properties()) const;
|
||||||
|
|
|
@ -92,7 +92,6 @@ void text_layout::layout()
|
||||||
init_alignment();
|
init_alignment();
|
||||||
|
|
||||||
// Find text origin.
|
// Find text origin.
|
||||||
std::cerr << displacement_.x << "," << displacement_.y << " " << this << std::endl;
|
|
||||||
displacement_ = scale_factor_ * displacement_ + alignment_offset();
|
displacement_ = scale_factor_ * displacement_ + alignment_offset();
|
||||||
if (rotate_displacement_) displacement_ = displacement_.rotate(!orientation_);
|
if (rotate_displacement_) displacement_ = displacement_.rotate(!orientation_);
|
||||||
// Find layout bounds, expanded for rotation
|
// Find layout bounds, expanded for rotation
|
||||||
|
|
|
@ -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)
|
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();
|
vertex_cache::state state = pp.save_state();
|
||||||
if (!pp.move(dx)) pp.restore_state(state);
|
if (!pp.move(dx)) pp.restore_state(state);
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double placement_finder::normalize_angle(double angle)
|
double placement_finder::normalize_angle(double angle)
|
||||||
|
|
|
@ -32,11 +32,22 @@ namespace mapnik
|
||||||
|
|
||||||
bool text_placement_info_list::next()
|
bool text_placement_info_list::next()
|
||||||
{
|
{
|
||||||
if (state == 0) {
|
if (state == 0)
|
||||||
|
{
|
||||||
properties = parent_->defaults;
|
properties = parent_->defaults;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (state >= parent_->list_.size() + 1) return false;
|
if (state >= parent_->list_.size() + 1) return false;
|
||||||
properties = parent_->list_[state-1];
|
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<value_double>(feature,attrs),
|
||||||
|
parent_->list_[state-1].layout_defaults.dx);
|
||||||
|
double dy = boost::apply_visitor(extract_value<value_double>(feature,attrs),
|
||||||
|
parent_->list_[state-1].layout_defaults.dy);
|
||||||
|
return pixel_position(dx,dy);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
++state;
|
++state;
|
||||||
return true;
|
return true;
|
||||||
|
@ -71,11 +82,9 @@ text_placements_list::text_placements_list()
|
||||||
void text_placements_list::add_expressions(expression_set & output) const
|
void text_placements_list::add_expressions(expression_set & output) const
|
||||||
{
|
{
|
||||||
defaults.add_expressions(output);
|
defaults.add_expressions(output);
|
||||||
|
for (auto & prop : list_)
|
||||||
std::vector<text_symbolizer_properties>::const_iterator it;
|
|
||||||
for (it=list_.begin(); it != list_.end(); it++)
|
|
||||||
{
|
{
|
||||||
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)
|
text_placements_ptr text_placements_list::from_xml(xml_node const& xml, fontset_map const & fontsets)
|
||||||
{
|
{
|
||||||
using boost::property_tree::ptree;
|
using boost::property_tree::ptree;
|
||||||
text_placements_list *list = new text_placements_list;
|
auto list = std::make_shared<text_placements_list>();
|
||||||
text_placements_ptr ptr = text_placements_ptr(list);
|
|
||||||
list->defaults.from_xml(xml, fontsets);
|
list->defaults.from_xml(xml, fontsets);
|
||||||
xml_node::const_iterator itr = xml.begin();
|
for (auto const& node : xml)
|
||||||
xml_node::const_iterator end = xml.end();
|
|
||||||
for( ;itr != end; ++itr)
|
|
||||||
{
|
{
|
||||||
if (itr->is_text() || !itr->is("Placement")) continue;
|
if (node.is_text() || !node.is("Placement")) continue;
|
||||||
text_symbolizer_properties & p = list->add();
|
text_symbolizer_properties & p = list->add();
|
||||||
p.format = std::make_shared<char_properties>(*(p.format)); //Make a deep copy
|
p.format = std::make_shared<char_properties>(*(p.format)); //Make a deep copy <-- FIXME
|
||||||
|
|
||||||
//p.layout_defaults = std::make_shared<text_layout_properties>(*(p.layout_defaults));
|
//p.layout_defaults = std::make_shared<text_layout_properties>(*(p.layout_defaults));
|
||||||
//TODO: This needs a real copy constructor for text_symbolizer_properties
|
//TODO: This needs a real copy constructor for text_symbolizer_properties
|
||||||
p.from_xml(*itr, fontsets);
|
p.from_xml(node, fontsets);
|
||||||
|
|
||||||
//TODO: if (strict_ &&
|
//TODO: if (strict_ &&
|
||||||
// !p.format.fontset.size())
|
// !p.format.fontset.size())
|
||||||
// ensure_font_face(p.format.face_name);
|
// ensure_font_face(p.format.face_name);
|
||||||
}
|
}
|
||||||
return ptr;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
} //ns mapnik
|
} //ns mapnik
|
||||||
|
|
|
@ -200,7 +200,6 @@ void set_property_from_xml(symbolizer_base::value_type & val, char const* name,
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
optional<target_type> val_ = node.get_opt_attr<target_type>(name);
|
optional<target_type> val_ = node.get_opt_attr<target_type>(name);
|
||||||
if (val_) std::cerr << std::string(name) << ":" << *val_ << std::endl;
|
|
||||||
if (val_) val = *val_;
|
if (val_) val = *val_;
|
||||||
}
|
}
|
||||||
catch (config_error const& ex)
|
catch (config_error const& ex)
|
||||||
|
@ -218,31 +217,24 @@ text_layout_properties::text_layout_properties()
|
||||||
: halign(H_AUTO),
|
: halign(H_AUTO),
|
||||||
jalign(J_AUTO),
|
jalign(J_AUTO),
|
||||||
valign(V_AUTO)
|
valign(V_AUTO)
|
||||||
{
|
{}
|
||||||
displacement_evaluator_ = [this](feature_impl const& feature, attributes const& attrs)
|
|
||||||
{ double dx_ = boost::apply_visitor(extract_value<value_double>(feature,attrs), this->dx);
|
|
||||||
double dy_ = boost::apply_visitor(extract_value<value_double>(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)
|
void text_layout_properties::from_xml(xml_node const &node)
|
||||||
{
|
{
|
||||||
set_property_from_xml<double>(dx, "dx", node);
|
set_property_from_xml<double>(dx, "dx", node);
|
||||||
set_property_from_xml<double>(dy, "dy", node);
|
set_property_from_xml<double>(dy, "dy", node);
|
||||||
|
set_property_from_xml<double>(text_ratio, "text-ratio", node);
|
||||||
|
set_property_from_xml<double>(wrap_width, "wrap-width", node);
|
||||||
|
set_property_from_xml<boolean>(wrap_before, "wrap-before", node);
|
||||||
|
set_property_from_xml<boolean>(rotate_displacement, "rotate-displacement", node);
|
||||||
|
set_property_from_xml<double>(orientation, "orientation", node);
|
||||||
|
//
|
||||||
optional<vertical_alignment_e> valign_ = node.get_opt_attr<vertical_alignment_e>("vertical-alignment");
|
optional<vertical_alignment_e> valign_ = node.get_opt_attr<vertical_alignment_e>("vertical-alignment");
|
||||||
if (valign_) valign = *valign_;
|
if (valign_) valign = *valign_;
|
||||||
optional<horizontal_alignment_e> halign_ = node.get_opt_attr<horizontal_alignment_e>("horizontal-alignment");
|
optional<horizontal_alignment_e> halign_ = node.get_opt_attr<horizontal_alignment_e>("horizontal-alignment");
|
||||||
if (halign_) halign = *halign_;
|
if (halign_) halign = *halign_;
|
||||||
optional<justify_alignment_e> jalign_ = node.get_opt_attr<justify_alignment_e>("justify-alignment");
|
optional<justify_alignment_e> jalign_ = node.get_opt_attr<justify_alignment_e>("justify-alignment");
|
||||||
if (jalign_) jalign = *jalign_;
|
if (jalign_) jalign = *jalign_;
|
||||||
|
|
||||||
set_property_from_xml<double>(text_ratio, "text-ratio", node);
|
|
||||||
set_property_from_xml<double>(wrap_width, "wrap-width", node);
|
|
||||||
set_property_from_xml<boolean>(wrap_before, "wrap-before", node);
|
|
||||||
set_property_from_xml<boolean>(rotate_displacement, "rotate-displacement", node);
|
|
||||||
set_property_from_xml<double>(orientation, "orientation", node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void text_layout_properties::to_xml(boost::property_tree::ptree & node,
|
void text_layout_properties::to_xml(boost::property_tree::ptree & node,
|
||||||
|
|
Loading…
Reference in a new issue