KHTML
SVGTransform.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
00021
00022
00023 #include "config.h"
00024 #include "wtf/Platform.h"
00025 #if ENABLE(SVG)
00026
00027 #include "FloatPoint.h"
00028 #include "FloatSize.h"
00029 #include "SVGAngle.h"
00030 #include "SVGSVGElement.h"
00031 #include "SVGTransform.h"
00032
00033 #include <math.h>
00034
00035 using namespace WebCore;
00036
00037 SVGTransform::SVGTransform()
00038 : m_type(SVG_TRANSFORM_UNKNOWN)
00039 , m_angle(0)
00040 {
00041 }
00042
00043 SVGTransform::SVGTransform(SVGTransformType type)
00044 : m_type(type)
00045 , m_angle(0)
00046 , m_center(FloatPoint())
00047 , m_matrix(AffineTransform())
00048 {
00049 }
00050
00051 SVGTransform::SVGTransform(const AffineTransform& matrix)
00052 : m_type(SVG_TRANSFORM_MATRIX)
00053 , m_angle(0)
00054 , m_matrix(matrix)
00055 {
00056 }
00057
00058 SVGTransform::~SVGTransform()
00059 {
00060 }
00061
00062 bool SVGTransform::isValid()
00063 {
00064 return (m_type != SVG_TRANSFORM_UNKNOWN);
00065 }
00066
00067 SVGTransform::SVGTransformType SVGTransform::type() const
00068 {
00069 return m_type;
00070 }
00071
00072 AffineTransform SVGTransform::matrix() const
00073 {
00074 return m_matrix;
00075 }
00076
00077 float SVGTransform::angle() const
00078 {
00079 return m_angle;
00080 }
00081
00082 FloatPoint SVGTransform::rotationCenter() const
00083 {
00084 return m_center;
00085 }
00086
00087 void SVGTransform::setMatrix(const AffineTransform& matrix)
00088 {
00089 m_type = SVG_TRANSFORM_MATRIX;
00090 m_angle = 0;
00091
00092 m_matrix = matrix;
00093 }
00094
00095 void SVGTransform::setTranslate(float tx, float ty)
00096 {
00097 m_type = SVG_TRANSFORM_TRANSLATE;
00098 m_angle = 0;
00099
00100 m_matrix.reset();
00101 m_matrix.translate(tx, ty);
00102 }
00103
00104 FloatPoint SVGTransform::translate() const
00105 {
00106 return FloatPoint::narrowPrecision(m_matrix.e(), m_matrix.f());
00107 }
00108
00109 void SVGTransform::setScale(float sx, float sy)
00110 {
00111 m_type = SVG_TRANSFORM_SCALE;
00112 m_angle = 0;
00113 m_center = FloatPoint();
00114
00115 m_matrix.reset();
00116 m_matrix.scale(sx, sy);
00117 }
00118
00119 FloatSize SVGTransform::scale() const
00120 {
00121 return FloatSize::narrowPrecision(m_matrix.a(), m_matrix.d());
00122 }
00123
00124 void SVGTransform::setRotate(float angle, float cx, float cy)
00125 {
00126 m_type = SVG_TRANSFORM_ROTATE;
00127 m_angle = angle;
00128 m_center = FloatPoint(cx, cy);
00129
00130
00131 m_matrix.reset();
00132 m_matrix.translate(cx, cy);
00133 m_matrix.rotate(angle);
00134 m_matrix.translate(-cx, -cy);
00135 }
00136
00137 void SVGTransform::setSkewX(float angle)
00138 {
00139 m_type = SVG_TRANSFORM_SKEWX;
00140 m_angle = angle;
00141
00142 m_matrix.reset();
00143 m_matrix.skewX(angle);
00144 }
00145
00146 void SVGTransform::setSkewY(float angle)
00147 {
00148 m_type = SVG_TRANSFORM_SKEWY;
00149 m_angle = angle;
00150
00151 m_matrix.reset();
00152 m_matrix.skewY(angle);
00153 }
00154
00155
00156 #endif // ENABLE(SVG)
00157