1 | /* |
2 | * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz> |
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 | #include "SVGFEPointLightElement.h" |
22 | |
23 | #include "GeometryUtilities.h" |
24 | #include "PointLightSource.h" |
25 | #include "SVGFilterBuilder.h" |
26 | #include "SVGNames.h" |
27 | #include <wtf/MathExtras.h> |
28 | |
29 | namespace WebCore { |
30 | |
31 | inline SVGFEPointLightElement::SVGFEPointLightElement(const QualifiedName& tagName, Document& document) |
32 | : SVGFELightElement(tagName, document) |
33 | { |
34 | ASSERT(hasTagName(SVGNames::fePointLightTag)); |
35 | } |
36 | |
37 | Ref<SVGFEPointLightElement> SVGFEPointLightElement::create(const QualifiedName& tagName, Document& document) |
38 | { |
39 | return adoptRef(*new SVGFEPointLightElement(tagName, document)); |
40 | } |
41 | |
42 | Ref<LightSource> SVGFEPointLightElement::lightSource(SVGFilterBuilder& builder) const |
43 | { |
44 | FloatPoint3D position; |
45 | if (builder.primitiveUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) { |
46 | FloatRect referenceBox = builder.targetBoundingBox(); |
47 | |
48 | position.setX(referenceBox.x() + x() * referenceBox.width()); |
49 | position.setY(referenceBox.y() + y() * referenceBox.height()); |
50 | |
51 | // https://www.w3.org/TR/SVG/filters.html#fePointLightZAttribute and https://www.w3.org/TR/SVG/coords.html#Units_viewport_percentage |
52 | position.setZ(z() * euclidianDistance(referenceBox.minXMinYCorner(), referenceBox.maxXMaxYCorner()) / sqrtOfTwoFloat); |
53 | } else |
54 | position = FloatPoint3D(x(), y(), z()); |
55 | |
56 | return PointLightSource::create(position); |
57 | } |
58 | |
59 | } |
60 | |