parse comp-op property as enumeration_wrapper or expression_str
This commit is contained in:
parent
0702679bb0
commit
aa9966ed88
3 changed files with 75 additions and 29 deletions
|
@ -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
|
||||
|
|
|
@ -51,7 +51,7 @@ void agg_renderer<T0,T1>::process(polygon_symbolizer const& sym,
|
|||
{
|
||||
typedef boost::mpl::vector<clip_poly_tag,transform_tag,affine_transform_tag,simplify_tag,smooth_tag> conv_types;
|
||||
typedef vertex_converter<box2d<double>, rasterizer, polygon_symbolizer,
|
||||
CoordTransform, proj_transform, agg::trans_affine,
|
||||
CoordTransform, proj_transform, agg::trans_affine,
|
||||
conv_types, feature_impl> vertex_converter_type;
|
||||
|
||||
ras_ptr->reset();
|
||||
|
@ -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)));
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue