c0bd9f9fe5
Current strategy: everything from the top Things to look at first are the manual changes: - added tools/rewrite_includes.py - removed -Idirectives from BUILD.gn - various compile.sh simplifications - tweak tools/embed_resources.py - update gn/find_headers.py to write paths from the top - update gn/gn_to_bp.py SkUserConfig.h layout so that #include "include/config/SkUserConfig.h" always gets the header we want. No-Presubmit: true Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706 Commit-Queue: Mike Klein <mtklein@google.com> Reviewed-by: Hal Canary <halcanary@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
85 lines
2.0 KiB
C++
85 lines
2.0 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();
|
|
}
|
|
|
|
bool onQuery(Sample::Event* evt) override {
|
|
if (Sample::TitleQ(*evt)) {
|
|
Sample::TitleR(evt, fLabel.c_str());
|
|
return true;
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
}
|
|
private:
|
|
sk_sp<SkSVGDOM> fDom;
|
|
SkString fPath;
|
|
SkString fLabel;
|
|
|
|
typedef Sample INHERITED;
|
|
};
|
|
|
|
} // anonymous namespace
|
|
|
|
Sample* CreateSampleSVGFileView(const SkString& filename);
|
|
Sample* CreateSampleSVGFileView(const SkString& filename) {
|
|
return new SVGFileView(filename);
|
|
}
|
|
#endif // SK_XML
|