Reenable wrap-before and add tests for it.
This commit is contained in:
parent
e5351ced6f
commit
dc6ecc4be7
13 changed files with 55 additions and 30 deletions
|
@ -805,13 +805,13 @@ class _TextSymbolizer(TextSymbolizer,_injector):
|
|||
def wrap_before(self):
|
||||
warnings.warn("'wrap_before' is deprecated, use format.wrap_before",
|
||||
DeprecationWarning, 2)
|
||||
return self.format.wrap_before
|
||||
return self.properties.wrap_before
|
||||
|
||||
@wrap_before.setter
|
||||
def wrap_before(self, wrap_before):
|
||||
warnings.warn("'wrap_before' is deprecated, use format.wrap_before",
|
||||
DeprecationWarning, 2)
|
||||
self.format.wrap_before = wrap_before
|
||||
self.properties.wrap_before = wrap_before
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -387,6 +387,7 @@ void export_text_placement()
|
|||
.def_readwrite("largest_bbox_only", &text_symbolizer_properties::largest_bbox_only)
|
||||
.def_readwrite("text_ratio", &text_symbolizer_properties::text_ratio)
|
||||
.def_readwrite("wrap_width", &text_symbolizer_properties::wrap_width)
|
||||
.def_readwrite("wrap_before", &text_symbolizer_properties::wrap_before)
|
||||
.def_readwrite("format", &text_symbolizer_properties::format)
|
||||
.add_property ("format_tree",
|
||||
&text_symbolizer_properties::format_tree,
|
||||
|
@ -412,7 +413,6 @@ void export_text_placement()
|
|||
.def_readwrite("text_opacity", &char_properties::text_opacity)
|
||||
.def_readwrite("wrap_char", &char_properties::wrap_char)
|
||||
.def_readwrite("wrap_character", &char_properties::wrap_char)
|
||||
.def_readwrite("wrap_before", &char_properties::wrap_before)
|
||||
.def_readwrite("fill", &char_properties::fill)
|
||||
.def_readwrite("halo_fill", &char_properties::halo_fill)
|
||||
.def_readwrite("halo_radius", &char_properties::halo_radius)
|
||||
|
@ -488,7 +488,6 @@ void export_text_placement()
|
|||
.def_readwrite_convert("text_opacity", &formatting::format_node::text_opacity)
|
||||
.def_readwrite_convert("wrap_char", &formatting::format_node::wrap_char)
|
||||
.def_readwrite_convert("wrap_character", &formatting::format_node::wrap_char)
|
||||
.def_readwrite_convert("wrap_before", &formatting::format_node::wrap_before)
|
||||
.def_readwrite_convert("text_transform", &formatting::format_node::text_transform)
|
||||
.def_readwrite_convert("fill", &formatting::format_node::fill)
|
||||
.def_readwrite_convert("halo_fill", &formatting::format_node::halo_fill)
|
||||
|
@ -528,7 +527,6 @@ void export_text_placement()
|
|||
.def_readwrite("text_opacity", &formatting::expression_format::text_opacity)
|
||||
.def_readwrite("wrap_char", &formatting::expression_format::wrap_char)
|
||||
.def_readwrite("wrap_character", &formatting::expression_format::wrap_char)
|
||||
.def_readwrite("wrap_before", &formatting::expression_format::wrap_before)
|
||||
.def_readwrite("fill", &formatting::expression_format::fill)
|
||||
.def_readwrite("halo_fill", &formatting::expression_format::halo_fill)
|
||||
.def_readwrite("halo_radius", &formatting::expression_format::halo_radius)
|
||||
|
|
|
@ -43,7 +43,6 @@ public:
|
|||
expression_ptr character_spacing;
|
||||
expression_ptr line_spacing;
|
||||
expression_ptr text_opacity;
|
||||
expression_ptr wrap_before;
|
||||
expression_ptr wrap_char;
|
||||
expression_ptr fill;
|
||||
expression_ptr halo_fill;
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
void add_text(UnicodeString const& str, char_properties_ptr format);
|
||||
UnicodeString const& get_text() const;
|
||||
|
||||
void layout(double wrap_width, unsigned text_ratio);
|
||||
void layout(double wrap_width, unsigned text_ratio, bool wrap_before);
|
||||
|
||||
void clear();
|
||||
double height() const;
|
||||
|
@ -105,7 +105,7 @@ public:
|
|||
unsigned glyphs_count() const;
|
||||
|
||||
private:
|
||||
void break_line(text_line_ptr line, double wrap_width, unsigned text_ratio);
|
||||
void break_line(text_line_ptr line, double wrap_width, unsigned text_ratio, bool wrap_before);
|
||||
void shape_text(text_line_ptr line);
|
||||
void add_line(text_line_ptr line);
|
||||
|
||||
|
|
|
@ -66,7 +66,6 @@ struct char_properties
|
|||
double character_spacing;
|
||||
double line_spacing; //Largest total height (fontsize+line_spacing) per line is chosen
|
||||
double text_opacity;
|
||||
bool wrap_before;
|
||||
unsigned wrap_char;
|
||||
text_transform_e text_transform; //Per expression
|
||||
color fill;
|
||||
|
@ -177,6 +176,7 @@ struct text_symbolizer_properties
|
|||
bool largest_bbox_only;
|
||||
double text_ratio;
|
||||
double wrap_width;
|
||||
bool wrap_before;
|
||||
bool rotate_displacement;
|
||||
text_upright_e upright;
|
||||
/** Default values for char_properties. */
|
||||
|
|
|
@ -46,7 +46,6 @@ void expression_format::to_xml(boost::property_tree::ptree &xml) const
|
|||
if (character_spacing) set_attr(new_node, "character-spacing", to_expression_string(*character_spacing));
|
||||
if (line_spacing) set_attr(new_node, "line-spacing", to_expression_string(*line_spacing));
|
||||
if (text_opacity) set_attr(new_node, "opacity", to_expression_string(*text_opacity));
|
||||
if (wrap_before) set_attr(new_node, "wrap-before", to_expression_string(*wrap_before));
|
||||
if (wrap_char) set_attr(new_node, "wrap-character", to_expression_string(*wrap_char));
|
||||
if (fill) set_attr(new_node, "fill", to_expression_string(*fill));
|
||||
if (halo_fill) set_attr(new_node, "halo-fill", to_expression_string(*halo_fill));
|
||||
|
@ -67,7 +66,6 @@ node_ptr expression_format::from_xml(xml_node const& xml)
|
|||
n->character_spacing = get_expression(xml, "character-spacing");
|
||||
n->line_spacing = get_expression(xml, "line-spacing");
|
||||
n->text_opacity = get_expression(xml, "opacity");
|
||||
n->wrap_before = get_expression(xml, "wrap-before");
|
||||
n->wrap_char = get_expression(xml, "wrap-character");
|
||||
n->fill = get_expression(xml, "fill");
|
||||
n->halo_fill = get_expression(xml, "halo-fill");
|
||||
|
@ -96,8 +94,6 @@ void expression_format::apply(char_properties_ptr p, const Feature &feature, tex
|
|||
boost::apply_visitor(evaluate<Feature,value_type>(feature), *line_spacing).to_double();
|
||||
if (text_opacity) new_properties->text_opacity =
|
||||
boost::apply_visitor(evaluate<Feature,value_type>(feature), *text_opacity).to_double();
|
||||
if (wrap_before) new_properties->wrap_before =
|
||||
boost::apply_visitor(evaluate<Feature,value_type>(feature), *wrap_before).to_bool();
|
||||
if (wrap_char) new_properties->wrap_char =
|
||||
boost::apply_visitor(evaluate<Feature,value_type>(feature), *character_spacing).to_unicode()[0];
|
||||
// if (fill) new_properties->fill =
|
||||
|
@ -134,7 +130,6 @@ void expression_format::add_expressions(expression_set &output) const
|
|||
output.insert(character_spacing);
|
||||
output.insert(line_spacing);
|
||||
output.insert(text_opacity);
|
||||
output.insert(wrap_before);
|
||||
output.insert(wrap_char);
|
||||
output.insert(fill);
|
||||
output.insert(halo_fill);
|
||||
|
|
|
@ -66,8 +66,6 @@ node_ptr format_node::from_xml(xml_node const& xml)
|
|||
n->character_spacing = xml.get_opt_attr<double>("character-spacing");
|
||||
n->line_spacing = xml.get_opt_attr<double>("line-spacing");
|
||||
n->text_opacity = xml.get_opt_attr<double>("opacity");
|
||||
boost::optional<boolean> wrap = xml.get_opt_attr<boolean>("wrap-before");
|
||||
if (wrap) n->wrap_before = *wrap;
|
||||
n->wrap_char = xml.get_opt_attr<unsigned>("wrap-character");
|
||||
n->text_transform = xml.get_opt_attr<text_transform_e>("text-transform");
|
||||
n->fill = xml.get_opt_attr<color>("fill");
|
||||
|
@ -85,7 +83,6 @@ void format_node::apply(char_properties_ptr p, const Feature &feature, text_layo
|
|||
if (character_spacing) new_properties->character_spacing = *character_spacing;
|
||||
if (line_spacing) new_properties->line_spacing = *line_spacing;
|
||||
if (text_opacity) new_properties->text_opacity = *text_opacity;
|
||||
if (wrap_before) new_properties->wrap_before = *wrap_before;
|
||||
if (wrap_char) new_properties->wrap_char = *wrap_char;
|
||||
if (text_transform) new_properties->text_transform = *text_transform;
|
||||
if (fill) new_properties->fill = *fill;
|
||||
|
|
|
@ -53,7 +53,7 @@ const UnicodeString &text_layout::get_text() const
|
|||
return itemizer_.get_text();
|
||||
}
|
||||
|
||||
void text_layout::layout(double wrap_width, unsigned text_ratio)
|
||||
void text_layout::layout(double wrap_width, unsigned text_ratio, bool wrap_before)
|
||||
{
|
||||
unsigned num_lines = itemizer_.num_lines();
|
||||
for (unsigned i = 0; i < num_lines; i++)
|
||||
|
@ -61,12 +61,12 @@ void text_layout::layout(double wrap_width, unsigned text_ratio)
|
|||
std::pair<unsigned, unsigned> line_limits = itemizer_.get_line(i);
|
||||
text_line_ptr line = boost::make_shared<text_line>(line_limits.first, line_limits.second);
|
||||
shape_text(line);
|
||||
break_line(line, wrap_width, text_ratio); //Break line if neccessary
|
||||
break_line(line, wrap_width, text_ratio, wrap_before); //Break line if neccessary
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void text_layout::break_line(text_line_ptr line, double wrap_width, unsigned text_ratio)
|
||||
void text_layout::break_line(text_line_ptr line, double wrap_width, unsigned text_ratio, bool wrap_before)
|
||||
{
|
||||
if (!wrap_width || line->width() < wrap_width)
|
||||
{
|
||||
|
|
|
@ -110,7 +110,7 @@ bool placement_finder::next_position()
|
|||
}
|
||||
|
||||
info_->properties.process(layout_, feature_);
|
||||
layout_.layout(info_->properties.wrap_width, info_->properties.text_ratio);
|
||||
layout_.layout(info_->properties.wrap_width, info_->properties.text_ratio, info_->properties.wrap_before);
|
||||
|
||||
if (info_->properties.orientation)
|
||||
{
|
||||
|
|
|
@ -110,6 +110,7 @@ text_symbolizer_properties::text_symbolizer_properties() :
|
|||
largest_bbox_only(true),
|
||||
text_ratio(0),
|
||||
wrap_width(0),
|
||||
wrap_before(false),
|
||||
rotate_displacement(false),
|
||||
upright(UPRIGHT_AUTO),
|
||||
format(boost::make_shared<char_properties>()),
|
||||
|
@ -148,6 +149,8 @@ void text_symbolizer_properties::from_xml(xml_node const &sym, fontset_map const
|
|||
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_;
|
||||
optional<boolean> wrap_before_ = sym.get_opt_attr<boolean>("wrap-before");
|
||||
if (wrap_before_) wrap_before = *wrap_before_;
|
||||
optional<unsigned> label_position_tolerance_ = sym.get_opt_attr<unsigned>("label-position-tolerance");
|
||||
if (label_position_tolerance_) label_position_tolerance = *label_position_tolerance_;
|
||||
optional<double> spacing_ = sym.get_opt_attr<double>("spacing");
|
||||
|
@ -235,6 +238,10 @@ void text_symbolizer_properties::to_xml(boost::property_tree::ptree &node,
|
|||
{
|
||||
set_attr(node, "wrap-width", wrap_width);
|
||||
}
|
||||
if (wrap_before != dfl.wrap_before || explicit_defaults)
|
||||
{
|
||||
set_attr(node, "wrap-before", wrap_before);
|
||||
}
|
||||
if (label_position_tolerance != dfl.label_position_tolerance || explicit_defaults)
|
||||
{
|
||||
set_attr(node, "label-position-tolerance", label_position_tolerance);
|
||||
|
@ -314,7 +321,6 @@ char_properties::char_properties() :
|
|||
character_spacing(0),
|
||||
line_spacing(0),
|
||||
text_opacity(1.0),
|
||||
wrap_before(false),
|
||||
wrap_char(' '),
|
||||
text_transform(NONE),
|
||||
fill(color(0,0,0)),
|
||||
|
@ -336,8 +342,6 @@ void char_properties::from_xml(xml_node const& sym, fontset_map const& fontsets)
|
|||
if (halo_fill_) halo_fill = *halo_fill_;
|
||||
optional<double> halo_radius_ = sym.get_opt_attr<double>("halo-radius");
|
||||
if (halo_radius_) halo_radius = *halo_radius_;
|
||||
optional<boolean> wrap_before_ = sym.get_opt_attr<boolean>("wrap-before");
|
||||
if (wrap_before_) wrap_before = *wrap_before_;
|
||||
optional<text_transform_e> tconvert_ = sym.get_opt_attr<text_transform_e>("text-transform");
|
||||
if (tconvert_) text_transform = *tconvert_;
|
||||
optional<double> line_spacing_ = sym.get_opt_attr<double>("line-spacing");
|
||||
|
@ -404,10 +408,6 @@ void char_properties::to_xml(boost::property_tree::ptree &node, bool explicit_de
|
|||
{
|
||||
set_attr(node, "halo-fill", halo_fill);
|
||||
}
|
||||
if (wrap_before != dfl.wrap_before || explicit_defaults)
|
||||
{
|
||||
set_attr(node, "wrap-before", wrap_before);
|
||||
}
|
||||
if (wrap_char != dfl.wrap_char || explicit_defaults)
|
||||
{
|
||||
set_attr(node, "wrap-character", std::string(1, wrap_char));
|
||||
|
|
|
@ -144,12 +144,12 @@ void text_symbolizer::set_wrap_width(double width)
|
|||
|
||||
bool text_symbolizer::get_wrap_before() const
|
||||
{
|
||||
return placement_options_->defaults.format->wrap_before;
|
||||
return placement_options_->defaults.wrap_before;
|
||||
}
|
||||
|
||||
void text_symbolizer::set_wrap_before(bool wrap_before)
|
||||
{
|
||||
placement_options_->defaults.format->wrap_before = wrap_before;
|
||||
placement_options_->defaults.wrap_before = wrap_before;
|
||||
}
|
||||
|
||||
unsigned char text_symbolizer::get_wrap_char() const
|
||||
|
|
BIN
tests/visual_tests/images/line_break-800-reference.png
Normal file
BIN
tests/visual_tests/images/line_break-800-reference.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 78 KiB |
36
tests/visual_tests/styles/line_break.xml
Normal file
36
tests/visual_tests/styles/line_break.xml
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE Map>
|
||||
<Map background-color="white" srs="+proj=latlong +datum=WGS84">
|
||||
<Layer name="layer" srs="+proj=latlong +datum=WGS84">
|
||||
<StyleName>My Style</StyleName>
|
||||
<Datasource>
|
||||
<Parameter name="type">osm</Parameter>
|
||||
<Parameter name="file">../data/points.osm</Parameter>
|
||||
</Datasource>
|
||||
</Layer>
|
||||
|
||||
|
||||
<Style name="My Style">
|
||||
<Rule>
|
||||
<PointSymbolizer/>
|
||||
</Rule>
|
||||
<Rule>
|
||||
<Filter>[nr] = "3"</Filter>
|
||||
<TextSymbolizer face-name="DejaVu Sans Book" size="36" placement="point" dy="-16" allow-overlap="true" wrap-width="80">"Overflowing lines"</TextSymbolizer>
|
||||
</Rule>
|
||||
<Rule>
|
||||
<Filter>[nr] = "3"</Filter>
|
||||
<TextSymbolizer face-name="DejaVu Sans Book" size="12" placement="point" dy="16" allow-overlap="true" wrap-width="300">"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ac urna ornare sapien porta hendrerit. In ultricies luctus massa vitae aliquam. Pellentesque in mauris nec velit elementum rhoncus. Pellentesque diam sapien, volutpat ac sollicitudin volutpat, sagittis in sem. Pellentesque ut purus a neque dapibus sodales. Etiam pellentesque elementum ligula, quis auctor ante ullamcorper in. Suspendisse potenti. Sed vulputate scelerisque orci, nec sagittis velit iaculis at. Integer laoreet aliquam bibendum. Nunc eu odio purus. Donec accumsan dolor in lorem volutpat nec posuere nulla tristique."</TextSymbolizer>
|
||||
</Rule>
|
||||
<Rule>
|
||||
<Filter>[nr] = "8"</Filter>
|
||||
<TextSymbolizer face-name="DejaVu Sans Book" size="12" placement="point" dy="16" allow-overlap="true" wrap-width="300" wrap-before="true">"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ac urna ornare sapien porta hendrerit. In ultricies luctus massa vitae aliquam. Pellentesque in mauris nec velit elementum rhoncus. Pellentesque diam sapien, volutpat ac sollicitudin volutpat, sagittis in sem. Pellentesque ut purus a neque dapibus sodales. Etiam pellentesque elementum ligula, quis auctor ante ullamcorper in. Suspendisse potenti. Sed vulputate scelerisque orci, nec sagittis velit iaculis at. Integer laoreet aliquam bibendum. Nunc eu odio purus. Donec accumsan dolor in lorem volutpat nec posuere nulla tristique."</TextSymbolizer>
|
||||
</Rule>
|
||||
<Rule>
|
||||
<Filter>[nr] = "7"</Filter>
|
||||
<!-- Text from http://fa.wikipedia.org/wiki/راستبهچپ -->
|
||||
<TextSymbolizer face-name="DejaVu Sans Book" size="12" placement="point" dy="-16" wrap-width="80">
|
||||
"راستبهچپ یا به خطهایی گفته میشود که نوشتنشان از سمت راست صفحه آغاز شود و به سمت چپ ادامه یابد. خطهای راستبهچپ عبارتند از"</TextSymbolizer>
|
||||
</Rule>
|
||||
</Style>
|
||||
</Map>
|
Loading…
Add table
Reference in a new issue