text - add ``repeat-wrap-char`` parameter default:false (#2333)

This commit is contained in:
artemp 2014-09-10 16:08:41 +01:00
parent 90f6258b41
commit f8dc7b023a
8 changed files with 28 additions and 9 deletions

View file

@ -50,6 +50,7 @@ public:
boost::optional<symbolizer_base::value_type> line_spacing;
boost::optional<symbolizer_base::value_type> text_opacity;
boost::optional<symbolizer_base::value_type> wrap_before;
boost::optional<symbolizer_base::value_type> repeat_wrap_char;
boost::optional<symbolizer_base::value_type> text_transform;
boost::optional<symbolizer_base::value_type> fill;
boost::optional<symbolizer_base::value_type> halo_fill;

View file

@ -48,6 +48,7 @@ public:
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> repeat_wrap_char;
boost::optional<symbolizer_base::value_type> rotate_displacement;
boost::optional<symbolizer_base::value_type> orientation;

View file

@ -113,7 +113,8 @@ public:
private:
void break_line(text_line & line, double wrap_width, unsigned text_ratio, bool wrap_before);
void break_line(text_line & line, char wrap_char,
double wrap_width, unsigned text_ratio, bool wrap_before);
double wrap_width, unsigned text_ratio,
bool wrap_before, bool repeat_wrap_char);
void shape_text(text_line & line);
void add_line(text_line & line);
void clear_cluster_widths(unsigned first, unsigned last);
@ -149,6 +150,7 @@ private:
char wrap_char_ = ' ';
double wrap_width_ = 0.0;
bool wrap_before_ = false;
bool repeat_wrap_char_ = false;
bool rotate_displacement_ = false;
double text_ratio_ = 0.0;
pixel_position displacement_ = {0,0};

View file

@ -121,6 +121,7 @@ struct MAPNIK_DECL text_layout_properties
symbolizer_base::value_type wrap_width;
symbolizer_base::value_type wrap_char;
symbolizer_base::value_type wrap_before;
symbolizer_base::value_type repeat_wrap_char;
symbolizer_base::value_type rotate_displacement;
symbolizer_base::value_type halign;
symbolizer_base::value_type jalign;

View file

@ -45,6 +45,7 @@ void format_node::to_xml(ptree & xml) const
if (line_spacing) serialize_property("line-spacing", *line_spacing, new_node);
if (text_opacity) serialize_property("opacity", *text_opacity, new_node);
if (wrap_before) serialize_property("wrap-before", *wrap_before, new_node);
if (repeat_wrap_char) serialize_property("repeat-wrap-char", *repeat_wrap_char, new_node);
if (fill) serialize_property("fill", *fill, new_node);
if (halo_fill) serialize_property("halo-fill", *halo_fill, new_node);
if (halo_radius) serialize_property("halo-radius", *halo_radius, new_node);
@ -150,6 +151,7 @@ void format_node::add_expressions(expression_set & output) const
if (text_opacity && is_expression(*text_opacity)) output.insert(util::get<expression_ptr>(*text_opacity));
//if (halo_opacity && is_expression(*halo_opacity)) output.insert(util::get<expression_ptr>(*halo_opacity));
if (wrap_before && is_expression(*wrap_before)) output.insert(util::get<expression_ptr>(*wrap_before));
if (repeat_wrap_char && is_expression(*repeat_wrap_char)) output.insert(util::get<expression_ptr>(*repeat_wrap_char));
if (fill && is_expression(*fill)) output.insert(util::get<expression_ptr>(*fill));
if (halo_fill && is_expression(*halo_fill)) output.insert(util::get<expression_ptr>(*halo_fill));
if (text_transform && is_expression(*text_transform)) output.insert(util::get<expression_ptr>(*text_transform));

View file

@ -51,6 +51,7 @@ void layout_node::to_xml(ptree &xml) const
if (text_ratio) serialize_property("text-ratio", *text_ratio, new_node);
if (wrap_width) serialize_property("wrap-width", *wrap_width, new_node);
if (wrap_before) serialize_property("wrap-before", *wrap_before, new_node);
if (repeat_wrap_char) serialize_property("repeat-wrap-char", *repeat_wrap_char, new_node);
if (rotate_displacement) serialize_property("rotate-displacement", *rotate_displacement, new_node);
if (orientation) serialize_property("orientation", *orientation, new_node);
if (halign) serialize_property("horizontal-alignment", *halign, new_node);
@ -71,6 +72,7 @@ node_ptr layout_node::from_xml(xml_node const& xml, fontset_map const& fontsets)
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<mapnik::boolean_type>(n->wrap_before, "wrap-before", xml);
if (xml.has_attribute("repeat-wrap-char")) set_property_from_xml<mapnik::boolean_type>(n->repeat_wrap_char, "repeat-wrap-char", xml);
if (xml.has_attribute("rotate-displacement")) set_property_from_xml<mapnik::boolean_type>(n->rotate_displacement, "rotate-displacement", xml);
if (xml.has_attribute("orientation")) set_property_from_xml<double>(n->orientation, "orientation", xml);
if (xml.has_attribute("horizontal-alignment")) set_property_from_xml<horizontal_alignment_e>(n->halign, "horizontal-alignment", xml);
@ -87,6 +89,7 @@ void layout_node::apply(evaluated_format_properties_ptr p, feature_impl const& f
if (text_ratio) new_properties.text_ratio = *text_ratio;
if (wrap_width) new_properties.wrap_width = *wrap_width;
if (wrap_before) new_properties.wrap_before = *wrap_before;
if (repeat_wrap_char) new_properties.repeat_wrap_char = *repeat_wrap_char;
if (rotate_displacement) new_properties.rotate_displacement = *rotate_displacement;
if (orientation) new_properties.orientation = *orientation;
if (halign) new_properties.halign = *halign;
@ -126,6 +129,7 @@ void layout_node::add_expressions(expression_set & output) const
if (orientation && is_expression(*orientation)) output.insert(util::get<expression_ptr>(*orientation));
if (wrap_width && is_expression(*wrap_width)) output.insert(util::get<expression_ptr>(*wrap_width));
if (wrap_before && is_expression(*wrap_before)) output.insert(util::get<expression_ptr>(*wrap_before));
if (repeat_wrap_char && is_expression(*repeat_wrap_char)) output.insert(util::get<expression_ptr>(*repeat_wrap_char));
if (rotate_displacement && is_expression(*rotate_displacement)) output.insert(util::get<expression_ptr>(*rotate_displacement));
if (text_ratio && is_expression(*text_ratio)) output.insert(util::get<expression_ptr>(*text_ratio));
if (halign && is_expression(*halign)) output.insert(util::get<expression_ptr>(*halign));

View file

@ -90,7 +90,7 @@ void text_layout::layout()
//Break line if neccessary
if (wrap_char_ != ' ')
{
break_line(line, wrap_char_, wrap_width_ * scale_factor_, text_ratio_, wrap_before_);
break_line(line, wrap_char_, wrap_width_ * scale_factor_, text_ratio_, wrap_before_, repeat_wrap_char_);
}
else
{
@ -228,8 +228,14 @@ struct line_breaker : mapnik::noncopyable
char wrap_char_;
};
inline int adjust_last_break_position (int pos, bool repeat_wrap_char)
{
if (repeat_wrap_char) return (pos==0) ? 0: pos - 1;
else return pos;
}
void text_layout::break_line(text_line & line, char wrap_char, double wrap_width,
unsigned text_ratio, bool wrap_before)
unsigned text_ratio, bool wrap_before, bool repeat_wrap_char)
{
shape_text(line);
if (!wrap_width || line.width() < wrap_width)
@ -276,9 +282,8 @@ void text_layout::break_line(text_line & line, char wrap_char, double wrap_width
{
break_position = line.last_char();
}
text_line new_line(last_break_position, break_position);
clear_cluster_widths(last_break_position, break_position);
text_line new_line(adjust_last_break_position(last_break_position, repeat_wrap_char_), break_position);
clear_cluster_widths(adjust_last_break_position(last_break_position, repeat_wrap_char_), break_position);
shape_text(new_line);
add_line(new_line);
last_break_position = break_position;
@ -291,8 +296,8 @@ void text_layout::break_line(text_line & line, char wrap_char, double wrap_width
}
else if (last_break_position != static_cast<int>(line.last_char()))
{
text_line new_line(last_break_position, line.last_char());
clear_cluster_widths(last_break_position, line.last_char());
text_line new_line(adjust_last_break_position(last_break_position, repeat_wrap_char_), line.last_char());
clear_cluster_widths(adjust_last_break_position(last_break_position, repeat_wrap_char_), line.last_char());
shape_text(new_line);
add_line(new_line);
}
@ -347,6 +352,7 @@ void text_layout::evaluate_properties(feature_impl const& feature, attributes co
orientation_.init(angle * M_PI/ 180.0);
wrap_before_ = util::apply_visitor(extract_value<value_bool>(feature,attrs), properties_.wrap_before);
repeat_wrap_char_ = util::apply_visitor(extract_value<value_bool>(feature,attrs), properties_.repeat_wrap_char);
rotate_displacement_ = util::apply_visitor(extract_value<value_bool>(feature,attrs), properties_.rotate_displacement);
valign_ = util::apply_visitor(extract_value<vertical_alignment_enum>(feature,attrs),properties_.valign);

View file

@ -260,6 +260,7 @@ void text_layout_properties::from_xml(xml_node const &node, fontset_map const& f
set_property_from_xml<double>(wrap_width, "wrap-width", node);
set_property_from_xml<std::string>(wrap_char, "wrap-char", node);
set_property_from_xml<boolean_type>(wrap_before, "wrap-before", node);
set_property_from_xml<boolean_type>(repeat_wrap_char, "repeat-wrap-char", node);
set_property_from_xml<boolean_type>(rotate_displacement, "rotate-displacement", node);
set_property_from_xml<double>(orientation, "orientation", node);
set_property_from_xml<vertical_alignment_e>(valign, "vertical-alignment", node);
@ -280,6 +281,7 @@ void text_layout_properties::to_xml(boost::property_tree::ptree & node,
if (!(wrap_width == dfl.wrap_width) || explicit_defaults) serialize_property("wrap-width", wrap_width, node);
if (!(wrap_char == dfl.wrap_char) || explicit_defaults) serialize_property("wrap-char", wrap_char, node);
if (!(wrap_before == dfl.wrap_before) || explicit_defaults) serialize_property("wrap-before", wrap_before, node);
if (!(repeat_wrap_char == dfl.repeat_wrap_char) || explicit_defaults) serialize_property("repeat-wrap-char", repeat_wrap_char, node);
if (!(rotate_displacement == dfl.rotate_displacement) || explicit_defaults)
serialize_property("rotate-displacement", rotate_displacement, node);
if (!(orientation == dfl.orientation) || explicit_defaults) serialize_property("orientation", orientation, node);
@ -292,7 +294,7 @@ void text_layout_properties::add_expressions(expression_set & output) const
if (is_expression(orientation)) output.insert(util::get<expression_ptr>(orientation));
if (is_expression(wrap_width)) output.insert(util::get<expression_ptr>(wrap_width));
if (is_expression(wrap_char)) output.insert(util::get<expression_ptr>(wrap_char));
if (is_expression(wrap_before)) output.insert(util::get<expression_ptr>(wrap_before));
if (is_expression(repeat_wrap_char)) output.insert(util::get<expression_ptr>(repeat_wrap_char));
if (is_expression(rotate_displacement)) output.insert(util::get<expression_ptr>(rotate_displacement));
if (is_expression(text_ratio)) output.insert(util::get<expression_ptr>(text_ratio));
if (is_expression(halign)) output.insert(util::get<expression_ptr>(halign));