text properties : displacement expr

This commit is contained in:
artemp 2014-07-15 10:15:56 +01:00
parent 0b1ad62cf5
commit 72bae0d6b8
8 changed files with 51 additions and 50 deletions

View file

@ -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<double>(arg[0]);
double y = extract<double>(arg[1]);
t.displacement.set(x, y);
//t.displacement.set(x, y); FIXME
}
struct NodeWrap: formatting::node, wrapper<formatting::node>

View file

@ -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<double> bounds_;
//children

View file

@ -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<text_layout_properties>;
@ -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.

View file

@ -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;

View file

@ -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<value_double>(feature,attr), properties_.dx);
double dy = boost::apply_visitor(extract_value<value_double>(feature,attr), properties_.dy);
displacement_ = {dx, dy};
wrap_width_ = boost::apply_visitor(extract_value<value_double>(feature,attr), properties_.wrap_width);
double angle = boost::apply_visitor(extract_value<value_double>(feature,attr), properties_.orientation);
orientation_.init(angle * M_PI/ 180.0);
wrap_before_ = boost::apply_visitor(extract_value<value_bool>(feature,attr), properties_.wrap_before);
rotate_displacement_ = boost::apply_visitor(extract_value<value_bool>(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;
}

View file

@ -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();

View file

@ -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) {

View file

@ -55,7 +55,7 @@ text_symbolizer_properties::text_symbolizer_properties()
format(std::make_shared<char_properties>()),
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<double> dx = node.get_opt_attr<double>("dx");
if (dx) displacement.x = *dx;
optional<double> dy = node.get_opt_attr<double>("dy");
if (dy) displacement.y = *dy;
set_property_from_xml<double>(dx, "dx", node);
set_property_from_xml<double>(dy, "dy", node);
optional<vertical_alignment_e> valign_ = node.get_opt_attr<vertical_alignment_e>("vertical-alignment");
if (valign_) valign = *valign_;
optional<horizontal_alignment_e> halign_ = node.get_opt_attr<horizontal_alignment_e>("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);