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