From 9f89ce17a6bd5d24bc9663a12e4b091f3d1ba23a Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Fri, 9 Dec 2011 11:28:41 +0000 Subject: [PATCH 1/2] + increase coordinates precision --- include/mapnik/util/geometry_wkt_generator.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/mapnik/util/geometry_wkt_generator.hpp b/include/mapnik/util/geometry_wkt_generator.hpp index 38ce28a02..7ff923ce0 100644 --- a/include/mapnik/util/geometry_wkt_generator.hpp +++ b/include/mapnik/util/geometry_wkt_generator.hpp @@ -78,6 +78,7 @@ struct coordinate_policy : karma::real_policies { typedef boost::spirit::karma::real_policies base_type; static int floatfield(T n) { return base_type::fmtflags::fixed; } + static unsigned precision(T n) { return 6u ;} }; From 05fbb2b6462a04fac434e89550eb47e7a8671c60 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Fri, 9 Dec 2011 11:29:34 +0000 Subject: [PATCH 2/2] SVG generator impl --- .../mapnik/util/geometry_svg_generator.hpp | 105 ++++++++++++++++-- 1 file changed, 93 insertions(+), 12 deletions(-) diff --git a/include/mapnik/util/geometry_svg_generator.hpp b/include/mapnik/util/geometry_svg_generator.hpp index e69070148..22337ed1c 100644 --- a/include/mapnik/util/geometry_svg_generator.hpp +++ b/include/mapnik/util/geometry_svg_generator.hpp @@ -30,7 +30,6 @@ #include #include #include - // boost #include #include @@ -38,6 +37,8 @@ #include #include #include +#include +#include //#define BOOST_SPIRIT_USE_PHOENIX_V3 1 @@ -46,20 +47,100 @@ namespace mapnik { namespace util { namespace karma = boost::spirit::karma; namespace phoenix = boost::phoenix; -template -bool generate_svg (OutputIterator sink, mapnik::geometry_type const& geom) +namespace detail { +struct get_type { - using boost::spirit::karma::double_; - using boost::spirit::karma::uint_; - using boost::spirit::karma::generate; - return generate (sink, - // begin grammar - ((&uint_(mapnik::SEG_MOVETO) << 'M' | 'L') - << " " << double_ << " " << double_) % ' ' - // end grammar - , geom); + template + struct result { typedef int type; }; + + int operator() (geometry_type const& geom) const + { + return (int)geom.type(); + } +}; + +struct get_first +{ + template + struct result { typedef geometry_type::value_type const type; }; + + geometry_type::value_type const operator() (geometry_type const& geom) const + { + geometry_type::value_type coord; + boost::get<0>(coord) = geom.get_vertex(0,&boost::get<1>(coord),&boost::get<2>(coord)); + return coord; + } +}; + +template +struct coordinate_policy : karma::real_policies +{ + typedef boost::spirit::karma::real_policies base_type; + static int floatfield(T n) { return base_type::fmtflags::fixed; } + static unsigned precision(T n) { return 6u ;} +}; } +template +struct svg_generator : + karma::grammar +{ + + svg_generator() + : svg_generator::base_type(svg) + { + using boost::spirit::karma::uint_; + using boost::spirit::karma::_val; + using boost::spirit::karma::_1; + using boost::spirit::karma::lit; + using boost::spirit::karma::_a; + + svg = point | linestring | polygon + ; + + point = &uint_(mapnik::Point)[_1 = _type(_val)] + << svg_point [_1 = _first(_val)] + ; + + svg_point = &uint_ + << lit("cx=\"") << coord_type + << lit("\" cy=\"") << coord_type + << lit('\"') + ; + + linestring = &uint_(mapnik::LineString)[_1 = _type(_val)] + << svg_path + ; + + polygon = &uint_(mapnik::Polygon)[_1 = _type(_val)] + << svg_path + ; + + svg_path %= ((&uint_(mapnik::SEG_MOVETO) << lit('M') + | &uint_(mapnik::SEG_LINETO) [_a +=1] << karma::string [if_(_a == 1) [_1 = "L" ] ]) + << lit(' ') << coord_type << lit(' ') << coord_type) % lit(' ') + ; + + + + } + // rules + karma::rule svg; + karma::rule point; + karma::rule linestring; + karma::rule polygon; + + karma::rule svg_point; + karma::rule, geometry_type const& ()> svg_path; + + // phoenix functions + phoenix::function _type; + phoenix::function _first; + // + karma::real_generator > coord_type; + +}; + }} #endif // MAPNIK_GEOMETRY_SVG_GENERATOR_HPP