From 9af87ba8db9458a0dbe25978e3e23e774b619fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20L=C3=B3pez?= Date: Fri, 30 Jul 2010 18:40:41 +0000 Subject: [PATCH] SVG generator outputs path vertices in user coordinates. --- .../mapnik/svg/svg_generator_path_grammar.hpp | 72 ++++++++++++++++++- src/SConscript | 2 +- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/include/mapnik/svg/svg_generator_path_grammar.hpp b/include/mapnik/svg/svg_generator_path_grammar.hpp index 343b0060c..0646e970c 100644 --- a/include/mapnik/svg/svg_generator_path_grammar.hpp +++ b/include/mapnik/svg/svg_generator_path_grammar.hpp @@ -29,14 +29,18 @@ #include // boost -#include #include +#include +#include +#include BOOST_FUSION_ADAPT_CLASS( mapnik::vertex_vector2::vertex_type, (unsigned, unsigned, obj.get<2>(), /**/) (mapnik::vertex_vector2::value_type, mapnik::vertex_vector2::value_type, obj.get<0>(), /**/) (mapnik::vertex_vector2::value_type, mapnik::vertex_vector2::value_type, obj.get<1>(), /**/) + (mapnik::vertex_vector2::value_type, mapnik::vertex_vector2::value_type, obj.get<0>(), /**/) + (mapnik::vertex_vector2::value_type, mapnik::vertex_vector2::value_type, obj.get<1>(), /**/) ) namespace boost { namespace spirit { namespace traits { @@ -76,20 +80,82 @@ namespace boost { namespace spirit { namespace traits { namespace mapnik { namespace svg { using namespace boost::spirit; + using namespace boost::phoenix; + + template + struct path_coordinate_transformer + { + explicit path_coordinate_transformer(PathType const& path_type) + : path_type_(path_type), + current_x_(0.0), + current_y_(0.0) + {} + + void set_current_x(double& x) + { + current_x_ = x; + } + + void set_current_y(double& y) + { + current_y_ = y; + path_type_.vertex(¤t_x_, ¤t_y_); + } + + void current_x(double& x) const + { + x = current_x_; + } + + void current_y(double& y) const + { + y = current_y_; + } + + PathType const& path_type_; + double current_x_; + double current_y_; + }; template struct svg_generator_path_grammar : karma::grammar { + typedef path_coordinate_transformer coordinate_transformer; + typedef mapnik::vertex_vector2::vertex_type vertex_type; + typedef mapnik::vertex_vector2::value_type vertex_component_type; + explicit svg_generator_path_grammar(PathType const& path_type) : svg_generator_path_grammar::base_type(svg_path), - path_type_(path_type) + path_type_(path_type), + ct_(path_type) { - svg_path = *(karma::int_ << karma::lit(' ') << karma::double_ << karma::lit(' ') << karma::double_ << karma::eol); + using karma::int_; + using karma::double_; + using karma::eol; + using karma::omit; + using karma::_1; + using karma::_a; + + svg_path = *(path_vertex); + path_vertex = int_ + << omit[path_vertex_component_x] << omit[path_vertex_component_y] + << path_vertex_transformed_x + << ' ' + << path_vertex_transformed_y + << eol; + path_vertex_component_x = double_[_1 = _a][bind(&coordinate_transformer::set_current_x, &ct_, _a)][_a = _val]; + path_vertex_component_y = double_[_1 = _a][bind(&coordinate_transformer::set_current_y, &ct_, _a)][_a = _val]; + path_vertex_transformed_x = double_[_1 = _a][bind(&coordinate_transformer::current_x, &ct_, _a)]; + path_vertex_transformed_y = double_[_1 = _a][bind(&coordinate_transformer::current_y, &ct_, _a)]; } karma::rule svg_path; + karma::rule path_vertex; + karma::rule > path_vertex_component_x, path_vertex_component_y; + karma::rule > path_vertex_transformed_x, path_vertex_transformed_y; PathType const& path_type_; + coordinate_transformer ct_; }; }} diff --git a/src/SConscript b/src/SConscript index 57277163d..32b5d4617 100644 --- a/src/SConscript +++ b/src/SConscript @@ -190,6 +190,7 @@ if env['SVG_RENDERER']: # svg backend source += Split( """ svg/svg_renderer.cpp + svg/svg_generator.cpp svg/process_building_symbolizer.cpp svg/process_glyph_symbolizer.cpp svg/process_line_pattern_symbolizer.cpp @@ -201,7 +202,6 @@ if env['SVG_RENDERER']: # svg backend svg/process_raster_symbolizer.cpp svg/process_shield_symbolizer.cpp svg/process_text_symbolizer.cpp - svg/svg_generator.cpp """) mapnik = env.SharedLibrary('mapnik2', source, LIBS=libraries, LINKFLAGS=linkflags)