Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005 Rob Buis <buis (at) 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 #if ENABLE(SVG)
     25 #include "FloatPoint.h"
     26 #include "SVGMatrix.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     SVGTransform();
     45     SVGTransform(SVGTransformType);
     46     explicit SVGTransform(const AffineTransform&);
     47 
     48     SVGTransformType type() const { return m_type; }
     49 
     50     SVGMatrix& svgMatrix() { return static_cast<SVGMatrix&>(m_matrix); }
     51     AffineTransform matrix() const { return m_matrix; }
     52     void updateMatrix();
     53 
     54     float angle() const { return m_angle; }
     55     FloatPoint rotationCenter() const { return m_center; }
     56 
     57     void setMatrix(const AffineTransform&);
     58     void setTranslate(float tx, float ty);
     59     void setScale(float sx, float sy);
     60     void setRotate(float angle, float cx, float cy);
     61     void setSkewX(float angle);
     62     void setSkewY(float angle);
     63 
     64     // Internal use only (animation system)
     65     FloatPoint translate() const;
     66     FloatSize scale() const;
     67 
     68     bool isValid() const { return m_type != SVG_TRANSFORM_UNKNOWN; }
     69     String valueAsString() const;
     70 
     71 private:
     72     friend bool operator==(const SVGTransform& a, const SVGTransform& b);
     73 
     74     SVGTransformType m_type;
     75     float m_angle;
     76     FloatPoint m_center;
     77     AffineTransform m_matrix;
     78 };
     79 
     80 inline bool operator==(const SVGTransform& a, const SVGTransform& b)
     81 {
     82     return a.m_type == b.m_type && a.m_angle == b.m_angle && a.m_matrix == b.m_matrix;
     83 }
     84 
     85 inline bool operator!=(const SVGTransform& a, const SVGTransform& b)
     86 {
     87     return !(a == b);
     88 }
     89 
     90 } // namespace WebCore
     91 
     92 #endif // ENABLE(SVG)
     93 #endif
     94