2012-07-24 03:12:10 +02:00
|
|
|
|
/*****************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*
|
|
|
|
|
*****************************************************************************/
|
2012-08-19 16:20:08 +02:00
|
|
|
|
|
|
|
|
|
// mapnik
|
2012-07-24 03:12:10 +02:00
|
|
|
|
#include <mapnik/transform_expression_grammar.hpp>
|
|
|
|
|
|
2012-08-16 01:45:18 +02:00
|
|
|
|
// boost
|
2013-01-08 23:17:31 +01:00
|
|
|
|
#include <boost/spirit/include/qi.hpp>
|
|
|
|
|
#include <boost/spirit/include/phoenix_operator.hpp>
|
2013-01-15 23:32:29 +01:00
|
|
|
|
#include <boost/spirit/include/phoenix_object.hpp>
|
2012-08-19 16:20:08 +02:00
|
|
|
|
|
2013-01-08 23:17:31 +01:00
|
|
|
|
|
2012-07-24 03:12:10 +02:00
|
|
|
|
namespace mapnik {
|
|
|
|
|
|
|
|
|
|
namespace qi = boost::spirit::qi;
|
|
|
|
|
|
|
|
|
|
template <typename Iterator>
|
2014-04-30 09:11:27 +02:00
|
|
|
|
transform_expression_grammar<Iterator>::transform_expression_grammar()
|
2012-07-24 03:12:10 +02:00
|
|
|
|
: transform_expression_grammar::base_type(start)
|
|
|
|
|
{
|
|
|
|
|
using boost::phoenix::construct;
|
2014-01-26 23:00:58 +01:00
|
|
|
|
qi::_1_type _1;
|
|
|
|
|
qi::_4_type _4;
|
|
|
|
|
qi::_2_type _2;
|
|
|
|
|
qi::_5_type _5;
|
|
|
|
|
qi::_3_type _3;
|
|
|
|
|
qi::_6_type _6;
|
|
|
|
|
qi::_val_type _val;
|
|
|
|
|
qi::char_type char_;
|
|
|
|
|
qi::double_type double_;
|
|
|
|
|
qi::lit_type lit;
|
|
|
|
|
qi::no_case_type no_case;
|
2012-08-19 16:20:08 +02:00
|
|
|
|
|
|
|
|
|
// [http://www.w3.org/TR/SVG/coords.html#TransformAttribute]
|
|
|
|
|
|
|
|
|
|
// The value of the ‘transform’ attribute is a <transform-list>, which
|
|
|
|
|
// is defined as a list of transform definitions, which are applied in
|
|
|
|
|
// the order provided. The individual transform definitions are
|
|
|
|
|
// separated by whitespace and/or a comma.
|
|
|
|
|
|
2014-01-26 23:00:58 +01:00
|
|
|
|
qi::no_skip_type no_skip;
|
2012-07-24 03:12:10 +02:00
|
|
|
|
start = transform_ % no_skip[char_(", ")] ;
|
|
|
|
|
|
|
|
|
|
transform_ = matrix | translate | scale | rotate | skewX | skewY ;
|
|
|
|
|
|
2012-08-19 16:20:08 +02:00
|
|
|
|
// matrix(<a> <b> <c> <d> <e> <f>)
|
2012-07-24 03:12:10 +02:00
|
|
|
|
matrix = no_case[lit("matrix")]
|
|
|
|
|
>> (lit('(')
|
2012-08-19 16:20:08 +02:00
|
|
|
|
>> ( atom >> sep_atom >> sep_atom >> sep_atom >> sep_atom
|
|
|
|
|
>> sep_atom >> lit(')')
|
|
|
|
|
| expr >> sep_expr >> sep_expr >> sep_expr >> sep_expr
|
|
|
|
|
>> sep_expr >> lit(')')
|
|
|
|
|
))
|
2012-07-24 03:12:10 +02:00
|
|
|
|
[ _val = construct<matrix_node>(_1,_2,_3,_4,_5,_6) ];
|
|
|
|
|
|
2012-08-19 16:20:08 +02:00
|
|
|
|
// translate(<tx> [<ty>])
|
2012-07-24 03:12:10 +02:00
|
|
|
|
translate = no_case[lit("translate")]
|
2012-08-19 16:20:08 +02:00
|
|
|
|
>> lit('(')
|
|
|
|
|
>> ( ( atom >> -sep_atom >> lit(')') )
|
|
|
|
|
[ _val = construct<translate_node>(_1,_2) ]
|
|
|
|
|
| ( expr >> -sep_expr >> lit(')') )
|
|
|
|
|
[ _val = construct<translate_node>(_1,_2) ]
|
|
|
|
|
);
|
2012-07-24 03:12:10 +02:00
|
|
|
|
|
2012-08-19 16:20:08 +02:00
|
|
|
|
// scale(<sx> [<sy>])
|
2012-07-24 03:12:10 +02:00
|
|
|
|
scale = no_case[lit("scale")]
|
2012-08-19 16:20:08 +02:00
|
|
|
|
>> lit('(')
|
|
|
|
|
>> ( ( atom >> -sep_atom >> lit(')') )
|
|
|
|
|
[ _val = construct<scale_node>(_1,_2) ]
|
|
|
|
|
| ( expr >> -sep_expr >> lit(')') )
|
|
|
|
|
[ _val = construct<scale_node>(_1,_2) ]
|
|
|
|
|
);
|
2012-07-24 03:12:10 +02:00
|
|
|
|
|
2012-08-19 16:20:08 +02:00
|
|
|
|
// rotate(<rotate-angle> [<cx> <cy>])
|
2012-07-24 03:12:10 +02:00
|
|
|
|
rotate = no_case[lit("rotate")]
|
|
|
|
|
>> lit('(')
|
2012-08-19 16:20:08 +02:00
|
|
|
|
>> ( ( atom >> -( sep_atom >> sep_atom ) >> lit(')') )
|
|
|
|
|
[ _val = construct<rotate_node>(_1,_2) ]
|
|
|
|
|
| ( expr >> -( sep_expr >> sep_expr ) >> lit(')') )
|
|
|
|
|
[ _val = construct<rotate_node>(_1,_2) ]
|
|
|
|
|
);
|
2012-07-24 03:12:10 +02:00
|
|
|
|
|
2012-08-19 16:20:08 +02:00
|
|
|
|
// skewX(<skew-angle>)
|
2012-07-24 03:12:10 +02:00
|
|
|
|
skewX = no_case[lit("skewX")]
|
|
|
|
|
>> lit('(')
|
|
|
|
|
>> expr [ _val = construct<skewX_node>(_1) ]
|
|
|
|
|
>> lit(')');
|
|
|
|
|
|
2012-08-19 16:20:08 +02:00
|
|
|
|
// skewY(<skew-angle>)
|
2012-07-24 03:12:10 +02:00
|
|
|
|
skewY = no_case[lit("skewY")]
|
|
|
|
|
>> lit('(')
|
|
|
|
|
>> expr [ _val = construct<skewY_node>(_1) ]
|
|
|
|
|
>> lit(')');
|
|
|
|
|
|
2012-08-19 16:20:08 +02:00
|
|
|
|
// number or attribute
|
|
|
|
|
atom = double_ [ _val = _1 ]
|
|
|
|
|
| attr [ _val = construct<mapnik::attribute>(_1) ];
|
|
|
|
|
|
|
|
|
|
// Individual arguments in lists consiting solely of numbers and/or
|
|
|
|
|
// attributes are separated by whitespace and/or a comma.
|
|
|
|
|
sep_atom = -lit(',') >> atom [ _val = _1 ];
|
|
|
|
|
|
|
|
|
|
// Individual arguments in lists containing one or more compound
|
|
|
|
|
// expressions are separated by a comma.
|
|
|
|
|
sep_expr = lit(',') >> expr [ _val = _1 ];
|
|
|
|
|
|
2014-04-30 09:11:27 +02:00
|
|
|
|
attr = g_.attr.alias();
|
|
|
|
|
expr = g_.expr.alias();
|
2012-07-24 03:12:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template struct mapnik::transform_expression_grammar<std::string::const_iterator>;
|
|
|
|
|
|
2012-08-19 16:20:08 +02:00
|
|
|
|
}
|