KHTML
JSSVGMatrixCustom.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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