From: Magnus Jacobsson Date: Thu, 28 Jul 2022 10:13:08 +0000 (+0200) Subject: tests: SvgAnalyzer: add handling of the 'font-size' attribute X-Git-Tag: 5.0.1~7^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dad4a5d7696db0ce83fcd766a69e08f0fbbea990;p=graphviz tests: SvgAnalyzer: add handling of the 'font-size' attribute --- diff --git a/tests/svg_analyzer.cpp b/tests/svg_analyzer.cpp index e7af7f226..be7b3bc29 100644 --- a/tests/svg_analyzer.cpp +++ b/tests/svg_analyzer.cpp @@ -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; } diff --git a/tests/svg_analyzer.h b/tests/svg_analyzer.h index 0d13420a6..861c36f63 100644 --- a/tests/svg_analyzer.h +++ b/tests/svg_analyzer.h @@ -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; diff --git a/tests/svg_analyzer_interface.h b/tests/svg_analyzer_interface.h index 59567773a..295f82f93 100644 --- a/tests/svg_analyzer_interface.h +++ b/tests/svg_analyzer_interface.h @@ -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; diff --git a/tests/svg_element.cpp b/tests/svg_element.cpp index bb0955893..ff07e5f80 100644 --- a/tests/svg_element.cpp +++ b/tests/svg_element.cpp @@ -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 diff --git a/tests/svg_element.h b/tests/svg_element.h index 79966e16a..928834700 100644 --- a/tests/svg_element.h +++ b/tests/svg_element.h @@ -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 points; diff --git a/tests/svgpp_context.cpp b/tests/svgpp_context.cpp index 39c71d780..db4cf826f 100644 --- a/tests/svgpp_context.cpp +++ b/tests/svgpp_context.cpp @@ -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"); diff --git a/tests/svgpp_context.h b/tests/svgpp_context.h index b5a2a375b..828e26fc1 100644 --- a/tests/svgpp_context.h +++ b/tests/svgpp_context.h @@ -176,6 +176,16 @@ public: boost::iterator_range v); void set(svgpp::tag::attribute::font_family a, boost::iterator_range 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); diff --git a/tests/svgpp_document_traverser.cpp b/tests/svgpp_document_traverser.cpp index cede40efb..8ee6a9ee7 100644 --- a/tests/svgpp_document_traverser.cpp +++ b/tests/svgpp_document_traverser.cpp @@ -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, // diff --git a/tests/test_svg_analyzer.cpp b/tests/test_svg_analyzer.cpp index 5fc1f9348..e84f5d8ac 100644 --- a/tests/test_svg_analyzer.cpp +++ b/tests/test_svg_analyzer.cpp @@ -129,12 +129,6 @@ TEST_CASE( // yet handle all attributes on the 'path' element break; } - if (recreated_svg_lines[i].starts_with( - "g1") != std::string::npos); CHECK(recreated_svg.find("a") != std::string::npos); CHECK(recreated_svg.find("b") != std::string::npos); - if (shape != "point") { - CHECK(recreated_svg.find("a") != - std::string::npos); - CHECK(recreated_svg.find(" font-family=\"Times,serif\">b") != - std::string::npos); - } CHECK(recreated_svg.find("") != std::string::npos); CHECK(recreated_svg.find("") != std::string::npos);