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