Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: experimental/svg/model/SkSVGNode.cpp

Issue 2234153002: [SVGDom] Add more presentation attributes. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: review Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « experimental/svg/model/SkSVGDOM.cpp ('k') | experimental/svg/model/SkSVGRenderContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "SkSVGRenderContext.h" 11 #include "SkSVGRenderContext.h"
12 #include "SkSVGValue.h" 12 #include "SkSVGValue.h"
13 #include "SkTLazy.h" 13 #include "SkTLazy.h"
14 14
15 SkSVGNode::SkSVGNode(SkSVGTag t) : fTag(t) { } 15 SkSVGNode::SkSVGNode(SkSVGTag t) : fTag(t) { }
16 16
17 SkSVGNode::~SkSVGNode() { } 17 SkSVGNode::~SkSVGNode() { }
18 18
19 void SkSVGNode::render(const SkSVGRenderContext& ctx) const { 19 void SkSVGNode::render(const SkSVGRenderContext& ctx) const {
20 SkSVGRenderContext localContext(ctx); 20 SkSVGRenderContext localContext(ctx);
21 21
22 if (this->onPrepareToRender(&localContext)) { 22 if (this->onPrepareToRender(&localContext)) {
23 this->onRender(localContext); 23 this->onRender(localContext);
24 } 24 }
25 } 25 }
26 26
27 bool SkSVGNode::onPrepareToRender(SkSVGRenderContext* ctx) const { 27 bool SkSVGNode::onPrepareToRender(SkSVGRenderContext* ctx) const {
28 fPresentationAttributes.applyTo(ctx); 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::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { 36 void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
37 switch (attr) { 37 switch (attr) {
38 case SkSVGAttribute::kFill: 38 case SkSVGAttribute::kFill:
39 if (const SkSVGColorValue* color = v.as<SkSVGColorValue>()) { 39 if (const SkSVGPaintValue* paint = v.as<SkSVGPaintValue>()) {
40 fPresentationAttributes.setFill(*color); 40 fPresentationAttributes.fFill.set(*paint);
41 }
42 break;
43 case SkSVGAttribute::kFillOpacity:
44 if (const SkSVGNumberValue* opacity = v.as<SkSVGNumberValue>()) {
45 fPresentationAttributes.fFillOpacity.set(
46 SkSVGNumberType(SkTPin<SkScalar>((*opacity)->value(), 0, 1)));
41 } 47 }
42 break; 48 break;
43 case SkSVGAttribute::kStroke: 49 case SkSVGAttribute::kStroke:
44 if (const SkSVGColorValue* color = v.as<SkSVGColorValue>()) { 50 if (const SkSVGPaintValue* paint = v.as<SkSVGPaintValue>()) {
45 fPresentationAttributes.setStroke(*color); 51 fPresentationAttributes.fStroke.set(*paint);
52 }
53 break;
54 case SkSVGAttribute::kStrokeOpacity:
55 if (const SkSVGNumberValue* opacity = v.as<SkSVGNumberValue>()) {
56 fPresentationAttributes.fStrokeOpacity.set(
57 SkSVGNumberType(SkTPin<SkScalar>((*opacity)->value(), 0, 1)));
58 }
59 break;
60 case SkSVGAttribute::kStrokeLineCap:
61 if (const SkSVGLineCapValue* lineCap = v.as<SkSVGLineCapValue>()) {
62 fPresentationAttributes.fStrokeLineCap.set(*lineCap);
63 }
64 break;
65 case SkSVGAttribute::kStrokeLineJoin:
66 if (const SkSVGLineJoinValue* lineJoin = v.as<SkSVGLineJoinValue>()) {
67 fPresentationAttributes.fStrokeLineJoin.set(*lineJoin);
68 }
69 break;
70 case SkSVGAttribute::kStrokeWidth:
71 if (const SkSVGLengthValue* strokeWidth = v.as<SkSVGLengthValue>()) {
72 fPresentationAttributes.fStrokeWidth.set(*strokeWidth);
46 } 73 }
47 break; 74 break;
48 default: 75 default:
49 SkDebugf("attribute ID <%d> ignored for node <%d>\n", attr, fTag); 76 SkDebugf("attribute ID <%d> ignored for node <%d>\n", attr, fTag);
50 break; 77 break;
51 } 78 }
52 } 79 }
OLDNEW
« no previous file with comments | « experimental/svg/model/SkSVGDOM.cpp ('k') | experimental/svg/model/SkSVGRenderContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698