
Purpose
This a header-only library for generating SVG files from a simple C++ interface. It can also perform non-trivial tasks such as calculating a bounding box for an SVG's elements, or merging several graphics together.
Want to see more? Read the documentation.
Basic Usage
#include <fstream>
int main() {
root.
style(
"circle").set_attr(
"fill",
"#000000")
.set_attr("stroke", "#000000");
root.
style(
"rect#my_rectangle").set_attr(
"fill",
"red");
->set_attr("x", 20).set_attr("y", 20)
.set_attr("width", 40).set_attr("height", 40);
" circles." << std::endl;
std::ofstream outfile("my_drawing.svg");
outfile << std::string(root);
}
Element * get_element_by_id(const std::string &id)
Definition svg.hpp:385
T * add_child(Args &&... args)
Definition svg.hpp:311
std::vector< T * > get_children()
Definition svg.hpp:327
void autoscale(const Margins &margins=DEFAULT_MARGINS)
Definition svg.hpp:794
AttributeMap & style(const std::string &key)
Definition svg.hpp:470
Output
<svg height="420.0" viewBox="-210.0 -210.0 420.0 420.0" width="420.0" xmlns="http://www.w3.org/2000/svg">
<style type="text/css">
<![CDATA[
circle {
fill: #000000;
stroke: #000000;
}
rect#my_rectangle {
fill: red;
}
]]>
</style>
<g>
<rect height="40" id="my_rectangle" width="40" x="20" y="20" />
<circle cx="-100.0" cy="-100.0" r="100.0" />
<circle cx="100.0" cy="100.0" r="100.0" />
</g>
</svg>
Simple Animations
This package supports creating basic animations via CSS keyframes via the frame_animate() function.