diff --git a/bindings/python/mapnik_text_placement.cpp b/bindings/python/mapnik_text_placement.cpp index c9f1ac4e5..13de8478b 100644 --- a/bindings/python/mapnik_text_placement.cpp +++ b/bindings/python/mapnik_text_placement.cpp @@ -329,6 +329,7 @@ void export_text_placement() .value("LEFT",J_LEFT) .value("MIDDLE",J_MIDDLE) .value("RIGHT",J_RIGHT) + .value("AUTO", J_AUTO) ; enumeration_("text_transform") diff --git a/include/mapnik/placement_finder.hpp b/include/mapnik/placement_finder.hpp index 1ee636349..57d6ee2ab 100644 --- a/include/mapnik/placement_finder.hpp +++ b/include/mapnik/placement_finder.hpp @@ -137,6 +137,7 @@ private: double first_line_space_; vertical_alignment_e valign_; horizontal_alignment_e halign_; + justify_alignment_e jalign_; std::vector line_breaks_; std::vector > line_sizes_; std::queue< box2d > envelopes_; diff --git a/include/mapnik/text_properties.hpp b/include/mapnik/text_properties.hpp index 9f12b3663..7b6ab953a 100644 --- a/include/mapnik/text_properties.hpp +++ b/include/mapnik/text_properties.hpp @@ -110,6 +110,7 @@ enum justify_alignment J_LEFT = 0, J_MIDDLE, J_RIGHT, + J_AUTO, justify_alignment_MAX }; diff --git a/src/placement_finder.cpp b/src/placement_finder.cpp index 719b56dee..5419cb8b6 100644 --- a/src/placement_finder.cpp +++ b/src/placement_finder.cpp @@ -305,23 +305,47 @@ template void placement_finder::init_alignment() { valign_ = p.valign; - if (valign_ == V_AUTO) { + if (valign_ == V_AUTO) + { if (p.displacement.second > 0.0) + { valign_ = V_BOTTOM; - else if (p.displacement.second < 0.0) + } else if (p.displacement.second < 0.0) + { valign_ = V_TOP; - else + } else + { valign_ = V_MIDDLE; + } } halign_ = p.halign; - if (halign_ == H_AUTO) { + if (halign_ == H_AUTO) + { if (p.displacement.first > 0.0) + { halign_ = H_RIGHT; - else if (p.displacement.first < 0.0) + } else if (p.displacement.first < 0.0) + { halign_ = H_LEFT; - else + } else + { halign_ = H_MIDDLE; + } + } + + jalign_ = p.jalign; + if (jalign_ == J_AUTO) + { + if (p.displacement.first > 0.0) + { + jalign_ = J_LEFT; + } else if (p.displacement.first < 0.0) + { + jalign_ = J_RIGHT; + } else { + jalign_ = J_MIDDLE; + } } } @@ -389,9 +413,9 @@ void placement_finder::find_point_placement(double label_x, if (info_.get_rtl()) y = -y; // adjust for desired justification - if (p.jalign == J_LEFT) + if (jalign_ == J_LEFT) x = -(string_width_ / 2.0); - else if (p.jalign == J_RIGHT) + else if (jalign_ == J_RIGHT) x = (string_width_ / 2.0) - line_width; else /* J_MIDDLE */ x = -(line_width / 2.0); @@ -420,9 +444,9 @@ void placement_finder::find_point_placement(double label_x, } // reset to begining of line position - if (p.jalign == J_LEFT) + if (jalign_ == J_LEFT) x = -(string_width_ / 2.0); - else if (p.jalign == J_RIGHT) + else if (jalign_ == J_RIGHT) x = (string_width_ / 2.0) - line_width; else x = -(line_width / 2.0); diff --git a/src/text_properties.cpp b/src/text_properties.cpp index 4587cb5e4..89e4ee6cd 100644 --- a/src/text_properties.cpp +++ b/src/text_properties.cpp @@ -40,7 +40,7 @@ text_symbolizer_properties::text_symbolizer_properties() : displacement(0,0), label_placement(POINT_PLACEMENT), halign(H_AUTO), - jalign(J_MIDDLE), + jalign(J_AUTO), valign(V_AUTO), label_spacing(0), label_position_tolerance(0), diff --git a/src/text_symbolizer.cpp b/src/text_symbolizer.cpp index c060e43d1..75e76849b 100644 --- a/src/text_symbolizer.cpp +++ b/src/text_symbolizer.cpp @@ -69,6 +69,7 @@ static const char * justify_alignment_strings[] = { "left", "center", "right", + "auto", "" }; diff --git a/tests/visual_tests/jalign-auto-200-reference.png b/tests/visual_tests/jalign-auto-200-reference.png new file mode 100644 index 000000000..6acf39cdc Binary files /dev/null and b/tests/visual_tests/jalign-auto-200-reference.png differ diff --git a/tests/visual_tests/jalign-auto.xml b/tests/visual_tests/jalign-auto.xml new file mode 100644 index 000000000..d3c8631f0 --- /dev/null +++ b/tests/visual_tests/jalign-auto.xml @@ -0,0 +1,30 @@ + + + + + + My Style + + shape + points.shp + + + + + + diff --git a/tests/visual_tests/test.py b/tests/visual_tests/test.py index 804137c0b..8d9d3166f 100755 --- a/tests/visual_tests/test.py +++ b/tests/visual_tests/test.py @@ -28,7 +28,8 @@ files = [ ("formating-4", 500), ("shieldsymbolizer-1", 490, 495, 497, 498, 499, 500, 501, 502, 505, 510), ("expressionformat", 500), - ("rtl-point", (200, 200)) + ("rtl-point", (200, 200)), + ("jalign-auto", (200, 200)) ] def render(filename, width, height=100):