1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVX_ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
21 #define INCLUDED_SVX_ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
23 #include <sal/config.h>
24 #include <com/sun/star/drawing/EnhancedCustomShapeParameter.hpp>
29 #include <svx/svxdllapi.h>
31 struct EnhancedCustomShapeEquation
36 EnhancedCustomShapeEquation() :
39 nPara
[ 0 ] = nPara
[ 1 ] = nPara
[ 2 ] = 0;
43 class EnhancedCustomShape2d
;
45 namespace EnhancedCustomShape
{
47 enum class ExpressionFunct
86 template< typename charT
, typename traits
>
87 inline std::basic_ostream
<charT
, traits
> & operator <<(
88 std::basic_ostream
<charT
, traits
> & stream
, const ExpressionFunct
& eFunc
)
92 case ExpressionFunct::Const
: return stream
<< "const";
94 case ExpressionFunct::EnumPi
: return stream
<< "pi";
95 case ExpressionFunct::EnumLeft
: return stream
<< "left";
96 case ExpressionFunct::EnumTop
: return stream
<< "top";
97 case ExpressionFunct::EnumRight
: return stream
<< "right";
98 case ExpressionFunct::EnumBottom
: return stream
<< "bottom";
99 case ExpressionFunct::EnumXStretch
: return stream
<< "xstretch";
100 case ExpressionFunct::EnumYStretch
: return stream
<< "ystretch";
101 case ExpressionFunct::EnumHasStroke
: return stream
<< "hasstroke";
102 case ExpressionFunct::EnumHasFill
: return stream
<< "hasfill";
103 case ExpressionFunct::EnumWidth
: return stream
<< "width";
104 case ExpressionFunct::EnumHeight
: return stream
<< "height";
105 case ExpressionFunct::EnumLogWidth
: return stream
<< "logwidth";
106 case ExpressionFunct::EnumLogHeight
: return stream
<< "logheight";
107 case ExpressionFunct::EnumAdjustment
: return stream
<< "adjustment";
108 case ExpressionFunct::EnumEquation
: return stream
<< "equation";
110 case ExpressionFunct::UnaryAbs
: return stream
<< "abs";
111 case ExpressionFunct::UnarySqrt
: return stream
<< "sqrt";
112 case ExpressionFunct::UnarySin
: return stream
<< "sin";
113 case ExpressionFunct::UnaryCos
: return stream
<< "cos";
114 case ExpressionFunct::UnaryTan
: return stream
<< "tan";
115 case ExpressionFunct::UnaryAtan
: return stream
<< "atan";
116 case ExpressionFunct::UnaryNeg
: return stream
<< "neg";
118 case ExpressionFunct::BinaryPlus
: return stream
<< "plus";
119 case ExpressionFunct::BinaryMinus
: return stream
<< "minus";
120 case ExpressionFunct::BinaryMul
: return stream
<< "mul";
121 case ExpressionFunct::BinaryDiv
: return stream
<< "div";
122 case ExpressionFunct::BinaryMin
: return stream
<< "min";
123 case ExpressionFunct::BinaryMax
: return stream
<< "max";
124 case ExpressionFunct::BinaryAtan2
: return stream
<< "atan2";
126 case ExpressionFunct::TernaryIf
: return stream
<< "if";
128 default: return stream
<< "?(" << static_cast<int>(eFunc
) << ")";
132 #define EXPRESSION_FLAG_SUMANGLE_MODE 1
134 SVX_DLLPUBLIC
void FillEquationParameter( const css::drawing::EnhancedCustomShapeParameter
&, const sal_Int32
, EnhancedCustomShapeEquation
& );
136 class SAL_DLLPUBLIC_RTTI ExpressionNode
139 virtual ~ExpressionNode();
141 /** Predicate whether this node is constant.
143 This predicate returns true, if this node is
144 neither time- nor ViewInfo dependent. This allows
145 for certain optimizations, i.e. not the full
146 expression tree needs be represented by
149 @returns true, if the note is constant
151 virtual bool isConstant() const = 0;
153 /** Operator to calculate function value.
155 This method calculates the function value.
157 virtual double operator()() const = 0;
159 /** Operator to retrieve the type of expression node
161 virtual ExpressionFunct
getType() const = 0;
163 /** Operator to retrieve the ms version of expression
165 virtual css::drawing::EnhancedCustomShapeParameter
fillNode(
166 std::vector
< EnhancedCustomShapeEquation
>& rEquations
, ExpressionNode
* pOptionalArg
, sal_uInt32 nFlags
) = 0;
169 /** This exception is thrown, when the arithmetic expression
170 parser failed to parse a string.
174 ParseError( const char* ) {}
183 The following grammar is accepted by this method:
186 number_digit = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'
188 number = number number_digit | number_digit
190 identifier = 'pi'|'left'|'top'|'right'|'bottom'|'xstretch'|'ystretch'|
191 'hasstroke'|'hasfill'|'width'|'height'|'logwidth'|'logheight'
193 unary_function = 'abs'|'sqrt'|'sin'|'cos'|'tan'|'atan'
194 binary_function = 'min'|'max'|'atan2'
195 ternary_function = 'if'
197 function_reference = '?' 'a-z,A-Z,0-9' ' '
198 modifier_reference = '$' '0-9' ' '
204 unary_function '(' additive_expression ')' |
205 binary_function '(' additive_expression ',' additive_expression ')' |
206 ternary_function '(' additive_expression ',' additive_expression ',
207 ' additive_expression ')' | '(' additive_expression ')'
209 unary_expression = '-' basic_expression
211 multiplicative_expression =
213 multiplicative_expression '*' basic_expression |
214 multiplicative_expression '/' basic_expression
216 additive_expression =
217 multiplicative_expression |
218 additive_expression '+' multiplicative_expression |
219 additive_expression '-' multiplicative_expression
227 The CustomShape is required for calculation of dynamic values such
228 "hasstroke", function references and or modifier references ...
230 @throws ParseError if an invalid expression is given.
232 @return the generated function object.
235 SVX_DLLPUBLIC
static std::shared_ptr
<ExpressionNode
> const & parseFunction( const OUString
& rFunction
, const EnhancedCustomShape2d
& rCustoShape
);
237 // this is a singleton
238 FunctionParser() = delete;
239 FunctionParser(const FunctionParser
&) = delete;
240 FunctionParser
& operator=( const FunctionParser
& ) = delete;
245 #endif // INCLUDED_SVX_ENHANCEDCUSTOMSHAPEFUNCTIONPARSER_HXX
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */