blob: cd9d0dfb9ec23c82515e4f3ed11518b1b9157a33 [file] [log] [blame]
darinb9481ed2006-03-20 02:57:59 +00001/*
zimmermann@webkit.org711245f2010-08-03 19:39:01 +00002 * 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 */
darinb9481ed2006-03-20 02:57:59 +000020
21#include "config.h"
oliver98d52382007-10-12 10:47:18 +000022
mjsd2948ef2007-02-26 19:29:04 +000023#if ENABLE(SVG)
darinb9481ed2006-03-20 02:57:59 +000024#include "SVGTextElement.h"
darincfcabdb2006-04-02 02:41:24 +000025
weinig@apple.comc3608932010-05-19 17:48:06 +000026#include "Attribute.h"
zimmermann@webkit.org5bed57f2010-07-16 08:26:24 +000027#include "RenderSVGResource.h"
rwlbuis40a85562006-10-12 15:07:55 +000028#include "RenderSVGText.h"
zimmermann@webkit.orgefff7252011-05-21 06:15:40 +000029#include "SVGElementInstance.h"
zimmermann@webkit.org42ab4a72010-12-03 11:14:32 +000030#include "SVGNames.h"
darinb9481ed2006-03-20 02:57:59 +000031#include "SVGRenderStyle.h"
darincfcabdb2006-04-02 02:41:24 +000032#include "SVGTSpanElement.h"
darinb9481ed2006-03-20 02:57:59 +000033
34namespace WebCore {
35
weinig@apple.com52e786e2013-09-15 18:06:06 +000036inline SVGTextElement::SVGTextElement(const QualifiedName& tagName, Document& document)
37 : SVGTextPositioningElement(tagName, document)
darinb9481ed2006-03-20 02:57:59 +000038{
rwlbuis@webkit.org25518122011-05-09 13:41:55 +000039 ASSERT(hasTagName(SVGNames::textTag));
darinb9481ed2006-03-20 02:57:59 +000040}
41
weinig@apple.com52e786e2013-09-15 18:06:06 +000042PassRefPtr<SVGTextElement> SVGTextElement::create(const QualifiedName& tagName, Document& document)
darin@apple.com3cbd5cb2010-08-30 06:51:56 +000043{
darin@apple.com69b3ef42010-08-31 17:08:40 +000044 return adoptRef(new SVGTextElement(tagName, document));
darin@apple.com3cbd5cb2010-08-30 06:51:56 +000045}
46
ch.dumez@sisa.samsung.com50e120f2013-07-04 18:48:51 +000047// We override SVGGraphics::animatedLocalTransform() so that the transform-origin
48// is not taken into account.
krit@webkit.org2b95a9a2010-02-08 20:30:42 +000049AffineTransform SVGTextElement::animatedLocalTransform() const
oliver09e98ea2007-10-12 15:38:34 +000050{
zimmermann@webkit.orgbbd697c2010-11-11 11:20:11 +000051 AffineTransform matrix;
akling@apple.com827be9c2013-10-29 02:58:43 +000052 RenderStyle* style = renderer() ? &renderer()->style() : nullptr;
commit-queue@webkit.org0db57552011-11-23 11:34:37 +000053
54 // if CSS property was set, use that, otherwise fallback to attribute (if set)
schenney@chromium.orgfa6cd712012-03-28 14:28:02 +000055 if (style && style->hasTransform()) {
commit-queue@webkit.org0db57552011-11-23 11:34:37 +000056 TransformationMatrix t;
57 // For now, the transform-origin is not taken into account
58 // Also, any percentage values will not be taken into account
59 style->applyTransform(t, IntSize(0, 0), RenderStyle::ExcludeTransformOrigin);
60 // Flatten any 3D transform
61 matrix = t.toAffineTransform();
62 } else
63 transform().concatenate(matrix);
64
ch.dumez@sisa.samsung.com50e120f2013-07-04 18:48:51 +000065 const AffineTransform* transform = const_cast<SVGTextElement*>(this)->supplementalTransform();
66 if (transform)
67 return *transform * matrix;
commit-queue@webkit.org17b17862011-01-19 20:10:07 +000068 return matrix;
antti@apple.comaf579272008-04-18 07:40:17 +000069}
70
akling@apple.com8f40c5b2013-10-27 22:54:07 +000071RenderElement* SVGTextElement::createRenderer(PassRef<RenderStyle> style)
darinb9481ed2006-03-20 02:57:59 +000072{
akling@apple.com8f40c5b2013-10-27 22:54:07 +000073 return new RenderSVGText(*this, std::move(style));
darinb9481ed2006-03-20 02:57:59 +000074}
75
antti@apple.comdacd6de2013-08-20 22:52:55 +000076bool SVGTextElement::childShouldCreateRenderer(const Node* child) const
darinb9481ed2006-03-20 02:57:59 +000077{
antti@apple.comdacd6de2013-08-20 22:52:55 +000078 if (child->isTextNode()
79 || child->hasTagName(SVGNames::aTag)
hausmann@webkit.orgaf1cc002008-03-27 21:37:33 +000080#if ENABLE(SVG_FONTS)
antti@apple.comdacd6de2013-08-20 22:52:55 +000081 || child->hasTagName(SVGNames::altGlyphTag)
hausmann@webkit.orgaf1cc002008-03-27 21:37:33 +000082#endif
antti@apple.comdacd6de2013-08-20 22:52:55 +000083 || child->hasTagName(SVGNames::textPathTag)
84 || child->hasTagName(SVGNames::trefTag)
85 || child->hasTagName(SVGNames::tspanTag))
darinb9481ed2006-03-20 02:57:59 +000086 return true;
commit-queue@webkit.orgea6bdc72010-12-11 01:23:26 +000087
darinb9481ed2006-03-20 02:57:59 +000088 return false;
89}
90
91}
92
mjsd2948ef2007-02-26 19:29:04 +000093#endif // ENABLE(SVG)