1 /*
2 Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005 Rob Buis <buis@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 #include "config.h"
22
23 #if ENABLE(SVG)
24 #include "SVGTransformList.h"
25
26 #include "AffineTransform.h"
27 #include "SVGSVGElement.h"
28 #include "SVGTransform.h"
29
30 using namespace WebCore;
31
SVGTransformList(const QualifiedName & attributeName)32 SVGTransformList::SVGTransformList(const QualifiedName& attributeName)
33 : SVGPODList<SVGTransform>(attributeName)
34 {
35 }
36
~SVGTransformList()37 SVGTransformList::~SVGTransformList()
38 {
39 }
40
createSVGTransformFromMatrix(const AffineTransform & matrix) const41 SVGTransform SVGTransformList::createSVGTransformFromMatrix(const AffineTransform& matrix) const
42 {
43 return SVGSVGElement::createSVGTransformFromMatrix(matrix);
44 }
45
consolidate()46 SVGTransform SVGTransformList::consolidate()
47 {
48 ExceptionCode ec = 0;
49 return initialize(concatenate(), ec);
50 }
51
concatenate() const52 SVGTransform SVGTransformList::concatenate() const
53 {
54 unsigned int length = numberOfItems();
55 if (!length)
56 return SVGTransform();
57
58 AffineTransform matrix;
59 ExceptionCode ec = 0;
60 for (unsigned int i = 0; i < length; i++)
61 matrix = getItem(i, ec).matrix() * matrix;
62
63 return SVGTransform(matrix);
64 }
65
valueAsString() const66 String SVGTransformList::valueAsString() const
67 {
68 // TODO: We may want to build a real transform string, instead of concatting to a matrix(...).
69 SVGTransform transform = concatenate();
70 if (transform.type() == SVGTransform::SVG_TRANSFORM_MATRIX) {
71 AffineTransform matrix = transform.matrix();
72 return String::format("matrix(%f %f %f %f %f %f)", matrix.a(), matrix.b(), matrix.c(), matrix.d(), matrix.e(), matrix.f());
73 }
74
75 return String();
76 }
77
78 #endif // ENABLE(SVG)
79