1 /*
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 
10 #if defined(SK_XML)
11 
12 #include "SkCanvas.h"
13 #include "SkStream.h"
14 #include "SkSVGDOM.h"
15 
SvgSlide(const SkString & name,const SkString & path)16 SvgSlide::SvgSlide(const SkString& name, const SkString& path)
17     : fPath(path) {
18     fName = name;
19 }
20 
load(SkScalar w,SkScalar h)21 void 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 
unload()32 void SvgSlide::unload() {
33     fDom.reset();
34 }
35 
getDimensions() const36 SkISize SvgSlide::getDimensions() const {
37     // We always scale to fill the window.
38     return fWinSize.toCeil();
39 }
40 
draw(SkCanvas * canvas)41 void SvgSlide::draw(SkCanvas* canvas) {
42     if (fDom) {
43         fDom->render(canvas);
44     }
45 }
46 
47 #endif // SK_XML
48