#ifndef slic3r_Emboss_hpp_ #define slic3r_Emboss_hpp_ #include #include #include #include #include // indexed_triangle_set #include "Polygon.hpp" namespace Slic3r { /// /// class with only static function add ability to engraved OR raised /// text OR polygons onto model surface /// class Emboss { public: Emboss() = delete; /// /// keep information from file about font /// struct Font { // loaded data from font file std::vector buffer; unsigned int index=0; // index of actual file info in collection unsigned int count=0; // count of fonts in file collection // vertical position is "scale*(ascent - descent + lineGap)" int ascent=0, descent=0, linegap=0; // user defined unscaled char space int extra_char_space = 0; // unscaled precision of lettter outline curve in conversion to lines float flatness = 2.; // enum class Align: center/left/right }; /// /// Load font file into buffer /// /// Location of .ttf or .ttc font file /// Font object when loaded. static std::optional load_font(const char *file_path); /// /// convert letter into polygons /// /// Define fonts /// One character to convert /// Precision of lettter outline curve in conversion to lines /// inner polygon ccw(outer cw) static Polygons letter2polygons(const Font &font, char letter, float flatness); /// /// Convert text into polygons /// /// Define fonts /// Characters to convert /// Precision of lettter outline curve in conversion to lines /// Inner polygon ccw(outer cw) static Polygons text2polygons(const Font &font, const char *text, float flatness); /// /// Project 2d point into space /// Could be plane, sphere, cylindric, ... /// class IProject { public: virtual ~IProject() = default; /// /// convert 2d point to 3d point /// /// 2d coordinate /// /// first - front spatial point /// second - back spatial point /// virtual std::pair project(const Point &p) const = 0; }; /// /// Create triangle model for text /// /// text or image /// Define transformation from 2d to 3d(orientation, position, scale, ...) /// Projected shape into space static indexed_triangle_set polygons2model(const Polygons &shape2d, const IProject& projection); // define oriented connection of 2 vertices(defined by its index) using HalfEdge = std::pair; using HalfEdges = std::set; using Indices = std::vector; /// /// Connect points by triangulation to create filled surface by triangle indices /// /// Points to connect /// Constraint for edges, pair is from point(first) to point(second) /// Triangles static Indices triangulate(const Points &points, const HalfEdges &half_edges); static Indices triangulate(const Polygon &polygon); static Indices triangulate(const Polygons &polygons); /// /// Filter out triagles without both side edge or inside half edges /// Main purpose: Filter out triangles which lay outside of ExPolygon given to triangulation /// /// Triangles /// Only outer edges static void remove_outer(Indices &indices, const HalfEdges &half_edges); class ProjectZ : public IProject { public: ProjectZ(float depth) : m_depth(depth) {} // Inherited via IProject virtual std::pair project(const Point &p) const override; float m_depth; }; class ProjectScale : public IProject { std::unique_ptr core; public: ProjectScale(std::unique_ptr core, float scale) : m_scale(scale) , core(std::move(core)) {} // Inherited via IProject virtual std::pair project(const Point &p) const override { auto res = core->project(p); return std::make_pair(res.first * m_scale, res.second * m_scale); } float m_scale; }; }; } // namespace Slic3r #endif // slic3r_Emboss_hpp_