+ improve c++ style

+ formatting
This commit is contained in:
artemp 2013-07-16 11:15:00 +01:00
parent 43723d3f81
commit cbfe228790
5 changed files with 79 additions and 74 deletions

View file

@ -33,11 +33,9 @@
#include <mapnik/ctrans.hpp>
#include <mapnik/noncopyable.hpp>
// agg
#include "agg_conv_clip_polyline.h"
// stl
#include <queue>
@ -65,21 +63,21 @@ public:
DetectorT & detector,
box2d<double> const& extent);
/** Try place a single label at the given point. */
// 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. */
// 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. */
// 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. */
// Add placements to detector. */
void update_detector();
/** Remove old placements. */
// Remove old placements. */
void clear_placements();
inline placements_type const& get_results() { return placements_; }
@ -134,17 +132,14 @@ private:
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.
*/
// 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.
*/
// 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.
*/
// 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_;
@ -152,18 +147,17 @@ private:
std::vector<unsigned> line_breaks_;
std::vector<std::pair<double, double> > line_sizes_;
std::queue< box2d<double> > envelopes_;
/** Used to return all placements found. */
// Used to return all placements found. */
placements_type placements_;
/** Bounding box of all texts placed. */
// Bounding box of all texts placed. */
box2d<double> extents_;
/** Collect a bounding box of all texts placed. */
// 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!
*/
// 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

@ -40,11 +40,10 @@ template <typename T> class face_manager;
class MAPNIK_DECL processed_text : mapnik::noncopyable
{
public:
class processed_expression
struct processed_expression
{
public:
processed_expression(char_properties const& properties, UnicodeString const& text) :
p(properties), str(text) {}
processed_expression(char_properties const& properties, UnicodeString const& text)
: p(properties), str(text) {}
char_properties p;
UnicodeString str;
};
@ -57,7 +56,7 @@ public:
typedef std::list<processed_expression> expression_list;
expression_list::const_iterator begin() const;
expression_list::const_iterator end() const;
string_info &get_string_info();
string_info const& get_string_info();
private:
expression_list expr_list_;
face_manager<freetype_engine> &font_manager_;

View file

@ -30,7 +30,7 @@
#include <mapnik/processed_text.hpp>
//boost
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
// agg
#include "agg_trans_affine.h"
@ -65,34 +65,14 @@ public:
CoordTransform const& t,
FaceManagerT &font_manager,
DetectorT &detector,
box2d<double> const& query_extent)
: sym_(sym),
feature_(feature),
prj_trans_(prj_trans),
t_(t),
font_manager_(font_manager),
detector_(detector),
dims_(0, 0, width, height),
query_extent_(query_extent),
text_(font_manager, scale_factor),
angle_(0.0),
placement_valid_(false),
points_on_line_(false),
finder_()
{
initialize_geometries();
if (!geometries_to_process_.size()) return;
placement_ = sym_.get_placement_options()->get_placement_info(scale_factor);
next_placement();
initialize_points();
}
box2d<double> const& query_extent);
/** Return next placement.
* If no more placements are found returns null pointer.
*/
~text_symbolizer_helper();
// Return next placement.
// If no more placements are found returns null pointer.
bool next();
/** Get current placement. next() has to be called before! */
// Get current placement. next() has to be called before!
placements_type const& placements() const;
protected:
bool next_point_placement();
@ -113,28 +93,26 @@ protected:
box2d<double> const& query_extent_;
//Processing
processed_text text_;
/* Using list instead of vector, because we delete random elements and need iterators to stay valid. */
/** Remaining geometries to be processed. */
// Using list instead of vector, because we delete random elements and need iterators to stay valid.
// Remaining geometries to be processed.
std::list<geometry_type*> geometries_to_process_;
/** Geometry currently being processed. */
// Geometry currently being processed.
std::list<geometry_type*>::iterator geo_itr_;
/** Remaining points to be processed. */
// Remaining points to be processed.
std::list<position> points_;
/** Point currently being processed. */
// Point currently being processed.
std::list<position>::iterator point_itr_;
/** Text rotation. */
// Text rotation.
double angle_;
/** Text + formatting. */
string_info *info_;
/** Did last call to next_placement return true? */
// Did last call to next_placement return true?
bool placement_valid_;
/** Use point placement. Otherwise line placement is used. */
// Use point placement. Otherwise line placement is used.
bool point_placement_;
/** Place text at points on a line instead of following the line (used for ShieldSymbolizer) .*/
// Place text at points on a line instead of following the line (used for ShieldSymbolizer).
bool points_on_line_;
text_placement_info_ptr placement_;
boost::shared_ptr<placement_finder<DetectorT> > finder_;
boost::scoped_ptr<placement_finder<DetectorT> > finder_;
};
template <typename FaceManagerT, typename DetectorT>
@ -193,7 +171,6 @@ protected:
using text_symbolizer_helper<FaceManagerT, DetectorT>::geometries_to_process_;
using text_symbolizer_helper<FaceManagerT, DetectorT>::placement_;
using text_symbolizer_helper<FaceManagerT, DetectorT>::next_placement;
using text_symbolizer_helper<FaceManagerT, DetectorT>::info_;
using text_symbolizer_helper<FaceManagerT, DetectorT>::geo_itr_;
using text_symbolizer_helper<FaceManagerT, DetectorT>::point_itr_;
using text_symbolizer_helper<FaceManagerT, DetectorT>::points_;

View file

@ -55,7 +55,7 @@ void processed_text::clear()
}
string_info &processed_text::get_string_info()
string_info const& processed_text::get_string_info()
{
info_.clear(); //if this function is called twice invalid results are returned, so clear string_info first
expression_list::iterator itr = expr_list_.begin();

View file

@ -39,6 +39,42 @@
namespace mapnik {
template <typename FaceManagerT, typename DetectorT>
text_symbolizer_helper<FaceManagerT, DetectorT>::text_symbolizer_helper(text_symbolizer const& sym,
feature_impl const& feature,
proj_transform const& prj_trans,
unsigned width,
unsigned height,
double scale_factor,
CoordTransform const& t,
FaceManagerT &font_manager,
DetectorT &detector,
box2d<double> const& query_extent)
: sym_(sym),
feature_(feature),
prj_trans_(prj_trans),
t_(t),
font_manager_(font_manager),
detector_(detector),
dims_(0, 0, width, height),
query_extent_(query_extent),
text_(font_manager, scale_factor),
angle_(0.0),
placement_valid_(false),
points_on_line_(false),
finder_(0)
{
initialize_geometries();
if (!geometries_to_process_.size()) return;
placement_ = sym_.get_placement_options()->get_placement_info(scale_factor);
next_placement();
initialize_points();
}
template <typename FaceManagerT, typename DetectorT>
text_symbolizer_helper<FaceManagerT, DetectorT>::~text_symbolizer_helper()
{}
template <typename FaceManagerT, typename DetectorT>
bool text_symbolizer_helper<FaceManagerT, DetectorT>::next()
{
@ -283,7 +319,6 @@ bool text_symbolizer_helper<FaceManagerT, DetectorT>::next_placement()
return false;
}
placement_->properties.process(text_, feature_);
info_ = &(text_.get_string_info());
if (placement_->properties.orientation)
{
// https://github.com/mapnik/mapnik/issues/1352
@ -295,10 +330,9 @@ bool text_symbolizer_helper<FaceManagerT, DetectorT>::next_placement()
angle_ = 0.0;
}
finder_ = boost::shared_ptr<placement_finder<DetectorT> >(new placement_finder<DetectorT>(feature_, *placement_, *info_, detector_, dims_));
// boost::make_shared<placement_finder<DetectorT> >(feature_, *placement_, *info_, detector_, dims_);
finder_.reset(new placement_finder<DetectorT>(feature_, *placement_,
text_.get_string_info(),
detector_, dims_));
placement_valid_ = true;
return true;
}
@ -470,4 +504,5 @@ agg::trans_affine const& shield_symbolizer_helper<FaceManagerT, DetectorT>::get_
template class text_symbolizer_helper<face_manager<freetype_engine>, label_collision_detector4>;
template class shield_symbolizer_helper<face_manager<freetype_engine>, label_collision_detector4>;
template class mapnik::placement_finder<mapnik::label_collision_detector4>;
} //namespace