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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/svg/model/SkSVGDOM.h ('k') | experimental/svg/model/SkSVGSVG.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/svg/model/SkSVGDOM.cpp
diff --git a/experimental/svg/model/SkSVGDOM.cpp b/experimental/svg/model/SkSVGDOM.cpp
index f467c5e6d0443d87263b5121957daf4c4c8fe4f1..c9745f1730d65c1c43447cdb05c30ebe5093e0d4 100644
--- a/experimental/svg/model/SkSVGDOM.cpp
+++ b/experimental/svg/model/SkSVGDOM.cpp
@@ -384,26 +384,29 @@ sk_sp<SkSVGNode> construct_svg_node(const SkDOM& dom, const ConstructionContext&
} // anonymous namespace
-SkSVGDOM::SkSVGDOM(const SkSize& containerSize)
- : fContainerSize(containerSize) {
+SkSVGDOM::SkSVGDOM()
+ : fContainerSize(SkSize::Make(0, 0)) {
}
-sk_sp<SkSVGDOM> SkSVGDOM::MakeFromDOM(const SkDOM& xmlDom, const SkSize& containerSize) {
- sk_sp<SkSVGDOM> dom = sk_make_sp<SkSVGDOM>(containerSize);
+sk_sp<SkSVGDOM> SkSVGDOM::MakeFromDOM(const SkDOM& xmlDom) {
+ sk_sp<SkSVGDOM> dom = sk_make_sp<SkSVGDOM>();
ConstructionContext ctx(&dom->fIDMapper);
dom->fRoot = construct_svg_node(xmlDom, ctx, xmlDom.getRootNode());
+ // Reset the default container size to match the intrinsic SVG size.
+ dom->setContainerSize(dom->intrinsicSize());
+
return dom;
}
-sk_sp<SkSVGDOM> SkSVGDOM::MakeFromStream(SkStream& svgStream, const SkSize& containerSize) {
+sk_sp<SkSVGDOM> SkSVGDOM::MakeFromStream(SkStream& svgStream) {
SkDOM xmlDom;
if (!xmlDom.build(svgStream)) {
return nullptr;
}
- return MakeFromDOM(xmlDom, containerSize);
+ return MakeFromDOM(xmlDom);
}
void SkSVGDOM::render(SkCanvas* canvas) const {
@@ -416,6 +419,20 @@ void SkSVGDOM::render(SkCanvas* canvas) const {
}
}
+SkSize SkSVGDOM::intrinsicSize() const {
+ if (!fRoot || fRoot->tag() != SkSVGTag::kSvg) {
+ return SkSize::Make(0, 0);
+ }
+
+ // Intrinsic sizes are never relative, so the viewport size is irrelevant.
+ const SkSVGLengthContext lctx(SkSize::Make(0, 0));
+ return static_cast<const SkSVGSVG*>(fRoot.get())->intrinsicSize(lctx);
+}
+
+const SkSize& SkSVGDOM::containerSize() const {
+ return fContainerSize;
+}
+
void SkSVGDOM::setContainerSize(const SkSize& containerSize) {
// TODO: inval
fContainerSize = containerSize;
« 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