text_properties : wrap-width

This commit is contained in:
artemp 2014-07-11 15:44:44 +01:00
parent de900539c6
commit e066aa924f
6 changed files with 31 additions and 19 deletions

View file

@ -101,7 +101,7 @@ public:
pixel_position alignment_offset() const;
double jalign_offset(double line_width) const;
void init_orientation(feature_impl const& feature, attributes const& attr);
void evaluate_properties(feature_impl const& feature, attributes const& attr);
private:
void break_line(text_line & line, double wrap_width, unsigned text_ratio, bool wrap_before);
@ -136,7 +136,8 @@ private:
justify_alignment_e jalign_;
// Precalculated values for maximum performance
rotation orientation_;
rotation orientation_ = {0,1.0};
double wrap_width_ = 0.0;
pixel_position displacement_;
box2d<double> bounds_;

View file

@ -91,7 +91,7 @@ struct MAPNIK_DECL text_layout_properties
justify_alignment_e jalign;
vertical_alignment_e valign;
double text_ratio;
double wrap_width;
symbolizer_base::value_type wrap_width;
bool wrap_before;
bool rotate_displacement;
};

View file

@ -95,7 +95,7 @@ void layout_node::apply(char_properties_ptr p, feature_impl const& feature, attr
// 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->init_orientation(feature,vars);
child_layout->evaluate_properties(feature,vars);
// process contained format tree into the child node
if (child_) {

View file

@ -89,7 +89,7 @@ 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, properties_.wrap_width * scale_factor_, properties_.text_ratio, properties_.wrap_before);
break_line(line, wrap_width_ * scale_factor_, properties_.text_ratio, properties_.wrap_before);
}
init_alignment();
@ -150,8 +150,6 @@ void text_layout::break_line(text_line & line, double wrap_width, unsigned text_
current_line_length += width_itr->second;
}
if (current_line_length <= wrap_width) continue;
/***********************************************/
int break_position = wrap_before ? breakitr->preceding(i) : breakitr->following(i);
// following() returns a break position after the last word. So DONE should only be returned
@ -235,8 +233,9 @@ void text_layout::shape_text(text_line & line)
shaper_type::shape_text(line, itemizer_, width_map_, font_manager_, scale_factor_);
}
void text_layout::init_orientation(feature_impl const& feature, attributes const& attr)
void text_layout::evaluate_properties(feature_impl const& feature, attributes const& attr)
{
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);
}

View file

@ -76,7 +76,7 @@ bool placement_finder::next_position()
}
text_layout_ptr layout = std::make_shared<text_layout>(font_manager_, scale_factor_, info_.properties.layout_defaults);
layout->init_orientation(feature_, attr_);
layout->evaluate_properties(feature_, attr_);
info_.properties.process(*layout, feature_, attr_);
layouts_.clear();

View file

@ -193,7 +193,7 @@ void text_symbolizer_properties::set_old_style_expression(expression_ptr expr)
}
text_layout_properties::text_layout_properties()
: orientation(),
: orientation(0.0),
displacement(0.0,0.0),
halign(H_AUTO),
jalign(J_AUTO),
@ -217,13 +217,27 @@ void text_layout_properties::from_xml(xml_node const &sym)
if (jalign_) jalign = *jalign_;
optional<double> text_ratio_ = sym.get_opt_attr<double>("text-ratio");
if (text_ratio_) text_ratio = *text_ratio_;
optional<double> wrap_width_ = sym.get_opt_attr<double>("wrap-width");
if (wrap_width_) wrap_width = *wrap_width_;
try
{
optional<double> val = sym.get_opt_attr<double>("wrap-width");
if (val) wrap_width = *val;
}
catch (config_error const& ex)
{
optional<expression_ptr> val = sym.get_opt_attr<expression_ptr>("wrap-width");
if (val) wrap_width = *val;
else
{
ex.append_context(std::string("text_layout_properties::from_xml '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_;
// TODO!!
try
{
optional<value_double> val = sym.get_opt_attr<value_double>("orientation");
@ -238,8 +252,6 @@ void text_layout_properties::from_xml(xml_node const &sym)
ex.append_context(std::string("text_layout_properties::from_xml 'orientation'"), sym);
}
}
//optional<expression_ptr> orientation_ = sym.get_opt_attr<expression_ptr>("orientation");
//if (orientation_) orientation = *orientation_;
}
void text_layout_properties::to_xml(boost::property_tree::ptree &node,
@ -270,10 +282,10 @@ void text_layout_properties::to_xml(boost::property_tree::ptree &node,
{
set_attr(node, "text-ratio", text_ratio);
}
if (wrap_width != dfl.wrap_width || explicit_defaults)
{
set_attr(node, "wrap-width", wrap_width);
}
//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);