2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SampleCode.h"
19 class SVGFileView : public SampleView {
21 SVGFileView(const SkString& path)
22 : fPath(path), fLabel(SkStringPrintf("[%s]", SkOSPath::Basename(path.c_str()).c_str())) {}
23 ~SVGFileView() override = default;
26 void onOnceBeforeDraw() override {
27 SkFILEStream svgStream(fPath.c_str());
28 if (!svgStream.isValid()) {
29 SkDebugf("file not found: \"path\"\n", fPath.c_str());
34 if (!xmlDom.build(svgStream)) {
35 SkDebugf("XML parsing failed: \"path\"\n", fPath.c_str());
39 fDom = SkSVGDOM::MakeFromDOM(xmlDom);
41 fDom->setContainerSize(SkSize::Make(this->width(), this->height()));
45 void onDrawContent(SkCanvas* canvas) override {
51 void onSizeChange() override {
53 fDom->setContainerSize(SkSize::Make(this->width(), this->height()));
56 this->INHERITED::onSizeChange();
59 bool onQuery(SkEvent* evt) override {
60 if (SampleCode::TitleQ(*evt)) {
61 SampleCode::TitleR(evt, fLabel.c_str());
65 return this->INHERITED::onQuery(evt);
72 typedef SampleView INHERITED;
75 } // anonymous namespace
77 SampleView* CreateSampleSVGFileView(const SkString& filename);
78 SampleView* CreateSampleSVGFileView(const SkString& filename) {
79 return new SVGFileView(filename);