blob: 9ea9e4039501f380352507adf44a4bddddc6dec4 [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
8#include "SvgSlide.h"
9
Florin Malita5d3ff432018-07-31 16:38:43 -040010#if defined(SK_XML)
11
Florin Malitac659c2c2018-04-05 11:57:21 -040012#include "SkCanvas.h"
13#include "SkStream.h"
14#include "SkSVGDOM.h"
15
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
36SkISize SvgSlide::getDimensions() const {
37 // We always scale to fill the window.
38 return fWinSize.toCeil();
39}
40
41void SvgSlide::draw(SkCanvas* canvas) {
42 if (fDom) {
43 fDom->render(canvas);
44 }
45}
Florin Malita5d3ff432018-07-31 16:38:43 -040046
47#endif // SK_XML