From 45239af178e8efa6734087e52a50e2f863cb61f6 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Sat, 11 Jan 2025 17:45:36 +0100 Subject: Make Fl_SVG_Graphics_Driver use the C locale when writing float values --- src/drivers/SVG/Fl_SVG_File_Surface.cxx | 54 ++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 15 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/SVG/Fl_SVG_File_Surface.cxx b/src/drivers/SVG/Fl_SVG_File_Surface.cxx index 2ee14d216..f1de59e9e 100644 --- a/src/drivers/SVG/Fl_SVG_File_Surface.cxx +++ b/src/drivers/SVG/Fl_SVG_File_Surface.cxx @@ -24,12 +24,14 @@ #include #include #include +#include "Fl_System_Driver.H" #include #include #include #include #include #include +#include extern "C" { #if defined(HAVE_LIBPNG) @@ -71,6 +73,7 @@ public: ~Fl_SVG_Graphics_Driver(); FILE* file() {return out_;} protected: + int clocale_printf(const char *format, ...); void rect(int x, int y, int w, int h) FL_OVERRIDE; void rectf(int x, int y, int w, int h) FL_OVERRIDE; virtual void compute_dasharray(float s, char *dashes=0); @@ -152,6 +155,27 @@ Fl_SVG_Graphics_Driver::~Fl_SVG_Graphics_Driver() if (last_rgb_name_) free(last_rgb_name_); } + +int Fl_SVG_Graphics_Driver::clocale_printf(const char *format, ...) +{ + va_list args; + va_start(args, format); + int retval = Fl::system_driver()->clocale_vprintf(out_, format, args); + va_end(args); + return retval; +} + + +static int clocale_fprintf(FILE *f, const char *format, ...) +{ + va_list args; + va_start(args, format); + int retval = Fl::system_driver()->clocale_vprintf(f, format, args); + va_end(args); + return retval; +} + + void Fl_SVG_Graphics_Driver::rect(int x, int y, int w, int h) { fprintf(out_, "\n", sw, sh, sw, sh); width_ = w; height_ = h; - fprintf(f, "\n", s); + clocale_fprintf(f, "\n", s); fputs("\n", f); } @@ -475,7 +499,7 @@ void Fl_SVG_Graphics_Driver::define_rgb_png(Fl_RGB_Image *rgb, const char *name, float f = rgb->data_w() > rgb->data_h() ? float(rgb->w()) / rgb->data_w(): float(rgb->h()) / rgb->data_h(); if (name) fprintf(out_, "data_w(), f*rgb->data_h()); + clocale_printf("width=\"%f\" height=\"%f\" href=\"data:image/png;base64,\n", f*rgb->data_w(), f*rgb->data_h()); // Transforms the image into a stream of bytes in PNG format, // base64-encode this byte stream, and outputs the result to the svg FILE. svg_base64_t svg_base64_data; @@ -564,7 +588,7 @@ void Fl_SVG_Graphics_Driver::define_rgb_jpeg(Fl_RGB_Image *rgb, const char *name float f = rgb->data_w() > rgb->data_h() ? float(rgb->w()) / rgb->data_w(): float(rgb->h()) / rgb->data_h(); if (name) fprintf(out_, "data_w(), f*rgb->data_h()); + clocale_printf("width=\"%f\" height=\"%f\" href=\"data:image/jpeg;base64,\n", f*rgb->data_w(), f*rgb->data_h()); // Transforms the image into a stream of bytes in JPEG format, // base64-encode this byte stream, and outputs the result to the svg FILE. jpeg_compress_struct cinfo; @@ -856,7 +880,7 @@ void Fl_SVG_Graphics_Driver::loop(int x0, int y0, int x1, int y1, int x2, int y2 void Fl_SVG_Graphics_Driver::end_points() { for (int i=0; i\n", + clocale_printf("\n", xpoint[i].x, xpoint[i].y, xpoint[i].x, xpoint[i].y, red_, green_, blue_, width_); } } @@ -867,9 +891,9 @@ void Fl_SVG_Graphics_Driver::end_line() { return; } if (n<=1) return; - fprintf(out_, "\n", red_, green_, blue_, width_, dasharray_, linecap_, linejoin_); } @@ -881,9 +905,9 @@ void Fl_SVG_Graphics_Driver::end_polygon() { return; } if (n<=1) return; - fprintf(out_, "\n", red_, green_, blue_); } @@ -896,7 +920,7 @@ void Fl_SVG_Graphics_Driver::circle(double x, double y, double r) { int w = (int)rint(xt+rx)-llx; int lly = (int)rint(yt-ry); int h = (int)rint(yt+ry)-lly; - fprintf(out_, "\n", red_, green_, blue_); } @@ -952,22 +976,22 @@ void Fl_SVG_Graphics_Driver::arc_pie(char AorP, int x, int y, int w, int h, doub sx = sy = float(2*r); stroke_width /= sx; } - fprintf(out_, "\n", cx, cy, sx, sy); + clocale_printf("\n", cx, cy, sx, sy); if (AorP == 'A') compute_dasharray((sx+sy)/2, user_dash_array_); if (full) { fprintf(out_, " M_PI ? 1 : 0; if (AorP == 'A') - fprintf(out_, "\n\n", red_, green_, blue_); -- cgit v1.2.3