File indexing completed on 2024-04-28 15:24:42
0001 /* 0002 Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> 0003 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> 0004 0005 This file is part of the KDE project 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #include "wtf/Platform.h" 0024 0025 #if ENABLE(SVG) 0026 #include "SVGTextElement.h" 0027 0028 #include "AffineTransform.h" 0029 #include "FloatRect.h" 0030 #include "RenderSVGText.h" 0031 #include "SVGLengthList.h" 0032 #include "SVGRenderStyle.h" 0033 #include "SVGTSpanElement.h" 0034 #include "SVGTransformList.h" 0035 0036 namespace WebCore 0037 { 0038 0039 SVGTextElement::SVGTextElement(const QualifiedName &tagName, Document *doc) 0040 : SVGTextPositioningElement(tagName, doc) 0041 , SVGTransformable() 0042 , m_transform(SVGTransformList::create(SVGNames::transformAttr)) 0043 { 0044 } 0045 0046 SVGTextElement::~SVGTextElement() 0047 { 0048 } 0049 0050 ANIMATED_PROPERTY_DEFINITIONS(SVGTextElement, SVGTransformList *, TransformList, transformList, Transform, transform, SVGNames::transformAttr, m_transform.get()) 0051 0052 void SVGTextElement::parseMappedAttribute(MappedAttribute *attr) 0053 { 0054 if (attr->name() == SVGNames::transformAttr) { 0055 SVGTransformList *localTransforms = transformBaseValue(); 0056 0057 ExceptionCode ec = 0; 0058 localTransforms->clear(ec); 0059 0060 if (!SVGTransformable::parseTransformAttribute(localTransforms, attr->value())) { 0061 localTransforms->clear(ec); 0062 } else { 0063 setTransformBaseValue(localTransforms); 0064 if (renderer()) { 0065 renderer()->setNeedsLayout(true); // should be in setTransformBaseValue 0066 } 0067 } 0068 } else { 0069 SVGTextPositioningElement::parseMappedAttribute(attr); 0070 } 0071 } 0072 0073 SVGElement *SVGTextElement::nearestViewportElement() const 0074 { 0075 return SVGTransformable::nearestViewportElement(this); 0076 } 0077 0078 SVGElement *SVGTextElement::farthestViewportElement() const 0079 { 0080 return SVGTransformable::farthestViewportElement(this); 0081 } 0082 0083 FloatRect SVGTextElement::getBBox() const 0084 { 0085 return SVGTransformable::getBBox(this); 0086 } 0087 0088 AffineTransform SVGTextElement::getScreenCTM() const 0089 { 0090 return SVGTransformable::getScreenCTM(this); 0091 } 0092 0093 AffineTransform SVGTextElement::getCTM() const 0094 { 0095 return SVGTransformable::getCTM(this); 0096 } 0097 0098 AffineTransform SVGTextElement::animatedLocalTransform() const 0099 { 0100 return m_supplementalTransform ? transform()->concatenate().matrix() **m_supplementalTransform : transform()->concatenate().matrix(); 0101 } 0102 0103 AffineTransform *SVGTextElement::supplementalTransform() 0104 { 0105 if (!m_supplementalTransform) { 0106 m_supplementalTransform.set(new AffineTransform()); 0107 } 0108 return m_supplementalTransform.get(); 0109 } 0110 0111 RenderObject *SVGTextElement::createRenderer(RenderArena *arena, RenderStyle *style) 0112 { 0113 Q_UNUSED(style); 0114 // qCDebug(KHTML_LOG) << "create renderer for <text>"; 0115 return new(arena) RenderSVGText(this); 0116 } 0117 0118 bool SVGTextElement::childShouldCreateRenderer(Node *child) const 0119 { 0120 if (child->isTextNode() 0121 #if ENABLE(SVG_FONTS) 0122 || child->hasTagName(SVGNames::altGlyphTag) 0123 #endif 0124 || child->hasTagName(SVGNames::tspanTag) || child->hasTagName(SVGNames::trefTag) || child->hasTagName(SVGNames::aTag) || child->hasTagName(SVGNames::textPathTag)) { 0125 return true; 0126 } 0127 return false; 0128 } 0129 0130 void SVGTextElement::svgAttributeChanged(const QualifiedName &attrName) 0131 { 0132 SVGTextPositioningElement::svgAttributeChanged(attrName); 0133 0134 if (!renderer()) { 0135 return; 0136 } 0137 0138 if (SVGTextPositioningElement::isKnownAttribute(attrName)) { 0139 renderer()->setNeedsLayout(true); 0140 } 0141 } 0142 0143 } 0144 0145 #endif // ENABLE(SVG)