blob: c420843464c29292b3502f567623e691774b00b9 [file] [log] [blame]
Florin Malitac659c2c2018-04-05 11:57:21 -04001/*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "tools/viewer/SvgSlide.h"
Florin Malitac659c2c2018-04-05 11:57:21 -04009
Florin Malita5d3ff432018-07-31 16:38:43 -040010#if defined(SK_XML)
11
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "experimental/svg/model/SkSVGDOM.h"
13#include "include/core/SkCanvas.h"
14#include "include/core/SkStream.h"
Florin Malitac659c2c2018-04-05 11:57:21 -040015
16SvgSlide::SvgSlide(const SkString& name, const SkString& path)
Chris Dalton3e7d5112020-05-28 14:04:53 -060017 : SvgSlide(name, SkStream::MakeFromFile(path.c_str())) {
18}
19
20SvgSlide::SvgSlide(const SkString& name, std::unique_ptr<SkStream> stream)
21 : fStream(std::move(stream)) {
Florin Malitac659c2c2018-04-05 11:57:21 -040022 fName = name;
23}
24
25void SvgSlide::load(SkScalar w, SkScalar h) {
Chris Dalton3e7d5112020-05-28 14:04:53 -060026 if (!fStream) {
27 SkDebugf("No svg stream for slide %s.\n", fName.c_str());
28 return;
29 }
Florin Malitac659c2c2018-04-05 11:57:21 -040030
Chris Dalton3e7d5112020-05-28 14:04:53 -060031 fWinSize = SkSize::Make(w, h);
32
33 fStream->rewind();
34 fDom = SkSVGDOM::MakeFromStream(*fStream);
35 if (fDom) {
36 fDom->setContainerSize(fWinSize);
Florin Malitac659c2c2018-04-05 11:57:21 -040037 }
38}
39
40void SvgSlide::unload() {
41 fDom.reset();
42}
43
Florin Malitad532bdb2020-04-08 21:12:10 -040044void SvgSlide::resize(SkScalar w, SkScalar h) {
45 fWinSize = { w, h };
46 if (fDom) {
47 fDom->setContainerSize(fWinSize);
48 }
49}
50
Florin Malitac659c2c2018-04-05 11:57:21 -040051SkISize SvgSlide::getDimensions() const {
52 // We always scale to fill the window.
53 return fWinSize.toCeil();
54}
55
56void SvgSlide::draw(SkCanvas* canvas) {
57 if (fDom) {
58 fDom->render(canvas);
59 }
60}
Florin Malita5d3ff432018-07-31 16:38:43 -040061
62#endif // SK_XML