• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "modules/svg/include/SkSVGAttributeParser.h"
9 #include "modules/svg/include/SkSVGFeLightSource.h"
10 #include "modules/svg/include/SkSVGValue.h"
11 
computeDirection() const12 SkPoint3 SkSVGFeDistantLight::computeDirection() const {
13     // Computing direction from azimuth+elevation is two 3D rotations:
14     //  - Rotate [1,0,0] about y axis first (elevation)
15     //  - Rotate result about z axis (azimuth)
16     // Which is just the first column vector in the 3x3 matrix Rz*Ry.
17     const float azimuthRad = SkDegreesToRadians(fAzimuth);
18     const float elevationRad = SkDegreesToRadians(fElevation);
19     const float sinAzimuth = sinf(azimuthRad), cosAzimuth = cosf(azimuthRad);
20     const float sinElevation = sinf(elevationRad), cosElevation = cosf(elevationRad);
21     return SkPoint3::Make(cosAzimuth * cosElevation, sinAzimuth * cosElevation, sinElevation);
22 }
23 
parseAndSetAttribute(const char * n,const char * v)24 bool SkSVGFeDistantLight::parseAndSetAttribute(const char* n, const char* v) {
25     return INHERITED::parseAndSetAttribute(n, v) ||
26            this->setAzimuth(SkSVGAttributeParser::parse<SkSVGNumberType>("azimuth", n, v)) ||
27            this->setElevation(SkSVGAttributeParser::parse<SkSVGNumberType>("elevation", n, v));
28 }
29 
parseAndSetAttribute(const char * n,const char * v)30 bool SkSVGFePointLight::parseAndSetAttribute(const char* n, const char* v) {
31     return INHERITED::parseAndSetAttribute(n, v) ||
32            this->setX(SkSVGAttributeParser::parse<SkSVGNumberType>("x", n, v)) ||
33            this->setY(SkSVGAttributeParser::parse<SkSVGNumberType>("y", n, v)) ||
34            this->setZ(SkSVGAttributeParser::parse<SkSVGNumberType>("z", n, v));
35 }
36 
parseAndSetAttribute(const char * n,const char * v)37 bool SkSVGFeSpotLight::parseAndSetAttribute(const char* n, const char* v) {
38     return INHERITED::parseAndSetAttribute(n, v) ||
39            this->setX(SkSVGAttributeParser::parse<SkSVGNumberType>("x", n, v)) ||
40            this->setY(SkSVGAttributeParser::parse<SkSVGNumberType>("y", n, v)) ||
41            this->setZ(SkSVGAttributeParser::parse<SkSVGNumberType>("z", n, v)) ||
42            this->setPointsAtX(SkSVGAttributeParser::parse<SkSVGNumberType>("pointsAtX", n, v)) ||
43            this->setPointsAtY(SkSVGAttributeParser::parse<SkSVGNumberType>("pointsAtY", n, v)) ||
44            this->setPointsAtZ(SkSVGAttributeParser::parse<SkSVGNumberType>("pointsAtZ", n, v)) ||
45            this->setSpecularExponent(
46                    SkSVGAttributeParser::parse<SkSVGNumberType>("specularExponent", n, v)) ||
47            this->setLimitingConeAngle(
48                    SkSVGAttributeParser::parse<SkSVGNumberType>("limitingConeAngle", n, v));
49 }
50