}
};
-extern SampleView* CreateSampleSVGFileView(const char filename[]);
+extern SampleView* CreateSampleSVGFileView(const SkString& filename);
class SVGFileFactory : public SkViewFactory {
SkString fFilename;
public:
SVGFileFactory(const SkString& filename) : fFilename(filename) {}
SkView* operator() () const override {
- return CreateSampleSVGFileView(fFilename.c_str());
+ return CreateSampleSVGFileView(fFilename);
}
};
class SVGFileView : public SampleView {
public:
- SVGFileView(const char path[])
- : fLabel(SkStringPrintf("[%s]", SkOSPath::Basename(path).c_str())) {
- SkFILEStream svgStream(path);
+ SVGFileView(const SkString& path)
+ : fPath(path), fLabel(SkStringPrintf("[%s]", SkOSPath::Basename(path.c_str()).c_str())) {}
+ virtual ~SVGFileView() = default;
+
+protected:
+ void onOnceBeforeDraw() override {
+ SkFILEStream svgStream(fPath.c_str());
if (!svgStream.isValid()) {
- SkDebugf("file not found: \"path\"\n", path);
+ SkDebugf("file not found: \"path\"\n", fPath.c_str());
return;
}
SkDOM xmlDom;
if (!xmlDom.build(svgStream)) {
- SkDebugf("XML parsing failed: \"path\"\n", path);
+ SkDebugf("XML parsing failed: \"path\"\n", fPath.c_str());
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);
}
private:
sk_sp<SkSVGDOM> fDom;
+ SkString fPath;
SkString fLabel;
typedef SampleView INHERITED;
} // anonymous namespace
-SampleView* CreateSampleSVGFileView(const char filename[]);
-SampleView* CreateSampleSVGFileView(const char filename[]) {
+SampleView* CreateSampleSVGFileView(const SkString& filename);
+SampleView* CreateSampleSVGFileView(const SkString& filename) {
return new SVGFileView(filename);
}