Modified text drawing methods in debugging visualization (SVG) to support changing font size.

This commit is contained in:
Lukáš Hejl 2022-08-02 13:20:54 +02:00
parent caf3e258b8
commit 1b934518b3
2 changed files with 15 additions and 13 deletions

View File

@ -274,26 +274,28 @@ std::string SVG::get_path_d(const ClipperLib::Path &path, double scale, bool clo
return d.str(); return d.str();
} }
void SVG::draw_text(const Point &pt, const char *text, const char *color) void SVG::draw_text(const Point &pt, const char *text, const char *color, const coordf_t font_size)
{ {
fprintf(this->f, fprintf(this->f,
"<text x=\"%f\" y=\"%f\" font-family=\"sans-serif\" font-size=\"20px\" fill=\"%s\">%s</text>", R"(<text x="%f" y="%f" font-family="sans-serif" font-size="%fpx" fill="%s">%s</text>)",
to_svg_x(pt(0)-origin(0)), to_svg_x(float(pt.x() - origin.x())),
to_svg_y(pt(1)-origin(1)), to_svg_y(float(pt.y() - origin.y())),
font_size,
color, text); color, text);
} }
void SVG::draw_legend(const Point &pt, const char *text, const char *color) void SVG::draw_legend(const Point &pt, const char *text, const char *color, const coordf_t font_size)
{ {
fprintf(this->f, fprintf(this->f,
"<circle cx=\"%f\" cy=\"%f\" r=\"10\" fill=\"%s\"/>", R"(<circle cx="%f" cy="%f" r="10" fill="%s"/>)",
to_svg_x(pt(0)-origin(0)), to_svg_x(float(pt.x() - origin.x())),
to_svg_y(pt(1)-origin(1)), to_svg_y(float(pt.y() - origin.y())),
color); color);
fprintf(this->f, fprintf(this->f,
"<text x=\"%f\" y=\"%f\" font-family=\"sans-serif\" font-size=\"10px\" fill=\"%s\">%s</text>", R"(<text x="%f" y="%f" font-family="sans-serif" font-size="%fpx" fill="%s">%s</text>)",
to_svg_x(pt(0)-origin(0)) + 20.f, to_svg_x(float(pt.x() - origin.x())) + 20.f,
to_svg_y(pt(1)-origin(1)), to_svg_y(float(pt.y() - origin.y())),
font_size,
"black", text); "black", text);
} }

View File

@ -72,8 +72,8 @@ public:
void draw(const ClipperLib::Path &polygon, double scale, std::string fill = "grey", coordf_t stroke_width = 0); void draw(const ClipperLib::Path &polygon, double scale, std::string fill = "grey", coordf_t stroke_width = 0);
void draw(const ClipperLib::Paths &polygons, double scale, std::string fill = "grey", coordf_t stroke_width = 0); void draw(const ClipperLib::Paths &polygons, double scale, std::string fill = "grey", coordf_t stroke_width = 0);
void draw_text(const Point &pt, const char *text, const char *color); void draw_text(const Point &pt, const char *text, const char *color, coordf_t font_size = 20.f);
void draw_legend(const Point &pt, const char *text, const char *color); void draw_legend(const Point &pt, const char *text, const char *color, coordf_t font_size = 10.f);
void Close(); void Close();