From 16e5fefb4dffa8f0124a561d504de32c8234c91f Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Sun, 29 Jan 2012 20:04:31 +0100 Subject: [PATCH] Remove text_placement_info::initialize() to avoid incorrect usage of this object. --- include/mapnik/symbolizer_helpers.hpp | 5 +-- include/mapnik/text_placements.hpp | 24 +++++++------- include/mapnik/text_placements_list.hpp | 9 ++++-- include/mapnik/text_placements_simple.hpp | 11 +++++-- src/text_placements.cpp | 38 +++++++++++------------ 5 files changed, 49 insertions(+), 38 deletions(-) diff --git a/include/mapnik/symbolizer_helpers.hpp b/include/mapnik/symbolizer_helpers.hpp index 4869f07eb..6c9dcdcb5 100644 --- a/include/mapnik/symbolizer_helpers.hpp +++ b/include/mapnik/symbolizer_helpers.hpp @@ -65,8 +65,9 @@ public: { initialize_geometries(); if (!geometries_to_process_.size()) return; //TODO: Test this - placement_ = sym_.get_placement_options()->get_placement_info(); - placement_->init(scale_factor, width, height); + placement_ = sym_.get_placement_options()->get_placement_info( + scale_factor, std::make_pair(width, height), false); + //TODO: has_dimensions? Why? When? if (writer_.first) placement_->collect_extents = true; next_placement(); initialize_points(); diff --git a/include/mapnik/text_placements.hpp b/include/mapnik/text_placements.hpp index d4e159c55..31a6a7019 100644 --- a/include/mapnik/text_placements.hpp +++ b/include/mapnik/text_placements.hpp @@ -47,6 +47,7 @@ namespace mapnik { class text_placements; typedef std::pair position; +typedef std::pair dimension_type; enum label_placement_enum { POINT_PLACEMENT, @@ -134,7 +135,8 @@ 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); + text_placement_info(text_placements const* parent, + double scale_factor_, dimension_type dim, bool has_dimensions_); /** Get next placement. * This function is also called before the first placement is tried. * Each class has to return at least one position! @@ -143,11 +145,6 @@ public: */ virtual bool next()=0; virtual ~text_placement_info() {} - /** Initialize values used by placement finder. Only has to be done once - * per object. - */ - void init(double scale_factor_, - unsigned w = 0, unsigned h = 0, bool has_dimensions_ = false); /** Properties actually used by placement finder and renderer. Values in * here are modified each time next() is called. */ @@ -158,7 +155,7 @@ public: /* TODO: Don't know what this is used for. */ bool has_dimensions; /* TODO: Don't know what this is used for. */ - std::pair dimensions; + dimension_type dimensions; /** Set scale factor. */ void set_scale_factor(double factor) { scale_factor = factor; } /** Get scale factor. */ @@ -204,7 +201,9 @@ public: * return text_placement_info_ptr(new text_placement_info_XXX(this)); * } */ - virtual text_placement_info_ptr get_placement_info() const =0; + virtual text_placement_info_ptr get_placement_info( + double scale_factor_, dimension_type dim, + bool has_dimensions_) const =0; /** Get a list of all expressions used in any placement. * This function is used to collect attributes. */ @@ -227,7 +226,8 @@ class text_placements_info_dummy; class MAPNIK_DECL text_placements_dummy: public text_placements { public: - text_placement_info_ptr get_placement_info() const; + text_placement_info_ptr get_placement_info( + double scale_factor, dimension_type dim, bool has_dimensions) const; friend class text_placement_info_dummy; }; @@ -235,8 +235,10 @@ public: class MAPNIK_DECL text_placement_info_dummy : public text_placement_info { public: - text_placement_info_dummy(text_placements_dummy const* parent) : text_placement_info(parent), - state(0), parent_(parent) {} + 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), + state(0), parent_(parent) {} bool next(); private: unsigned state; diff --git a/include/mapnik/text_placements_list.hpp b/include/mapnik/text_placements_list.hpp index e43fe724a..3453c3010 100644 --- a/include/mapnik/text_placements_list.hpp +++ b/include/mapnik/text_placements_list.hpp @@ -33,7 +33,8 @@ class text_placements_list: public text_placements { public: text_placements_list(); - text_placement_info_ptr get_placement_info() const; + text_placement_info_ptr get_placement_info( + double scale_factor, dimension_type dim, bool has_dimensions) const; virtual std::set get_all_expressions(); text_symbolizer_properties & add(); text_symbolizer_properties & get(unsigned i); @@ -48,8 +49,10 @@ private: class text_placement_info_list : public text_placement_info { public: - text_placement_info_list(text_placements_list const* parent) : - text_placement_info(parent), state(0), parent_(parent) {} + 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), + state(0), parent_(parent) {} bool next(); private: unsigned state; diff --git a/include/mapnik/text_placements_simple.hpp b/include/mapnik/text_placements_simple.hpp index 2c9efed7c..575dee4cd 100644 --- a/include/mapnik/text_placements_simple.hpp +++ b/include/mapnik/text_placements_simple.hpp @@ -49,7 +49,8 @@ class text_placements_simple: public text_placements public: text_placements_simple(); text_placements_simple(std::string positions); - text_placement_info_ptr get_placement_info() const; + text_placement_info_ptr get_placement_info( + double scale_factor, dimension_type dim, bool has_dimensions) const; void set_positions(std::string positions); std::string get_positions(); private: @@ -64,8 +65,12 @@ private: class text_placement_info_simple : public text_placement_info { public: - text_placement_info_simple(text_placements_simple const* parent) : - text_placement_info(parent), state(0), position_state(0), parent_(parent) {} + 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), + state(0), position_state(0), parent_(parent) + { + } bool next(); protected: bool next_position_only(); diff --git a/src/text_placements.cpp b/src/text_placements.cpp index f12772ab9..457e24d78 100644 --- a/src/text_placements.cpp +++ b/src/text_placements.cpp @@ -328,11 +328,13 @@ std::set text_placements::get_all_expressions() /************************************************************************/ -text_placement_info::text_placement_info(text_placements const* parent): - properties(parent->properties), - scale_factor(1), - has_dimensions(false), - collect_extents(false) +text_placement_info::text_placement_info(text_placements const* parent, + double scale_factor_, dimension_type dim, bool has_dimensions_) + : properties(parent->properties), + scale_factor(scale_factor_), + has_dimensions(has_dimensions_), + dimensions(dim), + collect_extents(false) { } @@ -344,17 +346,11 @@ bool text_placement_info_dummy::next() return true; } -text_placement_info_ptr text_placements_dummy::get_placement_info() const +text_placement_info_ptr text_placements_dummy::get_placement_info( + double scale_factor, dimension_type dim, bool has_dimensions) const { - return text_placement_info_ptr(new text_placement_info_dummy(this)); -} - -void text_placement_info::init(double scale_factor_, - unsigned w, unsigned h, bool has_dimensions_) -{ - scale_factor = scale_factor_; - dimensions = std::make_pair(w, h); - has_dimensions = has_dimensions_; + return text_placement_info_ptr(new text_placement_info_dummy( + this, scale_factor, dim, has_dimensions)); } /************************************************************************/ @@ -419,9 +415,11 @@ bool text_placement_info_simple::next_position_only() return true; } -text_placement_info_ptr text_placements_simple::get_placement_info() const +text_placement_info_ptr text_placements_simple::get_placement_info( + double scale_factor, dimension_type dim, bool has_dimensions) const { - return text_placement_info_ptr(new text_placement_info_simple(this)); + return text_placement_info_ptr(new text_placement_info_simple(this, + scale_factor, dim, has_dimensions)); } /** Position string: [POS][SIZE] @@ -517,9 +515,11 @@ text_symbolizer_properties & text_placements_list::get(unsigned i) /***************************************************************************/ -text_placement_info_ptr text_placements_list::get_placement_info() const +text_placement_info_ptr text_placements_list::get_placement_info( + double scale_factor, dimension_type dim, bool has_dimensions) const { - return text_placement_info_ptr(new text_placement_info_list(this)); + return text_placement_info_ptr(new text_placement_info_list(this, + scale_factor, dim, has_dimensions)); } text_placements_list::text_placements_list() : text_placements(), list_(0)