Skip to content

Commit

Permalink
m92-f46c37ba85-2 Removed SkSVGDOM patch, added SkSVGDOM.getRoot API h…
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Jun 7, 2021
1 parent 530433b commit 04cf144
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
default: 'false'

env:
version: m92-f46c37ba85
version: m92-f46c37ba85-2

jobs:
macos:
Expand Down
66 changes: 37 additions & 29 deletions patches/11144_SkSVGDOM.patch
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
diff --git a/modules/svg/src/SkSVGDOM.cpp b/modules/svg/src/SkSVGDOM.cpp
index 7915654963..509c52548d 100644
--- a/modules/svg/src/SkSVGDOM.cpp
+++ b/modules/svg/src/SkSVGDOM.cpp
@@ -426,6 +426,15 @@ SkSVGDOM::SkSVGDOM(sk_sp<SkSVGSVG> root, sk_sp<SkFontMgr> fmgr,
, fContainerSize(fRoot->intrinsicSize(SkSVGLengthContext(SkSize::Make(0, 0))))
{
SkASSERT(fResourceProvider);
+ if (!fRoot->getViewBox().isValid()
+ && fRoot->getWidth().unit() != SkSVGLength::Unit::kPercentage
+ && fRoot->getHeight().unit() != SkSVGLength::Unit::kPercentage)
+ {
+ SkSVGLengthContext lctx(SkSize::Make(0, 0));
+ SkScalar width = lctx.resolve(fRoot->getWidth(), SkSVGLengthContext::LengthType::kHorizontal);
+ SkScalar height = lctx.resolve(fRoot->getHeight(), SkSVGLengthContext::LengthType::kVertical);
+ fRoot->setViewBox(SkRect::MakeWH(width, height));
+ }
}
diff --git a/modules/svg/include/SkSVGDOM.h b/modules/svg/include/SkSVGDOM.h
index c9e0b312dc..a9cc540e43 100644
--- a/modules/svg/include/SkSVGDOM.h
+++ b/modules/svg/include/SkSVGDOM.h
@@ -46,8 +46,33 @@ public:
return Builder().make(str);
}

void SkSVGDOM::render(SkCanvas* canvas) const {
@@ -444,6 +453,10 @@ const SkSize& SkSVGDOM::containerSize() const {
void SkSVGDOM::setContainerSize(const SkSize& containerSize) {
// TODO: inval
fContainerSize = containerSize;
+ if (fRoot) {
+ fRoot->setWidth(SkSVGLength(containerSize.fWidth));
+ fRoot->setHeight(SkSVGLength(containerSize.fHeight));
+ }
}
- const SkSize& containerSize() const;
+ /**
+ * Returns the root (outermost) SVG element.
+ */
+ SkSVGSVG* getRoot() const { return fRoot.get(); }
+ /**
+ * Specify a "container size" for the SVG dom.
+ *
+ * This is used to resolve the initial viewport when the root SVG width/height are specified
+ * in relative units.
+ *
+ * If the root dimensions are in absolute units, then the container size has no effect since
+ * the initial viewport is fixed.
+ */
void setContainerSize(const SkSize&);
+ /**
+ * DEPRECATED: use getRoot()->intrinsicSize() to query the root element intrinsic size.
+ *
+ * Returns the SVG dom container size.
+ *
+ * If the client specified a container size via setContainerSize(), then the same size is
+ * returned.
+ *
+ * When unspecified by clients, this returns the intrinsic size of the root element, as defined
+ * by its width/height attributes. If either width or height is specified in relative units
+ * (e.g. "100%"), then the corresponding intrinsic size dimension is zero.
+ */
+ const SkSize& containerSize() const;

sk_sp<SkSVGNode>* SkSVGDOM::findNodeById(const char* id) {
// Returns the node with the given id, or nullptr if not found.
sk_sp<SkSVGNode>* findNodeById(const char* id);

0 comments on commit 04cf144

Please sign in to comment.