From 162f82cba5b0fb984c425586c6a4b354917abc47 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Tue, 4 Aug 2015 13:29:16 +0000 Subject: [PATCH 1/2] ensure null text has no bbox --- include/mapnik/text/placement_finder.hpp | 2 +- src/text/placement_finder.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/mapnik/text/placement_finder.hpp b/include/mapnik/text/placement_finder.hpp index 0460b2c52..8bb63a759 100644 --- a/include/mapnik/text/placement_finder.hpp +++ b/include/mapnik/text/placement_finder.hpp @@ -74,7 +74,7 @@ private: // Checks for collision. 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; + bool add_marker(glyph_positions_ptr & glyphs, pixel_position const& pos, std::vector> & bboxes) const; // Maps upright==auto, left-only and right-only to left,right to simplify processing. // angle = angle of at start of line (to estimate best option for upright==auto) text_upright_e simplify_upright(text_upright_e upright, double angle) const; diff --git a/src/text/placement_finder.cpp b/src/text/placement_finder.cpp index 53dda7da7..4c97e4038 100644 --- a/src/text/placement_finder.cpp +++ b/src/text/placement_finder.cpp @@ -143,7 +143,7 @@ bool placement_finder::find_point_placement(pixel_position const& pos) /* For point placements it is faster to just check the bounding box. */ if (collision(bbox, layouts_.text(), false)) return false; - if (layout.num_lines()) bboxes.push_back(std::move(bbox)); + if (layout.glyphs_count()) bboxes.push_back(std::move(bbox)); pixel_position layout_offset = layout_center - glyphs->get_base_point(); layout_offset.y = -layout_offset.y; @@ -178,7 +178,7 @@ bool placement_finder::find_point_placement(pixel_position const& pos) } // add_marker first checks for collision and then updates the detector. - if (has_marker_ && !add_marker(glyphs, pos)) return false; + if (has_marker_ && !add_marker(glyphs, pos, bboxes)) return false; box2d label_box; bool first = true; @@ -418,7 +418,7 @@ void placement_finder::set_marker(marker_info_ptr m, box2d box, bool mar } -bool placement_finder::add_marker(glyph_positions_ptr & glyphs, pixel_position const& pos) const +bool placement_finder::add_marker(glyph_positions_ptr & glyphs, pixel_position const& pos, std::vector> & bboxes) const { pixel_position real_pos = (marker_unlocked_ ? pos : glyphs->get_base_point()) + marker_displacement_; box2d bbox = marker_box_; @@ -426,6 +426,7 @@ bool placement_finder::add_marker(glyph_positions_ptr & glyphs, pixel_position c glyphs->set_marker(marker_, real_pos); if (collision(bbox, layouts_.text(), false)) return false; detector_.insert(bbox); + bboxes.push_back(std::move(bbox)); return true; } From c1d8095d599d4c7c70fdf19e1abc489502516ff6 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Tue, 4 Aug 2015 13:38:52 +0000 Subject: [PATCH 2/2] shields: set marker after collision test --- src/text/placement_finder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/text/placement_finder.cpp b/src/text/placement_finder.cpp index 4c97e4038..086501e47 100644 --- a/src/text/placement_finder.cpp +++ b/src/text/placement_finder.cpp @@ -423,10 +423,10 @@ bool placement_finder::add_marker(glyph_positions_ptr & glyphs, pixel_position c pixel_position real_pos = (marker_unlocked_ ? pos : glyphs->get_base_point()) + marker_displacement_; box2d bbox = marker_box_; bbox.move(real_pos.x, real_pos.y); - glyphs->set_marker(marker_, real_pos); if (collision(bbox, layouts_.text(), false)) return false; detector_.insert(bbox); bboxes.push_back(std::move(bbox)); + glyphs->set_marker(marker_, real_pos); return true; }