diff options
Diffstat (limited to 'svg.cpp')
-rw-r--r-- | svg.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -0,0 +1,29 @@ +#include <sstream> +#include "svg.h" + + +Polygon::Polygon(std::vector<std::array<double, 2>> pts, std::string bg) + : pts{move(pts)}, bg{move(bg)} +{} + +std::string Polygon::svg() const { + std::ostringstream ss; + ss << "<path d=\""; + for (size_t i = 0; i < pts.size(); i++) { + if (i == 0) ss << 'M'; else ss << 'L'; + ss << pts[i][0] << ' ' << pts[i][1] << ' '; + } + ss << "Z\" stroke=\"black\" fill=\"" << bg << "\" stroke-width=\"0.03px\"/>"; + return ss.str(); +} + +Text::Text(double x, double y, double rotation, std::string text) + : x{x}, y{y}, rotation{rotation}, text{move(text)} +{} + +std::string Text::svg() const { + std::ostringstream ss; + ss << "<text x=\"" << x << "\" y=\"" << y - 0.04 << "\" transform=\"rotate(" << rotation << ")\" style=\"font-size:0.3px\" text-anchor=\"middle\" dominant-baseline=\"middle\">"; + ss << text << "</text>"; + return ss.str(); +} |