KHTML
JSSVGMatrixCustom.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Library General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "config.h" 00021 #include "wtf/Platform.h" 00022 00023 #if ENABLE(SVG) 00024 00025 #include "JSSVGMatrix.h" 00026 00027 #include "AffineTransform.h" 00028 #include "SVGException.h" 00029 00030 using namespace KJS; 00031 using namespace WebCore; 00032 00033 namespace khtml { 00034 00035 JSValue* JSSVGMatrix::multiply(ExecState* exec, const List& args) 00036 { 00037 AffineTransform imp(*impl()); 00038 00039 AffineTransform secondMatrix = toSVGMatrix(args[0]); 00040 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.multiply(secondMatrix)), m_context.get()); 00041 } 00042 00043 JSValue* JSSVGMatrix::inverse(ExecState* exec, const List&) 00044 { 00045 AffineTransform imp(*impl()); 00046 KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.inverse()), m_context.get()); 00047 00048 if (!imp.isInvertible()) 00049 setDOMException(exec, SVGException::SVG_MATRIX_NOT_INVERTABLE); 00050 00051 return result; 00052 } 00053 00054 JSValue* JSSVGMatrix::translate(ExecState* exec, const List& args) 00055 { 00056 AffineTransform imp(*impl()); 00057 00058 float x = args[0]->toFloat(exec); 00059 float y = args[1]->toFloat(exec); 00060 00061 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.translate(x, y)), m_context.get()); 00062 } 00063 00064 JSValue* JSSVGMatrix::scale(ExecState* exec, const List& args) 00065 { 00066 AffineTransform imp(*impl()); 00067 00068 float scaleFactor = args[0]->toFloat(exec); 00069 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.scale(scaleFactor)), m_context.get()); 00070 } 00071 00072 JSValue* JSSVGMatrix::scaleNonUniform(ExecState* exec, const List& args) 00073 { 00074 AffineTransform imp(*impl()); 00075 00076 float scaleFactorX = args[0]->toFloat(exec); 00077 float scaleFactorY = args[1]->toFloat(exec); 00078 00079 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.scaleNonUniform(scaleFactorX, scaleFactorY)), m_context.get()); 00080 } 00081 00082 JSValue* JSSVGMatrix::rotate(ExecState* exec, const List& args) 00083 { 00084 AffineTransform imp(*impl()); 00085 00086 float angle = args[0]->toFloat(exec); 00087 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.rotate(angle)), m_context.get()); 00088 } 00089 00090 JSValue* JSSVGMatrix::rotateFromVector(ExecState* exec, const List& args) 00091 { 00092 AffineTransform imp(*impl()); 00093 00094 float x = args[0]->toFloat(exec); 00095 float y = args[1]->toFloat(exec); 00096 00097 KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.rotateFromVector(x, y)), m_context.get()); 00098 00099 if (x == 0.0 || y == 0.0) 00100 setDOMException(exec, SVGException::SVG_INVALID_VALUE_ERR); 00101 00102 return result; 00103 } 00104 00105 JSValue* JSSVGMatrix::flipX(ExecState* exec, const List&) 00106 { 00107 AffineTransform imp(*impl()); 00108 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.flipX()), m_context.get()); 00109 } 00110 00111 JSValue* JSSVGMatrix::flipY(ExecState* exec, const List&) 00112 { 00113 AffineTransform imp(*impl()); 00114 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.flipY()), m_context.get()); 00115 } 00116 00117 JSValue* JSSVGMatrix::skewX(ExecState* exec, const List& args) 00118 { 00119 AffineTransform imp(*impl()); 00120 00121 float angle = args[0]->toFloat(exec); 00122 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.skewX(angle)), m_context.get()); 00123 } 00124 00125 JSValue* JSSVGMatrix::skewY(ExecState* exec, const List& args) 00126 { 00127 AffineTransform imp(*impl()); 00128 00129 float angle = args[0]->toFloat(exec); 00130 return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.skewY(angle)), m_context.get()); 00131 } 00132 00133 } 00134 00135 #endif // ENABLE(SVG) 00136 00137 // vim:ts=4:noet
KDE 4.6 API Reference