KHtml

SVGTextElement.cpp
1 /*
2  Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006, 2008 Rob Buis <[email protected]>
4 
5  This file is part of the KDE project
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "wtf/Platform.h"
24 
25 #if ENABLE(SVG)
26 #include "SVGTextElement.h"
27 
28 #include "AffineTransform.h"
29 #include "FloatRect.h"
30 #include "RenderSVGText.h"
31 #include "SVGLengthList.h"
32 #include "SVGRenderStyle.h"
33 #include "SVGTSpanElement.h"
34 #include "SVGTransformList.h"
35 
36 namespace WebCore
37 {
38 
39 SVGTextElement::SVGTextElement(const QualifiedName &tagName, Document *doc)
40  : SVGTextPositioningElement(tagName, doc)
41  , SVGTransformable()
42  , m_transform(SVGTransformList::create(SVGNames::transformAttr))
43 {
44 }
45 
46 SVGTextElement::~SVGTextElement()
47 {
48 }
49 
50 ANIMATED_PROPERTY_DEFINITIONS(SVGTextElement, SVGTransformList *, TransformList, transformList, Transform, transform, SVGNames::transformAttr, m_transform.get())
51 
52 void SVGTextElement::parseMappedAttribute(MappedAttribute *attr)
53 {
54  if (attr->name() == SVGNames::transformAttr) {
55  SVGTransformList *localTransforms = transformBaseValue();
56 
57  ExceptionCode ec = 0;
58  localTransforms->clear(ec);
59 
60  if (!SVGTransformable::parseTransformAttribute(localTransforms, attr->value())) {
61  localTransforms->clear(ec);
62  } else {
63  setTransformBaseValue(localTransforms);
64  if (renderer()) {
65  renderer()->setNeedsLayout(true); // should be in setTransformBaseValue
66  }
67  }
68  } else {
69  SVGTextPositioningElement::parseMappedAttribute(attr);
70  }
71 }
72 
73 SVGElement *SVGTextElement::nearestViewportElement() const
74 {
75  return SVGTransformable::nearestViewportElement(this);
76 }
77 
78 SVGElement *SVGTextElement::farthestViewportElement() const
79 {
80  return SVGTransformable::farthestViewportElement(this);
81 }
82 
83 FloatRect SVGTextElement::getBBox() const
84 {
85  return SVGTransformable::getBBox(this);
86 }
87 
88 AffineTransform SVGTextElement::getScreenCTM() const
89 {
90  return SVGTransformable::getScreenCTM(this);
91 }
92 
93 AffineTransform SVGTextElement::getCTM() const
94 {
95  return SVGTransformable::getCTM(this);
96 }
97 
98 AffineTransform SVGTextElement::animatedLocalTransform() const
99 {
100  return m_supplementalTransform ? transform()->concatenate().matrix() **m_supplementalTransform : transform()->concatenate().matrix();
101 }
102 
103 AffineTransform *SVGTextElement::supplementalTransform()
104 {
105  if (!m_supplementalTransform) {
106  m_supplementalTransform.set(new AffineTransform());
107  }
108  return m_supplementalTransform.get();
109 }
110 
111 RenderObject *SVGTextElement::createRenderer(RenderArena *arena, RenderStyle *style)
112 {
113  Q_UNUSED(style);
114  // qCDebug(KHTML_LOG) << "create renderer for <text>";
115  return new(arena) RenderSVGText(this);
116 }
117 
118 bool SVGTextElement::childShouldCreateRenderer(Node *child) const
119 {
120  if (child->isTextNode()
121 #if ENABLE(SVG_FONTS)
122  || child->hasTagName(SVGNames::altGlyphTag)
123 #endif
124  || child->hasTagName(SVGNames::tspanTag) || child->hasTagName(SVGNames::trefTag) || child->hasTagName(SVGNames::aTag) || child->hasTagName(SVGNames::textPathTag)) {
125  return true;
126  }
127  return false;
128 }
129 
130 void SVGTextElement::svgAttributeChanged(const QualifiedName &attrName)
131 {
132  SVGTextPositioningElement::svgAttributeChanged(attrName);
133 
134  if (!renderer()) {
135  return;
136  }
137 
138  if (SVGTextPositioningElement::isKnownAttribute(attrName)) {
139  renderer()->setNeedsLayout(true);
140  }
141 }
142 
143 }
144 
145 #endif // ENABLE(SVG)
QAction * create(StandardAction id, const QObject *recvr, Func slot, QObject *parent)
KDOCTOOLS_EXPORT QString transform(const QString &file, const QString &stylesheet, const QVector< const char * > &params=QVector< const char * >())
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.