From aa9966ed8862f3f0a1e9d78cc30e034de0a5d32e Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 27 Jun 2014 13:58:03 +0100 Subject: [PATCH] parse comp-op property as enumeration_wrapper or expression_str --- include/mapnik/symbolizer.hpp | 15 +++++ src/agg/process_polygon_symbolizer.cpp | 5 +- src/load_map.cpp | 84 +++++++++++++++++--------- 3 files changed, 75 insertions(+), 29 deletions(-) diff --git a/include/mapnik/symbolizer.hpp b/include/mapnik/symbolizer.hpp index a08f393c3..96ef8deae 100644 --- a/include/mapnik/symbolizer.hpp +++ b/include/mapnik/symbolizer.hpp @@ -51,6 +51,8 @@ // boost #include #include +// agg +#include "agg_pixfmt_rgba.h" namespace agg { struct trans_affine; } @@ -186,6 +188,19 @@ struct expression_result } }; +template <> +struct expression_result +{ + 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); + return agg::comp_op_src_over; + } +}; + + // enum template struct enumeration_result diff --git a/src/agg/process_polygon_symbolizer.cpp b/src/agg/process_polygon_symbolizer.cpp index a53501a94..7a46967c2 100644 --- a/src/agg/process_polygon_symbolizer.cpp +++ b/src/agg/process_polygon_symbolizer.cpp @@ -51,7 +51,7 @@ void agg_renderer::process(polygon_symbolizer const& sym, { typedef boost::mpl::vector conv_types; typedef vertex_converter, 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::process(polygon_symbolizer const& sym, typedef agg::renderer_base renderer_base; typedef agg::renderer_scanline_aa_solid renderer_type; pixfmt_comp_type pixf(buf); - pixf.comp_op(get(sym, keys::comp_op, feature, common_.vars_, agg::comp_op_src_over)); + auto comp_op = get(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))); diff --git a/src/load_map.cpp b/src/load_map.cpp index d729cffd1..5cfd2dac2 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -846,41 +846,71 @@ void map_parser::parse_symbolizers(rule & rule, xml_node const & node) } } -// helper method +namespace detail { +// helpers +template +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 val = node.get_opt_attr(name); + if (val) put(sym, key, *val); + } + catch (config_error const&) + { + // try parser as an expression + optional val = node.get_opt_attr(name); + if (val) put(sym, key, *val); + } + } +}; + +template +struct set_symbolizer_property_impl +{ + 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 comp_op_name = node.get_opt_attr("comp-op"); + if (comp_op_name) + { + optional comp_op = comp_op_from_string(*comp_op_name); + if (comp_op) + { + put(sym, keys::comp_op, *comp_op); + } + else + { + optional val = node.get_opt_attr(name); + if (val) put(sym, key, *val); + } + } + } + catch (config_error const& ex) + { + MAPNIK_LOG_ERROR(composite_mode_e) << ex.what(); + } + } +}; +} // namespace detail + template 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 val = node.get_opt_attr(name); - if (val) put(sym, key, *val); - } - catch (config_error const&) - { - // try parser as an expression - optional val = node.get_opt_attr(name); - if (val) put(sym, key, *val); - } + detail::set_symbolizer_property_impl::apply(sym,key,node); } void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const &pt) { - optional comp_op_name = pt.get_opt_attr("comp-op"); - if (comp_op_name) - { - optional 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(sym, keys::comp_op, pt); optional geometry_transform_wkt = pt.get_opt_attr("geometry-transform"); if (geometry_transform_wkt) {