convert to expressions: text-ratio, wrap-before, rotate-displacement

This commit is contained in:
artemp 2014-07-14 16:51:11 +01:00
parent 24e21cd387
commit a66c1ddb06
4 changed files with 46 additions and 47 deletions

View file

@ -138,6 +138,9 @@ private:
// Precalculated values for maximum performance
rotation orientation_ = {0,1.0};
double wrap_width_ = 0.0;
bool wrap_before_ = false;
bool rotate_displacement_ = false;
double text_ratio_ = 0.0;
pixel_position displacement_;
box2d<double> bounds_;

View file

@ -75,8 +75,8 @@ struct MAPNIK_DECL text_layout_properties
// Load all values from XML ptree.
void from_xml(xml_node const &sym);
// 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,
text_layout_properties const &dfl=text_layout_properties()) const;
void to_xml(boost::property_tree::ptree & node, bool explicit_defaults,
text_layout_properties const& dfl=text_layout_properties()) const;
// Get a list of all expressions used in any placement.
// This function is used to collect attributes.
@ -89,10 +89,11 @@ struct MAPNIK_DECL text_layout_properties
horizontal_alignment_e halign;
justify_alignment_e jalign;
vertical_alignment_e valign;
double text_ratio;
symbolizer_base::value_type text_ratio;
symbolizer_base::value_type wrap_width;
bool wrap_before;
bool rotate_displacement;
symbolizer_base::value_type wrap_before;
symbolizer_base::value_type rotate_displacement;
};
using text_layout_properties_ptr = std::shared_ptr<text_layout_properties>;

View file

@ -89,13 +89,13 @@ void text_layout::layout()
std::pair<unsigned, unsigned> line_limits = itemizer_.line(i);
text_line line(line_limits.first, line_limits.second);
//Break line if neccessary
break_line(line, wrap_width_ * scale_factor_, properties_.text_ratio, properties_.wrap_before);
break_line(line, wrap_width_ * scale_factor_, text_ratio_, wrap_before_);
}
init_alignment();
/* Find text origin. */
displacement_ = scale_factor_ * properties_.displacement + alignment_offset();
if (properties_.rotate_displacement) displacement_ = displacement_.rotate(!orientation_);
if (rotate_displacement_) displacement_ = displacement_.rotate(!orientation_);
/* Find layout bounds, expanded for rotation */
rotated_box2d(bounds_, orientation_, displacement_, width_, height_);
@ -238,6 +238,8 @@ void text_layout::evaluate_properties(feature_impl const& feature, attributes co
wrap_width_ = boost::apply_visitor(extract_value<value_double>(feature,attr), properties_.wrap_width);
double angle = boost::apply_visitor(extract_value<value_double>(feature,attr), properties_.orientation);
orientation_.init(angle * M_PI/ 180.0);
wrap_before_ = boost::apply_visitor(extract_value<value_bool>(feature,attr), properties_.wrap_before);
rotate_displacement_ = boost::apply_visitor(extract_value<value_bool>(feature,attr), properties_.rotate_displacement);
}
void text_layout::init_alignment()

View file

@ -215,15 +215,10 @@ void set_property_from_xml(symbolizer_base::value_type & val, char const* name,
}
text_layout_properties::text_layout_properties()
: orientation(0.0),
displacement(0.0,0.0),
: displacement(0.0,0.0),
halign(H_AUTO),
jalign(J_AUTO),
valign(V_AUTO),
text_ratio(0.0),
wrap_width(0.0),
wrap_before(false),
rotate_displacement(false) {}
valign(V_AUTO) {}
void text_layout_properties::from_xml(xml_node const &sym)
{
@ -237,16 +232,11 @@ void text_layout_properties::from_xml(xml_node const &sym)
if (halign_) halign = *halign_;
optional<justify_alignment_e> jalign_ = sym.get_opt_attr<justify_alignment_e>("justify-alignment");
if (jalign_) jalign = *jalign_;
optional<double> text_ratio_ = sym.get_opt_attr<double>("text-ratio");
if (text_ratio_) text_ratio = *text_ratio_;
set_property_from_xml<double>(text_ratio, "text-ratio", sym);
set_property_from_xml<double>(wrap_width, "wrap-width", sym);
optional<boolean> wrap_before_ = sym.get_opt_attr<boolean>("wrap-before");
if (wrap_before_) wrap_before = *wrap_before_;
optional<boolean> rotate_displacement_ = sym.get_opt_attr<boolean>("rotate-displacement");
if (rotate_displacement_) rotate_displacement = *rotate_displacement_;
set_property_from_xml<boolean>(wrap_before, "wrap-before", sym);
set_property_from_xml<boolean>(rotate_displacement, "rotate-displacement", sym);
set_property_from_xml<double>(orientation, "orientation", sym);
}
@ -274,22 +264,22 @@ void text_layout_properties::to_xml(boost::property_tree::ptree & node,
{
set_attr(node, "justify-alignment", jalign);
}
if (text_ratio != dfl.text_ratio || explicit_defaults)
{
set_attr(node, "text-ratio", text_ratio);
}
//if (text_ratio != dfl.text_ratio || explicit_defaults)
//{
// set_attr(node, "text-ratio", text_ratio);
//}
//if (wrap_width != dfl.wrap_width || explicit_defaults)
//{
// set_attr(node, "wrap-width", wrap_width);
//}
if (wrap_before != dfl.wrap_before || explicit_defaults)
{
set_attr(node, "wrap-before", wrap_before);
}
if (rotate_displacement != dfl.rotate_displacement || explicit_defaults)
{
set_attr(node, "rotate-displacement", rotate_displacement);
}
//if (wrap_before != dfl.wrap_before || explicit_defaults)
//{
// set_attr(node, "wrap-before", wrap_before);
//}
//if (rotate_displacement != dfl.rotate_displacement || explicit_defaults)
//{
// set_attr(node, "rotate-displacement", rotate_displacement);
//}
/// TODO
//if (orientation)
//{
@ -304,10 +294,13 @@ void text_layout_properties::add_expressions(expression_set& output) const
{
if (is_expression(orientation)) output.insert(boost::get<expression_ptr>(orientation));
if (is_expression(wrap_width)) output.insert(boost::get<expression_ptr>(wrap_width));
if (is_expression(wrap_before)) output.insert(boost::get<expression_ptr>(wrap_before));
if (is_expression(rotate_displacement)) output.insert(boost::get<expression_ptr>(rotate_displacement));
if (is_expression(text_ratio)) output.insert(boost::get<expression_ptr>(text_ratio));
}
char_properties::char_properties() :
face_name(),
char_properties::char_properties()
: face_name(),
fontset(),
text_size(10.0),
character_spacing(0),