• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef SVGTransform_h
22 #define SVGTransform_h
23 
24 #include "core/svg/SVGMatrix.h"
25 #include "platform/geometry/FloatPoint.h"
26 #include "wtf/text/WTFString.h"
27 
28 namespace WebCore {
29 
30 class FloatSize;
31 
32 class SVGTransform {
33 public:
34     enum SVGTransformType {
35         SVG_TRANSFORM_UNKNOWN = 0,
36         SVG_TRANSFORM_MATRIX = 1,
37         SVG_TRANSFORM_TRANSLATE = 2,
38         SVG_TRANSFORM_SCALE = 3,
39         SVG_TRANSFORM_ROTATE = 4,
40         SVG_TRANSFORM_SKEWX = 5,
41         SVG_TRANSFORM_SKEWY = 6
42     };
43 
44     enum ConstructionMode {
45         ConstructIdentityTransform,
46         ConstructZeroTransform
47     };
48 
49     SVGTransform();
50     SVGTransform(SVGTransformType, ConstructionMode = ConstructIdentityTransform);
51     explicit SVGTransform(const AffineTransform&);
52 
type()53     SVGTransformType type() const { return m_type; }
54 
svgMatrix()55     SVGMatrix& svgMatrix() { return static_cast<SVGMatrix&>(m_matrix); }
matrix()56     AffineTransform matrix() const { return m_matrix; }
57     void updateSVGMatrix();
58 
angle()59     float angle() const { return m_angle; }
rotationCenter()60     FloatPoint rotationCenter() const { return m_center; }
61 
62     void setMatrix(const AffineTransform&);
63     void setTranslate(float tx, float ty);
64     void setScale(float sx, float sy);
65     void setRotate(float angle, float cx, float cy);
66     void setSkewX(float angle);
67     void setSkewY(float angle);
68 
69     // Internal use only (animation system)
70     FloatPoint translate() const;
71     FloatSize scale() const;
72 
isValid()73     bool isValid() const { return m_type != SVG_TRANSFORM_UNKNOWN; }
74     String valueAsString() const;
75 
76     static const String& transformTypePrefixForParsing(SVGTransformType);
77 
78 private:
79     friend bool operator==(const SVGTransform& a, const SVGTransform& b);
80 
81     SVGTransformType m_type;
82     float m_angle;
83     FloatPoint m_center;
84     AffineTransform m_matrix;
85 };
86 
87 inline bool operator==(const SVGTransform& a, const SVGTransform& b)
88 {
89     return a.m_type == b.m_type && a.m_angle == b.m_angle && a.m_matrix == b.m_matrix;
90 }
91 
92 inline bool operator!=(const SVGTransform& a, const SVGTransform& b)
93 {
94     return !(a == b);
95 }
96 
97 } // namespace WebCore
98 
99 #endif
100