From 0b1c983d404414635823e60e120a2f3bc46cd365 Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Sun, 5 Aug 2012 01:51:42 +0200 Subject: [PATCH] Add option for selecting which text should be upright. --- include/mapnik/text_properties.hpp | 11 ++++++++++ src/text_properties.cpp | 34 ++++++++++++++++++------------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/include/mapnik/text_properties.hpp b/include/mapnik/text_properties.hpp index d5d5cbe20..6df05f660 100644 --- a/include/mapnik/text_properties.hpp +++ b/include/mapnik/text_properties.hpp @@ -119,6 +119,16 @@ enum justify_alignment DEFINE_ENUM(justify_alignment_e, justify_alignment); +enum text_upright +{ + UPRIGHT_AUTO, + UPRIGHT_LEFT, + UPRIGHT_RIGHT, + text_upright_MAX +}; + +DEFINE_ENUM(text_upright_e, text_upright); + class text_layout; @@ -169,6 +179,7 @@ struct text_symbolizer_properties unsigned text_ratio; unsigned wrap_width; bool rotate_displacement; + text_upright_e upright; /** Default values for char_properties. */ char_properties_ptr format; private: diff --git a/src/text_properties.cpp b/src/text_properties.cpp index 2486852e8..21a506128 100644 --- a/src/text_properties.cpp +++ b/src/text_properties.cpp @@ -43,9 +43,7 @@ static const char * label_placement_strings[] = { "interior", "" }; - - -IMPLEMENT_ENUM( label_placement_e, label_placement_strings ) +IMPLEMENT_ENUM(label_placement_e, label_placement_strings) static const char * vertical_alignment_strings[] = { "top", @@ -54,9 +52,7 @@ static const char * vertical_alignment_strings[] = { "auto", "" }; - - -IMPLEMENT_ENUM( vertical_alignment_e, vertical_alignment_strings ) +IMPLEMENT_ENUM(vertical_alignment_e, vertical_alignment_strings) static const char * horizontal_alignment_strings[] = { "left", @@ -65,9 +61,7 @@ static const char * horizontal_alignment_strings[] = { "auto", "" }; - - -IMPLEMENT_ENUM( horizontal_alignment_e, horizontal_alignment_strings ) +IMPLEMENT_ENUM(horizontal_alignment_e, horizontal_alignment_strings) static const char * justify_alignment_strings[] = { "left", @@ -76,9 +70,7 @@ static const char * justify_alignment_strings[] = { "auto", "" }; - - -IMPLEMENT_ENUM( justify_alignment_e, justify_alignment_strings ) +IMPLEMENT_ENUM(justify_alignment_e, justify_alignment_strings) static const char * text_transform_strings[] = { "none", @@ -87,9 +79,18 @@ static const char * text_transform_strings[] = { "capitalize", "" }; +IMPLEMENT_ENUM(text_transform_e, text_transform_strings) -IMPLEMENT_ENUM( text_transform_e, text_transform_strings ) +static const char * text_upright_strings[] = { + "auto", + "left", + "right", + "capitalize", + "" +}; +IMPLEMENT_ENUM(text_upright_e, text_upright_strings) + text_symbolizer_properties::text_symbolizer_properties() : orientation(), @@ -111,6 +112,7 @@ text_symbolizer_properties::text_symbolizer_properties() : text_ratio(0), wrap_width(0), rotate_displacement(false), + upright(UPRIGHT_AUTO), format(boost::make_shared()), tree_() { @@ -171,6 +173,8 @@ void text_symbolizer_properties::from_xml(xml_node const &sym, fontset_map const if (orientation_) orientation = *orientation_; optional rotate_displacement_ = sym.get_opt_attr("rotate-displacement"); if (rotate_displacement_) rotate_displacement = *rotate_displacement_; + optional upright_ = sym.get_opt_attr("upright"); + if (upright_) upright = *upright_; optional dx = sym.get_opt_attr("dx"); if (dx) displacement.x = *dx; optional dy = sym.get_opt_attr("dy"); @@ -279,6 +283,10 @@ void text_symbolizer_properties::to_xml(boost::property_tree::ptree &node, { set_attr(node, "rotate-displacement", rotate_displacement); } + if (upright != dfl.upright || explicit_defaults) + { + set_attr(node, "upright", upright); + } format->to_xml(node, explicit_defaults, *(dfl.format)); if (tree_) tree_->to_xml(node); }