Merge branch 'master' into geometry-clipping

Conflicts:
	SConstruct
	include/mapnik/symbolizer_helpers.hpp
	src/placement_finder.cpp
This commit is contained in:
Artem Pavlenko 2012-03-09 14:18:41 +00:00
commit 254b3c9fa7
44 changed files with 255 additions and 160 deletions

View file

@ -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 file

@ -682,6 +682,7 @@ __all__ = [
'SQLite',
'Osm',
'Kismet',
'Geos',
# version and environment
'mapnik_version_string',
'mapnik_version',

View file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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;
}

View file

@ -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 file

@ -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_;
}

View file

@ -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_;
};

View file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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

View file

@ -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 file

@ -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 file

@ -53,7 +53,7 @@ public:
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 @@ 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<double> dims_;
box2d<double> 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();

View file

@ -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_()
{
}

View file

@ -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 file

@ -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;
}

View file

@ -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")
{

View file

@ -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 file

@ -92,7 +92,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&);
};

View file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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())
{

View file

@ -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);
@ -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 file

@ -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)
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 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<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 file

@ -23,11 +23,13 @@
//$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>
@ -35,6 +37,7 @@
#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 file

@ -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 file

@ -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 file

@ -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 file

@ -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 file

@ -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()