Viewer SVG support
Change-Id: I93ee61271ebe960063bec16ba472b3fd243ee149 Reviewed-on: https://skia-review.googlesource.com/118885 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
parent
1861e88cad
commit
c659c2c30d
4
BUILD.gn
4
BUILD.gn
@ -1693,7 +1693,7 @@ if (skia_enable_tools) {
|
||||
deps = [
|
||||
":flags",
|
||||
":skia",
|
||||
":tool_utils"
|
||||
":tool_utils",
|
||||
]
|
||||
}
|
||||
|
||||
@ -2014,6 +2014,7 @@ if (skia_enable_tools) {
|
||||
"tools/viewer/SkottieSlide.cpp",
|
||||
"tools/viewer/SlideDir.cpp",
|
||||
"tools/viewer/StatsLayer.cpp",
|
||||
"tools/viewer/SvgSlide.cpp",
|
||||
"tools/viewer/Viewer.cpp",
|
||||
]
|
||||
libs = []
|
||||
@ -2022,6 +2023,7 @@ if (skia_enable_tools) {
|
||||
deps = [
|
||||
":experimental_skottie",
|
||||
":experimental_sksg",
|
||||
":experimental_svg_model",
|
||||
":flags",
|
||||
":gm",
|
||||
":gpu_tool_utils",
|
||||
|
43
tools/viewer/SvgSlide.cpp
Normal file
43
tools/viewer/SvgSlide.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2018 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SvgSlide.h"
|
||||
|
||||
#include "SkCanvas.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkSVGDOM.h"
|
||||
|
||||
SvgSlide::SvgSlide(const SkString& name, const SkString& path)
|
||||
: fPath(path) {
|
||||
fName = name;
|
||||
}
|
||||
|
||||
void SvgSlide::load(SkScalar w, SkScalar h) {
|
||||
fWinSize = SkSize::Make(w, h);
|
||||
|
||||
if (const auto svgStream = SkStream::MakeFromFile(fPath.c_str())) {
|
||||
fDom = SkSVGDOM::MakeFromStream(*svgStream);
|
||||
if (fDom) {
|
||||
fDom->setContainerSize(fWinSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SvgSlide::unload() {
|
||||
fDom.reset();
|
||||
}
|
||||
|
||||
SkISize SvgSlide::getDimensions() const {
|
||||
// We always scale to fill the window.
|
||||
return fWinSize.toCeil();
|
||||
}
|
||||
|
||||
void SvgSlide::draw(SkCanvas* canvas) {
|
||||
if (fDom) {
|
||||
fDom->render(canvas);
|
||||
}
|
||||
}
|
34
tools/viewer/SvgSlide.h
Normal file
34
tools/viewer/SvgSlide.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2018 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SvgSlide_DEFINED
|
||||
#define SvgSlide_DEFINED
|
||||
|
||||
#include "Slide.h"
|
||||
|
||||
class SkSVGDOM;
|
||||
|
||||
class SvgSlide final : public Slide {
|
||||
public:
|
||||
SvgSlide(const SkString& name, const SkString& path);
|
||||
|
||||
void load(SkScalar winWidth, SkScalar winHeight) override;
|
||||
void unload() override;
|
||||
|
||||
SkISize getDimensions() const override;
|
||||
|
||||
void draw(SkCanvas*) override;
|
||||
private:
|
||||
const SkString fPath;
|
||||
|
||||
SkSize fWinSize = SkSize::MakeEmpty();
|
||||
sk_sp<SkSVGDOM> fDom;
|
||||
|
||||
typedef Slide INHERITED;
|
||||
};
|
||||
|
||||
#endif // SvgSlide_DEFINED
|
@ -15,6 +15,7 @@
|
||||
#include "SkottieSlide.h"
|
||||
#include "SKPSlide.h"
|
||||
#include "SlideDir.h"
|
||||
#include "SvgSlide.h"
|
||||
|
||||
#include "GrContext.h"
|
||||
#include "SkCanvas.h"
|
||||
@ -577,6 +578,21 @@ void Viewer::initSlides() {
|
||||
std::move(dirSlides)));
|
||||
}
|
||||
}
|
||||
|
||||
// SVGs
|
||||
for (const auto& svg : FLAGS_svgs) {
|
||||
SkOSFile::Iter it(svg.c_str(), ".svg");
|
||||
|
||||
SkString svgName;
|
||||
while (it.next(&svgName)) {
|
||||
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, svgName.c_str())) {
|
||||
continue;
|
||||
}
|
||||
auto slide = sk_make_sp<SvgSlide>(svgName, SkOSPath::Join(svg.c_str(),
|
||||
svgName.c_str()));
|
||||
fSlides.push_back(std::move(slide));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user