• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3                   2004, 2005, 2006, 2008 Rob Buis <buis@kde.org>
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 "config.h"
24 
25 #if ENABLE(SVG)
26 #include "SVGTextElement.h"
27 
28 #include "FloatRect.h"
29 #include "MappedAttribute.h"
30 #include "RenderSVGText.h"
31 #include "SVGLengthList.h"
32 #include "SVGRenderStyle.h"
33 #include "SVGTSpanElement.h"
34 #include "SVGTransformList.h"
35 #include "TransformationMatrix.h"
36 
37 namespace WebCore {
38 
SVGTextElement(const QualifiedName & tagName,Document * doc)39 SVGTextElement::SVGTextElement(const QualifiedName& tagName, Document* doc)
40     : SVGTextPositioningElement(tagName, doc)
41     , SVGTransformable()
42     , m_transform(this, SVGNames::transformAttr, SVGTransformList::create(SVGNames::transformAttr))
43 {
44 }
45 
~SVGTextElement()46 SVGTextElement::~SVGTextElement()
47 {
48 }
49 
parseMappedAttribute(MappedAttribute * attr)50 void SVGTextElement::parseMappedAttribute(MappedAttribute* attr)
51 {
52     if (attr->name() == SVGNames::transformAttr) {
53         SVGTransformList* localTransforms = transformBaseValue();
54 
55         ExceptionCode ec = 0;
56         localTransforms->clear(ec);
57 
58         if (!SVGTransformable::parseTransformAttribute(localTransforms, attr->value()))
59             localTransforms->clear(ec);
60         else {
61             setTransformBaseValue(localTransforms);
62             if (renderer())
63                 renderer()->setNeedsLayout(true); // should be in setTransformBaseValue
64         }
65     } else
66         SVGTextPositioningElement::parseMappedAttribute(attr);
67 }
68 
nearestViewportElement() const69 SVGElement* SVGTextElement::nearestViewportElement() const
70 {
71     return SVGTransformable::nearestViewportElement(this);
72 }
73 
farthestViewportElement() const74 SVGElement* SVGTextElement::farthestViewportElement() const
75 {
76     return SVGTransformable::farthestViewportElement(this);
77 }
78 
getBBox() const79 FloatRect SVGTextElement::getBBox() const
80 {
81     return SVGTransformable::getBBox(this);
82 }
83 
getScreenCTM() const84 TransformationMatrix SVGTextElement::getScreenCTM() const
85 {
86     return SVGTransformable::getScreenCTM(this);
87 }
88 
getCTM() const89 TransformationMatrix SVGTextElement::getCTM() const
90 {
91     return SVGTransformable::getCTM(this);
92 }
93 
animatedLocalTransform() const94 TransformationMatrix SVGTextElement::animatedLocalTransform() const
95 {
96     return m_supplementalTransform ? transform()->concatenate().matrix() * *m_supplementalTransform : transform()->concatenate().matrix();
97 }
98 
supplementalTransform()99 TransformationMatrix* SVGTextElement::supplementalTransform()
100 {
101     if (!m_supplementalTransform)
102         m_supplementalTransform.set(new TransformationMatrix());
103     return m_supplementalTransform.get();
104 }
105 
createRenderer(RenderArena * arena,RenderStyle *)106 RenderObject* SVGTextElement::createRenderer(RenderArena* arena, RenderStyle*)
107 {
108     return new (arena) RenderSVGText(this);
109 }
110 
childShouldCreateRenderer(Node * child) const111 bool SVGTextElement::childShouldCreateRenderer(Node* child) const
112 {
113     if (child->isTextNode()
114 #if ENABLE(SVG_FONTS)
115         || child->hasTagName(SVGNames::altGlyphTag)
116 #endif
117         || child->hasTagName(SVGNames::tspanTag) || child->hasTagName(SVGNames::trefTag) || child->hasTagName(SVGNames::aTag) || child->hasTagName(SVGNames::textPathTag))
118         return true;
119     return false;
120 }
121 
svgAttributeChanged(const QualifiedName & attrName)122 void SVGTextElement::svgAttributeChanged(const QualifiedName& attrName)
123 {
124     SVGTextPositioningElement::svgAttributeChanged(attrName);
125 
126     if (!renderer())
127         return;
128 
129     if (SVGTextPositioningElement::isKnownAttribute(attrName))
130         renderer()->setNeedsLayout(true);
131 }
132 
133 }
134 
135 #endif // ENABLE(SVG)
136