From 0d835b47d51440c4355c701dfcf338ef050bc3cb Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 4 Aug 2023 22:13:06 -0400 Subject: [PATCH] io-svg.c: remove code for non-incremental loading. This requires you to completely install the module before testing with svg2png, but it makes sure that we test the real (incremental) code path that gets used. --- io-svg.c | 55 +++---------------------------------------------------- 1 file changed, 3 insertions(+), 52 deletions(-) diff --git a/io-svg.c b/io-svg.c index 750ea25..341d9e5 100644 --- a/io-svg.c +++ b/io-svg.c @@ -1,4 +1,4 @@ -#include /* fopen, fprintf, fread, printf */ +#include /* fprintf, printf */ #include /* memcpy */ #include @@ -328,48 +328,6 @@ static GdkPixbuf* gdk_pixbuf_from_svg_buffer(char* buffer, } -/** - * @brief Create a GdkPixbuf from an SVG filestream. - * - * This is essentially a wrapper around @gdk_pixbuf_from_svg_buffer - * that reads a @c FILE pointer into a buffer. - * - * @param fp - * A pointer to a @c FILE containing the SVG document. - * - * @param error - * The address of a @c GError pointer that we use to return errors. - * - * @return If successful, a valid pointer to a @c GdkPixbuf is - * returned; if not, @c NULL is returned and @c error is populated. - */ -static GdkPixbuf* gdk_pixbuf_from_svg_file_stream(FILE *fp, GError** error) { - size_t bytecount, bytesread; - char* buffer; - - /* Find the size of the file stream */ - fseek(fp, 0L, SEEK_END); - bytecount = ftell(fp); - rewind(fp); - - /* YOLO, no error checking */ - buffer = g_malloc(bytecount); - - bytesread = fread(buffer, 1, bytecount, fp); - if (bytesread != bytecount) { - g_set_error(error, - G_FILE_ERROR, - G_FILE_ERROR_FAILED, - "read only %zd of %zd bytes from stream", - bytesread, - bytecount); - return NULL; - } - - return gdk_pixbuf_from_svg_buffer(buffer, bytecount, error); -} - - static gpointer gdk_pixbuf_begin_load(GdkPixbufModuleSizeFunc size_func, GdkPixbufModulePreparedFunc prep_func, GdkPixbufModuleUpdatedFunc updated_func, @@ -478,7 +436,6 @@ void fill_vtable(GdkPixbufModule* module) { module->begin_load = gdk_pixbuf_begin_load; module->load_increment = gdk_pixbuf_load_increment; module->stop_load = gdk_pixbuf_stop_load; - module->load = gdk_pixbuf_from_svg_file_stream; } G_MODULE_EXPORT void fill_info(GdkPixbufFormat *info); @@ -535,16 +492,10 @@ int main(int argc, char** argv) { svgpath = argv[1]; pngpath = argv[2]; - fp = fopen(svgpath, "rb"); - if (!fp) { - perror(svgpath); - return 1; - } - - pb = gdk_pixbuf_from_svg_file_stream(fp, &err); + pb = gdk_pixbuf_new_from_file(svgpath, &err); if (!pb) { fprintf(stderr, - "Error %d in gdk_pixbuf_from_svg_file_stream: %s\n", + "Error %d in gdk_pixbuf_new_from_file: %s\n", err->code, err->message); g_error_free(err); -- 2.43.2