diff --git a/modules/svg/include/SkSVGAttribute.h b/modules/svg/include/SkSVGAttribute.h index e063501065..b8f13cb90b 100644 --- a/modules/svg/include/SkSVGAttribute.h +++ b/modules/svg/include/SkSVGAttribute.h @@ -109,6 +109,7 @@ struct SkSVGPresentationAttributes { SkSVGProperty fStopOpacity; SkSVGProperty fFloodColor; SkSVGProperty fFloodOpacity; + SkSVGProperty fLightingColor; }; #endif // SkSVGAttribute_DEFINED diff --git a/modules/svg/include/SkSVGFeLightSource.h b/modules/svg/include/SkSVGFeLightSource.h new file mode 100644 index 0000000000..75f0074d2f --- /dev/null +++ b/modules/svg/include/SkSVGFeLightSource.h @@ -0,0 +1,86 @@ +/* + * Copyright 2021 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkSVGFeLightSource_DEFINED +#define SkSVGFeLightSource_DEFINED + +#include "modules/svg/include/SkSVGHiddenContainer.h" +#include "modules/svg/include/SkSVGTypes.h" + +class SkSVGFeLightSource : public SkSVGHiddenContainer { +public: + void appendChild(sk_sp) final { + SkDebugf("cannot append child nodes to an SVG light source.\n"); + } + +protected: + explicit SkSVGFeLightSource(SkSVGTag tag) : INHERITED(tag) {} + +private: + using INHERITED = SkSVGHiddenContainer; +}; + +class SkSVGFeDistantLight final : public SkSVGFeLightSource { +public: + static sk_sp Make() { + return sk_sp(new SkSVGFeDistantLight()); + } + + SVG_ATTR(Azimuth , SkSVGNumberType, 0) + SVG_ATTR(Elevation, SkSVGNumberType, 0) + +private: + SkSVGFeDistantLight() : INHERITED(SkSVGTag::kFeDistantLight) {} + + bool parseAndSetAttribute(const char*, const char*) override; + + using INHERITED = SkSVGFeLightSource; +}; + +class SkSVGFePointLight final : public SkSVGFeLightSource { +public: + static sk_sp Make() { + return sk_sp(new SkSVGFePointLight()); + } + + SVG_ATTR(X, SkSVGNumberType, 0) + SVG_ATTR(Y, SkSVGNumberType, 0) + SVG_ATTR(Z, SkSVGNumberType, 0) + +private: + SkSVGFePointLight() : INHERITED(SkSVGTag::kFePointLight) {} + + bool parseAndSetAttribute(const char*, const char*) override; + + using INHERITED = SkSVGFeLightSource; +}; + +class SkSVGFeSpotLight final : public SkSVGFeLightSource { +public: + static sk_sp Make() { + return sk_sp(new SkSVGFeSpotLight()); + } + + SVG_ATTR(X , SkSVGNumberType, 0) + SVG_ATTR(Y , SkSVGNumberType, 0) + SVG_ATTR(Z , SkSVGNumberType, 0) + SVG_ATTR(PointsAtX , SkSVGNumberType, 0) + SVG_ATTR(PointsAtY , SkSVGNumberType, 0) + SVG_ATTR(PointsAtZ , SkSVGNumberType, 0) + SVG_ATTR(SpecularExponent, SkSVGNumberType, 1) + + SVG_OPTIONAL_ATTR(LimitingConeAngle, SkSVGNumberType) + +private: + SkSVGFeSpotLight() : INHERITED(SkSVGTag::kFeSpotLight) {} + + bool parseAndSetAttribute(const char*, const char*) override; + + using INHERITED = SkSVGFeLightSource; +}; + +#endif // SkSVGFeLightSource_DEFINED diff --git a/modules/svg/include/SkSVGNode.h b/modules/svg/include/SkSVGNode.h index f7fc6c995d..e8e5a8f639 100644 --- a/modules/svg/include/SkSVGNode.h +++ b/modules/svg/include/SkSVGNode.h @@ -29,10 +29,13 @@ enum class SkSVGTag { kFeColorMatrix, kFeComposite, kFeDisplacementMap, + kFeDistantLight, kFeFlood, kFeGaussianBlur, kFeMorphology, kFeOffset, + kFePointLight, + kFeSpotLight, kFeTurbulence, kFilter, kG, @@ -136,6 +139,7 @@ public: SVG_PRES_ATTR(StopOpacity , SkSVGNumberType, false) SVG_PRES_ATTR(FloodColor , SkSVGColor , false) SVG_PRES_ATTR(FloodOpacity , SkSVGNumberType, false) + SVG_PRES_ATTR(LightingColor , SkSVGColor , false) protected: SkSVGNode(SkSVGTag); diff --git a/modules/svg/src/SkSVGAttribute.cpp b/modules/svg/src/SkSVGAttribute.cpp index 098dc7b6e8..f636adb548 100644 --- a/modules/svg/src/SkSVGAttribute.cpp +++ b/modules/svg/src/SkSVGAttribute.cpp @@ -40,6 +40,7 @@ SkSVGPresentationAttributes SkSVGPresentationAttributes::MakeInitial() { result.fStopOpacity.set(SkSVGNumberType(1)); result.fFloodColor.set(SkSVGColor(SK_ColorBLACK)); result.fFloodOpacity.set(SkSVGNumberType(1)); + result.fLightingColor.set(SkSVGColor(SK_ColorWHITE)); return result; } diff --git a/modules/svg/src/SkSVGDOM.cpp b/modules/svg/src/SkSVGDOM.cpp index 08fea1f1c4..b026e36976 100644 --- a/modules/svg/src/SkSVGDOM.cpp +++ b/modules/svg/src/SkSVGDOM.cpp @@ -22,6 +22,7 @@ #include "modules/svg/include/SkSVGFeDisplacementMap.h" #include "modules/svg/include/SkSVGFeFlood.h" #include "modules/svg/include/SkSVGFeGaussianBlur.h" +#include "modules/svg/include/SkSVGFeLightSource.h" #include "modules/svg/include/SkSVGFeMorphology.h" #include "modules/svg/include/SkSVGFeOffset.h" #include "modules/svg/include/SkSVGFeTurbulence.h" @@ -266,11 +267,14 @@ SortedDictionaryEntry(*)()> gTagFactories[] = { { "feBlend" , []() -> sk_sp { return SkSVGFeBlend::Make(); }}, { "feColorMatrix" , []() -> sk_sp { return SkSVGFeColorMatrix::Make(); }}, { "feComposite" , []() -> sk_sp { return SkSVGFeComposite::Make(); }}, + { "feDistantLight" , []() -> sk_sp { return SkSVGFeDistantLight::Make(); }}, { "feDisplacementMap", []() -> sk_sp { return SkSVGFeDisplacementMap::Make(); }}, { "feFlood" , []() -> sk_sp { return SkSVGFeFlood::Make(); }}, { "feGaussianBlur" , []() -> sk_sp { return SkSVGFeGaussianBlur::Make(); }}, { "feMorphology" , []() -> sk_sp { return SkSVGFeMorphology::Make(); }}, { "feOffset" , []() -> sk_sp { return SkSVGFeOffset::Make(); }}, + { "fePointLight" , []() -> sk_sp { return SkSVGFePointLight::Make(); }}, + { "feSpotLight" , []() -> sk_sp { return SkSVGFeSpotLight::Make(); }}, { "feTurbulence" , []() -> sk_sp { return SkSVGFeTurbulence::Make(); }}, { "filter" , []() -> sk_sp { return SkSVGFilter::Make(); }}, { "g" , []() -> sk_sp { return SkSVGG::Make(); }}, diff --git a/modules/svg/src/SkSVGFeLightSource.cpp b/modules/svg/src/SkSVGFeLightSource.cpp new file mode 100644 index 0000000000..f1f74aff5a --- /dev/null +++ b/modules/svg/src/SkSVGFeLightSource.cpp @@ -0,0 +1,37 @@ +/* + * Copyright 2021 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "modules/svg/include/SkSVGAttributeParser.h" +#include "modules/svg/include/SkSVGFeLightSource.h" +#include "modules/svg/include/SkSVGValue.h" + +bool SkSVGFeDistantLight::parseAndSetAttribute(const char* n, const char* v) { + return INHERITED::parseAndSetAttribute(n, v) || + this->setAzimuth(SkSVGAttributeParser::parse("azimuth", n, v)) || + this->setElevation(SkSVGAttributeParser::parse("elevation", n, v)); +} + +bool SkSVGFePointLight::parseAndSetAttribute(const char* n, const char* v) { + return INHERITED::parseAndSetAttribute(n, v) || + this->setX(SkSVGAttributeParser::parse("x", n, v)) || + this->setY(SkSVGAttributeParser::parse("y", n, v)) || + this->setZ(SkSVGAttributeParser::parse("z", n, v)); +} + +bool SkSVGFeSpotLight::parseAndSetAttribute(const char* n, const char* v) { + return INHERITED::parseAndSetAttribute(n, v) || + this->setX(SkSVGAttributeParser::parse("x", n, v)) || + this->setY(SkSVGAttributeParser::parse("y", n, v)) || + this->setZ(SkSVGAttributeParser::parse("z", n, v)) || + this->setPointsAtX(SkSVGAttributeParser::parse("pointsAtX", n, v)) || + this->setPointsAtY(SkSVGAttributeParser::parse("pointsAtY", n, v)) || + this->setPointsAtZ(SkSVGAttributeParser::parse("pointsAtZ", n, v)) || + this->setSpecularExponent( + SkSVGAttributeParser::parse("specularExponent", n, v)) || + this->setLimitingConeAngle( + SkSVGAttributeParser::parse("limitingConeAngle", n, v)); +} diff --git a/modules/svg/src/SkSVGNode.cpp b/modules/svg/src/SkSVGNode.cpp index fd2a4e3f9a..ae3aef28e5 100644 --- a/modules/svg/src/SkSVGNode.cpp +++ b/modules/svg/src/SkSVGNode.cpp @@ -20,6 +20,7 @@ SkSVGNode::SkSVGNode(SkSVGTag t) : fTag(t) { fPresentationAttributes.fStopOpacity.set(SkSVGNumberType(1.0f)); fPresentationAttributes.fFloodColor.set(SkSVGColor(SK_ColorBLACK)); fPresentationAttributes.fFloodOpacity.set(SkSVGNumberType(1.0f)); + fPresentationAttributes.fLightingColor.set(SkSVGColor(SK_ColorWHITE)); } SkSVGNode::~SkSVGNode() { } @@ -103,6 +104,7 @@ bool SkSVGNode::parseAndSetAttribute(const char* n, const char* v) { || PARSE_AND_SET("font-size" , FontSize) || PARSE_AND_SET("font-style" , FontStyle) || PARSE_AND_SET("font-weight" , FontWeight) + || PARSE_AND_SET("lighting-color" , LightingColor) || PARSE_AND_SET("mask" , Mask) || PARSE_AND_SET("opacity" , Opacity) || PARSE_AND_SET("stop-color" , StopColor) diff --git a/modules/svg/src/SkSVGRenderContext.cpp b/modules/svg/src/SkSVGRenderContext.cpp index 431296e64e..563f8dba1d 100644 --- a/modules/svg/src/SkSVGRenderContext.cpp +++ b/modules/svg/src/SkSVGRenderContext.cpp @@ -254,6 +254,7 @@ void SkSVGRenderContext::applyPresentationAttributes(const SkSVGPresentationAttr // - stop-opacity // - flood-color // - flood-opacity + // - lighting-color } void SkSVGRenderContext::applyOpacity(SkScalar opacity, uint32_t flags, bool hasFilter) { diff --git a/modules/svg/svg.gni b/modules/svg/svg.gni index 0d677dd9dd..169ee3f1bf 100644 --- a/modules/svg/svg.gni +++ b/modules/svg/svg.gni @@ -23,6 +23,7 @@ skia_svg_public = [ "$_include/SkSVGFeDisplacementMap.h", "$_include/SkSVGFeFlood.h", "$_include/SkSVGFeGaussianBlur.h", + "$_include/SkSVGFeLightSource.h", "$_include/SkSVGFeMorphology.h", "$_include/SkSVGFeOffset.h", "$_include/SkSVGFeTurbulence.h", @@ -67,6 +68,7 @@ skia_svg_sources = [ "$_src/SkSVGFeDisplacementMap.cpp", "$_src/SkSVGFeFlood.cpp", "$_src/SkSVGFeGaussianBlur.cpp", + "$_src/SkSVGFeLightSource.cpp", "$_src/SkSVGFeMorphology.cpp", "$_src/SkSVGFeOffset.cpp", "$_src/SkSVGFeTurbulence.cpp",