current_element().attributes.height = height;
}
+void SVGAnalyzer::set_stroke(std::string_view stroke) {
+ current_element().attributes.stroke = stroke;
+}
+
void SVGAnalyzer::set_id(std::string_view id) {
current_element().attributes.id = id;
}
void set_height(double height) override;
void set_id(std::string_view id) override;
void set_class(std::string_view) override;
+ void set_stroke(std::string_view stroke) override;
void set_text(std::string_view text) override;
void set_transform(double a, double b, double c, double d, double e,
double f) override;
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_stroke(std::string_view stroke) = 0;
virtual void set_text(std::string_view text) = 0;
virtual void set_transform(double a, double b, double c, double d, double e,
double f) = 0;
return fmt::format(R"(id="{}")", attributes.id);
}
+std::string SVG::SVGElement::stroke_attribute_to_string() const {
+ if (attributes.stroke.empty()) {
+ return "";
+ }
+
+ return fmt::format(R"(stroke="{}")",
+ stroke_to_graphviz_color(attributes.stroke));
+}
+
std::string SVG::SVGElement::to_string(std::size_t indent_size = 2) const {
std::string output;
output += R"(<?xml version="1.0" encoding="UTF-8" standalone="no"?>)"
switch (type) {
case SVG::SVGElementType::Ellipse:
append_attribute(attributes_str, fill_attribute_to_string());
+ append_attribute(attributes_str, stroke_attribute_to_string());
break;
case SVG::SVGElementType::Group:
attributes_str += fmt::format(R"( class="{}")", attributes.class_);
break;
case SVG::SVGElementType::Path:
append_attribute(attributes_str, fill_attribute_to_string());
+ append_attribute(attributes_str, stroke_attribute_to_string());
break;
case SVG::SVGElementType::Polygon:
append_attribute(attributes_str, fill_attribute_to_string());
+ append_attribute(attributes_str, stroke_attribute_to_string());
break;
case SVG::SVGElementType::Polyline:
append_attribute(attributes_str, fill_attribute_to_string());
+ append_attribute(attributes_str, stroke_attribute_to_string());
break;
case SVG::SVGElementType::Svg:
attributes_str += fmt::format(
}
}
+std::string
+SVG::SVGElement::stroke_to_graphviz_color(const std::string &color) const {
+ return to_graphviz_color(color);
+}
+
std::string_view SVG::tag(SVGElementType type) {
switch (type) {
case SVG::SVGElementType::Circle:
std::string fill;
double height;
std::string id;
+ std::string stroke;
std::optional<SVGMatrix> transform;
SVGRect viewBox;
double width;
const std::string &attribute) const;
std::string id_attribute_to_string() const;
std::string fill_attribute_to_string() const;
+ std::string stroke_attribute_to_string() const;
+ std::string stroke_to_graphviz_color(const std::string &color) const;
void to_string_impl(std::string &output, std::size_t indent_size,
std::size_t current_indent) const;
};
m_svgAnalyzer->set_fill(to_color_string(color));
}
+void SvgppContext::set(svgpp::tag::attribute::stroke, svgpp::tag::value::none) {
+ m_svgAnalyzer->set_stroke("none");
+}
+
+void SvgppContext::set(svgpp::tag::attribute::stroke,
+ svgpp::tag::value::currentColor) {
+ throw std::runtime_error{
+ "the 'stroke' attribute 'currentColor' value is not yet implemented"};
+}
+
+void SvgppContext::set(svgpp::tag::attribute::stroke,
+ SvgppContext::color_t color,
+ svgpp::tag::skip_icc_color) {
+ m_svgAnalyzer->set_stroke(to_color_string(color));
+}
+
void SvgppContext::transform_matrix(const boost::array<double, 6> &matrix) {
double a = matrix.at(0);
double b = matrix.at(1);
throw std::runtime_error{
"this flavor of the 'fill' attribute is not yet implemented"};
};
+ void set(svgpp::tag::attribute::stroke, svgpp::tag::value::none);
+ void set(svgpp::tag::attribute::stroke, svgpp::tag::value::currentColor);
+ void set(svgpp::tag::attribute::stroke, color_t color,
+ svgpp::tag::skip_icc_color = svgpp::tag::skip_icc_color());
+ template <class IRI> void set(svgpp::tag::attribute::stroke, IRI const &) {
+ throw std::runtime_error{
+ "this flavor of the 'stroke' attribute is not yet implemented"};
+ };
+ template <class IRI>
+ void set(svgpp::tag::attribute::stroke, svgpp::tag::iri_fragment,
+ IRI const &) {
+ throw std::runtime_error{
+ "this flavor of the 'stroke' attribute is not yet implemented"};
+ };
+ template <class IRI>
+ void set(svgpp::tag::attribute::stroke, IRI const &,
+ svgpp::tag::value::none) {
+ throw std::runtime_error{
+ "this flavor of the 'stroke' attribute is not yet implemented"};
+ };
+ template <class IRI>
+ void set(svgpp::tag::attribute::stroke, svgpp::tag::iri_fragment, IRI const &,
+ svgpp::tag::value::none) {
+ throw std::runtime_error{
+ "this flavor of the 'stroke' attribute is not yet implemented"};
+ };
+ template <class IRI>
+ void set(svgpp::tag::attribute::stroke, IRI const &,
+ svgpp::tag::value::currentColor) {
+ throw std::runtime_error{
+ "this flavor of the 'stroke' attribute is not yet implemented"};
+ };
+ template <class IRI>
+ void set(svgpp::tag::attribute::stroke, svgpp::tag::iri_fragment, IRI const &,
+ svgpp::tag::value::currentColor) {
+ throw std::runtime_error{
+ "this flavor of the 'stroke' attribute is not yet implemented"};
+ };
+ template <class IRI>
+ void set(svgpp::tag::attribute::stroke, IRI const &, color_t,
+ svgpp::tag::skip_icc_color = svgpp::tag::skip_icc_color()) {
+ throw std::runtime_error{
+ "this flavor of the 'stroke' attribute is not yet implemented"};
+ };
+ template <class IRI>
+ void set(svgpp::tag::attribute::stroke, svgpp::tag::iri_fragment, IRI const &,
+ color_t, svgpp::tag::skip_icc_color = svgpp::tag::skip_icc_color()) {
+ throw std::runtime_error{
+ "this flavor of the 'stroke' attribute is not yet implemented"};
+ };
void transform_matrix(const boost::array<double, 6> &matrix);
void set(svgpp::tag::attribute::r r, double v);
void set(svgpp::tag::attribute::rx rx, double v);
svgpp::tag::attribute::fill, //
svgpp::tag::attribute::height, //
svgpp::tag::attribute::id, //
+ svgpp::tag::attribute::stroke, //
svgpp::tag::attribute::transform, //
svgpp::tag::attribute::viewBox, //
svgpp::tag::attribute::width //
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] == "<polygon fill=\"white\"/>") {
+ if (recreated_svg_lines[i] ==
+ "<polygon fill=\"white\" stroke=\"none\"/>") {
// stop comparison here since we do not yet handle all attributes on the
// 'polygon' element
break;
CHECK(recreated_svg.find("<text>a</text>") != std::string::npos);
CHECK(recreated_svg.find("<text>b</text>") != std::string::npos);
}
- CHECK(recreated_svg.find("<polygon fill=\"white\"/>") != std::string::npos);
- CHECK(recreated_svg.find("<path fill=\"none\"/>") != std::string::npos);
+ CHECK(recreated_svg.find("<polygon fill=\"white\" stroke=\"none\"/>") !=
+ std::string::npos);
+ CHECK(recreated_svg.find("<path fill=\"none\" stroke=\"black\"/>") !=
+ std::string::npos);
CHECK(recreated_svg.find("<!-- a -->") != std::string::npos);
CHECK(recreated_svg.find("<!-- b -->") != std::string::npos);
CHECK(recreated_svg.find("<!-- a->b -->") != std::string::npos);