diff --git a/bindings/python/mapnik_text_placement.cpp b/bindings/python/mapnik_text_placement.cpp index 1df247182..b3d92ecbc 100644 --- a/bindings/python/mapnik_text_placement.cpp +++ b/bindings/python/mapnik_text_placement.cpp @@ -99,7 +99,7 @@ public: boost::python::tuple get_displacement(text_layout_properties const& t) { - return boost::python::make_tuple(t.displacement.x, t.displacement.y); + return boost::python::make_tuple(0.0,0.0);// FIXME t.displacement.x, t.displacement.y); } void set_displacement(text_layout_properties &t, boost::python::tuple arg) @@ -115,7 +115,7 @@ void set_displacement(text_layout_properties &t, boost::python::tuple arg) double x = extract(arg[0]); double y = extract(arg[1]); - t.displacement.set(x, y); + //t.displacement.set(x, y); FIXME } struct NodeWrap: formatting::node, wrapper diff --git a/include/mapnik/text/layout.hpp b/include/mapnik/text/layout.hpp index a18a5725e..e62439e91 100644 --- a/include/mapnik/text/layout.hpp +++ b/include/mapnik/text/layout.hpp @@ -141,7 +141,7 @@ private: bool wrap_before_ = false; bool rotate_displacement_ = false; double text_ratio_ = 0.0; - pixel_position displacement_; + pixel_position displacement_ = {0,0}; box2d bounds_; //children diff --git a/include/mapnik/text/text_properties.hpp b/include/mapnik/text/text_properties.hpp index 951338614..602e76925 100644 --- a/include/mapnik/text/text_properties.hpp +++ b/include/mapnik/text/text_properties.hpp @@ -83,17 +83,17 @@ struct MAPNIK_DECL text_layout_properties void add_expressions(expression_set &output) const; //Per layout options + symbolizer_base::value_type dx; + symbolizer_base::value_type dy; symbolizer_base::value_type orientation; - - pixel_position displacement; - horizontal_alignment_e halign; - justify_alignment_e jalign; - vertical_alignment_e valign; - symbolizer_base::value_type text_ratio; symbolizer_base::value_type wrap_width; symbolizer_base::value_type wrap_before; symbolizer_base::value_type rotate_displacement; + horizontal_alignment_e halign; + justify_alignment_e jalign; + vertical_alignment_e valign; + }; using text_layout_properties_ptr = std::shared_ptr; @@ -109,7 +109,8 @@ struct MAPNIK_DECL text_symbolizer_properties // Load all values from XML ptree. void from_xml(xml_node const &sym, fontset_map const & fontsets); // 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_symbolizer_properties const &dfl=text_symbolizer_properties()) const; + void to_xml(boost::property_tree::ptree &node, bool explicit_defaults, + text_symbolizer_properties const &dfl=text_symbolizer_properties()) const; // Takes a feature and produces formated text as output. // The output object has to be created by the caller and passed in for thread safety. diff --git a/src/text/formatting/layout.cpp b/src/text/formatting/layout.cpp index d09d722e1..2b48024e1 100644 --- a/src/text/formatting/layout.cpp +++ b/src/text/formatting/layout.cpp @@ -82,8 +82,8 @@ node_ptr layout_node::from_xml(xml_node const& xml) void layout_node::apply(char_properties_ptr p, feature_impl const& feature, attributes const& vars, text_layout& output) const { text_layout_properties new_properties(output.get_layout_properties()); - if (dx) new_properties.displacement.x = *dx; - if (dy) new_properties.displacement.y = *dy; + if (dx) new_properties.dx = *dx; + if (dy) new_properties.dy = *dy; if (halign) new_properties.halign = *halign; if (valign) new_properties.valign = *valign; if (jalign) new_properties.jalign = *jalign; diff --git a/src/text/layout.cpp b/src/text/layout.cpp index 0e247c344..1617b44de 100644 --- a/src/text/layout.cpp +++ b/src/text/layout.cpp @@ -62,9 +62,7 @@ text_layout::text_layout(face_manager_freetype & font_manager, double scale_fact height_(0.0), glyphs_count_(0), lines_(), - properties_(properties) -{ -} + properties_(properties) {} void text_layout::add_text(mapnik::value_unicode_string const& str, char_properties_ptr format) { @@ -93,18 +91,18 @@ void text_layout::layout() } init_alignment(); - /* Find text origin. */ - displacement_ = scale_factor_ * properties_.displacement + alignment_offset(); + // Find text origin. + displacement_ = scale_factor_ * displacement_ + alignment_offset(); if (rotate_displacement_) displacement_ = displacement_.rotate(!orientation_); - /* Find layout bounds, expanded for rotation */ + // Find layout bounds, expanded for rotation rotated_box2d(bounds_, orientation_, displacement_, width_, height_); } -/* In the Unicode string characters are always stored in logical order. - * This makes line breaking easy. One word is added to the current line at a time. Once the line is too long - * we either go back one step or inset the line break at the current position (depending on "wrap_before" setting). - * At the end everything that is left over is added as the final line. */ +// In the Unicode string characters are always stored in logical order. +// This makes line breaking easy. One word is added to the current line at a time. Once the line is too long +// we either go back one step or inset the line break at the current position (depending on "wrap_before" setting). +// At the end everything that is left over is added as the final line. void text_layout::break_line(text_line & line, double wrap_width, unsigned text_ratio, bool wrap_before) { shape_text(line); @@ -235,8 +233,12 @@ void text_layout::shape_text(text_line & line) void text_layout::evaluate_properties(feature_impl const& feature, attributes const& attr) { + double dx = boost::apply_visitor(extract_value(feature,attr), properties_.dx); + double dy = boost::apply_visitor(extract_value(feature,attr), properties_.dy); + displacement_ = {dx, dy}; 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); @@ -247,11 +249,11 @@ void text_layout::init_alignment() valign_ = properties_.valign; if (valign_ == V_AUTO) { - if (properties_.displacement.y > 0.0) + if (displacement_.y > 0.0) { valign_ = V_BOTTOM; } - else if (properties_.displacement.y < 0.0) + else if (displacement_.y < 0.0) { valign_ = V_TOP; } @@ -264,11 +266,11 @@ void text_layout::init_alignment() halign_ = properties_.halign; if (halign_ == H_AUTO) { - if (properties_.displacement.x > 0.0) + if (displacement_.x > 0.0) { halign_ = H_RIGHT; } - else if (properties_.displacement.x < 0.0) + else if (displacement_.x < 0.0) { halign_ = H_LEFT; } @@ -281,11 +283,11 @@ void text_layout::init_alignment() jalign_ = properties_.jalign; if (jalign_ == J_AUTO) { - if (properties_.displacement.x > 0.0) + if (displacement_.x > 0.0) { jalign_ = J_LEFT; } - else if (properties_.displacement.x < 0.0) + else if (displacement_.x < 0.0) { jalign_ = J_RIGHT; } diff --git a/src/text/placement_finder.cpp b/src/text/placement_finder.cpp index 7ffa4d94c..37095f16a 100644 --- a/src/text/placement_finder.cpp +++ b/src/text/placement_finder.cpp @@ -262,7 +262,7 @@ bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e or { text_layout const& layout = *layout_ptr; pixel_position align_offset = layout.alignment_offset(); - pixel_position const& layout_displacement = layout.get_layout_properties().displacement; + pixel_position const& layout_displacement = layout.displacement(); double sign = (real_orientation == UPRIGHT_LEFT) ? -1 : 1; double offset = align_offset.y + layout_displacement.y * scale_factor_ + sign * layout.height()/2.; @@ -350,9 +350,9 @@ bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e or return true; } -void placement_finder::path_move_dx(vertex_cache &pp) +void placement_finder::path_move_dx(vertex_cache & pp) { - double dx = info_.properties.layout_defaults.displacement.x * scale_factor_; + double dx = 0.0;// FIXME info_.properties.layout_defaults.displacement.x * scale_factor_; if (dx != 0.0) { vertex_cache::state state = pp.save_state(); diff --git a/src/text/placements/simple.cpp b/src/text/placements/simple.cpp index c0ec151f8..e99f78ed0 100644 --- a/src/text/placements/simple.cpp +++ b/src/text/placements/simple.cpp @@ -62,8 +62,8 @@ bool text_placement_info_simple::next() bool text_placement_info_simple::next_position_only() { - pixel_position const& pdisp = parent_->defaults.layout_defaults.displacement; - pixel_position &displacement = properties.layout_defaults.displacement; + pixel_position const& pdisp = {0,0};// FIXME parent_->defaults.layout_defaults.displacement; + pixel_position displacement = {0,0};// FIXME properties.layout_defaults.displacement; if (position_state >= parent_->direction_.size()) return false; directions_e dir = parent_->direction_[position_state]; switch (dir) { diff --git a/src/text/text_properties.cpp b/src/text/text_properties.cpp index 28a19f14f..c39b32361 100644 --- a/src/text/text_properties.cpp +++ b/src/text/text_properties.cpp @@ -55,7 +55,7 @@ text_symbolizer_properties::text_symbolizer_properties() format(std::make_shared()), tree_() {} -void text_symbolizer_properties::process(text_layout &output, feature_impl const& feature, attributes const& vars) const +void text_symbolizer_properties::process(text_layout & output, feature_impl const& feature, attributes const& vars) const { output.clear(); if (tree_) { @@ -215,17 +215,15 @@ void set_property_from_xml(symbolizer_base::value_type & val, char const* name, } text_layout_properties::text_layout_properties() - : displacement(0.0,0.0), - halign(H_AUTO), + : halign(H_AUTO), jalign(J_AUTO), valign(V_AUTO) {} void text_layout_properties::from_xml(xml_node const &node) { - optional dx = node.get_opt_attr("dx"); - if (dx) displacement.x = *dx; - optional dy = node.get_opt_attr("dy"); - if (dy) displacement.y = *dy; + set_property_from_xml(dx, "dx", node); + set_property_from_xml(dy, "dy", node); + optional valign_ = node.get_opt_attr("vertical-alignment"); if (valign_) valign = *valign_; optional halign_ = node.get_opt_attr("horizontal-alignment"); @@ -241,17 +239,17 @@ void text_layout_properties::from_xml(xml_node const &node) } void text_layout_properties::to_xml(boost::property_tree::ptree & node, - bool explicit_defaults, - text_layout_properties const& dfl) const + bool explicit_defaults, + text_layout_properties const& dfl) const { - if (displacement.x != dfl.displacement.x || explicit_defaults) - { - set_attr(node, "dx", displacement.x); - } - if (displacement.y != dfl.displacement.y || explicit_defaults) - { - set_attr(node, "dy", displacement.y); - } + //if (displacement.x != dfl.displacement.x || explicit_defaults) + //{ + // set_attr(node, "dx", displacement.x); + //} + //if (displacement.y != dfl.displacement.y || explicit_defaults) + //{ + // set_attr(node, "dy", displacement.y); + //} if (valign != dfl.valign || explicit_defaults) { set_attr(node, "vertical-alignment", valign);