SvgSlide.cpp 994 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #include "tools/viewer/SvgSlide.h"
  8. #if defined(SK_XML)
  9. #include "experimental/svg/model/SkSVGDOM.h"
  10. #include "include/core/SkCanvas.h"
  11. #include "include/core/SkStream.h"
  12. SvgSlide::SvgSlide(const SkString& name, const SkString& path)
  13. : fPath(path) {
  14. fName = name;
  15. }
  16. void SvgSlide::load(SkScalar w, SkScalar h) {
  17. fWinSize = SkSize::Make(w, h);
  18. if (const auto svgStream = SkStream::MakeFromFile(fPath.c_str())) {
  19. fDom = SkSVGDOM::MakeFromStream(*svgStream);
  20. if (fDom) {
  21. fDom->setContainerSize(fWinSize);
  22. }
  23. }
  24. }
  25. void SvgSlide::unload() {
  26. fDom.reset();
  27. }
  28. SkISize SvgSlide::getDimensions() const {
  29. // We always scale to fill the window.
  30. return fWinSize.toCeil();
  31. }
  32. void SvgSlide::draw(SkCanvas* canvas) {
  33. if (fDom) {
  34. fDom->render(canvas);
  35. }
  36. }
  37. #endif // SK_XML