Florin Malita | c659c2c | 2018-04-05 11:57:21 -0400 | [diff] [blame] | 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 | |
Florin Malita | 5d3ff43 | 2018-07-31 16:38:43 -0400 | [diff] [blame] | 10 | #if defined(SK_XML) |
| 11 | |
Florin Malita | c659c2c | 2018-04-05 11:57:21 -0400 | [diff] [blame] | 12 | #include "SkCanvas.h" |
| 13 | #include "SkStream.h" |
| 14 | #include "SkSVGDOM.h" |
| 15 | |
| 16 | SvgSlide::SvgSlide(const SkString& name, const SkString& path) |
| 17 | : fPath(path) { |
| 18 | fName = name; |
| 19 | } |
| 20 | |
| 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 | |
| 32 | void SvgSlide::unload() { |
| 33 | fDom.reset(); |
| 34 | } |
| 35 | |
| 36 | SkISize SvgSlide::getDimensions() const { |
| 37 | // We always scale to fill the window. |
| 38 | return fWinSize.toCeil(); |
| 39 | } |
| 40 | |
| 41 | void SvgSlide::draw(SkCanvas* canvas) { |
| 42 | if (fDom) { |
| 43 | fDom->render(canvas); |
| 44 | } |
| 45 | } |
Florin Malita | 5d3ff43 | 2018-07-31 16:38:43 -0400 | [diff] [blame] | 46 | |
| 47 | #endif // SK_XML |