Remove has_dimensions and dimensions from text_placement_info.

This functionality is better provided by placement_finder.additional_boxes.
This commit is contained in:
Hermann Kraus 2012-03-04 16:38:40 +01:00
parent 46272d836b
commit 5578bdb6f9
12 changed files with 37 additions and 77 deletions

View file

@ -251,8 +251,7 @@ struct ListNodeWrap: formatting::list_node, wrapper<formatting::list_node>
struct TextPlacementsWrap: text_placements, wrapper<text_placements>
{
text_placement_info_ptr get_placement_info(double scale_factor_, dimension_type dim,
bool has_dimensions_) const
text_placement_info_ptr get_placement_info(double scale_factor_) const
{
python_block_auto_unblock b;
return this->get_override("get_placement_info")();
@ -262,8 +261,8 @@ struct TextPlacementsWrap: text_placements, wrapper<text_placements>
struct TextPlacementInfoWrap: text_placement_info, wrapper<text_placement_info>
{
TextPlacementInfoWrap(text_placements const* parent,
double scale_factor_, dimension_type dim, bool has_dimensions_)
: text_placement_info(parent, scale_factor_, dim, has_dimensions_)
double scale_factor_)
: text_placement_info(parent, scale_factor_)
{
}
@ -421,15 +420,13 @@ void export_text_placement()
boost::shared_ptr<TextPlacementInfoWrap>,
boost::noncopyable>
("TextPlacementInfo",
init<text_placements const*, double, dimension_type, bool>())
init<text_placements const*, double>())
.def("next", pure_virtual(&text_placement_info::next))
.def("get_actual_label_spacing", &text_placement_info::get_actual_label_spacing)
.def("get_actual_minimum_distance", &text_placement_info::get_actual_minimum_distance)
.def("get_actual_minimum_padding", &text_placement_info::get_actual_minimum_padding)
.def_readwrite("properties", &text_placement_info::properties)
.def_readwrite("scale_factor", &text_placement_info::scale_factor)
.def_readwrite("has_dimensions", &text_placement_info::has_dimensions)
.def_readwrite("dimensions", &text_placement_info::dimensions)
;
register_ptr_to_python<boost::shared_ptr<text_placement_info> >();

View file

@ -72,6 +72,7 @@ public:
/** 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;

View file

@ -69,9 +69,7 @@ public:
{
initialize_geometries();
if (!geometries_to_process_.size()) return;
placement_ = sym_.get_placement_options()->get_placement_info(
scale_factor, std::make_pair(width, height), false);
//TODO: has_dimensions? Why? When?
placement_ = sym_.get_placement_options()->get_placement_info(scale_factor);
next_placement();
initialize_points();
}

View file

@ -27,7 +27,6 @@
#include <mapnik/config.hpp>
#include <mapnik/text_properties.hpp>
#include <mapnik/formatting/base.hpp>
#include <mapnik/text_path.hpp> //TODO: Remove this again after text_placement_info::placements is moved to a better place.
namespace mapnik
{
@ -43,8 +42,7 @@ class text_placement_info : boost::noncopyable
public:
/** Constructor. Takes the parent text_placements object as a parameter
* to read defaults from it. */
text_placement_info(text_placements const* parent,
double scale_factor_, dimension_type dim, bool has_dimensions_);
text_placement_info(text_placements const* parent, double scale_factor_);
/** Get next placement.
* This function is also called before the first placement is tried.
* Each class has to return at least one position!
@ -60,10 +58,6 @@ public:
/** Scale factor used by the renderer. */
double scale_factor;
/* TODO: Don't know what this is used for. */
bool has_dimensions;
/* TODO: Don't know what this is used for. */
dimension_type dimensions;
/** Set scale factor. */
void set_scale_factor(double factor) { scale_factor = factor; }
/** Get scale factor. */
@ -100,8 +94,7 @@ public:
* }
*/
virtual text_placement_info_ptr get_placement_info(
double scale_factor_, dimension_type dim,
bool has_dimensions_) const =0;
double scale_factor_) const =0;
/** Get a list of all expressions used in any placement.
* This function is used to collect attributes.
*/

View file

@ -34,8 +34,7 @@ class text_placements_info_dummy;
class MAPNIK_DECL text_placements_dummy: public text_placements
{
public:
text_placement_info_ptr get_placement_info(
double scale_factor, dimension_type dim, bool has_dimensions) const;
text_placement_info_ptr get_placement_info(double scale_factor) const;
friend class text_placement_info_dummy;
};
@ -43,9 +42,8 @@ public:
class MAPNIK_DECL text_placement_info_dummy : public text_placement_info
{
public:
text_placement_info_dummy(text_placements_dummy const* parent,
double scale_factor, dimension_type dim, bool has_dimensions)
: text_placement_info(parent, scale_factor, dim, has_dimensions),
text_placement_info_dummy(text_placements_dummy const* parent, double scale_factor)
: text_placement_info(parent, scale_factor),
state(0), parent_(parent) {}
bool next();
private:

View file

@ -33,8 +33,7 @@ class text_placements_list: public text_placements
{
public:
text_placements_list();
text_placement_info_ptr get_placement_info(
double scale_factor, dimension_type dim, bool has_dimensions) const;
text_placement_info_ptr get_placement_info(double scale_factor) const;
virtual void add_expressions(expression_set &output);
text_symbolizer_properties & add();
text_symbolizer_properties & get(unsigned i);
@ -50,9 +49,8 @@ private:
class text_placement_info_list : public text_placement_info
{
public:
text_placement_info_list(text_placements_list const* parent,
double scale_factor, dimension_type dim, bool has_dimensions) :
text_placement_info(parent, scale_factor, dim, has_dimensions),
text_placement_info_list(text_placements_list const* parent, double scale_factor) :
text_placement_info(parent, scale_factor),
state(0), parent_(parent) {}
bool next();
private:

View file

@ -49,8 +49,7 @@ class text_placements_simple: public text_placements
public:
text_placements_simple();
text_placements_simple(std::string positions);
text_placement_info_ptr get_placement_info(
double scale_factor, dimension_type dim, bool has_dimensions) const;
text_placement_info_ptr get_placement_info(double scale_factor) const;
void set_positions(std::string positions);
std::string get_positions();
static text_placements_ptr from_xml(boost::property_tree::ptree const &xml, fontset_map const & fontsets);
@ -67,8 +66,8 @@ class text_placement_info_simple : public text_placement_info
{
public:
text_placement_info_simple(text_placements_simple const* parent,
double scale_factor, dimension_type dim, bool has_dimensions)
: text_placement_info(parent, scale_factor, dim, has_dimensions),
double scale_factor)
: text_placement_info(parent, scale_factor),
state(0), position_state(0), parent_(parent)
{
}

View file

@ -426,22 +426,10 @@ void placement_finder<DetectorT>::find_point_placement(double label_x, double la
// overlap, minimum distance or edge avoidance - exit if condition occurs
box2d<double> e;
/*x axis: left to right, y axis: top to bottom (negative values higher)*/
if (pi.has_dimensions)
{
e.init(current_placement->center.x - (pi.dimensions.first/2.0), // Top Left
current_placement->center.y - (pi.dimensions.second/2.0),
current_placement->center.x + (pi.dimensions.first/2.0), // Bottom Right
current_placement->center.y + (pi.dimensions.second/2.0));
}
else
{
e.init(current_placement->center.x + dx, // Bottom Left
current_placement->center.y - dy - ci.ymin, /*ymin usually <0 */
current_placement->center.x + dx + ci.width, // Top Right
current_placement->center.y - dy - ci.ymax);
}
e.init(current_placement->center.x + dx, // Bottom Left
current_placement->center.y - dy - ci.ymin, // ymin usually <0
current_placement->center.x + dx + ci.width, // Top Right
current_placement->center.y - dy - ci.ymax);
// if there is an overlap with existing envelopes, then exit - no placement
if (!detector_.extent().intersects(e) || (!p.allow_overlap && !detector_.has_point_placement(e, pi.get_actual_minimum_distance()))) {
@ -890,21 +878,12 @@ bool placement_finder<DetectorT>::test_placement(const std::auto_ptr<text_path>
cosa = -cosa;
}
box2d<double> e;
if (pi.has_dimensions)
{
e.init(x, y, x + pi.dimensions.first, y + pi.dimensions.second);
}
else
{
// put four corners of the letter into envelope
e.init(x, y, x + cwidth*cosa,
y - cwidth*sina);
e.expand_to_include(x - ci.height()*sina,
y - ci.height()*cosa);
e.expand_to_include(x + (cwidth*cosa - ci.height()*sina),
y - (cwidth*sina + ci.height()*cosa));
}
box2d<double> e(x, y, x + cwidth*cosa, y - cwidth*sina);
// put four corners of the letter into envelope
e.expand_to_include(x - ci.height()*sina,
y - ci.height()*cosa);
e.expand_to_include(x + (cwidth*cosa - ci.height()*sina),
y - (cwidth*sina + ci.height()*cosa));
if (!detector_.extent().intersects(e) ||
!detector_.has_placement(e, info_.get_string(), pi.get_actual_minimum_distance()))

View file

@ -35,11 +35,9 @@ void text_placements::add_expressions(expression_set &output)
/************************************************************************/
text_placement_info::text_placement_info(text_placements const* parent,
double scale_factor_, dimension_type dim, bool has_dimensions_)
double scale_factor_)
: properties(parent->defaults),
scale_factor(scale_factor_),
has_dimensions(has_dimensions_),
dimensions(dim)
scale_factor(scale_factor_)
{
}

View file

@ -33,10 +33,10 @@ bool text_placement_info_dummy::next()
}
text_placement_info_ptr text_placements_dummy::get_placement_info(
double scale_factor, dimension_type dim, bool has_dimensions) const
double scale_factor) const
{
return text_placement_info_ptr(boost::make_shared<text_placement_info_dummy>(
this, scale_factor, dim, has_dimensions));
this, scale_factor));
}
} //ns mapnik

View file

@ -56,11 +56,10 @@ text_symbolizer_properties & text_placements_list::get(unsigned i)
/***************************************************************************/
text_placement_info_ptr text_placements_list::get_placement_info(
double scale_factor, dimension_type dim, bool has_dimensions) const
text_placement_info_ptr text_placements_list::get_placement_info(double scale_factor) const
{
return text_placement_info_ptr(boost::make_shared<text_placement_info_list>(this,
scale_factor, dim, has_dimensions));
return text_placement_info_ptr(
boost::make_shared<text_placement_info_list>(this, scale_factor));
}
text_placements_list::text_placements_list() : text_placements(), list_(0)

View file

@ -100,10 +100,10 @@ bool text_placement_info_simple::next_position_only()
}
text_placement_info_ptr text_placements_simple::get_placement_info(
double scale_factor, dimension_type dim, bool has_dimensions) const
double scale_factor) const
{
return text_placement_info_ptr(boost::make_shared<text_placement_info_simple>(this,
scale_factor, dim, has_dimensions));
return text_placement_info_ptr(
boost::make_shared<text_placement_info_simple>(this, scale_factor));
}
/** Position string: [POS][SIZE]