]> granicus.if.org Git - graphviz/commitdiff
tests: SvgAnalyzer: add handling of the 'font-size' attribute
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Thu, 28 Jul 2022 10:13:08 +0000 (12:13 +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_context.h
tests/svgpp_document_traverser.cpp
tests/test_svg_analyzer.cpp

index e7af7f226c0ef71addff8d509244ce76f1bcb6e5..be7b3bc2953562cb900529b1b47cbe3da4f8e722 100644 (file)
@@ -123,6 +123,10 @@ void SVGAnalyzer::set_font_family(std::string_view font_family) {
   current_element().attributes.font_family = font_family;
 }
 
+void SVGAnalyzer::set_font_size(double font_size) {
+  current_element().attributes.font_size = font_size;
+}
+
 void SVGAnalyzer::set_fill(std::string_view fill) {
   current_element().attributes.fill = fill;
 }
index 0d13420a64c66d15525d9b7def4bcfdb2cad6ca7..861c36f6349ae047189531604fefa66c7d99187d 100644 (file)
@@ -30,6 +30,7 @@ public:
   void set_cx(double cx) override;
   void set_cy(double cy) override;
   void set_font_family(std::string_view font_family) override;
+  void set_font_size(double font_size) override;
   void set_fill(std::string_view fill) override;
   void set_height(double height) override;
   void set_id(std::string_view id) override;
index 59567773ab110838a78607dcf069bd5fe19b46e9..295f82f933f28bbd0b0fc5b2a630c9907aa65d73 100644 (file)
@@ -30,6 +30,7 @@ public:
   virtual void set_cx(double cx) = 0;
   virtual void set_cy(double cy) = 0;
   virtual void set_font_family(std::string_view font_family) = 0;
+  virtual void set_font_size(double font_size) = 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 bb095589301363165b1af6d06e2dfb26f2e876ef..ff07e5f80e558b8559f7f0496e059fca072e2346 100644 (file)
@@ -181,10 +181,10 @@ void SVG::SVGElement::to_string_impl(std::string &output,
         attributes.viewBox.height);
     break;
   case SVG::SVGElementType::Text:
-    attributes_str +=
-        fmt::format(R"(text-anchor="{}" x="{}" y="{}" font-family="{}")",
-                    attributes.text_anchor, attributes.x, attributes.y,
-                    attributes.font_family);
+    attributes_str += fmt::format(
+        R"(text-anchor="{}" x="{}" y="{}" font-family="{}" font-size="{:.2f}")",
+        attributes.text_anchor, attributes.x, attributes.y,
+        attributes.font_family, attributes.font_size);
     break;
   case SVG::SVGElementType::Title:
     // Graphviz doesn't generate attributes on 'title' elements
index 79966e16a3a339fa4043b34a6810ac1ec2831e05..9288347004f709fc1262179fbb457c55b64cbd63 100644 (file)
@@ -51,6 +51,7 @@ struct SVGAttributes {
   double cy;
   std::string fill;
   std::string font_family;
+  double font_size;
   double height;
   std::string id;
   std::vector<SVGPoint> points;
index 39c71d7809f4f8ee3ce2204ce29d243414062b8c..db4cf826f8b401fa28ed130c00666ad90552f3f6 100644 (file)
@@ -245,6 +245,64 @@ void SvgppContext::set(svgpp::tag::attribute::font_family,
   m_svgAnalyzer->set_font_family({v.begin(), v.end()});
 }
 
+void SvgppContext::set(svgpp::tag::attribute::font_size, const double v) {
+  m_svgAnalyzer->set_font_size(v);
+}
+
+void SvgppContext::set(svgpp::tag::attribute::font_size,
+                       svgpp::tag::value::xx_small) {
+  throw std::runtime_error{
+      "the 'font_size' attribute 'xx_small' value is not yet implemented"};
+}
+
+void SvgppContext::set(svgpp::tag::attribute::font_size,
+                       svgpp::tag::value::x_small) {
+  throw std::runtime_error{
+      "the 'font_size' attribute 'x_small' value is not yet implemented"};
+}
+
+void SvgppContext::set(svgpp::tag::attribute::font_size,
+                       svgpp::tag::value::smaller) {
+  throw std::runtime_error{
+      "the 'font_size' attribute 'smaller' value is not yet implemented"};
+}
+
+void SvgppContext::set(svgpp::tag::attribute::font_size,
+                       svgpp::tag::value::small) {
+  throw std::runtime_error{
+      "the 'font_size' attribute 'small' value is not yet implemented"};
+}
+
+void SvgppContext::set(svgpp::tag::attribute::font_size,
+                       svgpp::tag::value::medium) {
+  throw std::runtime_error{
+      "the 'font_size' attribute 'medium' value is not yet implemented"};
+}
+
+void SvgppContext::set(svgpp::tag::attribute::font_size,
+                       svgpp::tag::value::large) {
+  throw std::runtime_error{
+      "the 'font_size' attribute 'large' value is not yet implemented"};
+}
+
+void SvgppContext::set(svgpp::tag::attribute::font_size,
+                       svgpp::tag::value::larger) {
+  throw std::runtime_error{
+      "the 'font_size' attribute 'larger' value is not yet implemented"};
+}
+
+void SvgppContext::set(svgpp::tag::attribute::font_size,
+                       svgpp::tag::value::x_large) {
+  throw std::runtime_error{
+      "the 'font_size' attribute 'x_large' value is not yet implemented"};
+}
+
+void SvgppContext::set(svgpp::tag::attribute::font_size,
+                       svgpp::tag::value::xx_large) {
+  throw std::runtime_error{
+      "the 'font_size' attribute 'xx_large' value is not yet implemented"};
+}
+
 void SvgppContext::set(svgpp::tag::attribute::text_anchor,
                        svgpp::tag::value::start) {
   m_svgAnalyzer->set_text_anchor("start");
index b5a2a375b52a42ab39fe963b6bf959463d35694c..828e26fc19dd5b39214fddacf32084f9df198de9 100644 (file)
@@ -176,6 +176,16 @@ public:
            boost::iterator_range<const char *> v);
   void set(svgpp::tag::attribute::font_family a,
            boost::iterator_range<const char *> v);
+  void set(svgpp::tag::attribute::font_size a, double v);
+  void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::xx_small v);
+  void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::x_small v);
+  void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::smaller v);
+  void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::small v);
+  void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::medium v);
+  void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::large v);
+  void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::larger v);
+  void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::x_large v);
+  void set(svgpp::tag::attribute::font_size a, svgpp::tag::value::xx_large v);
   void set(svgpp::tag::attribute::text_anchor a, svgpp::tag::value::start v);
   void set(svgpp::tag::attribute::text_anchor a, svgpp::tag::value::middle v);
   void set(svgpp::tag::attribute::text_anchor a, svgpp::tag::value::end v);
index cede40efb2a6576768959ec7fc4856036f5e888a..8ee6a9ee7a45003ef868fab7745debdeb2553cd8 100644 (file)
@@ -31,6 +31,7 @@ void traverseDocumentWithSvgpp(SvgppContext &context, char *text) {
                         svgpp::tag::attribute::cy,          //
                         svgpp::tag::attribute::fill,        //
                         svgpp::tag::attribute::font_family, //
+                        svgpp::tag::attribute::font_size,   //
                         svgpp::tag::attribute::height,      //
                         svgpp::tag::attribute::id,          //
                         svgpp::tag::attribute::points,      //
index 5fc1f93482de29ff150079a20363c26b672a38f1..e84f5d8ac50f6ab2c9aa564f00751eec4ca1986a 100644 (file)
@@ -129,12 +129,6 @@ TEST_CASE(
         // yet handle all attributes on the 'path' element
         break;
       }
-      if (recreated_svg_lines[i].starts_with(
-              "<text text-anchor=\"middle\" x=\"")) {
-        // stop comparison here since we do not yet handle all attributes on the
-        // 'text' element
-        break;
-      }
       REQUIRE(recreated_svg_lines[i] == original_svg_lines[i]);
     }
 
@@ -143,15 +137,6 @@ TEST_CASE(
     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);
-    if (shape != "point") {
-      CHECK(recreated_svg.find("<text text-anchor=\"middle\" x=\"") !=
-            std::string::npos);
-      CHECK(recreated_svg.find("\" y=\"") != std::string::npos);
-      CHECK(recreated_svg.find(" font-family=\"Times,serif\">a</text>") !=
-            std::string::npos);
-      CHECK(recreated_svg.find(" font-family=\"Times,serif\">b</text>") !=
-            std::string::npos);
-    }
     CHECK(recreated_svg.find("<path fill=\"none\" stroke=\"black\"/>") !=
           std::string::npos);
     CHECK(recreated_svg.find("<!-- a -->") != std::string::npos);