blob: 3779ffd3f7fd5722e7d6eb73ca248529adb3a7b6 [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)
17 : fPath(path) {
18 fName = name;
19}
20
21void SvgSlide::load(SkScalar w, SkScalar h) {
22 fWinSize = SkSize::Make(w, h);
23
24 if (const auto svgStream = SkStream::MakeFromFile(fPath.c_str())) {
25 fDom = SkSVGDOM::MakeFromStream(*svgStream);
26 if (fDom) {
27 fDom->setContainerSize(fWinSize);
28 }
29 }
30}
31
32void SvgSlide::unload() {
33 fDom.reset();
34}
35
Florin Malitad532bdb2020-04-08 21:12:10 -040036void SvgSlide::resize(SkScalar w, SkScalar h) {
37 fWinSize = { w, h };
38 if (fDom) {
39 fDom->setContainerSize(fWinSize);
40 }
41}
42
Florin Malitac659c2c2018-04-05 11:57:21 -040043SkISize SvgSlide::getDimensions() const {
44 // We always scale to fill the window.
45 return fWinSize.toCeil();
46}
47
48void SvgSlide::draw(SkCanvas* canvas) {
49 if (fDom) {
50 fDom->render(canvas);
51 }
52}
Florin Malita5d3ff432018-07-31 16:38:43 -040053
54#endif // SK_XML