KHtml

SVGTextPathElement.cpp
1 /*
2  Copyright (C) 2007 Nikolas Zimmermann <[email protected]>
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 "wtf/Platform.h"
23 
24 #if ENABLE(SVG)
25 #include "SVGTextPathElement.h"
26 
27 #include "AffineTransform.h"
28 #include "FloatRect.h"
29 #include "RenderSVGTextPath.h"
30 #include "SVGLengthList.h"
31 #include "SVGPathElement.h"
32 #include "SVGRenderStyle.h"
33 #include "SVGTextPathElement.h"
34 #include "SVGTransformList.h"
35 
36 namespace WebCore
37 {
38 
39 SVGTextPathElement::SVGTextPathElement(const QualifiedName &tagName, Document *doc)
40  : SVGTextContentElement(tagName, doc)
41  , SVGURIReference()
42  , m_startOffset(this, LengthModeOther)
43  , m_method(SVG_TEXTPATH_METHODTYPE_ALIGN)
44  , m_spacing(SVG_TEXTPATH_SPACINGTYPE_EXACT)
45 {
46 }
47 
48 SVGTextPathElement::~SVGTextPathElement()
49 {
50 }
51 
52 ANIMATED_PROPERTY_DEFINITIONS(SVGTextPathElement, SVGLength, Length, length, StartOffset, startOffset, SVGNames::startOffsetAttr, m_startOffset)
53 ANIMATED_PROPERTY_DEFINITIONS(SVGTextPathElement, int, Enumeration, enumeration, Method, method, SVGNames::methodAttr, m_method)
54 ANIMATED_PROPERTY_DEFINITIONS(SVGTextPathElement, int, Enumeration, enumeration, Spacing, spacing, SVGNames::spacingAttr, m_spacing)
55 
56 void SVGTextPathElement::parseMappedAttribute(MappedAttribute *attr)
57 {
58  const String &value = attr->value();
59 
60  if (attr->name() == SVGNames::startOffsetAttr) {
61  setStartOffsetBaseValue(SVGLength(this, LengthModeOther, value));
62  } else if (attr->name() == SVGNames::methodAttr) {
63  if (value == "align") {
64  setSpacingBaseValue(SVG_TEXTPATH_METHODTYPE_ALIGN);
65  } else if (value == "stretch") {
66  setSpacingBaseValue(SVG_TEXTPATH_METHODTYPE_STRETCH);
67  }
68  } else if (attr->name() == SVGNames::spacingAttr) {
69  if (value == "auto") {
70  setMethodBaseValue(SVG_TEXTPATH_SPACINGTYPE_AUTO);
71  } else if (value == "exact") {
72  setMethodBaseValue(SVG_TEXTPATH_SPACINGTYPE_EXACT);
73  }
74  } else {
75  if (SVGURIReference::parseMappedAttribute(attr)) {
76  return;
77  }
78  SVGTextContentElement::parseMappedAttribute(attr);
79  }
80 }
81 
82 RenderObject *SVGTextPathElement::createRenderer(RenderArena *arena, RenderStyle *style)
83 {
84  Q_UNUSED(style);
85  return new(arena) RenderSVGTextPath(this);
86 }
87 
88 bool SVGTextPathElement::childShouldCreateRenderer(Node *child) const
89 {
90  if (child->isTextNode()
91 #if ENABLE(SVG_FONTS)
92  || child->hasTagName(SVGNames::altGlyphTag)
93 #endif
94  || child->hasTagName(SVGNames::trefTag) || child->hasTagName(SVGNames::tspanTag) || child->hasTagName(SVGNames::textPathTag)) {
95  return true;
96  }
97 
98  return false;
99 }
100 
101 void SVGTextPathElement::insertedIntoDocument()
102 {
103  SVGElement::insertedIntoDocument();
104 
105  String id = SVGURIReference::getTarget(href());
106  Element *targetElement = ownerDocument()->getElementById(id);
107  if (!targetElement) {
108  document()->accessSVGExtensions()->addPendingResource(id, this);
109  return;
110  }
111 }
112 
113 }
114 
115 #endif // ENABLE(SVG)
116 
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:48:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.