KHTML
SVGTransform.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org> 00003 2004, 2005 Rob Buis <buis@kde.org> 00004 00005 This file is part of the KDE project 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #include "config.h" 00024 #include "wtf/Platform.h" 00025 #if ENABLE(SVG) 00026 00027 #include "FloatPoint.h" 00028 #include "FloatSize.h" 00029 #include "SVGAngle.h" 00030 #include "SVGSVGElement.h" 00031 #include "SVGTransform.h" 00032 00033 #include <math.h> 00034 00035 using namespace WebCore; 00036 00037 SVGTransform::SVGTransform() 00038 : m_type(SVG_TRANSFORM_UNKNOWN) 00039 , m_angle(0) 00040 { 00041 } 00042 00043 SVGTransform::SVGTransform(SVGTransformType type) 00044 : m_type(type) 00045 , m_angle(0) 00046 , m_center(FloatPoint()) 00047 , m_matrix(AffineTransform()) 00048 { 00049 } 00050 00051 SVGTransform::SVGTransform(const AffineTransform& matrix) 00052 : m_type(SVG_TRANSFORM_MATRIX) 00053 , m_angle(0) 00054 , m_matrix(matrix) 00055 { 00056 } 00057 00058 SVGTransform::~SVGTransform() 00059 { 00060 } 00061 00062 bool SVGTransform::isValid() 00063 { 00064 return (m_type != SVG_TRANSFORM_UNKNOWN); 00065 } 00066 00067 SVGTransform::SVGTransformType SVGTransform::type() const 00068 { 00069 return m_type; 00070 } 00071 00072 AffineTransform SVGTransform::matrix() const 00073 { 00074 return m_matrix; 00075 } 00076 00077 float SVGTransform::angle() const 00078 { 00079 return m_angle; 00080 } 00081 00082 FloatPoint SVGTransform::rotationCenter() const 00083 { 00084 return m_center; 00085 } 00086 00087 void SVGTransform::setMatrix(const AffineTransform& matrix) 00088 { 00089 m_type = SVG_TRANSFORM_MATRIX; 00090 m_angle = 0; 00091 00092 m_matrix = matrix; 00093 } 00094 00095 void SVGTransform::setTranslate(float tx, float ty) 00096 { 00097 m_type = SVG_TRANSFORM_TRANSLATE; 00098 m_angle = 0; 00099 00100 m_matrix.reset(); 00101 m_matrix.translate(tx, ty); 00102 } 00103 00104 FloatPoint SVGTransform::translate() const 00105 { 00106 return FloatPoint::narrowPrecision(m_matrix.e(), m_matrix.f()); 00107 } 00108 00109 void SVGTransform::setScale(float sx, float sy) 00110 { 00111 m_type = SVG_TRANSFORM_SCALE; 00112 m_angle = 0; 00113 m_center = FloatPoint(); 00114 00115 m_matrix.reset(); 00116 m_matrix.scale(sx, sy); 00117 } 00118 00119 FloatSize SVGTransform::scale() const 00120 { 00121 return FloatSize::narrowPrecision(m_matrix.a(), m_matrix.d()); 00122 } 00123 00124 void SVGTransform::setRotate(float angle, float cx, float cy) 00125 { 00126 m_type = SVG_TRANSFORM_ROTATE; 00127 m_angle = angle; 00128 m_center = FloatPoint(cx, cy); 00129 00130 // TODO: toString() implementation, which can show cx, cy (need to be stored?) 00131 m_matrix.reset(); 00132 m_matrix.translate(cx, cy); 00133 m_matrix.rotate(angle); 00134 m_matrix.translate(-cx, -cy); 00135 } 00136 00137 void SVGTransform::setSkewX(float angle) 00138 { 00139 m_type = SVG_TRANSFORM_SKEWX; 00140 m_angle = angle; 00141 00142 m_matrix.reset(); 00143 m_matrix.skewX(angle); 00144 } 00145 00146 void SVGTransform::setSkewY(float angle) 00147 { 00148 m_type = SVG_TRANSFORM_SKEWY; 00149 m_angle = angle; 00150 00151 m_matrix.reset(); 00152 m_matrix.skewY(angle); 00153 } 00154 00155 // vim:ts=4:noet 00156 #endif // ENABLE(SVG) 00157
KDE 4.6 API Reference