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

Side by Side Diff: experimental/svg/model/SkSVGDOM.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/SkSVGAttributeParser.cpp ('k') | experimental/svg/model/SkSVGNode.cpp » ('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 "SkDOM.h" 9 #include "SkDOM.h"
10 #include "SkParsePath.h" 10 #include "SkParsePath.h"
11 #include "SkString.h" 11 #include "SkString.h"
12 #include "SkSVGAttributeParser.h" 12 #include "SkSVGAttributeParser.h"
13 #include "SkSVGDOM.h" 13 #include "SkSVGDOM.h"
14 #include "SkSVGG.h" 14 #include "SkSVGG.h"
15 #include "SkSVGNode.h" 15 #include "SkSVGNode.h"
16 #include "SkSVGPath.h" 16 #include "SkSVGPath.h"
17 #include "SkSVGRect.h" 17 #include "SkSVGRect.h"
18 #include "SkSVGRenderContext.h" 18 #include "SkSVGRenderContext.h"
19 #include "SkSVGSVG.h" 19 #include "SkSVGSVG.h"
20 #include "SkSVGTypes.h" 20 #include "SkSVGTypes.h"
21 #include "SkSVGValue.h" 21 #include "SkSVGValue.h"
22 #include "SkTSearch.h" 22 #include "SkTSearch.h"
23 23
24 namespace { 24 namespace {
25 25
26 bool SetPaintAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, 26 bool SetPaintAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
27 const char* stringValue) { 27 const char* stringValue) {
28 SkSVGColorType color; 28 SkSVGPaint paint;
29 SkSVGAttributeParser parser(stringValue); 29 SkSVGAttributeParser parser(stringValue);
30 if (!parser.parseColor(&color)) { 30 if (!parser.parsePaint(&paint)) {
31 return false; 31 // Until we have paint server support, failing here will cause default/a ll-black rendering.
32 // It's better to just not draw for now.
33 paint = SkSVGPaint(SkSVGPaint::Type::kNone);
34
35 // return false;
32 } 36 }
33 37
34 node->setAttribute(attr, SkSVGColorValue(color)); 38 node->setAttribute(attr, SkSVGPaintValue(paint));
35 return true; 39 return true;
36 } 40 }
37 41
38 bool SetPathDataAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, 42 bool SetPathDataAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
39 const char* stringValue) { 43 const char* stringValue) {
40 SkPath path; 44 SkPath path;
41 if (!SkParsePath::FromSVGString(stringValue, &path)) { 45 if (!SkParsePath::FromSVGString(stringValue, &path)) {
42 return false; 46 return false;
43 } 47 }
44 48
(...skipping 18 matching lines...) Expand all
63 SkSVGLength length; 67 SkSVGLength length;
64 SkSVGAttributeParser parser(stringValue); 68 SkSVGAttributeParser parser(stringValue);
65 if (!parser.parseLength(&length)) { 69 if (!parser.parseLength(&length)) {
66 return false; 70 return false;
67 } 71 }
68 72
69 node->setAttribute(attr, SkSVGLengthValue(length)); 73 node->setAttribute(attr, SkSVGLengthValue(length));
70 return true; 74 return true;
71 } 75 }
72 76
77 bool SetNumberAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
78 const char* stringValue) {
79 SkSVGNumberType number;
80 SkSVGAttributeParser parser(stringValue);
81 if (!parser.parseNumber(&number)) {
82 return false;
83 }
84
85 node->setAttribute(attr, SkSVGNumberValue(number));
86 return true;
87 }
88
73 bool SetViewBoxAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, 89 bool SetViewBoxAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
74 const char* stringValue) { 90 const char* stringValue) {
75 SkSVGViewBoxType viewBox; 91 SkSVGViewBoxType viewBox;
76 SkSVGAttributeParser parser(stringValue); 92 SkSVGAttributeParser parser(stringValue);
77 if (!parser.parseViewBox(&viewBox)) { 93 if (!parser.parseViewBox(&viewBox)) {
78 return false; 94 return false;
79 } 95 }
80 96
81 node->setAttribute(attr, SkSVGViewBoxValue(viewBox)); 97 node->setAttribute(attr, SkSVGViewBoxValue(viewBox));
82 return true; 98 return true;
83 } 99 }
84 100
101 bool SetLineCapAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
102 const char* stringValue) {
103 SkSVGLineCap lineCap;
104 SkSVGAttributeParser parser(stringValue);
105 if (!parser.parseLineCap(&lineCap)) {
106 return false;
107 }
108
109 node->setAttribute(attr, SkSVGLineCapValue(lineCap));
110 return true;
111 }
112
113 bool SetLineJoinAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
114 const char* stringValue) {
115 SkSVGLineJoin lineJoin;
116 SkSVGAttributeParser parser(stringValue);
117 if (!parser.parseLineJoin(&lineJoin)) {
118 return false;
119 }
120
121 node->setAttribute(attr, SkSVGLineJoinValue(lineJoin));
122 return true;
123 }
124
85 SkString TrimmedString(const char* first, const char* last) { 125 SkString TrimmedString(const char* first, const char* last) {
86 SkASSERT(first); 126 SkASSERT(first);
87 SkASSERT(last); 127 SkASSERT(last);
88 SkASSERT(first <= last); 128 SkASSERT(first <= last);
89 129
90 while (first <= last && *first <= ' ') { first++; } 130 while (first <= last && *first <= ' ') { first++; }
91 while (first <= last && *last <= ' ') { last--; } 131 while (first <= last && *last <= ' ') { last--; }
92 132
93 SkASSERT(last - first + 1 >= 0); 133 SkASSERT(last - first + 1 >= 0);
94 return SkString(first, SkTo<size_t>(last - first + 1)); 134 return SkString(first, SkTo<size_t>(last - first + 1));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 const char* fKey; 193 const char* fKey;
154 const T fValue; 194 const T fValue;
155 }; 195 };
156 196
157 struct AttrParseInfo { 197 struct AttrParseInfo {
158 SkSVGAttribute fAttr; 198 SkSVGAttribute fAttr;
159 bool (*fSetter)(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, const cha r* stringValue); 199 bool (*fSetter)(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, const cha r* stringValue);
160 }; 200 };
161 201
162 SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = { 202 SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = {
163 { "d" , { SkSVGAttribute::kD , SetPathDataAttribute }}, 203 { "d" , { SkSVGAttribute::kD , SetPathDataAttribute }},
164 { "fill" , { SkSVGAttribute::kFill , SetPaintAttribute }}, 204 { "fill" , { SkSVGAttribute::kFill , SetPaintAttribute }},
165 { "height" , { SkSVGAttribute::kHeight , SetLengthAttribute }}, 205 { "fill-opacity" , { SkSVGAttribute::kFillOpacity , SetNumberAttribute }},
166 { "rx" , { SkSVGAttribute::kRx , SetLengthAttribute }}, 206 { "height" , { SkSVGAttribute::kHeight , SetLengthAttribute }},
167 { "ry" , { SkSVGAttribute::kRy , SetLengthAttribute }}, 207 { "rx" , { SkSVGAttribute::kRx , SetLengthAttribute }},
168 { "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }}, 208 { "ry" , { SkSVGAttribute::kRy , SetLengthAttribute }},
169 { "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes }}, 209 { "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }},
170 { "transform", { SkSVGAttribute::kTransform, SetTransformAttribute }}, 210 { "stroke-linecap" , { SkSVGAttribute::kStrokeLineCap , SetLineCapAttribute }},
171 { "viewBox" , { SkSVGAttribute::kViewBox , SetViewBoxAttribute }}, 211 { "stroke-linejoin", { SkSVGAttribute::kStrokeLineJoin, SetLineJoinAttribute }},
172 { "width" , { SkSVGAttribute::kWidth , SetLengthAttribute }}, 212 { "stroke-opacity" , { SkSVGAttribute::kStrokeOpacity , SetNumberAttribute }},
173 { "x" , { SkSVGAttribute::kX , SetLengthAttribute }}, 213 { "stroke-width" , { SkSVGAttribute::kStrokeWidth , SetLengthAttribute }},
174 { "y" , { SkSVGAttribute::kY , SetLengthAttribute }}, 214 { "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes }},
215 { "transform" , { SkSVGAttribute::kTransform , SetTransformAttribut e }},
216 { "viewBox" , { SkSVGAttribute::kViewBox , SetViewBoxAttribute }},
217 { "width" , { SkSVGAttribute::kWidth , SetLengthAttribute }},
218 { "x" , { SkSVGAttribute::kX , SetLengthAttribute }},
219 { "y" , { SkSVGAttribute::kY , SetLengthAttribute }},
175 }; 220 };
176 221
177 SortedDictionaryEntry<sk_sp<SkSVGNode>(*)()> gTagFactories[] = { 222 SortedDictionaryEntry<sk_sp<SkSVGNode>(*)()> gTagFactories[] = {
178 { "g" , []() -> sk_sp<SkSVGNode> { return SkSVGG::Make(); }}, 223 { "g" , []() -> sk_sp<SkSVGNode> { return SkSVGG::Make(); }},
179 { "path", []() -> sk_sp<SkSVGNode> { return SkSVGPath::Make(); }}, 224 { "path", []() -> sk_sp<SkSVGNode> { return SkSVGPath::Make(); }},
180 { "rect", []() -> sk_sp<SkSVGNode> { return SkSVGRect::Make(); }}, 225 { "rect", []() -> sk_sp<SkSVGNode> { return SkSVGRect::Make(); }},
181 { "svg" , []() -> sk_sp<SkSVGNode> { return SkSVGSVG::Make(); }}, 226 { "svg" , []() -> sk_sp<SkSVGNode> { return SkSVGSVG::Make(); }},
182 }; 227 };
183 228
184 struct ConstructionContext { 229 struct ConstructionContext {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 SkSVGLengthContext(fContainerSize), 332 SkSVGLengthContext(fContainerSize),
288 SkSVGPresentationContext()); 333 SkSVGPresentationContext());
289 fRoot->render(ctx); 334 fRoot->render(ctx);
290 } 335 }
291 } 336 }
292 337
293 void SkSVGDOM::setContainerSize(const SkSize& containerSize) { 338 void SkSVGDOM::setContainerSize(const SkSize& containerSize) {
294 // TODO: inval 339 // TODO: inval
295 fContainerSize = containerSize; 340 fContainerSize = containerSize;
296 } 341 }
OLDNEW
« no previous file with comments | « experimental/svg/model/SkSVGAttributeParser.cpp ('k') | experimental/svg/model/SkSVGNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698