• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 #if ENABLE(SVG)
24 #include "SVGTextElement.h"
25 
26 #include "AffineTransform.h"
27 #include "Attribute.h"
28 #include "FloatRect.h"
29 #include "RenderSVGResource.h"
30 #include "RenderSVGText.h"
31 #include "SVGNames.h"
32 #include "SVGRenderStyle.h"
33 #include "SVGTSpanElement.h"
34 
35 namespace WebCore {
36 
37 // Animated property definitions
DEFINE_ANIMATED_TRANSFORM_LIST(SVGTextElement,SVGNames::transformAttr,Transform,transform)38 DEFINE_ANIMATED_TRANSFORM_LIST(SVGTextElement, SVGNames::transformAttr, Transform, transform)
39 
40 inline SVGTextElement::SVGTextElement(const QualifiedName& tagName, Document* doc)
41     : SVGTextPositioningElement(tagName, doc)
42 {
43 }
44 
create(const QualifiedName & tagName,Document * document)45 PassRefPtr<SVGTextElement> SVGTextElement::create(const QualifiedName& tagName, Document* document)
46 {
47     return adoptRef(new SVGTextElement(tagName, document));
48 }
49 
parseMappedAttribute(Attribute * attr)50 void SVGTextElement::parseMappedAttribute(Attribute* attr)
51 {
52     if (SVGTransformable::isKnownAttribute(attr->name())) {
53         SVGTransformList newList;
54         if (!SVGTransformable::parseTransformAttribute(newList, attr->value()))
55             newList.clear();
56 
57         detachAnimatedTransformListWrappers(newList.size());
58         setTransformBaseValue(newList);
59     } else
60         SVGTextPositioningElement::parseMappedAttribute(attr);
61 }
62 
nearestViewportElement() const63 SVGElement* SVGTextElement::nearestViewportElement() const
64 {
65     return SVGTransformable::nearestViewportElement(this);
66 }
67 
farthestViewportElement() const68 SVGElement* SVGTextElement::farthestViewportElement() const
69 {
70     return SVGTransformable::farthestViewportElement(this);
71 }
72 
getBBox(StyleUpdateStrategy styleUpdateStrategy) const73 FloatRect SVGTextElement::getBBox(StyleUpdateStrategy styleUpdateStrategy) const
74 {
75     return SVGTransformable::getBBox(this, styleUpdateStrategy);
76 }
77 
getCTM(StyleUpdateStrategy styleUpdateStrategy) const78 AffineTransform SVGTextElement::getCTM(StyleUpdateStrategy styleUpdateStrategy) const
79 {
80     return SVGLocatable::computeCTM(this, SVGLocatable::NearestViewportScope, styleUpdateStrategy);
81 }
82 
getScreenCTM(StyleUpdateStrategy styleUpdateStrategy) const83 AffineTransform SVGTextElement::getScreenCTM(StyleUpdateStrategy styleUpdateStrategy) const
84 {
85     return SVGLocatable::computeCTM(this, SVGLocatable::ScreenScope, styleUpdateStrategy);
86 }
87 
animatedLocalTransform() const88 AffineTransform SVGTextElement::animatedLocalTransform() const
89 {
90     AffineTransform matrix;
91     transform().concatenate(matrix);
92     if (m_supplementalTransform)
93         matrix *= *m_supplementalTransform;
94     return matrix;
95 }
96 
supplementalTransform()97 AffineTransform* SVGTextElement::supplementalTransform()
98 {
99     if (!m_supplementalTransform)
100         m_supplementalTransform.set(new AffineTransform());
101     return m_supplementalTransform.get();
102 }
103 
createRenderer(RenderArena * arena,RenderStyle *)104 RenderObject* SVGTextElement::createRenderer(RenderArena* arena, RenderStyle*)
105 {
106     return new (arena) RenderSVGText(this);
107 }
108 
childShouldCreateRenderer(Node * child) const109 bool SVGTextElement::childShouldCreateRenderer(Node* child) const
110 {
111     if (child->isTextNode()
112         || child->hasTagName(SVGNames::aTag)
113 #if ENABLE(SVG_FONTS)
114         || child->hasTagName(SVGNames::altGlyphTag)
115 #endif
116         || child->hasTagName(SVGNames::textPathTag)
117         || child->hasTagName(SVGNames::trefTag)
118         || child->hasTagName(SVGNames::tspanTag))
119         return true;
120 
121     return false;
122 }
123 
svgAttributeChanged(const QualifiedName & attrName)124 void SVGTextElement::svgAttributeChanged(const QualifiedName& attrName)
125 {
126     SVGTextPositioningElement::svgAttributeChanged(attrName);
127 
128     RenderObject* renderer = this->renderer();
129     if (!renderer)
130         return;
131 
132     if (SVGTransformable::isKnownAttribute(attrName)) {
133         renderer->setNeedsTransformUpdate();
134         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
135     }
136 }
137 
synchronizeProperty(const QualifiedName & attrName)138 void SVGTextElement::synchronizeProperty(const QualifiedName& attrName)
139 {
140     SVGTextPositioningElement::synchronizeProperty(attrName);
141 
142     if (attrName == anyQName() || SVGTransformable::isKnownAttribute(attrName))
143         synchronizeTransform();
144 }
145 
attributeToPropertyTypeMap()146 AttributeToPropertyTypeMap& SVGTextElement::attributeToPropertyTypeMap()
147 {
148     DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ());
149     return s_attributeToPropertyTypeMap;
150 }
151 
fillAttributeToPropertyTypeMap()152 void SVGTextElement::fillAttributeToPropertyTypeMap()
153 {
154     AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap();
155 
156     SVGTextPositioningElement::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap);
157     attributeToPropertyTypeMap.set(SVGNames::transformAttr, AnimatedTransformList);
158 }
159 
160 }
161 
162 #endif // ENABLE(SVG)
163