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#include "SVGTransformList.h"
23
24#include "AffineTransform.h"
25#include "SVGSVGElement.h"
26#include "SVGTransform.h"
27#include "SVGTransformable.h"
28#include <wtf/text/StringBuilder.h>
29
30namespace WebCore {
31
32SVGTransform SVGTransformList::createSVGTransformFromMatrix(const SVGMatrix& matrix) const
33{
34    return SVGSVGElement::createSVGTransformFromMatrix(matrix);
35}
36
37SVGTransform SVGTransformList::consolidate()
38{
39    AffineTransform matrix;
40    if (!concatenate(matrix))
41        return SVGTransform();
42
43    SVGTransform transform(matrix);
44    clear();
45    append(transform);
46    return transform;
47}
48
49bool SVGTransformList::concatenate(AffineTransform& result) const
50{
51    unsigned size = this->size();
52    if (!size)
53        return false;
54
55    for (unsigned i = 0; i < size; ++i)
56        result *= at(i).matrix();
57
58    return true;
59}
60
61String SVGTransformList::valueAsString() const
62{
63    StringBuilder builder;
64    unsigned size = this->size();
65    for (unsigned i = 0; i < size; ++i) {
66        if (i > 0)
67            builder.append(' ');
68
69        builder.append(at(i).valueAsString());
70    }
71
72    return builder.toString();
73}
74
75void SVGTransformList::parse(const String& transform)
76{
77    auto upconvertedCharacters = StringView(transform).upconvertedCharacters();
78    const UChar* start = upconvertedCharacters;
79    if (!SVGTransformable::parseTransformAttribute(*this, start, start + transform.length()))
80        clear();
81}
82
83} // namespace WebCore
84