Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #ifndef SVGMatrix_h
     21 #define SVGMatrix_h
     22 
     23 #include "bindings/v8/ExceptionState.h"
     24 #include "core/dom/ExceptionCode.h"
     25 #include "core/platform/graphics/transforms/AffineTransform.h"
     26 
     27 namespace WebCore {
     28 
     29 // Only used in the bindings.
     30 class SVGMatrix : public AffineTransform {
     31 public:
     32     SVGMatrix() { }
     33     SVGMatrix(const AffineTransform& other)
     34         : AffineTransform(other)
     35     {
     36     }
     37 
     38     SVGMatrix(double a, double b, double c, double d, double e, double f)
     39         : AffineTransform(a, b, c, d, e, f)
     40     {
     41     }
     42 
     43     SVGMatrix translate(double tx, double ty)
     44     {
     45         AffineTransform copy = *this;
     46         copy.translate(tx, ty);
     47         return static_cast<SVGMatrix>(copy);
     48     }
     49 
     50     SVGMatrix scale(double s)
     51     {
     52         AffineTransform copy = *this;
     53         copy.scale(s, s);
     54         return static_cast<SVGMatrix>(copy);
     55     }
     56 
     57     SVGMatrix scaleNonUniform(double sx, double sy)
     58     {
     59         AffineTransform copy = *this;
     60         copy.scale(sx, sy);
     61         return static_cast<SVGMatrix>(copy);
     62     }
     63 
     64     SVGMatrix rotate(double d)
     65     {
     66         AffineTransform copy = *this;
     67         copy.rotate(d);
     68         return static_cast<SVGMatrix>(copy);
     69     }
     70 
     71     SVGMatrix flipX()
     72     {
     73         AffineTransform copy = *this;
     74         copy.flipX();
     75         return static_cast<SVGMatrix>(copy);
     76     }
     77 
     78     SVGMatrix flipY()
     79     {
     80         AffineTransform copy = *this;
     81         copy.flipY();
     82         return static_cast<SVGMatrix>(copy);
     83     }
     84 
     85     SVGMatrix skewX(double angle)
     86     {
     87         AffineTransform copy = *this;
     88         copy.skewX(angle);
     89         return static_cast<SVGMatrix>(copy);
     90     }
     91 
     92     SVGMatrix skewY(double angle)
     93     {
     94         AffineTransform copy = *this;
     95         copy.skewY(angle);
     96         return static_cast<SVGMatrix>(copy);
     97     }
     98 
     99     SVGMatrix multiply(const SVGMatrix& other)
    100     {
    101         AffineTransform copy = *this;
    102         copy *= static_cast<const AffineTransform&>(other);
    103         return static_cast<SVGMatrix>(copy);
    104     }
    105 
    106     SVGMatrix inverse(ExceptionState& es) const
    107     {
    108         AffineTransform transform = AffineTransform::inverse();
    109         if (!isInvertible()) {
    110             // FIXME: This used to have a more specific error message:
    111             // "An attempt was made to invert a matrix that is not invertible."
    112             // When switching to SVG2 style exceptions we lost this information.
    113             es.throwDOMException(InvalidStateError);
    114         }
    115 
    116         return transform;
    117     }
    118 
    119     SVGMatrix rotateFromVector(double x, double y, ExceptionState& es)
    120     {
    121         if (!x || !y)
    122             es.throwDOMException(InvalidAccessError);
    123 
    124         AffineTransform copy = *this;
    125         copy.rotateFromVector(x, y);
    126         return static_cast<SVGMatrix>(copy);
    127     }
    128 
    129 };
    130 
    131 } // namespace WebCore
    132 
    133 #endif
    134