1/*
2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2008 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 "SVGTextElement.h"
23
24#include "Attribute.h"
25#include "RenderSVGResource.h"
26#include "RenderSVGText.h"
27#include "SVGElementInstance.h"
28#include "SVGNames.h"
29#include "SVGRenderStyle.h"
30#include "SVGTSpanElement.h"
31
32namespace WebCore {
33
34inline SVGTextElement::SVGTextElement(const QualifiedName& tagName, Document& document)
35    : SVGTextPositioningElement(tagName, document)
36{
37    ASSERT(hasTagName(SVGNames::textTag));
38}
39
40PassRefPtr<SVGTextElement> SVGTextElement::create(const QualifiedName& tagName, Document& document)
41{
42    return adoptRef(new SVGTextElement(tagName, document));
43}
44
45// We override SVGGraphics::animatedLocalTransform() so that the transform-origin
46// is not taken into account.
47AffineTransform SVGTextElement::animatedLocalTransform() const
48{
49    AffineTransform matrix;
50    RenderStyle* style = renderer() ? &renderer()->style() : nullptr;
51
52    // if CSS property was set, use that, otherwise fallback to attribute (if set)
53    if (style && style->hasTransform()) {
54        TransformationMatrix t;
55        // For now, the transform-origin is not taken into account
56        // Also, any percentage values will not be taken into account
57        style->applyTransform(t, FloatRect(0, 0, 0, 0), RenderStyle::ExcludeTransformOrigin);
58        // Flatten any 3D transform
59        matrix = t.toAffineTransform();
60    } else
61        transform().concatenate(matrix);
62
63    const AffineTransform* transform = const_cast<SVGTextElement*>(this)->supplementalTransform();
64    if (transform)
65        return *transform * matrix;
66    return matrix;
67}
68
69RenderPtr<RenderElement> SVGTextElement::createElementRenderer(PassRef<RenderStyle> style)
70{
71    return createRenderer<RenderSVGText>(*this, WTF::move(style));
72}
73
74bool SVGTextElement::childShouldCreateRenderer(const Node& child) const
75{
76    if (child.isTextNode()
77        || child.hasTagName(SVGNames::aTag)
78#if ENABLE(SVG_FONTS)
79        || child.hasTagName(SVGNames::altGlyphTag)
80#endif
81        || child.hasTagName(SVGNames::textPathTag)
82        || child.hasTagName(SVGNames::trefTag)
83        || child.hasTagName(SVGNames::tspanTag))
84        return true;
85
86    return false;
87}
88
89}
90