2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org>
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.
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.
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.
24 #include "SVGTextElement.h"
26 #include "AffineTransform.h"
27 #include "Attribute.h"
28 #include "FloatRect.h"
29 #include "RenderSVGResource.h"
30 #include "RenderSVGText.h"
31 #include "SVGElementInstance.h"
33 #include "SVGRenderStyle.h"
34 #include "SVGTSpanElement.h"
38 // Animated property definitions
39 DEFINE_ANIMATED_TRANSFORM_LIST(SVGTextElement, SVGNames::transformAttr, Transform, transform)
41 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGTextElement)
42 REGISTER_LOCAL_ANIMATED_PROPERTY(transform)
43 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTextPositioningElement)
44 END_REGISTER_ANIMATED_PROPERTIES
46 inline SVGTextElement::SVGTextElement(const QualifiedName& tagName, Document* doc)
47 : SVGTextPositioningElement(tagName, doc)
49 ASSERT(hasTagName(SVGNames::textTag));
50 registerAnimatedPropertiesForSVGTextElement();
53 PassRefPtr<SVGTextElement> SVGTextElement::create(const QualifiedName& tagName, Document* document)
55 return adoptRef(new SVGTextElement(tagName, document));
58 bool SVGTextElement::isSupportedAttribute(const QualifiedName& attrName)
60 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
61 if (supportedAttributes.isEmpty())
62 supportedAttributes.add(SVGNames::transformAttr);
63 return supportedAttributes.contains<QualifiedName, SVGAttributeHashTranslator>(attrName);
66 void SVGTextElement::parseMappedAttribute(Attribute* attr)
68 if (!isSupportedAttribute(attr->name())) {
69 SVGTextPositioningElement::parseMappedAttribute(attr);
73 if (attr->name() == SVGNames::transformAttr) {
74 SVGTransformList newList;
75 if (!SVGTransformable::parseTransformAttribute(newList, attr->value()))
78 detachAnimatedTransformListWrappers(newList.size());
79 setTransformBaseValue(newList);
86 SVGElement* SVGTextElement::nearestViewportElement() const
88 return SVGTransformable::nearestViewportElement(this);
91 SVGElement* SVGTextElement::farthestViewportElement() const
93 return SVGTransformable::farthestViewportElement(this);
96 FloatRect SVGTextElement::getBBox(StyleUpdateStrategy styleUpdateStrategy)
98 return SVGTransformable::getBBox(this, styleUpdateStrategy);
101 AffineTransform SVGTextElement::getCTM(StyleUpdateStrategy styleUpdateStrategy)
103 return SVGLocatable::computeCTM(this, SVGLocatable::NearestViewportScope, styleUpdateStrategy);
106 AffineTransform SVGTextElement::getScreenCTM(StyleUpdateStrategy styleUpdateStrategy)
108 return SVGLocatable::computeCTM(this, SVGLocatable::ScreenScope, styleUpdateStrategy);
111 AffineTransform SVGTextElement::animatedLocalTransform() const
113 AffineTransform matrix;
114 RenderStyle* style = renderer()->style();
116 // if CSS property was set, use that, otherwise fallback to attribute (if set)
117 if (style->hasTransform()) {
118 TransformationMatrix t;
119 // For now, the transform-origin is not taken into account
120 // Also, any percentage values will not be taken into account
121 style->applyTransform(t, IntSize(0, 0), RenderStyle::ExcludeTransformOrigin);
122 // Flatten any 3D transform
123 matrix = t.toAffineTransform();
125 transform().concatenate(matrix);
127 if (m_supplementalTransform)
128 return *m_supplementalTransform * matrix;
132 AffineTransform* SVGTextElement::supplementalTransform()
134 if (!m_supplementalTransform)
135 m_supplementalTransform = adoptPtr(new AffineTransform);
136 return m_supplementalTransform.get();
139 RenderObject* SVGTextElement::createRenderer(RenderArena* arena, RenderStyle*)
141 return new (arena) RenderSVGText(this);
144 bool SVGTextElement::childShouldCreateRenderer(Node* child) const
146 if (child->isTextNode()
147 || child->hasTagName(SVGNames::aTag)
148 #if ENABLE(SVG_FONTS)
149 || child->hasTagName(SVGNames::altGlyphTag)
151 || child->hasTagName(SVGNames::textPathTag)
152 || child->hasTagName(SVGNames::trefTag)
153 || child->hasTagName(SVGNames::tspanTag))
159 void SVGTextElement::svgAttributeChanged(const QualifiedName& attrName)
161 if (!isSupportedAttribute(attrName)) {
162 SVGTextPositioningElement::svgAttributeChanged(attrName);
166 SVGElementInstance::InvalidationGuard invalidationGuard(this);
168 RenderObject* renderer = this->renderer();
172 if (attrName == SVGNames::transformAttr) {
173 renderer->setNeedsTransformUpdate();
174 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
178 ASSERT_NOT_REACHED();
183 #endif // ENABLE(SVG)