Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@springmeyer springmeyer authored
View
48 include/mapnik/image_filter_grammar.hpp
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ *
+ * This file is part of Mapnik (c++ mapping toolkit)
+ *
+ * Copyright (C) 2012 Artem Pavlenko
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ *****************************************************************************/
+
+#ifndef MAPNIK_IMAGE_FILITER_GRAMMAR_HPP
+#define MAPNIK_IMAGE_FILITER_GRAMMAR_HPP
+
+// boost
+#include <boost/spirit/include/qi.hpp>
+
+// stl
+#include <vector>
+
+namespace mapnik {
+
+namespace qi = boost::spirit::qi;
+
+template <typename Iterator, typename ContType>
+struct image_filter_grammar :
+ qi::grammar<Iterator, ContType(), qi::ascii::space_type>
+{
+ image_filter_grammar();
+ qi::rule<Iterator, ContType(), qi::ascii::space_type> start;
+ qi::rule<Iterator, ContType(), qi::locals<int,int>, qi::ascii::space_type> filter;
+ qi::uint_parser< unsigned, 10, 1, 3 > radius_;
+};
+
+}
+
+#endif // MAPNIK_IMAGE_FILITER_PARSER_HPP
View
97 include/mapnik/image_filter_parser.hpp
@@ -1,97 +0,0 @@
-/*****************************************************************************
- *
- * This file is part of Mapnik (c++ mapping toolkit)
- *
- * Copyright (C) 2012 Artem Pavlenko
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- *****************************************************************************/
-
-#ifndef MAPNIK_IMAGE_FILITER_PARSER_HPP
-#define MAPNIK_IMAGE_FILITER_PARSER_HPP
-
-#include <mapnik/image_filter.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/phoenix.hpp>
-#include <vector>
-
-namespace mapnik {
-
-namespace qi = boost::spirit::qi;
-namespace phoenix = boost::phoenix;
-
-template <typename Iterator, typename ContType>
-struct image_filter_grammar :
- qi::grammar<Iterator, ContType(), qi::ascii::space_type>
-{
- image_filter_grammar()
- : image_filter_grammar::base_type(start)
- {
- using qi::lit;
- using qi::_val;
- using qi::_1;
- using qi::_a;
- using qi::_b;
- using qi::eps;
- using qi::char_;
- using phoenix::push_back;
- using phoenix::construct;
-
-#if BOOST_VERSION >= 104700
- using qi::no_skip;
- start = -(filter % no_skip[*char_(", ")])
- ;
-#else
- start = -(filter)
- ;
-#endif
-
- filter =
- lit("emboss")[push_back(_val,construct<mapnik::filter::emboss>())]
- |
- lit("blur")[push_back(_val,construct<mapnik::filter::blur>())]
- |
- lit("gray")[push_back(_val,construct<mapnik::filter::gray>())]
- |
- lit("edge-detect")[push_back(_val,construct<mapnik::filter::edge_detect>())]
- |
- lit("sobel")[push_back(_val,construct<mapnik::filter::sobel>())]
- |
- lit("sharpen")[push_back(_val,construct<mapnik::filter::sharpen>())]
- |
- lit("x-gradient")[push_back(_val,construct<mapnik::filter::x_gradient>())]
- |
- lit("y-gradient")[push_back(_val,construct<mapnik::filter::y_gradient>())]
- |
- (lit("agg-stack-blur")[_a = 1, _b = 1]
- >> -( lit('(') >> radius_[_a = _1]
- >> lit(',')
- >> radius_[_b = _1]
- >> lit(')'))
- [push_back(_val,construct<mapnik::filter::agg_stack_blur>(_a,_b))])
- |
- lit("invert")[push_back(_val,construct<mapnik::filter::invert>())]
- ;
- }
- //
- qi::rule<Iterator, ContType(), qi::ascii::space_type> start;
- qi::rule<Iterator, ContType(), qi::locals<int,int>, qi::ascii::space_type> filter;
- qi::uint_parser< unsigned, 10, 1, 3 > radius_;
-};
-
-}
-
-#endif // MAPNIK_IMAGE_FILITER_PARSER_HPP
View
9 include/mapnik/xml_tree.hpp
@@ -22,17 +22,18 @@
#ifndef MAPNIK_XML_TREE_H
#define MAPNIK_XML_TREE_H
-//mapnik
+
+// mapnik
#include <mapnik/xml_node.hpp>
#include <mapnik/expression_grammar.hpp>
#include <mapnik/path_expression_grammar.hpp>
#include <mapnik/transform_expression_grammar.hpp>
+#include <mapnik/image_filter_parser.hpp>
+#include <mapnik/css_color_grammar.hpp>
// boost
#include <boost/format.hpp>
-#include <mapnik/css_color_grammar.hpp>
-
//stl
#include <string>
@@ -56,6 +57,8 @@ class xml_tree
mapnik::expression_grammar<std::string::const_iterator> expr_grammar;
path_expression_grammar<std::string::const_iterator> path_expr_grammar;
transform_expression_grammar<std::string::const_iterator> transform_expr_grammar;
+ image_filter_grammar<std::string::const_iterator,std::vector<mapnik::filter::filter_type> > image_filters_grammar;
+
};
} //ns mapnik
View
1  src/build.py
@@ -104,6 +104,7 @@ def ldconfig(*args,**kwargs):
css_color_grammar.cpp
conversions.cpp
image_compositing.cpp
+ image_filter_grammar.cpp
image_scaling.cpp
box2d.cpp
building_symbolizer.cpp
View
91 src/image_filter_grammar.cpp
@@ -0,0 +1,91 @@
+/*****************************************************************************
+ *
+ * This file is part of Mapnik (c++ mapping toolkit)
+ *
+ * Copyright (C) 2012 Artem Pavlenko
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ *****************************************************************************/
+
+// mapnik
+#include <mapnik/image_filter_grammar.hpp>
+#include <mapnik/image_filter.hpp>
+
+// boost
+#include <boost/version.hpp>
+
+// spirit
+#include <boost/spirit/include/phoenix.hpp>
+
+namespace mapnik {
+
+namespace qi = boost::spirit::qi;
+namespace phoenix = boost::phoenix;
+
+template <typename Iterator, typename ContType>
+image_filter_grammar<Iterator,ContType>::image_filter_grammar()
+ : image_filter_grammar::base_type(start)
+{
+ using qi::lit;
+ using qi::_val;
+ using qi::_1;
+ using qi::_a;
+ using qi::_b;
+ using qi::eps;
+ using qi::char_;
+ using phoenix::push_back;
+ using phoenix::construct;
+
+#if BOOST_VERSION >= 104700
+ using qi::no_skip;
+ start = -(filter % no_skip[*char_(", ")])
+ ;
+#else
+ start = -(filter)
+ ;
+#endif
+
+ filter =
+ lit("emboss")[push_back(_val,construct<mapnik::filter::emboss>())]
+ |
+ lit("blur")[push_back(_val,construct<mapnik::filter::blur>())]
+ |
+ lit("gray")[push_back(_val,construct<mapnik::filter::gray>())]
+ |
+ lit("edge-detect")[push_back(_val,construct<mapnik::filter::edge_detect>())]
+ |
+ lit("sobel")[push_back(_val,construct<mapnik::filter::sobel>())]
+ |
+ lit("sharpen")[push_back(_val,construct<mapnik::filter::sharpen>())]
+ |
+ lit("x-gradient")[push_back(_val,construct<mapnik::filter::x_gradient>())]
+ |
+ lit("y-gradient")[push_back(_val,construct<mapnik::filter::y_gradient>())]
+ |
+ (lit("agg-stack-blur")[_a = 1, _b = 1]
+ >> -( lit('(') >> radius_[_a = _1]
+ >> lit(',')
+ >> radius_[_b = _1]
+ >> lit(')'))
+ [push_back(_val,construct<mapnik::filter::agg_stack_blur>(_a,_b))])
+ |
+ lit("invert")[push_back(_val,construct<mapnik::filter::invert>())]
+ ;
+}
+
+template struct mapnik::image_filter_grammar<std::string::const_iterator,std::vector<mapnik::filter::filter_type> >;
+
+}
View
8 src/load_map.cpp
@@ -31,7 +31,6 @@
#include <mapnik/color_factory.hpp>
#include <mapnik/symbolizer.hpp>
#include <mapnik/feature_type_style.hpp>
-#include <mapnik/image_filter_parser.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp>
@@ -427,9 +426,6 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
}
// image filters
- mapnik::image_filter_grammar<std::string::const_iterator,
- std::vector<mapnik::filter::filter_type> > filter_grammar;
-
optional<std::string> filters = sty.get_opt_attr<std::string>("image-filters");
if (filters)
{
@@ -437,7 +433,7 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
std::string::const_iterator itr = filter_mode.begin();
std::string::const_iterator end = filter_mode.end();
bool result = boost::spirit::qi::phrase_parse(itr,end,
- filter_grammar,
+ sty.get_tree().image_filters_grammar,
boost::spirit::qi::ascii::space,
style.image_filters());
if (!result || itr!=end)
@@ -457,7 +453,7 @@ void map_parser::parse_style(Map & map, xml_node const& sty)
std::string::const_iterator itr = filter_mode.begin();
std::string::const_iterator end = filter_mode.end();
bool result = boost::spirit::qi::phrase_parse(itr,end,
- filter_grammar,
+ sty.get_tree().image_filters_grammar,
boost::spirit::qi::ascii::space,
style.direct_image_filters());
if (!result || itr!=end)
View
3  src/xml_tree.cpp
@@ -173,7 +173,8 @@ xml_tree::xml_tree(std::string const& encoding)
color_grammar(),
expr_grammar(tr_),
path_expr_grammar(),
- transform_expr_grammar(expr_grammar)
+ transform_expr_grammar(expr_grammar),
+ image_filters_grammar()
{
node_.set_processed(true); //root node is always processed
}
Please sign in to comment.
Something went wrong with that request. Please try again.