KHtml

SVGTransform.cpp
1 /*
2  Copyright (C) 2004, 2005 Nikolas Zimmermann <[email protected]>
3  2004, 2005 Rob Buis <[email protected]>
4 
5  This file is part of the KDE project
6 
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.
11 
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.
16 
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.
21 */
22 
23 #include "wtf/Platform.h"
24 #if ENABLE(SVG)
25 
26 #include "FloatSize.h"
27 #include "SVGAngle.h"
28 #include "SVGSVGElement.h"
29 #include "SVGTransform.h"
30 
31 #include <math.h>
32 
33 using namespace WebCore;
34 
35 SVGTransform::SVGTransform()
36  : m_type(SVG_TRANSFORM_UNKNOWN)
37  , m_angle(0)
38 {
39 }
40 
41 SVGTransform::SVGTransform(SVGTransformType type)
42  : m_type(type)
43  , m_angle(0)
44  , m_center(FloatPoint())
45  , m_matrix(AffineTransform())
46 {
47 }
48 
49 SVGTransform::SVGTransform(const AffineTransform &matrix)
50  : m_type(SVG_TRANSFORM_MATRIX)
51  , m_angle(0)
52  , m_matrix(matrix)
53 {
54 }
55 
56 SVGTransform::~SVGTransform()
57 {
58 }
59 
60 bool SVGTransform::isValid()
61 {
62  return (m_type != SVG_TRANSFORM_UNKNOWN);
63 }
64 
65 SVGTransform::SVGTransformType SVGTransform::type() const
66 {
67  return m_type;
68 }
69 
70 AffineTransform SVGTransform::matrix() const
71 {
72  return m_matrix;
73 }
74 
75 float SVGTransform::angle() const
76 {
77  return m_angle;
78 }
79 
80 FloatPoint SVGTransform::rotationCenter() const
81 {
82  return m_center;
83 }
84 
85 void SVGTransform::setMatrix(const AffineTransform &matrix)
86 {
87  m_type = SVG_TRANSFORM_MATRIX;
88  m_angle = 0;
89 
90  m_matrix = matrix;
91 }
92 
93 void SVGTransform::setTranslate(float tx, float ty)
94 {
95  m_type = SVG_TRANSFORM_TRANSLATE;
96  m_angle = 0;
97 
98  m_matrix.reset();
99  m_matrix.translate(tx, ty);
100 }
101 
102 FloatPoint SVGTransform::translate() const
103 {
104  return FloatPoint::narrowPrecision(m_matrix.e(), m_matrix.f());
105 }
106 
107 void SVGTransform::setScale(float sx, float sy)
108 {
109  m_type = SVG_TRANSFORM_SCALE;
110  m_angle = 0;
111  m_center = FloatPoint();
112 
113  m_matrix.reset();
114  m_matrix.scale(sx, sy);
115 }
116 
117 FloatSize SVGTransform::scale() const
118 {
119  return FloatSize::narrowPrecision(m_matrix.a(), m_matrix.d());
120 }
121 
122 void SVGTransform::setRotate(float angle, float cx, float cy)
123 {
124  m_type = SVG_TRANSFORM_ROTATE;
125  m_angle = angle;
126  m_center = FloatPoint(cx, cy);
127 
128  // TODO: toString() implementation, which can show cx, cy (need to be stored?)
129  m_matrix.reset();
130  m_matrix.translate(cx, cy);
131  m_matrix.rotate(angle);
132  m_matrix.translate(-cx, -cy);
133 }
134 
135 void SVGTransform::setSkewX(float angle)
136 {
137  m_type = SVG_TRANSFORM_SKEWX;
138  m_angle = angle;
139 
140  m_matrix.reset();
141  m_matrix.skewX(angle);
142 }
143 
144 void SVGTransform::setSkewY(float angle)
145 {
146  m_type = SVG_TRANSFORM_SKEWY;
147  m_angle = angle;
148 
149  m_matrix.reset();
150  m_matrix.skewY(angle);
151 }
152 
153 #endif // ENABLE(SVG)
154 
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.