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.
24 #include "wtf/Platform.h"
27 #include "FloatPoint.h"
28 #include "FloatSize.h"
30 #include "SVGSVGElement.h"
31 #include "SVGTransform.h"
35 using namespace WebCore
;
37 SVGTransform::SVGTransform()
38 : m_type(SVG_TRANSFORM_UNKNOWN
)
43 SVGTransform::SVGTransform(SVGTransformType type
)
46 , m_center(FloatPoint())
47 , m_matrix(AffineTransform())
51 SVGTransform::SVGTransform(const AffineTransform
& matrix
)
52 : m_type(SVG_TRANSFORM_MATRIX
)
58 SVGTransform::~SVGTransform()
62 bool SVGTransform::isValid()
64 return (m_type
!= SVG_TRANSFORM_UNKNOWN
);
67 SVGTransform::SVGTransformType
SVGTransform::type() const
72 AffineTransform
SVGTransform::matrix() const
77 float SVGTransform::angle() const
82 FloatPoint
SVGTransform::rotationCenter() const
87 void SVGTransform::setMatrix(const AffineTransform
& matrix
)
89 m_type
= SVG_TRANSFORM_MATRIX
;
95 void SVGTransform::setTranslate(float tx
, float ty
)
97 m_type
= SVG_TRANSFORM_TRANSLATE
;
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
;
113 m_center
= FloatPoint();
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
;
128 m_center
= FloatPoint(cx
, cy
);
130 // TODO: toString() implementation, which can show cx, cy (need to be stored?)
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
;
143 m_matrix
.skewX(angle
);
146 void SVGTransform::setSkewY(float angle
)
148 m_type
= SVG_TRANSFORM_SKEWY
;
152 m_matrix
.skewY(angle
);
156 #endif // ENABLE(SVG)