From a66c1ddb06ba4e3af231613b951d072750328401 Mon Sep 17 00:00:00 2001 From: artemp Date: Mon, 14 Jul 2014 16:51:11 +0100 Subject: [PATCH] convert to expressions: text-ratio, wrap-before, rotate-displacement --- include/mapnik/text/layout.hpp | 3 + include/mapnik/text/text_properties.hpp | 11 ++-- src/text/layout.cpp | 6 +- src/text/text_properties.cpp | 73 +++++++++++-------------- 4 files changed, 46 insertions(+), 47 deletions(-) diff --git a/include/mapnik/text/layout.hpp b/include/mapnik/text/layout.hpp index 1ee4f06c1..a18a5725e 100644 --- a/include/mapnik/text/layout.hpp +++ b/include/mapnik/text/layout.hpp @@ -138,6 +138,9 @@ private: // Precalculated values for maximum performance rotation orientation_ = {0,1.0}; double wrap_width_ = 0.0; + bool wrap_before_ = false; + bool rotate_displacement_ = false; + double text_ratio_ = 0.0; pixel_position displacement_; box2d bounds_; diff --git a/include/mapnik/text/text_properties.hpp b/include/mapnik/text/text_properties.hpp index 15d266164..951338614 100644 --- a/include/mapnik/text/text_properties.hpp +++ b/include/mapnik/text/text_properties.hpp @@ -75,8 +75,8 @@ struct MAPNIK_DECL text_layout_properties // Load all values from XML ptree. void from_xml(xml_node const &sym); // Save all values to XML ptree (but does not create a new parent node!). - void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, - text_layout_properties const &dfl=text_layout_properties()) const; + void to_xml(boost::property_tree::ptree & node, bool explicit_defaults, + text_layout_properties const& dfl=text_layout_properties()) const; // Get a list of all expressions used in any placement. // This function is used to collect attributes. @@ -89,10 +89,11 @@ struct MAPNIK_DECL text_layout_properties horizontal_alignment_e halign; justify_alignment_e jalign; vertical_alignment_e valign; - double text_ratio; + + symbolizer_base::value_type text_ratio; symbolizer_base::value_type wrap_width; - bool wrap_before; - bool rotate_displacement; + symbolizer_base::value_type wrap_before; + symbolizer_base::value_type rotate_displacement; }; using text_layout_properties_ptr = std::shared_ptr; diff --git a/src/text/layout.cpp b/src/text/layout.cpp index 53aa6ea88..0e247c344 100644 --- a/src/text/layout.cpp +++ b/src/text/layout.cpp @@ -89,13 +89,13 @@ void text_layout::layout() std::pair line_limits = itemizer_.line(i); text_line line(line_limits.first, line_limits.second); //Break line if neccessary - break_line(line, wrap_width_ * scale_factor_, properties_.text_ratio, properties_.wrap_before); + break_line(line, wrap_width_ * scale_factor_, text_ratio_, wrap_before_); } init_alignment(); /* Find text origin. */ displacement_ = scale_factor_ * properties_.displacement + alignment_offset(); - if (properties_.rotate_displacement) displacement_ = displacement_.rotate(!orientation_); + if (rotate_displacement_) displacement_ = displacement_.rotate(!orientation_); /* Find layout bounds, expanded for rotation */ rotated_box2d(bounds_, orientation_, displacement_, width_, height_); @@ -238,6 +238,8 @@ void text_layout::evaluate_properties(feature_impl const& feature, attributes co wrap_width_ = boost::apply_visitor(extract_value(feature,attr), properties_.wrap_width); double angle = boost::apply_visitor(extract_value(feature,attr), properties_.orientation); orientation_.init(angle * M_PI/ 180.0); + wrap_before_ = boost::apply_visitor(extract_value(feature,attr), properties_.wrap_before); + rotate_displacement_ = boost::apply_visitor(extract_value(feature,attr), properties_.rotate_displacement); } void text_layout::init_alignment() diff --git a/src/text/text_properties.cpp b/src/text/text_properties.cpp index 450c16eba..4ce4ec21f 100644 --- a/src/text/text_properties.cpp +++ b/src/text/text_properties.cpp @@ -215,15 +215,10 @@ void set_property_from_xml(symbolizer_base::value_type & val, char const* name, } text_layout_properties::text_layout_properties() - : orientation(0.0), - displacement(0.0,0.0), + : displacement(0.0,0.0), halign(H_AUTO), jalign(J_AUTO), - valign(V_AUTO), - text_ratio(0.0), - wrap_width(0.0), - wrap_before(false), - rotate_displacement(false) {} + valign(V_AUTO) {} void text_layout_properties::from_xml(xml_node const &sym) { @@ -237,16 +232,11 @@ void text_layout_properties::from_xml(xml_node const &sym) if (halign_) halign = *halign_; optional jalign_ = sym.get_opt_attr("justify-alignment"); if (jalign_) jalign = *jalign_; - optional text_ratio_ = sym.get_opt_attr("text-ratio"); - if (text_ratio_) text_ratio = *text_ratio_; + set_property_from_xml(text_ratio, "text-ratio", sym); set_property_from_xml(wrap_width, "wrap-width", sym); - - optional wrap_before_ = sym.get_opt_attr("wrap-before"); - if (wrap_before_) wrap_before = *wrap_before_; - optional rotate_displacement_ = sym.get_opt_attr("rotate-displacement"); - if (rotate_displacement_) rotate_displacement = *rotate_displacement_; - + set_property_from_xml(wrap_before, "wrap-before", sym); + set_property_from_xml(rotate_displacement, "rotate-displacement", sym); set_property_from_xml(orientation, "orientation", sym); } @@ -274,22 +264,22 @@ void text_layout_properties::to_xml(boost::property_tree::ptree & node, { set_attr(node, "justify-alignment", jalign); } - if (text_ratio != dfl.text_ratio || explicit_defaults) - { - set_attr(node, "text-ratio", text_ratio); - } + //if (text_ratio != dfl.text_ratio || explicit_defaults) + //{ + // set_attr(node, "text-ratio", text_ratio); + //} //if (wrap_width != dfl.wrap_width || explicit_defaults) //{ // set_attr(node, "wrap-width", wrap_width); //} - if (wrap_before != dfl.wrap_before || explicit_defaults) - { - set_attr(node, "wrap-before", wrap_before); - } - if (rotate_displacement != dfl.rotate_displacement || explicit_defaults) - { - set_attr(node, "rotate-displacement", rotate_displacement); - } + //if (wrap_before != dfl.wrap_before || explicit_defaults) + //{ + // set_attr(node, "wrap-before", wrap_before); + //} + //if (rotate_displacement != dfl.rotate_displacement || explicit_defaults) + //{ + // set_attr(node, "rotate-displacement", rotate_displacement); + //} /// TODO //if (orientation) //{ @@ -304,21 +294,24 @@ void text_layout_properties::add_expressions(expression_set& output) const { if (is_expression(orientation)) output.insert(boost::get(orientation)); if (is_expression(wrap_width)) output.insert(boost::get(wrap_width)); + if (is_expression(wrap_before)) output.insert(boost::get(wrap_before)); + if (is_expression(rotate_displacement)) output.insert(boost::get(rotate_displacement)); + if (is_expression(text_ratio)) output.insert(boost::get(text_ratio)); } -char_properties::char_properties() : - face_name(), - fontset(), - text_size(10.0), - character_spacing(0), - line_spacing(0), - text_opacity(1.0), - halo_opacity(1.0), - wrap_char(' '), - text_transform(NONE), - fill(color(0,0,0)), - halo_fill(color(255,255,255)), - halo_radius(0) {} +char_properties::char_properties() + : face_name(), + fontset(), + text_size(10.0), + character_spacing(0), + line_spacing(0), + text_opacity(1.0), + halo_opacity(1.0), + wrap_char(' '), + text_transform(NONE), + fill(color(0,0,0)), + halo_fill(color(255,255,255)), + halo_radius(0) {} void char_properties::from_xml(xml_node const& node, fontset_map const& fontsets) {