diff --git a/include/utils/SVG.h b/include/utils/SVG.h index d3ac435561..619fd1e5bf 100644 --- a/include/utils/SVG.h +++ b/include/utils/SVG.h @@ -1,5 +1,5 @@ -//Copyright (c) 2022 Ultimaker B.V. -//CuraEngine is released under the terms of the AGPLv3 or higher. +// Copyright (c) 2022 Ultimaker B.V. +// CuraEngine is released under the terms of the AGPLv3 or higher. #ifndef SVG_H #define SVG_H @@ -19,7 +19,8 @@ class FPoint3; class SVG : NoCopy { public: - enum class Color { + enum class Color + { BLACK, WHITE, GRAY, @@ -42,16 +43,18 @@ class SVG : NoCopy ColorObject(Color color) : is_enum(true) , color(color) - {} + { + } ColorObject(int r, int g, int b) : is_enum(false) , r(r) , g(g) , b(b) - {} + { + } }; -private: +private: std::string toString(const Color color) const; std::string toString(const ColorObject& color) const; @@ -129,7 +132,7 @@ class SVG : NoCopy * \param b The ending endpoint of the line. * \param color The stroke colour of the line. */ - void writeDashedLine(const Point& a,const Point& b, ColorObject color = Color::BLACK) const; + void writeDashedLine(const Point& a, const Point& b, ColorObject color = Color::BLACK) const; template void printf(const char* txt, Args&&... args) const; @@ -187,7 +190,6 @@ class SVG : NoCopy * \param font_size The size of the font to write the coordinates with. */ void writeCoordinateGrid(const coord_t grid_size = MM2INT(1), const Color color = Color::BLACK, const float stroke_width = 0.1, const float font_size = 10) const; - }; template diff --git a/src/utils/SVG.cpp b/src/utils/SVG.cpp index 0b45100b3d..e4dddb05e0 100644 --- a/src/utils/SVG.cpp +++ b/src/utils/SVG.cpp @@ -1,12 +1,13 @@ // Copyright (c) 2022 Ultimaker B.V. // CuraEngine is released under the terms of the AGPLv3 or higher +#include "utils/SVG.h" + #include #include #include "utils/ExtrusionLine.h" -#include "utils/SVG.h" #include "utils/floatpoint.h" #include "utils/polygon.h" @@ -59,15 +60,26 @@ std::string SVG::toString(const ColorObject& color) const SVG::SVG(std::string filename, AABB aabb, Point canvas_size, ColorObject background) - : SVG(filename, aabb, std::min(double(canvas_size.X - canvas_size.X / 5 * 2) / (aabb.max.X - aabb.min.X), double(canvas_size.Y - canvas_size.Y / 5) / (aabb.max.Y - aabb.min.Y)), canvas_size, background) + : SVG( + filename, + aabb, + std::min(double(canvas_size.X - canvas_size.X / 5 * 2) / (aabb.max.X - aabb.min.X), double(canvas_size.Y - canvas_size.Y / 5) / (aabb.max.Y - aabb.min.Y)), + canvas_size, + background) { } -SVG::SVG(std::string filename, AABB aabb, double scale, ColorObject background) : SVG(filename, aabb, scale, (aabb.max - aabb.min) * scale, background) +SVG::SVG(std::string filename, AABB aabb, double scale, ColorObject background) + : SVG(filename, aabb, scale, (aabb.max - aabb.min) * scale, background) { } -SVG::SVG(std::string filename, AABB aabb, double scale, Point canvas_size, ColorObject background) : aabb(aabb), aabb_size(aabb.max - aabb.min), canvas_size(canvas_size), scale(scale), background(background) +SVG::SVG(std::string filename, AABB aabb, double scale, Point canvas_size, ColorObject background) + : aabb(aabb) + , aabb_size(aabb.max - aabb.min) + , canvas_size(canvas_size) + , scale(scale) + , background(background) { output_is_html = strcmp(filename.c_str() + strlen(filename.c_str()) - 4, "html") == 0; out = fopen(filename.c_str(), "w"); @@ -165,7 +177,12 @@ void SVG::writeAreas(const Polygons& polygons, const ColorObject color, const Co void SVG::writeAreas(ConstPolygonRef polygon, const ColorObject color, const ColorObject outline_color, const float stroke_width) const { - fprintf(out, "& polyline, const ColorObject color } FPoint3 transformed = transformF(polyline[0]); // Element 0 must exist due to the check above. - fprintf(out, "", toString(color).c_str(), fa.x, fa.y, fb.x, fb.y, tip.x, tip.y, b_base.x, b_base.y, a_base.x, a_base.y); + fprintf( + out, + "", + toString(color).c_str(), + fa.x, + fa.y, + fb.x, + fb.y, + tip.x, + tip.y, + b_base.x, + b_base.y, + a_base.x, + a_base.y); } void SVG::writeLineRGB(const Point& from, const Point& to, const int r, const int g, const int b, const float stroke_width) const @@ -369,7 +404,7 @@ void SVG::writeLine(const ExtrusionLine& line, const ColorObject color, const fl { ExtrusionJunction end_vertex = line.junctions[index]; - // Compute the corners of the trapezoid for this variable-width line segment. + // Compute the corners of the trapezoid for this variable-width line segment. const Point direction_vector = end_vertex.p - start_vertex.p; const Point direction_left = turn90CCW(direction_vector); const Point direction_right = -direction_left; // Opposite of left. @@ -378,7 +413,18 @@ void SVG::writeLine(const ExtrusionLine& line, const ColorObject color, const fl const FPoint3 end_left = transformF(end_vertex.p + normal(direction_left, std::max(minimum_line_width, end_vertex.w * width_factor))); const FPoint3 end_right = transformF(end_vertex.p + normal(direction_right, std::max(minimum_line_width, end_vertex.w * width_factor))); - fprintf(out, "\n", toString(color).c_str(), start_left.x, start_left.y, start_right.x, start_right.y, end_right.x, end_right.y, end_left.x, end_left.y); + fprintf( + out, + "\n", + toString(color).c_str(), + start_left.x, + start_left.y, + start_right.x, + start_right.y, + end_right.x, + end_right.y, + end_left.x, + end_left.y); start_vertex = end_vertex; // For the next line segment. }