]> granicus.if.org Git - graphviz/commitdiff
tests: SvgAnalyzer: add handling of the 'cx' and 'cy' attributes
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Wed, 27 Jul 2022 19:42:19 +0000 (21:42 +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 3c004959bfa09b99334eeab2857aa43ded14f7ff..b7ce39aac431cbe497049473bb66cb7c535e3fd4 100644 (file)
@@ -115,6 +115,10 @@ void SVGAnalyzer::set_class(std::string_view class_) {
   current_element().attributes.class_ = class_;
 }
 
+void SVGAnalyzer::set_cx(double cx) { current_element().attributes.cx = cx; }
+
+void SVGAnalyzer::set_cy(double cy) { current_element().attributes.cy = cy; }
+
 void SVGAnalyzer::set_fill(std::string_view fill) {
   current_element().attributes.fill = fill;
 }
index a21fec1aff80297f435940ec1cfd38335de47f82..499dcbdadf65c12283cf4b685ab6fe8aeb76cbee 100644 (file)
@@ -27,6 +27,8 @@ public:
   void on_enter_element_text() override;
   void on_enter_element_title() override;
   void on_exit_element() override;
+  void set_cx(double cx) override;
+  void set_cy(double cy) override;
   void set_fill(std::string_view fill) override;
   void set_height(double height) override;
   void set_id(std::string_view id) override;
index 907c2112a7ea0ffce3407a788ae742cb38f45ea9..14546982bc2473af13456e0fbd0f114b95316e34 100644 (file)
@@ -27,6 +27,8 @@ public:
   virtual void on_enter_element_title() = 0;
   virtual void on_exit_element() = 0;
   virtual void set_class(std::string_view) = 0;
+  virtual void set_cx(double cx) = 0;
+  virtual void set_cy(double cy) = 0;
   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;
index 3a8084abc650437e21a0918111ce8d5d42901f0e..89666c8d737eacd54cc326aa7be3c78e85612f69 100644 (file)
@@ -143,6 +143,8 @@ void SVG::SVGElement::to_string_impl(std::string &output,
   case SVG::SVGElementType::Ellipse:
     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);
     break;
   case SVG::SVGElementType::Group:
     attributes_str += fmt::format(R"( class="{}")", attributes.class_);
index a2301421203f102ce52e6400db83c67592bde982..855627d666a855c6e89773d2ff65fc82e1d798f0 100644 (file)
@@ -47,6 +47,8 @@ std::string_view tag(SVG::SVGElementType type);
 
 struct SVGAttributes {
   std::string class_;
+  double cx;
+  double cy;
   std::string fill;
   double height;
   std::string id;
index 6b17f1d09843085f776c63b3f06a20efd4ab87e6..39ec5a76447a65e2ac3f3e309a3195c389778a0d 100644 (file)
@@ -116,14 +116,12 @@ void SvgppContext::path_close_subpath() {}
 
 void SvgppContext::path_exit() {}
 
-void SvgppContext::set(svgpp::tag::attribute::cy a, const double v) {
-  (void)a;
-  (void)v;
+void SvgppContext::set(svgpp::tag::attribute::cy, const double v) {
+  m_svgAnalyzer->set_cy(v);
 }
 
-void SvgppContext::set(svgpp::tag::attribute::cx a, const double v) {
-  (void)a;
-  (void)v;
+void SvgppContext::set(svgpp::tag::attribute::cx, const double v) {
+  m_svgAnalyzer->set_cx(v);
 }
 
 void SvgppContext::set(svgpp::tag::attribute::fill, svgpp::tag::value::none) {
index 9dfed9dfb50e39a87e5372829f75010ec8863ca0..98c4d69f5b1df3b191d5951db4d1631d427d610a 100644 (file)
@@ -27,6 +27,8 @@ void traverseDocumentWithSvgpp(SvgppContext &context, char *text) {
     using processed_attributes_t =
         boost::mpl::set<svgpp::traits::shapes_attributes_by_element,
                         svgpp::tag::attribute::class_,    //
+                        svgpp::tag::attribute::cx,        //
+                        svgpp::tag::attribute::cy,        //
                         svgpp::tag::attribute::fill,      //
                         svgpp::tag::attribute::height,    //
                         svgpp::tag::attribute::id,        //
index cbb1d2a68204b0c2e52c5797da343b448228eae6..fe5681fb4ca9d4548bebba6c01dc3213851713a1 100644 (file)
@@ -144,6 +144,10 @@ 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);