1 /*
2 * Copyright 2021 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "include/core/SkScalar.h"
9 #include "modules/svg/include/SkSVGAttributeParser.h"
10 #include "modules/svg/include/SkSVGFeLightSource.h"
11
12 #include <cmath>
13
computeDirection() const14 SkPoint3 SkSVGFeDistantLight::computeDirection() const {
15 // Computing direction from azimuth+elevation is two 3D rotations:
16 // - Rotate [1,0,0] about y axis first (elevation)
17 // - Rotate result about z axis (azimuth)
18 // Which is just the first column vector in the 3x3 matrix Rz*Ry.
19 const float azimuthRad = SkDegreesToRadians(fAzimuth);
20 const float elevationRad = SkDegreesToRadians(fElevation);
21 const float sinAzimuth = sinf(azimuthRad), cosAzimuth = cosf(azimuthRad);
22 const float sinElevation = sinf(elevationRad), cosElevation = cosf(elevationRad);
23 return SkPoint3::Make(cosAzimuth * cosElevation, sinAzimuth * cosElevation, sinElevation);
24 }
25
parseAndSetAttribute(const char * n,const char * v)26 bool SkSVGFeDistantLight::parseAndSetAttribute(const char* n, const char* v) {
27 return INHERITED::parseAndSetAttribute(n, v) ||
28 this->setAzimuth(SkSVGAttributeParser::parse<SkSVGNumberType>("azimuth", n, v)) ||
29 this->setElevation(SkSVGAttributeParser::parse<SkSVGNumberType>("elevation", n, v));
30 }
31
parseAndSetAttribute(const char * n,const char * v)32 bool SkSVGFePointLight::parseAndSetAttribute(const char* n, const char* v) {
33 return INHERITED::parseAndSetAttribute(n, v) ||
34 this->setX(SkSVGAttributeParser::parse<SkSVGNumberType>("x", n, v)) ||
35 this->setY(SkSVGAttributeParser::parse<SkSVGNumberType>("y", n, v)) ||
36 this->setZ(SkSVGAttributeParser::parse<SkSVGNumberType>("z", n, v));
37 }
38
parseAndSetAttribute(const char * n,const char * v)39 bool SkSVGFeSpotLight::parseAndSetAttribute(const char* n, const char* v) {
40 return INHERITED::parseAndSetAttribute(n, v) ||
41 this->setX(SkSVGAttributeParser::parse<SkSVGNumberType>("x", n, v)) ||
42 this->setY(SkSVGAttributeParser::parse<SkSVGNumberType>("y", n, v)) ||
43 this->setZ(SkSVGAttributeParser::parse<SkSVGNumberType>("z", n, v)) ||
44 this->setPointsAtX(SkSVGAttributeParser::parse<SkSVGNumberType>("pointsAtX", n, v)) ||
45 this->setPointsAtY(SkSVGAttributeParser::parse<SkSVGNumberType>("pointsAtY", n, v)) ||
46 this->setPointsAtZ(SkSVGAttributeParser::parse<SkSVGNumberType>("pointsAtZ", n, v)) ||
47 this->setSpecularExponent(
48 SkSVGAttributeParser::parse<SkSVGNumberType>("specularExponent", n, v)) ||
49 this->setLimitingConeAngle(
50 SkSVGAttributeParser::parse<SkSVGNumberType>("limitingConeAngle", n, v));
51 }
52