current_element().attributes.width = width;
}
+void SVGAnalyzer::set_transform(double a, double b, double c, double d,
+ double e, double f) {
+ current_element().attributes.transform = {a, b, c, d, e, f};
+}
+
void SVGAnalyzer::set_viewBox(double x, double y, double width, double height) {
current_element().attributes.viewBox = {x, y, width, height};
}
void set_id(std::string_view id) override;
void set_class(std::string_view) override;
void set_text(std::string_view text) override;
+ void set_transform(double a, double b, double c, double d, double e,
+ double f) override;
void set_viewBox(double x, double y, double width, double height) override;
void set_width(double width) override;
std::size_t num_svgs() const { return m_num_svgs; };
virtual void set_height(double height) = 0;
virtual void set_id(std::string_view id) = 0;
virtual void set_text(std::string_view text) = 0;
+ virtual void set_transform(double a, double b, double c, double d, double e,
+ double f) = 0;
virtual void set_viewBox(double x, double y, double width, double height) = 0;
virtual void set_width(double width) = 0;
};
break;
case SVG::SVGElementType::Group:
attributes_str += fmt::format(R"( class="{}")", attributes.class_);
+ if (attributes.transform.has_value()) {
+ const auto transform = attributes.transform;
+ attributes_str += fmt::format(
+ R"|( transform="scale({} {}) rotate({}) translate({} {})")|",
+ transform->a, transform->d, transform->c, transform->e, transform->f);
+ }
break;
case SVG::SVGElementType::Path:
// ignore for now
#pragma once
#include <cmath>
+#include <optional>
#include <string>
#include <string_view>
#include <vector>
double height;
};
+struct SVGMatrix {
+ double a;
+ double b;
+ double c;
+ double d;
+ double e;
+ double f;
+};
+
enum class SVGElementType {
Circle,
Ellipse,
std::string class_;
double height;
std::string id;
+ std::optional<SVGMatrix> transform;
SVGRect viewBox;
double width;
};
#include <any>
+#include <boost/array.hpp>
+
#include "svg_analyzer_interface.h"
#include "svgpp_context.h"
(void)v;
}
+void SvgppContext::transform_matrix(const boost::array<double, 6> &matrix) {
+ double a = matrix.at(0);
+ double b = matrix.at(1);
+ double c = matrix.at(2);
+ double d = matrix.at(3);
+ double e = matrix.at(4);
+ double f = matrix.at(5);
+ m_svgAnalyzer->set_transform(a, b, c, d, e, f);
+}
+
void SvgppContext::set(svgpp::tag::attribute::r a, const double v) {
(void)a;
(void)v;
void path_exit();
void set(svgpp::tag::attribute::cy cy, double v);
void set(svgpp::tag::attribute::cx cx, double v);
+ void transform_matrix(const boost::array<double, 6> &matrix);
void set(svgpp::tag::attribute::r r, double v);
void set(svgpp::tag::attribute::rx rx, double v);
void set(svgpp::tag::attribute::ry ry, double v);
using processed_attributes_t =
boost::mpl::set<svgpp::traits::shapes_attributes_by_element,
- svgpp::tag::attribute::class_, //
- svgpp::tag::attribute::height, //
- svgpp::tag::attribute::id, //
- svgpp::tag::attribute::viewBox, //
- svgpp::tag::attribute::width //
+ svgpp::tag::attribute::class_, //
+ svgpp::tag::attribute::height, //
+ svgpp::tag::attribute::id, //
+ svgpp::tag::attribute::transform, //
+ svgpp::tag::attribute::viewBox, //
+ svgpp::tag::attribute::width //
>::type;
svgpp::document_traversal<
boost::split(recreated_svg_lines, recreated_svg, boost::is_any_of("\n"));
for (std::size_t i = 0; i < original_svg_lines.size(); i++) {
REQUIRE(i < recreated_svg_lines.size());
- if (recreated_svg_lines[i] == "<g id=\"graph0\" class=\"graph\">") {
+ if (recreated_svg_lines[i] == "<polygon/>") {
// stop comparison here since we do not yet handle all attributes on the
- // 'g' element
+ // 'polygon' element
break;
}
REQUIRE(recreated_svg_lines[i] == original_svg_lines[i]);
// do some sanity checks of the parts of the recreated SVG that we cannot
// yet compare with the original SVG
- CHECK(recreated_svg.find("<g id=\"graph0\" class=\"graph\">") !=
- std::string::npos);
- CHECK(recreated_svg.find("<g id=\"node1\" class=\"node\">") !=
- std::string::npos);
- CHECK(recreated_svg.find("<g id=\"node2\" class=\"node\">") !=
- std::string::npos);
- CHECK(recreated_svg.find("<g id=\"edge1\" class=\"edge\">") !=
- std::string::npos);
- CHECK(recreated_svg.find("</g>") != std::string::npos);
CHECK(recreated_svg.find("<title>g1</title>") != std::string::npos);
CHECK(recreated_svg.find("<title>a</title>") != std::string::npos);
CHECK(recreated_svg.find("<title>b</title>") != std::string::npos);