File indexing completed on 2024-04-28 15:24:42

0001 /*
0002     Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
0003 
0004     This file is part of the KDE project
0005 
0006     This library is free software; you can redistribute it and/or
0007     modify it under the terms of the GNU Library General Public
0008     License as published by the Free Software Foundation; either
0009     version 2 of the License, or (at your option) any later version.
0010 
0011     This library is distributed in the hope that it will be useful,
0012     but WITHOUT ANY WARRANTY; without even the implied warranty of
0013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014     Library General Public License for more details.
0015 
0016     You should have received a copy of the GNU Library General Public License
0017     along with this library; see the file COPYING.LIB.  If not, write to
0018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019     Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #include "wtf/Platform.h"
0023 
0024 #if ENABLE(SVG)
0025 #include "SVGTextPathElement.h"
0026 
0027 #include "AffineTransform.h"
0028 #include "FloatRect.h"
0029 #include "RenderSVGTextPath.h"
0030 #include "SVGLengthList.h"
0031 #include "SVGPathElement.h"
0032 #include "SVGRenderStyle.h"
0033 #include "SVGTextPathElement.h"
0034 #include "SVGTransformList.h"
0035 
0036 namespace WebCore
0037 {
0038 
0039 SVGTextPathElement::SVGTextPathElement(const QualifiedName &tagName, Document *doc)
0040     : SVGTextContentElement(tagName, doc)
0041     , SVGURIReference()
0042     , m_startOffset(this, LengthModeOther)
0043     , m_method(SVG_TEXTPATH_METHODTYPE_ALIGN)
0044     , m_spacing(SVG_TEXTPATH_SPACINGTYPE_EXACT)
0045 {
0046 }
0047 
0048 SVGTextPathElement::~SVGTextPathElement()
0049 {
0050 }
0051 
0052 ANIMATED_PROPERTY_DEFINITIONS(SVGTextPathElement, SVGLength, Length, length, StartOffset, startOffset, SVGNames::startOffsetAttr, m_startOffset)
0053 ANIMATED_PROPERTY_DEFINITIONS(SVGTextPathElement, int, Enumeration, enumeration, Method, method, SVGNames::methodAttr, m_method)
0054 ANIMATED_PROPERTY_DEFINITIONS(SVGTextPathElement, int, Enumeration, enumeration, Spacing, spacing, SVGNames::spacingAttr, m_spacing)
0055 
0056 void SVGTextPathElement::parseMappedAttribute(MappedAttribute *attr)
0057 {
0058     const String &value = attr->value();
0059 
0060     if (attr->name() == SVGNames::startOffsetAttr) {
0061         setStartOffsetBaseValue(SVGLength(this, LengthModeOther, value));
0062     } else if (attr->name() == SVGNames::methodAttr) {
0063         if (value == "align") {
0064             setSpacingBaseValue(SVG_TEXTPATH_METHODTYPE_ALIGN);
0065         } else if (value == "stretch") {
0066             setSpacingBaseValue(SVG_TEXTPATH_METHODTYPE_STRETCH);
0067         }
0068     } else if (attr->name() == SVGNames::spacingAttr) {
0069         if (value == "auto") {
0070             setMethodBaseValue(SVG_TEXTPATH_SPACINGTYPE_AUTO);
0071         } else if (value == "exact") {
0072             setMethodBaseValue(SVG_TEXTPATH_SPACINGTYPE_EXACT);
0073         }
0074     } else {
0075         if (SVGURIReference::parseMappedAttribute(attr)) {
0076             return;
0077         }
0078         SVGTextContentElement::parseMappedAttribute(attr);
0079     }
0080 }
0081 
0082 RenderObject *SVGTextPathElement::createRenderer(RenderArena *arena, RenderStyle *style)
0083 {
0084     Q_UNUSED(style);
0085     return new(arena) RenderSVGTextPath(this);
0086 }
0087 
0088 bool SVGTextPathElement::childShouldCreateRenderer(Node *child) const
0089 {
0090     if (child->isTextNode()
0091 #if ENABLE(SVG_FONTS)
0092             || child->hasTagName(SVGNames::altGlyphTag)
0093 #endif
0094             || child->hasTagName(SVGNames::trefTag) || child->hasTagName(SVGNames::tspanTag) || child->hasTagName(SVGNames::textPathTag)) {
0095         return true;
0096     }
0097 
0098     return false;
0099 }
0100 
0101 void SVGTextPathElement::insertedIntoDocument()
0102 {
0103     SVGElement::insertedIntoDocument();
0104 
0105     String id = SVGURIReference::getTarget(href());
0106     Element *targetElement = ownerDocument()->getElementById(id);
0107     if (!targetElement) {
0108         document()->accessSVGExtensions()->addPendingResource(id, this);
0109         return;
0110     }
0111 }
0112 
0113 }
0114 
0115 #endif // ENABLE(SVG)
0116