tvgSvgLoader.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2020 - 2023 the ThorVG project. All rights reserved.
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. * The above copyright notice and this permission notice shall be included in all
  10. * copies or substantial portions of the Software.
  11. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. * SOFTWARE.
  18. */
  19. #ifndef _TVG_SVG_LOADER_H_
  20. #define _TVG_SVG_LOADER_H_
  21. #include "tvgTaskScheduler.h"
  22. #include "tvgSvgLoaderCommon.h"
  23. class SvgLoader : public LoadModule, public Task
  24. {
  25. public:
  26. string filePath;
  27. string svgPath = "";
  28. const char* content = nullptr;
  29. uint32_t size = 0;
  30. SvgLoaderData loaderData;
  31. unique_ptr<Scene> root;
  32. bool copy = false;
  33. SvgLoader();
  34. ~SvgLoader();
  35. using LoadModule::open;
  36. bool open(const string& path) override;
  37. bool open(const char* data, uint32_t size, bool copy) override;
  38. bool resize(Paint* paint, float w, float h) override;
  39. bool read() override;
  40. bool close() override;
  41. unique_ptr<Paint> paint() override;
  42. private:
  43. SvgViewFlag viewFlag = SvgViewFlag::None;
  44. AspectRatioAlign align = AspectRatioAlign::XMidYMid;
  45. AspectRatioMeetOrSlice meetOrSlice = AspectRatioMeetOrSlice::Meet;
  46. float vx = 0;
  47. float vy = 0;
  48. float vw = 0;
  49. float vh = 0;
  50. bool header();
  51. void clear(bool all = true);
  52. void run(unsigned tid) override;
  53. };
  54. #endif //_TVG_SVG_LOADER_H_