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