From 95cfb061afe3d3d30e137db54418aa87cdd34be6 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Wed, 21 Mar 2012 15:47:33 +0000 Subject: [PATCH] + experimental compositing symbolizer (fill only) --- bindings/python/mapnik_symbolizer.cpp | 7 +++++ include/mapnik/agg_renderer.hpp | 4 +++ include/mapnik/rule.hpp | 13 ++++++--- src/build.py | 2 ++ src/load_map.cpp | 41 +++++++++++++++++++++++++++ src/save_map.cpp | 9 ++++++ 6 files changed, 72 insertions(+), 4 deletions(-) diff --git a/bindings/python/mapnik_symbolizer.cpp b/bindings/python/mapnik_symbolizer.cpp index a4c4c3512..625efe7a2 100644 --- a/bindings/python/mapnik_symbolizer.cpp +++ b/bindings/python/mapnik_symbolizer.cpp @@ -94,6 +94,13 @@ public: { return "markers"; } + + template + std::string operator() ( Symbolizer const& sym) + { + boost::ignore_unused_variable_warning(sym); + return "unknown"; + } }; std::string get_symbol_type(const symbolizer& symbol) diff --git a/include/mapnik/agg_renderer.hpp b/include/mapnik/agg_renderer.hpp index d7e09049a..578e79f2d 100644 --- a/include/mapnik/agg_renderer.hpp +++ b/include/mapnik/agg_renderer.hpp @@ -97,6 +97,10 @@ public: void process(markers_symbolizer const& sym, mapnik::feature_ptr const& feature, proj_transform const& prj_trans); + void process(compositing_symbolizer const& sym, + mapnik::feature_ptr const& feature, + proj_transform const& prj_trans); + inline bool process(rule::symbolizers const& /*syms*/, mapnik::feature_ptr const& /*feature*/, proj_transform const& /*prj_trans*/) diff --git a/include/mapnik/rule.hpp b/include/mapnik/rule.hpp index 23cf62a0d..2d7bdaa0a 100644 --- a/include/mapnik/rule.hpp +++ b/include/mapnik/rule.hpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -108,6 +109,12 @@ inline bool operator==(markers_symbolizer const& lhs, return (&lhs == &rhs); } +inline bool operator==(compositing_symbolizer const& lhs, + compositing_symbolizer const& rhs) +{ + return (&lhs == &rhs); +} + typedef boost::variant symbolizer; - - - + markers_symbolizer, + compositing_symbolizer> symbolizer; class rule { diff --git a/src/build.py b/src/build.py index 59bf949ca..211248212 100644 --- a/src/build.py +++ b/src/build.py @@ -104,6 +104,7 @@ else: # Linux and others source = Split( """ color.cpp + compositing_symbolizer.cpp conversions.cpp image_compositing.cpp box2d.cpp @@ -251,6 +252,7 @@ source += Split( agg/process_raster_symbolizer.cpp agg/process_shield_symbolizer.cpp agg/process_markers_symbolizer.cpp + agg/process_compositing_symbolizer.cpp """ ) diff --git a/src/load_map.cpp b/src/load_map.cpp index 38bcfbff7..1ca110d77 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -107,6 +108,7 @@ private: void parse_shield_symbolizer(rule & rule, xml_node const& sym); void parse_line_symbolizer(rule & rule, xml_node const& sym); void parse_polygon_symbolizer(rule & rule, xml_node const& sym); + void parse_compositing_symbolizer(rule & rule, xml_node const& sym); void parse_building_symbolizer(rule & rule, xml_node const& sym); void parse_raster_symbolizer(rule & rule, xml_node const& sym); void parse_markers_symbolizer(rule & rule, xml_node const& sym); @@ -691,6 +693,10 @@ void map_parser::parse_rule(feature_type_style & style, xml_node const& r) { parse_polygon_pattern_symbolizer(rule, *symIter); } + else if (symIter->is("CompositingSymbolizer")) + { + parse_compositing_symbolizer(rule, *symIter); + } else if (symIter->is("TextSymbolizer")) { parse_text_symbolizer(rule, *symIter); @@ -1314,6 +1320,41 @@ void map_parser::parse_polygon_symbolizer(rule & rule, xml_node const & sym) } } +void map_parser::parse_compositing_symbolizer(rule & rule, xml_node const & sym) +{ + try + { + compositing_symbolizer comp_sym; + // fill + optional fill = sym.get_opt_attr("fill"); + if (fill) comp_sym.set_fill(*fill); + // fill-opacity + optional opacity = sym.get_opt_attr("fill-opacity"); + if (opacity) comp_sym.set_opacity(*opacity); + // gamma + optional gamma = sym.get_opt_attr("gamma"); + if (gamma) comp_sym.set_gamma(*gamma); + // gamma method + optional gamma_method = sym.get_opt_attr("gamma-method"); + if (gamma_method) comp_sym.set_gamma_method(*gamma_method); + // smooth value + optional smooth = sym.get_opt_attr("smooth"); + if (smooth) comp_sym.set_smooth(*smooth); + + optional comp_op_name = sym.get_opt_attr("comp-op"); + if (comp_op_name) + { + composite_mode_e comp_op = comp_op_from_string(*comp_op_name); + comp_sym.set_comp_op(comp_op); + } + rule.append(comp_sym); + } + catch (const config_error & ex) + { + ex.append_context("in CompositingSymbolizer", sym); + throw; + } +} void map_parser::parse_building_symbolizer(rule & rule, xml_node const & sym) { diff --git a/src/save_map.cpp b/src/save_map.cpp index 6aa9fe5d5..70c46f5b0 100644 --- a/src/save_map.cpp +++ b/src/save_map.cpp @@ -321,6 +321,15 @@ public: add_metawriter_attributes(sym_node, sym); } + template + void operator () ( Symbolizer const& sym) + { + // not-supported +#ifdef MAPNIK_DEBUG + std::clog << typeid(sym).name() << " is not supported" << std::endl; +#endif + } + private: serialize_symbolizer();