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

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

Issue 2235273003: [SVGDom] <polygon> & <polyline> support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: GN build fix 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.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 "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 "SkSVGPoly.h"
17 #include "SkSVGRect.h" 18 #include "SkSVGRect.h"
18 #include "SkSVGRenderContext.h" 19 #include "SkSVGRenderContext.h"
19 #include "SkSVGSVG.h" 20 #include "SkSVGSVG.h"
20 #include "SkSVGTypes.h" 21 #include "SkSVGTypes.h"
21 #include "SkSVGValue.h" 22 #include "SkSVGValue.h"
22 #include "SkTSearch.h" 23 #include "SkTSearch.h"
23 24
24 namespace { 25 namespace {
25 26
26 bool SetPaintAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, 27 bool SetPaintAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 SkSVGLineJoin lineJoin; 116 SkSVGLineJoin lineJoin;
116 SkSVGAttributeParser parser(stringValue); 117 SkSVGAttributeParser parser(stringValue);
117 if (!parser.parseLineJoin(&lineJoin)) { 118 if (!parser.parseLineJoin(&lineJoin)) {
118 return false; 119 return false;
119 } 120 }
120 121
121 node->setAttribute(attr, SkSVGLineJoinValue(lineJoin)); 122 node->setAttribute(attr, SkSVGLineJoinValue(lineJoin));
122 return true; 123 return true;
123 } 124 }
124 125
126 bool SetPointsAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
127 const char* stringValue) {
128 SkSVGPointsType points;
129 SkSVGAttributeParser parser(stringValue);
130 if (!parser.parsePoints(&points)) {
131 return false;
132 }
133
134 node->setAttribute(attr, SkSVGPointsValue(points));
135 return true;
136 }
137
125 SkString TrimmedString(const char* first, const char* last) { 138 SkString TrimmedString(const char* first, const char* last) {
126 SkASSERT(first); 139 SkASSERT(first);
127 SkASSERT(last); 140 SkASSERT(last);
128 SkASSERT(first <= last); 141 SkASSERT(first <= last);
129 142
130 while (first <= last && *first <= ' ') { first++; } 143 while (first <= last && *first <= ' ') { first++; }
131 while (first <= last && *last <= ' ') { last--; } 144 while (first <= last && *last <= ' ') { last--; }
132 145
133 SkASSERT(last - first + 1 >= 0); 146 SkASSERT(last - first + 1 >= 0);
134 return SkString(first, SkTo<size_t>(last - first + 1)); 147 return SkString(first, SkTo<size_t>(last - first + 1));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 struct AttrParseInfo { 210 struct AttrParseInfo {
198 SkSVGAttribute fAttr; 211 SkSVGAttribute fAttr;
199 bool (*fSetter)(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, const cha r* stringValue); 212 bool (*fSetter)(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, const cha r* stringValue);
200 }; 213 };
201 214
202 SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = { 215 SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = {
203 { "d" , { SkSVGAttribute::kD , SetPathDataAttribute }}, 216 { "d" , { SkSVGAttribute::kD , SetPathDataAttribute }},
204 { "fill" , { SkSVGAttribute::kFill , SetPaintAttribute }}, 217 { "fill" , { SkSVGAttribute::kFill , SetPaintAttribute }},
205 { "fill-opacity" , { SkSVGAttribute::kFillOpacity , SetNumberAttribute }}, 218 { "fill-opacity" , { SkSVGAttribute::kFillOpacity , SetNumberAttribute }},
206 { "height" , { SkSVGAttribute::kHeight , SetLengthAttribute }}, 219 { "height" , { SkSVGAttribute::kHeight , SetLengthAttribute }},
220 { "points" , { SkSVGAttribute::kPoints , SetPointsAttribute }},
207 { "rx" , { SkSVGAttribute::kRx , SetLengthAttribute }}, 221 { "rx" , { SkSVGAttribute::kRx , SetLengthAttribute }},
208 { "ry" , { SkSVGAttribute::kRy , SetLengthAttribute }}, 222 { "ry" , { SkSVGAttribute::kRy , SetLengthAttribute }},
209 { "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }}, 223 { "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }},
210 { "stroke-linecap" , { SkSVGAttribute::kStrokeLineCap , SetLineCapAttribute }}, 224 { "stroke-linecap" , { SkSVGAttribute::kStrokeLineCap , SetLineCapAttribute }},
211 { "stroke-linejoin", { SkSVGAttribute::kStrokeLineJoin, SetLineJoinAttribute }}, 225 { "stroke-linejoin", { SkSVGAttribute::kStrokeLineJoin, SetLineJoinAttribute }},
212 { "stroke-opacity" , { SkSVGAttribute::kStrokeOpacity , SetNumberAttribute }}, 226 { "stroke-opacity" , { SkSVGAttribute::kStrokeOpacity , SetNumberAttribute }},
213 { "stroke-width" , { SkSVGAttribute::kStrokeWidth , SetLengthAttribute }}, 227 { "stroke-width" , { SkSVGAttribute::kStrokeWidth , SetLengthAttribute }},
214 { "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes }}, 228 { "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes }},
215 { "transform" , { SkSVGAttribute::kTransform , SetTransformAttribut e }}, 229 { "transform" , { SkSVGAttribute::kTransform , SetTransformAttribut e }},
216 { "viewBox" , { SkSVGAttribute::kViewBox , SetViewBoxAttribute }}, 230 { "viewBox" , { SkSVGAttribute::kViewBox , SetViewBoxAttribute }},
217 { "width" , { SkSVGAttribute::kWidth , SetLengthAttribute }}, 231 { "width" , { SkSVGAttribute::kWidth , SetLengthAttribute }},
218 { "x" , { SkSVGAttribute::kX , SetLengthAttribute }}, 232 { "x" , { SkSVGAttribute::kX , SetLengthAttribute }},
219 { "y" , { SkSVGAttribute::kY , SetLengthAttribute }}, 233 { "y" , { SkSVGAttribute::kY , SetLengthAttribute }},
220 }; 234 };
221 235
222 SortedDictionaryEntry<sk_sp<SkSVGNode>(*)()> gTagFactories[] = { 236 SortedDictionaryEntry<sk_sp<SkSVGNode>(*)()> gTagFactories[] = {
223 { "g" , []() -> sk_sp<SkSVGNode> { return SkSVGG::Make(); }}, 237 { "g" , []() -> sk_sp<SkSVGNode> { return SkSVGG::Make(); } },
224 { "path", []() -> sk_sp<SkSVGNode> { return SkSVGPath::Make(); }}, 238 { "path" , []() -> sk_sp<SkSVGNode> { return SkSVGPath::Make(); } },
225 { "rect", []() -> sk_sp<SkSVGNode> { return SkSVGRect::Make(); }}, 239 { "polygon" , []() -> sk_sp<SkSVGNode> { return SkSVGPoly::MakePolygon(); } },
226 { "svg" , []() -> sk_sp<SkSVGNode> { return SkSVGSVG::Make(); }}, 240 { "polyline", []() -> sk_sp<SkSVGNode> { return SkSVGPoly::MakePolyline(); } },
241 { "rect" , []() -> sk_sp<SkSVGNode> { return SkSVGRect::Make(); } },
242 { "svg" , []() -> sk_sp<SkSVGNode> { return SkSVGSVG::Make(); } },
227 }; 243 };
228 244
229 struct ConstructionContext { 245 struct ConstructionContext {
230 ConstructionContext() : fParent(nullptr) { } 246 ConstructionContext() : fParent(nullptr) { }
231 ConstructionContext(const ConstructionContext& other, const sk_sp<SkSVGNode> & newParent) 247 ConstructionContext(const ConstructionContext& other, const sk_sp<SkSVGNode> & newParent)
232 : fParent(newParent.get()) { } 248 : fParent(newParent.get()) { }
233 249
234 const SkSVGNode* fParent; 250 const SkSVGNode* fParent;
235 }; 251 };
236 252
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 SkSVGLengthContext(fContainerSize), 348 SkSVGLengthContext(fContainerSize),
333 SkSVGPresentationContext()); 349 SkSVGPresentationContext());
334 fRoot->render(ctx); 350 fRoot->render(ctx);
335 } 351 }
336 } 352 }
337 353
338 void SkSVGDOM::setContainerSize(const SkSize& containerSize) { 354 void SkSVGDOM::setContainerSize(const SkSize& containerSize) {
339 // TODO: inval 355 // TODO: inval
340 fContainerSize = containerSize; 356 fContainerSize = containerSize;
341 } 357 }
OLDNEW
« no previous file with comments | « experimental/svg/model/SkSVGAttributeParser.cpp ('k') | experimental/svg/model/SkSVGNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698