Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / svg / RenderSVGTextPath.cpp
1 /*
2  * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include "config.h"
21
22 #include "core/rendering/svg/RenderSVGTextPath.h"
23
24 #include "SVGNames.h"
25 #include "core/rendering/svg/SVGPathData.h"
26 #include "core/rendering/svg/SVGRenderSupport.h"
27 #include "core/svg/SVGPathElement.h"
28 #include "core/svg/SVGTextPathElement.h"
29
30 namespace WebCore {
31
32 RenderSVGTextPath::RenderSVGTextPath(Element* element)
33     : RenderSVGInline(element)
34 {
35 }
36
37 bool RenderSVGTextPath::isChildAllowed(RenderObject* child, RenderStyle*) const
38 {
39     if (child->isText())
40         return SVGRenderSupport::isRenderableTextNode(child);
41
42 #if ENABLE(SVG_FONTS)
43     // 'altGlyph' is supported by the content model for 'textPath', but...
44     ASSERT(child->node());
45     if (isSVGAltGlyphElement(*child->node()))
46         return false;
47 #endif
48
49     return child->isSVGInline() && !child->isSVGTextPath();
50 }
51
52 Path RenderSVGTextPath::layoutPath() const
53 {
54     SVGTextPathElement* textPathElement = toSVGTextPathElement(node());
55     Element* targetElement = SVGURIReference::targetElementFromIRIString(textPathElement->href()->currentValue()->value(), textPathElement->document());
56     if (!isSVGPathElement(targetElement))
57         return Path();
58
59     SVGPathElement& pathElement = toSVGPathElement(*targetElement);
60
61     Path pathData;
62     updatePathFromGraphicsElement(&pathElement, pathData);
63
64     // Spec:  The transform attribute on the referenced 'path' element represents a
65     // supplemental transformation relative to the current user coordinate system for
66     // the current 'text' element, including any adjustments to the current user coordinate
67     // system due to a possible transform attribute on the current 'text' element.
68     // http://www.w3.org/TR/SVG/text.html#TextPathElement
69     pathData.transform(pathElement.animatedLocalTransform());
70     return pathData;
71 }
72
73 float RenderSVGTextPath::startOffset() const
74 {
75     return toSVGTextPathElement(node())->startOffset()->currentValue()->valueAsPercentage();
76 }
77
78 }