diff --git a/include/mapnik/ctrans.hpp b/include/mapnik/ctrans.hpp index 7186667d1..7f19721db 100644 --- a/include/mapnik/ctrans.hpp +++ b/include/mapnik/ctrans.hpp @@ -100,6 +100,11 @@ struct MAPNIK_DECL coord_transform geom_.rewind(pos); } + unsigned type() const + { + return static_cast(geom_.type()); + } + Geometry const& geom() const { return geom_; diff --git a/include/mapnik/svg/output/svg_generator.hpp b/include/mapnik/svg/output/svg_generator.hpp index b55fa19b8..973f32c75 100644 --- a/include/mapnik/svg/output/svg_generator.hpp +++ b/include/mapnik/svg/output/svg_generator.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -44,11 +45,8 @@ namespace mapnik { namespace svg { template class svg_generator : private boost::noncopyable { - typedef coord_transform path_type; - typedef svg::svg_root_attributes_grammar root_attributes_grammar; typedef svg::svg_rect_attributes_grammar rect_attributes_grammar; - //typedef svg::svg_path_data_grammar path_data_grammar; typedef svg::svg_path_attributes_grammar path_attributes_grammar; typedef svg::svg_path_dash_array_grammar path_dash_array_grammar; @@ -60,7 +58,16 @@ namespace mapnik { namespace svg { void generate_opening_root(root_output_attributes const& root_attributes); void generate_closing_root(); void generate_rect(rect_output_attributes const& rect_attributes); - //void generate_path(path_type const& path, path_output_attributes const& path_attributes); + template + void generate_path(PathType const& path, path_output_attributes const& path_attributes) + { + util::svg_generator svg_path_grammer; + karma::generate(output_iterator_, lit("\n"), path_attributes); + } private: OutputIterator& output_iterator_; diff --git a/include/mapnik/svg/output/svg_output_grammars.hpp b/include/mapnik/svg/output/svg_output_grammars.hpp index 591c5b47d..818624c05 100644 --- a/include/mapnik/svg/output/svg_output_grammars.hpp +++ b/include/mapnik/svg/output/svg_output_grammars.hpp @@ -87,88 +87,11 @@ BOOST_FUSION_ADAPT_STRUCT( (std::string, svg_namespace_url_) ) -/*! - * mapnik::geometry_type is adapted to conform to the concepts - * required by Karma to be recognized as a container of - * attributes for output generation. - */ -/* -namespace boost { namespace spirit { namespace traits { - - typedef mapnik::coord_transform path_type; - - template <> - struct is_container - : mpl::true_ {}; - - template <> - struct container_iterator - { - typedef mapnik::svg::path_iterator_type type; - }; - - template <> - struct begin_container - { - static mapnik::svg::path_iterator_type - call(path_type const& path) - { - return mapnik::svg::path_iterator_type(0, path); - } - }; - - template <> - struct end_container - { - static mapnik::svg::path_iterator_type - call(path_type const& path) - { - return mapnik::svg::path_iterator_type(path); - } - }; -}}} -*/ - namespace mapnik { namespace svg { using namespace boost::spirit; using namespace boost::phoenix; -/* - template - struct svg_path_data_grammar : karma::grammar - { - typedef path_iterator_type::value_type vertex_type; - - explicit svg_path_data_grammar(PathType const& path_type) - : svg_path_data_grammar::base_type(svg_path), - path_type_(path_type) - { - using karma::int_; - using karma::double_; - using repository::confix; - - svg_path = - lit("d=") - << confix('"', '"')[ - -(path_vertex % lit(' '))]; - - path_vertex = - path_vertex_command - << double_ - << lit(' ') - << double_; - - path_vertex_command = &int_(1) << lit('M') | lit('L'); - } - - karma::rule svg_path; - karma::rule path_vertex; - karma::rule path_vertex_command; - - PathType const& path_type_; - }; -*/ template struct svg_path_attributes_grammar : karma::grammar diff --git a/include/mapnik/util/geometry_svg_generator.hpp b/include/mapnik/util/geometry_svg_generator.hpp index b229e73c1..2c9dc0c6c 100644 --- a/include/mapnik/util/geometry_svg_generator.hpp +++ b/include/mapnik/util/geometry_svg_generator.hpp @@ -25,7 +25,8 @@ // mapnik #include -#include +#include // for container stuff +#include // for container stuff #include #include @@ -38,35 +39,84 @@ #include #include #include +#include //#define BOOST_SPIRIT_USE_PHOENIX_V3 1 +/*! + * adapted to conform to the concepts + * required by Karma to be recognized as a container of + * attributes for output generation. + */ +namespace boost { namespace spirit { namespace traits { + +// TODO - this needs to be made generic to any path type +typedef mapnik::coord_transform path_type; + +template <> +struct is_container : mpl::true_ {} ; + +template <> +struct container_iterator +{ + typedef mapnik::util::path_iterator type; +}; + +template <> +struct begin_container +{ + static mapnik::util::path_iterator + call (path_type const& g) + { + return mapnik::util::path_iterator(g); + } +}; + +template <> +struct end_container +{ + static mapnik::util::path_iterator + call (path_type const& g) + { + return mapnik::util::path_iterator(); + } +}; + +}}} + + namespace mapnik { namespace util { namespace karma = boost::spirit::karma; namespace phoenix = boost::phoenix; namespace svg_detail { + + template struct get_type { template struct result { typedef int type; }; - int operator() (geometry_type const& geom) const + int operator() (Geometry const& geom) const { - return (int)geom.type(); + return static_cast(geom.type()); } }; + template struct get_first { - template - struct result { typedef geometry_type::value_type const type; }; + typedef T geometry_type; - geometry_type::value_type const operator() (geometry_type const& geom) const + template + struct result { typedef typename geometry_type::value_type const type; }; + + typename geometry_type::value_type const operator() (geometry_type const& geom) const { - geometry_type::value_type coord; - boost::get<0>(coord) = geom.vertex(0,&boost::get<1>(coord),&boost::get<2>(coord)); + typename geometry_type::value_type coord; + geom.rewind(0); + boost::get<0>(coord) = geom.vertex(&boost::get<1>(coord),&boost::get<2>(coord)); return coord; } }; @@ -80,11 +130,14 @@ namespace mapnik { namespace util { }; } - template + template struct svg_generator : - karma::grammar + karma::grammar { + typedef Geometry geometry_type; + typedef typename boost::remove_pointer::type coord_type; + svg_generator() : svg_generator::base_type(svg) { @@ -102,22 +155,22 @@ namespace mapnik { namespace util { ; svg_point = &uint_ - << lit("cx=\"") << coord_type - << lit("\" cy=\"") << coord_type + << lit("cx=\"") << coordinate + << lit("\" cy=\"") << coordinate << lit('\"') ; linestring = &uint_(mapnik::LineString)[_1 = _type(_val)] - << svg_path + << svg_path << lit('\"') ; polygon = &uint_(mapnik::Polygon)[_1 = _type(_val)] - << svg_path + << svg_path << lit('\"') ; - svg_path %= ((&uint_(mapnik::SEG_MOVETO) << lit('M') + svg_path %= ((&uint_(mapnik::SEG_MOVETO) << lit("d=\"") << lit('M') | &uint_(mapnik::SEG_LINETO) [_a +=1] << karma::string [if_(_a == 1) [_1 = "L" ] ]) - << lit(' ') << coord_type << lit(' ') << coord_type) % lit(' ') + << lit(' ') << coordinate << lit(' ') << coordinate) % lit(' ') ; @@ -129,14 +182,14 @@ namespace mapnik { namespace util { karma::rule linestring; karma::rule polygon; - karma::rule svg_point; + karma::rule svg_point; karma::rule, geometry_type const& ()> svg_path; // phoenix functions - phoenix::function _type; - phoenix::function _first; + phoenix::function > _type; + phoenix::function > _first; // - karma::real_generator > coord_type; + karma::real_generator > coordinate; }; diff --git a/include/mapnik/util/geometry_to_svg.hpp b/include/mapnik/util/geometry_to_svg.hpp index d65d14d6c..d7294d878 100644 --- a/include/mapnik/util/geometry_to_svg.hpp +++ b/include/mapnik/util/geometry_to_svg.hpp @@ -39,7 +39,7 @@ bool to_svg(std::string & svg, mapnik::geometry_type const& geom) { typedef std::back_insert_iterator sink_type; sink_type sink(svg); - svg_generator generator; + svg_generator generator; bool result = karma::generate(sink, generator, geom); return result; } diff --git a/src/svg/output/process_symbolizers.cpp b/src/svg/output/process_symbolizers.cpp index 6c8268a37..8df8472b8 100644 --- a/src/svg/output/process_symbolizers.cpp +++ b/src/svg/output/process_symbolizers.cpp @@ -44,11 +44,11 @@ bool svg_renderer::process(rule::symbolizers const& syms, // generate path output for each geometry of the current feature. for(unsigned i=0; i 1) + geometry_type & geom = feature.get_geometry(i); + if(geom.size() > 0) { - //path_type path(t_, geom, prj_trans); - //generator_.generate_path(path, path_attributes_); + path_type path(t_, geom, prj_trans); + generator_.generate_path(path, path_attributes_); } } diff --git a/src/svg/output/svg_generator.cpp b/src/svg/output/svg_generator.cpp index ffaf5320f..f5d955e07 100644 --- a/src/svg/output/svg_generator.cpp +++ b/src/svg/output/svg_generator.cpp @@ -65,17 +65,5 @@ namespace mapnik { namespace svg { karma::generate(output_iterator_, lit("\n"), rect_attributes); } - /*template - void svg_generator::generate_path(path_type const& path, path_output_attributes const& path_attributes) - { - path_data_grammar data_grammar(path); - path_attributes_grammar attributes_grammar; - path_dash_array_grammar dash_array_grammar; - - karma::generate(output_iterator_, lit("\n"), path_attributes); - }*/ - template class svg_generator >; }}