SVGFESpotLightElement.cpp [plain text]
#include "config.h"
#include "SVGFESpotLightElement.h"
#include "GeometryUtilities.h"
#include "SVGFilterBuilder.h"
#include "SVGNames.h"
#include "SpotLightSource.h"
#include <wtf/MathExtras.h>
namespace WebCore {
inline SVGFESpotLightElement::SVGFESpotLightElement(const QualifiedName& tagName, Document& document)
: SVGFELightElement(tagName, document)
{
ASSERT(hasTagName(SVGNames::feSpotLightTag));
}
Ref<SVGFESpotLightElement> SVGFESpotLightElement::create(const QualifiedName& tagName, Document& document)
{
return adoptRef(*new SVGFESpotLightElement(tagName, document));
}
Ref<LightSource> SVGFESpotLightElement::lightSource(SVGFilterBuilder& builder) const
{
FloatPoint3D position;
FloatPoint3D pointsAt;
if (builder.primitiveUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
FloatRect referenceBox = builder.targetBoundingBox();
position.setX(referenceBox.x() + x() * referenceBox.width());
position.setY(referenceBox.y() + y() * referenceBox.height());
position.setZ(z() * euclidianDistance(referenceBox.minXMinYCorner(), referenceBox.maxXMaxYCorner()) / sqrtOfTwoFloat);
pointsAt.setX(referenceBox.x() + pointsAtX() * referenceBox.width());
pointsAt.setY(referenceBox.y() + pointsAtY() * referenceBox.height());
pointsAt.setZ(pointsAtZ() * euclidianDistance(referenceBox.minXMinYCorner(), referenceBox.maxXMaxYCorner()) / sqrtOfTwoFloat);
} else {
position = FloatPoint3D(x(), y(), z());
pointsAt = FloatPoint3D(pointsAtX(), pointsAtY(), pointsAtZ());
}
return SpotLightSource::create(position, pointsAt, specularExponent(), limitingConeAngle());
}
}