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