#include "SVG.hpp" #include #define COORD(x) ((float)unscale(x)*10) namespace Slic3r { SVG::SVG(const char* filename) : arrows(true), filename(filename), fill("grey"), stroke("black") { this->f = fopen(filename, "w"); fprintf(this->f, "\n" "\n" "\n" " \n" " \n" " \n" ); } void SVG::AddLine(const Line &line) { fprintf(this->f, " arrows) fprintf(this->f, " marker-end=\"url(#endArrow)\""); fprintf(this->f, "/>\n"); } void SVG::AddLine(const IntersectionLine &line) { this->AddLine(Line(line.a, line.b)); } void SVG::draw(const ExPolygon &expolygon) { std::string d; Polygons pp = expolygon; for (Polygons::const_iterator p = pp.begin(); p != pp.end(); ++p) { d += this->get_path_d(*p) + " "; } this->path(d, true); } void SVG::draw(const Polygon &polygon) { this->path(this->get_path_d(polygon), true); } void SVG::draw(const Polyline &polyline) { this->path(this->get_path_d(polyline), false); } void SVG::path(const std::string &d, bool fill) { fprintf( this->f, " \n", d.c_str(), fill ? this->fill.c_str() : "none", this->stroke.c_str(), fill ? "0" : "2" ); } std::string SVG::get_path_d(const MultiPoint &mp) const { std::ostringstream d; d << "M"; for (Points::const_iterator p = mp.points.begin(); p != mp.points.end(); ++p) { d << " " << COORD(p->x); d << " " << COORD(p->y); } d << " z"; return d.str(); } void SVG::Close() { fprintf(this->f, "\n"); fclose(this->f); printf("SVG written to %s\n", this->filename.c_str()); } }