skia2/samplecode/SampleSVGFile.cpp
Robert Phillips 2af13c135b Reland "Fix compilation w/ "skia_enable_svg = false" (take 2)"
This reverts commit 44b7568c8a.

Reason for revert: Google 3 CL has landed

Original change's description:
> Revert "Fix compilation w/ "skia_enable_svg = false" (take 2)"
>
> This reverts commit 30a6b101f4.
>
> Reason for revert: Maybe blocking G3 roll?
>
> Original change's description:
> > Fix compilation w/ "skia_enable_svg = false" (take 2)
> >
> > Change-Id: I036ae171809af56cc9594704b44705ebd095ec80
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/443898
> > Reviewed-by: Florin Malita <fmalita@chromium.org>
> > Commit-Queue: Robert Phillips <robertphillips@google.com>
>
> TBR=robertphillips@google.com,fmalita@chromium.org,fmalita@google.com,skcq-be@skia-corp.google.com.iam.gserviceaccount.com
>
> Change-Id: Ibee3819e073b04efdf9736058c1f9b288249620c
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/444216
> Reviewed-by: Robert Phillips <robertphillips@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>

# Not skipping CQ checks because this is a reland.

Change-Id: Idf73d864108067ee1c34e88ee4e5236847abd582
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/444501
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2021-09-01 17:54:08 +00:00

74 lines
1.8 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"
#if defined(SK_ENABLE_SVG)
#include "include/core/SkCanvas.h"
#include "include/core/SkStream.h"
#include "modules/svg/include/SkSVGDOM.h"
#include "modules/svg/include/SkSVGNode.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: \"%s\"\n", fPath.c_str());
return;
}
fDom = SkSVGDOM::MakeFromStream(svgStream);
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 // defined(SK_ENABLE_SVG)