initial import
[vuplus_webkit] / Source / WebCore / svg / SVGTransformList.cpp
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 #include <wtf/text/StringBuilder.h>
30
31 namespace WebCore {
32
33 SVGTransform SVGTransformList::createSVGTransformFromMatrix(const SVGMatrix& matrix) const
34 {
35     return SVGSVGElement::createSVGTransformFromMatrix(matrix);
36 }
37
38 SVGTransform SVGTransformList::consolidate()
39 {
40     AffineTransform matrix;
41     if (!concatenate(matrix))
42         return SVGTransform();
43
44     SVGTransform transform(matrix);
45     clear();
46     append(transform);
47     return transform;
48 }
49
50 bool SVGTransformList::concatenate(AffineTransform& result) const
51 {
52     unsigned size = this->size();
53     if (!size)
54         return false;
55
56     for (unsigned i = 0; i < size; ++i)
57         result *= at(i).matrix();
58
59     return true;
60 }
61
62 String SVGTransformList::valueAsString() const
63 {
64     StringBuilder builder;
65     unsigned size = this->size();
66     for (unsigned i = 0; i < size; ++i) {
67         if (i > 0)
68             builder.append(' ');
69
70         builder.append(at(i).valueAsString());
71     }
72
73     return builder.toString();
74 }
75
76 } // namespace WebCore
77
78 #endif // ENABLE(SVG)