diff --git a/include/mapnik/text/placement_finder.hpp b/include/mapnik/text/placement_finder.hpp index f7afd8979..bf7dc157c 100644 --- a/include/mapnik/text/placement_finder.hpp +++ b/include/mapnik/text/placement_finder.hpp @@ -72,7 +72,7 @@ private: // Adjusts user defined spacing to place an integer number of labels. double get_spacing(double path_length, double layout_width) const; // Checks for collision. - bool collision(box2d const& box, const value_unicode_string &repeat_key = "") const; + bool collision(box2d const& box, const value_unicode_string &repeat_key, bool line_placement) const; // Adds marker to glyph_positions and to collision detector. Returns false if there is a collision. bool add_marker(glyph_positions_ptr glyphs, pixel_position const& pos) const; // Maps upright==auto, left_only and right_only to left,right to simplify processing. diff --git a/src/text/placement_finder.cpp b/src/text/placement_finder.cpp index 13c36de93..1d7c7a1e1 100644 --- a/src/text/placement_finder.cpp +++ b/src/text/placement_finder.cpp @@ -121,7 +121,7 @@ bool placement_finder::find_point_placement(pixel_position const& pos) bbox.re_center(layout_center.x, layout_center.y); /* For point placements it is faster to just check the bounding box. */ - if (collision(bbox, layouts_.text())) return false; + if (collision(bbox, layouts_.text(), false)) return false; if (layout.num_lines()) bboxes.push_back(std::move(bbox)); @@ -244,7 +244,7 @@ bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e or cluster_offset.y -= rot.sin * glyph.advance(); box2d bbox = get_bbox(layout, glyph, pos, rot); - if (collision(bbox, layouts_.text())) return false; + if (collision(bbox, layouts_.text(), true)) return false; bboxes.push_back(std::move(bbox)); glyphs->push_back(glyph, pos, rot); } @@ -311,8 +311,19 @@ double placement_finder::get_spacing(double path_length, double layout_width) co return path_length / num_labels; } -bool placement_finder::collision(const box2d &box, const value_unicode_string &repeat_key) const +bool placement_finder::collision(const box2d &box, const value_unicode_string &repeat_key, bool line_placement) const { + double text_margin, repeat_distance; + if (line_placement) + { + text_margin = info_.properties.text_margin * scale_factor_; + repeat_distance = (info_.properties.repeat_distance != 0 ? info_.properties.repeat_distance : info_.properties.minimum_distance) * scale_factor_; + } + else + { + text_margin = (info_.properties.text_margin != 0 ? info_.properties.text_margin : info_.properties.minimum_distance) * scale_factor_; + repeat_distance = info_.properties.repeat_distance * scale_factor_; + } return !detector_.extent().intersects(box) || (info_.properties.avoid_edges && !extent_.contains(box)) @@ -321,10 +332,9 @@ bool placement_finder::collision(const box2d &box, const value_unicode_s !extent_.contains(box + (scale_factor_ * info_.properties.minimum_padding))) || (!info_.properties.allow_overlap && - ((repeat_key.length() == 0 && !detector_.has_placement(box, info_.properties.text_margin * scale_factor_)) + ((repeat_key.length() == 0 && !detector_.has_placement(box, text_margin)) || - (repeat_key.length() > 0 && !detector_.has_placement(box, info_.properties.text_margin * scale_factor_, - repeat_key, info_.properties.repeat_distance * scale_factor_)))); + (repeat_key.length() > 0 && !detector_.has_placement(box, text_margin, repeat_key, repeat_distance)))); } void placement_finder::set_marker(marker_info_ptr m, box2d box, bool marker_unlocked, pixel_position const& marker_displacement) @@ -343,7 +353,7 @@ bool placement_finder::add_marker(glyph_positions_ptr glyphs, pixel_position con box2d bbox = marker_box_; bbox.move(real_pos.x, real_pos.y); glyphs->set_marker(marker_, real_pos); - if (collision(bbox, layouts_.text())) return false; + if (collision(bbox, layouts_.text(), false)) return false; detector_.insert(bbox); return true; } diff --git a/src/text/text_properties.cpp b/src/text/text_properties.cpp index 9b63e10d9..127b78777 100644 --- a/src/text/text_properties.cpp +++ b/src/text/text_properties.cpp @@ -64,6 +64,7 @@ void text_symbolizer_properties::evaluate_text_properties(feature_impl const& fe label_spacing = util::apply_visitor(extract_value(feature,attrs), expressions.label_spacing); label_position_tolerance = util::apply_visitor(extract_value(feature,attrs), expressions.label_position_tolerance); avoid_edges = util::apply_visitor(extract_value(feature,attrs), expressions.avoid_edges); + text_margin = util::apply_visitor(extract_value(feature,attrs), expressions.text_margin); repeat_distance = util::apply_visitor(extract_value(feature,attrs), expressions.repeat_distance); minimum_distance = util::apply_visitor(extract_value(feature,attrs), expressions.minimum_distance); minimum_padding = util::apply_visitor(extract_value(feature,attrs), expressions.minimum_padding); diff --git a/tests/visual_tests/styles/repeat-labels-1.xml b/tests/visual_tests/styles/repeat-labels-1.xml index e116f57a2..ca2b9f575 100644 --- a/tests/visual_tests/styles/repeat-labels-1.xml +++ b/tests/visual_tests/styles/repeat-labels-1.xml @@ -18,14 +18,14 @@ diff --git a/tests/visual_tests/styles/repeat-labels-2.xml b/tests/visual_tests/styles/repeat-labels-2.xml index b78dca811..07944c283 100644 --- a/tests/visual_tests/styles/repeat-labels-2.xml +++ b/tests/visual_tests/styles/repeat-labels-2.xml @@ -18,14 +18,14 @@ diff --git a/tests/visual_tests/styles/repeat-labels-3.xml b/tests/visual_tests/styles/repeat-labels-3.xml index fc24a2f38..cf8b31108 100644 --- a/tests/visual_tests/styles/repeat-labels-3.xml +++ b/tests/visual_tests/styles/repeat-labels-3.xml @@ -18,14 +18,14 @@ diff --git a/tests/visual_tests/styles/repeat-labels-4.xml b/tests/visual_tests/styles/repeat-labels-4.xml index 080c63e66..24db0f7ff 100644 --- a/tests/visual_tests/styles/repeat-labels-4.xml +++ b/tests/visual_tests/styles/repeat-labels-4.xml @@ -18,14 +18,14 @@