blob: 3abf505abb9fcbda83340da1fff24daff9f3285e [file] [log] [blame]
fmalita28d5b722016-09-12 17:06:47 -07001/*
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
12SkSVGStop::SkSVGStop() : INHERITED(SkSVGTag::kStop) {}
13
14void SkSVGStop::setOffset(const SkSVGLength& offset) {
15 fOffset = offset;
16}
17
18void SkSVGStop::setStopColor(const SkSVGColorType& color) {
19 fStopColor = color;
20}
21
22void SkSVGStop::setStopOpacity(const SkSVGNumberType& opacity) {
23 fStopOpacity = SkTPin<SkScalar>(opacity.value(), 0, 1);
24}
25
26void 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}