diff --git a/include/mapnik/text/placement_finder_ng.hpp b/include/mapnik/text/placement_finder_ng.hpp index 728b02d97..fcafb9365 100644 --- a/include/mapnik/text/placement_finder_ng.hpp +++ b/include/mapnik/text/placement_finder_ng.hpp @@ -58,12 +58,9 @@ public: /** Try to place a single label at the given point. */ bool find_point_placement(pixel_position pos); - /** Iterate over the given path, placing line-following labels with respect to label_spacing. */ + /** Iterate over the given path, placing line-following labels or point labels with respect to label_spacing. */ template - bool find_line_placements(T & path); - /** Iterate over the given path, placing point labels with respect to label_spacing. */ - template - bool find_point_on_line_placements(T & path); + bool find_line_placements(T & path, bool points); /** Try next position alternative from placement_info. */ bool next_position(); diff --git a/src/symbolizer_helpers.cpp b/src/symbolizer_helpers.cpp index 3a6527c7f..332c457b1 100644 --- a/src/symbolizer_helpers.cpp +++ b/src/symbolizer_helpers.cpp @@ -87,12 +87,7 @@ bool text_symbolizer_helper::next_line_placement() clipped.clip_box(query_extent_.minx(), query_extent_.miny(), query_extent_.maxx(), query_extent_.maxy()); path_type path(t_, clipped, prj_trans_); - bool success; - if (points_on_line_) { - success = finder_.find_point_on_line_placements(path); - } else { - success = finder_.find_line_placements(path); - } + bool success = finder_.find_line_placements(path, points_on_line_); if (success) { //Found a placement diff --git a/src/text/placement_finder_ng.cpp b/src/text/placement_finder_ng.cpp index f90b1c15e..f376653db 100644 --- a/src/text/placement_finder_ng.cpp +++ b/src/text/placement_finder_ng.cpp @@ -233,7 +233,6 @@ bool placement_finder_ng::find_point_placement(pixel_position pos) pixel_position displacement = scale_factor_ * info_->properties.displacement + alignment_offset(); if (info_->properties.rotate_displacement) displacement = displacement.rotate(!orientation_); glyphs->set_base_point(pos + displacement); - box2d bbox; rotated_box2d(bbox, orientation_, layout_.width(), layout_.height()); bbox.re_center(glyphs->get_base_point().x, glyphs->get_base_point().y); @@ -276,46 +275,29 @@ bool placement_finder_ng::find_point_placement(pixel_position pos) return true; } - template -bool placement_finder_ng::find_point_on_line_placements(T & path) +bool placement_finder_ng::find_line_placements(T & path, bool points) { if (!layout_.size()) return true; vertex_cache pp(path); + bool success = false; while (pp.next_subpath()) { - if (pp.length() == 0.0) + if (points) { - success = find_point_placement(pp.current_position()) || success; - continue; + if (pp.length() == 0.0) + { + success = find_point_placement(pp.current_position()) || success; + continue; + } + } else { + if ((pp.length() < info_->properties.minimum_path_length) + || + (pp.length() < layout_.width())) continue; } - double spacing = get_spacing(pp.length(), 0); - pp.forward(spacing/2.); // first label should be placed at half the spacing - path_move_dx(pp); - do - { - success = find_point_placement(pp.current_position()) || success; - } while (pp.forward(spacing)); - } - return success; -} - -template -bool placement_finder_ng::find_line_placements(T & path) -{ - if (!layout_.size()) return true; - vertex_cache pp(path); - - bool success = false; - while (pp.next_subpath()) - { - if ((pp.length() < info_->properties.minimum_path_length) - || - (pp.length() < layout_.width())) continue; - - double spacing = get_spacing(pp.length(), layout_.width()); + double spacing = get_spacing(pp.length(), points ? 0. : layout_.width()); // first label should be placed at half the spacing pp.forward(spacing/2); @@ -323,16 +305,17 @@ bool placement_finder_ng::find_line_placements(T & path) do { tolerance_iterator tolerance_offset(info_->properties.label_position_tolerance, spacing); - vertex_cache::state state = pp.save_state(); while (tolerance_offset.next()) { - if (pp.move(tolerance_offset.get()) && single_line_placement(pp, info_->properties.upright)) + vertex_cache::scoped_state state(pp); + if (pp.move(tolerance_offset.get()) + && ( + (points && find_point_placement(pp.current_position())) + || (!points && single_line_placement(pp, info_->properties.upright)))) { success = true; - pp.restore_state(state); break; } - pp.restore_state(state); } } while (pp.forward(spacing)); } @@ -596,10 +579,8 @@ const pixel_position &glyph_positions::marker_pos() const typedef agg::conv_clip_polyline clipped_geometry_type; typedef coord_transform ClippedPathType; typedef coord_transform PathType; -template bool placement_finder_ng::find_point_on_line_placements(ClippedPathType &); -template bool placement_finder_ng::find_line_placements(ClippedPathType &); -template bool placement_finder_ng::find_point_on_line_placements(PathType &); -template bool placement_finder_ng::find_line_placements(PathType &); +template bool placement_finder_ng::find_line_placements(ClippedPathType &, bool); +template bool placement_finder_ng::find_line_placements(PathType &, bool); }// ns mapnik