blob: 01a1958f114ae6f62e74d847313e54ea38cf6b56 [file] [log] [blame]
fmalita6ceef3d2016-07-26 18:46:34 -07001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SampleCode.h"
9#include "SkCanvas.h"
10#include "SkDOM.h"
11#include "SkStream.h"
12#include "SkSVGDOM.h"
13#include "SkView.h"
14
15namespace {
16
17class SVGFileView : public SampleView {
18public:
19 SVGFileView(const char path[]) {
20 SkFILEStream svgStream(path);
21 if (!svgStream.isValid()) {
22 SkDebugf("file not found: \"path\"\n", path);
23 return;
24 }
25
26 SkDOM xmlDom;
27 if (!xmlDom.build(svgStream)) {
28 SkDebugf("XML parsing failed: \"path\"\n", path);
29 return;
30 }
31
32 fDom = SkSVGDOM::MakeFromDOM(xmlDom, SkSize::Make(this->width(), this->height()));
33 }
34
35 virtual ~SVGFileView() = default;
36
37protected:
38 void onDrawContent(SkCanvas* canvas) override {
39 if (fDom) {
40 fDom->render(canvas);
41 }
42 }
43
44 void onSizeChange() override {
45 if (fDom) {
46 fDom->setContainerSize(SkSize::Make(this->width(), this->height()));
47 }
48
49 this->INHERITED::onSizeChange();
50 }
51
52private:
53 sk_sp<SkSVGDOM> fDom;
54
55 typedef SampleView INHERITED;
56};
57
58} // anonymous namespace
59
60SampleView* CreateSampleSVGFileView(const char filename[]);
61SampleView* CreateSampleSVGFileView(const char filename[]) {
62 return new SVGFileView(filename);
63}