diff --git a/src/libslic3r/NSVGUtils.cpp b/src/libslic3r/NSVGUtils.cpp index 7a8683e18f..8a569ba4aa 100644 --- a/src/libslic3r/NSVGUtils.cpp +++ b/src/libslic3r/NSVGUtils.cpp @@ -130,106 +130,106 @@ size_t get_shapes_count(const NSVGimage &image) return count; } -void save(const NSVGimage &image, std::ostream &data) -{ - data << ""; - - // tl .. top left - Vec2f tl(std::numeric_limits::max(), std::numeric_limits::max()); - // br .. bottom right - Vec2f br(std::numeric_limits::min(), std::numeric_limits::min()); - bounds(image, tl, br); - - tl.x() = std::floor(tl.x()); - tl.y() = std::floor(tl.y()); - - br.x() = std::ceil(br.x()); - br.y() = std::ceil(br.y()); - Vec2f s = br - tl; - Point size = s.cast(); - - data << "\n"; - data << "\n"; - - std::array buffer; - auto write_point = [&tl, &buffer](std::string &d, const float *p) { - float x = p[0] - tl.x(); - float y = p[1] - tl.y(); - auto to_string = [&buffer](float f) -> std::string { - auto [ptr, ec] = std::to_chars(buffer.data(), buffer.data() + buffer.size(), f); - if (ec != std::errc{}) - return "0"; - return std::string(buffer.data(), ptr); - }; - d += to_string(x) + "," + to_string(y) + " "; - }; - - for (const NSVGshape *shape = image.shapes; shape != NULL; shape = shape->next) { - enum struct Type { move, line, curve, close }; // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d - Type type = Type::move; - std::string d = "M "; // move on start point - for (const NSVGpath *path = shape->paths; path != NULL; path = path->next) { - if (path->npts <= 1) - continue; - - if (type == Type::close) { - Type type = Type::move; - // NOTE: After close must be a space - d += " M "; // move on start point - } - write_point(d, path->pts); - size_t path_size = static_cast(path->npts - 1); - - if (path->closed) { - // Do not use last point in path it is duplicit - if (path->npts <= 4) - continue; - path_size = static_cast(path->npts - 4); - } - - for (size_t i = 0; i < path_size; i += 3) { - const float *p = &path->pts[i * 2]; - if (!::is_line(p)) { - if (type != Type::curve) { - type = Type::curve; - d += "C "; // start sequence of triplets defining curves - } - write_point(d, &p[2]); - write_point(d, &p[4]); - } else { - - if (type != Type::line) { - type = Type::line; - d += "L "; // start sequence of line points - } - } - write_point(d, &p[6]); - } - if (path->closed) { - type = Type::close; - d += "Z"; // start sequence of line points - } - } - if (type != Type::close) { - //type = Type::close; - d += "Z"; // closed path - } - data << "\n"; - } - data << "\n"; -} - -bool save(const NSVGimage &image, const std::string &svg_file_path) -{ - std::ofstream file{svg_file_path}; - if (!file.is_open()) - return false; - save(image, file); - return true; -} +//void save(const NSVGimage &image, std::ostream &data) +//{ +// data << ""; +// +// // tl .. top left +// Vec2f tl(std::numeric_limits::max(), std::numeric_limits::max()); +// // br .. bottom right +// Vec2f br(std::numeric_limits::min(), std::numeric_limits::min()); +// bounds(image, tl, br); +// +// tl.x() = std::floor(tl.x()); +// tl.y() = std::floor(tl.y()); +// +// br.x() = std::ceil(br.x()); +// br.y() = std::ceil(br.y()); +// Vec2f s = br - tl; +// Point size = s.cast(); +// +// data << "\n"; +// data << "\n"; +// +// std::array buffer; +// auto write_point = [&tl, &buffer](std::string &d, const float *p) { +// float x = p[0] - tl.x(); +// float y = p[1] - tl.y(); +// auto to_string = [&buffer](float f) -> std::string { +// auto [ptr, ec] = std::to_chars(buffer.data(), buffer.data() + buffer.size(), f); +// if (ec != std::errc{}) +// return "0"; +// return std::string(buffer.data(), ptr); +// }; +// d += to_string(x) + "," + to_string(y) + " "; +// }; +// +// for (const NSVGshape *shape = image.shapes; shape != NULL; shape = shape->next) { +// enum struct Type { move, line, curve, close }; // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d +// Type type = Type::move; +// std::string d = "M "; // move on start point +// for (const NSVGpath *path = shape->paths; path != NULL; path = path->next) { +// if (path->npts <= 1) +// continue; +// +// if (type == Type::close) { +// type = Type::move; +// // NOTE: After close must be a space +// d += " M "; // move on start point +// } +// write_point(d, path->pts); +// size_t path_size = static_cast(path->npts - 1); +// +// if (path->closed) { +// // Do not use last point in path it is duplicit +// if (path->npts <= 4) +// continue; +// path_size = static_cast(path->npts - 4); +// } +// +// for (size_t i = 0; i < path_size; i += 3) { +// const float *p = &path->pts[i * 2]; +// if (!::is_line(p)) { +// if (type != Type::curve) { +// type = Type::curve; +// d += "C "; // start sequence of triplets defining curves +// } +// write_point(d, &p[2]); +// write_point(d, &p[4]); +// } else { +// +// if (type != Type::line) { +// type = Type::line; +// d += "L "; // start sequence of line points +// } +// } +// write_point(d, &p[6]); +// } +// if (path->closed) { +// type = Type::close; +// d += "Z"; // start sequence of line points +// } +// } +// if (type != Type::close) { +// //type = Type::close; +// d += "Z"; // closed path +// } +// data << "\n"; +// } +// data << "\n"; +//} +// +//bool save(const NSVGimage &image, const std::string &svg_file_path) +//{ +// std::ofstream file{svg_file_path}; +// if (!file.is_open()) +// return false; +// save(image, file); +// return true; +//} } // namespace Slic3r namespace { diff --git a/src/libslic3r/NSVGUtils.hpp b/src/libslic3r/NSVGUtils.hpp index 62ad3deb27..12cd2c3f59 100644 --- a/src/libslic3r/NSVGUtils.hpp +++ b/src/libslic3r/NSVGUtils.hpp @@ -79,7 +79,7 @@ NSVGimage_ptr nsvgParse(const std::string& file_data, const char *units = "mm", /// Count of shapes size_t get_shapes_count(const NSVGimage &image); -void save(const NSVGimage &image, std::ostream &data); -bool save(const NSVGimage &image, const std::string &svg_file_path); +//void save(const NSVGimage &image, std::ostream &data); +//bool save(const NSVGimage &image, const std::string &svg_file_path); } // namespace Slic3r #endif // slic3r_NSVGUtils_hpp_