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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
OLD | NEW |