diff --git a/bindings/python/mapnik_text_symbolizer.cpp b/bindings/python/mapnik_text_symbolizer.cpp index 00c8d8e5d..69d793ba7 100644 --- a/bindings/python/mapnik_text_symbolizer.cpp +++ b/bindings/python/mapnik_text_symbolizer.cpp @@ -59,6 +59,16 @@ void set_anchor(text_symbolizer & t, boost::python::tuple arg) t.set_anchor(extract(arg[0]),extract(arg[1])); } +void set_placement_options(text_symbolizer & t, placement_type_e arg, std::string const& placements) +{ + t.set_placement_options(arg, placements); +} + +void set_placement_options_2(text_symbolizer & t, placement_type_e arg) +{ + t.set_placement_options(arg, ""); +} + } struct text_symbolizer_pickle_suite : boost::python::pickle_suite @@ -195,6 +205,11 @@ void export_text_symbolizer() .value("CAPITALIZE",CAPITALIZE) ; + enumeration_("placement_type") + .value("SIMPLE",T_SIMPLE) + .value("DUMMY",T_DUMMY) + ; + class_("TextSymbolizer",init()) /* // todo - all python classes can have kwargs and default constructors @@ -287,6 +302,10 @@ void export_text_symbolizer() &text_symbolizer::get_text_opacity, &text_symbolizer::set_text_opacity, "Set/get the text opacity") + .add_property("placement", + &text_symbolizer::get_label_placement, + &text_symbolizer::set_label_placement, + "Set/get the placement of the label") .add_property("text_transform", &text_symbolizer::get_text_transform, &text_symbolizer::set_text_transform, @@ -310,5 +329,9 @@ void export_text_symbolizer() .add_property("wrap_before", &text_symbolizer::get_wrap_before, &text_symbolizer::set_wrap_before) + .add_property("placement_type", &text_symbolizer::get_placement_type) + .add_property("placements", &text_symbolizer::get_placements) + .def("set_placement_options", set_placement_options) + .def("set_placement_options", set_placement_options_2) ; } diff --git a/include/mapnik/text_placements.hpp b/include/mapnik/text_placements.hpp index 383bbcb33..7921031c0 100644 --- a/include/mapnik/text_placements.hpp +++ b/include/mapnik/text_placements.hpp @@ -93,6 +93,15 @@ enum text_transform DEFINE_ENUM( text_transform_e, text_transform ); +enum placement_type +{ + T_SIMPLE = 0, + T_DUMMY, + placement_type_MAX +}; + +DEFINE_ENUM( placement_type_e, placement_type ); + class text_placements; class text_placement_info : boost::noncopyable diff --git a/include/mapnik/text_placements_simple.hpp b/include/mapnik/text_placements_simple.hpp index fe0e541ca..9a52825e8 100644 --- a/include/mapnik/text_placements_simple.hpp +++ b/include/mapnik/text_placements_simple.hpp @@ -51,6 +51,7 @@ public: text_placements_simple(std::string positions); text_placement_info_ptr get_placement_info() const; void set_positions(std::string positions); + std::string get_positions() const; private: std::string positions_; std::vector direction_; diff --git a/include/mapnik/text_symbolizer.hpp b/include/mapnik/text_symbolizer.hpp index d6c023499..03beb5b04 100644 --- a/include/mapnik/text_symbolizer.hpp +++ b/include/mapnik/text_symbolizer.hpp @@ -123,6 +123,9 @@ struct MAPNIK_DECL text_symbolizer : public symbolizer_base justify_alignment_e get_justify_alignment() const; text_placements_ptr get_placement_options() const; void set_placement_options(text_placements_ptr placement_options); + void set_placement_options(placement_type_e arg, std::string const& placements); + placement_type_e get_placement_type() const; + std::string get_placements() const; private: expression_ptr name_; diff --git a/src/text_placements.cpp b/src/text_placements.cpp index aca06a5ac..9ed8b20b2 100644 --- a/src/text_placements.cpp +++ b/src/text_placements.cpp @@ -187,6 +187,11 @@ text_placements_simple::text_placements_simple() set_positions("X"); } +std::string text_placements_simple::get_positions() const +{ + return positions_; +} + text_placements_simple::text_placements_simple(std::string positions) { set_positions(positions); diff --git a/src/text_symbolizer.cpp b/src/text_symbolizer.cpp index 00a91401d..2b43527e2 100644 --- a/src/text_symbolizer.cpp +++ b/src/text_symbolizer.cpp @@ -22,8 +22,13 @@ //$Id$ +#include + //mapnik #include +#include +#include + // boost #include @@ -85,6 +90,15 @@ static const char * text_transform_strings[] = { IMPLEMENT_ENUM( text_transform_e, text_transform_strings ) +static const char * placement_type_strings[] = { + "dummy", + "simple", + "" +}; + + +IMPLEMENT_ENUM( placement_type_e, placement_type_strings ) + text_symbolizer::text_symbolizer(expression_ptr name, std::string const& face_name, float size, color const& fill, @@ -553,5 +567,47 @@ void text_symbolizer::set_placement_options(text_placements_ptr placement_option placement_options_ = placement_options; } +void text_symbolizer::set_placement_options(placement_type_e arg, std::string const& placements) +{ + text_placements_ptr placement_finder; + switch (arg) + { + case T_SIMPLE: + placement_finder = text_placements_ptr( + new text_placements_simple(placements)); + break; + + case T_DUMMY: + placement_finder = text_placements_ptr(new text_placements_dummy()); + break; + + default: + throw config_error(std::string("Unknown placement type")); + break; + } + this->set_placement_options(placement_finder); +} + +placement_type_e text_symbolizer::get_placement_type() const +{ + text_placements_ptr placement_finder = this->get_placement_options(); + if (dynamic_cast(placement_finder.get()) != NULL) + { + return T_SIMPLE; + } + return T_DUMMY; +} + +std::string text_symbolizer::get_placements() const +{ + text_placements_ptr placement_finder = this->get_placement_options(); + text_placements_simple *placements_simple = dynamic_cast(placement_finder.get()); + + if (placements_simple != NULL) + { + return placements_simple->get_positions(); + } + return ""; +} }