From b45c6ef173b6709b9215f82c59218728f43bfe6a Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Fri, 7 Jan 2022 13:18:40 +0100 Subject: [PATCH] Export scaled integer coordinates into svg This is faster and lossless --- src/libslic3r/Format/SL1_SVG.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/Format/SL1_SVG.cpp b/src/libslic3r/Format/SL1_SVG.cpp index bb2f94a68..70e3a444f 100644 --- a/src/libslic3r/Format/SL1_SVG.cpp +++ b/src/libslic3r/Format/SL1_SVG.cpp @@ -32,9 +32,9 @@ void append_svg(std::string &buf, const Polygon &poly) buf += "(p.x())); + buf += std::to_string(p.x()); buf += " "; - buf += float_to_string_decimal_point(unscaled(p.y())); + buf += std::to_string(p.y()); } buf += " z\""; // mark path as closed buf += " />\n"; @@ -55,13 +55,24 @@ public: : m_bb{BoundingBox{{0, 0}, Vec2crd{res.width_px, res.height_px}}} , m_trafo{tr} { - std::string w = float_to_string_decimal_point(unscaled(res.width_px)); - std::string h = float_to_string_decimal_point(unscaled(res.height_px)); + // Inside the svg header, the boundaries will be defined in mm to + // the actual bed size. The viewport is then defined to work with our + // scaled coordinates. All the exported polygons will be in these scaled + // coordinates but svg rendering software will interpret them correctly + // in mm due to the header's definition. + std::string wf = float_to_string_decimal_point(unscaled(res.width_px)); + std::string hf = float_to_string_decimal_point(unscaled(res.height_px)); + std::string w = std::to_string(res.width_px); + std::string h = std::to_string(res.height_px); + + // Notice the header also defines the fill-rule as nonzero which should + // generate correct results for our ExPolygons. + // Add svg header. m_svg = "\n" "\n" - "\n"; @@ -128,7 +139,7 @@ std::unique_ptr SL1_SVGArchive::create_raster() const // Gamma does not really make sense in an svg, right? // double gamma = cfg().gamma_correction.getFloat(); - return std::make_unique(SVGRaster::Resolution{w, h}, tr); + return std::make_unique(res, tr); } sla::RasterEncoder SL1_SVGArchive::get_encoder() const