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

Unified Diff: samplecode/SampleSVGFile.cpp

Issue 2164193002: Initial SVG model (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: warning fix Created 4 years, 5 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 | « samplecode/SampleApp.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleSVGFile.cpp
diff --git a/samplecode/SampleSVGFile.cpp b/samplecode/SampleSVGFile.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..01a1958f114ae6f62e74d847313e54ea38cf6b56
--- /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);
+}
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698