RenderSVGTextPath.cpp revision 65f03d4f644ce73618e5f4f50dd694b26f55ae12
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#if ENABLE(SVG)
23#include "RenderSVGTextPath.h"
24
25#include "FloatQuad.h"
26#include "RenderBlock.h"
27#include "SVGInlineTextBox.h"
28#include "SVGNames.h"
29#include "SVGPathElement.h"
30#include "SVGRootInlineBox.h"
31#include "SVGTextPathElement.h"
32#include "SVGTransformList.h"
33
34namespace WebCore {
35
36RenderSVGTextPath::RenderSVGTextPath(Node* n)
37    : RenderSVGInline(n)
38    , m_startOffset(0.0f)
39    , m_exactAlignment(true)
40    , m_stretchMethod(false)
41{
42}
43
44Path RenderSVGTextPath::layoutPath() const
45{
46    SVGTextPathElement* textPathElement = static_cast<SVGTextPathElement*>(node());
47        String pathId = SVGURIReference::getTarget(textPathElement->href());
48    Element* targetElement = textPathElement->document()->getElementById(pathId);
49    if (!targetElement || !targetElement->hasTagName(SVGNames::pathTag))
50        return Path();
51
52    SVGPathElement* pathElement = static_cast<SVGPathElement*>(targetElement);
53
54    Path pathData;
55    pathElement->toPathData(pathData);
56    // Spec:  The transform attribute on the referenced 'path' element represents a
57    // supplemental transformation relative to the current user coordinate system for
58    // the current 'text' element, including any adjustments to the current user coordinate
59    // system due to a possible transform attribute on the current 'text' element.
60    // http://www.w3.org/TR/SVG/text.html#TextPathElement
61    pathData.transform(pathElement->animatedLocalTransform());
62    return pathData;
63}
64
65float RenderSVGTextPath::startOffset() const
66{
67    return static_cast<SVGTextPathElement*>(node())->startOffset().valueAsPercentage();
68}
69
70bool RenderSVGTextPath::exactAlignment() const
71{
72    return static_cast<SVGTextPathElement*>(node())->spacing() == SVG_TEXTPATH_SPACINGTYPE_EXACT;
73}
74
75bool RenderSVGTextPath::stretchMethod() const
76{
77    return static_cast<SVGTextPathElement*>(node())->method() == SVG_TEXTPATH_METHODTYPE_STRETCH;
78}
79
80}
81
82#endif // ENABLE(SVG)
83