From: Magnus Jacobsson Date: Wed, 27 Jul 2022 10:40:42 +0000 (+0200) Subject: tests: SvgAnalyzer: add handling of the 'transform' attribute X-Git-Tag: 5.0.1~7^2~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4ce417bda5af7c8b39f46b5f21e342c8b859836b;p=graphviz tests: SvgAnalyzer: add handling of the 'transform' attribute --- diff --git a/tests/svg_analyzer.cpp b/tests/svg_analyzer.cpp index cd1e88a99..339a88d01 100644 --- a/tests/svg_analyzer.cpp +++ b/tests/svg_analyzer.cpp @@ -147,6 +147,11 @@ void SVGAnalyzer::set_width(double width) { 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}; } diff --git a/tests/svg_analyzer.h b/tests/svg_analyzer.h index 26c6bd633..5a2e77770 100644 --- a/tests/svg_analyzer.h +++ b/tests/svg_analyzer.h @@ -31,6 +31,8 @@ public: 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; }; diff --git a/tests/svg_analyzer_interface.h b/tests/svg_analyzer_interface.h index 48a10f2c4..d2091a231 100644 --- a/tests/svg_analyzer_interface.h +++ b/tests/svg_analyzer_interface.h @@ -30,6 +30,8 @@ public: 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; }; diff --git a/tests/svg_element.cpp b/tests/svg_element.cpp index 2a50161c5..35768d83a 100644 --- a/tests/svg_element.cpp +++ b/tests/svg_element.cpp @@ -97,6 +97,12 @@ void SVG::SVGElement::to_string_impl(std::string &output, 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 diff --git a/tests/svg_element.h b/tests/svg_element.h index e910a7cb1..8b8d6cc45 100644 --- a/tests/svg_element.h +++ b/tests/svg_element.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -14,6 +15,15 @@ struct SVGRect { double height; }; +struct SVGMatrix { + double a; + double b; + double c; + double d; + double e; + double f; +}; + enum class SVGElementType { Circle, Ellipse, @@ -34,6 +44,7 @@ struct SVGAttributes { std::string class_; double height; std::string id; + std::optional transform; SVGRect viewBox; double width; }; diff --git a/tests/svgpp_context.cpp b/tests/svgpp_context.cpp index 24d33c394..b8a14853f 100644 --- a/tests/svgpp_context.cpp +++ b/tests/svgpp_context.cpp @@ -1,5 +1,7 @@ #include +#include + #include "svg_analyzer_interface.h" #include "svgpp_context.h" @@ -117,6 +119,16 @@ void SvgppContext::set(svgpp::tag::attribute::cx a, const double v) { (void)v; } +void SvgppContext::transform_matrix(const boost::array &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; diff --git a/tests/svgpp_context.h b/tests/svgpp_context.h index ec9a5b68b..8c0568b09 100644 --- a/tests/svgpp_context.h +++ b/tests/svgpp_context.h @@ -48,6 +48,7 @@ public: 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 &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); diff --git a/tests/svgpp_document_traverser.cpp b/tests/svgpp_document_traverser.cpp index ad63276c1..19133e7bc 100644 --- a/tests/svgpp_document_traverser.cpp +++ b/tests/svgpp_document_traverser.cpp @@ -26,11 +26,12 @@ void traverseDocumentWithSvgpp(SvgppContext &context, char *text) { using processed_attributes_t = boost::mpl::set::type; svgpp::document_traversal< diff --git a/tests/test_svg_analyzer.cpp b/tests/test_svg_analyzer.cpp index 786681f62..3fe9749f4 100644 --- a/tests/test_svg_analyzer.cpp +++ b/tests/test_svg_analyzer.cpp @@ -123,9 +123,9 @@ TEST_CASE( 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] == "") { + if (recreated_svg_lines[i] == "") { // 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]); @@ -133,15 +133,6 @@ TEST_CASE( // do some sanity checks of the parts of the recreated SVG that we cannot // yet compare with the original SVG - CHECK(recreated_svg.find("") != - std::string::npos); - CHECK(recreated_svg.find("") != - std::string::npos); - CHECK(recreated_svg.find("") != - std::string::npos); - CHECK(recreated_svg.find("") != - std::string::npos); - CHECK(recreated_svg.find("") != std::string::npos); CHECK(recreated_svg.find("g1") != std::string::npos); CHECK(recreated_svg.find("a") != std::string::npos); CHECK(recreated_svg.find("b") != std::string::npos);