From 8f12da81d113d7e9a838adff7b3d14b25147e9ca Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 27 Feb 2013 08:29:56 -0500 Subject: [PATCH] + image-filters: make grammar more flexible to accomodate different ctors signitures + add 'hsla' filter placeholder (TODO: add impl) + remove inused include --- include/mapnik/image_filter_grammar.hpp | 5 ++++- include/mapnik/image_filter_types.hpp | 12 +++++++++-- src/image_filter_grammar.cpp | 28 ++++++++++++++++++------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/include/mapnik/image_filter_grammar.hpp b/include/mapnik/image_filter_grammar.hpp index 054cd856e..823b21b93 100644 --- a/include/mapnik/image_filter_grammar.hpp +++ b/include/mapnik/image_filter_grammar.hpp @@ -39,7 +39,10 @@ struct image_filter_grammar : { image_filter_grammar(); qi::rule start; - qi::rule, qi::ascii::space_type> filter; + qi::rule filter; + qi::rule, void(ContType&), qi::ascii::space_type> agg_blur_filter; + qi::rule, void(ContType&), qi::ascii::space_type> hsla_filter; + qi::rule string_arg; qi::uint_parser< unsigned, 10, 1, 3 > radius_; }; diff --git a/include/mapnik/image_filter_types.hpp b/include/mapnik/image_filter_types.hpp index d651e9c68..7c61b1b1f 100644 --- a/include/mapnik/image_filter_types.hpp +++ b/include/mapnik/image_filter_types.hpp @@ -30,7 +30,6 @@ #include // stl -#include #include #include #include // for std::back_insert_iterator @@ -55,6 +54,14 @@ struct agg_stack_blur unsigned ry; }; +struct hsla +{ + hsla(std::string const& str) + { + // do something + } +}; + typedef boost::variant filter_type; + filter::invert, + filter::hsla> filter_type; inline std::ostream& operator<< (std::ostream& os, blur) { diff --git a/src/image_filter_grammar.cpp b/src/image_filter_grammar.cpp index 1601b2904..80becb931 100644 --- a/src/image_filter_grammar.cpp +++ b/src/image_filter_grammar.cpp @@ -44,8 +44,11 @@ image_filter_grammar::image_filter_grammar() using qi::_1; using qi::_a; using qi::_b; + using qi::_r1; using qi::eps; using qi::char_; + using qi::lexeme; + using boost::spirit::ascii::string; using phoenix::push_back; using phoenix::construct; @@ -75,15 +78,26 @@ image_filter_grammar::image_filter_grammar() | lit("y-gradient")[push_back(_val,construct())] | - (lit("agg-stack-blur")[_a = 1, _b = 1] - >> -( lit('(') >> radius_[_a = _1] - >> lit(',') - >> radius_[_b = _1] - >> lit(')')) - [push_back(_val,construct(_a,_b))]) - | lit("invert")[push_back(_val,construct())] + | + agg_blur_filter(_val) + | + hsla_filter(_val) ; + + agg_blur_filter = (lit("agg-stack-blur")[_a = 1, _b = 1] + >> -( lit('(') >> radius_[_a = _1] + >> lit(',') + >> radius_[_b = _1] + >> lit(')'))) + [push_back(_r1,construct(_a,_b))] + ; + + hsla_filter = (lit("hsla") >> lit('(') >> string_arg[_a = _1] >> lit(')')) + [push_back(_r1,construct(_a))] + ; + + string_arg = +~char_(')'); } template struct mapnik::image_filter_grammar >;