parse comp-op property as enumeration_wrapper or expression_str

This commit is contained in:
artemp 2014-06-27 13:58:03 +01:00
parent 0702679bb0
commit aa9966ed88
3 changed files with 75 additions and 29 deletions

View file

@ -51,6 +51,8 @@
// boost
#include <boost/variant/variant_fwd.hpp>
#include <boost/concept_check.hpp>
// agg
#include "agg_pixfmt_rgba.h"
namespace agg { struct trans_affine; }
@ -186,6 +188,19 @@ struct expression_result<T,false>
}
};
template <>
struct expression_result<agg::comp_op_e,true>
{
typedef agg::comp_op_e result_type;
static result_type convert(value_type const& val)
{
auto result = comp_op_from_string(val.to_string());
if (result) return static_cast<result_type>(*result);
return agg::comp_op_src_over;
}
};
// enum
template <typename T, bool is_enum = true>
struct enumeration_result

View file

@ -81,7 +81,8 @@ void agg_renderer<T0,T1>::process(polygon_symbolizer const& sym,
typedef agg::renderer_base<pixfmt_comp_type> renderer_base;
typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_type;
pixfmt_comp_type pixf(buf);
pixf.comp_op(get<agg::comp_op_e>(sym, keys::comp_op, feature, common_.vars_, agg::comp_op_src_over));
auto comp_op = get<agg::comp_op_e>(sym, keys::comp_op, feature, common_.vars_, agg::comp_op_src_over);
pixf.comp_op(comp_op);
renderer_base renb(pixf);
renderer_type ren(renb);
ren.color(agg::rgba8_pre(r, g, b, int(a * opacity)));

View file

@ -846,10 +846,13 @@ void map_parser::parse_symbolizers(rule & rule, xml_node const & node)
}
}
// helper method
namespace detail {
// helpers
template <typename Symbolizer, typename T>
void set_symbolizer_property(Symbolizer & sym, keys key, xml_node const & node)
struct set_symbolizer_property_impl
{
static void apply(Symbolizer & sym, keys key, xml_node const & node)
{
typedef T value_type;
std::string const& name = std::get<0>(get_meta(key));
try
@ -863,11 +866,19 @@ void set_symbolizer_property(Symbolizer & sym, keys key, xml_node const & node)
optional<expression_ptr> val = node.get_opt_attr<expression_ptr>(name);
if (val) put(sym, key, *val);
}
}
}
};
void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const &pt)
template <typename Symbolizer>
struct set_symbolizer_property_impl<Symbolizer, composite_mode_e>
{
optional<std::string> comp_op_name = pt.get_opt_attr<std::string>("comp-op");
static void apply(Symbolizer & sym, keys key, xml_node const & node)
{
typedef composite_mode_e value_type;
std::string const& name = std::get<0>(get_meta(key));
try
{
optional<std::string> comp_op_name = node.get_opt_attr<std::string>("comp-op");
if (comp_op_name)
{
optional<composite_mode_e> comp_op = comp_op_from_string(*comp_op_name);
@ -877,10 +888,29 @@ void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const &pt)
}
else
{
throw config_error("failed to parse comp-op: '" + *comp_op_name + "'");
optional<expression_ptr> val = node.get_opt_attr<expression_ptr>(name);
if (val) put(sym, key, *val);
}
}
}
catch (config_error const& ex)
{
MAPNIK_LOG_ERROR(composite_mode_e) << ex.what();
}
}
};
} // namespace detail
template <typename Symbolizer, typename T>
void set_symbolizer_property(Symbolizer & sym, keys key, xml_node const & node)
{
detail::set_symbolizer_property_impl<Symbolizer,T>::apply(sym,key,node);
}
void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const &pt)
{
set_symbolizer_property<symbolizer_base,composite_mode_e>(sym, keys::comp_op, pt);
optional<std::string> geometry_transform_wkt = pt.get_opt_attr<std::string>("geometry-transform");
if (geometry_transform_wkt)
{