• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3                   2004, 2005 Rob Buis <buis@kde.org>
4 
5     This file is part of the KDE project
6 
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Library General Public
9     License as published by the Free Software Foundation; either
10     version 2 of the License, or (at your option) any later version.
11 
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Library General Public License for more details.
16 
17     You should have received a copy of the GNU Library General Public License
18     along with this library; see the file COPYING.LIB.  If not, write to
19     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20     Boston, MA 02110-1301, USA.
21 */
22 
23 #include "config.h"
24 
25 #if ENABLE(SVG)
26 #include "TransformationMatrix.h"
27 #include "SVGTransform.h"
28 #include "SVGSVGElement.h"
29 #include "SVGTransformList.h"
30 
31 using namespace WebCore;
32 
SVGTransformList(const QualifiedName & attributeName)33 SVGTransformList::SVGTransformList(const QualifiedName& attributeName)
34     : SVGPODList<SVGTransform>(attributeName)
35 {
36 }
37 
~SVGTransformList()38 SVGTransformList::~SVGTransformList()
39 {
40 }
41 
createSVGTransformFromMatrix(const TransformationMatrix & matrix) const42 SVGTransform SVGTransformList::createSVGTransformFromMatrix(const TransformationMatrix& matrix) const
43 {
44     return SVGSVGElement::createSVGTransformFromMatrix(matrix);
45 }
46 
consolidate()47 SVGTransform SVGTransformList::consolidate()
48 {
49     ExceptionCode ec = 0;
50     return initialize(concatenate(), ec);
51 }
52 
concatenate() const53 SVGTransform SVGTransformList::concatenate() const
54 {
55     unsigned int length = numberOfItems();
56     if (!length)
57         return SVGTransform();
58 
59     TransformationMatrix matrix;
60     ExceptionCode ec = 0;
61     for (unsigned int i = 0; i < length; i++)
62         matrix = getItem(i, ec).matrix() * matrix;
63 
64     return SVGTransform(matrix);
65 }
66 
valueAsString() const67 String SVGTransformList::valueAsString() const
68 {
69     // TODO: We may want to build a real transform string, instead of concatting to a matrix(...).
70     SVGTransform transform = concatenate();
71     if (transform.type() == SVGTransform::SVG_TRANSFORM_MATRIX) {
72         TransformationMatrix matrix = transform.matrix();
73         return String::format("matrix(%f %f %f %f %f %f)", matrix.a(), matrix.b(), matrix.c(), matrix.d(), matrix.e(), matrix.f());
74     }
75 
76     return String();
77 }
78 
79 #endif // ENABLE(SVG)
80