Skip to content
This repository
Browse code

move image filter grammar to cpp and re-use in load map by attaching …

…to xml_tree - closes #1435
  • Loading branch information...
commit bf3efbeab8ec7c162699a2b87dcd5513d6f84dd3 1 parent ce03b35
Dane Springmeyer springmeyer authored
48 include/mapnik/image_filter_grammar.hpp
... ... @@ -0,0 +1,48 @@
  1 +/*****************************************************************************
  2 + *
  3 + * This file is part of Mapnik (c++ mapping toolkit)
  4 + *
  5 + * Copyright (C) 2012 Artem Pavlenko
  6 + *
  7 + * This library is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public
  9 + * License as published by the Free Software Foundation; either
  10 + * version 2.1 of the License, or (at your option) any later version.
  11 + *
  12 + * This library is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15 + * Lesser General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU Lesser General Public
  18 + * License along with this library; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + *****************************************************************************/
  22 +
  23 +#ifndef MAPNIK_IMAGE_FILITER_GRAMMAR_HPP
  24 +#define MAPNIK_IMAGE_FILITER_GRAMMAR_HPP
  25 +
  26 +// boost
  27 +#include <boost/spirit/include/qi.hpp>
  28 +
  29 +// stl
  30 +#include <vector>
  31 +
  32 +namespace mapnik {
  33 +
  34 +namespace qi = boost::spirit::qi;
  35 +
  36 +template <typename Iterator, typename ContType>
  37 +struct image_filter_grammar :
  38 + qi::grammar<Iterator, ContType(), qi::ascii::space_type>
  39 +{
  40 + image_filter_grammar();
  41 + qi::rule<Iterator, ContType(), qi::ascii::space_type> start;
  42 + qi::rule<Iterator, ContType(), qi::locals<int,int>, qi::ascii::space_type> filter;
  43 + qi::uint_parser< unsigned, 10, 1, 3 > radius_;
  44 +};
  45 +
  46 +}
  47 +
  48 +#endif // MAPNIK_IMAGE_FILITER_PARSER_HPP
97 include/mapnik/image_filter_parser.hpp
... ... @@ -1,97 +0,0 @@
1   -/*****************************************************************************
2   - *
3   - * This file is part of Mapnik (c++ mapping toolkit)
4   - *
5   - * Copyright (C) 2012 Artem Pavlenko
6   - *
7   - * This library is free software; you can redistribute it and/or
8   - * modify it under the terms of the GNU Lesser General Public
9   - * License as published by the Free Software Foundation; either
10   - * version 2.1 of the License, or (at your option) any later version.
11   - *
12   - * This library is distributed in the hope that it will be useful,
13   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   - * Lesser General Public License for more details.
16   - *
17   - * You should have received a copy of the GNU Lesser General Public
18   - * License along with this library; if not, write to the Free Software
19   - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20   - *
21   - *****************************************************************************/
22   -
23   -#ifndef MAPNIK_IMAGE_FILITER_PARSER_HPP
24   -#define MAPNIK_IMAGE_FILITER_PARSER_HPP
25   -
26   -#include <mapnik/image_filter.hpp>
27   -#include <boost/spirit/include/qi.hpp>
28   -#include <boost/spirit/include/phoenix.hpp>
29   -#include <vector>
30   -
31   -namespace mapnik {
32   -
33   -namespace qi = boost::spirit::qi;
34   -namespace phoenix = boost::phoenix;
35   -
36   -template <typename Iterator, typename ContType>
37   -struct image_filter_grammar :
38   - qi::grammar<Iterator, ContType(), qi::ascii::space_type>
39   -{
40   - image_filter_grammar()
41   - : image_filter_grammar::base_type(start)
42   - {
43   - using qi::lit;
44   - using qi::_val;
45   - using qi::_1;
46   - using qi::_a;
47   - using qi::_b;
48   - using qi::eps;
49   - using qi::char_;
50   - using phoenix::push_back;
51   - using phoenix::construct;
52   -
53   -#if BOOST_VERSION >= 104700
54   - using qi::no_skip;
55   - start = -(filter % no_skip[*char_(", ")])
56   - ;
57   -#else
58   - start = -(filter)
59   - ;
60   -#endif
61   -
62   - filter =
63   - lit("emboss")[push_back(_val,construct<mapnik::filter::emboss>())]
64   - |
65   - lit("blur")[push_back(_val,construct<mapnik::filter::blur>())]
66   - |
67   - lit("gray")[push_back(_val,construct<mapnik::filter::gray>())]
68   - |
69   - lit("edge-detect")[push_back(_val,construct<mapnik::filter::edge_detect>())]
70   - |
71   - lit("sobel")[push_back(_val,construct<mapnik::filter::sobel>())]
72   - |
73   - lit("sharpen")[push_back(_val,construct<mapnik::filter::sharpen>())]
74   - |
75   - lit("x-gradient")[push_back(_val,construct<mapnik::filter::x_gradient>())]
76   - |
77   - lit("y-gradient")[push_back(_val,construct<mapnik::filter::y_gradient>())]
78   - |
79   - (lit("agg-stack-blur")[_a = 1, _b = 1]
80   - >> -( lit('(') >> radius_[_a = _1]
81   - >> lit(',')
82   - >> radius_[_b = _1]
83   - >> lit(')'))
84   - [push_back(_val,construct<mapnik::filter::agg_stack_blur>(_a,_b))])
85   - |
86   - lit("invert")[push_back(_val,construct<mapnik::filter::invert>())]
87   - ;
88   - }
89   - //
90   - qi::rule<Iterator, ContType(), qi::ascii::space_type> start;
91   - qi::rule<Iterator, ContType(), qi::locals<int,int>, qi::ascii::space_type> filter;
92   - qi::uint_parser< unsigned, 10, 1, 3 > radius_;
93   -};
94   -
95   -}
96   -
97   -#endif // MAPNIK_IMAGE_FILITER_PARSER_HPP
9 include/mapnik/xml_tree.hpp
@@ -22,17 +22,18 @@
22 22
23 23 #ifndef MAPNIK_XML_TREE_H
24 24 #define MAPNIK_XML_TREE_H
25   -//mapnik
  25 +
  26 +// mapnik
26 27 #include <mapnik/xml_node.hpp>
27 28 #include <mapnik/expression_grammar.hpp>
28 29 #include <mapnik/path_expression_grammar.hpp>
29 30 #include <mapnik/transform_expression_grammar.hpp>
  31 +#include <mapnik/image_filter_parser.hpp>
  32 +#include <mapnik/css_color_grammar.hpp>
30 33
31 34 // boost
32 35 #include <boost/format.hpp>
33 36
34   -#include <mapnik/css_color_grammar.hpp>
35   -
36 37 //stl
37 38 #include <string>
38 39
@@ -56,6 +57,8 @@ class xml_tree
56 57 mapnik::expression_grammar<std::string::const_iterator> expr_grammar;
57 58 path_expression_grammar<std::string::const_iterator> path_expr_grammar;
58 59 transform_expression_grammar<std::string::const_iterator> transform_expr_grammar;
  60 + image_filter_grammar<std::string::const_iterator,std::vector<mapnik::filter::filter_type> > image_filters_grammar;
  61 +
59 62 };
60 63
61 64 } //ns mapnik
1  src/build.py
@@ -104,6 +104,7 @@ def ldconfig(*args,**kwargs):
104 104 css_color_grammar.cpp
105 105 conversions.cpp
106 106 image_compositing.cpp
  107 + image_filter_grammar.cpp
107 108 image_scaling.cpp
108 109 box2d.cpp
109 110 building_symbolizer.cpp
91 src/image_filter_grammar.cpp
... ... @@ -0,0 +1,91 @@
  1 +/*****************************************************************************
  2 + *
  3 + * This file is part of Mapnik (c++ mapping toolkit)
  4 + *
  5 + * Copyright (C) 2012 Artem Pavlenko
  6 + *
  7 + * This library is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public
  9 + * License as published by the Free Software Foundation; either
  10 + * version 2.1 of the License, or (at your option) any later version.
  11 + *
  12 + * This library is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15 + * Lesser General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU Lesser General Public
  18 + * License along with this library; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + *****************************************************************************/
  22 +
  23 +// mapnik
  24 +#include <mapnik/image_filter_grammar.hpp>
  25 +#include <mapnik/image_filter.hpp>
  26 +
  27 +// boost
  28 +#include <boost/version.hpp>
  29 +
  30 +// spirit
  31 +#include <boost/spirit/include/phoenix.hpp>
  32 +
  33 +namespace mapnik {
  34 +
  35 +namespace qi = boost::spirit::qi;
  36 +namespace phoenix = boost::phoenix;
  37 +
  38 +template <typename Iterator, typename ContType>
  39 +image_filter_grammar<Iterator,ContType>::image_filter_grammar()
  40 + : image_filter_grammar::base_type(start)
  41 +{
  42 + using qi::lit;
  43 + using qi::_val;
  44 + using qi::_1;
  45 + using qi::_a;
  46 + using qi::_b;
  47 + using qi::eps;
  48 + using qi::char_;
  49 + using phoenix::push_back;
  50 + using phoenix::construct;
  51 +
  52 +#if BOOST_VERSION >= 104700
  53 + using qi::no_skip;
  54 + start = -(filter % no_skip[*char_(", ")])
  55 + ;
  56 +#else
  57 + start = -(filter)
  58 + ;
  59 +#endif
  60 +
  61 + filter =
  62 + lit("emboss")[push_back(_val,construct<mapnik::filter::emboss>())]
  63 + |
  64 + lit("blur")[push_back(_val,construct<mapnik::filter::blur>())]
  65 + |
  66 + lit("gray")[push_back(_val,construct<mapnik::filter::gray>())]
  67 + |
  68 + lit("edge-detect")[push_back(_val,construct<mapnik::filter::edge_detect>())]
  69 + |
  70 + lit("sobel")[push_back(_val,construct<mapnik::filter::sobel>())]
  71 + |
  72 + lit("sharpen")[push_back(_val,construct<mapnik::filter::sharpen>())]
  73 + |
  74 + lit("x-gradient")[push_back(_val,construct<mapnik::filter::x_gradient>())]
  75 + |
  76 + lit("y-gradient")[push_back(_val,construct<mapnik::filter::y_gradient>())]
  77 + |
  78 + (lit("agg-stack-blur")[_a = 1, _b = 1]
  79 + >> -( lit('(') >> radius_[_a = _1]
  80 + >> lit(',')
  81 + >> radius_[_b = _1]
  82 + >> lit(')'))
  83 + [push_back(_val,construct<mapnik::filter::agg_stack_blur>(_a,_b))])
  84 + |
  85 + lit("invert")[push_back(_val,construct<mapnik::filter::invert>())]
  86 + ;
  87 +}
  88 +
  89 +template struct mapnik::image_filter_grammar<std::string::const_iterator,std::vector<mapnik::filter::filter_type> >;
  90 +
  91 +}
8 src/load_map.cpp
@@ -31,7 +31,6 @@
31 31 #include <mapnik/color_factory.hpp>
32 32 #include <mapnik/symbolizer.hpp>
33 33 #include <mapnik/feature_type_style.hpp>
34   -#include <mapnik/image_filter_parser.hpp>
35 34 #include <mapnik/layer.hpp>
36 35 #include <mapnik/datasource_cache.hpp>
37 36 #include <mapnik/font_engine_freetype.hpp>
@@ -427,9 +426,6 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
427 426 }
428 427
429 428 // image filters
430   - mapnik::image_filter_grammar<std::string::const_iterator,
431   - std::vector<mapnik::filter::filter_type> > filter_grammar;
432   -
433 429 optional<std::string> filters = sty.get_opt_attr<std::string>("image-filters");
434 430 if (filters)
435 431 {
@@ -437,7 +433,7 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
437 433 std::string::const_iterator itr = filter_mode.begin();
438 434 std::string::const_iterator end = filter_mode.end();
439 435 bool result = boost::spirit::qi::phrase_parse(itr,end,
440   - filter_grammar,
  436 + sty.get_tree().image_filters_grammar,
441 437 boost::spirit::qi::ascii::space,
442 438 style.image_filters());
443 439 if (!result || itr!=end)
@@ -457,7 +453,7 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
457 453 std::string::const_iterator itr = filter_mode.begin();
458 454 std::string::const_iterator end = filter_mode.end();
459 455 bool result = boost::spirit::qi::phrase_parse(itr,end,
460   - filter_grammar,
  456 + sty.get_tree().image_filters_grammar,
461 457 boost::spirit::qi::ascii::space,
462 458 style.direct_image_filters());
463 459 if (!result || itr!=end)
3  src/xml_tree.cpp
@@ -173,7 +173,8 @@ xml_tree::xml_tree(std::string const& encoding)
173 173 color_grammar(),
174 174 expr_grammar(tr_),
175 175 path_expr_grammar(),
176   - transform_expr_grammar(expr_grammar)
  176 + transform_expr_grammar(expr_grammar),
  177 + image_filters_grammar()
177 178 {
178 179 node_.set_processed(true); //root node is always processed
179 180 }

0 comments on commit bf3efbe

Please sign in to comment.
Something went wrong with that request. Please try again.