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,41 +846,71 @@ void map_parser::parse_symbolizers(rule & rule, xml_node const & node)
}
}
// helper method
namespace detail {
// helpers
template <typename Symbolizer, typename T>
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
{
optional<value_type> val = node.get_opt_attr<value_type>(name);
if (val) put(sym, key, *val);
}
catch (config_error const&)
{
// try parser as an expression
optional<expression_ptr> val = node.get_opt_attr<expression_ptr>(name);
if (val) put(sym, key, *val);
}
}
};
template <typename Symbolizer>
struct set_symbolizer_property_impl<Symbolizer, composite_mode_e>
{
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);
if (comp_op)
{
put(sym, keys::comp_op, *comp_op);
}
else
{
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)
{
typedef T value_type;
std::string const& name = std::get<0>(get_meta(key));
try
{
optional<value_type> val = node.get_opt_attr<value_type>(name);
if (val) put(sym, key, *val);
}
catch (config_error const&)
{
// try parser as an expression
optional<expression_ptr> val = node.get_opt_attr<expression_ptr>(name);
if (val) put(sym, key, *val);
}
detail::set_symbolizer_property_impl<Symbolizer,T>::apply(sym,key,node);
}
void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const &pt)
{
optional<std::string> comp_op_name = pt.get_opt_attr<std::string>("comp-op");
if (comp_op_name)
{
optional<composite_mode_e> comp_op = comp_op_from_string(*comp_op_name);
if (comp_op)
{
put(sym, keys::comp_op, *comp_op);
}
else
{
throw config_error("failed to parse comp-op: '" + *comp_op_name + "'");
}
}
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)
{