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> struct TextPlacementsWrap: text_placements, wrapper<text_placements>
{ {
text_placement_info_ptr get_placement_info(double scale_factor_, dimension_type dim, text_placement_info_ptr get_placement_info(double scale_factor_) const
bool has_dimensions_) const
{ {
python_block_auto_unblock b; python_block_auto_unblock b;
return this->get_override("get_placement_info")(); 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> struct TextPlacementInfoWrap: text_placement_info, wrapper<text_placement_info>
{ {
TextPlacementInfoWrap(text_placements const* parent, TextPlacementInfoWrap(text_placements const* parent,
double scale_factor_, dimension_type dim, bool has_dimensions_) double scale_factor_)
: text_placement_info(parent, scale_factor_, dim, has_dimensions_) : text_placement_info(parent, scale_factor_)
{ {
} }
@ -421,15 +420,13 @@ void export_text_placement()
boost::shared_ptr<TextPlacementInfoWrap>, boost::shared_ptr<TextPlacementInfoWrap>,
boost::noncopyable> boost::noncopyable>
("TextPlacementInfo", ("TextPlacementInfo",
init<text_placements const*, double, dimension_type, bool>()) init<text_placements const*, double>())
.def("next", pure_virtual(&text_placement_info::next)) .def("next", pure_virtual(&text_placement_info::next))
.def("get_actual_label_spacing", &text_placement_info::get_actual_label_spacing) .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_distance", &text_placement_info::get_actual_minimum_distance)
.def("get_actual_minimum_padding", &text_placement_info::get_actual_minimum_padding) .def("get_actual_minimum_padding", &text_placement_info::get_actual_minimum_padding)
.def_readwrite("properties", &text_placement_info::properties) .def_readwrite("properties", &text_placement_info::properties)
.def_readwrite("scale_factor", &text_placement_info::scale_factor) .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> >(); 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. /** Additional boxes to take into account when finding placement.
* Used for finding line placements where multiple placements are returned. * Used for finding line placements where multiple placements are returned.
* Boxes are relative to starting point of current placement. * Boxes are relative to starting point of current placement.
* Only used for point placements!
*/ */
std::vector<box2d<double> > additional_boxes; std::vector<box2d<double> > additional_boxes;

View file

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

View file

@ -27,7 +27,6 @@
#include <mapnik/config.hpp> #include <mapnik/config.hpp>
#include <mapnik/text_properties.hpp> #include <mapnik/text_properties.hpp>
#include <mapnik/formatting/base.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 namespace mapnik
{ {
@ -43,8 +42,7 @@ class text_placement_info : boost::noncopyable
public: public:
/** Constructor. Takes the parent text_placements object as a parameter /** Constructor. Takes the parent text_placements object as a parameter
* to read defaults from it. */ * to read defaults from it. */
text_placement_info(text_placements const* parent, text_placement_info(text_placements const* parent, double scale_factor_);
double scale_factor_, dimension_type dim, bool has_dimensions_);
/** Get next placement. /** Get next placement.
* This function is also called before the first placement is tried. * This function is also called before the first placement is tried.
* Each class has to return at least one position! * Each class has to return at least one position!
@ -60,10 +58,6 @@ public:
/** Scale factor used by the renderer. */ /** Scale factor used by the renderer. */
double scale_factor; 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. */ /** Set scale factor. */
void set_scale_factor(double factor) { scale_factor = factor; } void set_scale_factor(double factor) { scale_factor = factor; }
/** Get scale factor. */ /** Get scale factor. */
@ -100,8 +94,7 @@ public:
* } * }
*/ */
virtual text_placement_info_ptr get_placement_info( virtual text_placement_info_ptr get_placement_info(
double scale_factor_, dimension_type dim, double scale_factor_) const =0;
bool has_dimensions_) const =0;
/** Get a list of all expressions used in any placement. /** Get a list of all expressions used in any placement.
* This function is used to collect attributes. * 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 class MAPNIK_DECL text_placements_dummy: public text_placements
{ {
public: public:
text_placement_info_ptr get_placement_info( text_placement_info_ptr get_placement_info(double scale_factor) const;
double scale_factor, dimension_type dim, bool has_dimensions) const;
friend class text_placement_info_dummy; friend class text_placement_info_dummy;
}; };
@ -43,9 +42,8 @@ public:
class MAPNIK_DECL text_placement_info_dummy : public text_placement_info class MAPNIK_DECL text_placement_info_dummy : public text_placement_info
{ {
public: public:
text_placement_info_dummy(text_placements_dummy const* parent, text_placement_info_dummy(text_placements_dummy const* parent, double scale_factor)
double scale_factor, dimension_type dim, bool has_dimensions) : text_placement_info(parent, scale_factor),
: text_placement_info(parent, scale_factor, dim, has_dimensions),
state(0), parent_(parent) {} state(0), parent_(parent) {}
bool next(); bool next();
private: private:

View file

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

View file

@ -49,8 +49,7 @@ class text_placements_simple: public text_placements
public: public:
text_placements_simple(); text_placements_simple();
text_placements_simple(std::string positions); text_placements_simple(std::string positions);
text_placement_info_ptr get_placement_info( text_placement_info_ptr get_placement_info(double scale_factor) const;
double scale_factor, dimension_type dim, bool has_dimensions) const;
void set_positions(std::string positions); void set_positions(std::string positions);
std::string get_positions(); std::string get_positions();
static text_placements_ptr from_xml(boost::property_tree::ptree const &xml, fontset_map const & fontsets); 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: public:
text_placement_info_simple(text_placements_simple const* parent, text_placement_info_simple(text_placements_simple const* parent,
double scale_factor, dimension_type dim, bool has_dimensions) double scale_factor)
: text_placement_info(parent, scale_factor, dim, has_dimensions), : text_placement_info(parent, scale_factor),
state(0), position_state(0), parent_(parent) 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 // overlap, minimum distance or edge avoidance - exit if condition occurs
box2d<double> e; box2d<double> e;
/*x axis: left to right, y axis: top to bottom (negative values higher)*/ /*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 e.init(current_placement->center.x + dx, // Bottom Left
current_placement->center.y - dy - ci.ymin, /*ymin usually <0 */ current_placement->center.y - dy - ci.ymin, // ymin usually <0
current_placement->center.x + dx + ci.width, // Top Right current_placement->center.x + dx + ci.width, // Top Right
current_placement->center.y - dy - ci.ymax); current_placement->center.y - dy - ci.ymax);
}
// if there is an overlap with existing envelopes, then exit - no placement // 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()))) { 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; cosa = -cosa;
} }
box2d<double> e; box2d<double> e(x, y, x + cwidth*cosa, y - cwidth*sina);
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 // 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, e.expand_to_include(x - ci.height()*sina,
y - ci.height()*cosa); y - ci.height()*cosa);
e.expand_to_include(x + (cwidth*cosa - ci.height()*sina), e.expand_to_include(x + (cwidth*cosa - ci.height()*sina),
y - (cwidth*sina + ci.height()*cosa)); y - (cwidth*sina + ci.height()*cosa));
}
if (!detector_.extent().intersects(e) || if (!detector_.extent().intersects(e) ||
!detector_.has_placement(e, info_.get_string(), pi.get_actual_minimum_distance())) !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, 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), : properties(parent->defaults),
scale_factor(scale_factor_), scale_factor(scale_factor_)
has_dimensions(has_dimensions_),
dimensions(dim)
{ {
} }

View file

@ -33,10 +33,10 @@ bool text_placement_info_dummy::next()
} }
text_placement_info_ptr text_placements_dummy::get_placement_info( 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>( return text_placement_info_ptr(boost::make_shared<text_placement_info_dummy>(
this, scale_factor, dim, has_dimensions)); this, scale_factor));
} }
} //ns mapnik } //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( text_placement_info_ptr text_placements_list::get_placement_info(double scale_factor) const
double scale_factor, dimension_type dim, bool has_dimensions) const
{ {
return text_placement_info_ptr(boost::make_shared<text_placement_info_list>(this, return text_placement_info_ptr(
scale_factor, dim, has_dimensions)); boost::make_shared<text_placement_info_list>(this, scale_factor));
} }
text_placements_list::text_placements_list() : text_placements(), list_(0) 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( 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, return text_placement_info_ptr(
scale_factor, dim, has_dimensions)); boost::make_shared<text_placement_info_simple>(this, scale_factor));
} }
/** Position string: [POS][SIZE] /** Position string: [POS][SIZE]