Merge branch 'master' into move_bind_logic_to_layer
This commit is contained in:
commit
3a8c11cfa3
25 changed files with 175 additions and 91 deletions
|
@ -62,7 +62,7 @@ struct map_pickle_suite : boost::python::pickle_suite
|
|||
Map::const_style_iterator end = m.styles().end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
const std::string & name = it->first;
|
||||
std::string const& name = it->first;
|
||||
const mapnik::feature_type_style & style = it->second;
|
||||
boost::python::tuple style_pair = boost::python::make_tuple(name,style);
|
||||
s.append(style_pair);
|
||||
|
@ -153,7 +153,7 @@ bool has_metawriter(mapnik::Map const& m)
|
|||
|
||||
// returns empty shared_ptr when the metawriter isn't found, or is
|
||||
// of the wrong type. empty pointers make it back to Python as a None.
|
||||
mapnik::metawriter_inmem_ptr find_inmem_metawriter(const mapnik::Map &m, const std::string &name) {
|
||||
mapnik::metawriter_inmem_ptr find_inmem_metawriter(const mapnik::Map &m, std::string const&name) {
|
||||
mapnik::metawriter_ptr metawriter = m.find_metawriter(name);
|
||||
mapnik::metawriter_inmem_ptr inmem;
|
||||
|
||||
|
|
|
@ -95,6 +95,18 @@ If you see bits of code around that do not follow these please don't hesitate to
|
|||
|
||||
(int)value; // no
|
||||
|
||||
#### Use const keyword after the type
|
||||
|
||||
std::string const& variable_name // preferred, for consistency
|
||||
|
||||
const std::string & variable_name // no
|
||||
|
||||
#### Pass built-in types by value, all others by const&
|
||||
|
||||
void my_function(int double val); // if int, char, double, etc pass by value
|
||||
|
||||
void my_function(std::string const& val); // if std::string or user type, pass by const&
|
||||
|
||||
#### Shared pointers should be created with [boost::make_shared](http://www.boost.org/doc/libs/1_47_0/libs/smart_ptr/make_shared.html) where possible
|
||||
|
||||
#### Function definitions should not be separated from their arguments:
|
||||
|
|
|
@ -31,11 +31,24 @@ struct char_properties;
|
|||
class char_info {
|
||||
public:
|
||||
char_info(unsigned c_, double width_, double ymax_, double ymin_, double line_height_)
|
||||
: c(c_), width(width_), line_height(line_height_), ymin(ymin_), ymax(ymax_)
|
||||
: c(c_),
|
||||
width(width_),
|
||||
line_height(line_height_),
|
||||
ymin(ymin_),
|
||||
ymax(ymax_),
|
||||
avg_height(ymax_-ymin_),
|
||||
format()
|
||||
{
|
||||
}
|
||||
|
||||
char_info()
|
||||
: c(0), width(0), line_height(0), ymin(0), ymax(0)
|
||||
: c(0),
|
||||
width(0),
|
||||
line_height(0),
|
||||
ymin(0),
|
||||
ymax(0),
|
||||
avg_height(0),
|
||||
format()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,10 @@ namespace mapnik {
|
|||
class config_error : public std::exception
|
||||
{
|
||||
public:
|
||||
config_error() {}
|
||||
config_error():
|
||||
what_() {}
|
||||
|
||||
config_error( const std::string & what ) :
|
||||
config_error( std::string const& what ) :
|
||||
what_( what )
|
||||
{
|
||||
}
|
||||
|
@ -44,7 +45,7 @@ public:
|
|||
return what_.c_str();
|
||||
}
|
||||
|
||||
void append_context(const std::string & ctx) const
|
||||
void append_context(std::string const& ctx) const
|
||||
{
|
||||
what_ += " " + ctx;
|
||||
}
|
||||
|
|
|
@ -380,20 +380,27 @@ class CoordTransform
|
|||
private:
|
||||
int width_;
|
||||
int height_;
|
||||
double sx_;
|
||||
double sy_;
|
||||
box2d<double> extent_;
|
||||
double offset_x_;
|
||||
double offset_y_;
|
||||
double sx_;
|
||||
double sy_;
|
||||
|
||||
public:
|
||||
CoordTransform(int width, int height, const box2d<double>& extent,
|
||||
double offset_x = 0, double offset_y = 0)
|
||||
: width_(width), height_(height), extent_(extent),
|
||||
offset_x_(offset_x), offset_y_(offset_y)
|
||||
: width_(width),
|
||||
height_(height),
|
||||
extent_(extent),
|
||||
offset_x_(offset_x),
|
||||
offset_y_(offset_y),
|
||||
sx_(1.0),
|
||||
sy_(1.0)
|
||||
{
|
||||
sx_ = static_cast<double>(width_) / extent_.width();
|
||||
sy_ = static_cast<double>(height_) / extent_.height();
|
||||
if (extent_.width())
|
||||
sx_ = static_cast<double>(width_) / extent_.width();
|
||||
if (extent_.height())
|
||||
sy_ = static_cast<double>(height_) / extent_.height();
|
||||
}
|
||||
|
||||
inline int width() const
|
||||
|
|
|
@ -37,9 +37,10 @@ namespace mapnik {
|
|||
class illegal_enum_value : public std::exception
|
||||
{
|
||||
public:
|
||||
illegal_enum_value() {}
|
||||
illegal_enum_value():
|
||||
what_() {}
|
||||
|
||||
illegal_enum_value( const std::string & what ) :
|
||||
illegal_enum_value( std::string const& what ) :
|
||||
what_( what )
|
||||
{
|
||||
}
|
||||
|
@ -138,7 +139,8 @@ template <class ENUM, int THE_MAX>
|
|||
class MAPNIK_DECL enumeration {
|
||||
public:
|
||||
typedef ENUM native_type;
|
||||
enumeration() {};
|
||||
enumeration():
|
||||
value_() {};
|
||||
enumeration( ENUM v ) : value_(v) {}
|
||||
enumeration( const enumeration & other ) : value_(other.value_) {}
|
||||
|
||||
|
@ -171,7 +173,7 @@ public:
|
|||
/** Converts @p str to an enum.
|
||||
* @throw illegal_enum_value @p str is not a legal identifier.
|
||||
* */
|
||||
void from_string(const std::string & str)
|
||||
void from_string(std::string const& str)
|
||||
{
|
||||
for (unsigned i = 0; i < THE_MAX; ++i)
|
||||
{
|
||||
|
@ -267,7 +269,7 @@ public:
|
|||
}
|
||||
return true;
|
||||
}
|
||||
static const std::string & get_full_qualified_name()
|
||||
static std::string const& get_full_qualified_name()
|
||||
{
|
||||
return our_name_;
|
||||
}
|
||||
|
|
|
@ -100,7 +100,9 @@ public:
|
|||
feature_impl(context_ptr const& ctx, int id)
|
||||
: id_(id),
|
||||
ctx_(ctx),
|
||||
data_(ctx_->mapping_.size())
|
||||
data_(ctx_->mapping_.size()),
|
||||
geom_cont_(),
|
||||
raster_()
|
||||
{}
|
||||
|
||||
inline int id() const { return id_;}
|
||||
|
@ -280,9 +282,9 @@ public:
|
|||
private:
|
||||
int id_;
|
||||
context_ptr ctx_;
|
||||
cont_type data_;
|
||||
boost::ptr_vector<geometry_type> geom_cont_;
|
||||
raster_ptr raster_;
|
||||
cont_type data_;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -152,7 +152,8 @@ class MAPNIK_DECL font_face_set : private boost::noncopyable
|
|||
{
|
||||
public:
|
||||
font_face_set(void)
|
||||
: faces_() {}
|
||||
: faces_(),
|
||||
dimension_cache_() {}
|
||||
|
||||
void add(face_ptr face)
|
||||
{
|
||||
|
|
|
@ -147,7 +147,7 @@ inline boost::optional<std::string> type_from_filename(std::string const& filena
|
|||
return result_type();
|
||||
}
|
||||
|
||||
inline std::string guess_type( const std::string & filename )
|
||||
inline std::string guess_type( std::string const& filename )
|
||||
{
|
||||
std::string::size_type idx = filename.find_last_of(".");
|
||||
if ( idx != std::string::npos ) {
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
namespace mapnik
|
||||
{
|
||||
MAPNIK_DECL void load_map(Map & map, std::string const& filename, bool strict = false);
|
||||
MAPNIK_DECL void load_map_string(Map & map, std::string const& str, bool strict = false, std::string const& base_path="");
|
||||
MAPNIK_DECL void load_map_string(Map & map, std::string const& str, bool strict = false, std::string base_path="");
|
||||
}
|
||||
|
||||
#endif // MAPNIK_LOAD_MAP_HPP
|
||||
|
|
|
@ -92,14 +92,14 @@ private:
|
|||
// 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(const std::vector<vertex2d> & path_positions,
|
||||
const std::vector<double> & path_distances,
|
||||
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 wether the given text_path be placed without a collision
|
||||
///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(const std::auto_ptr<text_path> & current_placement, const int & orientation);
|
||||
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
|
||||
|
@ -107,14 +107,14 @@ private:
|
|||
// This means there is exactly one intersect point
|
||||
// Result is returned in ix, iy
|
||||
void find_line_circle_intersection(
|
||||
const double &cx, const double &cy, const double &radius,
|
||||
const double &x1, const double &y1, const double &x2, const double &y2,
|
||||
double &ix, double &iy);
|
||||
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, double label_x, double label_y);
|
||||
void adjust_position(text_path *current_placement);
|
||||
void add_line(double width, double height, bool first_line);
|
||||
|
||||
///General Internals
|
||||
|
|
|
@ -93,7 +93,7 @@ operator << ( std::basic_ostream<charT, traits> & s, mapnik::color const& c )
|
|||
/** Helper for class bool */
|
||||
class boolean {
|
||||
public:
|
||||
boolean() {}
|
||||
boolean() : b_(false) {}
|
||||
boolean(bool b) : b_(b) {}
|
||||
boolean(boolean const& b) : b_(b.b_) {}
|
||||
|
||||
|
@ -211,7 +211,15 @@ struct name_trait< mapnik::enumeration<ENUM, MAX> >
|
|||
template <typename T>
|
||||
inline boost::optional<T> fast_cast(std::string const& value)
|
||||
{
|
||||
return boost::lexical_cast<T>( value );
|
||||
try
|
||||
{
|
||||
return boost::lexical_cast<T>( value );
|
||||
}
|
||||
catch (boost::bad_lexical_cast const& ex)
|
||||
{
|
||||
return boost::optional<T>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template <>
|
||||
|
|
|
@ -51,7 +51,7 @@ struct MAPNIK_DECL shield_symbolizer : public text_symbolizer,
|
|||
|
||||
bool get_unlock_image() const; // image is not locked to the text placement
|
||||
void set_unlock_image(bool unlock_image);
|
||||
void set_shield_displacement(double shield_dx,double shield_dy);
|
||||
void set_shield_displacement(double shield_dx, double shield_dy);
|
||||
position const& get_shield_displacement() const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
unsigned width,
|
||||
unsigned height,
|
||||
double scale_factor,
|
||||
CoordTransform const &t,
|
||||
CoordTransform const& t,
|
||||
FaceManagerT &font_manager,
|
||||
DetectorT &detector)
|
||||
: sym_(sym),
|
||||
|
@ -83,7 +83,7 @@ public:
|
|||
bool next();
|
||||
|
||||
/** Get current placement. next() has to be called before! */
|
||||
placements_type &placements() const;
|
||||
placements_type & placements() const;
|
||||
protected:
|
||||
bool next_point_placement();
|
||||
bool next_line_placement();
|
||||
|
@ -96,8 +96,8 @@ protected:
|
|||
Feature const& feature_;
|
||||
proj_transform const& prj_trans_;
|
||||
CoordTransform const& t_;
|
||||
FaceManagerT &font_manager_;
|
||||
DetectorT &detector_;
|
||||
FaceManagerT & font_manager_;
|
||||
DetectorT & detector_;
|
||||
metawriter_with_properties writer_;
|
||||
box2d<double> dims_;
|
||||
|
||||
|
@ -137,9 +137,9 @@ public:
|
|||
unsigned width,
|
||||
unsigned height,
|
||||
double scale_factor,
|
||||
CoordTransform const &t,
|
||||
FaceManagerT &font_manager,
|
||||
DetectorT &detector) :
|
||||
CoordTransform const& t,
|
||||
FaceManagerT & font_manager,
|
||||
DetectorT & detector) :
|
||||
text_symbolizer_helper<FaceManagerT, DetectorT>(sym, feature, prj_trans, width, height, scale_factor, t, font_manager, detector),
|
||||
sym_(sym)
|
||||
{
|
||||
|
@ -149,7 +149,7 @@ public:
|
|||
|
||||
bool next();
|
||||
pixel_position get_marker_position(text_path const& p);
|
||||
marker &get_marker() const;
|
||||
marker & get_marker() const;
|
||||
agg::trans_affine const& get_transform() const;
|
||||
protected:
|
||||
bool next_point_placement();
|
||||
|
|
|
@ -131,7 +131,9 @@ class text_path : boost::noncopyable
|
|||
double angle;
|
||||
|
||||
character_node(char_info_ptr c_, double x_, double y_, double angle_)
|
||||
: c(c_), pos(x_, y_), angle(angle_)
|
||||
: c(c_),
|
||||
pos(x_, y_),
|
||||
angle(angle_)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -150,12 +152,13 @@ class text_path : boost::noncopyable
|
|||
int itr_;
|
||||
public:
|
||||
typedef std::vector<character_node> character_nodes_t;
|
||||
pixel_position center;
|
||||
character_nodes_t nodes_;
|
||||
|
||||
pixel_position center;
|
||||
|
||||
text_path()
|
||||
: itr_(0)
|
||||
text_path(double x, double y)
|
||||
: itr_(0),
|
||||
center(x,y),
|
||||
nodes_()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ struct char_properties
|
|||
/** Construct object from XML. */
|
||||
void from_xml(boost::property_tree::ptree const &sym, fontset_map const & fontsets);
|
||||
/** Write object to XML ptree. */
|
||||
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, char_properties const &dfl=char_properties()) const;
|
||||
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, char_properties const& dfl=char_properties()) const;
|
||||
std::string face_name;
|
||||
font_set fontset;
|
||||
float text_size;
|
||||
|
|
|
@ -33,7 +33,7 @@ class value_error : public std::exception
|
|||
public:
|
||||
value_error() {}
|
||||
|
||||
value_error( const std::string & what ) :
|
||||
value_error( std::string const& what ) :
|
||||
what_( what )
|
||||
{
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public:
|
|||
return what_.c_str();
|
||||
}
|
||||
|
||||
void append_context(const std::string & ctx) const
|
||||
void append_context(std::string const& ctx) const
|
||||
{
|
||||
what_ += " " + ctx;
|
||||
}
|
||||
|
|
|
@ -206,24 +206,24 @@ void ogr_datasource::init(mapnik::parameters const& params)
|
|||
|
||||
if (! layer_.is_valid())
|
||||
{
|
||||
std::string s("OGR Plugin: ");
|
||||
std::ostringstream s("OGR Plugin: ");
|
||||
|
||||
if (layer_by_name)
|
||||
{
|
||||
s += "cannot find layer by name '" + *layer_by_name;
|
||||
s << "cannot find layer by name '" << *layer_by_name;
|
||||
}
|
||||
else if (layer_by_index)
|
||||
{
|
||||
s += "cannot find layer by index number '" + *layer_by_index;
|
||||
s << "cannot find layer by index number '" << *layer_by_index;
|
||||
}
|
||||
else if (layer_by_sql)
|
||||
{
|
||||
s += "cannot find layer by sql query '" + *layer_by_sql;
|
||||
s << "cannot find layer by sql query '" << *layer_by_sql;
|
||||
}
|
||||
|
||||
s += "' in dataset '" + dataset_name_ + "'";
|
||||
s << "' in dataset '" << dataset_name_ << "'";
|
||||
|
||||
throw datasource_exception(s);
|
||||
throw datasource_exception(s.str());
|
||||
}
|
||||
|
||||
// work with real OGR layer
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
(source=="api" && hasBbox() && zoom_start>=0 && tiled==true));
|
||||
}
|
||||
|
||||
void setSource(const std::string & src)
|
||||
void setSource(std::string const& src)
|
||||
{
|
||||
if(src=="api" || src=="osm")
|
||||
{
|
||||
|
|
|
@ -412,7 +412,7 @@ std::string postgis_datasource::populate_tokens(const std::string& sql, double s
|
|||
}
|
||||
|
||||
|
||||
boost::shared_ptr<IResultSet> postgis_datasource::get_resultset(boost::shared_ptr<Connection> const &conn, const std::string &sql) const
|
||||
boost::shared_ptr<IResultSet> postgis_datasource::get_resultset(boost::shared_ptr<Connection> const &conn, std::string const& sql) const
|
||||
{
|
||||
if (cursor_fetch_size_ > 0)
|
||||
{
|
||||
|
|
|
@ -95,7 +95,7 @@ private:
|
|||
std::string populate_tokens(const std::string& sql, double scale_denom, box2d<double> const& env) const;
|
||||
std::string populate_tokens(const std::string& sql) const;
|
||||
static std::string unquote(const std::string& sql);
|
||||
boost::shared_ptr<IResultSet> get_resultset(boost::shared_ptr<Connection> const &conn, const std::string &sql) const;
|
||||
boost::shared_ptr<IResultSet> get_resultset(boost::shared_ptr<Connection> const &conn, std::string const& sql) const;
|
||||
postgis_datasource(const postgis_datasource&);
|
||||
postgis_datasource& operator=(const postgis_datasource&);
|
||||
};
|
||||
|
|
|
@ -71,7 +71,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void load( const std::string & filename, ptree & pt )
|
||||
void load( std::string const& filename, ptree & pt )
|
||||
{
|
||||
boost::filesystem::path path(filename);
|
||||
if ( !boost::filesystem::exists( path ) ) {
|
||||
|
@ -119,7 +119,7 @@ public:
|
|||
load(doc, pt);
|
||||
}
|
||||
|
||||
void load_string( const std::string & buffer, ptree & pt, std::string const & base_path )
|
||||
void load_string( std::string const& buffer, ptree & pt, std::string const & base_path )
|
||||
{
|
||||
if (!base_path.empty())
|
||||
{
|
||||
|
|
|
@ -122,7 +122,7 @@ private:
|
|||
void parse_stroke(stroke & strk, ptree const & sym);
|
||||
expression_ptr parse_expr(std::string const& expr);
|
||||
|
||||
void ensure_font_face( const std::string & face_name );
|
||||
void ensure_font_face( std::string const& face_name );
|
||||
|
||||
std::string ensure_relative_to_xml( boost::optional<std::string> opt_path );
|
||||
void ensure_attrs( ptree const& sym, std::string name, std::string attrs);
|
||||
|
@ -184,8 +184,13 @@ void load_map(Map & map, std::string const& filename, bool strict)
|
|||
parser.parse_map(map, pt);
|
||||
}
|
||||
|
||||
void load_map_string(Map & map, std::string const& str, bool strict, std::string const& base_path)
|
||||
void load_map_string(Map & map, std::string const& str, bool strict, std::string base_path)
|
||||
{
|
||||
if (str.empty())
|
||||
{
|
||||
throw config_error( "Cannot load map, XML string is empty" ) ;
|
||||
}
|
||||
|
||||
ptree pt;
|
||||
#ifdef HAVE_LIBXML2
|
||||
if (!base_path.empty())
|
||||
|
@ -1773,7 +1778,7 @@ void map_parser::parse_raster_colorizer(raster_colorizer_ptr const& rc,
|
|||
}
|
||||
}
|
||||
|
||||
void map_parser::ensure_font_face( const std::string & face_name )
|
||||
void map_parser::ensure_font_face( std::string const& face_name )
|
||||
{
|
||||
if ( ! font_manager_.get_face( face_name ) )
|
||||
{
|
||||
|
|
|
@ -219,9 +219,13 @@ void placement_finder<DetectorT>::find_line_breaks()
|
|||
if (p.wrap_width && string_width_ > p.wrap_width)
|
||||
{
|
||||
if (p.text_ratio)
|
||||
{
|
||||
for (double i = 1.0; ((wrap_at = string_width_/i)/(string_height_*i)) > p.text_ratio && (string_width_/i) > p.wrap_width; i += 1.0) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
wrap_at = p.wrap_width;
|
||||
}
|
||||
}
|
||||
|
||||
// work out where our line breaks need to be and the resultant width to the 'wrapped' string
|
||||
|
@ -265,8 +269,10 @@ void placement_finder<DetectorT>::find_line_breaks()
|
|||
|
||||
// wrap text at first wrap_char after (default) the wrap width or immediately before the current word
|
||||
if ((c == '\n') ||
|
||||
(line_width > 0 && ((line_width > wrap_at && !ci.format->wrap_before) ||
|
||||
((line_width + last_wrap_char_width + word_width) > wrap_at && ci.format->wrap_before)) ))
|
||||
(line_width > 0 &&
|
||||
((line_width > wrap_at && !ci.format->wrap_before) ||
|
||||
((line_width + last_wrap_char_width + word_width) > wrap_at && ci.format->wrap_before)) )
|
||||
)
|
||||
{
|
||||
add_line(line_width, line_height, first_line);
|
||||
line_breaks_.push_back(last_wrap_char_pos);
|
||||
|
@ -322,10 +328,9 @@ void placement_finder<DetectorT>::init_alignment()
|
|||
|
||||
|
||||
template <typename DetectorT>
|
||||
void placement_finder<DetectorT>::adjust_position(text_path *current_placement, double label_x, double label_y)
|
||||
void placement_finder<DetectorT>::adjust_position(text_path *current_placement)
|
||||
{
|
||||
// if needed, adjust for desired vertical alignment
|
||||
current_placement->center.y = label_y; // no adjustment, default is MIDDLE
|
||||
if (valign_ == V_TOP)
|
||||
{
|
||||
current_placement->center.y -= 0.5 * string_height_; // move center up by 1/2 the total height
|
||||
|
@ -335,7 +340,6 @@ void placement_finder<DetectorT>::adjust_position(text_path *current_placement,
|
|||
}
|
||||
|
||||
// set horizontal position to middle of text
|
||||
current_placement->center.x = label_x; // no adjustment, default is MIDDLE
|
||||
if (halign_ == H_LEFT)
|
||||
{
|
||||
current_placement->center.x -= 0.5 * string_width_; // move center left by 1/2 the string width
|
||||
|
@ -351,7 +355,9 @@ void placement_finder<DetectorT>::adjust_position(text_path *current_placement,
|
|||
}
|
||||
|
||||
template <typename DetectorT>
|
||||
void placement_finder<DetectorT>::find_point_placement(double label_x, double label_y, double angle)
|
||||
void placement_finder<DetectorT>::find_point_placement(double label_x,
|
||||
double label_y,
|
||||
double angle)
|
||||
{
|
||||
find_line_breaks();
|
||||
|
||||
|
@ -360,9 +366,9 @@ void placement_finder<DetectorT>::find_point_placement(double label_x, double la
|
|||
double sina = std::sin(rad);
|
||||
|
||||
double x, y;
|
||||
std::auto_ptr<text_path> current_placement(new text_path);
|
||||
std::auto_ptr<text_path> current_placement(new text_path(label_x, label_y));
|
||||
|
||||
adjust_position(current_placement.get(), label_x, label_y);
|
||||
adjust_position(current_placement.get());
|
||||
|
||||
// presets for first line
|
||||
unsigned int line_number = 0;
|
||||
|
@ -432,12 +438,16 @@ void placement_finder<DetectorT>::find_point_placement(double label_x, double la
|
|||
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()))) {
|
||||
if (!detector_.extent().intersects(e) ||
|
||||
(!p.allow_overlap && !detector_.has_point_placement(e, pi.get_actual_minimum_distance()))
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// if avoid_edges test dimensions contains e
|
||||
if (p.avoid_edges && !dimensions_.contains(e)) {
|
||||
if (p.avoid_edges && !dimensions_.contains(e))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -551,7 +561,7 @@ void placement_finder<DetectorT>::find_line_placements(PathT & shape_path)
|
|||
//If there is no spacing then just do one label, otherwise calculate how many there should be
|
||||
int num_labels = 1;
|
||||
if (p.label_spacing > 0)
|
||||
num_labels = static_cast<int> (floor(total_distance / (pi.get_actual_label_spacing() + string_width_)));
|
||||
num_labels = static_cast<int>(floor(total_distance / (pi.get_actual_label_spacing() + string_width_)));
|
||||
|
||||
if (p.force_odd_labels && (num_labels % 2 == 0))
|
||||
num_labels--;
|
||||
|
@ -664,7 +674,11 @@ void placement_finder<DetectorT>::find_line_placements(PathT & shape_path)
|
|||
}
|
||||
|
||||
template <typename DetectorT>
|
||||
std::auto_ptr<text_path> placement_finder<DetectorT>::get_placement_offset(const std::vector<vertex2d> &path_positions, const std::vector<double> &path_distances, int &orientation, unsigned index, double distance)
|
||||
std::auto_ptr<text_path> placement_finder<DetectorT>::get_placement_offset(std::vector<vertex2d> const& path_positions,
|
||||
std::vector<double> const& path_distances,
|
||||
int & orientation,
|
||||
unsigned index,
|
||||
double distance)
|
||||
{
|
||||
//Check that the given distance is on the given index and find the correct index and distance if not
|
||||
while (distance < 0 && index > 1)
|
||||
|
@ -688,8 +702,6 @@ std::auto_ptr<text_path> placement_finder<DetectorT>::get_placement_offset(const
|
|||
const unsigned initial_index = index;
|
||||
const double initial_distance = distance;
|
||||
|
||||
std::auto_ptr<text_path> current_placement(new text_path);
|
||||
|
||||
double old_x = path_positions[index-1].x;
|
||||
double old_y = path_positions[index-1].y;
|
||||
|
||||
|
@ -705,11 +717,15 @@ std::auto_ptr<text_path> placement_finder<DetectorT>::get_placement_offset(const
|
|||
return std::auto_ptr<text_path>(NULL);
|
||||
}
|
||||
|
||||
current_placement->center.x = old_x + dx*distance/segment_length;
|
||||
current_placement->center.y = old_y + dy*distance/segment_length;
|
||||
std::auto_ptr<text_path> current_placement(
|
||||
new text_path((old_x + dx*distance/segment_length),
|
||||
(old_y + dy*distance/segment_length)
|
||||
)
|
||||
);
|
||||
|
||||
double angle = atan2(-dy, dx);
|
||||
|
||||
bool orientation_forced = (orientation != 0); //Wether the orientation was set by the caller
|
||||
bool orientation_forced = (orientation != 0); // Whether the orientation was set by the caller
|
||||
if (!orientation_forced)
|
||||
orientation = (angle > 0.55*M_PI || angle < -0.45*M_PI) ? -1 : 1;
|
||||
|
||||
|
@ -835,7 +851,11 @@ std::auto_ptr<text_path> placement_finder<DetectorT>::get_placement_offset(const
|
|||
if (!orientation_forced)
|
||||
{
|
||||
orientation = -orientation;
|
||||
current_placement = get_placement_offset(path_positions, path_distances, orientation, initial_index, initial_distance);
|
||||
current_placement = get_placement_offset(path_positions,
|
||||
path_distances,
|
||||
orientation,
|
||||
initial_index,
|
||||
initial_distance);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -849,7 +869,8 @@ std::auto_ptr<text_path> placement_finder<DetectorT>::get_placement_offset(const
|
|||
}
|
||||
|
||||
template <typename DetectorT>
|
||||
bool placement_finder<DetectorT>::test_placement(const std::auto_ptr<text_path> & current_placement, const int & orientation)
|
||||
bool placement_finder<DetectorT>::test_placement(std::auto_ptr<text_path> const& current_placement,
|
||||
int orientation)
|
||||
{
|
||||
//Create and test envelopes
|
||||
bool status = true;
|
||||
|
@ -923,9 +944,9 @@ bool placement_finder<DetectorT>::test_placement(const std::auto_ptr<text_path>
|
|||
|
||||
template <typename DetectorT>
|
||||
void placement_finder<DetectorT>::find_line_circle_intersection(
|
||||
const double &cx, const double &cy, const double &radius,
|
||||
const double &x1, const double &y1, const double &x2, const double &y2,
|
||||
double &ix, double &iy)
|
||||
double cx, double cy, double radius,
|
||||
double x1, double y1, double x2, double y2,
|
||||
double & ix, double & iy)
|
||||
{
|
||||
double dx = x2 - x1;
|
||||
double dy = y2 - y1;
|
||||
|
|
|
@ -31,6 +31,8 @@ namespace mapnik
|
|||
using boost::optional;
|
||||
|
||||
text_symbolizer_properties::text_symbolizer_properties() :
|
||||
orientation(),
|
||||
displacement(0,0),
|
||||
label_placement(POINT_PLACEMENT),
|
||||
halign(H_AUTO),
|
||||
jalign(J_MIDDLE),
|
||||
|
@ -40,11 +42,13 @@ text_symbolizer_properties::text_symbolizer_properties() :
|
|||
avoid_edges(false),
|
||||
minimum_distance(0.0),
|
||||
minimum_padding(0.0),
|
||||
minimum_path_length(0.0),
|
||||
max_char_angle_delta(22.5 * M_PI/180.0),
|
||||
force_odd_labels(false),
|
||||
allow_overlap(false),
|
||||
text_ratio(0),
|
||||
wrap_width(0),
|
||||
format(),
|
||||
tree_()
|
||||
{
|
||||
|
||||
|
@ -121,11 +125,13 @@ void text_symbolizer_properties::from_xml(boost::property_tree::ptree const &sym
|
|||
if (n) set_format_tree(n);
|
||||
}
|
||||
|
||||
void text_symbolizer_properties::to_xml(boost::property_tree::ptree &node, bool explicit_defaults, text_symbolizer_properties const &dfl) const
|
||||
void text_symbolizer_properties::to_xml(boost::property_tree::ptree &node,
|
||||
bool explicit_defaults,
|
||||
text_symbolizer_properties const& dfl) const
|
||||
{
|
||||
if (orientation)
|
||||
{
|
||||
const std::string & orientationstr = to_expression_string(*orientation);
|
||||
std::string const& orientationstr = to_expression_string(*orientation);
|
||||
if (!dfl.orientation || orientationstr != to_expression_string(*(dfl.orientation)) || explicit_defaults) {
|
||||
set_attr(node, "orientation", orientationstr);
|
||||
}
|
||||
|
@ -216,6 +222,8 @@ void text_symbolizer_properties::set_old_style_expression(expression_ptr expr)
|
|||
}
|
||||
|
||||
char_properties::char_properties() :
|
||||
face_name(),
|
||||
fontset(),
|
||||
text_size(10.0),
|
||||
character_spacing(0),
|
||||
line_spacing(0),
|
||||
|
@ -263,7 +271,8 @@ void char_properties::from_xml(boost::property_tree::ptree const &sym, fontset_m
|
|||
if (itr != fontsets.end())
|
||||
{
|
||||
fontset = itr->second;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
throw config_error("Unable to find any fontset named '" + *fontset_name_ + "'");
|
||||
}
|
||||
|
@ -280,8 +289,8 @@ void char_properties::from_xml(boost::property_tree::ptree const &sym, fontset_m
|
|||
|
||||
void char_properties::to_xml(boost::property_tree::ptree &node, bool explicit_defaults, char_properties const &dfl) const
|
||||
{
|
||||
const std::string & fontset_name = fontset.get_name();
|
||||
const std::string & dfl_fontset_name = dfl.fontset.get_name();
|
||||
std::string const& fontset_name = fontset.get_name();
|
||||
std::string const& dfl_fontset_name = dfl.fontset.get_name();
|
||||
if (fontset_name != dfl_fontset_name || explicit_defaults)
|
||||
{
|
||||
set_attr(node, "fontset-name", fontset_name);
|
||||
|
|
Loading…
Add table
Reference in a new issue