1/*
2 * Copyright (C) 2011 Leo Yang <leoyang@webkit.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_FONTS)
23#include "SVGGlyphRefElement.h"
24
25#include "SVGGlyphElement.h"
26#include "SVGNames.h"
27#include "SVGParserUtilities.h"
28#include "XLinkNames.h"
29#include <wtf/text/AtomicString.h>
30#include <wtf/text/StringView.h>
31
32namespace WebCore {
33
34// Animated property definitions
35DEFINE_ANIMATED_STRING(SVGGlyphRefElement, XLinkNames::hrefAttr, Href, href)
36
37BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGGlyphRefElement)
38    REGISTER_LOCAL_ANIMATED_PROPERTY(href)
39    REGISTER_PARENT_ANIMATED_PROPERTIES(SVGElement)
40END_REGISTER_ANIMATED_PROPERTIES
41
42inline SVGGlyphRefElement::SVGGlyphRefElement(const QualifiedName& tagName, Document& document)
43    : SVGElement(tagName, document)
44    , m_x(0)
45    , m_y(0)
46    , m_dx(0)
47    , m_dy(0)
48{
49    ASSERT(hasTagName(SVGNames::glyphRefTag));
50    registerAnimatedPropertiesForSVGGlyphRefElement();
51}
52
53PassRefPtr<SVGGlyphRefElement> SVGGlyphRefElement::create(const QualifiedName& tagName, Document& document)
54{
55    return adoptRef(new SVGGlyphRefElement(tagName, document));
56}
57
58bool SVGGlyphRefElement::hasValidGlyphElement(String& glyphName) const
59{
60    // FIXME: We only support xlink:href so far.
61    // https://bugs.webkit.org/show_bug.cgi?id=64787
62    Element* element = targetElementFromIRIString(getAttribute(XLinkNames::hrefAttr), document(), &glyphName);
63    if (!element || !element->hasTagName(SVGNames::glyphTag))
64        return false;
65    return true;
66}
67
68void SVGGlyphRefElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
69{
70    auto upconvertedCharacters = StringView(value.string()).upconvertedCharacters();
71    const UChar* startPtr = upconvertedCharacters;
72    const UChar* endPtr = startPtr + value.length();
73
74    // FIXME: We need some error handling here.
75    if (name == SVGNames::xAttr)
76        parseNumber(startPtr, endPtr, m_x);
77    else if (name == SVGNames::yAttr)
78        parseNumber(startPtr, endPtr, m_y);
79    else if (name == SVGNames::dxAttr)
80        parseNumber(startPtr, endPtr, m_dx);
81    else if (name == SVGNames::dyAttr)
82        parseNumber(startPtr, endPtr, m_dy);
83    else {
84        if (SVGURIReference::parseAttribute(name, value))
85            return;
86        SVGElement::parseAttribute(name, value);
87    }
88}
89
90const AtomicString& SVGGlyphRefElement::glyphRef() const
91{
92    return fastGetAttribute(SVGNames::glyphRefAttr);
93}
94
95void SVGGlyphRefElement::setGlyphRef(const AtomicString&, ExceptionCode&)
96{
97    // FIXME: Set and honor attribute change.
98    // https://bugs.webkit.org/show_bug.cgi?id=64787
99}
100
101void SVGGlyphRefElement::setX(float x, ExceptionCode&)
102{
103    // FIXME: Honor attribute change.
104    // https://bugs.webkit.org/show_bug.cgi?id=64787
105    m_x = x;
106}
107
108void SVGGlyphRefElement::setY(float y , ExceptionCode&)
109{
110    // FIXME: Honor attribute change.
111    // https://bugs.webkit.org/show_bug.cgi?id=64787
112    m_y = y;
113}
114
115void SVGGlyphRefElement::setDx(float dx, ExceptionCode&)
116{
117    // FIXME: Honor attribute change.
118    // https://bugs.webkit.org/show_bug.cgi?id=64787
119    m_dx = dx;
120}
121
122void SVGGlyphRefElement::setDy(float dy, ExceptionCode&)
123{
124    // FIXME: Honor attribute change.
125    // https://bugs.webkit.org/show_bug.cgi?id=64787
126    m_dy = dy;
127}
128
129}
130
131#endif
132