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