split svg_path_grammar
,svg_points_grammar
,svg_transform_grammar
into *.hpp, *_impl.hpp + move boost::phoenix::function initialisation into ctor's
(ref #3343)
This commit is contained in:
parent
f5d6b19fb4
commit
a80c85bff8
10 changed files with 374 additions and 253 deletions
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 Artem Pavlenko
|
||||
* Copyright (C) 2016 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -23,77 +23,21 @@
|
|||
#ifndef MAPNIK_SVG_PATH_GRAMMAR_HPP
|
||||
#define MAPNIK_SVG_PATH_GRAMMAR_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/svg/svg_path_commands.hpp>
|
||||
|
||||
// spirit
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik { namespace svg {
|
||||
|
||||
using namespace boost::spirit;
|
||||
using namespace boost::phoenix;
|
||||
|
||||
template <typename Iterator, typename PathType, typename SkipType>
|
||||
struct svg_path_grammar : qi::grammar<Iterator, void(PathType&), SkipType>
|
||||
{
|
||||
svg_path_grammar()
|
||||
: svg_path_grammar::base_type(start)
|
||||
{
|
||||
qi::_1_type _1;
|
||||
qi::_2_type _2;
|
||||
qi::_3_type _3;
|
||||
qi::_4_type _4;
|
||||
qi::_5_type _5;
|
||||
qi::_a_type _a;
|
||||
qi::lit_type lit;
|
||||
qi::_r1_type _r1;
|
||||
qi::double_type double_;
|
||||
qi::int_type int_;
|
||||
qi::no_case_type no_case;
|
||||
|
||||
start = +cmd(_r1);
|
||||
|
||||
cmd = M(_r1) >> *drawto_cmd(_r1);
|
||||
|
||||
drawto_cmd = L(_r1) | H(_r1) | V(_r1) | C(_r1) | S(_r1) | Q(_r1) | T(_r1) | A(_r1) | Z(_r1);
|
||||
|
||||
M = (lit('M')[_a = false] | lit('m')[_a = true]) >> coord[move_to_(_r1, _1, _a)] // move_to
|
||||
>> *(-lit(',') >> coord[line_to_(_r1, _1, _a)]); // *line_to
|
||||
|
||||
H = (lit('H')[_a = false] | lit('h')[_a = true])
|
||||
>> (double_[ hline_to_(_r1, _1,_a) ] % -lit(',')) ; // +hline_to
|
||||
|
||||
V = (lit('V')[_a = false] | lit('v')[_a = true])
|
||||
>> (double_ [ vline_to_(_r1, _1,_a) ] % -lit(',')); // +vline_to
|
||||
|
||||
L = (lit('L')[_a = false] | lit('l')[_a = true])
|
||||
>> (coord [ line_to_(_r1, _1, _a) ] % -lit(',')); // +line_to
|
||||
|
||||
C = (lit('C')[_a = false] | lit('c')[_a = true])
|
||||
>> ((coord >> -lit(',') >> coord >> -lit(',') >> coord)[curve4_(_r1, _1, _2, _3, _a)] % -lit(',')); // +curve4
|
||||
|
||||
S = (lit('S')[_a = false] | lit('s')[_a = true])
|
||||
>> ((coord >> -lit(',') >> coord) [ curve4_smooth_(_r1, _1,_2,_a) ] % -lit(',')); // +curve4_smooth (smooth curveto)
|
||||
|
||||
Q = (lit('Q')[_a = false] | lit('q')[_a = true])
|
||||
>> ((coord >> -lit(',') >> coord) [ curve3_(_r1, _1,_2,_a) ] % -lit(',')); // +curve3 (quadratic-bezier-curveto)
|
||||
|
||||
T = (lit('T')[_a = false] | lit('t')[_a = true])
|
||||
>> ((coord ) [ curve3_smooth_(_r1, _1,_a) ] % -lit(',')); // +curve3_smooth (smooth-quadratic-bezier-curveto)
|
||||
|
||||
A = (lit('A')[_a = false] | lit('a')[_a = true])
|
||||
>> ((coord >> -lit(',') >> double_ >> -lit(',') >> int_ >> -lit(',') >> int_ >> -lit(',') >> coord)
|
||||
[arc_to_(_r1, _1, _2, _3, _4, _5, _a)] % -lit(',')); // arc_to;
|
||||
|
||||
Z = no_case[lit('z')] [close_(_r1)]; // close path
|
||||
|
||||
coord = double_ >> -lit(',') >> double_;
|
||||
}
|
||||
|
||||
// ctor
|
||||
svg_path_grammar();
|
||||
// rules
|
||||
qi::rule<Iterator, void(PathType&), SkipType> start;
|
||||
qi::rule<Iterator, void(PathType&), SkipType> cmd;
|
||||
|
@ -108,20 +52,7 @@ struct svg_path_grammar : qi::grammar<Iterator, void(PathType&), SkipType>
|
|||
qi::rule<Iterator, qi::locals<bool>, void(PathType&), SkipType> T; // T,t
|
||||
qi::rule<Iterator, qi::locals<bool>, void(PathType&), SkipType> A; // A,a
|
||||
qi::rule<Iterator, void(PathType&), SkipType> Z; // Z,z
|
||||
|
||||
qi::rule<Iterator, boost::fusion::vector2<double, double>(), SkipType> coord;
|
||||
|
||||
// commands
|
||||
function<move_to> move_to_;
|
||||
function<hline_to> hline_to_;
|
||||
function<vline_to> vline_to_;
|
||||
function<line_to> line_to_;
|
||||
function<curve4> curve4_;
|
||||
function<curve4_smooth> curve4_smooth_;
|
||||
function<curve3> curve3_;
|
||||
function<curve3_smooth> curve3_smooth_;
|
||||
function<arc_to> arc_to_;
|
||||
function<close> close_;
|
||||
};
|
||||
|
||||
}}
|
||||
|
|
110
include/mapnik/svg/svg_path_grammar_impl.hpp
Normal file
110
include/mapnik/svg/svg_path_grammar_impl.hpp
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2016 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/svg/svg_path_grammar.hpp>
|
||||
#include <mapnik/svg/svg_path_commands.hpp>
|
||||
|
||||
// spirit
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik { namespace svg {
|
||||
|
||||
using namespace boost::spirit;
|
||||
using namespace boost::phoenix;
|
||||
|
||||
|
||||
template <typename Iterator, typename PathType, typename SkipType>
|
||||
svg_path_grammar<Iterator, PathType, SkipType>::svg_path_grammar()
|
||||
: svg_path_grammar::base_type(start)
|
||||
{
|
||||
qi::_1_type _1;
|
||||
qi::_2_type _2;
|
||||
qi::_3_type _3;
|
||||
qi::_4_type _4;
|
||||
qi::_5_type _5;
|
||||
qi::_a_type _a;
|
||||
qi::lit_type lit;
|
||||
qi::_r1_type _r1;
|
||||
qi::double_type double_;
|
||||
qi::int_type int_;
|
||||
qi::no_case_type no_case;
|
||||
|
||||
// commands
|
||||
function<move_to> move_to_;
|
||||
function<hline_to> hline_to_;
|
||||
function<vline_to> vline_to_;
|
||||
function<line_to> line_to_;
|
||||
function<curve4> curve4_;
|
||||
function<curve4_smooth> curve4_smooth_;
|
||||
function<curve3> curve3_;
|
||||
function<curve3_smooth> curve3_smooth_;
|
||||
function<arc_to> arc_to_;
|
||||
function<close> close_;
|
||||
//
|
||||
start = +cmd(_r1);
|
||||
|
||||
cmd = M(_r1) >> *drawto_cmd(_r1);
|
||||
|
||||
drawto_cmd = L(_r1) | H(_r1) | V(_r1) | C(_r1) | S(_r1) | Q(_r1) | T(_r1) | A(_r1) | Z(_r1);
|
||||
|
||||
M = (lit('M')[_a = false] | lit('m')[_a = true]) >> coord[move_to_(_r1, _1, _a)] // move_to
|
||||
>> *(-lit(',') >> coord[line_to_(_r1, _1, _a)]); // *line_to
|
||||
|
||||
H = (lit('H')[_a = false] | lit('h')[_a = true])
|
||||
>> (double_[ hline_to_(_r1, _1,_a) ] % -lit(',')) ; // +hline_to
|
||||
|
||||
V = (lit('V')[_a = false] | lit('v')[_a = true])
|
||||
>> (double_ [ vline_to_(_r1, _1,_a) ] % -lit(',')); // +vline_to
|
||||
|
||||
L = (lit('L')[_a = false] | lit('l')[_a = true])
|
||||
>> (coord [ line_to_(_r1, _1, _a) ] % -lit(',')); // +line_to
|
||||
|
||||
C = (lit('C')[_a = false] | lit('c')[_a = true])
|
||||
>> ((coord >> -lit(',') >> coord >> -lit(',') >> coord)[curve4_(_r1, _1, _2, _3, _a)] % -lit(',')); // +curve4
|
||||
|
||||
S = (lit('S')[_a = false] | lit('s')[_a = true])
|
||||
>> ((coord >> -lit(',') >> coord) [ curve4_smooth_(_r1, _1,_2,_a) ] % -lit(',')); // +curve4_smooth (smooth curveto)
|
||||
|
||||
Q = (lit('Q')[_a = false] | lit('q')[_a = true])
|
||||
>> ((coord >> -lit(',') >> coord) [ curve3_(_r1, _1,_2,_a) ] % -lit(',')); // +curve3 (quadratic-bezier-curveto)
|
||||
|
||||
T = (lit('T')[_a = false] | lit('t')[_a = true])
|
||||
>> ((coord ) [ curve3_smooth_(_r1, _1,_a) ] % -lit(',')); // +curve3_smooth (smooth-quadratic-bezier-curveto)
|
||||
|
||||
A = (lit('A')[_a = false] | lit('a')[_a = true])
|
||||
>> ((coord >> -lit(',') >> double_ >> -lit(',') >> int_ >> -lit(',') >> int_ >> -lit(',') >> coord)
|
||||
[arc_to_(_r1, _1, _2, _3, _4, _5, _a)] % -lit(',')); // arc_to;
|
||||
|
||||
Z = no_case[lit('z')] [close_(_r1)]; // close path
|
||||
|
||||
coord = double_ >> -lit(',') >> double_;
|
||||
}
|
||||
|
||||
} // namespace svg
|
||||
} // namespace mapnik
|
|
@ -23,20 +23,32 @@
|
|||
#ifndef MAPNIK_SVG_PATH_PARSER_HPP
|
||||
#define MAPNIK_SVG_PATH_PARSER_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/svg/svg_converter.hpp>
|
||||
#include <mapnik/svg/svg_path_attributes.hpp>
|
||||
// stl
|
||||
#include <string>
|
||||
|
||||
namespace mapnik { namespace svg {
|
||||
namespace mapnik {
|
||||
namespace svg {
|
||||
|
||||
template <typename PathType>
|
||||
bool parse_path(const char * wkt, PathType & p);
|
||||
template <typename PathType>
|
||||
bool parse_path(const char* wkt, PathType& p);
|
||||
|
||||
template <typename PathType>
|
||||
bool parse_points(const char * wkt, PathType & p);
|
||||
template <typename PathType>
|
||||
bool parse_points(const char* wkt, PathType& p);
|
||||
|
||||
template <typename TransformType>
|
||||
bool MAPNIK_DECL parse_svg_transform(const char* wkt, TransformType& tr);
|
||||
|
||||
//
|
||||
extern template bool MAPNIK_DECL parse_path<svg_converter_type>(const char*, svg_converter_type&);
|
||||
extern template bool MAPNIK_DECL parse_points<svg_converter_type>(const char*, svg_converter_type&);
|
||||
extern template bool MAPNIK_DECL parse_svg_transform<svg_converter_type>(const char*, svg_converter_type&);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TransformType>
|
||||
bool MAPNIK_DECL parse_svg_transform(const char * wkt, TransformType & tr);
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_SVG_PATH_PARSER_HPP
|
||||
|
|
|
@ -29,9 +29,6 @@
|
|||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik { namespace svg {
|
||||
|
@ -42,31 +39,12 @@ using namespace boost::phoenix;
|
|||
template <typename Iterator, typename PathType, typename SkipType>
|
||||
struct svg_points_grammar : qi::grammar<Iterator, void(PathType&), SkipType>
|
||||
{
|
||||
svg_points_grammar()
|
||||
: svg_points_grammar::base_type(start)
|
||||
{
|
||||
qi::_1_type _1;
|
||||
qi::_r1_type _r1;
|
||||
qi::lit_type lit;
|
||||
qi::double_type double_;
|
||||
|
||||
start = coord[move_to_(_r1, _1, false)] // move_to
|
||||
>> *(-lit(',') >> coord [ line_to_(_r1, _1,false) ] ); // *line_to
|
||||
|
||||
coord = double_ >> -lit(',') >> double_;
|
||||
}
|
||||
|
||||
// ctor
|
||||
svg_points_grammar();
|
||||
// rules
|
||||
qi::rule<Iterator, void(PathType&), SkipType> start;
|
||||
qi::rule<Iterator,boost::fusion::vector2<double,double>(),SkipType> coord;
|
||||
|
||||
// commands
|
||||
function<move_to> move_to_;
|
||||
function<line_to> line_to_;
|
||||
function<close> close_;
|
||||
qi::rule<Iterator, boost::fusion::vector2<double, double>(), SkipType> coord;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
|
||||
#endif // SVG_POINTS_GRAMMAR_HPP
|
||||
|
|
60
include/mapnik/svg/svg_points_grammar_impl.hpp
Normal file
60
include/mapnik/svg/svg_points_grammar_impl.hpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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/svg/svg_points_grammar.hpp>
|
||||
#include <mapnik/svg/svg_path_commands.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik { namespace svg {
|
||||
|
||||
using namespace boost::spirit;
|
||||
using namespace boost::phoenix;
|
||||
|
||||
template <typename Iterator, typename PathType, typename SkipType>
|
||||
svg_points_grammar<Iterator, PathType,SkipType>::svg_points_grammar()
|
||||
: svg_points_grammar::base_type(start)
|
||||
{
|
||||
qi::_1_type _1;
|
||||
qi::_r1_type _r1;
|
||||
qi::lit_type lit;
|
||||
qi::double_type double_;
|
||||
// commands
|
||||
function<move_to> move_to_;
|
||||
function<line_to> line_to_;
|
||||
function<close> close_;
|
||||
|
||||
start = coord[move_to_(_r1, _1, false)] // move_to
|
||||
>> *(-lit(',') >> coord [ line_to_(_r1, _1,false) ] ); // *line_to
|
||||
|
||||
coord = double_ >> -lit(',') >> double_;
|
||||
}
|
||||
|
||||
}}
|
|
@ -26,144 +26,20 @@
|
|||
// mapnik
|
||||
#include <mapnik/global.hpp>
|
||||
|
||||
// agg
|
||||
#include <agg_trans_affine.h>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#include <boost/spirit/include/phoenix_object.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik { namespace svg {
|
||||
|
||||
using namespace boost::spirit;
|
||||
using namespace boost::fusion;
|
||||
using namespace boost::phoenix;
|
||||
|
||||
inline double deg2rad(double d)
|
||||
{
|
||||
return M_PI * d / 180.0;
|
||||
}
|
||||
|
||||
struct process_matrix
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename TransformType>
|
||||
void operator () (TransformType & tr, double a, double b, double c, double d, double e, double f) const
|
||||
{
|
||||
tr = agg::trans_affine(a,b,c,d,e,f) * tr;
|
||||
}
|
||||
};
|
||||
|
||||
struct process_rotate
|
||||
{
|
||||
using result_type = void;
|
||||
|
||||
template <typename TransformType, typename T0,typename T1,typename T2>
|
||||
void operator () (TransformType & tr, T0 a, T1 cx, T2 cy) const
|
||||
{
|
||||
if (cx == 0.0 && cy == 0.0)
|
||||
{
|
||||
tr = agg::trans_affine_rotation(deg2rad(a)) * tr;
|
||||
}
|
||||
else
|
||||
{
|
||||
agg::trans_affine t = agg::trans_affine_translation(-cx,-cy);
|
||||
t *= agg::trans_affine_rotation(deg2rad(a));
|
||||
t *= agg::trans_affine_translation(cx, cy);
|
||||
tr = t * tr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct process_translate
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename TransformType, typename T0,typename T1>
|
||||
void operator () (TransformType & tr, T0 tx, T1 ty) const
|
||||
{
|
||||
if (ty) tr = agg::trans_affine_translation(tx,*ty) * tr;
|
||||
else tr = agg::trans_affine_translation(tx,0.0) * tr;
|
||||
}
|
||||
};
|
||||
|
||||
struct process_scale
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename TransformType, typename T0,typename T1>
|
||||
void operator () (TransformType & tr, T0 sx, T1 sy) const
|
||||
{
|
||||
if (sy) tr = agg::trans_affine_scaling(sx,*sy) * tr;
|
||||
else tr = agg::trans_affine_scaling(sx,sx) * tr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct process_skew
|
||||
{
|
||||
using result_type = void;
|
||||
|
||||
template <typename TransformType, typename T0,typename T1>
|
||||
void operator () (TransformType & tr, T0 skew_x, T1 skew_y) const
|
||||
{
|
||||
tr = agg::trans_affine_skewing(deg2rad(skew_x),deg2rad(skew_y)) * tr;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Iterator, typename TransformType, typename SkipType>
|
||||
struct svg_transform_grammar : qi::grammar<Iterator, void(TransformType&), SkipType>
|
||||
{
|
||||
svg_transform_grammar()
|
||||
: svg_transform_grammar::base_type(start)
|
||||
{
|
||||
qi::_1_type _1;
|
||||
qi::_2_type _2;
|
||||
qi::_3_type _3;
|
||||
qi::_4_type _4;
|
||||
qi::_5_type _5;
|
||||
qi::_6_type _6;
|
||||
qi::_a_type _a;
|
||||
qi::_b_type _b;
|
||||
qi::_c_type _c;
|
||||
qi::_r1_type _r1;
|
||||
qi::lit_type lit;
|
||||
qi::double_type double_;
|
||||
qi::no_case_type no_case;
|
||||
|
||||
start = +transform_(_r1) ;
|
||||
|
||||
transform_ = matrix(_r1) | rotate(_r1) | translate(_r1) | scale(_r1) | rotate(_r1) | skewX(_r1) | skewY (_r1) ;
|
||||
|
||||
matrix = no_case[lit("matrix")] >> lit('(')
|
||||
>> (double_ >> -lit(',')
|
||||
>> double_ >> -lit(',')
|
||||
>> double_ >> -lit(',')
|
||||
>> double_ >> -lit(',')
|
||||
>> double_ >> -lit(',')
|
||||
>> double_)[matrix_action(_r1, _1, _2, _3, _4, _5, _6)] >> lit(')');
|
||||
|
||||
translate = no_case[lit("translate")]
|
||||
>> lit('(') >> (double_ >> -lit(',') >> -double_)[translate_action(_r1, _1, _2)] >> lit(')');
|
||||
|
||||
scale = no_case[lit("scale")]
|
||||
>> lit('(') >> (double_ >> -lit(',') >> -double_)[scale_action(_r1, _1, _2)] >> lit(')');
|
||||
|
||||
rotate = no_case[lit("rotate")]
|
||||
>> lit('(')
|
||||
>> double_[_a = _1] >> -lit(',')
|
||||
>> -(double_ [_b = _1] >> -lit(',') >> double_[_c = _1])
|
||||
>> lit(')') [ rotate_action(_r1, _a,_b,_c)];
|
||||
|
||||
skewX = no_case[lit("skewX")] >> lit('(') >> double_ [ skew_action(_r1, _1, 0.0)] >> lit(')');
|
||||
|
||||
skewY = no_case[lit("skewY")] >> lit('(') >> double_ [ skew_action(_r1, 0.0, _1)] >> lit(')');
|
||||
|
||||
}
|
||||
|
||||
// ctor
|
||||
svg_transform_grammar();
|
||||
// rules
|
||||
qi::rule<Iterator, void(TransformType&), SkipType> start;
|
||||
qi::rule<Iterator, void(TransformType&), SkipType> transform_;
|
||||
|
@ -173,13 +49,6 @@ struct svg_transform_grammar : qi::grammar<Iterator, void(TransformType&), SkipT
|
|||
qi::rule<Iterator, qi::locals<double, double, double>, void(TransformType&), SkipType> rotate;
|
||||
qi::rule<Iterator, void(TransformType&), SkipType> skewX;
|
||||
qi::rule<Iterator, void(TransformType&), SkipType> skewY;
|
||||
|
||||
// actions
|
||||
function<process_matrix> matrix_action;
|
||||
function<process_rotate> rotate_action;
|
||||
function<process_translate> translate_action;
|
||||
function<process_scale> scale_action;
|
||||
function<process_skew> skew_action;
|
||||
};
|
||||
|
||||
}}
|
||||
|
|
167
include/mapnik/svg/svg_transform_grammar_impl.hpp
Normal file
167
include/mapnik/svg/svg_transform_grammar_impl.hpp
Normal file
|
@ -0,0 +1,167 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 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/svg/svg_transform_grammar.hpp>
|
||||
// agg
|
||||
#include <agg_trans_affine.h>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#include <boost/spirit/include/phoenix_object.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik { namespace svg {
|
||||
|
||||
using namespace boost::spirit;
|
||||
using namespace boost::fusion;
|
||||
using namespace boost::phoenix;
|
||||
|
||||
inline double deg2rad(double d)
|
||||
{
|
||||
return M_PI * d / 180.0;
|
||||
}
|
||||
|
||||
struct process_matrix
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename TransformType>
|
||||
void operator () (TransformType & tr, double a, double b, double c, double d, double e, double f) const
|
||||
{
|
||||
tr = agg::trans_affine(a,b,c,d,e,f) * tr;
|
||||
}
|
||||
};
|
||||
|
||||
struct process_rotate
|
||||
{
|
||||
using result_type = void;
|
||||
|
||||
template <typename TransformType, typename T0,typename T1,typename T2>
|
||||
void operator () (TransformType & tr, T0 a, T1 cx, T2 cy) const
|
||||
{
|
||||
if (cx == 0.0 && cy == 0.0)
|
||||
{
|
||||
tr = agg::trans_affine_rotation(deg2rad(a)) * tr;
|
||||
}
|
||||
else
|
||||
{
|
||||
agg::trans_affine t = agg::trans_affine_translation(-cx,-cy);
|
||||
t *= agg::trans_affine_rotation(deg2rad(a));
|
||||
t *= agg::trans_affine_translation(cx, cy);
|
||||
tr = t * tr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct process_translate
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename TransformType, typename T0,typename T1>
|
||||
void operator () (TransformType & tr, T0 tx, T1 ty) const
|
||||
{
|
||||
if (ty) tr = agg::trans_affine_translation(tx,*ty) * tr;
|
||||
else tr = agg::trans_affine_translation(tx,0.0) * tr;
|
||||
}
|
||||
};
|
||||
|
||||
struct process_scale
|
||||
{
|
||||
using result_type = void;
|
||||
template <typename TransformType, typename T0,typename T1>
|
||||
void operator () (TransformType & tr, T0 sx, T1 sy) const
|
||||
{
|
||||
if (sy) tr = agg::trans_affine_scaling(sx,*sy) * tr;
|
||||
else tr = agg::trans_affine_scaling(sx,sx) * tr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct process_skew
|
||||
{
|
||||
using result_type = void;
|
||||
|
||||
template <typename TransformType, typename T0,typename T1>
|
||||
void operator () (TransformType & tr, T0 skew_x, T1 skew_y) const
|
||||
{
|
||||
tr = agg::trans_affine_skewing(deg2rad(skew_x),deg2rad(skew_y)) * tr;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Iterator, typename TransformType, typename SkipType>
|
||||
svg_transform_grammar<Iterator, TransformType, SkipType>::svg_transform_grammar()
|
||||
: svg_transform_grammar::base_type(start)
|
||||
{
|
||||
qi::_1_type _1;
|
||||
qi::_2_type _2;
|
||||
qi::_3_type _3;
|
||||
qi::_4_type _4;
|
||||
qi::_5_type _5;
|
||||
qi::_6_type _6;
|
||||
qi::_a_type _a;
|
||||
qi::_b_type _b;
|
||||
qi::_c_type _c;
|
||||
qi::_r1_type _r1;
|
||||
qi::lit_type lit;
|
||||
qi::double_type double_;
|
||||
qi::no_case_type no_case;
|
||||
|
||||
// actions
|
||||
function<process_matrix> matrix_action;
|
||||
function<process_rotate> rotate_action;
|
||||
function<process_translate> translate_action;
|
||||
function<process_scale> scale_action;
|
||||
function<process_skew> skew_action;
|
||||
|
||||
start = +transform_(_r1) ;
|
||||
|
||||
transform_ = matrix(_r1) | rotate(_r1) | translate(_r1) | scale(_r1) | rotate(_r1) | skewX(_r1) | skewY (_r1) ;
|
||||
|
||||
matrix = no_case[lit("matrix")] >> lit('(')
|
||||
>> (double_ >> -lit(',')
|
||||
>> double_ >> -lit(',')
|
||||
>> double_ >> -lit(',')
|
||||
>> double_ >> -lit(',')
|
||||
>> double_ >> -lit(',')
|
||||
>> double_)[matrix_action(_r1, _1, _2, _3, _4, _5, _6)] >> lit(')');
|
||||
|
||||
translate = no_case[lit("translate")]
|
||||
>> lit('(') >> (double_ >> -lit(',') >> -double_)[translate_action(_r1, _1, _2)] >> lit(')');
|
||||
|
||||
scale = no_case[lit("scale")]
|
||||
>> lit('(') >> (double_ >> -lit(',') >> -double_)[scale_action(_r1, _1, _2)] >> lit(')');
|
||||
|
||||
rotate = no_case[lit("rotate")]
|
||||
>> lit('(')
|
||||
>> double_[_a = _1] >> -lit(',')
|
||||
>> -(double_ [_b = _1] >> -lit(',') >> double_[_c = _1])
|
||||
>> lit(')') [ rotate_action(_r1, _a,_b,_c)];
|
||||
|
||||
skewX = no_case[lit("skewX")] >> lit('(') >> double_ [ skew_action(_r1, _1, 0.0)] >> lit(')');
|
||||
|
||||
skewY = no_case[lit("skewY")] >> lit('(') >> double_ [ skew_action(_r1, 0.0, _1)] >> lit(')');
|
||||
|
||||
}
|
||||
|
||||
}}
|
|
@ -21,14 +21,9 @@
|
|||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/svg/svg_converter.hpp>
|
||||
#include <mapnik/svg/svg_path_attributes.hpp>
|
||||
#include <mapnik/svg/svg_path_grammar.hpp>
|
||||
|
||||
#include <mapnik/svg/svg_path_parser.hpp>
|
||||
|
||||
// agg
|
||||
#include "agg_path_storage.h"
|
||||
|
||||
#include <mapnik/svg/svg_path_grammar_impl.hpp>
|
||||
// stl
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
|
|
@ -22,8 +22,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/svg/svg_path_parser.hpp>
|
||||
#include <mapnik/svg/svg_points_grammar.hpp>
|
||||
#include <mapnik/svg/svg_converter.hpp>
|
||||
#include <mapnik/svg/svg_points_grammar_impl.hpp>
|
||||
// stl
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
//#include <mapnik/svg/svg_path_parser.hpp>
|
||||
#include <mapnik/svg/svg_transform_grammar.hpp>
|
||||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/svg/svg_transform_grammar_impl.hpp>
|
||||
// stl
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
@ -42,7 +42,7 @@ bool parse_svg_transform(const char* wkt, TransformType& tr)
|
|||
return qi::phrase_parse(first, last, (g)(boost::phoenix::ref(tr)), skip_type());
|
||||
}
|
||||
|
||||
template MAPNIK_DECL bool parse_svg_transform<agg::trans_affine>(const char*, agg::trans_affine&);
|
||||
template bool MAPNIK_DECL parse_svg_transform<agg::trans_affine>(const char*, agg::trans_affine&);
|
||||
|
||||
} // namespace svg
|
||||
} // namespace mapnik
|
||||
|
|
Loading…
Reference in a new issue