don't discard iframe children.
[kdelibs.git] / khtml / svg / SVGTransform.cpp
blobb6f6f0c48aafae399aa1a4398066f90b8358f1f7
1 /*
2 Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
3 2004, 2005 Rob Buis <buis@kde.org>
5 This file is part of the KDE project
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
23 #include "config.h"
24 #include "wtf/Platform.h"
25 #if ENABLE(SVG)
27 #include "FloatPoint.h"
28 #include "FloatSize.h"
29 #include "SVGAngle.h"
30 #include "SVGSVGElement.h"
31 #include "SVGTransform.h"
33 #include <math.h>
35 using namespace WebCore;
37 SVGTransform::SVGTransform()
38 : m_type(SVG_TRANSFORM_UNKNOWN)
39 , m_angle(0)
43 SVGTransform::SVGTransform(SVGTransformType type)
44 : m_type(type)
45 , m_angle(0)
46 , m_center(FloatPoint())
47 , m_matrix(AffineTransform())
51 SVGTransform::SVGTransform(const AffineTransform& matrix)
52 : m_type(SVG_TRANSFORM_MATRIX)
53 , m_angle(0)
54 , m_matrix(matrix)
58 SVGTransform::~SVGTransform()
62 bool SVGTransform::isValid()
64 return (m_type != SVG_TRANSFORM_UNKNOWN);
67 SVGTransform::SVGTransformType SVGTransform::type() const
69 return m_type;
72 AffineTransform SVGTransform::matrix() const
74 return m_matrix;
77 float SVGTransform::angle() const
79 return m_angle;
82 FloatPoint SVGTransform::rotationCenter() const
84 return m_center;
87 void SVGTransform::setMatrix(const AffineTransform& matrix)
89 m_type = SVG_TRANSFORM_MATRIX;
90 m_angle = 0;
92 m_matrix = matrix;
95 void SVGTransform::setTranslate(float tx, float ty)
97 m_type = SVG_TRANSFORM_TRANSLATE;
98 m_angle = 0;
100 m_matrix.reset();
101 m_matrix.translate(tx, ty);
104 FloatPoint SVGTransform::translate() const
106 return FloatPoint::narrowPrecision(m_matrix.e(), m_matrix.f());
109 void SVGTransform::setScale(float sx, float sy)
111 m_type = SVG_TRANSFORM_SCALE;
112 m_angle = 0;
113 m_center = FloatPoint();
115 m_matrix.reset();
116 m_matrix.scale(sx, sy);
119 FloatSize SVGTransform::scale() const
121 return FloatSize::narrowPrecision(m_matrix.a(), m_matrix.d());
124 void SVGTransform::setRotate(float angle, float cx, float cy)
126 m_type = SVG_TRANSFORM_ROTATE;
127 m_angle = angle;
128 m_center = FloatPoint(cx, cy);
130 // TODO: toString() implementation, which can show cx, cy (need to be stored?)
131 m_matrix.reset();
132 m_matrix.translate(cx, cy);
133 m_matrix.rotate(angle);
134 m_matrix.translate(-cx, -cy);
137 void SVGTransform::setSkewX(float angle)
139 m_type = SVG_TRANSFORM_SKEWX;
140 m_angle = angle;
142 m_matrix.reset();
143 m_matrix.skewX(angle);
146 void SVGTransform::setSkewY(float angle)
148 m_type = SVG_TRANSFORM_SKEWY;
149 m_angle = angle;
151 m_matrix.reset();
152 m_matrix.skewY(angle);
155 // vim:ts=4:noet
156 #endif // ENABLE(SVG)