• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 
4     This file is part of the KDE project
5 
6     This library is free software; you can redistribute it and/or
7     modify it under the terms of the GNU Library General Public
8     License as published by the Free Software Foundation; either
9     version 2 of the License, or (at your option) any later version.
10 
11     This library is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14     Library General Public License for more details.
15 
16     You should have received a copy of the GNU Library General Public License
17     along with this library; see the file COPYING.LIB.  If not, write to
18     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19     Boston, MA 02110-1301, USA.
20 */
21 
22 #include "config.h"
23 
24 #if ENABLE(SVG)
25 #include "SVGTextPathElement.h"
26 
27 #include "FloatRect.h"
28 #include "MappedAttribute.h"
29 #include "RenderSVGTextPath.h"
30 #include "SVGLengthList.h"
31 #include "SVGPathElement.h"
32 #include "SVGRenderStyle.h"
33 #include "SVGTransformList.h"
34 #include "TransformationMatrix.h"
35 
36 namespace WebCore {
37 
SVGTextPathElement(const QualifiedName & tagName,Document * doc)38 SVGTextPathElement::SVGTextPathElement(const QualifiedName& tagName, Document* doc)
39     : SVGTextContentElement(tagName, doc)
40     , SVGURIReference()
41     , m_startOffset(this, SVGNames::startOffsetAttr, LengthModeOther)
42     , m_method(this, SVGNames::methodAttr, SVG_TEXTPATH_METHODTYPE_ALIGN)
43     , m_spacing(this, SVGNames::spacingAttr, SVG_TEXTPATH_SPACINGTYPE_EXACT)
44 {
45 }
46 
~SVGTextPathElement()47 SVGTextPathElement::~SVGTextPathElement()
48 {
49 }
50 
parseMappedAttribute(MappedAttribute * attr)51 void SVGTextPathElement::parseMappedAttribute(MappedAttribute* attr)
52 {
53     const String& value = attr->value();
54 
55     if (attr->name() == SVGNames::startOffsetAttr)
56         setStartOffsetBaseValue(SVGLength(LengthModeOther, value));
57     else if (attr->name() == SVGNames::methodAttr) {
58         if (value == "align")
59             setSpacingBaseValue(SVG_TEXTPATH_METHODTYPE_ALIGN);
60         else if (value == "stretch")
61             setSpacingBaseValue(SVG_TEXTPATH_METHODTYPE_STRETCH);
62     } else if (attr->name() == SVGNames::spacingAttr) {
63         if (value == "auto")
64             setMethodBaseValue(SVG_TEXTPATH_SPACINGTYPE_AUTO);
65         else if (value == "exact")
66             setMethodBaseValue(SVG_TEXTPATH_SPACINGTYPE_EXACT);
67     } else {
68         if (SVGURIReference::parseMappedAttribute(attr))
69             return;
70         SVGTextContentElement::parseMappedAttribute(attr);
71     }
72 }
73 
createRenderer(RenderArena * arena,RenderStyle *)74 RenderObject* SVGTextPathElement::createRenderer(RenderArena* arena, RenderStyle*)
75 {
76     return new (arena) RenderSVGTextPath(this);
77 }
78 
childShouldCreateRenderer(Node * child) const79 bool SVGTextPathElement::childShouldCreateRenderer(Node* child) const
80 {
81     if (child->isTextNode()
82 #if ENABLE(SVG_FONTS)
83         || child->hasTagName(SVGNames::altGlyphTag)
84 #endif
85         || child->hasTagName(SVGNames::trefTag) || child->hasTagName(SVGNames::tspanTag) || child->hasTagName(SVGNames::textPathTag))
86         return true;
87 
88     return false;
89 }
90 
insertedIntoDocument()91 void SVGTextPathElement::insertedIntoDocument()
92 {
93     SVGElement::insertedIntoDocument();
94 
95     String id = SVGURIReference::getTarget(href());
96     Element* targetElement = ownerDocument()->getElementById(id);
97     if (!targetElement) {
98         document()->accessSVGExtensions()->addPendingResource(id, this);
99         return;
100     }
101 }
102 
103 }
104 
105 #endif // ENABLE(SVG)
106 
107 // vim:ts=4:noet
108