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 "SkParsePath.h" | 10 #include "SkParsePath.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 SkSVGViewBoxType viewBox; | 75 SkSVGViewBoxType viewBox; |
76 SkSVGAttributeParser parser(stringValue); | 76 SkSVGAttributeParser parser(stringValue); |
77 if (!parser.parseViewBox(&viewBox)) { | 77 if (!parser.parseViewBox(&viewBox)) { |
78 return false; | 78 return false; |
79 } | 79 } |
80 | 80 |
81 node->setAttribute(attr, SkSVGViewBoxValue(viewBox)); | 81 node->setAttribute(attr, SkSVGViewBoxValue(viewBox)); |
82 return true; | 82 return true; |
83 } | 83 } |
84 | 84 |
| 85 SkString TrimmedString(const char* first, const char* last) { |
| 86 SkASSERT(first); |
| 87 SkASSERT(last); |
| 88 SkASSERT(first <= last); |
| 89 |
| 90 while (first <= last && *first <= ' ') { first++; } |
| 91 while (first <= last && *last <= ' ') { last--; } |
| 92 |
| 93 SkASSERT(last - first + 1 >= 0); |
| 94 return SkString(first, SkTo<size_t>(last - first + 1)); |
| 95 } |
| 96 |
85 // Breaks a "foo: bar; baz: ..." string into key:value pairs. | 97 // Breaks a "foo: bar; baz: ..." string into key:value pairs. |
86 class StyleIterator { | 98 class StyleIterator { |
87 public: | 99 public: |
88 StyleIterator(const char* str) : fPos(str) { } | 100 StyleIterator(const char* str) : fPos(str) { } |
89 | 101 |
90 std::tuple<SkString, SkString> next() { | 102 std::tuple<SkString, SkString> next() { |
91 SkString name, value; | 103 SkString name, value; |
92 | 104 |
93 if (fPos) { | 105 if (fPos) { |
94 const char* sep = this->nextSeparator(); | 106 const char* sep = this->nextSeparator(); |
95 SkASSERT(*sep == ';' || *sep == '\0'); | 107 SkASSERT(*sep == ';' || *sep == '\0'); |
96 | 108 |
97 const char* valueSep = strchr(fPos, ':'); | 109 const char* valueSep = strchr(fPos, ':'); |
98 if (valueSep && valueSep < sep) { | 110 if (valueSep && valueSep < sep) { |
99 name.set(fPos, valueSep - fPos); | 111 name = TrimmedString(fPos, valueSep - 1); |
100 value.set(valueSep + 1, sep - valueSep - 1); | 112 value = TrimmedString(valueSep + 1, sep - 1); |
101 } | 113 } |
102 | 114 |
103 fPos = *sep ? sep + 1 : nullptr; | 115 fPos = *sep ? sep + 1 : nullptr; |
104 } | 116 } |
105 | 117 |
106 return std::make_tuple(name, value); | 118 return std::make_tuple(name, value); |
107 } | 119 } |
108 | 120 |
109 private: | 121 private: |
110 const char* nextSeparator() const { | 122 const char* nextSeparator() const { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 SkSVGLengthContext(fContainerSize), | 279 SkSVGLengthContext(fContainerSize), |
268 SkSVGPresentationContext()); | 280 SkSVGPresentationContext()); |
269 fRoot->render(ctx); | 281 fRoot->render(ctx); |
270 } | 282 } |
271 } | 283 } |
272 | 284 |
273 void SkSVGDOM::setContainerSize(const SkSize& containerSize) { | 285 void SkSVGDOM::setContainerSize(const SkSize& containerSize) { |
274 // TODO: inval | 286 // TODO: inval |
275 fContainerSize = containerSize; | 287 fContainerSize = containerSize; |
276 } | 288 } |
OLD | NEW |