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