skia2/samplecode/SampleSVGFile.cpp
John Stiles 7571f9e490 Replace 'typedef xxxxx INHERITED' with 'using INHERITED = xxxx;'.
Mechanically updated via Xcode "Replace Regular Expression":

  typedef (.*) INHERITED;
    -->
  using INHERITED = $1;

The ClangTidy approach generated an even larger CL which would have
required a significant amount of hand-tweaking to be usable.

Change-Id: I671dc9d9efdf6d60151325c8d4d13fad7e10a15b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314999
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-09-03 03:41:26 +00:00

79 lines
1.9 KiB
C++

/*
* 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 "include/core/SkTypes.h"
#ifdef SK_XML
#include "experimental/svg/model/SkSVGDOM.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkStream.h"
#include "samplecode/Sample.h"
#include "src/core/SkOSFile.h"
#include "src/utils/SkOSPath.h"
#include "src/xml/SkDOM.h"
namespace {
class SVGFileView : public Sample {
public:
SVGFileView(const SkString& path)
: fPath(path), fLabel(SkStringPrintf("[%s]", SkOSPath::Basename(path.c_str()).c_str())) {}
~SVGFileView() override = default;
protected:
void onOnceBeforeDraw() override {
SkFILEStream svgStream(fPath.c_str());
if (!svgStream.isValid()) {
SkDebugf("file not found: \"path\"\n", fPath.c_str());
return;
}
SkDOM xmlDom;
if (!xmlDom.build(svgStream)) {
SkDebugf("XML parsing failed: \"path\"\n", fPath.c_str());
return;
}
fDom = SkSVGDOM::MakeFromDOM(xmlDom);
if (fDom) {
fDom->setContainerSize(SkSize::Make(this->width(), this->height()));
}
}
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();
}
SkString name() override { return fLabel; }
private:
sk_sp<SkSVGDOM> fDom;
SkString fPath;
SkString fLabel;
using INHERITED = Sample;
};
} // anonymous namespace
Sample* CreateSampleSVGFileView(const SkString& filename);
Sample* CreateSampleSVGFileView(const SkString& filename) {
return new SVGFileView(filename);
}
#endif // SK_XML