SVGLineElement.cpp [plain text]
#include "config.h"
#if SVG_SUPPORT
#include "Attr.h"
#include "SVGNames.h"
#include "SVGHelper.h"
#include "SVGLineElement.h"
#include "SVGAnimatedLength.h"
#include <kcanvas/KCanvasCreator.h>
using namespace WebCore;
SVGLineElement::SVGLineElement(const QualifiedName& tagName, Document *doc)
: SVGStyledTransformableElement(tagName, doc), SVGTests(), SVGLangSpace(), SVGExternalResourcesRequired()
{
}
SVGLineElement::~SVGLineElement()
{
}
SVGAnimatedLength *SVGLineElement::x1() const
{
return lazy_create<SVGAnimatedLength>(m_x1, this, LM_WIDTH, viewportElement());
}
SVGAnimatedLength *SVGLineElement::y1() const
{
return lazy_create<SVGAnimatedLength>(m_y1, this, LM_HEIGHT, viewportElement());
}
SVGAnimatedLength *SVGLineElement::x2() const
{
return lazy_create<SVGAnimatedLength>(m_x2, this, LM_WIDTH, viewportElement());
}
SVGAnimatedLength *SVGLineElement::y2() const
{
return lazy_create<SVGAnimatedLength>(m_y2, this, LM_HEIGHT, viewportElement());
}
void SVGLineElement::parseMappedAttribute(MappedAttribute *attr)
{
const AtomicString& value = attr->value();
if (attr->name() == SVGNames::x1Attr)
x1()->baseVal()->setValueAsString(value.impl());
else if (attr->name() == SVGNames::y1Attr)
y1()->baseVal()->setValueAsString(value.impl());
else if (attr->name() == SVGNames::x2Attr)
x2()->baseVal()->setValueAsString(value.impl());
else if (attr->name() == SVGNames::y2Attr)
y2()->baseVal()->setValueAsString(value.impl());
else
{
if(SVGTests::parseMappedAttribute(attr)) return;
if(SVGLangSpace::parseMappedAttribute(attr)) return;
if(SVGExternalResourcesRequired::parseMappedAttribute(attr)) return;
SVGStyledTransformableElement::parseMappedAttribute(attr);
}
}
KCanvasPath* SVGLineElement::toPathData() const
{
float _x1 = x1()->baseVal()->value(), _y1 = y1()->baseVal()->value();
float _x2 = x2()->baseVal()->value(), _y2 = y2()->baseVal()->value();
return KCanvasCreator::self()->createLine(_x1, _y1, _x2, _y2);
}
const SVGStyledElement *SVGLineElement::pushAttributeContext(const SVGStyledElement *context)
{
const SVGStyledElement *restore = x1()->baseVal()->context();
x1()->baseVal()->setContext(context);
y1()->baseVal()->setContext(context);
x2()->baseVal()->setContext(context);
y2()->baseVal()->setContext(context);
SVGStyledElement::pushAttributeContext(context);
return restore;
}
#endif // SVG_SUPPORT