1 /* 2 * Copyright 2016 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 "SkSVGRenderContext.h" 9 #include "SkSVGStop.h" 10 #include "SkSVGValue.h" 11 12 SkSVGStop::SkSVGStop() : INHERITED(SkSVGTag::kStop) {} 13 14 void SkSVGStop::setOffset(const SkSVGLength& offset) { 15 fOffset = offset; 16 } 17 18 void SkSVGStop::setStopColor(const SkSVGColorType& color) { 19 fStopColor = color; 20 } 21 22 void SkSVGStop::setStopOpacity(const SkSVGNumberType& opacity) { 23 fStopOpacity = SkTPin<SkScalar>(opacity.value(), 0, 1); 24 } 25 26 void SkSVGStop::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { 27 switch (attr) { 28 case SkSVGAttribute::kOffset: 29 if (const auto* offset = v.as<SkSVGLengthValue>()) { 30 this->setOffset(*offset); 31 } 32 break; 33 case SkSVGAttribute::kStopColor: 34 if (const auto* color = v.as<SkSVGColorValue>()) { 35 this->setStopColor(*color); 36 } 37 break; 38 case SkSVGAttribute::kStopOpacity: 39 if (const auto* opacity = v.as<SkSVGNumberValue>()) { 40 this->setStopOpacity(*opacity); 41 } 42 break; 43 default: 44 this->INHERITED::onSetAttribute(attr, v); 45 } 46 } 47