Skip to content
Browse files

Merge branch 'master' into geometry-clipping

Conflicts:
	SConstruct
	include/mapnik/symbolizer_helpers.hpp
	src/placement_finder.cpp
  • Loading branch information...
2 parents 5ce1871 + c5c0f92 commit 254b3c9fa7da1a45dcd694292b17ba8d01485257 @artemp artemp committed Mar 9, 2012
Showing with 255 additions and 160 deletions.
  1. +2 −0 SConstruct
  2. +1 −0 bindings/python/mapnik/__init__.py
  3. +2 −2 bindings/python/mapnik_map.cpp
  4. +12 −0 docs/contributing.markdown
  5. +0 −4 include/mapnik/agg_renderer.hpp
  6. +15 −2 include/mapnik/char_info.hpp
  7. +4 −3 include/mapnik/config_error.hpp
  8. +13 −6 include/mapnik/ctrans.hpp
  9. +7 −5 include/mapnik/enumeration.hpp
  10. +4 −2 include/mapnik/feature.hpp
  11. +2 −1 include/mapnik/font_engine_freetype.hpp
  12. +1 −1 include/mapnik/image_util.hpp
  13. +1 −1 include/mapnik/load_map.hpp
  14. +1 −8 include/mapnik/marker_cache.hpp
  15. +8 −8 include/mapnik/placement_finder.hpp
  16. +10 −2 include/mapnik/ptree_helpers.hpp
  17. +1 −1 include/mapnik/shield_symbolizer.hpp
  18. +5 −5 include/mapnik/symbolizer_helpers.hpp
  19. +8 −5 include/mapnik/text_path.hpp
  20. +1 −1 include/mapnik/text_properties.hpp
  21. +2 −2 include/mapnik/value_error.hpp
  22. +1 −1 plugins/input/osm/demo/MapSource.h
  23. +1 −1 plugins/input/postgis/postgis_datasource.cpp
  24. +1 −1 plugins/input/postgis/postgis_datasource.hpp
  25. +2 −1 src/agg/agg_renderer.cpp
  26. +1 −0 src/agg/process_line_pattern_symbolizer.cpp
  27. +1 −0 src/agg/process_markers_symbolizer.cpp
  28. +1 −0 src/agg/process_point_symbolizer.cpp
  29. +1 −0 src/agg/process_polygon_pattern_symbolizer.cpp
  30. +2 −1 src/cairo_renderer.cpp
  31. +4 −2 src/feature_style_processor.cpp
  32. +2 −1 src/grid/grid_renderer.cpp
  33. +1 −0 src/grid/process_markers_symbolizer.cpp
  34. +1 −1 src/grid/process_point_symbolizer.cpp
  35. +0 −1 src/image_util.cpp
  36. +2 −2 src/libxml2_loader.cpp
  37. +8 −3 src/load_map.cpp
  38. +47 −44 src/map.cpp
  39. +8 −5 src/marker_cache.cpp
  40. +39 −21 src/placement_finder.cpp
  41. +13 −7 src/symbolizer_helpers.cpp
  42. +2 −0 src/text_placements/registry.cpp
  43. +14 −5 src/text_properties.cpp
  44. +3 −4 tests/visual_tests/test.py
View
2 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'
View
1 bindings/python/mapnik/__init__.py
@@ -682,6 +682,7 @@ def register_fonts(path=fontscollectionpath,valid_extensions=['.ttf','.otf','.tt
'SQLite',
'Osm',
'Kismet',
+ 'Geos',
# version and environment
'mapnik_version_string',
'mapnik_version',
View
4 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;
View
12 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:
View
4 include/mapnik/agg_renderer.hpp
@@ -29,10 +29,6 @@
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/label_collision_detector.hpp>
#include <mapnik/map.hpp>
-//#include <mapnik/marker.hpp>
-
-// agg
-//#include "agg_trans_affine.h"
// boost
#include <boost/utility.hpp>
View
17 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()
{
}
View
7 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 @@ class config_error : public std::exception
return what_.c_str();
}
- void append_context(const std::string & ctx) const
+ void append_context(std::string const& ctx) const
{
what_ += " " + ctx;
}
View
19 include/mapnik/ctrans.hpp
@@ -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
View
12 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 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 @@ class MAPNIK_DECL enumeration {
/** 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 @@ class MAPNIK_DECL enumeration {
}
return true;
}
- static const std::string & get_full_qualified_name()
+ static std::string const& get_full_qualified_name()
{
return our_name_;
}
View
6 include/mapnik/feature.hpp
@@ -100,7 +100,9 @@ class MAPNIK_DECL feature_impl : private boost::noncopyable
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 @@ class MAPNIK_DECL feature_impl : private boost::noncopyable
private:
int id_;
context_ptr ctx_;
+ cont_type data_;
boost::ptr_vector<geometry_type> geom_cont_;
raster_ptr raster_;
- cont_type data_;
};
View
3 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)
{
View
2 include/mapnik/image_util.hpp
@@ -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 ) {
View
2 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
View
9 include/mapnik/marker_cache.hpp
@@ -25,14 +25,7 @@
// mapnik
#include <mapnik/utils.hpp>
-#include <mapnik/marker.hpp>
#include <mapnik/config.hpp>
-#include <mapnik/svg/svg_path_attributes.hpp>
-#include <mapnik/svg/svg_storage.hpp>
-#include <mapnik/svg/svg_path_adapter.hpp>
-
-// agg
-#include "agg_path_storage.h"
// boost
#include <boost/utility.hpp>
@@ -43,7 +36,7 @@
namespace mapnik
{
-using namespace mapnik::svg;
+class marker;
typedef boost::shared_ptr<marker> marker_ptr;
View
16 include/mapnik/placement_finder.hpp
@@ -92,29 +92,29 @@ class placement_finder : boost::noncopyable
// 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
// Pre Conditions: x1,y1 is within radius distance of cx,cy. x2,y2 is outside radius distance of cx,cy
// 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
View
12 include/mapnik/ptree_helpers.hpp
@@ -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 <>
View
2 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:
View
10 include/mapnik/symbolizer_helpers.hpp
@@ -53,7 +53,7 @@ class text_symbolizer_helper
unsigned width,
unsigned height,
double scale_factor,
- CoordTransform const &t,
+ CoordTransform const& t,
FaceManagerT &font_manager,
DetectorT &detector,
box2d<double> const& query_extent)
@@ -85,7 +85,7 @@ class text_symbolizer_helper
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 @@ class text_symbolizer_helper
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_;
box2d<double> const& query_extent_;
@@ -152,7 +152,7 @@ class shield_symbolizer_helper: public text_symbolizer_helper<FaceManagerT, Dete
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();
View
13 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_node> character_nodes_t;
- character_nodes_t nodes_;
-
pixel_position center;
+ character_nodes_t nodes_;
- text_path()
- : itr_(0)
+ text_path(double x, double y)
+ : itr_(0),
+ center(x,y),
+ nodes_()
{
}
View
2 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;
View
4 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 @@ class value_error : public std::exception
return what_.c_str();
}
- void append_context(const std::string & ctx) const
+ void append_context(std::string const& ctx) const
{
what_ += " " + ctx;
}
View
2 plugins/input/osm/demo/MapSource.h
@@ -70,7 +70,7 @@ class MapSource
(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")
{
View
2 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<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)
{
View
2 plugins/input/postgis/postgis_datasource.hpp
@@ -92,7 +92,7 @@ class postgis_datasource : public datasource
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&);
};
View
3 src/agg/agg_renderer.cpp
@@ -24,6 +24,7 @@
// mapnik
#include <mapnik/agg_renderer.hpp>
#include <mapnik/agg_rasterizer.hpp>
+#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/config_error.hpp>
@@ -248,7 +249,7 @@ void agg_renderer<T>::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<svg_path_storage> stl_storage((*marker.get_vector_data())->source());
svg_path_adapter svg_path(stl_storage);
svg_renderer<svg_path_adapter,
View
1 src/agg/process_line_pattern_symbolizer.cpp
@@ -26,6 +26,7 @@
#include <mapnik/agg_rasterizer.hpp>
#include <mapnik/agg_pattern_source.hpp>
#include <mapnik/expression_evaluator.hpp>
+#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/line_pattern_symbolizer.hpp>
View
1 src/agg/process_markers_symbolizer.cpp
@@ -25,6 +25,7 @@
#include <mapnik/agg_rasterizer.hpp>
#include <mapnik/expression_evaluator.hpp>
#include <mapnik/image_util.hpp>
+#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/svg/svg_renderer.hpp>
#include <mapnik/svg/svg_path_adapter.hpp>
View
1 src/agg/process_point_symbolizer.cpp
@@ -26,6 +26,7 @@
#include <mapnik/agg_rasterizer.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/metawriter.hpp>
+#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/expression_evaluator.hpp>
View
1 src/agg/process_polygon_pattern_symbolizer.cpp
@@ -24,6 +24,7 @@
// mapnik
#include <mapnik/agg_renderer.hpp>
#include <mapnik/agg_rasterizer.hpp>
+#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/expression_evaluator.hpp>
View
3 src/cairo_renderer.cpp
@@ -31,6 +31,7 @@
#include <mapnik/arrow.hpp>
#include <mapnik/config_error.hpp>
#include <mapnik/parse_path.hpp>
+#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/svg/svg_path_adapter.hpp>
#include <mapnik/svg/svg_path_attributes.hpp>
@@ -913,7 +914,7 @@ void cairo_renderer_base::start_map_processing(Map const& map)
typedef coord_transform2<CoordTransform,geometry_type> path_type;
mapnik::path_ptr vmarker = *marker.get_vector_data();
-
+ using namespace mapnik::svg;
agg::pod_bvector<path_attributes> const & attributes_ = vmarker->attributes();
for(unsigned i = 0; i < attributes_.size(); ++i)
{
View
6 src/feature_style_processor.cpp
@@ -264,8 +264,10 @@ void feature_style_processor<Processor>::apply_to_layer(layer const& lay, Proces
box2d<double> query_ext = m_.get_current_extent();
box2d<double> 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);
View
3 src/grid/grid_renderer.cpp
@@ -29,6 +29,7 @@
#include <mapnik/grid/grid.hpp>
+#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/config_error.hpp>
@@ -145,7 +146,7 @@ void grid_renderer<T>::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<svg_path_storage> stl_storage((*marker.get_vector_data())->source());
svg_path_adapter svg_path(stl_storage);
svg_renderer<svg_path_adapter,
View
1 src/grid/process_markers_symbolizer.cpp
@@ -27,6 +27,7 @@
#include <mapnik/grid/grid_pixfmt.hpp>
#include <mapnik/grid/grid_pixel.hpp>
#include <mapnik/grid/grid.hpp>
+#include <mapnik/marker.hpp>
#include <mapnik/markers_symbolizer.hpp>
#include <mapnik/expression_evaluator.hpp>
View
2 src/grid/process_point_symbolizer.cpp
@@ -29,7 +29,7 @@
#include <mapnik/grid/grid.hpp>
#include <mapnik/point_symbolizer.hpp>
#include <mapnik/expression_evaluator.hpp>
-
+#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
// stl
View
1 src/image_util.cpp
@@ -57,7 +57,6 @@ extern "C"
#include <sstream>
// agg
-//#include "agg_conv_transform.h"
#include "agg_image_accessors.h"
#include "agg_pixfmt_rgba.h"
#include "agg_rasterizer_scanline_aa.h"
View
4 src/libxml2_loader.cpp
@@ -71,7 +71,7 @@ class libxml2_loader : boost::noncopyable
}
}
- 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 @@ class libxml2_loader : boost::noncopyable
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())
{
View
11 src/load_map.cpp
@@ -122,7 +122,7 @@ class map_parser : boost::noncopyable {
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);
@@ -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 ) )
{
View
91 src/map.cpp
@@ -451,54 +451,57 @@ void Map::zoom_to_box(const box2d<double> &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)
- current_extent_.height(current_extent_.width() / ratio1);
- else
- current_extent_.width(current_extent_.height() * ratio1);
- break;
- case SHRINK_BBOX:
- if (ratio2 < ratio1)
+ double ratio1 = static_cast<double>(width_) / static_cast<double>(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 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<int>(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<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;
+ }
}
}
View
13 src/marker_cache.cpp
@@ -23,18 +23,21 @@
//$Id$
// mapnik
+#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/svg/svg_parser.hpp>
#include <mapnik/svg/svg_storage.hpp>
-#include <mapnik/svg/svg_path_adapter.hpp>
#include <mapnik/svg/svg_converter.hpp>
+#include <mapnik/svg/svg_path_adapter.hpp>
+#include <mapnik/svg/svg_path_attributes.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/image_reader.hpp>
// boost
#include <boost/assert.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/algorithm/string.hpp>
+#include <boost/make_shared.hpp>
namespace mapnik
{
@@ -72,7 +75,7 @@ boost::optional<marker_ptr> 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<svg_storage_type>());
vertex_stl_adapter<svg_path_storage> 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_ptr> 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>(marker_path));
result.reset(mark);
if (update_cache)
{
@@ -107,9 +110,9 @@ boost::optional<marker_ptr> 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<mapnik::image_data_32>(width,height));
reader->read(0,0,*image);
- marker_ptr mark(new marker(image));
+ marker_ptr mark(boost::make_shared<marker>(image));
result.reset(mark);
if (update_cache)
{
View
60 src/placement_finder.cpp
@@ -218,9 +218,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
@@ -264,8 +268,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);
@@ -321,10 +327,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
@@ -334,7 +339,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
@@ -350,7 +354,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();
@@ -359,9 +365,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;
@@ -440,7 +446,8 @@ void placement_finder<DetectorT>::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<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--;
@@ -667,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)
@@ -691,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;
@@ -708,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;
@@ -838,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
{
@@ -852,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;
@@ -929,9 +947,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;
View
20 src/symbolizer_helpers.cpp
@@ -141,9 +141,7 @@ void text_symbolizer_helper<FaceManagerT, DetectorT>::initialize_geometries()
largest_box_only = true;
if (sym_.get_minimum_path_length() > 0)
{
- // TODO - find less costly method than fetching full envelope
box2d<double> gbox = t_.forward(geom.envelope(), prj_trans_);
-
if (gbox.width() < sym_.get_minimum_path_length())
{
continue;
@@ -167,10 +165,13 @@ template <typename FaceManagerT, typename DetectorT>
void text_symbolizer_helper<FaceManagerT, DetectorT>::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<FaceManagerT, DetectorT>::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
View
2 src/text_placements/registry.cpp
@@ -23,6 +23,7 @@
#include <mapnik/text_placements/registry.hpp>
#include <mapnik/text_placements/simple.hpp>
#include <mapnik/text_placements/list.hpp>
+#include <mapnik/text_placements/dummy.hpp>
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)
View
19 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);
View
7 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 @@ def render(filename, width, height=100):
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()

0 comments on commit 254b3c9

Please sign in to comment.
Something went wrong with that request. Please try again.