2013-10-13 13:59:38 +00:00
|
|
|
#include "SVG.hpp"
|
2015-01-06 15:26:15 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2017-08-03 15:31:31 +00:00
|
|
|
#include <boost/nowide/cstdio.hpp>
|
|
|
|
|
2018-08-21 15:43:05 +00:00
|
|
|
#define COORD(x) (unscale<float>((x))*10)
|
2013-10-13 13:59:38 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2016-10-20 15:44:46 +00:00
|
|
|
bool SVG::open(const char* afilename)
|
2013-10-13 13:59:38 +00:00
|
|
|
{
|
2016-10-20 15:44:46 +00:00
|
|
|
this->filename = afilename;
|
2017-08-03 15:31:31 +00:00
|
|
|
this->f = boost::nowide::fopen(afilename, "w");
|
2016-10-20 15:44:46 +00:00
|
|
|
if (this->f == NULL)
|
|
|
|
return false;
|
2013-10-13 13:59:38 +00:00
|
|
|
fprintf(this->f,
|
|
|
|
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
|
|
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
|
|
|
|
"<svg height=\"2000\" width=\"2000\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
|
2016-10-20 15:44:46 +00:00
|
|
|
" <marker id=\"endArrow\" markerHeight=\"8\" markerUnits=\"strokeWidth\" markerWidth=\"10\" orient=\"auto\" refX=\"1\" refY=\"5\" viewBox=\"0 0 10 10\">\n"
|
|
|
|
" <polyline fill=\"darkblue\" points=\"0,0 10,5 0,10 1,5\" />\n"
|
|
|
|
" </marker>\n"
|
|
|
|
);
|
2020-06-16 11:13:51 +00:00
|
|
|
fprintf(this->f, "<rect fill='white' stroke='none' x='0' y='0' width='%f' height='%f'/>\n", 2000.f, 2000.f);
|
2016-10-20 15:44:46 +00:00
|
|
|
return true;
|
2013-10-13 13:59:38 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 15:44:46 +00:00
|
|
|
bool SVG::open(const char* afilename, const BoundingBox &bbox, const coord_t bbox_offset, bool aflipY)
|
2016-03-27 08:53:59 +00:00
|
|
|
{
|
2016-10-20 15:44:46 +00:00
|
|
|
this->filename = afilename;
|
|
|
|
this->origin = bbox.min - Point(bbox_offset, bbox_offset);
|
|
|
|
this->flipY = aflipY;
|
2017-08-03 15:31:31 +00:00
|
|
|
this->f = boost::nowide::fopen(afilename, "w");
|
2016-10-20 15:44:46 +00:00
|
|
|
if (f == NULL)
|
|
|
|
return false;
|
2018-08-17 13:53:43 +00:00
|
|
|
float w = COORD(bbox.max(0) - bbox.min(0) + 2 * bbox_offset);
|
|
|
|
float h = COORD(bbox.max(1) - bbox.min(1) + 2 * bbox_offset);
|
2016-03-27 08:53:59 +00:00
|
|
|
fprintf(this->f,
|
|
|
|
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
|
|
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
|
|
|
|
"<svg height=\"%f\" width=\"%f\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
|
|
|
|
" <marker id=\"endArrow\" markerHeight=\"8\" markerUnits=\"strokeWidth\" markerWidth=\"10\" orient=\"auto\" refX=\"1\" refY=\"5\" viewBox=\"0 0 10 10\">\n"
|
|
|
|
" <polyline fill=\"darkblue\" points=\"0,0 10,5 0,10 1,5\" />\n"
|
|
|
|
" </marker>\n",
|
|
|
|
h, w);
|
2020-06-16 11:13:51 +00:00
|
|
|
fprintf(this->f, "<rect fill='white' stroke='none' x='0' y='0' width='%f' height='%f'/>\n", w, h);
|
2016-10-20 15:44:46 +00:00
|
|
|
return true;
|
2016-03-27 08:53:59 +00:00
|
|
|
}
|
|
|
|
|
2013-10-13 13:59:38 +00:00
|
|
|
void
|
2016-09-13 11:30:00 +00:00
|
|
|
SVG::draw(const Line &line, std::string stroke, coordf_t stroke_width)
|
2013-10-13 13:59:38 +00:00
|
|
|
{
|
|
|
|
fprintf(this->f,
|
2016-03-27 08:53:59 +00:00
|
|
|
" <line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: %s; stroke-width: %f\"",
|
2018-08-17 13:53:43 +00:00
|
|
|
COORD(line.a(0) - origin(0)), COORD(line.a(1) - origin(1)), COORD(line.b(0) - origin(0)), COORD(line.b(1) - origin(1)), stroke.c_str(), (stroke_width == 0) ? 1.f : COORD(stroke_width));
|
2013-10-26 12:41:37 +00:00
|
|
|
if (this->arrows)
|
|
|
|
fprintf(this->f, " marker-end=\"url(#endArrow)\"");
|
|
|
|
fprintf(this->f, "/>\n");
|
|
|
|
}
|
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
void SVG::draw(const ThickLine &line, const std::string &fill, const std::string &stroke, coordf_t stroke_width)
|
2016-03-27 08:53:59 +00:00
|
|
|
{
|
2018-08-21 19:05:24 +00:00
|
|
|
Vec2d dir(line.b(0)-line.a(0), line.b(1)-line.a(1));
|
|
|
|
Vec2d perp(-dir(1), dir(0));
|
2018-08-17 13:53:43 +00:00
|
|
|
coordf_t len = sqrt(perp(0)*perp(0) + perp(1)*perp(1));
|
2016-03-27 08:53:59 +00:00
|
|
|
coordf_t da = coordf_t(0.5)*line.a_width/len;
|
|
|
|
coordf_t db = coordf_t(0.5)*line.b_width/len;
|
|
|
|
fprintf(this->f,
|
|
|
|
" <polygon points=\"%f,%f %f,%f %f,%f %f,%f\" style=\"fill:%s; stroke: %s; stroke-width: %f\"/>\n",
|
2018-08-17 13:53:43 +00:00
|
|
|
COORD(line.a(0)-da*perp(0)-origin(0)),
|
|
|
|
COORD(line.a(1)-da*perp(1)-origin(1)),
|
|
|
|
COORD(line.b(0)-db*perp(0)-origin(0)),
|
|
|
|
COORD(line.b(1)-db*perp(1)-origin(1)),
|
|
|
|
COORD(line.b(0)+db*perp(0)-origin(0)),
|
|
|
|
COORD(line.b(1)+db*perp(1)-origin(1)),
|
|
|
|
COORD(line.a(0)+da*perp(0)-origin(0)),
|
|
|
|
COORD(line.a(1)+da*perp(1)-origin(1)),
|
2016-03-27 08:53:59 +00:00
|
|
|
fill.c_str(), stroke.c_str(),
|
|
|
|
(stroke_width == 0) ? 1.f : COORD(stroke_width));
|
|
|
|
}
|
|
|
|
|
2013-10-26 12:41:37 +00:00
|
|
|
void
|
2016-09-13 11:30:00 +00:00
|
|
|
SVG::draw(const Lines &lines, std::string stroke, coordf_t stroke_width)
|
2013-10-26 12:41:37 +00:00
|
|
|
{
|
2015-01-28 12:00:38 +00:00
|
|
|
for (Lines::const_iterator it = lines.begin(); it != lines.end(); ++it)
|
2016-09-13 11:30:00 +00:00
|
|
|
this->draw(*it, stroke, stroke_width);
|
2015-01-28 12:00:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw(const IntersectionLines &lines, std::string stroke)
|
|
|
|
{
|
|
|
|
for (IntersectionLines::const_iterator it = lines.begin(); it != lines.end(); ++it)
|
|
|
|
this->draw((Line)*it, stroke);
|
2013-10-13 13:59:38 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 15:26:15 +00:00
|
|
|
void
|
2016-09-26 10:45:23 +00:00
|
|
|
SVG::draw(const ExPolygon &expolygon, std::string fill, const float fill_opacity)
|
2015-01-06 15:26:15 +00:00
|
|
|
{
|
2015-01-06 19:51:48 +00:00
|
|
|
this->fill = fill;
|
|
|
|
|
2015-01-06 15:26:15 +00:00
|
|
|
std::string d;
|
|
|
|
Polygons pp = expolygon;
|
|
|
|
for (Polygons::const_iterator p = pp.begin(); p != pp.end(); ++p) {
|
2015-01-06 19:51:48 +00:00
|
|
|
d += this->get_path_d(*p, true) + " ";
|
2015-01-06 15:26:15 +00:00
|
|
|
}
|
2016-09-26 10:45:23 +00:00
|
|
|
this->path(d, true, 0, fill_opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw_outline(const ExPolygon &expolygon, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width)
|
|
|
|
{
|
|
|
|
draw_outline(expolygon.contour, stroke_outer, stroke_width);
|
|
|
|
for (Polygons::const_iterator it = expolygon.holes.begin(); it != expolygon.holes.end(); ++ it) {
|
|
|
|
draw_outline(*it, stroke_holes, stroke_width);
|
|
|
|
}
|
2015-01-06 15:26:15 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 12:00:38 +00:00
|
|
|
void
|
2016-09-26 10:45:23 +00:00
|
|
|
SVG::draw(const ExPolygons &expolygons, std::string fill, const float fill_opacity)
|
2015-01-28 12:00:38 +00:00
|
|
|
{
|
|
|
|
for (ExPolygons::const_iterator it = expolygons.begin(); it != expolygons.end(); ++it)
|
2016-09-26 10:45:23 +00:00
|
|
|
this->draw(*it, fill, fill_opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw_outline(const ExPolygons &expolygons, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width)
|
|
|
|
{
|
|
|
|
for (ExPolygons::const_iterator it = expolygons.begin(); it != expolygons.end(); ++ it)
|
|
|
|
draw_outline(*it, stroke_outer, stroke_holes, stroke_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw(const Surface &surface, std::string fill, const float fill_opacity)
|
|
|
|
{
|
|
|
|
draw(surface.expolygon, fill, fill_opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw_outline(const Surface &surface, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width)
|
|
|
|
{
|
|
|
|
draw_outline(surface.expolygon, stroke_outer, stroke_holes, stroke_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw(const Surfaces &surfaces, std::string fill, const float fill_opacity)
|
|
|
|
{
|
|
|
|
for (Surfaces::const_iterator it = surfaces.begin(); it != surfaces.end(); ++it)
|
|
|
|
this->draw(*it, fill, fill_opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw_outline(const Surfaces &surfaces, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width)
|
|
|
|
{
|
|
|
|
for (Surfaces::const_iterator it = surfaces.begin(); it != surfaces.end(); ++ it)
|
|
|
|
draw_outline(*it, stroke_outer, stroke_holes, stroke_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw(const SurfacesPtr &surfaces, std::string fill, const float fill_opacity)
|
|
|
|
{
|
|
|
|
for (SurfacesPtr::const_iterator it = surfaces.begin(); it != surfaces.end(); ++it)
|
|
|
|
this->draw(*(*it), fill, fill_opacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw_outline(const SurfacesPtr &surfaces, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width)
|
|
|
|
{
|
|
|
|
for (SurfacesPtr::const_iterator it = surfaces.begin(); it != surfaces.end(); ++ it)
|
|
|
|
draw_outline(*(*it), stroke_outer, stroke_holes, stroke_width);
|
2015-01-28 12:00:38 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 15:26:15 +00:00
|
|
|
void
|
2015-01-06 19:51:48 +00:00
|
|
|
SVG::draw(const Polygon &polygon, std::string fill)
|
2015-01-06 15:26:15 +00:00
|
|
|
{
|
2015-01-06 19:51:48 +00:00
|
|
|
this->fill = fill;
|
2016-09-26 10:45:23 +00:00
|
|
|
this->path(this->get_path_d(polygon, true), !fill.empty(), 0, 1.f);
|
2015-01-28 12:00:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw(const Polygons &polygons, std::string fill)
|
|
|
|
{
|
|
|
|
for (Polygons::const_iterator it = polygons.begin(); it != polygons.end(); ++it)
|
|
|
|
this->draw(*it, fill);
|
2015-01-06 15:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-13 11:30:00 +00:00
|
|
|
SVG::draw(const Polyline &polyline, std::string stroke, coordf_t stroke_width)
|
2015-01-06 15:26:15 +00:00
|
|
|
{
|
2015-01-06 19:51:48 +00:00
|
|
|
this->stroke = stroke;
|
2016-09-26 10:45:23 +00:00
|
|
|
this->path(this->get_path_d(polyline, false), false, stroke_width, 1.f);
|
2015-01-06 19:51:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 12:00:38 +00:00
|
|
|
void
|
2016-09-13 11:30:00 +00:00
|
|
|
SVG::draw(const Polylines &polylines, std::string stroke, coordf_t stroke_width)
|
2015-01-28 12:00:38 +00:00
|
|
|
{
|
|
|
|
for (Polylines::const_iterator it = polylines.begin(); it != polylines.end(); ++it)
|
2016-09-30 13:23:18 +00:00
|
|
|
this->draw(*it, stroke, stroke_width);
|
2016-03-27 08:53:59 +00:00
|
|
|
}
|
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
void SVG::draw(const ThickLines &thicklines, const std::string &fill, const std::string &stroke, coordf_t stroke_width)
|
2016-03-27 08:53:59 +00:00
|
|
|
{
|
|
|
|
for (ThickLines::const_iterator it = thicklines.begin(); it != thicklines.end(); ++it)
|
|
|
|
this->draw(*it, fill, stroke, stroke_width);
|
2016-03-19 14:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-13 11:30:00 +00:00
|
|
|
SVG::draw(const ThickPolylines &polylines, const std::string &stroke, coordf_t stroke_width)
|
2016-03-19 14:33:58 +00:00
|
|
|
{
|
|
|
|
for (ThickPolylines::const_iterator it = polylines.begin(); it != polylines.end(); ++it)
|
2016-03-27 08:53:59 +00:00
|
|
|
this->draw((Polyline)*it, stroke, stroke_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-09-13 11:30:00 +00:00
|
|
|
SVG::draw(const ThickPolylines &thickpolylines, const std::string &fill, const std::string &stroke, coordf_t stroke_width)
|
2016-03-27 08:53:59 +00:00
|
|
|
{
|
|
|
|
for (ThickPolylines::const_iterator it = thickpolylines.begin(); it != thickpolylines.end(); ++ it)
|
|
|
|
draw(it->thicklines(), fill, stroke, stroke_width);
|
2015-01-28 12:00:38 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 19:51:48 +00:00
|
|
|
void
|
2016-03-27 08:53:59 +00:00
|
|
|
SVG::draw(const Point &point, std::string fill, coord_t iradius)
|
2015-01-06 19:51:48 +00:00
|
|
|
{
|
2016-03-27 08:53:59 +00:00
|
|
|
float radius = (iradius == 0) ? 3.f : COORD(iradius);
|
2015-01-06 19:51:48 +00:00
|
|
|
std::ostringstream svg;
|
2018-08-17 13:53:43 +00:00
|
|
|
svg << " <circle cx=\"" << COORD(point(0) - origin(0)) << "\" cy=\"" << COORD(point(1) - origin(1))
|
2015-01-06 19:51:48 +00:00
|
|
|
<< "\" r=\"" << radius << "\" "
|
|
|
|
<< "style=\"stroke: none; fill: " << fill << "\" />";
|
|
|
|
|
|
|
|
fprintf(this->f, "%s\n", svg.str().c_str());
|
2015-01-06 15:26:15 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 12:00:38 +00:00
|
|
|
void
|
2016-03-27 08:53:59 +00:00
|
|
|
SVG::draw(const Points &points, std::string fill, coord_t radius)
|
2015-01-28 12:00:38 +00:00
|
|
|
{
|
|
|
|
for (Points::const_iterator it = points.begin(); it != points.end(); ++it)
|
|
|
|
this->draw(*it, fill, radius);
|
|
|
|
}
|
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
void
|
|
|
|
SVG::draw(const ClipperLib::Path &polygon, double scale, std::string stroke, coordf_t stroke_width)
|
|
|
|
{
|
|
|
|
this->stroke = stroke;
|
2016-09-26 10:45:23 +00:00
|
|
|
this->path(this->get_path_d(polygon, scale, true), false, stroke_width, 1.f);
|
2016-09-13 11:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw(const ClipperLib::Paths &polygons, double scale, std::string stroke, coordf_t stroke_width)
|
|
|
|
{
|
|
|
|
for (ClipperLib::Paths::const_iterator it = polygons.begin(); it != polygons.end(); ++ it)
|
|
|
|
draw(*it, scale, stroke, stroke_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw_outline(const Polygon &polygon, std::string stroke, coordf_t stroke_width)
|
|
|
|
{
|
|
|
|
this->stroke = stroke;
|
2016-09-26 10:45:23 +00:00
|
|
|
this->path(this->get_path_d(polygon, true), false, stroke_width, 1.f);
|
2016-09-13 11:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVG::draw_outline(const Polygons &polygons, std::string stroke, coordf_t stroke_width)
|
|
|
|
{
|
|
|
|
for (Polygons::const_iterator it = polygons.begin(); it != polygons.end(); ++ it)
|
|
|
|
draw_outline(*it, stroke, stroke_width);
|
|
|
|
}
|
|
|
|
|
2015-01-06 15:26:15 +00:00
|
|
|
void
|
2016-09-26 10:45:23 +00:00
|
|
|
SVG::path(const std::string &d, bool fill, coordf_t stroke_width, const float fill_opacity)
|
2015-01-06 15:26:15 +00:00
|
|
|
{
|
2016-03-27 08:53:59 +00:00
|
|
|
float lineWidth = 0.f;
|
|
|
|
if (! fill)
|
|
|
|
lineWidth = (stroke_width == 0) ? 2.f : COORD(stroke_width);
|
|
|
|
|
2015-01-06 15:26:15 +00:00
|
|
|
fprintf(
|
|
|
|
this->f,
|
2016-09-26 10:45:23 +00:00
|
|
|
" <path d=\"%s\" style=\"fill: %s; stroke: %s; stroke-width: %f; fill-type: evenodd\" %s fill-opacity=\"%f\" />\n",
|
2015-01-06 15:26:15 +00:00
|
|
|
d.c_str(),
|
|
|
|
fill ? this->fill.c_str() : "none",
|
|
|
|
this->stroke.c_str(),
|
2016-03-27 08:53:59 +00:00
|
|
|
lineWidth,
|
2016-09-26 10:45:23 +00:00
|
|
|
(this->arrows && !fill) ? " marker-end=\"url(#endArrow)\"" : "",
|
|
|
|
fill_opacity
|
2015-01-06 15:26:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
2015-01-06 19:51:48 +00:00
|
|
|
SVG::get_path_d(const MultiPoint &mp, bool closed) const
|
2015-01-06 15:26:15 +00:00
|
|
|
{
|
|
|
|
std::ostringstream d;
|
2015-01-06 19:51:48 +00:00
|
|
|
d << "M ";
|
2015-01-06 15:26:15 +00:00
|
|
|
for (Points::const_iterator p = mp.points.begin(); p != mp.points.end(); ++p) {
|
2018-08-17 13:53:43 +00:00
|
|
|
d << COORD((*p)(0) - origin(0)) << " ";
|
|
|
|
d << COORD((*p)(1) - origin(1)) << " ";
|
2015-01-06 15:26:15 +00:00
|
|
|
}
|
2015-01-06 19:51:48 +00:00
|
|
|
if (closed) d << "z";
|
2015-01-06 15:26:15 +00:00
|
|
|
return d.str();
|
|
|
|
}
|
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
std::string
|
|
|
|
SVG::get_path_d(const ClipperLib::Path &path, double scale, bool closed) const
|
|
|
|
{
|
|
|
|
std::ostringstream d;
|
|
|
|
d << "M ";
|
|
|
|
for (ClipperLib::Path::const_iterator p = path.begin(); p != path.end(); ++p) {
|
2018-08-17 13:53:43 +00:00
|
|
|
d << COORD(scale * p->X - origin(0)) << " ";
|
|
|
|
d << COORD(scale * p->Y - origin(1)) << " ";
|
2016-09-13 11:30:00 +00:00
|
|
|
}
|
|
|
|
if (closed) d << "z";
|
|
|
|
return d.str();
|
|
|
|
}
|
|
|
|
|
2016-09-26 10:45:23 +00:00
|
|
|
void SVG::draw_text(const Point &pt, const char *text, const char *color)
|
|
|
|
{
|
|
|
|
fprintf(this->f,
|
|
|
|
"<text x=\"%f\" y=\"%f\" font-family=\"sans-serif\" font-size=\"20px\" fill=\"%s\">%s</text>",
|
2018-08-17 13:53:43 +00:00
|
|
|
COORD(pt(0)-origin(0)),
|
|
|
|
COORD(pt(1)-origin(1)),
|
2016-09-26 10:45:23 +00:00
|
|
|
color, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SVG::draw_legend(const Point &pt, const char *text, const char *color)
|
|
|
|
{
|
|
|
|
fprintf(this->f,
|
|
|
|
"<circle cx=\"%f\" cy=\"%f\" r=\"10\" fill=\"%s\"/>",
|
2018-08-17 13:53:43 +00:00
|
|
|
COORD(pt(0)-origin(0)),
|
|
|
|
COORD(pt(1)-origin(1)),
|
2016-09-26 10:45:23 +00:00
|
|
|
color);
|
|
|
|
fprintf(this->f,
|
|
|
|
"<text x=\"%f\" y=\"%f\" font-family=\"sans-serif\" font-size=\"10px\" fill=\"%s\">%s</text>",
|
2018-08-17 13:53:43 +00:00
|
|
|
COORD(pt(0)-origin(0)) + 20.f,
|
|
|
|
COORD(pt(1)-origin(1)),
|
2016-09-26 10:45:23 +00:00
|
|
|
"black", text);
|
|
|
|
}
|
|
|
|
|
2013-10-13 13:59:38 +00:00
|
|
|
void
|
|
|
|
SVG::Close()
|
|
|
|
{
|
|
|
|
fprintf(this->f, "</svg>\n");
|
|
|
|
fclose(this->f);
|
2016-04-15 15:57:38 +00:00
|
|
|
this->f = NULL;
|
2016-10-20 11:04:23 +00:00
|
|
|
// printf("SVG written to %s\n", this->filename.c_str());
|
2013-10-13 13:59:38 +00:00
|
|
|
}
|
|
|
|
|
2016-09-26 10:45:23 +00:00
|
|
|
void SVG::export_expolygons(const char *path, const BoundingBox &bbox, const Slic3r::ExPolygons &expolygons, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width)
|
|
|
|
{
|
|
|
|
SVG svg(path, bbox);
|
|
|
|
svg.draw(expolygons);
|
|
|
|
svg.draw_outline(expolygons, stroke_outer, stroke_holes, stroke_width);
|
|
|
|
svg.Close();
|
|
|
|
}
|
|
|
|
|
2017-03-02 15:32:43 +00:00
|
|
|
void SVG::export_expolygons(const char *path, const std::vector<std::pair<Slic3r::ExPolygons, ExPolygonAttributes>> &expolygons_with_attributes)
|
|
|
|
{
|
|
|
|
if (expolygons_with_attributes.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
BoundingBox bbox = get_extents(expolygons_with_attributes.front().first);
|
|
|
|
for (size_t i = 0; i < expolygons_with_attributes.size(); ++ i)
|
|
|
|
bbox.merge(get_extents(expolygons_with_attributes[i].first));
|
|
|
|
|
|
|
|
SVG svg(path, bbox);
|
|
|
|
for (const auto &exp_with_attr : expolygons_with_attributes)
|
|
|
|
svg.draw(exp_with_attr.first, exp_with_attr.second.color_fill, exp_with_attr.second.fill_opacity);
|
|
|
|
for (const auto &exp_with_attr : expolygons_with_attributes) {
|
|
|
|
std::string color_contour = exp_with_attr.second.color_contour;
|
|
|
|
if (color_contour.empty())
|
|
|
|
color_contour = exp_with_attr.second.color_fill;
|
|
|
|
std::string color_holes = exp_with_attr.second.color_holes;
|
|
|
|
if (color_holes.empty())
|
|
|
|
color_holes = color_contour;
|
|
|
|
svg.draw_outline(exp_with_attr.first, color_contour, color_holes, exp_with_attr.second.outline_width);
|
|
|
|
}
|
2019-11-01 18:59:09 +00:00
|
|
|
for (const auto &exp_with_attr : expolygons_with_attributes)
|
|
|
|
if (exp_with_attr.second.radius_points > 0)
|
|
|
|
for (const ExPolygon &expoly : exp_with_attr.first)
|
|
|
|
svg.draw((Points)expoly, exp_with_attr.second.color_points, exp_with_attr.second.radius_points);
|
2017-03-02 15:32:43 +00:00
|
|
|
svg.Close();
|
|
|
|
}
|
|
|
|
|
2013-10-13 13:59:38 +00:00
|
|
|
}
|