| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
| 10 #include "SkSVGNode.h" | 10 #include "SkSVGNode.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 bool SkSVGNode::onPrepareToRender(SkSVGRenderContext* ctx) const { | 27 bool SkSVGNode::onPrepareToRender(SkSVGRenderContext* ctx) const { |
| 28 ctx->applyPresentationAttributes(fPresentationAttributes); | 28 ctx->applyPresentationAttributes(fPresentationAttributes); |
| 29 return true; | 29 return true; |
| 30 } | 30 } |
| 31 | 31 |
| 32 void SkSVGNode::setAttribute(SkSVGAttribute attr, const SkSVGValue& v) { | 32 void SkSVGNode::setAttribute(SkSVGAttribute attr, const SkSVGValue& v) { |
| 33 this->onSetAttribute(attr, v); | 33 this->onSetAttribute(attr, v); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void SkSVGNode::setFill(const SkSVGPaint& svgPaint) { |
| 37 fPresentationAttributes.fFill.set(svgPaint); |
| 38 } |
| 39 |
| 40 void SkSVGNode::setFillOpacity(const SkSVGNumberType& opacity) { |
| 41 fPresentationAttributes.fFillOpacity.set( |
| 42 SkSVGNumberType(SkTPin<SkScalar>(opacity.value(), 0, 1))); |
| 43 } |
| 44 |
| 45 void SkSVGNode::setStroke(const SkSVGPaint& svgPaint) { |
| 46 fPresentationAttributes.fStroke.set(svgPaint); |
| 47 } |
| 48 |
| 49 void SkSVGNode::setStrokeOpacity(const SkSVGNumberType& opacity) { |
| 50 fPresentationAttributes.fStrokeOpacity.set( |
| 51 SkSVGNumberType(SkTPin<SkScalar>(opacity.value(), 0, 1))); |
| 52 } |
| 53 |
| 54 void SkSVGNode::setStrokeWidth(const SkSVGLength& strokeWidth) { |
| 55 fPresentationAttributes.fStrokeWidth.set(strokeWidth); |
| 56 } |
| 57 |
| 36 void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { | 58 void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { |
| 37 switch (attr) { | 59 switch (attr) { |
| 38 case SkSVGAttribute::kFill: | 60 case SkSVGAttribute::kFill: |
| 39 if (const SkSVGPaintValue* paint = v.as<SkSVGPaintValue>()) { | 61 if (const SkSVGPaintValue* paint = v.as<SkSVGPaintValue>()) { |
| 40 fPresentationAttributes.fFill.set(*paint); | 62 this->setFill(*paint); |
| 41 } | 63 } |
| 42 break; | 64 break; |
| 43 case SkSVGAttribute::kFillOpacity: | 65 case SkSVGAttribute::kFillOpacity: |
| 44 if (const SkSVGNumberValue* opacity = v.as<SkSVGNumberValue>()) { | 66 if (const SkSVGNumberValue* opacity = v.as<SkSVGNumberValue>()) { |
| 45 fPresentationAttributes.fFillOpacity.set( | 67 this->setFillOpacity(*opacity); |
| 46 SkSVGNumberType(SkTPin<SkScalar>((*opacity)->value(), 0, 1))); | |
| 47 } | 68 } |
| 48 break; | 69 break; |
| 49 case SkSVGAttribute::kStroke: | 70 case SkSVGAttribute::kStroke: |
| 50 if (const SkSVGPaintValue* paint = v.as<SkSVGPaintValue>()) { | 71 if (const SkSVGPaintValue* paint = v.as<SkSVGPaintValue>()) { |
| 51 fPresentationAttributes.fStroke.set(*paint); | 72 this->setStroke(*paint); |
| 52 } | 73 } |
| 53 break; | 74 break; |
| 54 case SkSVGAttribute::kStrokeOpacity: | 75 case SkSVGAttribute::kStrokeOpacity: |
| 55 if (const SkSVGNumberValue* opacity = v.as<SkSVGNumberValue>()) { | 76 if (const SkSVGNumberValue* opacity = v.as<SkSVGNumberValue>()) { |
| 56 fPresentationAttributes.fStrokeOpacity.set( | 77 this->setStrokeOpacity(*opacity); |
| 57 SkSVGNumberType(SkTPin<SkScalar>((*opacity)->value(), 0, 1))); | |
| 58 } | 78 } |
| 59 break; | 79 break; |
| 60 case SkSVGAttribute::kStrokeLineCap: | 80 case SkSVGAttribute::kStrokeLineCap: |
| 61 if (const SkSVGLineCapValue* lineCap = v.as<SkSVGLineCapValue>()) { | 81 if (const SkSVGLineCapValue* lineCap = v.as<SkSVGLineCapValue>()) { |
| 62 fPresentationAttributes.fStrokeLineCap.set(*lineCap); | 82 fPresentationAttributes.fStrokeLineCap.set(*lineCap); |
| 63 } | 83 } |
| 64 break; | 84 break; |
| 65 case SkSVGAttribute::kStrokeLineJoin: | 85 case SkSVGAttribute::kStrokeLineJoin: |
| 66 if (const SkSVGLineJoinValue* lineJoin = v.as<SkSVGLineJoinValue>()) { | 86 if (const SkSVGLineJoinValue* lineJoin = v.as<SkSVGLineJoinValue>()) { |
| 67 fPresentationAttributes.fStrokeLineJoin.set(*lineJoin); | 87 fPresentationAttributes.fStrokeLineJoin.set(*lineJoin); |
| 68 } | 88 } |
| 69 break; | 89 break; |
| 70 case SkSVGAttribute::kStrokeWidth: | 90 case SkSVGAttribute::kStrokeWidth: |
| 71 if (const SkSVGLengthValue* strokeWidth = v.as<SkSVGLengthValue>()) { | 91 if (const SkSVGLengthValue* strokeWidth = v.as<SkSVGLengthValue>()) { |
| 72 fPresentationAttributes.fStrokeWidth.set(*strokeWidth); | 92 this->setStrokeWidth(*strokeWidth); |
| 73 } | 93 } |
| 74 break; | 94 break; |
| 75 default: | 95 default: |
| 76 SkDebugf("attribute ID <%d> ignored for node <%d>\n", attr, fTag); | 96 SkDebugf("attribute ID <%d> ignored for node <%d>\n", attr, fTag); |
| 77 break; | 97 break; |
| 78 } | 98 } |
| 79 } | 99 } |
| OLD | NEW |