diff --git a/SConstruct b/SConstruct index b860bb58e..5b10da417 100644 --- a/SConstruct +++ b/SConstruct @@ -1411,7 +1411,9 @@ if not preconfigured: pthread = '-pthread' # Common debugging flags. + # http://lists.fedoraproject.org/pipermail/devel/2010-November/144952.html debug_flags = '-g -fno-omit-frame-pointer -DDEBUG -DMAPNIK_DEBUG' + ndebug_flags = '-DNDEBUG' diff --git a/bindings/python/mapnik/__init__.py b/bindings/python/mapnik/__init__.py index 9fa035211..7d7a93d2c 100644 --- a/bindings/python/mapnik/__init__.py +++ b/bindings/python/mapnik/__init__.py @@ -682,6 +682,7 @@ __all__ = [ 'SQLite', 'Osm', 'Kismet', + 'Geos', # version and environment 'mapnik_version_string', 'mapnik_version', diff --git a/bindings/python/mapnik_map.cpp b/bindings/python/mapnik_map.cpp index ab89de292..9e1287420 100644 --- a/bindings/python/mapnik_map.cpp +++ b/bindings/python/mapnik_map.cpp @@ -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; diff --git a/docs/contributing.markdown b/docs/contributing.markdown index b3fba320a..6bc272f18 100644 --- a/docs/contributing.markdown +++ b/docs/contributing.markdown @@ -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: diff --git a/include/mapnik/agg_renderer.hpp b/include/mapnik/agg_renderer.hpp index 41fb52932..592105ef1 100644 --- a/include/mapnik/agg_renderer.hpp +++ b/include/mapnik/agg_renderer.hpp @@ -29,10 +29,6 @@ #include #include #include -//#include - -// agg -//#include "agg_trans_affine.h" // boost #include diff --git a/include/mapnik/char_info.hpp b/include/mapnik/char_info.hpp index a1417735f..12da2bf31 100644 --- a/include/mapnik/char_info.hpp +++ b/include/mapnik/char_info.hpp @@ -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() { } diff --git a/include/mapnik/config_error.hpp b/include/mapnik/config_error.hpp index b25ae07f1..ad06fba58 100644 --- a/include/mapnik/config_error.hpp +++ b/include/mapnik/config_error.hpp @@ -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; } diff --git a/include/mapnik/ctrans.hpp b/include/mapnik/ctrans.hpp index ba1e939fb..014073906 100644 --- a/include/mapnik/ctrans.hpp +++ b/include/mapnik/ctrans.hpp @@ -380,20 +380,27 @@ class CoordTransform private: int width_; int height_; - double sx_; - double sy_; box2d extent_; double offset_x_; double offset_y_; + double sx_; + double sy_; public: CoordTransform(int width, int height, const box2d& 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(width_) / extent_.width(); - sy_ = static_cast(height_) / extent_.height(); + if (extent_.width()) + sx_ = static_cast(width_) / extent_.width(); + if (extent_.height()) + sy_ = static_cast(height_) / extent_.height(); } inline int width() const diff --git a/include/mapnik/enumeration.hpp b/include/mapnik/enumeration.hpp index 0e069e4f1..b3c00dfa0 100644 --- a/include/mapnik/enumeration.hpp +++ b/include/mapnik/enumeration.hpp @@ -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 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_; } diff --git a/include/mapnik/feature.hpp b/include/mapnik/feature.hpp index 3b627d418..9b636824d 100644 --- a/include/mapnik/feature.hpp +++ b/include/mapnik/feature.hpp @@ -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 geom_cont_; raster_ptr raster_; - cont_type data_; }; diff --git a/include/mapnik/font_engine_freetype.hpp b/include/mapnik/font_engine_freetype.hpp index 12eb518bf..b8b91ea7b 100644 --- a/include/mapnik/font_engine_freetype.hpp +++ b/include/mapnik/font_engine_freetype.hpp @@ -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) { diff --git a/include/mapnik/image_util.hpp b/include/mapnik/image_util.hpp index efbed9eea..4ff3a08b2 100644 --- a/include/mapnik/image_util.hpp +++ b/include/mapnik/image_util.hpp @@ -147,7 +147,7 @@ inline boost::optional 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 ) { diff --git a/include/mapnik/load_map.hpp b/include/mapnik/load_map.hpp index 3dbba801f..7858c9395 100644 --- a/include/mapnik/load_map.hpp +++ b/include/mapnik/load_map.hpp @@ -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 diff --git a/include/mapnik/marker_cache.hpp b/include/mapnik/marker_cache.hpp index 5b56770b0..8f5fb8a0d 100644 --- a/include/mapnik/marker_cache.hpp +++ b/include/mapnik/marker_cache.hpp @@ -25,14 +25,7 @@ // mapnik #include -#include #include -#include -#include -#include - -// agg -#include "agg_path_storage.h" // boost #include @@ -43,7 +36,7 @@ namespace mapnik { -using namespace mapnik::svg; +class marker; typedef boost::shared_ptr marker_ptr; diff --git a/include/mapnik/placement_finder.hpp b/include/mapnik/placement_finder.hpp index 90561eaf1..662078238 100644 --- a/include/mapnik/placement_finder.hpp +++ b/include/mapnik/placement_finder.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 get_placement_offset(const std::vector & path_positions, - const std::vector & path_distances, + std::auto_ptr get_placement_offset(std::vector const& path_positions, + std::vector 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 & current_placement, const int & orientation); + bool test_placement(std::auto_ptr 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 diff --git a/include/mapnik/ptree_helpers.hpp b/include/mapnik/ptree_helpers.hpp index 811317312..0c3e8bf63 100644 --- a/include/mapnik/ptree_helpers.hpp +++ b/include/mapnik/ptree_helpers.hpp @@ -93,7 +93,7 @@ operator << ( std::basic_ostream & 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 > template inline boost::optional fast_cast(std::string const& value) { - return boost::lexical_cast( value ); + try + { + return boost::lexical_cast( value ); + } + catch (boost::bad_lexical_cast const& ex) + { + return boost::optional(); + } + } template <> diff --git a/include/mapnik/shield_symbolizer.hpp b/include/mapnik/shield_symbolizer.hpp index d31305664..85322f48e 100644 --- a/include/mapnik/shield_symbolizer.hpp +++ b/include/mapnik/shield_symbolizer.hpp @@ -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: diff --git a/include/mapnik/symbolizer_helpers.hpp b/include/mapnik/symbolizer_helpers.hpp index 8cd0554e1..d0eb0f014 100644 --- a/include/mapnik/symbolizer_helpers.hpp +++ b/include/mapnik/symbolizer_helpers.hpp @@ -53,7 +53,7 @@ public: unsigned width, unsigned height, double scale_factor, - CoordTransform const &t, + CoordTransform const& t, FaceManagerT &font_manager, DetectorT &detector, box2d const& query_extent) @@ -85,7 +85,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(); @@ -98,8 +98,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 dims_; box2d const& query_extent_; @@ -152,7 +152,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(); diff --git a/include/mapnik/text_path.hpp b/include/mapnik/text_path.hpp index f29cd903d..90490d154 100644 --- a/include/mapnik/text_path.hpp +++ b/include/mapnik/text_path.hpp @@ -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_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_() { } diff --git a/include/mapnik/text_properties.hpp b/include/mapnik/text_properties.hpp index 4362a632f..dbf21f8d7 100644 --- a/include/mapnik/text_properties.hpp +++ b/include/mapnik/text_properties.hpp @@ -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; diff --git a/include/mapnik/value_error.hpp b/include/mapnik/value_error.hpp index 7239dd450..5b53664b9 100644 --- a/include/mapnik/value_error.hpp +++ b/include/mapnik/value_error.hpp @@ -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; } diff --git a/plugins/input/osm/demo/MapSource.h b/plugins/input/osm/demo/MapSource.h index c51970c47..bf7eb3ede 100755 --- a/plugins/input/osm/demo/MapSource.h +++ b/plugins/input/osm/demo/MapSource.h @@ -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") { diff --git a/plugins/input/postgis/postgis_datasource.cpp b/plugins/input/postgis/postgis_datasource.cpp index 0c5f083e8..8e7556ed7 100644 --- a/plugins/input/postgis/postgis_datasource.cpp +++ b/plugins/input/postgis/postgis_datasource.cpp @@ -423,7 +423,7 @@ std::string postgis_datasource::populate_tokens(const std::string& sql, double s } -boost::shared_ptr postgis_datasource::get_resultset(boost::shared_ptr const &conn, const std::string &sql) const +boost::shared_ptr postgis_datasource::get_resultset(boost::shared_ptr const &conn, std::string const& sql) const { if (cursor_fetch_size_ > 0) { diff --git a/plugins/input/postgis/postgis_datasource.hpp b/plugins/input/postgis/postgis_datasource.hpp index 846664de1..047796e4f 100644 --- a/plugins/input/postgis/postgis_datasource.hpp +++ b/plugins/input/postgis/postgis_datasource.hpp @@ -92,7 +92,7 @@ private: std::string populate_tokens(const std::string& sql, double scale_denom, box2d const& env) const; std::string populate_tokens(const std::string& sql) const; static std::string unquote(const std::string& sql); - boost::shared_ptr get_resultset(boost::shared_ptr const &conn, const std::string &sql) const; + boost::shared_ptr get_resultset(boost::shared_ptr const &conn, std::string const& sql) const; postgis_datasource(const postgis_datasource&); postgis_datasource& operator=(const postgis_datasource&); }; diff --git a/src/agg/agg_renderer.cpp b/src/agg/agg_renderer.cpp index ec8fe8320..cbb703639 100644 --- a/src/agg/agg_renderer.cpp +++ b/src/agg/agg_renderer.cpp @@ -24,6 +24,7 @@ // mapnik #include #include +#include #include #include #include @@ -248,7 +249,7 @@ void agg_renderer::render_marker(pixel_position const& pos, marker const& mar mtx *= agg::trans_affine_scaling(scale_factor_); // render the marker at the center of the marker box mtx.translate(pos.x+0.5 * marker.width(), pos.y+0.5 * marker.height()); - + using namespace mapnik::svg; vertex_stl_adapter stl_storage((*marker.get_vector_data())->source()); svg_path_adapter svg_path(stl_storage); svg_renderer #include #include +#include #include #include diff --git a/src/agg/process_markers_symbolizer.cpp b/src/agg/process_markers_symbolizer.cpp index 0f05ee05c..1637f9450 100644 --- a/src/agg/process_markers_symbolizer.cpp +++ b/src/agg/process_markers_symbolizer.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include diff --git a/src/agg/process_point_symbolizer.cpp b/src/agg/process_point_symbolizer.cpp index 967ebd082..d29f6d15c 100644 --- a/src/agg/process_point_symbolizer.cpp +++ b/src/agg/process_point_symbolizer.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include diff --git a/src/agg/process_polygon_pattern_symbolizer.cpp b/src/agg/process_polygon_pattern_symbolizer.cpp index 9756e2e86..7e0f92c94 100644 --- a/src/agg/process_polygon_pattern_symbolizer.cpp +++ b/src/agg/process_polygon_pattern_symbolizer.cpp @@ -24,6 +24,7 @@ // mapnik #include #include +#include #include #include diff --git a/src/cairo_renderer.cpp b/src/cairo_renderer.cpp index 4c1c8b6ab..ea1813631 100644 --- a/src/cairo_renderer.cpp +++ b/src/cairo_renderer.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -913,7 +914,7 @@ void cairo_renderer_base::start_map_processing(Map const& map) typedef coord_transform2 path_type; mapnik::path_ptr vmarker = *marker.get_vector_data(); - + using namespace mapnik::svg; agg::pod_bvector const & attributes_ = vmarker->attributes(); for(unsigned i = 0; i < attributes_.size(); ++i) { diff --git a/src/feature_style_processor.cpp b/src/feature_style_processor.cpp index 04a5750d6..bb8441080 100644 --- a/src/feature_style_processor.cpp +++ b/src/feature_style_processor.cpp @@ -264,8 +264,10 @@ void feature_style_processor::apply_to_layer(layer const& lay, Proces box2d query_ext = m_.get_current_extent(); box2d unbuffered_extent = m_.get_current_extent(); prj_trans.forward(query_ext, PROJ_ENVELOPE_POINTS); - query::resolution_type res(m_.width()/query_ext.width(), - m_.height()/query_ext.height()); + double qw = query_ext.width()>0 ? query_ext.width() : 1; + double qh = query_ext.height()>0 ? query_ext.height() : 1; + query::resolution_type res(m_.width()/qw, + m_.height()/qh); query q(layer_ext,res,scale_denom,unbuffered_extent); p.start_layer_processing(lay, query_ext); diff --git a/src/grid/grid_renderer.cpp b/src/grid/grid_renderer.cpp index a4cc30f80..5a9a81448 100644 --- a/src/grid/grid_renderer.cpp +++ b/src/grid/grid_renderer.cpp @@ -29,6 +29,7 @@ #include +#include #include #include #include @@ -145,7 +146,7 @@ void grid_renderer::render_marker(mapnik::feature_ptr const& feature, unsigne mtx *= agg::trans_affine_scaling(scale_factor_*(1.0/step)); // render the marker at the center of the marker box mtx.translate(pos.x+0.5 * marker.width(), pos.y+0.5 * marker.height()); - + using namespace mapnik::svg; vertex_stl_adapter stl_storage((*marker.get_vector_data())->source()); svg_path_adapter svg_path(stl_storage); svg_renderer #include #include +#include #include #include diff --git a/src/grid/process_point_symbolizer.cpp b/src/grid/process_point_symbolizer.cpp index 2db4dd5c2..2c3e2b634 100644 --- a/src/grid/process_point_symbolizer.cpp +++ b/src/grid/process_point_symbolizer.cpp @@ -29,7 +29,7 @@ #include #include #include - +#include #include // stl diff --git a/src/image_util.cpp b/src/image_util.cpp index c3cee7610..5b3b46454 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -57,7 +57,6 @@ extern "C" #include // agg -//#include "agg_conv_transform.h" #include "agg_image_accessors.h" #include "agg_pixfmt_rgba.h" #include "agg_rasterizer_scanline_aa.h" diff --git a/src/libxml2_loader.cpp b/src/libxml2_loader.cpp index c4111696f..af9ff4de9 100644 --- a/src/libxml2_loader.cpp +++ b/src/libxml2_loader.cpp @@ -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()) { diff --git a/src/load_map.cpp b/src/load_map.cpp index 1b6345d77..3cfd51fb0 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -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 opt_path ); void ensure_attrs( ptree const& sym, std::string name, std::string attrs); @@ -185,8 +185,13 @@ void load_map(Map & map, std::string const& filename, bool strict) parser.parse_map(map, pt, base_path); } -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()) @@ -1789,7 +1794,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 ) ) { diff --git a/src/map.cpp b/src/map.cpp index f46437989..9a976c2a7 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -451,54 +451,57 @@ void Map::zoom_to_box(const box2d &box) void Map::fixAspectRatio() { - double ratio1 = (double) width_ / (double) height_; - double ratio2 = current_extent_.width() / current_extent_.height(); - if (ratio1 == ratio2) return; - - switch(aspectFixMode_) + if (current_extent_.width() > 0 && current_extent_.height() > 0) { - case ADJUST_BBOX_HEIGHT: - current_extent_.height(current_extent_.width() / ratio1); - break; - case ADJUST_BBOX_WIDTH: - current_extent_.width(current_extent_.height() * ratio1); - break; - case ADJUST_CANVAS_HEIGHT: - height_ = int (width_ / ratio2 + 0.5); - break; - case ADJUST_CANVAS_WIDTH: - width_ = int (height_ * ratio2 + 0.5); - break; - case GROW_BBOX: - if (ratio2 > ratio1) + double ratio1 = static_cast(width_) / static_cast(height_); + double ratio2 = current_extent_.width() / current_extent_.height(); + if (ratio1 == ratio2) return; + + switch(aspectFixMode_) + { + case ADJUST_BBOX_HEIGHT: current_extent_.height(current_extent_.width() / ratio1); - else + break; + case ADJUST_BBOX_WIDTH: current_extent_.width(current_extent_.height() * ratio1); - break; - case SHRINK_BBOX: - if (ratio2 < ratio1) - current_extent_.height(current_extent_.width() / ratio1); - else - current_extent_.width(current_extent_.height() * ratio1); - break; - case GROW_CANVAS: - if (ratio2 > ratio1) - width_ = (int) (height_ * ratio2 + 0.5); - else + break; + case ADJUST_CANVAS_HEIGHT: height_ = int (width_ / ratio2 + 0.5); - break; - case SHRINK_CANVAS: - if (ratio2 > ratio1) - height_ = int (width_ / ratio2 + 0.5); - else - width_ = (int) (height_ * ratio2 + 0.5); - break; - default: - if (ratio2 > ratio1) - current_extent_.height(current_extent_.width() / ratio1); - else - current_extent_.width(current_extent_.height() * ratio1); - break; + break; + case ADJUST_CANVAS_WIDTH: + width_ = int (height_ * ratio2 + 0.5); + break; + case GROW_BBOX: + if (ratio2 > ratio1) + current_extent_.height(current_extent_.width() / ratio1); + else + current_extent_.width(current_extent_.height() * ratio1); + break; + case SHRINK_BBOX: + if (ratio2 < ratio1) + current_extent_.height(current_extent_.width() / ratio1); + else + current_extent_.width(current_extent_.height() * ratio1); + break; + case GROW_CANVAS: + if (ratio2 > ratio1) + width_ = static_cast(height_ * ratio2 + 0.5); + else + height_ = int (width_ / ratio2 + 0.5); + break; + case SHRINK_CANVAS: + if (ratio2 > ratio1) + height_ = int (width_ / ratio2 + 0.5); + else + width_ = static_cast(height_ * ratio2 + 0.5); + break; + default: + if (ratio2 > ratio1) + current_extent_.height(current_extent_.width() / ratio1); + else + current_extent_.width(current_extent_.height() * ratio1); + break; + } } } diff --git a/src/marker_cache.cpp b/src/marker_cache.cpp index f5139699a..41117bba6 100644 --- a/src/marker_cache.cpp +++ b/src/marker_cache.cpp @@ -23,11 +23,13 @@ //$Id$ // mapnik +#include #include #include #include -#include #include +#include +#include #include #include @@ -35,6 +37,7 @@ #include #include #include +#include namespace mapnik { @@ -72,7 +75,7 @@ boost::optional marker_cache::find(std::string const& uri, bool upda using namespace mapnik::svg; try { - path_ptr marker_path(new svg_storage_type); + path_ptr marker_path(boost::make_shared()); vertex_stl_adapter stl_storage(marker_path->source()); svg_path_adapter svg_path(stl_storage); svg_converter_type svg(svg_path, marker_path->attributes()); @@ -84,7 +87,7 @@ boost::optional marker_cache::find(std::string const& uri, bool upda svg.bounding_rect(&lox, &loy, &hix, &hiy); marker_path->set_bounding_box(lox,loy,hix,hiy); - marker_ptr mark(new marker(marker_path)); + marker_ptr mark(boost::make_shared(marker_path)); result.reset(mark); if (update_cache) { @@ -107,9 +110,9 @@ boost::optional marker_cache::find(std::string const& uri, bool upda unsigned width = reader->width(); unsigned height = reader->height(); BOOST_ASSERT(width > 0 && height > 0); - mapnik::image_ptr image(new mapnik::image_data_32(width,height)); + mapnik::image_ptr image(boost::make_shared(width,height)); reader->read(0,0,*image); - marker_ptr mark(new marker(image)); + marker_ptr mark(boost::make_shared(image)); result.reset(mark); if (update_cache) { diff --git a/src/placement_finder.cpp b/src/placement_finder.cpp index af9a1ed8d..f68597edb 100644 --- a/src/placement_finder.cpp +++ b/src/placement_finder.cpp @@ -218,9 +218,13 @@ void placement_finder::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 @@ -264,8 +268,10 @@ void placement_finder::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); @@ -321,10 +327,9 @@ void placement_finder::init_alignment() template -void placement_finder::adjust_position(text_path *current_placement, double label_x, double label_y) +void placement_finder::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 @@ -334,7 +339,6 @@ void placement_finder::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 @@ -350,7 +354,9 @@ void placement_finder::adjust_position(text_path *current_placement, } template -void placement_finder::find_point_placement(double label_x, double label_y, double angle) +void placement_finder::find_point_placement(double label_x, + double label_y, + double angle) { find_line_breaks(); @@ -359,9 +365,9 @@ void placement_finder::find_point_placement(double label_x, double la double sina = std::sin(rad); double x, y; - std::auto_ptr current_placement(new text_path); + std::auto_ptr 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; @@ -440,7 +446,8 @@ void placement_finder::find_point_placement(double label_x, double la } // if avoid_edges test dimensions contains e - if (p.avoid_edges && !dimensions_.contains(e)) { + if (p.avoid_edges && !dimensions_.contains(e)) + { return; } @@ -554,7 +561,7 @@ void placement_finder::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 (floor(total_distance / (pi.get_actual_label_spacing() + string_width_))); + num_labels = static_cast(floor(total_distance / (pi.get_actual_label_spacing() + string_width_))); if (p.force_odd_labels && (num_labels % 2 == 0)) num_labels--; @@ -667,7 +674,11 @@ void placement_finder::find_line_placements(PathT & shape_path) } template -std::auto_ptr placement_finder::get_placement_offset(const std::vector &path_positions, const std::vector &path_distances, int &orientation, unsigned index, double distance) +std::auto_ptr placement_finder::get_placement_offset(std::vector const& path_positions, + std::vector 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) @@ -691,8 +702,6 @@ std::auto_ptr placement_finder::get_placement_offset(const const unsigned initial_index = index; const double initial_distance = distance; - std::auto_ptr current_placement(new text_path); - double old_x = path_positions[index-1].x; double old_y = path_positions[index-1].y; @@ -708,11 +717,15 @@ std::auto_ptr placement_finder::get_placement_offset(const return std::auto_ptr(NULL); } - current_placement->center.x = old_x + dx*distance/segment_length; - current_placement->center.y = old_y + dy*distance/segment_length; + std::auto_ptr 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; @@ -838,7 +851,11 @@ std::auto_ptr placement_finder::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 { @@ -852,7 +869,8 @@ std::auto_ptr placement_finder::get_placement_offset(const } template -bool placement_finder::test_placement(const std::auto_ptr & current_placement, const int & orientation) +bool placement_finder::test_placement(std::auto_ptr const& current_placement, + int orientation) { //Create and test envelopes bool status = true; @@ -929,9 +947,9 @@ bool placement_finder::test_placement(const std::auto_ptr template void placement_finder::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; diff --git a/src/symbolizer_helpers.cpp b/src/symbolizer_helpers.cpp index 2b2bf3cd4..8c59ff272 100644 --- a/src/symbolizer_helpers.cpp +++ b/src/symbolizer_helpers.cpp @@ -141,9 +141,7 @@ void text_symbolizer_helper::initialize_geometries() largest_box_only = true; if (sym_.get_minimum_path_length() > 0) { - // TODO - find less costly method than fetching full envelope box2d gbox = t_.forward(geom.envelope(), prj_trans_); - if (gbox.width() < sym_.get_minimum_path_length()) { continue; @@ -167,10 +165,13 @@ template void text_symbolizer_helper::initialize_points() { label_placement_enum how_placed = placement_->properties.label_placement; - if (how_placed == LINE_PLACEMENT) { + if (how_placed == LINE_PLACEMENT) + { point_placement_ = false; return; - } else { + } + else + { point_placement_ = true; } @@ -193,14 +194,19 @@ void text_symbolizer_helper::initialize_points() t_.forward(&label_x, &label_y); points_.push_back(std::make_pair(label_x, label_y)); } - } else { + } + else + { if (how_placed == POINT_PLACEMENT) { geom.label_position(&label_x, &label_y); - } else if (how_placed == INTERIOR_PLACEMENT) + } + else if (how_placed == INTERIOR_PLACEMENT) { geom.label_interior_position(&label_x, &label_y); - } else { + } + else + { #ifdef MAPNIK_DEBUG std::cerr << "ERROR: Unknown placement type in initialize_points();\n"; #endif diff --git a/src/text_placements/registry.cpp b/src/text_placements/registry.cpp index 30668b78f..621c161b3 100644 --- a/src/text_placements/registry.cpp +++ b/src/text_placements/registry.cpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace mapnik { @@ -33,6 +34,7 @@ registry::registry() { register_name("simple", &text_placements_simple::from_xml); register_name("list", &text_placements_list::from_xml); + register_name("dummy", &text_placements_list::from_xml); } void registry::register_name(std::string name, from_xml_function_ptr ptr, bool overwrite) diff --git a/src/text_properties.cpp b/src/text_properties.cpp index 864cdd4ec..6b1e45ce8 100644 --- a/src/text_properties.cpp +++ b/src/text_properties.cpp @@ -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); diff --git a/tests/visual_tests/test.py b/tests/visual_tests/test.py index b7509fd73..67dc0d468 100755 --- a/tests/visual_tests/test.py +++ b/tests/visual_tests/test.py @@ -2,12 +2,11 @@ # -*- coding: utf-8 -*- import mapnik -import cairo import sys import os.path from compare import compare, summary -dirname = os.path.dirname(sys.argv[0]) +dirname = os.path.dirname(__file__) files = [ ("list", 800, 600, 400, 300, 250, 200, 150, 100), ("simple", 800, 600, 400, 300, 250, 200, 150, 100), @@ -40,7 +39,7 @@ def render(filename, width, height=100): mapnik.load_map(m, os.path.join(dirname, "%s.xml" % filename), False) bbox = mapnik.Box2d(-0.05, -0.01, 0.95, 0.01) m.zoom_to_box(bbox) - basefn = '%s-%d' % (filename, width) + basefn = os.path.join(dirname,'%s-%d' % (filename, width)) mapnik.render_to_file(m, basefn+'-agg.png') diff = compare(basefn + '-agg.png', basefn + '-reference.png') if diff > 0: @@ -61,6 +60,6 @@ for f in files: m = render(f[0], width[0], width[1]) else: m = render(f[0], width) - mapnik.save_map(m, "%s-out.xml" % f[0]) + mapnik.save_map(m, os.path.join(dirname,"%s-out.xml" % f[0])) summary()