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 #if ENABLE(SVG) 24 #include "AffineTransform.h" 25 #include "SVGException.h" 26 27 namespace WebCore { 28 29 // Only used in the bindings. 30 class SVGMatrix : public AffineTransform { 31 public: SVGMatrix()32 SVGMatrix() { } SVGMatrix(const AffineTransform & other)33 SVGMatrix(const AffineTransform& other) 34 : AffineTransform(other) 35 { 36 } 37 SVGMatrix(double a,double b,double c,double d,double e,double f)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 translate(double tx,double ty)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 scale(double s)50 SVGMatrix scale(double s) 51 { 52 AffineTransform copy = *this; 53 copy.scale(s, s); 54 return static_cast<SVGMatrix>(copy); 55 } 56 scaleNonUniform(double sx,double sy)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 rotate(double d)64 SVGMatrix rotate(double d) 65 { 66 AffineTransform copy = *this; 67 copy.rotate(d); 68 return static_cast<SVGMatrix>(copy); 69 } 70 flipX()71 SVGMatrix flipX() 72 { 73 AffineTransform copy = *this; 74 copy.flipX(); 75 return static_cast<SVGMatrix>(copy); 76 } 77 flipY()78 SVGMatrix flipY() 79 { 80 AffineTransform copy = *this; 81 copy.flipY(); 82 return static_cast<SVGMatrix>(copy); 83 } 84 skewX(double angle)85 SVGMatrix skewX(double angle) 86 { 87 AffineTransform copy = *this; 88 copy.skewX(angle); 89 return static_cast<SVGMatrix>(copy); 90 } 91 skewY(double angle)92 SVGMatrix skewY(double angle) 93 { 94 AffineTransform copy = *this; 95 copy.skewY(angle); 96 return static_cast<SVGMatrix>(copy); 97 } 98 multiply(const SVGMatrix & other)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 inverse(ExceptionCode & ec)106 SVGMatrix inverse(ExceptionCode& ec) const 107 { 108 AffineTransform transform = AffineTransform::inverse(); 109 if (!isInvertible()) 110 ec = SVGException::SVG_MATRIX_NOT_INVERTABLE; 111 112 return transform; 113 } 114 rotateFromVector(double x,double y,ExceptionCode & ec)115 SVGMatrix rotateFromVector(double x, double y, ExceptionCode& ec) 116 { 117 if (!x || !y) 118 ec = SVGException::SVG_INVALID_VALUE_ERR; 119 120 AffineTransform copy = *this; 121 copy.rotateFromVector(x, y); 122 return static_cast<SVGMatrix>(copy); 123 } 124 125 }; 126 127 } // namespace WebCore 128 129 #endif // ENABLE(SVG) 130 #endif 131