Merge branch 'textplacement-rename'

This commit is contained in:
Hermann Kraus 2012-02-12 14:03:57 +01:00
commit afb2eedbb9
39 changed files with 695 additions and 498 deletions

View file

@ -24,7 +24,7 @@
#include <boost/python.hpp>
// mapnik
#include <mapnik/feature.hpp>
#include <mapnik/filter_factory.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/expression_string.hpp>
#include <mapnik/expression_evaluator.hpp>
#include <mapnik/parse_path.hpp>

View file

@ -27,7 +27,7 @@
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <mapnik/rule.hpp>
#include <mapnik/filter_factory.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/expression_string.hpp>
using mapnik::rule;

View file

@ -23,7 +23,7 @@
#include <boost/python.hpp>
#include <mapnik/text_placements.hpp>
#include <mapnik/text_properties.hpp>
#include "mapnik_enumeration.hpp"
#include <mapnik/expression_string.hpp>

View file

@ -19,13 +19,12 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
// $Id$
#include <mapnik/map.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/agg_renderer.hpp>
#include <mapnik/filter_factory.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/color_factory.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/config_error.hpp>

View file

@ -26,7 +26,7 @@
// mapnik
#include <mapnik/color.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/filter_factory.hpp>
#include <mapnik/expression.hpp>
namespace mapnik
{

View file

@ -37,7 +37,7 @@ public:
what_( what )
{
}
virtual ~config_error() throw() {};
virtual ~config_error() throw() {}
virtual const char * what() const throw()
{

View file

@ -20,8 +20,8 @@
*
*****************************************************************************/
#ifndef MAPNIK_FILTER_FACTORY_HPP
#define MAPNIK_FILTER_FACTORY_HPP
#ifndef MAPNIK_EXPRESSION_HPP
#define MAPNIK_EXPRESSION_HPP
// mapnik
#include <mapnik/config.hpp>
@ -40,4 +40,4 @@ MAPNIK_DECL expression_ptr parse_expression (std::string const& wkt);
}
#endif // MAPNIK_FILTER_FACTORY_HPP
#endif // MAPNIK_EXPRESSION_HPP

View file

@ -0,0 +1,57 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef FORMATING_BASE_HPP
#define FORMATING_BASE_HPP
// mapnik
#include <mapnik/feature.hpp>
#include <mapnik/expression.hpp>
// stl
#include <set>
// boost
#include <boost/property_tree/ptree.hpp>
namespace mapnik {
typedef std::set<expression_ptr> expression_set;
class processed_text;
struct char_properties;
namespace formating {
class node;
typedef boost::shared_ptr<node> node_ptr;
class node
{
public:
virtual ~node() {}
virtual void to_xml(boost::property_tree::ptree &xml) const;
static node_ptr from_xml(boost::property_tree::ptree const& xml);
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const = 0;
virtual void add_expressions(expression_set &output) const;
};
} //ns formating
} //ns mapnik
#endif // FORMATING_BASE_HPP

View file

@ -0,0 +1,59 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef FORMAT_HPP
#define FORMAT_HPP
#include <mapnik/formating/base.hpp>
#include <mapnik/text_properties.hpp>
namespace mapnik {
namespace formating {
class format_node: public node {
public:
void to_xml(boost::property_tree::ptree &xml) const;
static node_ptr from_xml(boost::property_tree::ptree const& xml);
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const;
virtual void add_expressions(expression_set &output) const;
void set_child(node_ptr child);
node_ptr get_child() const;
boost::optional<std::string> face_name;
boost::optional<unsigned> text_size;
boost::optional<unsigned> character_spacing;
boost::optional<unsigned> line_spacing;
boost::optional<double> text_opacity;
boost::optional<bool> wrap_before;
boost::optional<unsigned> wrap_char;
boost::optional<text_transform_e> text_transform;
boost::optional<color> fill;
boost::optional<color> halo_fill;
boost::optional<double> halo_radius;
private:
node_ptr child_;
};
} //ns formating
} //ns mapnik
#endif // FORMAT_HPP

View file

@ -0,0 +1,46 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef LIST_HPP
#define LIST_HPP
#include <mapnik/formating/base.hpp>
namespace mapnik {
namespace formating {
class list_node: public node {
public:
list_node() : node(), children_() {}
virtual void to_xml(boost::property_tree::ptree &xml) const;
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const;
virtual void add_expressions(expression_set &output) const;
void push_back(node_ptr n);
void set_children(std::vector<node_ptr> const& children);
std::vector<node_ptr> const& get_children() const;
void clear();
private:
std::vector<node_ptr> children_;
};
} //ns formating
} //ns mapnik
#endif // LIST_HPP

View file

@ -0,0 +1,46 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef TEXT_HPP
#define TEXT_HPP
#include <mapnik/formating/base.hpp>
namespace mapnik {
namespace formating {
class text_node: public node {
public:
text_node(expression_ptr text): node(), text_(text) {}
text_node(std::string text): node(), text_(parse_expression(text)) {}
void to_xml(boost::property_tree::ptree &xml) const;
static node_ptr from_xml(boost::property_tree::ptree const& xml);
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const;
virtual void add_expressions(expression_set &output) const;
void set_text(expression_ptr text);
expression_ptr get_text() const;
private:
expression_ptr text_;
};
} //ns formating
} //ns mapnik
#endif // TEXT_HPP

View file

@ -77,7 +77,7 @@ class metawriter_properties : public std::set<std::string>
{
public:
metawriter_properties(boost::optional<std::string> str);
metawriter_properties() {};
metawriter_properties() {}
template <class InputIterator> metawriter_properties(
InputIterator first, InputIterator last) : std::set<std::string>(first, last) {}
std::string to_string() const;
@ -92,7 +92,7 @@ public:
dflt_properties_(dflt_properties),
width_(0),
height_(0) {}
virtual ~metawriter() {};
virtual ~metawriter() {}
/** Output a rectangular area.
* \param box Area (in pixel coordinates)
* \param feature The feature being processed
@ -126,12 +126,12 @@ public:
virtual void start(metawriter_property_map const& properties)
{
boost::ignore_unused_variable_warning(properties);
};
}
/** Stop processing.
* Write file footer, close database connection, ...
*/
virtual void stop() {};
virtual void stop() {}
/** Set output size (pixels).
* All features that are completely outside this size are discarded.
*/

View file

@ -24,11 +24,15 @@
#define MAPNIK_PLACEMENT_FINDER_HPP
#include <mapnik/geometry.hpp>
#include <mapnik/text_placements.hpp>
#include <mapnik/text_properties.hpp>
namespace mapnik
{
class text_placement_info;
class string_info;
class text_path;
template <typename DetectorT>
class placement_finder : boost::noncopyable
{

View file

@ -26,7 +26,6 @@
// mapnik
#include <mapnik/color.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/filter_factory.hpp>
#include <mapnik/enumeration.hpp>
#include <mapnik/gamma_method.hpp>

View file

@ -0,0 +1,61 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef PROCESSED_TEXT_HPP
#define PROCESSED_TEXT_HPP
// mapnik
#include <mapnik/text_properties.hpp>
#include <mapnik/font_engine_freetype.hpp>
namespace mapnik
{
class processed_text : boost::noncopyable
{
public:
class processed_expression
{
public:
processed_expression(char_properties const& properties, UnicodeString const& text) :
p(properties), str(text) {}
char_properties p;
UnicodeString str;
};
public:
processed_text(face_manager<freetype_engine> & font_manager, double scale_factor);
void push_back(char_properties const& properties, UnicodeString const& text);
unsigned size() const { return expr_list_.size(); }
unsigned empty() const { return expr_list_.empty(); }
void clear();
typedef std::list<processed_expression> expression_list;
expression_list::const_iterator begin() const;
expression_list::const_iterator end() const;
string_info &get_string_info();
private:
expression_list expr_list_;
face_manager<freetype_engine> &font_manager_;
double scale_factor_;
string_info info_;
};
} // ns mapnik
#endif // PROCESSED_TEXT_HPP

View file

@ -35,7 +35,7 @@
#include <mapnik/text_symbolizer.hpp>
#include <mapnik/markers_symbolizer.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/filter_factory.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/expression_string.hpp>
// boost

View file

@ -24,12 +24,12 @@
#include <mapnik/text_symbolizer.hpp>
#include <mapnik/shield_symbolizer.hpp>
#include <mapnik/text_processing.hpp>
#include <mapnik/placement_finder.hpp>
#include <mapnik/expression_evaluator.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/processed_text.hpp>
#include <boost/shared_ptr.hpp>

View file

@ -1,281 +0,0 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2011 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MAPNIK_TEXT_PLACEMENTS_HPP
#define MAPNIK_TEXT_PLACEMENTS_HPP
// mapnik
#include <mapnik/color.hpp>
#include <mapnik/font_set.hpp>
#include <mapnik/text_path.hpp>
#include <mapnik/box2d.hpp>
#include <mapnik/text_processing.hpp>
// stl
#include <vector>
#include <string>
#include <queue>
#include <set>
// boost
#include <boost/tuple/tuple.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <boost/property_tree/ptree.hpp>
namespace mapnik {
class text_placements;
typedef std::pair<double,double> position;
typedef std::pair<double,double> dimension_type;
struct char_properties
{
char_properties();
/** Construct object from XML. */
void from_xml(boost::property_tree::ptree const &sym, std::map<std::string,font_set> 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;
std::string face_name;
font_set fontset;
float text_size;
double character_spacing;
double line_spacing; //Largest total height (fontsize+line_spacing) per line is chosen
double text_opacity;
bool wrap_before;
unsigned wrap_char;
text_transform_e text_transform; //Per expression
color fill;
color halo_fill;
double halo_radius;
};
/** Contains all text symbolizer properties which are not directly related to text formating. */
struct text_symbolizer_properties
{
text_symbolizer_properties();
/** Load all values from XML ptree. */
void from_xml(boost::property_tree::ptree const &sym, std::map<std::string,font_set> const & fontsets);
/** Save all values to XML ptree (but does not create a new parent node!). */
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, text_symbolizer_properties const &dfl=text_symbolizer_properties()) const;
/** Takes a feature and produces formated text as output.
* The output object has to be created by the caller and passed in for thread safety.
*/
void process(processed_text &output, Feature const& feature) const;
/** Automatically create processing instructions for a single expression. */
void set_old_style_expression(expression_ptr expr);
/** Sets new format tree. */
void set_format_tree(formating::node_ptr tree);
/** Get format tree. */
formating::node_ptr format_tree() const;
/** Get a list of all expressions used in any placement.
* This function is used to collect attributes. */
void add_expressions(expression_set &output) const;
//Per symbolizer options
expression_ptr orientation;
position displacement;
label_placement_e label_placement;
horizontal_alignment_e halign;
justify_alignment_e jalign;
vertical_alignment_e valign;
/** distance between repeated labels on a single geometry */
unsigned label_spacing;
/** distance the label can be moved on the line to fit, if 0 the default is used */
unsigned label_position_tolerance;
bool avoid_edges;
double minimum_distance;
double minimum_padding;
double minimum_path_length;
double max_char_angle_delta;
/** Always try render an odd amount of labels */
bool force_odd_labels;
bool allow_overlap;
unsigned text_ratio;
unsigned wrap_width;
/** Default values for char_properties. */
char_properties default_format;
private:
/** A tree of formating::nodes which contain text and formating information. */
formating::node_ptr tree_;
};
class processed_text : boost::noncopyable
{
public:
class processed_expression
{
public:
processed_expression(char_properties const& properties, UnicodeString const& text) :
p(properties), str(text) {}
char_properties p;
UnicodeString str;
};
public:
processed_text(face_manager<freetype_engine> & font_manager, double scale_factor);
void push_back(char_properties const& properties, UnicodeString const& text);
unsigned size() const { return expr_list_.size(); }
unsigned empty() const { return expr_list_.empty(); }
void clear();
typedef std::list<processed_expression> expression_list;
expression_list::const_iterator begin() const;
expression_list::const_iterator end() const;
string_info &get_string_info();
private:
expression_list expr_list_;
face_manager<freetype_engine> & font_manager_;
double scale_factor_;
string_info info_;
};
/** Generate a possible placement and store results of placement_finder.
* This placement has first to be tested by placement_finder to verify it
* can actually be used.
*/
class text_placement_info : boost::noncopyable
{
public:
/** Constructor. Takes the parent text_placements object as a parameter
* to read defaults from it. */
text_placement_info(text_placements const* parent,
double scale_factor_, dimension_type dim, bool has_dimensions_);
/** Get next placement.
* This function is also called before the first placement is tried.
* Each class has to return at least one position!
* If this functions returns false the placement data should be
* considered invalid!
*/
virtual bool next()=0;
virtual ~text_placement_info() {}
/** Properties actually used by placement finder and renderer. Values in
* here are modified each time next() is called. */
text_symbolizer_properties properties;
/** Scale factor used by the renderer. */
double scale_factor;
/* TODO: Don't know what this is used for. */
bool has_dimensions;
/* TODO: Don't know what this is used for. */
dimension_type dimensions;
/** Set scale factor. */
void set_scale_factor(double factor) { scale_factor = factor; }
/** Get scale factor. */
double get_scale_factor() { return scale_factor; }
/** Get label spacing taking the scale factor into account. */
double get_actual_label_spacing() { return scale_factor * properties.label_spacing; }
/** Get minimum distance taking the scale factor into account. */
double get_actual_minimum_distance() { return scale_factor * properties.minimum_distance; }
/** Get minimum padding taking the scale factor into account. */
double get_actual_minimum_padding() { return scale_factor * properties.minimum_padding; }
/** Collect a bounding box of all texts placed. */
bool collect_extents;
//Output by placement finder
/** Bounding box of all texts placed. */
box2d<double> extents;
/** Additional boxes to take into account when finding placement.
* Used for finding line placements where multiple placements are returned.
* Boxes are relative to starting point of current placement.
*/
std::vector<box2d<double> > additional_boxes;
/* TODO */
std::queue< box2d<double> > envelopes;
/** Used to return all placements found. */
boost::ptr_vector<text_path> placements;
};
typedef boost::shared_ptr<text_placement_info> text_placement_info_ptr;
/** This object handles the management of all TextSymbolizer properties. It can
* be used as a base class for own objects which implement new processing
* semantics. Basically this class just makes sure a pointer of the right
* class is returned by the get_placement_info call.
*/
class text_placements
{
public:
text_placements();
/** Get a text_placement_info object to use in rendering.
* The returned object creates a list of settings which is
* used to try to find a placement and stores all
* information that is generated by
* the placement finder.
*
* This function usually is implemented as
* text_placement_info_ptr text_placements_XXX::get_placement_info() const
* {
* return text_placement_info_ptr(new text_placement_info_XXX(this));
* }
*/
virtual text_placement_info_ptr get_placement_info(
double scale_factor_, dimension_type dim,
bool has_dimensions_) const =0;
/** Get a list of all expressions used in any placement.
* This function is used to collect attributes.
*/
virtual void add_expressions(expression_set &output);
/** Destructor. */
virtual ~text_placements() {}
/** List of all properties used as the default for the subclasses. */
text_symbolizer_properties properties;
};
/** Pointer to object of class text_placements */
typedef boost::shared_ptr<text_placements> text_placements_ptr;
class text_placements_info_dummy;
/** Dummy placement algorithm. Always takes the default value. */
class MAPNIK_DECL text_placements_dummy: public text_placements
{
public:
text_placement_info_ptr get_placement_info(
double scale_factor, dimension_type dim, bool has_dimensions) const;
friend class text_placement_info_dummy;
};
/** Placement info object for dummy placement algorithm. Always takes the default value. */
class MAPNIK_DECL text_placement_info_dummy : public text_placement_info
{
public:
text_placement_info_dummy(text_placements_dummy const* parent,
double scale_factor, dimension_type dim, bool has_dimensions)
: text_placement_info(parent, scale_factor, dim, has_dimensions),
state(0), parent_(parent) {}
bool next();
private:
unsigned state;
text_placements_dummy const* parent_;
};
} //namespace
#endif // MAPNIK_TEXT_PLACEMENTS_HPP

View file

@ -0,0 +1,140 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef PLACEMENTS_BASE_HPP
#define PLACEMENTS_BASE_HPP
// mapnik
#include <mapnik/text_properties.hpp>
#include <mapnik/formating/base.hpp>
#include <mapnik/text_path.hpp> //TODO: Remove this again after text_placement_info::placements is moved to a better place.
// stl
#include <queue>
namespace mapnik
{
typedef std::pair<double,double> dimension_type;
class text_placements;
/** Generate a possible placement and store results of placement_finder.
* This placement has first to be tested by placement_finder to verify it
* can actually be used.
*/
class text_placement_info : boost::noncopyable
{
public:
/** Constructor. Takes the parent text_placements object as a parameter
* to read defaults from it. */
text_placement_info(text_placements const* parent,
double scale_factor_, dimension_type dim, bool has_dimensions_);
/** Get next placement.
* This function is also called before the first placement is tried.
* Each class has to return at least one position!
* If this functions returns false the placement data should be
* considered invalid!
*/
virtual bool next()=0;
virtual ~text_placement_info() {}
/** Properties actually used by placement finder and renderer. Values in
* here are modified each time next() is called. */
text_symbolizer_properties properties;
/** Scale factor used by the renderer. */
double scale_factor;
/* TODO: Don't know what this is used for. */
bool has_dimensions;
/* TODO: Don't know what this is used for. */
dimension_type dimensions;
/** Set scale factor. */
void set_scale_factor(double factor) { scale_factor = factor; }
/** Get scale factor. */
double get_scale_factor() { return scale_factor; }
/** Get label spacing taking the scale factor into account. */
double get_actual_label_spacing() { return scale_factor * properties.label_spacing; }
/** Get minimum distance taking the scale factor into account. */
double get_actual_minimum_distance() { return scale_factor * properties.minimum_distance; }
/** Get minimum padding taking the scale factor into account. */
double get_actual_minimum_padding() { return scale_factor * properties.minimum_padding; }
/** Collect a bounding box of all texts placed. */
bool collect_extents;
//Output by placement finder
/** Bounding box of all texts placed. */
box2d<double> extents;
/** Additional boxes to take into account when finding placement.
* Used for finding line placements where multiple placements are returned.
* Boxes are relative to starting point of current placement.
*/
std::vector<box2d<double> > additional_boxes;
/* TODO */
std::queue< box2d<double> > envelopes;
/** Used to return all placements found. */
boost::ptr_vector<text_path> placements;
};
typedef boost::shared_ptr<text_placement_info> text_placement_info_ptr;
/** This object handles the management of all TextSymbolizer properties. It can
* be used as a base class for own objects which implement new processing
* semantics. Basically this class just makes sure a pointer of the right
* class is returned by the get_placement_info call.
*/
class text_placements
{
public:
text_placements();
/** Get a text_placement_info object to use in rendering.
* The returned object creates a list of settings which is
* used to try to find a placement and stores all
* information that is generated by
* the placement finder.
*
* This function usually is implemented as
* text_placement_info_ptr text_placements_XXX::get_placement_info() const
* {
* return text_placement_info_ptr(new text_placement_info_XXX(this));
* }
*/
virtual text_placement_info_ptr get_placement_info(
double scale_factor_, dimension_type dim,
bool has_dimensions_) const =0;
/** Get a list of all expressions used in any placement.
* This function is used to collect attributes.
*/
virtual void add_expressions(expression_set &output);
/** Destructor. */
virtual ~text_placements() {}
/** List of all properties used as the default for the subclasses. */
text_symbolizer_properties properties;
};
/** Pointer to object of class text_placements */
typedef boost::shared_ptr<text_placements> text_placements_ptr;
} //ns mapnik
#endif // PLACEMENTS_BASE_HPP

View file

@ -0,0 +1,58 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef PLACEMENTS_DUMMY_HPP
#define PLACEMENTS_DUMMY_HPP
#include <mapnik/config.hpp>
#include <mapnik/text_placements/base.hpp>
namespace mapnik
{
class text_placements_info_dummy;
/** Dummy placement algorithm. Always takes the default value. */
class MAPNIK_DECL text_placements_dummy: public text_placements
{
public:
text_placement_info_ptr get_placement_info(
double scale_factor, dimension_type dim, bool has_dimensions) const;
friend class text_placement_info_dummy;
};
/** Placement info object for dummy placement algorithm. Always takes the default value. */
class MAPNIK_DECL text_placement_info_dummy : public text_placement_info
{
public:
text_placement_info_dummy(text_placements_dummy const* parent,
double scale_factor, dimension_type dim, bool has_dimensions)
: text_placement_info(parent, scale_factor, dim, has_dimensions),
state(0), parent_(parent) {}
bool next();
private:
unsigned state;
text_placements_dummy const* parent_;
};
} //ns mapnik
#endif // PLACEMENTS_DUMMY_HPP

View file

@ -21,7 +21,7 @@
*****************************************************************************/
#ifndef TEXT_PLACEMENTS_LIST_HPP
#define TEXT_PLACEMENTS_LIST_HPP
#include <mapnik/text_placements.hpp>
#include <mapnik/text_placements/base.hpp>
namespace mapnik {

View file

@ -24,7 +24,7 @@
#define MAPNIK_TEXT_PLACEMENTS_SIMPLE_HPP
// mapnik
#include <mapnik/text_placements.hpp>
#include <mapnik/text_placements/base.hpp>
namespace mapnik {

View file

@ -1,172 +0,0 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2011 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MAPNIK_TEXT_PROCESSING_HPP
#define MAPNIK_TEXT_PROCESSING_HPP
#include <boost/property_tree/ptree.hpp>
#include <boost/optional.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/box2d.hpp>
#include <mapnik/ctrans.hpp>
#include <mapnik/label_collision_detector.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/text_path.hpp>
#include <mapnik/enumeration.hpp>
#include <mapnik/filter_factory.hpp>
#include <list>
#include <vector>
#include <set>
namespace mapnik
{
class processed_text;
struct char_properties;
typedef std::set<expression_ptr> expression_set;
enum label_placement_enum {
POINT_PLACEMENT,
LINE_PLACEMENT,
VERTEX_PLACEMENT,
INTERIOR_PLACEMENT,
label_placement_enum_MAX
};
DEFINE_ENUM( label_placement_e, label_placement_enum );
enum vertical_alignment
{
V_TOP = 0,
V_MIDDLE,
V_BOTTOM,
V_AUTO,
vertical_alignment_MAX
};
DEFINE_ENUM( vertical_alignment_e, vertical_alignment );
enum horizontal_alignment
{
H_LEFT = 0,
H_MIDDLE,
H_RIGHT,
H_AUTO,
horizontal_alignment_MAX
};
DEFINE_ENUM( horizontal_alignment_e, horizontal_alignment );
enum justify_alignment
{
J_LEFT = 0,
J_MIDDLE,
J_RIGHT,
justify_alignment_MAX
};
DEFINE_ENUM( justify_alignment_e, justify_alignment );
enum text_transform
{
NONE = 0,
UPPERCASE,
LOWERCASE,
CAPITALIZE,
text_transform_MAX
};
DEFINE_ENUM( text_transform_e, text_transform );
namespace formating {
class node;
typedef boost::shared_ptr<node> node_ptr;
class node
{
public:
virtual ~node() {}
virtual void to_xml(boost::property_tree::ptree &xml) const;
static node_ptr from_xml(boost::property_tree::ptree const& xml);
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const = 0;
virtual void add_expressions(expression_set &output) const;
};
class list_node: public node {
public:
list_node() : node(), children_() {}
virtual void to_xml(boost::property_tree::ptree &xml) const;
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const;
virtual void add_expressions(expression_set &output) const;
void push_back(node_ptr n);
void set_children(std::vector<node_ptr> const& children);
std::vector<node_ptr> const& get_children() const;
void clear();
private:
std::vector<node_ptr> children_;
};
class text_node: public node {
public:
text_node(expression_ptr text): node(), text_(text) {}
text_node(std::string text): node(), text_(parse_expression(text)) {}
void to_xml(boost::property_tree::ptree &xml) const;
static node_ptr from_xml(boost::property_tree::ptree const& xml);
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const;
virtual void add_expressions(expression_set &output) const;
void set_text(expression_ptr text);
expression_ptr get_text() const;
private:
expression_ptr text_;
};
class format_node: public node {
public:
void to_xml(boost::property_tree::ptree &xml) const;
static node_ptr from_xml(boost::property_tree::ptree const& xml);
virtual void apply(char_properties const& p, Feature const& feature, processed_text &output) const;
virtual void add_expressions(expression_set &output) const;
void set_child(node_ptr child);
node_ptr get_child() const;
boost::optional<std::string> face_name;
boost::optional<unsigned> text_size;
boost::optional<unsigned> character_spacing;
boost::optional<unsigned> line_spacing;
boost::optional<double> text_opacity;
boost::optional<bool> wrap_before;
boost::optional<unsigned> wrap_char;
boost::optional<text_transform_e> text_transform;
boost::optional<color> fill;
boost::optional<color> halo_fill;
boost::optional<double> halo_radius;
private:
node_ptr child_;
};
} //namespace formating
} /* namespace mapnik*/
#endif

View file

@ -0,0 +1,173 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef TEXT_PROPERTIES_HPP
#define TEXT_PROPERTIES_HPP
// mapnik
#include <mapnik/color.hpp>
#include <mapnik/font_set.hpp>
#include <mapnik/enumeration.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/formating/base.hpp>
// stl
#include <map>
// boost
#include <boost/property_tree/ptree.hpp>
namespace mapnik
{
enum text_transform
{
NONE = 0,
UPPERCASE,
LOWERCASE,
CAPITALIZE,
text_transform_MAX
};
DEFINE_ENUM(text_transform_e, text_transform);
struct char_properties
{
char_properties();
/** Construct object from XML. */
void from_xml(boost::property_tree::ptree const &sym, std::map<std::string,font_set> 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;
std::string face_name;
font_set fontset;
float text_size;
double character_spacing;
double line_spacing; //Largest total height (fontsize+line_spacing) per line is chosen
double text_opacity;
bool wrap_before;
unsigned wrap_char;
text_transform_e text_transform; //Per expression
color fill;
color halo_fill;
double halo_radius;
};
enum label_placement_enum
{
POINT_PLACEMENT,
LINE_PLACEMENT,
VERTEX_PLACEMENT,
INTERIOR_PLACEMENT,
label_placement_enum_MAX
};
DEFINE_ENUM(label_placement_e, label_placement_enum);
enum vertical_alignment
{
V_TOP = 0,
V_MIDDLE,
V_BOTTOM,
V_AUTO,
vertical_alignment_MAX
};
DEFINE_ENUM(vertical_alignment_e, vertical_alignment);
enum horizontal_alignment
{
H_LEFT = 0,
H_MIDDLE,
H_RIGHT,
H_AUTO,
horizontal_alignment_MAX
};
DEFINE_ENUM(horizontal_alignment_e, horizontal_alignment);
enum justify_alignment
{
J_LEFT = 0,
J_MIDDLE,
J_RIGHT,
justify_alignment_MAX
};
DEFINE_ENUM(justify_alignment_e, justify_alignment);
typedef std::pair<double, double> position;
class processed_text;
/** Contains all text symbolizer properties which are not directly related to text formating. */
struct text_symbolizer_properties
{
text_symbolizer_properties();
/** Load all values from XML ptree. */
void from_xml(boost::property_tree::ptree const &sym, std::map<std::string,font_set> const & fontsets);
/** Save all values to XML ptree (but does not create a new parent node!). */
void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, text_symbolizer_properties const &dfl=text_symbolizer_properties()) const;
/** Takes a feature and produces formated text as output.
* The output object has to be created by the caller and passed in for thread safety.
*/
void process(processed_text &output, Feature const& feature) const;
/** Automatically create processing instructions for a single expression. */
void set_old_style_expression(expression_ptr expr);
/** Sets new format tree. */
void set_format_tree(formating::node_ptr tree);
/** Get format tree. */
formating::node_ptr format_tree() const;
/** Get a list of all expressions used in any placement.
* This function is used to collect attributes. */
void add_expressions(expression_set &output) const;
//Per symbolizer options
expression_ptr orientation;
position displacement;
label_placement_e label_placement;
horizontal_alignment_e halign;
justify_alignment_e jalign;
vertical_alignment_e valign;
/** distance between repeated labels on a single geometry */
unsigned label_spacing;
/** distance the label can be moved on the line to fit, if 0 the default is used */
unsigned label_position_tolerance;
bool avoid_edges;
double minimum_distance;
double minimum_padding;
double minimum_path_length;
double max_char_angle_delta;
/** Always try render an odd amount of labels */
bool force_odd_labels;
bool allow_overlap;
unsigned text_ratio;
unsigned wrap_width;
/** Default values for char_properties. */
char_properties default_format;
private:
/** A tree of formating::nodes which contain text and formating information. */
formating::node_ptr tree_;
};
} //ns mapnik
#endif // TEXT_PROPERTIES_HPP

View file

@ -27,7 +27,8 @@
#include <mapnik/color.hpp>
#include <mapnik/font_set.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/text_placements.hpp>
#include <mapnik/text_placements/base.hpp>
#include <mapnik/text_placements/dummy.hpp>
// boost
#include <boost/shared_ptr.hpp>

View file

@ -109,7 +109,7 @@ source = Split(
datasource_cache.cpp
deepcopy.cpp
expression_string.cpp
filter_factory.cpp
expression.cpp
feature_kv_iterator.cpp
feature_type_style.cpp
font_engine_freetype.cpp

View file

@ -28,7 +28,6 @@
#include <mapnik/rule.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/params.hpp>
#include <mapnik/filter_factory.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/util/deepcopy.hpp>

View file

@ -21,7 +21,7 @@
*****************************************************************************/
//$Id$
#include <mapnik/filter_factory.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/expression_grammar.hpp>
#include <mapnik/config_error.hpp>
#include <mapnik/unicode.hpp>
@ -32,7 +32,7 @@
namespace mapnik
{
class filter_factory
class expression_factory
{
public:
static expression_ptr compile(std::string const& str,transcoder const& tr)
@ -58,7 +58,7 @@ public:
expression_ptr parse_expression (std::string const& wkt,std::string const& encoding)
{
transcoder tr(encoding);
return filter_factory::compile(wkt,tr);
return expression_factory::compile(wkt,tr);
}
expression_ptr parse_expression (std::string const& wkt)

View file

@ -22,7 +22,7 @@
// mapnik
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/text_placements.hpp>
#include <mapnik/text_properties.hpp>
#include <mapnik/graphics.hpp>
#include <mapnik/grid/grid.hpp>

View file

@ -39,7 +39,7 @@
#include <mapnik/libxml2_loader.hpp>
#endif
#include <mapnik/filter_factory.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/parse_path.hpp>
#include <mapnik/raster_colorizer.hpp>
@ -47,9 +47,9 @@
#include <mapnik/metawriter_factory.hpp>
#include <mapnik/text_placements_simple.hpp>
#include <mapnik/text_placements_list.hpp>
#include <mapnik/text_processing.hpp>
#include <mapnik/text_placements/simple.hpp>
#include <mapnik/text_placements/list.hpp>
#include <mapnik/text_placements/dummy.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/rule.hpp>

View file

@ -23,7 +23,7 @@
// Mapnik
#include <mapnik/metawriter.hpp>
#include <mapnik/metawriter_json.hpp>
#include <mapnik/text_placements.hpp>
#include <mapnik/text_placements/base.hpp>
// Boost
#include <boost/foreach.hpp>

View file

@ -24,6 +24,7 @@
#include <mapnik/metawriter.hpp>
#include <mapnik/metawriter_inmem.hpp>
#include <mapnik/placement_finder.hpp>
#include <mapnik/text_placements/base.hpp>
// Boost
#include <boost/foreach.hpp>

View file

@ -28,6 +28,8 @@
#include <mapnik/text_path.hpp>
#include <mapnik/label_collision_detector.hpp>
#include <mapnik/fastmath.hpp>
#include <mapnik/text_placements/base.hpp>
#include <mapnik/ctrans.hpp>
// agg
#include "agg_path_length.h"

View file

@ -28,8 +28,9 @@
#include <mapnik/expression_string.hpp>
#include <mapnik/raster_colorizer.hpp>
#include <mapnik/metawriter_factory.hpp>
#include <mapnik/text_placements_simple.hpp>
#include <mapnik/text_placements_list.hpp>
#include <mapnik/text_placements/simple.hpp>
#include <mapnik/text_placements/list.hpp>
#include <mapnik/text_placements/dummy.hpp>
// boost
#include <boost/algorithm/string.hpp>

View file

@ -1,4 +1,5 @@
#include <mapnik/symbolizer_helpers.hpp>
#include <mapnik/label_collision_detector.hpp>
namespace mapnik {

View file

@ -20,12 +20,13 @@
*
*****************************************************************************/
#include <mapnik/text_placements.hpp>
#include <mapnik/text_placements_simple.hpp>
#include <mapnik/text_placements_list.hpp>
#include <mapnik/text_placements/simple.hpp>
#include <mapnik/text_placements/list.hpp>
#include <mapnik/text_placements/dummy.hpp>
#include <mapnik/expression_string.hpp>
#include <mapnik/text_processing.hpp>
#include <mapnik/ptree_helpers.hpp>
#include <mapnik/formating/text.hpp>
#include <mapnik/processed_text.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/spirit/include/qi.hpp>

View file

@ -19,12 +19,13 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#include <mapnik/text_processing.hpp>
#include <mapnik/text_placements.hpp>
#include <mapnik/formating/text.hpp>
#include <mapnik/formating/list.hpp>
#include <mapnik/formating/format.hpp>
#include <mapnik/processed_text.hpp>
#include <mapnik/color.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/expression_evaluator.hpp>
#include <mapnik/filter_factory.hpp>
#include <mapnik/expression_string.hpp>
#include <mapnik/ptree_helpers.hpp>

View file

@ -20,13 +20,14 @@
*
*****************************************************************************/
//$Id$
//mapnik
#include <mapnik/text_symbolizer.hpp>
#include <mapnik/enumeration.hpp>
// boost
#include <boost/scoped_ptr.hpp>
#include <mapnik/text_processing.hpp>
namespace mapnik
{

View file

@ -14,7 +14,7 @@
#include <mapnik/svg_renderer.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/filter_factory.hpp>
#include <mapnik/expression.hpp>
#include <mapnik/color_factory.hpp>
// stl