current_element().attributes.width = width;
}
+void SVGAnalyzer::set_viewBox(double x, double y, double width, double height) {
+ current_element().attributes.viewBox = {x, y, width, height};
+}
+
void SVGAnalyzer::set_graphviz_version(std::string_view version) {
m_svg.graphviz_version = version;
}
void set_height(double height) override;
void set_class(std::string_view) override;
void set_text(std::string_view text) override;
+ void set_viewBox(double x, double y, double width, double height) override;
void set_width(double width) override;
std::size_t num_svgs() const { return m_num_svgs; };
std::size_t num_groups() const { return m_num_groups; };
virtual void set_class(std::string_view) = 0;
virtual void set_height(double height) = 0;
virtual void set_text(std::string_view text) = 0;
+ virtual void set_viewBox(double x, double y, double width, double height) = 0;
virtual void set_width(double width) = 0;
};
// ignore for now
break;
case SVG::SVGElementType::Svg:
- attributes_str += fmt::format(R"(width="{}pt" height="{}pt")",
- std::lround(px_to_pt(attributes.width)),
- std::lround(px_to_pt(attributes.height)));
+ attributes_str +=
+ fmt::format(R"(width="{}pt" height="{}pt")"
+ "\n"
+ R"( viewBox="{:.2f} {:.2f} {:.2f} {:.2f}")",
+ std::lround(px_to_pt(attributes.width)),
+ std::lround(px_to_pt(attributes.height)),
+ attributes.viewBox.x, attributes.viewBox.y,
+ attributes.viewBox.width, attributes.viewBox.height);
break;
case SVG::SVGElementType::Text:
// ignore for now
namespace SVG {
+struct SVGRect {
+ double x;
+ double y;
+ double width;
+ double height;
+};
+
enum class SVGElementType {
Circle,
Ellipse,
struct SVGAttributes {
std::string class_;
double height;
+ SVGRect viewBox;
double width;
};
m_svgAnalyzer->set_class({v.begin(), v.end()});
}
+void SvgppContext::set(svgpp::tag::attribute::viewBox, const double v1,
+ const double v2, const double v3, const double v4) {
+ m_svgAnalyzer->set_viewBox(v1, v2, v3, v4);
+}
+
void SvgppContext::set_impl(svgpp::tag::attribute::points &points,
const std::any &range) {
(void)points;
void set(svgpp::tag::attribute::height height, double v);
void set(svgpp::tag::attribute::class_ a,
boost::iterator_range<const char *> v);
+ void set(svgpp::tag::attribute::viewBox a, double v1, double v2, double v3,
+ double v4);
void set_text(boost::iterator_range<const char *> v);
private:
using processed_attributes_t =
boost::mpl::set<svgpp::traits::shapes_attributes_by_element,
- svgpp::tag::attribute::class_, //
- svgpp::tag::attribute::height, //
- svgpp::tag::attribute::width //
+ svgpp::tag::attribute::class_, //
+ svgpp::tag::attribute::height, //
+ svgpp::tag::attribute::viewBox, //
+ svgpp::tag::attribute::width //
>::type;
svgpp::document_traversal<
// yet compare with the original SVG
CHECK(recreated_svg.find("<svg width=\"") != std::string::npos);
CHECK(recreated_svg.find("\" height=\"") != std::string::npos);
+ CHECK(recreated_svg.find("\n viewBox=\"") != std::string::npos);
CHECK(recreated_svg.find("</svg>") != std::string::npos);
CHECK(recreated_svg.find("<g class=\"graph\">") != std::string::npos);
CHECK(recreated_svg.find("<g class=\"node\">") != std::string::npos);