diff options
| author | fmalita <fmalita@chromium.org> | 2016-07-26 18:46:34 -0700 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-07-26 18:46:34 -0700 |
| commit | 6ceef3dd67617c5f4572ada98d5ee85777d2db99 (patch) | |
| tree | 80d683062d7bba05f8fe4df14cedcb489dd4aa00 /samplecode/SampleSVGFile.cpp | |
| parent | fc49d56feb2d890ccb3827ed087ab32e18a9da12 (diff) | |
Initial SVG model
A minimal subset needed to render tiger.svg: <svg>, <g>, <path>, 'd', 'fill'/'stroke' (color-only), 'transform'.
R=reed@google.com,robertphillips@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2164193002
Review-Url: https://codereview.chromium.org/2164193002
Diffstat (limited to 'samplecode/SampleSVGFile.cpp')
| -rw-r--r-- | samplecode/SampleSVGFile.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/samplecode/SampleSVGFile.cpp b/samplecode/SampleSVGFile.cpp new file mode 100644 index 0000000000..01a1958f11 --- /dev/null +++ b/samplecode/SampleSVGFile.cpp @@ -0,0 +1,63 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SampleCode.h" +#include "SkCanvas.h" +#include "SkDOM.h" +#include "SkStream.h" +#include "SkSVGDOM.h" +#include "SkView.h" + +namespace { + +class SVGFileView : public SampleView { +public: + SVGFileView(const char path[]) { + SkFILEStream svgStream(path); + if (!svgStream.isValid()) { + SkDebugf("file not found: \"path\"\n", path); + return; + } + + SkDOM xmlDom; + if (!xmlDom.build(svgStream)) { + SkDebugf("XML parsing failed: \"path\"\n", path); + return; + } + + fDom = SkSVGDOM::MakeFromDOM(xmlDom, SkSize::Make(this->width(), this->height())); + } + + virtual ~SVGFileView() = default; + +protected: + void onDrawContent(SkCanvas* canvas) override { + if (fDom) { + fDom->render(canvas); + } + } + + void onSizeChange() override { + if (fDom) { + fDom->setContainerSize(SkSize::Make(this->width(), this->height())); + } + + this->INHERITED::onSizeChange(); + } + +private: + sk_sp<SkSVGDOM> fDom; + + typedef SampleView INHERITED; +}; + +} // anonymous namespace + +SampleView* CreateSampleSVGFileView(const char filename[]); +SampleView* CreateSampleSVGFileView(const char filename[]) { + return new SVGFileView(filename); +} |
