File indexing completed on 2024-05-12 15:37:26
0001 /* 0002 * Copyright (C) 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "wtf/Platform.h" 0021 0022 #if ENABLE(SVG) 0023 0024 #include "JSSVGMatrix.h" 0025 0026 #include "AffineTransform.h" 0027 #include "SVGException.h" 0028 0029 using namespace KJS; 0030 using namespace WebCore; 0031 0032 namespace khtml 0033 { 0034 0035 JSValue *JSSVGMatrix::multiply(ExecState *exec, const List &args) 0036 { 0037 AffineTransform imp(*impl()); 0038 0039 AffineTransform secondMatrix = toSVGMatrix(args[0]); 0040 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.multiply(secondMatrix)), m_context.get()); 0041 } 0042 0043 JSValue *JSSVGMatrix::inverse(ExecState *exec, const List &) 0044 { 0045 AffineTransform imp(*impl()); 0046 KJS::JSValue *result = toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.inverse()), m_context.get()); 0047 0048 if (!imp.isInvertible()) { 0049 setDOMException(exec, SVGException::SVG_MATRIX_NOT_INVERTABLE); 0050 } 0051 0052 return result; 0053 } 0054 0055 JSValue *JSSVGMatrix::translate(ExecState *exec, const List &args) 0056 { 0057 AffineTransform imp(*impl()); 0058 0059 float x = args[0]->toFloat(exec); 0060 float y = args[1]->toFloat(exec); 0061 0062 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.translate(x, y)), m_context.get()); 0063 } 0064 0065 JSValue *JSSVGMatrix::scale(ExecState *exec, const List &args) 0066 { 0067 AffineTransform imp(*impl()); 0068 0069 float scaleFactor = args[0]->toFloat(exec); 0070 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.scale(scaleFactor)), m_context.get()); 0071 } 0072 0073 JSValue *JSSVGMatrix::scaleNonUniform(ExecState *exec, const List &args) 0074 { 0075 AffineTransform imp(*impl()); 0076 0077 float scaleFactorX = args[0]->toFloat(exec); 0078 float scaleFactorY = args[1]->toFloat(exec); 0079 0080 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.scaleNonUniform(scaleFactorX, scaleFactorY)), m_context.get()); 0081 } 0082 0083 JSValue *JSSVGMatrix::rotate(ExecState *exec, const List &args) 0084 { 0085 AffineTransform imp(*impl()); 0086 0087 float angle = args[0]->toFloat(exec); 0088 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.rotate(angle)), m_context.get()); 0089 } 0090 0091 JSValue *JSSVGMatrix::rotateFromVector(ExecState *exec, const List &args) 0092 { 0093 AffineTransform imp(*impl()); 0094 0095 float x = args[0]->toFloat(exec); 0096 float y = args[1]->toFloat(exec); 0097 0098 KJS::JSValue *result = toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.rotateFromVector(x, y)), m_context.get()); 0099 0100 if (x == 0.0 || y == 0.0) { 0101 setDOMException(exec, SVGException::SVG_INVALID_VALUE_ERR); 0102 } 0103 0104 return result; 0105 } 0106 0107 JSValue *JSSVGMatrix::flipX(ExecState *exec, const List &) 0108 { 0109 AffineTransform imp(*impl()); 0110 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.flipX()), m_context.get()); 0111 } 0112 0113 JSValue *JSSVGMatrix::flipY(ExecState *exec, const List &) 0114 { 0115 AffineTransform imp(*impl()); 0116 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.flipY()), m_context.get()); 0117 } 0118 0119 JSValue *JSSVGMatrix::skewX(ExecState *exec, const List &args) 0120 { 0121 AffineTransform imp(*impl()); 0122 0123 float angle = args[0]->toFloat(exec); 0124 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.skewX(angle)), m_context.get()); 0125 } 0126 0127 JSValue *JSSVGMatrix::skewY(ExecState *exec, const List &args) 0128 { 0129 AffineTransform imp(*impl()); 0130 0131 float angle = args[0]->toFloat(exec); 0132 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.skewY(angle)), m_context.get()); 0133 } 0134 0135 } 0136 0137 #endif // ENABLE(SVG) 0138