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

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

Issue 2222793002: [SVGDom] Add <svg> viewBox support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: typo 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/SkSVGContainer.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 "SkParse.h" 10 #include "SkParse.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 if (str) { 66 if (str) {
67 m.setRotate(value); 67 m.setRotate(value);
68 } 68 }
69 } 69 }
70 70
71 return m; 71 return m;
72 } 72 }
73 73
74 bool SetPaintAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, 74 bool SetPaintAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
75 const char* stringValue) { 75 const char* stringValue) {
76 SkSVGColor color; 76 SkSVGColorType color;
77 SkSVGAttributeParser parser(stringValue); 77 SkSVGAttributeParser parser(stringValue);
78 if (!parser.parseColor(&color)) { 78 if (!parser.parseColor(&color)) {
79 return false; 79 return false;
80 } 80 }
81 81
82 node->setAttribute(attr, SkSVGColorValue(color)); 82 node->setAttribute(attr, SkSVGColorValue(color));
83 return true; 83 return true;
84 } 84 }
85 85
86 bool SetPathDataAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, 86 bool SetPathDataAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
(...skipping 18 matching lines...) Expand all
105 SkSVGLength length; 105 SkSVGLength length;
106 SkSVGAttributeParser parser(stringValue); 106 SkSVGAttributeParser parser(stringValue);
107 if (!parser.parseLength(&length)) { 107 if (!parser.parseLength(&length)) {
108 return false; 108 return false;
109 } 109 }
110 110
111 node->setAttribute(attr, SkSVGLengthValue(length)); 111 node->setAttribute(attr, SkSVGLengthValue(length));
112 return true; 112 return true;
113 } 113 }
114 114
115 bool SetViewBoxAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
116 const char* stringValue) {
117 SkSVGViewBoxType viewBox;
118 SkSVGAttributeParser parser(stringValue);
119 if (!parser.parseViewBox(&viewBox)) {
120 return false;
121 }
122
123 node->setAttribute(attr, SkSVGViewBoxValue(viewBox));
124 return true;
125 }
126
115 // Breaks a "foo: bar; baz: ..." string into key:value pairs. 127 // Breaks a "foo: bar; baz: ..." string into key:value pairs.
116 class StyleIterator { 128 class StyleIterator {
117 public: 129 public:
118 StyleIterator(const char* str) : fPos(str) { } 130 StyleIterator(const char* str) : fPos(str) { }
119 131
120 std::tuple<SkString, SkString> next() { 132 std::tuple<SkString, SkString> next() {
121 SkString name, value; 133 SkString name, value;
122 134
123 if (fPos) { 135 if (fPos) {
124 const char* sep = this->nextSeparator(); 136 const char* sep = this->nextSeparator();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 bool (*fSetter)(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, const cha r* stringValue); 189 bool (*fSetter)(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, const cha r* stringValue);
178 }; 190 };
179 191
180 SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = { 192 SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = {
181 { "d" , { SkSVGAttribute::kD , SetPathDataAttribute }}, 193 { "d" , { SkSVGAttribute::kD , SetPathDataAttribute }},
182 { "fill" , { SkSVGAttribute::kFill , SetPaintAttribute }}, 194 { "fill" , { SkSVGAttribute::kFill , SetPaintAttribute }},
183 { "height" , { SkSVGAttribute::kHeight , SetLengthAttribute }}, 195 { "height" , { SkSVGAttribute::kHeight , SetLengthAttribute }},
184 { "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }}, 196 { "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }},
185 { "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes }}, 197 { "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes }},
186 { "transform", { SkSVGAttribute::kTransform, SetTransformAttribute }}, 198 { "transform", { SkSVGAttribute::kTransform, SetTransformAttribute }},
199 { "viewBox" , { SkSVGAttribute::kViewBox , SetViewBoxAttribute }},
187 { "width" , { SkSVGAttribute::kWidth , SetLengthAttribute }}, 200 { "width" , { SkSVGAttribute::kWidth , SetLengthAttribute }},
188 { "x" , { SkSVGAttribute::kX , SetLengthAttribute }}, 201 { "x" , { SkSVGAttribute::kX , SetLengthAttribute }},
189 { "y" , { SkSVGAttribute::kY , SetLengthAttribute }}, 202 { "y" , { SkSVGAttribute::kY , SetLengthAttribute }},
190 }; 203 };
191 204
192 SortedDictionaryEntry<sk_sp<SkSVGNode>(*)()> gTagFactories[] = { 205 SortedDictionaryEntry<sk_sp<SkSVGNode>(*)()> gTagFactories[] = {
193 { "g" , []() -> sk_sp<SkSVGNode> { return SkSVGG::Make(); }}, 206 { "g" , []() -> sk_sp<SkSVGNode> { return SkSVGG::Make(); }},
194 { "path", []() -> sk_sp<SkSVGNode> { return SkSVGPath::Make(); }}, 207 { "path", []() -> sk_sp<SkSVGNode> { return SkSVGPath::Make(); }},
195 { "rect", []() -> sk_sp<SkSVGNode> { return SkSVGRect::Make(); }}, 208 { "rect", []() -> sk_sp<SkSVGNode> { return SkSVGRect::Make(); }},
196 { "svg" , []() -> sk_sp<SkSVGNode> { return SkSVGSVG::Make(); }}, 209 { "svg" , []() -> sk_sp<SkSVGNode> { return SkSVGSVG::Make(); }},
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 SkDOM xmlDom; 298 SkDOM xmlDom;
286 if (!xmlDom.build(svgStream)) { 299 if (!xmlDom.build(svgStream)) {
287 return nullptr; 300 return nullptr;
288 } 301 }
289 302
290 return MakeFromDOM(xmlDom, containerSize); 303 return MakeFromDOM(xmlDom, containerSize);
291 } 304 }
292 305
293 void SkSVGDOM::render(SkCanvas* canvas) const { 306 void SkSVGDOM::render(SkCanvas* canvas) const {
294 if (fRoot) { 307 if (fRoot) {
295 SkSVGRenderContext ctx(fContainerSize); 308 SkSVGRenderContext ctx(canvas,
296 fRoot->render(canvas, ctx); 309 SkSVGLengthContext(fContainerSize),
310 SkSVGPresentationContext());
311 fRoot->render(ctx);
297 } 312 }
298 } 313 }
299 314
300 void SkSVGDOM::setContainerSize(const SkSize& containerSize) { 315 void SkSVGDOM::setContainerSize(const SkSize& containerSize) {
301 // TODO: inval 316 // TODO: inval
302 fContainerSize = containerSize; 317 fContainerSize = containerSize;
303 } 318 }
OLDNEW
« no previous file with comments | « experimental/svg/model/SkSVGContainer.cpp ('k') | experimental/svg/model/SkSVGNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698