diff --git a/bindings/python/mapnik_text_placement.cpp b/bindings/python/mapnik_text_placement.cpp index 31a232df7..34ba44aa0 100644 --- a/bindings/python/mapnik_text_placement.cpp +++ b/bindings/python/mapnik_text_placement.cpp @@ -26,6 +26,7 @@ #include #include #include "mapnik_threads.hpp" +#include "python_optional.hpp" using namespace mapnik; @@ -390,26 +391,26 @@ void export_text_placement() register_ptr_to_python >(); - class_, bases, boost::noncopyable> ("FormatingFormatNode") + .def_readwrite_optional("text_size", &formating::format_node::text_size) + .def_readwrite_optional("face_name", &formating::format_node::face_name) + .def_readwrite_optional("character_spacing", &formating::format_node::character_spacing) + .def_readwrite_optional("line_spacing", &formating::format_node::line_spacing) + .def_readwrite_optional("text_opacity", &formating::format_node::text_opacity) + .def_readwrite_optional("wrap_char", &formating::format_node::wrap_char) + .def_readwrite_optional("wrap_before", &formating::format_node::wrap_before) + .def_readwrite_optional("text_transform", &formating::format_node::text_transform) + .def_readwrite_optional("fill", &formating::format_node::fill) + .def_readwrite_optional("halo_fill", &formating::format_node::halo_fill) + .def_readwrite_optional("halo_radius", &formating::format_node::halo_radius) .def("apply", &formating::format_node::apply, &FormatNodeWrap::default_apply) .add_property("child", &formating::format_node::get_child, &formating::format_node::set_child) - .def_readwrite("face_name", &formating::format_node::face_name) - .def_readwrite("text_size", &formating::format_node::text_size) - .def_readwrite("character_spacing", &formating::format_node::character_spacing) - .def_readwrite("line_spacing", &formating::format_node::line_spacing) - .def_readwrite("text_opacity", &formating::format_node::text_opacity) - .def_readwrite("wrap_char", &formating::format_node::wrap_char) - .def_readwrite("wrap_before", &formating::format_node::wrap_before) - .def_readwrite("text_transform", &formating::format_node::text_transform) - .def_readwrite("fill", &formating::format_node::fill) - .def_readwrite("halo_fill", &formating::format_node::halo_fill) - .def_readwrite("halo_radius", &formating::format_node::halo_radius) ; register_ptr_to_python >(); } diff --git a/bindings/python/python_optional.hpp b/bindings/python/python_optional.hpp index 0bcdf5430..99a5587a7 100644 --- a/bindings/python/python_optional.hpp +++ b/bindings/python/python_optional.hpp @@ -100,3 +100,39 @@ struct python_optional : public boost::noncopyable } }; +/** This class works around a bug in boost python. + + See http://osdir.com/ml/python.c++/2003-11/msg00158.html + */ +template +class class_with_optional : public boost::python::class_ +{ +public: + typedef class_with_optional self; + // Construct with the class name, with or without docstring, and default __init__() function + class_with_optional(char const* name, char const* doc = 0) : boost::python::class_(name, doc) { } + + // Construct with class name, no docstring, and an uncallable __init__ function + class_with_optional(char const* name, boost::python::no_init_t y) : boost::python::class_(name, y) { } + + // Construct with class name, docstring, and an uncallable __init__ function + class_with_optional(char const* name, char const* doc, boost::python::no_init_t y) : boost::python::class_(name, doc, y) { } + + // Construct with class name and init<> function + template class_with_optional(char const* name, boost::python::init_base const& i) + : boost::python::class_(name, i) { } + + // Construct with class name, docstring and init<> function + template + inline class_with_optional(char const* name, char const* doc, boost::python::init_base const& i) + : boost::python::class_(name, doc, i) { } + + template + self& def_readwrite_optional(char const* name, D const& d, char const* doc=0) + { + this->add_property(name, + make_getter(d, boost::python::return_value_policy()), + make_setter(d, boost::python::default_call_policies())); + return *this; + } +};