SVGGlyphRefElement.cpp [plain text]
#include "config.h"
#include "SVGGlyphRefElement.h"
#include "SVGGlyphElement.h"
#include "SVGNames.h"
#include "SVGParserUtilities.h"
#include "XLinkNames.h"
#include <wtf/IsoMallocInlines.h>
#include <wtf/text/AtomString.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(SVGGlyphRefElement);
inline SVGGlyphRefElement::SVGGlyphRefElement(const QualifiedName& tagName, Document& document)
: SVGElement(tagName, document)
, SVGURIReference(this)
{
ASSERT(hasTagName(SVGNames::glyphRefTag));
}
Ref<SVGGlyphRefElement> SVGGlyphRefElement::create(const QualifiedName& tagName, Document& document)
{
return adoptRef(*new SVGGlyphRefElement(tagName, document));
}
bool SVGGlyphRefElement::hasValidGlyphElement(String& glyphName) const
{
auto target = targetElementFromIRIString(getAttribute(SVGNames::hrefAttr, XLinkNames::hrefAttr), document());
glyphName = target.identifier;
return is<SVGGlyphElement>(target.element);
}
static float parseFloat(const AtomString& value)
{
return parseNumber(value).valueOr(0);
}
void SVGGlyphRefElement::parseAttribute(const QualifiedName& name, const AtomString& value)
{
if (name == SVGNames::xAttr)
m_x = parseFloat(value);
else if (name == SVGNames::yAttr)
m_y = parseFloat(value);
else if (name == SVGNames::dxAttr)
m_dx = parseFloat(value);
else if (name == SVGNames::dyAttr)
m_dy = parseFloat(value);
else {
SVGURIReference::parseAttribute(name, value);
SVGElement::parseAttribute(name, value);
}
}
void SVGGlyphRefElement::setX(float x)
{
setAttribute(SVGNames::xAttr, AtomString::number(x));
}
void SVGGlyphRefElement::setY(float y)
{
setAttribute(SVGNames::yAttr, AtomString::number(y));
}
void SVGGlyphRefElement::setDx(float dx)
{
setAttribute(SVGNames::dxAttr, AtomString::number(dx));
}
void SVGGlyphRefElement::setDy(float dy)
{
setAttribute(SVGNames::dyAttr, AtomString::number(dy));
}
}