fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / khtml / bindings / js / JSSVGMatrixCustom.cpp
blob6ce063d618073f67c4a03569ce24c09aeb04bb96
1 /*
2 * Copyright (C) 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include "config.h"
21 #include "wtf/Platform.h"
23 #if ENABLE(SVG)
25 #include "JSSVGMatrix.h"
27 #include "AffineTransform.h"
28 #include "SVGException.h"
30 using namespace KJS;
31 using namespace WebCore;
33 namespace khtml {
35 JSValue* JSSVGMatrix::multiply(ExecState* exec, const List& args)
37 AffineTransform imp(*impl());
39 AffineTransform secondMatrix = toSVGMatrix(args[0]);
40 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.multiply(secondMatrix)), m_context.get());
43 JSValue* JSSVGMatrix::inverse(ExecState* exec, const List&)
45 AffineTransform imp(*impl());
46 KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.inverse()), m_context.get());
48 if (!imp.isInvertible())
49 setDOMException(exec, SVGException::SVG_MATRIX_NOT_INVERTABLE);
51 return result;
54 JSValue* JSSVGMatrix::translate(ExecState* exec, const List& args)
56 AffineTransform imp(*impl());
58 float x = args[0]->toFloat(exec);
59 float y = args[1]->toFloat(exec);
61 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.translate(x, y)), m_context.get());
64 JSValue* JSSVGMatrix::scale(ExecState* exec, const List& args)
66 AffineTransform imp(*impl());
68 float scaleFactor = args[0]->toFloat(exec);
69 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.scale(scaleFactor)), m_context.get());
72 JSValue* JSSVGMatrix::scaleNonUniform(ExecState* exec, const List& args)
74 AffineTransform imp(*impl());
76 float scaleFactorX = args[0]->toFloat(exec);
77 float scaleFactorY = args[1]->toFloat(exec);
79 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.scaleNonUniform(scaleFactorX, scaleFactorY)), m_context.get());
82 JSValue* JSSVGMatrix::rotate(ExecState* exec, const List& args)
84 AffineTransform imp(*impl());
86 float angle = args[0]->toFloat(exec);
87 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.rotate(angle)), m_context.get());
90 JSValue* JSSVGMatrix::rotateFromVector(ExecState* exec, const List& args)
92 AffineTransform imp(*impl());
94 float x = args[0]->toFloat(exec);
95 float y = args[1]->toFloat(exec);
97 KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.rotateFromVector(x, y)), m_context.get());
99 if (x == 0.0 || y == 0.0)
100 setDOMException(exec, SVGException::SVG_INVALID_VALUE_ERR);
102 return result;
105 JSValue* JSSVGMatrix::flipX(ExecState* exec, const List&)
107 AffineTransform imp(*impl());
108 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.flipX()), m_context.get());
111 JSValue* JSSVGMatrix::flipY(ExecState* exec, const List&)
113 AffineTransform imp(*impl());
114 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.flipY()), m_context.get());
117 JSValue* JSSVGMatrix::skewX(ExecState* exec, const List& args)
119 AffineTransform imp(*impl());
121 float angle = args[0]->toFloat(exec);
122 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.skewX(angle)), m_context.get());
125 JSValue* JSSVGMatrix::skewY(ExecState* exec, const List& args)
127 AffineTransform imp(*impl());
129 float angle = args[0]->toFloat(exec);
130 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.skewY(angle)), m_context.get());
135 #endif // ENABLE(SVG)
137 // vim:ts=4:noet