1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_SMILFUNCTIONPARSER_HXX
29*cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_SMILFUNCTIONPARSER_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "expressionnode.hxx"
32*cdf0e10cSrcweir #include "slideshowexceptions.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <boost/noncopyable.hpp>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir namespace rtl
39*cdf0e10cSrcweir {
40*cdf0e10cSrcweir     class OUString;
41*cdf0e10cSrcweir }
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir /* Definition of SmilFunctionParser class */
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace slideshow
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir     namespace internal
48*cdf0e10cSrcweir     {
49*cdf0e10cSrcweir         class SmilFunctionParser : private boost::noncopyable
50*cdf0e10cSrcweir         {
51*cdf0e10cSrcweir         public:
52*cdf0e10cSrcweir             /** Parse a string containing a SMIL value.
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir             	This method parses a string representing
55*cdf0e10cSrcweir                 a fixed value (i.e. a value that does not
56*cdf0e10cSrcweir                 change by time). Due to the dynamic view
57*cdf0e10cSrcweir                 capabilities of the presentation engine,
58*cdf0e10cSrcweir                 this value can sometimes only be determined
59*cdf0e10cSrcweir                 during runtime of the animation (because
60*cdf0e10cSrcweir                 e.g. mixed screen/view coordinates are
61*cdf0e10cSrcweir                 involved), and is thus still returned as an
62*cdf0e10cSrcweir                 ExpressionNode object. An example for
63*cdf0e10cSrcweir                 such a case is the "Width+1.0" string, which
64*cdf0e10cSrcweir                 contains the width of the shape in user
65*cdf0e10cSrcweir                 coordinate space, and the screen width
66*cdf0e10cSrcweir                 in device coordinate space.
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir                 The following grammar is accepted by this method:
69*cdf0e10cSrcweir                 <code>
70*cdf0e10cSrcweir                identifier = 'pi'|'e'|'X'|'Y'|'Width'|'Height'
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir                function = 'abs'|'sqrt'|'sin'|'cos'|'tan'|'atan'|'acos'|'asin'|'exp'|'log'
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir                basic_expression =
75*cdf0e10cSrcweir                				 number |
76*cdf0e10cSrcweir                				 identifier |
77*cdf0e10cSrcweir                				 function '(' additive_expression ')' |
78*cdf0e10cSrcweir                				 '(' additive_expression ')'
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir                unary_expression =
81*cdf0e10cSrcweir                					'-' basic_expression |
82*cdf0e10cSrcweir                                 basic_expression
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir                multiplicative_expression =
85*cdf0e10cSrcweir                				    unary_expression ( ( '*' unary_expression )* |
86*cdf0e10cSrcweir                                 				   ( '/' unary_expression )* )
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir                additive_expression =
89*cdf0e10cSrcweir                					multiplicative_expression ( ( '+' multiplicative_expression )* |
90*cdf0e10cSrcweir                											    ( '-' multiplicative_expression )* )
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir                 </code>
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir                 @param rSmilValue
95*cdf0e10cSrcweir                 The string to parse
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir                 @param rRelativeShapeBounds
98*cdf0e10cSrcweir                 The bounds of the shape this SMIL value is to be
99*cdf0e10cSrcweir                 evaluated for. The bounds must be <em>relative</em> to
100*cdf0e10cSrcweir                 the page the shape is part of, i.e. within the [0,1]
101*cdf0e10cSrcweir                 range. This is necessary, since the string might
102*cdf0e10cSrcweir                 contain symbolic references to the shape bounding box.
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir                 @throws ParseError if an invalid expression is given.
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir                 @return the generated function object.
107*cdf0e10cSrcweir              */
108*cdf0e10cSrcweir             static ExpressionNodeSharedPtr parseSmilValue( const ::rtl::OUString& 			rSmilValue,
109*cdf0e10cSrcweir                                                            const ::basegfx::B2DRectangle&	rRelativeShapeBounds ); // throw ParseError
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir             /** Parse a string containing a SMIL function.
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir             	This method parses a string representing
114*cdf0e10cSrcweir                 a possibly time-varying SMIL function.
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir                 The following grammar is accepted by this method:
117*cdf0e10cSrcweir                 <code>
118*cdf0e10cSrcweir                identifier = 't'|'pi'|'e'|'X'|'Y'|'Width'|'Height'
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir                function = 'abs'|'sqrt'|'sin'|'cos'|'tan'|'atan'|'acos'|'asin'|'exp'|'log'
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir                basic_expression =
123*cdf0e10cSrcweir                				 number |
124*cdf0e10cSrcweir                				 identifier |
125*cdf0e10cSrcweir                				 function '(' additive_expression ')' |
126*cdf0e10cSrcweir                				 '(' additive_expression ')'
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir                unary_expression =
129*cdf0e10cSrcweir                					'-' basic_expression |
130*cdf0e10cSrcweir                                 basic_expression
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir                multiplicative_expression =
133*cdf0e10cSrcweir                				    unary_expression ( ( '*' unary_expression )* |
134*cdf0e10cSrcweir                                 				   ( '/' unary_expression )* )
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir                additive_expression =
137*cdf0e10cSrcweir                					multiplicative_expression ( ( '+' multiplicative_expression )* |
138*cdf0e10cSrcweir                											    ( '-' multiplicative_expression )* )
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir                 </code>
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir                 @param rSmilFunction
143*cdf0e10cSrcweir                 The string to parse
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir                 @param rRelativeShapeBounds
146*cdf0e10cSrcweir                 The bounds of the shape this SMIL value is to be
147*cdf0e10cSrcweir                 evaluated for. The bounds must be <em>relative</em> to
148*cdf0e10cSrcweir                 the page the shape is part of, i.e. within the [0,1]
149*cdf0e10cSrcweir                 range. This is necessary, since the string might
150*cdf0e10cSrcweir                 contain symbolic references to the shape bounding box.
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir                 @throws ParseError if an invalid expression is given.
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir                 @return the generated function object.
155*cdf0e10cSrcweir              */
156*cdf0e10cSrcweir             static ExpressionNodeSharedPtr parseSmilFunction( const ::rtl::OUString& 			rSmilFunction,
157*cdf0e10cSrcweir                                                               const ::basegfx::B2DRectangle&	rRelativeShapeBounds ); // throw ParseError
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir         private:
160*cdf0e10cSrcweir             // disabled constructor/destructor, since this is
161*cdf0e10cSrcweir             // supposed to be a singleton
162*cdf0e10cSrcweir             SmilFunctionParser();
163*cdf0e10cSrcweir         };
164*cdf0e10cSrcweir     }
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_SMILFUNCTIONPARSER_HXX */
168