| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "core/svg/SVGTransform.h" | 22 #include "core/svg/SVGTransform.h" |
| 23 | 23 |
| 24 #include "platform/FloatConversion.h" | 24 #include "platform/FloatConversion.h" |
| 25 #include "platform/geometry/FloatSize.h" | 25 #include "platform/geometry/FloatSize.h" |
| 26 #include "wtf/MathExtras.h" | 26 #include "wtf/MathExtras.h" |
| 27 #include "wtf/text/StringBuilder.h" | 27 #include "wtf/text/StringBuilder.h" |
| 28 | 28 |
| 29 namespace WebCore { | 29 namespace WebCore { |
| 30 | 30 |
| 31 SVGTransform::SVGTransform() | 31 SVGTransform::SVGTransform() |
| 32 : m_type(SVG_TRANSFORM_UNKNOWN) | 32 : NewSVGPropertyBase(classType()) |
| 33 , m_transformType(SVG_TRANSFORM_UNKNOWN) |
| 33 , m_angle(0) | 34 , m_angle(0) |
| 34 { | 35 { |
| 35 } | 36 } |
| 36 | 37 |
| 37 SVGTransform::SVGTransform(SVGTransformType type, ConstructionMode mode) | 38 SVGTransform::SVGTransform(SVGTransformType transformType, ConstructionMode mode
) |
| 38 : m_type(type) | 39 : NewSVGPropertyBase(classType()) |
| 40 , m_transformType(transformType) |
| 39 , m_angle(0) | 41 , m_angle(0) |
| 40 { | 42 { |
| 41 if (mode == ConstructZeroTransform) | 43 if (mode == ConstructZeroTransform) |
| 42 m_matrix = AffineTransform(0, 0, 0, 0, 0, 0); | 44 m_matrix = AffineTransform(0, 0, 0, 0, 0, 0); |
| 43 } | 45 } |
| 44 | 46 |
| 45 SVGTransform::SVGTransform(const AffineTransform& matrix) | 47 SVGTransform::SVGTransform(const AffineTransform& matrix) |
| 46 : m_type(SVG_TRANSFORM_MATRIX) | 48 : NewSVGPropertyBase(classType()) |
| 49 , m_transformType(SVG_TRANSFORM_MATRIX) |
| 47 , m_angle(0) | 50 , m_angle(0) |
| 48 , m_matrix(matrix) | 51 , m_matrix(matrix) |
| 49 { | 52 { |
| 50 } | 53 } |
| 51 | 54 |
| 55 SVGTransform::SVGTransform(SVGTransformType transformType, float angle, const Fl
oatPoint& center, const AffineTransform& matrix) |
| 56 : NewSVGPropertyBase(classType()) |
| 57 , m_transformType(transformType) |
| 58 , m_angle(angle) |
| 59 , m_center(center) |
| 60 , m_matrix(matrix) |
| 61 { |
| 62 } |
| 63 |
| 64 SVGTransform::~SVGTransform() |
| 65 { |
| 66 } |
| 67 |
| 68 PassRefPtr<SVGTransform> SVGTransform::clone() const |
| 69 { |
| 70 return adoptRef(new SVGTransform(m_transformType, m_angle, m_center, m_matri
x)); |
| 71 } |
| 72 |
| 73 PassRefPtr<NewSVGPropertyBase> SVGTransform::cloneForAnimation(const String&) co
nst |
| 74 { |
| 75 // SVGTransform is never animated. |
| 76 ASSERT_NOT_REACHED(); |
| 77 return 0; |
| 78 } |
| 79 |
| 52 void SVGTransform::setMatrix(const AffineTransform& matrix) | 80 void SVGTransform::setMatrix(const AffineTransform& matrix) |
| 53 { | 81 { |
| 54 m_type = SVG_TRANSFORM_MATRIX; | 82 onMatrixChange(); |
| 55 m_angle = 0; | |
| 56 m_matrix = matrix; | 83 m_matrix = matrix; |
| 57 } | 84 } |
| 58 | 85 |
| 59 void SVGTransform::updateSVGMatrix() | 86 void SVGTransform::onMatrixChange() |
| 60 { | 87 { |
| 61 // The underlying matrix has been changed, alter the transformation type. | 88 m_transformType = SVG_TRANSFORM_MATRIX; |
| 62 // Spec: In case the matrix object is changed directly (i.e., without using
the methods on the SVGTransform interface itself) | |
| 63 // then the type of the SVGTransform changes to SVG_TRANSFORM_MATRIX. | |
| 64 m_type = SVG_TRANSFORM_MATRIX; | |
| 65 m_angle = 0; | 89 m_angle = 0; |
| 66 } | 90 } |
| 67 | 91 |
| 68 void SVGTransform::setTranslate(float tx, float ty) | 92 void SVGTransform::setTranslate(float tx, float ty) |
| 69 { | 93 { |
| 70 m_type = SVG_TRANSFORM_TRANSLATE; | 94 m_transformType = SVG_TRANSFORM_TRANSLATE; |
| 71 m_angle = 0; | 95 m_angle = 0; |
| 72 | 96 |
| 73 m_matrix.makeIdentity(); | 97 m_matrix.makeIdentity(); |
| 74 m_matrix.translate(tx, ty); | 98 m_matrix.translate(tx, ty); |
| 75 } | 99 } |
| 76 | 100 |
| 77 FloatPoint SVGTransform::translate() const | 101 FloatPoint SVGTransform::translate() const |
| 78 { | 102 { |
| 79 return FloatPoint::narrowPrecision(m_matrix.e(), m_matrix.f()); | 103 return FloatPoint::narrowPrecision(m_matrix.e(), m_matrix.f()); |
| 80 } | 104 } |
| 81 | 105 |
| 82 void SVGTransform::setScale(float sx, float sy) | 106 void SVGTransform::setScale(float sx, float sy) |
| 83 { | 107 { |
| 84 m_type = SVG_TRANSFORM_SCALE; | 108 m_transformType = SVG_TRANSFORM_SCALE; |
| 85 m_angle = 0; | 109 m_angle = 0; |
| 86 m_center = FloatPoint(); | 110 m_center = FloatPoint(); |
| 87 | 111 |
| 88 m_matrix.makeIdentity(); | 112 m_matrix.makeIdentity(); |
| 89 m_matrix.scaleNonUniform(sx, sy); | 113 m_matrix.scaleNonUniform(sx, sy); |
| 90 } | 114 } |
| 91 | 115 |
| 92 FloatSize SVGTransform::scale() const | 116 FloatSize SVGTransform::scale() const |
| 93 { | 117 { |
| 94 return FloatSize::narrowPrecision(m_matrix.a(), m_matrix.d()); | 118 return FloatSize::narrowPrecision(m_matrix.a(), m_matrix.d()); |
| 95 } | 119 } |
| 96 | 120 |
| 97 void SVGTransform::setRotate(float angle, float cx, float cy) | 121 void SVGTransform::setRotate(float angle, float cx, float cy) |
| 98 { | 122 { |
| 99 m_type = SVG_TRANSFORM_ROTATE; | 123 m_transformType = SVG_TRANSFORM_ROTATE; |
| 100 m_angle = angle; | 124 m_angle = angle; |
| 101 m_center = FloatPoint(cx, cy); | 125 m_center = FloatPoint(cx, cy); |
| 102 | 126 |
| 103 // TODO: toString() implementation, which can show cx, cy (need to be stored
?) | 127 // TODO: toString() implementation, which can show cx, cy (need to be stored
?) |
| 104 m_matrix.makeIdentity(); | 128 m_matrix.makeIdentity(); |
| 105 m_matrix.translate(cx, cy); | 129 m_matrix.translate(cx, cy); |
| 106 m_matrix.rotate(angle); | 130 m_matrix.rotate(angle); |
| 107 m_matrix.translate(-cx, -cy); | 131 m_matrix.translate(-cx, -cy); |
| 108 } | 132 } |
| 109 | 133 |
| 110 void SVGTransform::setSkewX(float angle) | 134 void SVGTransform::setSkewX(float angle) |
| 111 { | 135 { |
| 112 m_type = SVG_TRANSFORM_SKEWX; | 136 m_transformType = SVG_TRANSFORM_SKEWX; |
| 113 m_angle = angle; | 137 m_angle = angle; |
| 114 | 138 |
| 115 m_matrix.makeIdentity(); | 139 m_matrix.makeIdentity(); |
| 116 m_matrix.skewX(angle); | 140 m_matrix.skewX(angle); |
| 117 } | 141 } |
| 118 | 142 |
| 119 void SVGTransform::setSkewY(float angle) | 143 void SVGTransform::setSkewY(float angle) |
| 120 { | 144 { |
| 121 m_type = SVG_TRANSFORM_SKEWY; | 145 m_transformType = SVG_TRANSFORM_SKEWY; |
| 122 m_angle = angle; | 146 m_angle = angle; |
| 123 | 147 |
| 124 m_matrix.makeIdentity(); | 148 m_matrix.makeIdentity(); |
| 125 m_matrix.skewY(angle); | 149 m_matrix.skewY(angle); |
| 126 } | 150 } |
| 127 | 151 |
| 128 const String& SVGTransform::transformTypePrefixForParsing(SVGTransformType type) | 152 namespace { |
| 153 |
| 154 const String& transformTypePrefixForParsing(SVGTransformType type) |
| 129 { | 155 { |
| 130 switch (type) { | 156 switch (type) { |
| 131 case SVG_TRANSFORM_UNKNOWN: | 157 case SVG_TRANSFORM_UNKNOWN: |
| 132 return emptyString(); | 158 return emptyString(); |
| 133 case SVG_TRANSFORM_MATRIX: { | 159 case SVG_TRANSFORM_MATRIX: { |
| 134 DEFINE_STATIC_LOCAL(String, matrixString, ("matrix(")); | 160 DEFINE_STATIC_LOCAL(String, matrixString, ("matrix(")); |
| 135 return matrixString; | 161 return matrixString; |
| 136 } | 162 } |
| 137 case SVG_TRANSFORM_TRANSLATE: { | 163 case SVG_TRANSFORM_TRANSLATE: { |
| 138 DEFINE_STATIC_LOCAL(String, translateString, ("translate(")); | 164 DEFINE_STATIC_LOCAL(String, translateString, ("translate(")); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 153 case SVG_TRANSFORM_SKEWY: { | 179 case SVG_TRANSFORM_SKEWY: { |
| 154 DEFINE_STATIC_LOCAL(String, skewYString, ("skewY(")); | 180 DEFINE_STATIC_LOCAL(String, skewYString, ("skewY(")); |
| 155 return skewYString; | 181 return skewYString; |
| 156 } | 182 } |
| 157 } | 183 } |
| 158 | 184 |
| 159 ASSERT_NOT_REACHED(); | 185 ASSERT_NOT_REACHED(); |
| 160 return emptyString(); | 186 return emptyString(); |
| 161 } | 187 } |
| 162 | 188 |
| 189 } |
| 190 |
| 163 String SVGTransform::valueAsString() const | 191 String SVGTransform::valueAsString() const |
| 164 { | 192 { |
| 165 const String& prefix = transformTypePrefixForParsing(m_type); | 193 const String& prefix = transformTypePrefixForParsing(m_transformType); |
| 166 switch (m_type) { | 194 switch (m_transformType) { |
| 167 case SVG_TRANSFORM_UNKNOWN: | 195 case SVG_TRANSFORM_UNKNOWN: |
| 168 return prefix; | 196 return prefix; |
| 169 case SVG_TRANSFORM_MATRIX: { | 197 case SVG_TRANSFORM_MATRIX: { |
| 170 StringBuilder builder; | 198 StringBuilder builder; |
| 171 builder.append(prefix + String::number(m_matrix.a()) + ' ' + String::num
ber(m_matrix.b()) + ' ' + String::number(m_matrix.c()) + ' ' + | 199 builder.append(prefix + String::number(m_matrix.a()) + ' ' + String::num
ber(m_matrix.b()) + ' ' + String::number(m_matrix.c()) + ' ' + |
| 172 String::number(m_matrix.d()) + ' ' + String::number(m_mat
rix.e()) + ' ' + String::number(m_matrix.f()) + ')'); | 200 String::number(m_matrix.d()) + ' ' + String::number(m_mat
rix.e()) + ' ' + String::number(m_matrix.f()) + ')'); |
| 173 return builder.toString(); | 201 return builder.toString(); |
| 174 } | 202 } |
| 175 case SVG_TRANSFORM_TRANSLATE: | 203 case SVG_TRANSFORM_TRANSLATE: |
| 176 return prefix + String::number(m_matrix.e()) + ' ' + String::number(m_ma
trix.f()) + ')'; | 204 return prefix + String::number(m_matrix.e()) + ' ' + String::number(m_ma
trix.f()) + ')'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 189 case SVG_TRANSFORM_SKEWX: | 217 case SVG_TRANSFORM_SKEWX: |
| 190 return prefix + String::number(m_angle) + ')'; | 218 return prefix + String::number(m_angle) + ')'; |
| 191 case SVG_TRANSFORM_SKEWY: | 219 case SVG_TRANSFORM_SKEWY: |
| 192 return prefix + String::number(m_angle) + ')'; | 220 return prefix + String::number(m_angle) + ')'; |
| 193 } | 221 } |
| 194 | 222 |
| 195 ASSERT_NOT_REACHED(); | 223 ASSERT_NOT_REACHED(); |
| 196 return emptyString(); | 224 return emptyString(); |
| 197 } | 225 } |
| 198 | 226 |
| 227 void SVGTransform::add(PassRefPtr<NewSVGPropertyBase>, SVGElement*) |
| 228 { |
| 229 // SVGTransform is not animated by itself. |
| 230 ASSERT_NOT_REACHED(); |
| 231 } |
| 232 |
| 233 void SVGTransform::calculateAnimatedValue(SVGAnimationElement*, float, unsigned,
PassRefPtr<NewSVGPropertyBase>, PassRefPtr<NewSVGPropertyBase>, PassRefPtr<NewS
VGPropertyBase>, SVGElement*) |
| 234 { |
| 235 // SVGTransform is not animated by itself. |
| 236 ASSERT_NOT_REACHED(); |
| 237 } |
| 238 |
| 239 float SVGTransform::calculateDistance(PassRefPtr<NewSVGPropertyBase>, SVGElement
*) |
| 240 { |
| 241 // SVGTransform is not animated by itself. |
| 242 ASSERT_NOT_REACHED(); |
| 243 |
| 244 return -1; |
| 245 } |
| 246 |
| 199 } // namespace WebCore | 247 } // namespace WebCore |
| OLD | NEW |