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