From e897b832a4dd92c5de4e969cbb7cf112385ea3f6 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 17 Aug 2009 22:54:50 +0000 Subject: [PATCH] +reflect new text symbolizer options added in r1254 - closes #391 --- bindings/python/mapnik_text_symbolizer.cpp | 201 ++++++++++++--------- include/mapnik/text_symbolizer.hpp | 2 + src/text_symbolizer.cpp | 10 + tests/python_tests/object_test.py | 6 + 4 files changed, 133 insertions(+), 86 deletions(-) diff --git a/bindings/python/mapnik_text_symbolizer.cpp b/bindings/python/mapnik_text_symbolizer.cpp index ef207a272..66df793a8 100644 --- a/bindings/python/mapnik_text_symbolizer.cpp +++ b/bindings/python/mapnik_text_symbolizer.cpp @@ -71,11 +71,20 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite { boost::python::list disp = get_displacement_list(t); boost::python::list anchor = get_anchor_list(t); + + // so we do not exceed max args accepted by make_tuple, + // lets put the increasing list of parameters in a list + boost::python::list extras; + extras.append(t.get_wrap_char()); + extras.append(t.get_line_spacing()); + extras.append(t.get_character_spacing()); + extras.append(t.get_text_convert()); return boost::python::make_tuple(disp,t.get_fontset().get_name(),t.get_label_placement(), t.get_vertical_alignment(),t.get_halo_radius(),t.get_halo_fill(),t.get_text_ratio(), t.get_wrap_width(),t.get_label_spacing(),t.get_minimum_distance(),t.get_allow_overlap(), - anchor,t.get_force_odd_labels(),t.get_max_char_angle_delta()); + anchor,t.get_force_odd_labels(),t.get_max_char_angle_delta(),extras + ); } static void @@ -83,10 +92,10 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite { using namespace boost::python; - if (len(state) != 14) + if (len(state) != 15) { PyErr_SetObject(PyExc_ValueError, - ("expected 14-item tuple in call to __setstate__; got %s" + ("expected 15-item tuple in call to __setstate__; got %s" % state).ptr() ); throw_error_already_set(); @@ -129,6 +138,13 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite t.set_force_odd_labels(extract(state[12])); t.set_max_char_angle_delta(extract(state[13])); + + list extras = extract(state[14]); + t.set_wrap_char_from_string(extract(extras[0])); + t.set_line_spacing(extract(extras[1])); + t.set_character_spacing(extract(extras[2])); + t.set_text_convert(extract(extras[3])); + } }; @@ -136,89 +152,102 @@ struct text_symbolizer_pickle_suite : boost::python::pickle_suite void export_text_symbolizer() { - using namespace boost::python; - - enumeration_("label_placement") - .value("LINE_PLACEMENT",LINE_PLACEMENT) - .value("POINT_PLACEMENT",POINT_PLACEMENT) - ; - enumeration_("vertical_alignment") - .value("TOP",TOP) - .value("MIDDLE",MIDDLE) - .value("BOTTOM",BOTTOM) - ; - - class_("TextSymbolizer", - init()) - .def_pickle(text_symbolizer_pickle_suite()) - .add_property("halo_fill",make_function( - &text_symbolizer::get_halo_fill, - return_value_policy()), - &text_symbolizer::set_halo_fill) - .add_property("halo_radius", - &text_symbolizer::get_halo_radius, - &text_symbolizer::set_halo_radius) - .add_property("wrap_width", - &text_symbolizer::get_wrap_width, - &text_symbolizer::set_wrap_width) - .add_property("text_ratio", - &text_symbolizer::get_text_ratio, - &text_symbolizer::set_text_ratio) - .add_property("label_spacing", - &text_symbolizer::get_label_spacing, - &text_symbolizer::set_label_spacing) - .add_property("label_position_tolerance", - &text_symbolizer::get_label_position_tolerance, - &text_symbolizer::set_label_position_tolerance) - .add_property("force_odd_labels", - &text_symbolizer::get_force_odd_labels, - &text_symbolizer::set_force_odd_labels) +using namespace boost::python; - .add_property("fontset", - make_function(&text_symbolizer::get_fontset,return_value_policy()), - &text_symbolizer::set_fontset) + enumeration_("label_placement") + .value("LINE_PLACEMENT",LINE_PLACEMENT) + .value("POINT_PLACEMENT",POINT_PLACEMENT) + ; + enumeration_("vertical_alignment") + .value("TOP",TOP) + .value("MIDDLE",MIDDLE) + .value("BOTTOM",BOTTOM) + ; + + enumeration_("text_convert") + .value("NONE",NONE) + .value("TOUPPER",TOUPPER) + .value("TOLOWER",TOLOWER) + ; - .add_property("fill", - make_function(&text_symbolizer::get_fill,return_value_policy()), - &text_symbolizer::set_fill) - .add_property("name", - make_function(&text_symbolizer::get_name,return_value_policy()), - &text_symbolizer::set_name) - - .add_property("text_size", - &text_symbolizer::get_text_size, - &text_symbolizer::set_text_size) - - .add_property("face_name", - make_function(&text_symbolizer::get_face_name,return_value_policy()), - &text_symbolizer::set_face_name) - - .add_property("max_char_angle_delta", - &text_symbolizer::get_max_char_angle_delta, - &text_symbolizer::set_max_char_angle_delta) - .add_property("avoid_edges", - &text_symbolizer::get_avoid_edges, - &text_symbolizer::set_avoid_edges) - .add_property("minimum_distance", - &text_symbolizer::get_minimum_distance, - &text_symbolizer::set_minimum_distance) - .def("displacement",&text_symbolizer::set_displacement) - .def("anchor",&text_symbolizer::set_anchor) - .def("get_displacement",get_displacement_list) - .def("get_anchor",get_anchor_list) - .add_property("label_placement", - &text_symbolizer::get_label_placement, - &text_symbolizer::set_label_placement, - "Set/get the placement of the label") - - .add_property("vertical_alignment", - &text_symbolizer::get_vertical_alignment, - &text_symbolizer::set_vertical_alignment, - "Set/get the vertical alignment of the label") - - .add_property("allow_overlap", - &text_symbolizer::get_allow_overlap, - &text_symbolizer::set_allow_overlap, - "Set/get the allow_overlap property of the label") - ; +class_("TextSymbolizer",init()) + .def_pickle(text_symbolizer_pickle_suite()) + .def("anchor",&text_symbolizer::set_anchor) + .def("displacement",&text_symbolizer::set_displacement) + .def("get_anchor",get_anchor_list) + .def("get_displacement",get_displacement_list) + .add_property("allow_overlap", + &text_symbolizer::get_allow_overlap, + &text_symbolizer::set_allow_overlap, + "Set/get the allow_overlap property of the label") + .add_property("avoid_edges", + &text_symbolizer::get_avoid_edges, + &text_symbolizer::set_avoid_edges, + "Set/get the avoid_edge property of the label") + .add_property("character_spacing", + &text_symbolizer::get_character_spacing, + &text_symbolizer::set_character_spacing, + "Set/get the character_spacing property of the label") + .add_property("face_name", + make_function(&text_symbolizer::get_face_name,return_value_policy()), + &text_symbolizer::set_face_name, + "Set/get the face_name property of the label") + .add_property("fill", + make_function(&text_symbolizer::get_fill,return_value_policy()), + &text_symbolizer::set_fill) + .add_property("fontset", + make_function(&text_symbolizer::get_fontset,return_value_policy()), + &text_symbolizer::set_fontset) + .add_property("force_odd_labels", + &text_symbolizer::get_force_odd_labels, + &text_symbolizer::set_force_odd_labels) + .add_property("halo_fill", + make_function(&text_symbolizer::get_halo_fill,return_value_policy()), + &text_symbolizer::set_halo_fill) + .add_property("halo_radius", + &text_symbolizer::get_halo_radius, + &text_symbolizer::set_halo_radius) + .add_property("label_placement", + &text_symbolizer::get_label_placement, + &text_symbolizer::set_label_placement, + "Set/get the placement of the label") + .add_property("label_position_tolerance", + &text_symbolizer::get_label_position_tolerance, + &text_symbolizer::set_label_position_tolerance) + .add_property("label_spacing", + &text_symbolizer::get_label_spacing, + &text_symbolizer::set_label_spacing) + .add_property("line_spacing", + &text_symbolizer::get_line_spacing, + &text_symbolizer::set_line_spacing) + .add_property("max_char_angle_delta", + &text_symbolizer::get_max_char_angle_delta, + &text_symbolizer::set_max_char_angle_delta) + .add_property("minimum_distance", + &text_symbolizer::get_minimum_distance, + &text_symbolizer::set_minimum_distance) + .add_property("name", + make_function(&text_symbolizer::get_name,return_value_policy()), + &text_symbolizer::set_name) + .add_property("text_convert", + &text_symbolizer::get_text_convert, + &text_symbolizer::set_text_convert, + "Set/get the text conversion method") + .add_property("text_ratio", + &text_symbolizer::get_text_ratio, + &text_symbolizer::set_text_ratio) + .add_property("text_size", + &text_symbolizer::get_text_size, + &text_symbolizer::set_text_size) + .add_property("vertical_alignment", + &text_symbolizer::get_vertical_alignment, + &text_symbolizer::set_vertical_alignment, + "Set/get the vertical alignment of the label") + .add_property("wrap_width", + &text_symbolizer::get_wrap_width, + &text_symbolizer::set_wrap_width) + .add_property("wrap_character", + make_function(&text_symbolizer::get_wrap_char_string,return_value_policy()), + &text_symbolizer::set_wrap_char_from_string) + ; } diff --git a/include/mapnik/text_symbolizer.hpp b/include/mapnik/text_symbolizer.hpp index b24fabc95..65b9fee11 100644 --- a/include/mapnik/text_symbolizer.hpp +++ b/include/mapnik/text_symbolizer.hpp @@ -81,7 +81,9 @@ namespace mapnik unsigned get_wrap_width() const; // width to wrap text at, or trigger ratio void set_wrap_width(unsigned ratio); unsigned char get_wrap_char() const; // character used to wrap lines + std::string const& get_wrap_char_string() const; // character used to wrap lines as std::string void set_wrap_char(unsigned char character); + void set_wrap_char_from_string(std::string character); text_convert_e get_text_convert() const; // text conversion on strings before display void set_text_convert(text_convert_e convert); unsigned get_line_spacing() const; // spacing between lines of text diff --git a/src/text_symbolizer.cpp b/src/text_symbolizer.cpp index 3547f5a67..990bd8751 100644 --- a/src/text_symbolizer.cpp +++ b/src/text_symbolizer.cpp @@ -223,11 +223,21 @@ namespace mapnik return wrap_char_; } + std::string const& text_symbolizer::get_wrap_char_string() const + { + return std::string(1, wrap_char_); + } + void text_symbolizer::set_wrap_char(unsigned char character) { wrap_char_ = character; } + void text_symbolizer::set_wrap_char_from_string(std::string character) + { + wrap_char_ = (character)[0]; + } + text_convert_e text_symbolizer::get_text_convert() const { return text_convert_; diff --git a/tests/python_tests/object_test.py b/tests/python_tests/object_test.py index e0f2f4ace..1d997d28e 100644 --- a/tests/python_tests/object_test.py +++ b/tests/python_tests/object_test.py @@ -203,6 +203,12 @@ def test_textsymbolizer_pickle(): eq_(ts.vertical_alignment, ts2.vertical_alignment) eq_(ts.label_spacing, ts2.label_spacing) eq_(ts.label_position_tolerance, ts2.label_position_tolerance) + + eq_(ts.wrap_character, ts2.wrap_character) + eq_(ts.text_convert, ts2.text_convert) + eq_(ts.line_spacing, ts2.line_spacing) + eq_(ts.character_spacing, ts2.character_spacing) + eq_(ts.fontset, ts2.fontset)