Remove old placement_finder code and rename placement_finder_ng => placement_finder.
This commit is contained in:
parent
5fbda3e579
commit
f40464a815
7 changed files with 29 additions and 1263 deletions
|
@ -1,170 +0,0 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef MAPNIK_PLACEMENT_FINDER_HPP
|
||||
#define MAPNIK_PLACEMENT_FINDER_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/text_properties.hpp>
|
||||
#include <mapnik/text_placements/base.hpp>
|
||||
#include <mapnik/symbolizer_helpers.hpp>
|
||||
#include <mapnik/label_collision_detector.hpp>
|
||||
#include <mapnik/ctrans.hpp>
|
||||
|
||||
|
||||
// agg
|
||||
#include "agg_conv_clip_polyline.h"
|
||||
|
||||
|
||||
// stl
|
||||
#include <queue>
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
class text_placement_info;
|
||||
class string_info;
|
||||
class text_path;
|
||||
|
||||
typedef agg::conv_clip_polyline<geometry_type> clipped_geometry_type;
|
||||
typedef coord_transform<CoordTransform,clipped_geometry_type> ClippedPathType;
|
||||
typedef coord_transform<CoordTransform,geometry_type> PathType;
|
||||
|
||||
typedef label_collision_detector4 DetectorType;
|
||||
|
||||
|
||||
template <typename DetectorT>
|
||||
class placement_finder : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
placement_finder(Feature const& feature,
|
||||
text_placement_info const& placement_info,
|
||||
string_info const& info,
|
||||
DetectorT & detector,
|
||||
box2d<double> const& extent);
|
||||
|
||||
/** Try place a single label at the given point. */
|
||||
void find_point_placement(double pos_x, double pos_y, double angle=0.0);
|
||||
|
||||
/** Iterate over the given path, placing point labels with respect to label_spacing. */
|
||||
template <typename T>
|
||||
void find_point_placements(T & path);
|
||||
|
||||
/** Iterate over the given path, placing line-following labels with respect to label_spacing. */
|
||||
template <typename T>
|
||||
void find_line_placements(T & path);
|
||||
|
||||
/** Add placements to detector. */
|
||||
void update_detector();
|
||||
|
||||
/** Remove old placements. */
|
||||
void clear_placements();
|
||||
|
||||
inline placements_type const& get_results() { return placements_; }
|
||||
|
||||
std::vector<box2d<double> > & additional_boxes() { return additional_boxes_;}
|
||||
std::vector<box2d<double> > const& additional_boxes() const { return additional_boxes_;}
|
||||
|
||||
void set_collect_extents(bool collect) { collect_extents_ = collect; }
|
||||
bool get_collect_extents() const { return collect_extents_; }
|
||||
|
||||
box2d<double> const& get_extents() const { return extents_; }
|
||||
|
||||
private:
|
||||
///Helpers for find_line_placement
|
||||
|
||||
///Returns a possible placement on the given line, does not test for collisions
|
||||
//index: index of the node the current line ends on
|
||||
//distance: distance along the given index that the placement should start at, this includes the offset,
|
||||
// as such it may be > or < the length of the current line, so this must be checked for
|
||||
//orientation: if set to != 0 the placement will be attempted with the given orientation
|
||||
// otherwise it will autodetect the orientation.
|
||||
// If >= 50% of the characters end up upside down, it will be retried the other way.
|
||||
// RETURN: 1/-1 depending which way up the string ends up being.
|
||||
std::auto_ptr<text_path> get_placement_offset(std::vector<vertex2d> const& path_positions,
|
||||
std::vector<double> const& path_distances,
|
||||
int & orientation, unsigned index, double distance);
|
||||
|
||||
///Tests whether the given text_path be placed without a collision
|
||||
// Returns true if it can
|
||||
// NOTE: This edits p.envelopes so it can be used afterwards (you must clear it otherwise)
|
||||
bool test_placement(std::auto_ptr<text_path> const& current_placement, int orientation);
|
||||
|
||||
///Does a line-circle intersect calculation
|
||||
// NOTE: Follow the strict pre conditions
|
||||
// Pre Conditions: x1,y1 is within radius distance of cx,cy. x2,y2 is outside radius distance of cx,cy
|
||||
// This means there is exactly one intersect point
|
||||
// Result is returned in ix, iy
|
||||
void find_line_circle_intersection(
|
||||
double cx, double cy, double radius,
|
||||
double x1, double y1, double x2, double y2,
|
||||
double & ix, double & iy);
|
||||
|
||||
void find_line_breaks();
|
||||
void init_string_size();
|
||||
void init_alignment();
|
||||
void adjust_position(text_path *current_placement);
|
||||
void add_line(double width, double height, bool first_line);
|
||||
|
||||
///General Internals
|
||||
DetectorT & detector_;
|
||||
box2d<double> const& dimensions_;
|
||||
string_info const& info_;
|
||||
text_symbolizer_properties const& p;
|
||||
text_placement_info const& pi;
|
||||
/** Length of the longest line after linebreaks.
|
||||
* Before find_line_breaks() this is the total length of the string.
|
||||
*/
|
||||
double string_width_;
|
||||
/** Height of the string after linebreaks.
|
||||
* Before find_line_breaks() this is the total length of the string.
|
||||
*/
|
||||
double string_height_;
|
||||
/** Height of the tallest font in the first line not including line spacing.
|
||||
* Used to determine the correct offset for the first line.
|
||||
*/
|
||||
double first_line_space_;
|
||||
vertical_alignment_e valign_;
|
||||
horizontal_alignment_e halign_;
|
||||
justify_alignment_e jalign_;
|
||||
std::vector<unsigned> line_breaks_;
|
||||
std::vector<std::pair<double, double> > line_sizes_;
|
||||
std::queue< box2d<double> > envelopes_;
|
||||
/** Used to return all placements found. */
|
||||
placements_type placements_;
|
||||
/** Bounding box of all texts placed. */
|
||||
box2d<double> extents_;
|
||||
/** Collect a bounding box of all texts placed. */
|
||||
bool collect_extents_;
|
||||
|
||||
/** Additional boxes to take into account when finding placement.
|
||||
* Used for finding line placements where multiple placements are returned.
|
||||
* Boxes are relative to starting point of current placement.
|
||||
* Only used for point placements!
|
||||
*/
|
||||
std::vector<box2d<double> > additional_boxes_;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // MAPNIK_PLACEMENT_FINDER_HPP
|
|
@ -28,7 +28,7 @@
|
|||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/marker.hpp>
|
||||
#include <mapnik/marker_cache.hpp>
|
||||
#include <mapnik/text/placement_finder_ng.hpp>
|
||||
#include <mapnik/text/placement_finder.hpp>
|
||||
#include <mapnik/proj_transform.hpp>
|
||||
#include <mapnik/ctrans.hpp>
|
||||
|
||||
|
@ -99,7 +99,7 @@ protected:
|
|||
bool points_on_line_;
|
||||
|
||||
text_placement_info_ptr placement_;
|
||||
placement_finder_ng finder_;
|
||||
placement_finder finder_;
|
||||
|
||||
//ShieldSymbolizer only
|
||||
void init_marker();
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifndef MAPNIK_PLACEMENT_FINDER_NG_HPP
|
||||
#define MAPNIK_PLACEMENT_FINDER_NG_HPP
|
||||
#ifndef MAPNIK_PLACEMENT_FINDER_HPP
|
||||
#define MAPNIK_PLACEMENT_FINDER_HPP
|
||||
|
||||
//mapnik
|
||||
#include <mapnik/box2d.hpp>
|
||||
|
@ -46,10 +46,10 @@ class feature_impl;
|
|||
typedef feature_impl Feature;
|
||||
class vertex_cache;
|
||||
|
||||
class placement_finder_ng : boost::noncopyable
|
||||
class placement_finder : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
placement_finder_ng(Feature const& feature,
|
||||
placement_finder(Feature const& feature,
|
||||
DetectorType & detector,
|
||||
box2d<double> const& extent,
|
||||
text_placement_info_ptr placement_info,
|
||||
|
@ -108,8 +108,6 @@ private:
|
|||
pixel_position marker_displacement_;
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<placement_finder_ng> placement_finder_ng_ptr;
|
||||
|
||||
}//ns mapnik
|
||||
|
||||
#endif // PLACEMENT_FINDER_NG_HPP
|
||||
#endif // PLACEMENT_FINDER_HPP
|
|
@ -2,7 +2,7 @@
|
|||
#define MAPNIK_TEXT_RENDERER_HPP
|
||||
|
||||
//mapnik
|
||||
#include <mapnik/text/placement_finder_ng.hpp>
|
||||
#include <mapnik/text/placement_finder.hpp>
|
||||
#include <mapnik/image_compositing.hpp>
|
||||
|
||||
//boost
|
||||
|
|
|
@ -190,7 +190,7 @@ source = Split(
|
|||
text/itemizer.cpp
|
||||
text/scrptrun.cpp
|
||||
text/face.cpp
|
||||
text/placement_finder_ng.cpp
|
||||
text/placement_finder.cpp
|
||||
text/renderer.cpp
|
||||
"""
|
||||
)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
*****************************************************************************/
|
||||
//mapnik
|
||||
#include <mapnik/text/placement_finder_ng.hpp>
|
||||
#include <mapnik/text/placement_finder.hpp>
|
||||
#include <mapnik/text/layout.hpp>
|
||||
#include <mapnik/text_properties.hpp>
|
||||
#include <mapnik/text/placements_list.hpp>
|
||||
|
@ -91,16 +91,16 @@ private:
|
|||
unsigned values_tried_;
|
||||
};
|
||||
|
||||
placement_finder_ng::placement_finder_ng(Feature const& feature, DetectorType &detector, box2d<double> const& extent, text_placement_info_ptr placement_info, face_manager_freetype &font_manager, double scale_factor)
|
||||
placement_finder::placement_finder(Feature const& feature, DetectorType &detector, box2d<double> const& extent, text_placement_info_ptr placement_info, face_manager_freetype &font_manager, double scale_factor)
|
||||
: feature_(feature), detector_(detector), extent_(extent), layout_(font_manager), info_(placement_info), valid_(true), scale_factor_(scale_factor), placements_(), has_marker_(false), marker_(), marker_box_()
|
||||
{
|
||||
}
|
||||
|
||||
bool placement_finder_ng::next_position()
|
||||
bool placement_finder::next_position()
|
||||
{
|
||||
if (!valid_)
|
||||
{
|
||||
MAPNIK_LOG_WARN(placement_finder_ng) << "next_position() called while last call already returned false!\n";
|
||||
MAPNIK_LOG_WARN(placement_finder) << "next_position() called while last call already returned false!\n";
|
||||
return false;
|
||||
}
|
||||
if (!info_->next())
|
||||
|
@ -127,12 +127,12 @@ bool placement_finder_ng::next_position()
|
|||
return true;
|
||||
}
|
||||
|
||||
const placements_list &placement_finder_ng::placements() const
|
||||
const placements_list &placement_finder::placements() const
|
||||
{
|
||||
return placements_;
|
||||
}
|
||||
|
||||
void placement_finder_ng::init_alignment()
|
||||
void placement_finder::init_alignment()
|
||||
{
|
||||
text_symbolizer_properties const& p = info_->properties;
|
||||
valign_ = p.valign;
|
||||
|
@ -181,7 +181,7 @@ void placement_finder_ng::init_alignment()
|
|||
}
|
||||
|
||||
|
||||
pixel_position placement_finder_ng::alignment_offset() const
|
||||
pixel_position placement_finder::alignment_offset() const
|
||||
{
|
||||
pixel_position result(0,0);
|
||||
// if needed, adjust for desired vertical alignment
|
||||
|
@ -204,7 +204,7 @@ pixel_position placement_finder_ng::alignment_offset() const
|
|||
return result;
|
||||
}
|
||||
|
||||
double placement_finder_ng::jalign_offset(double line_width) const
|
||||
double placement_finder::jalign_offset(double line_width) const
|
||||
{
|
||||
if (jalign_ == J_MIDDLE) return -(line_width / 2.0);
|
||||
if (jalign_ == J_LEFT) return -(layout_.width() / 2.0);
|
||||
|
@ -226,7 +226,7 @@ pixel_position pixel_position::rotate(rotation const& rot) const
|
|||
}
|
||||
|
||||
|
||||
bool placement_finder_ng::find_point_placement(pixel_position pos)
|
||||
bool placement_finder::find_point_placement(pixel_position pos)
|
||||
{
|
||||
glyph_positions_ptr glyphs = boost::make_shared<glyph_positions>();
|
||||
|
||||
|
@ -276,7 +276,7 @@ bool placement_finder_ng::find_point_placement(pixel_position pos)
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
bool placement_finder_ng::find_line_placements(T & path, bool points)
|
||||
bool placement_finder::find_line_placements(T & path, bool points)
|
||||
{
|
||||
if (!layout_.size()) return true;
|
||||
vertex_cache pp(path);
|
||||
|
@ -323,7 +323,7 @@ bool placement_finder_ng::find_line_placements(T & path, bool points)
|
|||
}
|
||||
|
||||
|
||||
bool placement_finder_ng::single_line_placement(vertex_cache &pp, text_upright_e orientation)
|
||||
bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e orientation)
|
||||
{
|
||||
vertex_cache::scoped_state s(pp);
|
||||
|
||||
|
@ -412,7 +412,7 @@ bool placement_finder_ng::single_line_placement(vertex_cache &pp, text_upright_e
|
|||
return true;
|
||||
}
|
||||
|
||||
void placement_finder_ng::path_move_dx(vertex_cache &pp)
|
||||
void placement_finder::path_move_dx(vertex_cache &pp)
|
||||
{
|
||||
double dx = info_->properties.displacement.x;
|
||||
if (dx != 0.0)
|
||||
|
@ -422,7 +422,7 @@ void placement_finder_ng::path_move_dx(vertex_cache &pp)
|
|||
}
|
||||
}
|
||||
|
||||
double placement_finder_ng::normalize_angle(double angle)
|
||||
double placement_finder::normalize_angle(double angle)
|
||||
{
|
||||
while (angle >= M_PI)
|
||||
angle -= 2*M_PI;
|
||||
|
@ -431,7 +431,7 @@ double placement_finder_ng::normalize_angle(double angle)
|
|||
return angle;
|
||||
}
|
||||
|
||||
double placement_finder_ng::get_spacing(double path_length, double layout_width) const
|
||||
double placement_finder::get_spacing(double path_length, double layout_width) const
|
||||
{
|
||||
int num_labels = 1;
|
||||
if (info_->properties.label_spacing > 0)
|
||||
|
@ -446,7 +446,7 @@ double placement_finder_ng::get_spacing(double path_length, double layout_width)
|
|||
return path_length / num_labels;
|
||||
}
|
||||
|
||||
bool placement_finder_ng::collision(const box2d<double> &box) const
|
||||
bool placement_finder::collision(const box2d<double> &box) const
|
||||
{
|
||||
if (!detector_.extent().intersects(box)
|
||||
||
|
||||
|
@ -464,7 +464,7 @@ bool placement_finder_ng::collision(const box2d<double> &box) const
|
|||
return false;
|
||||
}
|
||||
|
||||
void placement_finder_ng::set_marker(marker_info_ptr m, box2d<double> box, bool marker_unlocked, const pixel_position &marker_displacement)
|
||||
void placement_finder::set_marker(marker_info_ptr m, box2d<double> box, bool marker_unlocked, const pixel_position &marker_displacement)
|
||||
{
|
||||
marker_ = m;
|
||||
marker_box_ = box;
|
||||
|
@ -474,7 +474,7 @@ void placement_finder_ng::set_marker(marker_info_ptr m, box2d<double> box, bool
|
|||
}
|
||||
|
||||
|
||||
bool placement_finder_ng::add_marker(glyph_positions_ptr glyphs, const pixel_position &pos) const
|
||||
bool placement_finder::add_marker(glyph_positions_ptr glyphs, const pixel_position &pos) const
|
||||
{
|
||||
pixel_position real_pos = (marker_unlocked_ ? pos : glyphs->get_base_point()) + marker_displacement_;
|
||||
box2d<double> bbox = marker_box_;
|
||||
|
@ -485,7 +485,7 @@ bool placement_finder_ng::add_marker(glyph_positions_ptr glyphs, const pixel_pos
|
|||
return true;
|
||||
}
|
||||
|
||||
box2d<double> placement_finder_ng::get_bbox(glyph_info const& glyph, pixel_position const& pos, rotation const& rot)
|
||||
box2d<double> placement_finder::get_bbox(glyph_info const& glyph, pixel_position const& pos, rotation const& rot)
|
||||
{
|
||||
/*
|
||||
|
||||
|
@ -579,8 +579,8 @@ const pixel_position &glyph_positions::marker_pos() const
|
|||
typedef agg::conv_clip_polyline<geometry_type> clipped_geometry_type;
|
||||
typedef coord_transform<CoordTransform,clipped_geometry_type> ClippedPathType;
|
||||
typedef coord_transform<CoordTransform,geometry_type> PathType;
|
||||
template bool placement_finder_ng::find_line_placements<ClippedPathType>(ClippedPathType &, bool);
|
||||
template bool placement_finder_ng::find_line_placements<PathType>(PathType &, bool);
|
||||
template bool placement_finder::find_line_placements<ClippedPathType>(ClippedPathType &, bool);
|
||||
template bool placement_finder::find_line_placements<PathType>(PathType &, bool);
|
||||
|
||||
|
||||
}// ns mapnik
|
Loading…
Reference in a new issue