• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 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 #include <wtf/text/StringBuilder.h>
31 #include <wtf/text/StringConcatenate.h>
32 
33 namespace WebCore {
34 
createSVGTransformFromMatrix(const SVGMatrix & matrix) const35 SVGTransform SVGTransformList::createSVGTransformFromMatrix(const SVGMatrix& matrix) const
36 {
37     return SVGSVGElement::createSVGTransformFromMatrix(matrix);
38 }
39 
consolidate()40 SVGTransform SVGTransformList::consolidate()
41 {
42     AffineTransform matrix;
43     if (!concatenate(matrix))
44         return SVGTransform();
45 
46     SVGTransform transform(matrix);
47     clear();
48     append(transform);
49     return transform;
50 }
51 
concatenate(AffineTransform & result) const52 bool SVGTransformList::concatenate(AffineTransform& result) const
53 {
54     unsigned size = this->size();
55     if (!size)
56         return false;
57 
58     for (unsigned i = 0; i < size; ++i)
59         result *= at(i).matrix();
60 
61     return true;
62 }
63 
valueAsString() const64 String SVGTransformList::valueAsString() const
65 {
66     StringBuilder builder;
67     unsigned size = this->size();
68     for (unsigned i = 0; i < size; ++i) {
69         if (i > 0)
70             builder.append(' ');
71 
72         builder.append(at(i).valueAsString());
73     }
74 
75     return builder.toString();
76 }
77 
78 } // namespace WebCore
79 
80 #endif // ENABLE(SVG)
81