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 "FloatPoint.h"
25#include "SVGMatrix.h"
26
27namespace WebCore {
28
29class FloatSize;
30
31class SVGTransform {
32public:
33    enum SVGTransformType {
34        SVG_TRANSFORM_UNKNOWN = 0,
35        SVG_TRANSFORM_MATRIX = 1,
36        SVG_TRANSFORM_TRANSLATE = 2,
37        SVG_TRANSFORM_SCALE = 3,
38        SVG_TRANSFORM_ROTATE = 4,
39        SVG_TRANSFORM_SKEWX = 5,
40        SVG_TRANSFORM_SKEWY = 6
41    };
42
43    enum ConstructionMode {
44        ConstructIdentityTransform,
45        ConstructZeroTransform
46    };
47
48    SVGTransform();
49    SVGTransform(SVGTransformType, ConstructionMode = ConstructIdentityTransform);
50    explicit SVGTransform(const AffineTransform&);
51
52    SVGTransformType type() const { return m_type; }
53
54    SVGMatrix& svgMatrix() { return static_cast<SVGMatrix&>(m_matrix); }
55    AffineTransform matrix() const { return m_matrix; }
56    void updateSVGMatrix();
57
58    float angle() const { return m_angle; }
59    FloatPoint rotationCenter() const { return m_center; }
60
61    void setMatrix(const AffineTransform&);
62    void setTranslate(float tx, float ty);
63    void setScale(float sx, float sy);
64    void setRotate(float angle, float cx, float cy);
65    void setSkewX(float angle);
66    void setSkewY(float angle);
67
68    // Internal use only (animation system)
69    FloatPoint translate() const;
70    FloatSize scale() const;
71
72    bool isValid() const { return m_type != SVG_TRANSFORM_UNKNOWN; }
73    String valueAsString() const;
74
75    static const String& transformTypePrefixForParsing(SVGTransformType);
76
77private:
78    friend bool operator==(const SVGTransform& a, const SVGTransform& b);
79
80    SVGTransformType m_type;
81    float m_angle;
82    FloatPoint m_center;
83    AffineTransform m_matrix;
84};
85
86inline bool operator==(const SVGTransform& a, const SVGTransform& b)
87{
88    return a.m_type == b.m_type && a.m_angle == b.m_angle && a.m_matrix == b.m_matrix;
89}
90
91inline bool operator!=(const SVGTransform& a, const SVGTransform& b)
92{
93    return !(a == b);
94}
95
96} // namespace WebCore
97
98#endif
99