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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 SkSVGLineJoin lineJoin; | 142 SkSVGLineJoin lineJoin; |
143 SkSVGAttributeParser parser(stringValue); | 143 SkSVGAttributeParser parser(stringValue); |
144 if (!parser.parseLineJoin(&lineJoin)) { | 144 if (!parser.parseLineJoin(&lineJoin)) { |
145 return false; | 145 return false; |
146 } | 146 } |
147 | 147 |
148 node->setAttribute(attr, SkSVGLineJoinValue(lineJoin)); | 148 node->setAttribute(attr, SkSVGLineJoinValue(lineJoin)); |
149 return true; | 149 return true; |
150 } | 150 } |
151 | 151 |
| 152 bool SetSpreadMethodAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, |
| 153 const char* stringValue) { |
| 154 SkSVGSpreadMethod spread; |
| 155 SkSVGAttributeParser parser(stringValue); |
| 156 if (!parser.parseSpreadMethod(&spread)) { |
| 157 return false; |
| 158 } |
| 159 |
| 160 node->setAttribute(attr, SkSVGSpreadMethodValue(spread)); |
| 161 return true; |
| 162 } |
| 163 |
152 bool SetPointsAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, | 164 bool SetPointsAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, |
153 const char* stringValue) { | 165 const char* stringValue) { |
154 SkSVGPointsType points; | 166 SkSVGPointsType points; |
155 SkSVGAttributeParser parser(stringValue); | 167 SkSVGAttributeParser parser(stringValue); |
156 if (!parser.parsePoints(&points)) { | 168 if (!parser.parsePoints(&points)) { |
157 return false; | 169 return false; |
158 } | 170 } |
159 | 171 |
160 node->setAttribute(attr, SkSVGPointsValue(points)); | 172 node->setAttribute(attr, SkSVGPointsValue(points)); |
161 return true; | 173 return true; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 const char* fKey; | 244 const char* fKey; |
233 const T fValue; | 245 const T fValue; |
234 }; | 246 }; |
235 | 247 |
236 struct AttrParseInfo { | 248 struct AttrParseInfo { |
237 SkSVGAttribute fAttr; | 249 SkSVGAttribute fAttr; |
238 bool (*fSetter)(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, const cha
r* stringValue); | 250 bool (*fSetter)(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, const cha
r* stringValue); |
239 }; | 251 }; |
240 | 252 |
241 SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = { | 253 SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = { |
242 { "cx" , { SkSVGAttribute::kCx , SetLengthAttribute
}}, | 254 { "cx" , { SkSVGAttribute::kCx , SetLengthAttribute
}}, |
243 { "cy" , { SkSVGAttribute::kCy , SetLengthAttribute
}}, | 255 { "cy" , { SkSVGAttribute::kCy , SetLengthAttribute
}}, |
244 { "d" , { SkSVGAttribute::kD , SetPathDataAttribute
}}, | 256 { "d" , { SkSVGAttribute::kD , SetPathDataAttribute
}}, |
245 { "fill" , { SkSVGAttribute::kFill , SetPaintAttribute
}}, | 257 { "fill" , { SkSVGAttribute::kFill , SetPaintAttribute
}}, |
246 { "fill-opacity" , { SkSVGAttribute::kFillOpacity , SetNumberAttribute
}}, | 258 { "fill-opacity" , { SkSVGAttribute::kFillOpacity , SetNumberAttribute
}}, |
247 { "height" , { SkSVGAttribute::kHeight , SetLengthAttribute
}}, | 259 { "height" , { SkSVGAttribute::kHeight , SetLengthAttribute
}}, |
248 { "offset" , { SkSVGAttribute::kOffset , SetLengthAttribute
}}, | 260 { "offset" , { SkSVGAttribute::kOffset , SetLengthAttribute
}}, |
249 { "opacity" , { SkSVGAttribute::kOpacity , SetNumberAttribute
}}, | 261 { "opacity" , { SkSVGAttribute::kOpacity , SetNumberAttribute
}}, |
250 { "points" , { SkSVGAttribute::kPoints , SetPointsAttribute
}}, | 262 { "points" , { SkSVGAttribute::kPoints , SetPointsAttribute
}}, |
251 { "r" , { SkSVGAttribute::kR , SetLengthAttribute
}}, | 263 { "r" , { SkSVGAttribute::kR , SetLengthAttribute
}}, |
252 { "rx" , { SkSVGAttribute::kRx , SetLengthAttribute
}}, | 264 { "rx" , { SkSVGAttribute::kRx , SetLengthAttribute
}}, |
253 { "ry" , { SkSVGAttribute::kRy , SetLengthAttribute
}}, | 265 { "ry" , { SkSVGAttribute::kRy , SetLengthAttribute
}}, |
254 { "stop-color" , { SkSVGAttribute::kStopColor , SetColorAttribute
}}, | 266 { "spreadMethod" , { SkSVGAttribute::kSpreadMethod , SetSpreadMethodAttri
bute }}, |
255 { "stop-opacity" , { SkSVGAttribute::kStopOpacity , SetNumberAttribute
}}, | 267 { "stop-color" , { SkSVGAttribute::kStopColor , SetColorAttribute
}}, |
256 { "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute
}}, | 268 { "stop-opacity" , { SkSVGAttribute::kStopOpacity , SetNumberAttribute
}}, |
257 { "stroke-linecap" , { SkSVGAttribute::kStrokeLineCap , SetLineCapAttribute
}}, | 269 { "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute
}}, |
258 { "stroke-linejoin", { SkSVGAttribute::kStrokeLineJoin, SetLineJoinAttribute
}}, | 270 { "stroke-linecap" , { SkSVGAttribute::kStrokeLineCap , SetLineCapAttribute
}}, |
259 { "stroke-opacity" , { SkSVGAttribute::kStrokeOpacity , SetNumberAttribute
}}, | 271 { "stroke-linejoin", { SkSVGAttribute::kStrokeLineJoin, SetLineJoinAttribute
}}, |
260 { "stroke-width" , { SkSVGAttribute::kStrokeWidth , SetLengthAttribute
}}, | 272 { "stroke-opacity" , { SkSVGAttribute::kStrokeOpacity , SetNumberAttribute
}}, |
261 { "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes
}}, | 273 { "stroke-width" , { SkSVGAttribute::kStrokeWidth , SetLengthAttribute
}}, |
262 { "transform" , { SkSVGAttribute::kTransform , SetTransformAttribut
e }}, | 274 { "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes
}}, |
263 { "viewBox" , { SkSVGAttribute::kViewBox , SetViewBoxAttribute
}}, | 275 { "transform" , { SkSVGAttribute::kTransform , SetTransformAttribut
e }}, |
264 { "width" , { SkSVGAttribute::kWidth , SetLengthAttribute
}}, | 276 { "viewBox" , { SkSVGAttribute::kViewBox , SetViewBoxAttribute
}}, |
265 { "x" , { SkSVGAttribute::kX , SetLengthAttribute
}}, | 277 { "width" , { SkSVGAttribute::kWidth , SetLengthAttribute
}}, |
266 { "x1" , { SkSVGAttribute::kX1 , SetLengthAttribute
}}, | 278 { "x" , { SkSVGAttribute::kX , SetLengthAttribute
}}, |
267 { "x2" , { SkSVGAttribute::kX2 , SetLengthAttribute
}}, | 279 { "x1" , { SkSVGAttribute::kX1 , SetLengthAttribute
}}, |
268 { "xlink:href" , { SkSVGAttribute::kHref , SetIRIAttribute
}}, | 280 { "x2" , { SkSVGAttribute::kX2 , SetLengthAttribute
}}, |
269 { "y" , { SkSVGAttribute::kY , SetLengthAttribute
}}, | 281 { "xlink:href" , { SkSVGAttribute::kHref , SetIRIAttribute
}}, |
270 { "y1" , { SkSVGAttribute::kY1 , SetLengthAttribute
}}, | 282 { "y" , { SkSVGAttribute::kY , SetLengthAttribute
}}, |
271 { "y2" , { SkSVGAttribute::kY2 , SetLengthAttribute
}}, | 283 { "y1" , { SkSVGAttribute::kY1 , SetLengthAttribute
}}, |
| 284 { "y2" , { SkSVGAttribute::kY2 , SetLengthAttribute
}}, |
272 }; | 285 }; |
273 | 286 |
274 SortedDictionaryEntry<sk_sp<SkSVGNode>(*)()> gTagFactories[] = { | 287 SortedDictionaryEntry<sk_sp<SkSVGNode>(*)()> gTagFactories[] = { |
275 { "circle" , []() -> sk_sp<SkSVGNode> { return SkSVGCircle::Make();
}}, | 288 { "circle" , []() -> sk_sp<SkSVGNode> { return SkSVGCircle::Make();
}}, |
276 { "defs" , []() -> sk_sp<SkSVGNode> { return SkSVGDefs::Make();
}}, | 289 { "defs" , []() -> sk_sp<SkSVGNode> { return SkSVGDefs::Make();
}}, |
277 { "ellipse" , []() -> sk_sp<SkSVGNode> { return SkSVGEllipse::Make();
}}, | 290 { "ellipse" , []() -> sk_sp<SkSVGNode> { return SkSVGEllipse::Make();
}}, |
278 { "g" , []() -> sk_sp<SkSVGNode> { return SkSVGG::Make();
}}, | 291 { "g" , []() -> sk_sp<SkSVGNode> { return SkSVGG::Make();
}}, |
279 { "line" , []() -> sk_sp<SkSVGNode> { return SkSVGLine::Make();
}}, | 292 { "line" , []() -> sk_sp<SkSVGNode> { return SkSVGLine::Make();
}}, |
280 { "linearGradient", []() -> sk_sp<SkSVGNode> { return SkSVGLinearGradient::M
ake(); }}, | 293 { "linearGradient", []() -> sk_sp<SkSVGNode> { return SkSVGLinearGradient::M
ake(); }}, |
281 { "path" , []() -> sk_sp<SkSVGNode> { return SkSVGPath::Make();
}}, | 294 { "path" , []() -> sk_sp<SkSVGNode> { return SkSVGPath::Make();
}}, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 } | 416 } |
404 | 417 |
405 void SkSVGDOM::setContainerSize(const SkSize& containerSize) { | 418 void SkSVGDOM::setContainerSize(const SkSize& containerSize) { |
406 // TODO: inval | 419 // TODO: inval |
407 fContainerSize = containerSize; | 420 fContainerSize = containerSize; |
408 } | 421 } |
409 | 422 |
410 void SkSVGDOM::setRoot(sk_sp<SkSVGNode> root) { | 423 void SkSVGDOM::setRoot(sk_sp<SkSVGNode> root) { |
411 fRoot = std::move(root); | 424 fRoot = std::move(root); |
412 } | 425 } |
OLD | NEW |