KHtml

JSSVGMatrixCustom.cpp
1 /*
2  * Copyright (C) 2006, 2007 Nikolas Zimmermann <[email protected]>
3  *
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.
8  *
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.
13  *
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.
18  */
19 
20 #include "wtf/Platform.h"
21 
22 #if ENABLE(SVG)
23 
24 #include "JSSVGMatrix.h"
25 
26 #include "AffineTransform.h"
27 #include "SVGException.h"
28 
29 using namespace KJS;
30 using namespace WebCore;
31 
32 namespace khtml
33 {
34 
35 JSValue *JSSVGMatrix::multiply(ExecState *exec, const List &args)
36 {
37  AffineTransform imp(*impl());
38 
39  AffineTransform secondMatrix = toSVGMatrix(args[0]);
40  return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.multiply(secondMatrix)), m_context.get());
41 }
42 
43 JSValue *JSSVGMatrix::inverse(ExecState *exec, const List &)
44 {
45  AffineTransform imp(*impl());
46  KJS::JSValue *result = toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.inverse()), m_context.get());
47 
48  if (!imp.isInvertible()) {
49  setDOMException(exec, SVGException::SVG_MATRIX_NOT_INVERTABLE);
50  }
51 
52  return result;
53 }
54 
55 JSValue *JSSVGMatrix::translate(ExecState *exec, const List &args)
56 {
57  AffineTransform imp(*impl());
58 
59  float x = args[0]->toFloat(exec);
60  float y = args[1]->toFloat(exec);
61 
62  return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.translate(x, y)), m_context.get());
63 }
64 
65 JSValue *JSSVGMatrix::scale(ExecState *exec, const List &args)
66 {
67  AffineTransform imp(*impl());
68 
69  float scaleFactor = args[0]->toFloat(exec);
70  return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.scale(scaleFactor)), m_context.get());
71 }
72 
73 JSValue *JSSVGMatrix::scaleNonUniform(ExecState *exec, const List &args)
74 {
75  AffineTransform imp(*impl());
76 
77  float scaleFactorX = args[0]->toFloat(exec);
78  float scaleFactorY = args[1]->toFloat(exec);
79 
80  return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.scaleNonUniform(scaleFactorX, scaleFactorY)), m_context.get());
81 }
82 
83 JSValue *JSSVGMatrix::rotate(ExecState *exec, const List &args)
84 {
85  AffineTransform imp(*impl());
86 
87  float angle = args[0]->toFloat(exec);
88  return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.rotate(angle)), m_context.get());
89 }
90 
91 JSValue *JSSVGMatrix::rotateFromVector(ExecState *exec, const List &args)
92 {
93  AffineTransform imp(*impl());
94 
95  float x = args[0]->toFloat(exec);
96  float y = args[1]->toFloat(exec);
97 
98  KJS::JSValue *result = toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.rotateFromVector(x, y)), m_context.get());
99 
100  if (x == 0.0 || y == 0.0) {
101  setDOMException(exec, SVGException::SVG_INVALID_VALUE_ERR);
102  }
103 
104  return result;
105 }
106 
107 JSValue *JSSVGMatrix::flipX(ExecState *exec, const List &)
108 {
109  AffineTransform imp(*impl());
110  return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.flipX()), m_context.get());
111 }
112 
113 JSValue *JSSVGMatrix::flipY(ExecState *exec, const List &)
114 {
115  AffineTransform imp(*impl());
116  return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.flipY()), m_context.get());
117 }
118 
119 JSValue *JSSVGMatrix::skewX(ExecState *exec, const List &args)
120 {
121  AffineTransform imp(*impl());
122 
123  float angle = args[0]->toFloat(exec);
124  return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.skewX(angle)), m_context.get());
125 }
126 
127 JSValue *JSSVGMatrix::skewY(ExecState *exec, const List &args)
128 {
129  AffineTransform imp(*impl());
130 
131  float angle = args[0]->toFloat(exec);
132  return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.skewY(angle)), m_context.get());
133 }
134 
135 }
136 
137 #endif // ENABLE(SVG)
138 
This file is part of the HTML rendering engine for KDE.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:47:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.