]> granicus.if.org Git - graphviz/commitdiff
tests: SvgAnalyzer: add handling of the 'font-family' attribute
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Thu, 28 Jul 2022 10:00:50 +0000 (12:00 +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 8fbed77794ffa16a0dbb8a2c98a56fad95679ed9..e7af7f226c0ef71addff8d509244ce76f1bcb6e5 100644 (file)
@@ -119,6 +119,10 @@ 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_font_family(std::string_view font_family) {
+  current_element().attributes.font_family = font_family;
+}
+
 void SVGAnalyzer::set_fill(std::string_view fill) {
   current_element().attributes.fill = fill;
 }
index a83e7081afd7f9077aa8d0a2c335aa8d6eb8580c..0d13420a64c66d15525d9b7def4bcfdb2cad6ca7 100644 (file)
@@ -29,6 +29,7 @@ public:
   void on_exit_element() override;
   void set_cx(double cx) override;
   void set_cy(double cy) override;
+  void set_font_family(std::string_view font_family) override;
   void set_fill(std::string_view fill) override;
   void set_height(double height) override;
   void set_id(std::string_view id) override;
index 2df23e0d78d572604b742edb7dafc79fa4b0478d..59567773ab110838a78607dcf069bd5fe19b46e9 100644 (file)
@@ -29,6 +29,7 @@ public:
   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_font_family(std::string_view font_family) = 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 85d9802082f5ae2f1e76c6a3449c8517e6983eed..bb095589301363165b1af6d06e2dfb26f2e876ef 100644 (file)
@@ -182,8 +182,9 @@ void SVG::SVGElement::to_string_impl(std::string &output,
     break;
   case SVG::SVGElementType::Text:
     attributes_str +=
-        fmt::format(R"(text-anchor="{}" x="{}" y="{}")", attributes.text_anchor,
-                    attributes.x, attributes.y);
+        fmt::format(R"(text-anchor="{}" x="{}" y="{}" font-family="{}")",
+                    attributes.text_anchor, attributes.x, attributes.y,
+                    attributes.font_family);
     break;
   case SVG::SVGElementType::Title:
     // Graphviz doesn't generate attributes on 'title' elements
index e30b8fbe98517ce1126ddd5ad8ff3ca6b30e82df..79966e16a3a339fa4043b34a6810ac1ec2831e05 100644 (file)
@@ -50,6 +50,7 @@ struct SVGAttributes {
   double cx;
   double cy;
   std::string fill;
+  std::string font_family;
   double height;
   std::string id;
   std::vector<SVGPoint> points;
index 92d825fef73f4c63872c71e432408d9cb4717109..39c71d7809f4f8ee3ce2204ce29d243414062b8c 100644 (file)
@@ -240,6 +240,11 @@ void SvgppContext::set(svgpp::tag::attribute::class_,
   m_svgAnalyzer->set_class({v.begin(), v.end()});
 }
 
+void SvgppContext::set(svgpp::tag::attribute::font_family,
+                       boost::iterator_range<const char *> v) {
+  m_svgAnalyzer->set_font_family({v.begin(), v.end()});
+}
+
 void SvgppContext::set(svgpp::tag::attribute::text_anchor,
                        svgpp::tag::value::start) {
   m_svgAnalyzer->set_text_anchor("start");
index 1ec8ed58ac94b763366adbfc7cbcf2f0c553fd1a..b5a2a375b52a42ab39fe963b6bf959463d35694c 100644 (file)
@@ -174,6 +174,8 @@ public:
   void set(svgpp::tag::attribute::id a, boost::iterator_range<const char *> v);
   void set(svgpp::tag::attribute::class_ a,
            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::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 bd1a12647b7943dddd79ad5b48080d1b8d39b489..cede40efb2a6576768959ec7fc4856036f5e888a 100644 (file)
@@ -30,6 +30,7 @@ void traverseDocumentWithSvgpp(SvgppContext &context, char *text) {
                         svgpp::tag::attribute::cx,          //
                         svgpp::tag::attribute::cy,          //
                         svgpp::tag::attribute::fill,        //
+                        svgpp::tag::attribute::font_family, //
                         svgpp::tag::attribute::height,      //
                         svgpp::tag::attribute::id,          //
                         svgpp::tag::attribute::points,      //
index 46ae43358fa052dc587588403121ccdd13a4d2bb..5fc1f93482de29ff150079a20363c26b672a38f1 100644 (file)
@@ -147,8 +147,10 @@ TEST_CASE(
       CHECK(recreated_svg.find("<text text-anchor=\"middle\" x=\"") !=
             std::string::npos);
       CHECK(recreated_svg.find("\" y=\"") != std::string::npos);
-      CHECK(recreated_svg.find("a</text>") != std::string::npos);
-      CHECK(recreated_svg.find("b</text>") != 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);