1*aaef562fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*aaef562fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*aaef562fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*aaef562fSAndrew Rist  * distributed with this work for additional information
6*aaef562fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*aaef562fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*aaef562fSAndrew Rist  * "License"); you may not use this file except in compliance
9*aaef562fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*aaef562fSAndrew Rist  *
11*aaef562fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*aaef562fSAndrew Rist  *
13*aaef562fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*aaef562fSAndrew Rist  * software distributed under the License is distributed on an
15*aaef562fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*aaef562fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*aaef562fSAndrew Rist  * specific language governing permissions and limitations
18*aaef562fSAndrew Rist  * under the License.
19*aaef562fSAndrew Rist  *
20*aaef562fSAndrew Rist  *************************************************************/
21*aaef562fSAndrew Rist 
22*aaef562fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_SMILFUNCTIONPARSER_HXX
25cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_SMILFUNCTIONPARSER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "expressionnode.hxx"
28cdf0e10cSrcweir #include "slideshowexceptions.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <basegfx/range/b2drectangle.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <boost/noncopyable.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace rtl
35cdf0e10cSrcweir {
36cdf0e10cSrcweir     class OUString;
37cdf0e10cSrcweir }
38cdf0e10cSrcweir 
39cdf0e10cSrcweir /* Definition of SmilFunctionParser class */
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace slideshow
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     namespace internal
44cdf0e10cSrcweir     {
45cdf0e10cSrcweir         class SmilFunctionParser : private boost::noncopyable
46cdf0e10cSrcweir         {
47cdf0e10cSrcweir         public:
48cdf0e10cSrcweir             /** Parse a string containing a SMIL value.
49cdf0e10cSrcweir 
50cdf0e10cSrcweir             	This method parses a string representing
51cdf0e10cSrcweir                 a fixed value (i.e. a value that does not
52cdf0e10cSrcweir                 change by time). Due to the dynamic view
53cdf0e10cSrcweir                 capabilities of the presentation engine,
54cdf0e10cSrcweir                 this value can sometimes only be determined
55cdf0e10cSrcweir                 during runtime of the animation (because
56cdf0e10cSrcweir                 e.g. mixed screen/view coordinates are
57cdf0e10cSrcweir                 involved), and is thus still returned as an
58cdf0e10cSrcweir                 ExpressionNode object. An example for
59cdf0e10cSrcweir                 such a case is the "Width+1.0" string, which
60cdf0e10cSrcweir                 contains the width of the shape in user
61cdf0e10cSrcweir                 coordinate space, and the screen width
62cdf0e10cSrcweir                 in device coordinate space.
63cdf0e10cSrcweir 
64cdf0e10cSrcweir                 The following grammar is accepted by this method:
65cdf0e10cSrcweir                 <code>
66cdf0e10cSrcweir                identifier = 'pi'|'e'|'X'|'Y'|'Width'|'Height'
67cdf0e10cSrcweir 
68cdf0e10cSrcweir                function = 'abs'|'sqrt'|'sin'|'cos'|'tan'|'atan'|'acos'|'asin'|'exp'|'log'
69cdf0e10cSrcweir 
70cdf0e10cSrcweir                basic_expression =
71cdf0e10cSrcweir                				 number |
72cdf0e10cSrcweir                				 identifier |
73cdf0e10cSrcweir                				 function '(' additive_expression ')' |
74cdf0e10cSrcweir                				 '(' additive_expression ')'
75cdf0e10cSrcweir 
76cdf0e10cSrcweir                unary_expression =
77cdf0e10cSrcweir                					'-' basic_expression |
78cdf0e10cSrcweir                                 basic_expression
79cdf0e10cSrcweir 
80cdf0e10cSrcweir                multiplicative_expression =
81cdf0e10cSrcweir                				    unary_expression ( ( '*' unary_expression )* |
82cdf0e10cSrcweir                                 				   ( '/' unary_expression )* )
83cdf0e10cSrcweir 
84cdf0e10cSrcweir                additive_expression =
85cdf0e10cSrcweir                					multiplicative_expression ( ( '+' multiplicative_expression )* |
86cdf0e10cSrcweir                											    ( '-' multiplicative_expression )* )
87cdf0e10cSrcweir 
88cdf0e10cSrcweir                 </code>
89cdf0e10cSrcweir 
90cdf0e10cSrcweir                 @param rSmilValue
91cdf0e10cSrcweir                 The string to parse
92cdf0e10cSrcweir 
93cdf0e10cSrcweir                 @param rRelativeShapeBounds
94cdf0e10cSrcweir                 The bounds of the shape this SMIL value is to be
95cdf0e10cSrcweir                 evaluated for. The bounds must be <em>relative</em> to
96cdf0e10cSrcweir                 the page the shape is part of, i.e. within the [0,1]
97cdf0e10cSrcweir                 range. This is necessary, since the string might
98cdf0e10cSrcweir                 contain symbolic references to the shape bounding box.
99cdf0e10cSrcweir 
100cdf0e10cSrcweir                 @throws ParseError if an invalid expression is given.
101cdf0e10cSrcweir 
102cdf0e10cSrcweir                 @return the generated function object.
103cdf0e10cSrcweir              */
104cdf0e10cSrcweir             static ExpressionNodeSharedPtr parseSmilValue( const ::rtl::OUString& 			rSmilValue,
105cdf0e10cSrcweir                                                            const ::basegfx::B2DRectangle&	rRelativeShapeBounds ); // throw ParseError
106cdf0e10cSrcweir 
107cdf0e10cSrcweir             /** Parse a string containing a SMIL function.
108cdf0e10cSrcweir 
109cdf0e10cSrcweir             	This method parses a string representing
110cdf0e10cSrcweir                 a possibly time-varying SMIL function.
111cdf0e10cSrcweir 
112cdf0e10cSrcweir                 The following grammar is accepted by this method:
113cdf0e10cSrcweir                 <code>
114cdf0e10cSrcweir                identifier = 't'|'pi'|'e'|'X'|'Y'|'Width'|'Height'
115cdf0e10cSrcweir 
116cdf0e10cSrcweir                function = 'abs'|'sqrt'|'sin'|'cos'|'tan'|'atan'|'acos'|'asin'|'exp'|'log'
117cdf0e10cSrcweir 
118cdf0e10cSrcweir                basic_expression =
119cdf0e10cSrcweir                				 number |
120cdf0e10cSrcweir                				 identifier |
121cdf0e10cSrcweir                				 function '(' additive_expression ')' |
122cdf0e10cSrcweir                				 '(' additive_expression ')'
123cdf0e10cSrcweir 
124cdf0e10cSrcweir                unary_expression =
125cdf0e10cSrcweir                					'-' basic_expression |
126cdf0e10cSrcweir                                 basic_expression
127cdf0e10cSrcweir 
128cdf0e10cSrcweir                multiplicative_expression =
129cdf0e10cSrcweir                				    unary_expression ( ( '*' unary_expression )* |
130cdf0e10cSrcweir                                 				   ( '/' unary_expression )* )
131cdf0e10cSrcweir 
132cdf0e10cSrcweir                additive_expression =
133cdf0e10cSrcweir                					multiplicative_expression ( ( '+' multiplicative_expression )* |
134cdf0e10cSrcweir                											    ( '-' multiplicative_expression )* )
135cdf0e10cSrcweir 
136cdf0e10cSrcweir                 </code>
137cdf0e10cSrcweir 
138cdf0e10cSrcweir                 @param rSmilFunction
139cdf0e10cSrcweir                 The string to parse
140cdf0e10cSrcweir 
141cdf0e10cSrcweir                 @param rRelativeShapeBounds
142cdf0e10cSrcweir                 The bounds of the shape this SMIL value is to be
143cdf0e10cSrcweir                 evaluated for. The bounds must be <em>relative</em> to
144cdf0e10cSrcweir                 the page the shape is part of, i.e. within the [0,1]
145cdf0e10cSrcweir                 range. This is necessary, since the string might
146cdf0e10cSrcweir                 contain symbolic references to the shape bounding box.
147cdf0e10cSrcweir 
148cdf0e10cSrcweir                 @throws ParseError if an invalid expression is given.
149cdf0e10cSrcweir 
150cdf0e10cSrcweir                 @return the generated function object.
151cdf0e10cSrcweir              */
152cdf0e10cSrcweir             static ExpressionNodeSharedPtr parseSmilFunction( const ::rtl::OUString& 			rSmilFunction,
153cdf0e10cSrcweir                                                               const ::basegfx::B2DRectangle&	rRelativeShapeBounds ); // throw ParseError
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         private:
156cdf0e10cSrcweir             // disabled constructor/destructor, since this is
157cdf0e10cSrcweir             // supposed to be a singleton
158cdf0e10cSrcweir             SmilFunctionParser();
159cdf0e10cSrcweir         };
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_SMILFUNCTIONPARSER_HXX */
164