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

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

Issue 2345533002: [SVGDom] Expose intrinsic size info (Closed)
Patch Set: private intrinsicSize() Created 4 years, 3 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/SkSVGDOM.h ('k') | experimental/svg/model/SkSVGSVG.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"
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 if (childNode) { 377 if (childNode) {
378 node->appendChild(std::move(childNode)); 378 node->appendChild(std::move(childNode));
379 } 379 }
380 } 380 }
381 381
382 return node; 382 return node;
383 } 383 }
384 384
385 } // anonymous namespace 385 } // anonymous namespace
386 386
387 SkSVGDOM::SkSVGDOM(const SkSize& containerSize) 387 SkSVGDOM::SkSVGDOM()
388 : fContainerSize(containerSize) { 388 : fContainerSize(SkSize::Make(0, 0)) {
389 } 389 }
390 390
391 sk_sp<SkSVGDOM> SkSVGDOM::MakeFromDOM(const SkDOM& xmlDom, const SkSize& contain erSize) { 391 sk_sp<SkSVGDOM> SkSVGDOM::MakeFromDOM(const SkDOM& xmlDom) {
392 sk_sp<SkSVGDOM> dom = sk_make_sp<SkSVGDOM>(containerSize); 392 sk_sp<SkSVGDOM> dom = sk_make_sp<SkSVGDOM>();
393 393
394 ConstructionContext ctx(&dom->fIDMapper); 394 ConstructionContext ctx(&dom->fIDMapper);
395 dom->fRoot = construct_svg_node(xmlDom, ctx, xmlDom.getRootNode()); 395 dom->fRoot = construct_svg_node(xmlDom, ctx, xmlDom.getRootNode());
396 396
397 // Reset the default container size to match the intrinsic SVG size.
398 dom->setContainerSize(dom->intrinsicSize());
399
397 return dom; 400 return dom;
398 } 401 }
399 402
400 sk_sp<SkSVGDOM> SkSVGDOM::MakeFromStream(SkStream& svgStream, const SkSize& cont ainerSize) { 403 sk_sp<SkSVGDOM> SkSVGDOM::MakeFromStream(SkStream& svgStream) {
401 SkDOM xmlDom; 404 SkDOM xmlDom;
402 if (!xmlDom.build(svgStream)) { 405 if (!xmlDom.build(svgStream)) {
403 return nullptr; 406 return nullptr;
404 } 407 }
405 408
406 return MakeFromDOM(xmlDom, containerSize); 409 return MakeFromDOM(xmlDom);
407 } 410 }
408 411
409 void SkSVGDOM::render(SkCanvas* canvas) const { 412 void SkSVGDOM::render(SkCanvas* canvas) const {
410 if (fRoot) { 413 if (fRoot) {
411 SkSVGRenderContext ctx(canvas, 414 SkSVGRenderContext ctx(canvas,
412 fIDMapper, 415 fIDMapper,
413 SkSVGLengthContext(fContainerSize), 416 SkSVGLengthContext(fContainerSize),
414 SkSVGPresentationContext()); 417 SkSVGPresentationContext());
415 fRoot->render(ctx); 418 fRoot->render(ctx);
416 } 419 }
417 } 420 }
418 421
422 SkSize SkSVGDOM::intrinsicSize() const {
423 if (!fRoot || fRoot->tag() != SkSVGTag::kSvg) {
424 return SkSize::Make(0, 0);
425 }
426
427 // Intrinsic sizes are never relative, so the viewport size is irrelevant.
428 const SkSVGLengthContext lctx(SkSize::Make(0, 0));
429 return static_cast<const SkSVGSVG*>(fRoot.get())->intrinsicSize(lctx);
430 }
431
432 const SkSize& SkSVGDOM::containerSize() const {
433 return fContainerSize;
434 }
435
419 void SkSVGDOM::setContainerSize(const SkSize& containerSize) { 436 void SkSVGDOM::setContainerSize(const SkSize& containerSize) {
420 // TODO: inval 437 // TODO: inval
421 fContainerSize = containerSize; 438 fContainerSize = containerSize;
422 } 439 }
423 440
424 void SkSVGDOM::setRoot(sk_sp<SkSVGNode> root) { 441 void SkSVGDOM::setRoot(sk_sp<SkSVGNode> root) {
425 fRoot = std::move(root); 442 fRoot = std::move(root);
426 } 443 }
OLDNEW
« no previous file with comments | « experimental/svg/model/SkSVGDOM.h ('k') | experimental/svg/model/SkSVGSVG.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698