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#include "core/svg/SVGTextElement.h" 24 25#include "SVGNames.h" 26#include "core/dom/NodeRenderingContext.h" 27#include "core/rendering/svg/RenderSVGResource.h" 28#include "core/rendering/svg/RenderSVGText.h" 29#include "core/svg/SVGElementInstance.h" 30 31namespace WebCore { 32 33inline SVGTextElement::SVGTextElement(const QualifiedName& tagName, Document* doc) 34 : SVGTextPositioningElement(tagName, doc) 35{ 36 ASSERT(hasTagName(SVGNames::textTag)); 37 ScriptWrappable::init(this); 38} 39 40PassRefPtr<SVGTextElement> SVGTextElement::create(const QualifiedName& tagName, Document* document) 41{ 42 return adoptRef(new SVGTextElement(tagName, document)); 43} 44 45// We override SVGGraphics::animatedLocalTransform() so that the transform-origin 46// is not taken into account. 47AffineTransform SVGTextElement::animatedLocalTransform() const 48{ 49 AffineTransform matrix; 50 RenderStyle* style = renderer() ? renderer()->style() : 0; 51 52 // if CSS property was set, use that, otherwise fallback to attribute (if set) 53 if (style && style->hasTransform()) { 54 TransformationMatrix t; 55 // For now, the transform-origin is not taken into account 56 // Also, any percentage values will not be taken into account 57 style->applyTransform(t, IntSize(0, 0), RenderStyle::ExcludeTransformOrigin); 58 // Flatten any 3D transform 59 matrix = t.toAffineTransform(); 60 } else { 61 transformCurrentValue().concatenate(matrix); 62 } 63 64 const AffineTransform* transform = const_cast<SVGTextElement*>(this)->supplementalTransform(); 65 if (transform) 66 return *transform * matrix; 67 return matrix; 68} 69 70RenderObject* SVGTextElement::createRenderer(RenderStyle*) 71{ 72 return new RenderSVGText(this); 73} 74 75bool SVGTextElement::childShouldCreateRenderer(const NodeRenderingContext& childContext) const 76{ 77 if (childContext.node()->isTextNode() 78 || childContext.node()->hasTagName(SVGNames::aTag) 79#if ENABLE(SVG_FONTS) 80 || childContext.node()->hasTagName(SVGNames::altGlyphTag) 81#endif 82 || childContext.node()->hasTagName(SVGNames::textPathTag) 83 || childContext.node()->hasTagName(SVGNames::trefTag) 84 || childContext.node()->hasTagName(SVGNames::tspanTag)) 85 return true; 86 87 return false; 88} 89 90} 91