transform.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* transform.cpp - SvgRenderer transform renderer
  2. * Copyright (C) 2017 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <fmt/format.h>
  18. #include <2geom/affine.h>
  19. #include <core/serialize/node_writer.h>
  20. #include "svg_module.h"
  21. using namespace fmt::literals;
  22. namespace rainynite::core::renderers {
  23. const string svg_matrix = R"svg(<g transform="{matrix_2x3}">{source}</g>)svg";
  24. class TransformSvgRenderer : SVG_RENDERER_MODULE_CLASS(TransformSvgRenderer) {
  25. SVG_RENDERER_MODULE_NAME("Transform");
  26. public:
  27. string operator()(AbstractNode const& node, shared_ptr<Context> ctx, SvgRendererSettings const& settings) const override {
  28. auto source = node.get_property("source");
  29. auto matrix = node.get_property_as<Geom::Affine>("transform")->value(ctx);
  30. return fmt::format(
  31. svg_matrix,
  32. "matrix_2x3"_a=serialize::value_to_string(matrix),
  33. "source"_a=node_to_svg({source, ctx}, settings)
  34. );
  35. }
  36. };
  37. } // namespace rainynite::core::renderers