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 "SkDOM.h" | 9 #include "SkDOM.h" |
10 #include "SkParse.h" | |
11 #include "SkParsePath.h" | 10 #include "SkParsePath.h" |
12 #include "SkString.h" | 11 #include "SkString.h" |
13 #include "SkSVGAttributeParser.h" | 12 #include "SkSVGAttributeParser.h" |
14 #include "SkSVGDOM.h" | 13 #include "SkSVGDOM.h" |
15 #include "SkSVGG.h" | 14 #include "SkSVGG.h" |
16 #include "SkSVGNode.h" | 15 #include "SkSVGNode.h" |
17 #include "SkSVGPath.h" | 16 #include "SkSVGPath.h" |
18 #include "SkSVGRect.h" | 17 #include "SkSVGRect.h" |
19 #include "SkSVGRenderContext.h" | 18 #include "SkSVGRenderContext.h" |
20 #include "SkSVGSVG.h" | 19 #include "SkSVGSVG.h" |
21 #include "SkSVGTypes.h" | 20 #include "SkSVGTypes.h" |
22 #include "SkSVGValue.h" | 21 #include "SkSVGValue.h" |
23 #include "SkTSearch.h" | 22 #include "SkTSearch.h" |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
27 const char* ParseScalarPair(const char* str, SkScalar v[2]) { | |
28 str = SkParse::FindScalar(str, v); | |
29 if (str) { | |
30 const char* second = SkParse::FindScalar(str, v + 1); | |
31 if (!second) { | |
32 v[1] = v[0]; | |
33 } else { | |
34 str = second; | |
35 } | |
36 } | |
37 | |
38 return str; | |
39 } | |
40 | |
41 SkMatrix ParseTransform(const char* str) { | |
42 SkMatrix m = SkMatrix::I(); | |
43 | |
44 // FIXME: real parser | |
45 if (!strncmp(str, "matrix(", 7)) { | |
46 SkScalar values[6]; | |
47 str = SkParse::FindScalars(str + 7, values, 6); | |
48 if (str) { | |
49 m.setAffine(values); | |
50 } | |
51 } else if (!strncmp(str, "scale(", 6)) { | |
52 SkScalar values[2]; | |
53 str = ParseScalarPair(str + 6, values); | |
54 if (str) { | |
55 m.setScale(values[0], values[1]); | |
56 } | |
57 } else if (!strncmp(str, "translate(", 10)) { | |
58 SkScalar values[2]; | |
59 str = ParseScalarPair(str + 10, values); | |
60 if (str) { | |
61 m.setTranslate(values[0], values[1]); | |
62 } | |
63 } else if (!strncmp(str, "rotate(", 7)) { | |
64 SkScalar value; | |
65 str = SkParse::FindScalar(str + 7, &value); | |
66 if (str) { | |
67 m.setRotate(value); | |
68 } | |
69 } | |
70 | |
71 return m; | |
72 } | |
73 | |
74 bool SetPaintAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, | 26 bool SetPaintAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, |
75 const char* stringValue) { | 27 const char* stringValue) { |
76 SkSVGColorType color; | 28 SkSVGColorType color; |
77 SkSVGAttributeParser parser(stringValue); | 29 SkSVGAttributeParser parser(stringValue); |
78 if (!parser.parseColor(&color)) { | 30 if (!parser.parseColor(&color)) { |
79 return false; | 31 return false; |
80 } | 32 } |
81 | 33 |
82 node->setAttribute(attr, SkSVGColorValue(color)); | 34 node->setAttribute(attr, SkSVGColorValue(color)); |
83 return true; | 35 return true; |
84 } | 36 } |
85 | 37 |
86 bool SetPathDataAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, | 38 bool SetPathDataAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, |
87 const char* stringValue) { | 39 const char* stringValue) { |
88 SkPath path; | 40 SkPath path; |
89 if (!SkParsePath::FromSVGString(stringValue, &path)) { | 41 if (!SkParsePath::FromSVGString(stringValue, &path)) { |
90 return false; | 42 return false; |
91 } | 43 } |
92 | 44 |
93 node->setAttribute(attr, SkSVGPathValue(path)); | 45 node->setAttribute(attr, SkSVGPathValue(path)); |
94 return true; | 46 return true; |
95 } | 47 } |
96 | 48 |
97 bool SetTransformAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, | 49 bool SetTransformAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, |
98 const char* stringValue) { | 50 const char* stringValue) { |
99 node->setAttribute(attr, SkSVGTransformValue(ParseTransform(stringValue))); | 51 SkSVGTransformType transform; |
| 52 SkSVGAttributeParser parser(stringValue); |
| 53 if (!parser.parseTransform(&transform)) { |
| 54 return false; |
| 55 } |
| 56 |
| 57 node->setAttribute(attr, SkSVGTransformValue(transform)); |
100 return true; | 58 return true; |
101 } | 59 } |
102 | 60 |
103 bool SetLengthAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, | 61 bool SetLengthAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, |
104 const char* stringValue) { | 62 const char* stringValue) { |
105 SkSVGLength length; | 63 SkSVGLength length; |
106 SkSVGAttributeParser parser(stringValue); | 64 SkSVGAttributeParser parser(stringValue); |
107 if (!parser.parseLength(&length)) { | 65 if (!parser.parseLength(&length)) { |
108 return false; | 66 return false; |
109 } | 67 } |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 SkSVGLengthContext(fContainerSize), | 267 SkSVGLengthContext(fContainerSize), |
310 SkSVGPresentationContext()); | 268 SkSVGPresentationContext()); |
311 fRoot->render(ctx); | 269 fRoot->render(ctx); |
312 } | 270 } |
313 } | 271 } |
314 | 272 |
315 void SkSVGDOM::setContainerSize(const SkSize& containerSize) { | 273 void SkSVGDOM::setContainerSize(const SkSize& containerSize) { |
316 // TODO: inval | 274 // TODO: inval |
317 fContainerSize = containerSize; | 275 fContainerSize = containerSize; |
318 } | 276 } |
OLD | NEW |