FILE* svgBegin(const char *filename, double widthMM, double heightMM, double unitsPerMM) {
FILE *f = fopen(filename, "w");
if (f) {
fprintf(f, "<svg width=\"%gmm\" height=\"%gmm\" viewBox=\"0 0 %g %g\">\n",
widthMM, heightMM, widthMM*unitsPerMM, heightMM*unitsPerMM );
}
return f;
}
void svgEnd(FILE *f) {
if (!f) return;
fprintf(f, "</svg>\n");
fclose(f);
}
void svgAddText(FILE *f, double x, double y, double size, const char *text) {
if (!f) return;
fprintf(f, "<text x=\"%g\" y=\"%g\" style=\"font-size:%g\">%s</text>\n", x, y, size, text);
}
void svgAddPath(FILE *f, const char *path, double width, int round) {
if (!f) return;
fprintf(f, "<path style=\"fill:none;stroke:#000000;%sstroke-width:%f\"\n"
" d=\"%s\" />\n",
(round ? "stroke-linecap:round;stroke-linejoin:round;" : ""),
width, path );
}