]> granicus.if.org Git - graphviz/commitdiff
tests: SvgAnalyzer: add handling of the 'rx' and 'ry' attributes
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Wed, 27 Jul 2022 20:07:08 +0000 (22:07 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 16 Aug 2022 10:21:45 +0000 (12:21 +0200)
tests/svg_analyzer.cpp
tests/svg_analyzer.h
tests/svg_analyzer_interface.h
tests/svg_element.cpp
tests/svg_element.h
tests/svgpp_context.cpp
tests/svgpp_document_traverser.cpp
tests/test_svg_analyzer.cpp

index b7ce39aac431cbe497049473bb66cb7c535e3fd4..aa47b67649267dca8f34b9f81531b511b7991fe1 100644 (file)
@@ -135,6 +135,10 @@ void SVGAnalyzer::set_id(std::string_view id) {
   current_element().attributes.id = id;
 }
 
+void SVGAnalyzer::set_rx(double rx) { current_element().attributes.rx = rx; }
+
+void SVGAnalyzer::set_ry(double ry) { current_element().attributes.ry = ry; }
+
 void SVGAnalyzer::set_point(std::pair<double, double> point) {
   current_element().attributes.points.emplace_back(point.first, point.second);
 }
index 499dcbdadf65c12283cf4b685ab6fe8aeb76cbee..9eff98df92ff8924f7ac7f2d48b2c1639a147b60 100644 (file)
@@ -32,6 +32,8 @@ public:
   void set_fill(std::string_view fill) override;
   void set_height(double height) override;
   void set_id(std::string_view id) override;
+  void set_rx(double rx) override;
+  void set_ry(double ry) override;
   void set_class(std::string_view) override;
   void set_stroke(std::string_view stroke) override;
   void set_point(std::pair<double, double> point) override;
index 14546982bc2473af13456e0fbd0f114b95316e34..ea5a4a28f7c188f409e94c95b806652e6240acdd 100644 (file)
@@ -32,6 +32,8 @@ public:
   virtual void set_fill(std::string_view fill) = 0;
   virtual void set_height(double height) = 0;
   virtual void set_id(std::string_view id) = 0;
+  virtual void set_rx(double rx) = 0;
+  virtual void set_ry(double ry) = 0;
   virtual void set_point(std::pair<double, double> point) = 0;
   virtual void set_stroke(std::string_view stroke) = 0;
   virtual void set_text(std::string_view text) = 0;
index 89666c8d737eacd54cc326aa7be3c78e85612f69..6e29f588cf11d8c749ae39243481bf5f31130744 100644 (file)
@@ -144,7 +144,8 @@ void SVG::SVGElement::to_string_impl(std::string &output,
     append_attribute(attributes_str, fill_attribute_to_string());
     append_attribute(attributes_str, stroke_attribute_to_string());
     attributes_str +=
-        fmt::format(R"( cx="{}" cy="{}")", attributes.cx, attributes.cy);
+        fmt::format(R"( cx="{}" cy="{}" rx="{}" ry="{}")", attributes.cx,
+                    attributes.cy, attributes.rx, attributes.ry);
     break;
   case SVG::SVGElementType::Group:
     attributes_str += fmt::format(R"( class="{}")", attributes.class_);
index 855627d666a855c6e89773d2ff65fc82e1d798f0..7d554554d2a46dbbb3bbca82d11ff99a3b5f9a3e 100644 (file)
@@ -53,6 +53,8 @@ struct SVGAttributes {
   double height;
   std::string id;
   std::vector<SVGPoint> points;
+  double rx;
+  double ry;
   std::string stroke;
   std::optional<SVGMatrix> transform;
   SVGRect viewBox;
index 39ec5a76447a65e2ac3f3e309a3195c389778a0d..1bdd293d6da6d41c62a999b54aacc740c5be8de9 100644 (file)
@@ -170,14 +170,12 @@ void SvgppContext::set(svgpp::tag::attribute::r a, const double v) {
   (void)v;
 }
 
-void SvgppContext::set(svgpp::tag::attribute::rx a, const double v) {
-  (void)a;
-  (void)v;
+void SvgppContext::set(svgpp::tag::attribute::rx, const double v) {
+  m_svgAnalyzer->set_rx(v);
 }
 
-void SvgppContext::set(svgpp::tag::attribute::ry a, const double v) {
-  (void)a;
-  (void)v;
+void SvgppContext::set(svgpp::tag::attribute::ry, const double v) {
+  m_svgAnalyzer->set_ry(v);
 }
 
 void SvgppContext::set(svgpp::tag::attribute::x1 a, const double v) {
index 98c4d69f5b1df3b191d5951db4d1631d427d610a..9ed7421a6d0fd82782ae6d80a24115a00d5839ea 100644 (file)
@@ -33,6 +33,8 @@ void traverseDocumentWithSvgpp(SvgppContext &context, char *text) {
                         svgpp::tag::attribute::height,    //
                         svgpp::tag::attribute::id,        //
                         svgpp::tag::attribute::points,    //
+                        svgpp::tag::attribute::rx,        //
+                        svgpp::tag::attribute::ry,        //
                         svgpp::tag::attribute::stroke,    //
                         svgpp::tag::attribute::transform, //
                         svgpp::tag::attribute::viewBox,   //
index fe5681fb4ca9d4548bebba6c01dc3213851713a1..34469a9e529f0e3a3e6d76dc3f41f105a6ee1abf 100644 (file)
@@ -123,11 +123,6 @@ 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].starts_with("<ellipse fill=\"")) {
-        // stop comparison here for ellipse based node shapes since we do not
-        // yet handle all attributes on the 'ellipse' element
-        break;
-      }
       if (recreated_svg_lines[i] ==
           ("<path fill=\"none\" stroke=\"black\"/>")) {
         // stop comparison here for the 'cylinder' node shape since we do not
@@ -144,10 +139,6 @@ TEST_CASE(
 
     // do some sanity checks of the parts of the recreated SVG that we cannot
     // yet compare with the original SVG
-    if (contains_ellipse_shape(shape)) {
-      CHECK(recreated_svg.find(" cx=\"") != std::string::npos);
-      CHECK(recreated_svg.find(" cy=\"") != 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);